Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add [E³] SB6432 LCD key driver #1180

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add set backlight color function
  • Loading branch information
sephalon committed May 17, 2020
commit f06f7d26d39146f7c57c164684e13e6e5cd36c1b
3 changes: 3 additions & 0 deletions cppsrc/U8g2lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class U8G2 : public Print
void setContrast(uint8_t value) {
u8g2_SetContrast(&u8g2, value); }

void setBacklightColor(uint32_t value) {
u8g2_SetBacklightColor(&u8g2, value); }

void setDisplayRotation(const u8g2_cb_t *u8g2_cb) {
u8g2_SetDisplayRotation(&u8g2, u8g2_cb); }

Expand Down
3 changes: 3 additions & 0 deletions cppsrc/U8x8lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ class U8X8 : public Print
void setContrast(uint8_t value) {
u8x8_SetContrast(&u8x8, value); }

void setBacklightColor(uint32_t value) {
u8x8_SetBacklightColor(&u8x8, value); }

void setInverseFont(uint8_t value) {
u8x8_SetInverseFont(&u8x8, value); }

Expand Down
1 change: 1 addition & 0 deletions csrc/u8g2.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ struct u8g2_struct
#define u8g2_SetPowerSave(u8g2, is_enable) u8x8_SetPowerSave(u8g2_GetU8x8(u8g2), (is_enable))
#define u8g2_SetFlipMode(u8g2, mode) u8x8_SetFlipMode(u8g2_GetU8x8(u8g2), (mode))
#define u8g2_SetContrast(u8g2, value) u8x8_SetContrast(u8g2_GetU8x8(u8g2), (value))
#define u8g2_SetBacklightColor(u8g2, value) u8x8_SetBacklightColor(u8g2_GetU8x8(u8g2), (value))
//#define u8g2_ClearDisplay(u8g2) u8x8_ClearDisplay(u8g2_GetU8x8(u8g2)) obsolete, can not be used in all cases
void u8g2_ClearDisplay(u8g2_t *u8g2);

Expand Down
18 changes: 16 additions & 2 deletions csrc/u8x8.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
U8X8_MSG_DISPLAY_SET_FLIP_MODE
U8X8_MSG_DISPLAY_SET_POWER_SAVE
U8X8_MSG_DISPLAY_SET_CONTRAST
U8X8_MSG_DISPLAY_SET_BACKLIGHT_COLOR
U8X8_MSG_DISPLAY_DRAW_TILE

A display driver may decided to breakdown these messages to a lower level interface or
Expand Down Expand Up @@ -91,6 +92,9 @@
/* Undefine this to remove u8x8_SetContrast function */
#define U8X8_WITH_SET_CONTRAST

/* Undefine this to remove u8x8_SetBacklightColor function */
#define U8X8_WITH_SET_BACKLIGHT_COLOR

/* Define this for an additional user pointer inside the u8x8 data struct */
//#define U8X8_WITH_USER_PTR

Expand Down Expand Up @@ -471,6 +475,15 @@ void u8x8_d_helper_display_init(u8x8_t *u8g2);
/* arg_int: 0..255 contrast value */
#define U8X8_MSG_DISPLAY_SET_CONTRAST 14

/*
Name: U8X8_MSG_DISPLAY_SET_BACKLIGHT_COLOR
Args: arg_ptr: color: 24-bit RGB
Tasks:
Set the color of the backlight. The dsplay driver might transform the given
24-bit RGB color into the more limited color space of the backlight.
*/
#define U8X8_MSG_DISPLAY_SET_BACKLIGHT_COLOR 15

/*
Name: U8X8_MSG_DISPLAY_DRAW_TILE
Args:
Expand Down Expand Up @@ -498,7 +511,7 @@ void u8x8_d_helper_display_init(u8x8_t *u8g2);
ABABAB. Totally, cnt*arg_int tiles will be drawn.

*/
#define U8X8_MSG_DISPLAY_DRAW_TILE 15
#define U8X8_MSG_DISPLAY_DRAW_TILE 16


/*
Expand All @@ -515,7 +528,7 @@ void u8x8_d_helper_display_init(u8x8_t *u8g2);
void u8x8_RefreshDisplay(u8x8_t *u8x8)
to send the message to the display handler.
*/
#define U8X8_MSG_DISPLAY_REFRESH 16
#define U8X8_MSG_DISPLAY_REFRESH 17

/*==========================================*/
/* u8x8_setup.c */
Expand Down Expand Up @@ -555,6 +568,7 @@ void u8x8_InitDisplay(u8x8_t *u8x8);
void u8x8_SetPowerSave(u8x8_t *u8x8, uint8_t is_enable);
void u8x8_SetFlipMode(u8x8_t *u8x8, uint8_t mode);
void u8x8_SetContrast(u8x8_t *u8x8, uint8_t value);
void u8x8_SetBacklightColor(u8x8_t *u8x8, uint32_t color);
void u8x8_ClearDisplayWithTile(u8x8_t *u8x8, const uint8_t *buf) U8X8_NOINLINE;
void u8x8_ClearDisplay(u8x8_t *u8x8); // this does not work for u8g2 in some cases
void u8x8_FillDisplay(u8x8_t *u8x8);
Expand Down
25 changes: 25 additions & 0 deletions csrc/u8x8_d_e3keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ static const u8x8_display_info_t u8x8_e3keys_sb6432_display_info =


#define E3KEYS_AT_CMD_SET_DISPLAY_ADDR_WRITE_DATA 0x40
#define E3KEYS_AT_CMD_SET_RGB_COLOR 0x42
#define E3KEYS_AT_CMD_END_TRANSMISSION 0x43

#define E3KEYS_AT_EXT_CMD_START 0x47
Expand Down Expand Up @@ -105,6 +106,10 @@ static const uint8_t u8x8_d_e3keys_sb6432_powersave1_seq[] = {

uint8_t u8x8_d_e3keys_sb6432(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
#ifdef U8X8_WITH_SET_BACKLIGHT_COLOR
uint32_t color;
uint8_t color_bytes[3];
#endif
const u8x8_display_info_t *d_info = u8x8->display_info;
u8x8_tile_t *tile;
const uint16_t y_addr_offset = d_info->pixel_height / 8;
Expand All @@ -124,6 +129,26 @@ uint8_t u8x8_d_e3keys_sb6432(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *a
else
u8x8_cad_SendSequence(u8x8, u8x8_d_e3keys_sb6432_powersave0_seq);
break;
#ifdef U8X8_WITH_SET_BACKLIGHT_COLOR
case U8X8_MSG_DISPLAY_SET_BACKLIGHT_COLOR:
color = *((uint32_t *) arg_ptr);
/*
* Set RGB Color command data layout:
* Red: 0 D_6 D_5 D_4 D_3 D_2 D_1 D_0
* Green: 0 D_6 D_5 D_4 D_3 D_2 D_1 D_0
* Blue: 0 D_6 D_5 D_4 D_3 D_2 D_1 D_0
*/
color_bytes[0] = (color >> 16) & 0x7f; /* red */
color_bytes[1] = (color >> 8) & 0x7f; /* green */
color_bytes[2] = color & 0x7f; /* blue */

u8x8_cad_StartTransfer(u8x8);
u8x8_cad_SendCmd(u8x8, E3KEYS_AT_CMD_SET_RGB_COLOR);
u8x8_cad_SendData(u8x8, 3, color_bytes);
u8x8_cad_SendCmd(u8x8, E3KEYS_AT_CMD_END_TRANSMISSION);
u8x8_cad_EndTransfer(u8x8);
break;
#endif
case U8X8_MSG_DISPLAY_DRAW_TILE:
tile = (u8x8_tile_t *)arg_ptr;

Expand Down
7 changes: 6 additions & 1 deletion csrc/u8x8_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ void u8x8_SetContrast(u8x8_t *u8x8, uint8_t value)
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_CONTRAST, value, NULL);
}

void u8x8_SetBacklightColor(u8x8_t *u8x8, uint32_t color)
{
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_BACKLIGHT_COLOR, 0, &color);
}

void u8x8_RefreshDisplay(u8x8_t *u8x8)
{
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_REFRESH, 0, NULL);
Expand Down Expand Up @@ -162,4 +167,4 @@ void u8x8_ClearLine(u8x8_t *u8x8, uint8_t line)
tile.tile_ptr = (uint8_t *)buf; /* tile_ptr should be const, but isn't */
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, u8x8->display_info->tile_width, (void *)&tile);
}
}
}