diff --git a/cppsrc/U8g2lib.h b/cppsrc/U8g2lib.h index edcc45f98..d79a28550 100644 --- a/cppsrc/U8g2lib.h +++ b/cppsrc/U8g2lib.h @@ -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); } @@ -17168,6 +17171,60 @@ class U8G2_MAX7219_8X8_F_2ND_4W_HW_SPI : public U8G2 { u8x8_SetPin_4Wire_HW_SPI(getU8x8(), cs, dc, reset); } }; +class U8G2_E3KEYS_SB6432_1_4W_SW_SPI : public U8G2 { + public: U8G2_E3KEYS_SB6432_1_4W_SW_SPI(const u8g2_cb_t *rotation, uint8_t clock, uint8_t data, uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8G2() { + u8g2_Setup_e3keys_sb6432_1(&u8g2, rotation, u8x8_byte_arduino_4wire_sw_spi, u8x8_gpio_and_delay_arduino); + u8x8_SetPin_4Wire_SW_SPI(getU8x8(), clock, data, cs, dc, reset); + } +}; +class U8G2_E3KEYS_SB6432_1_4W_HW_SPI : public U8G2 { + public: U8G2_E3KEYS_SB6432_1_4W_HW_SPI(const u8g2_cb_t *rotation, uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8G2() { + u8g2_Setup_e3keys_sb6432_1(&u8g2, rotation, u8x8_byte_arduino_hw_spi, u8x8_gpio_and_delay_arduino); + u8x8_SetPin_4Wire_HW_SPI(getU8x8(), cs, dc, reset); + } +}; +class U8G2_E3KEYS_SB6432_1_2ND_4W_HW_SPI : public U8G2 { + public: U8G2_E3KEYS_SB6432_1_2ND_4W_HW_SPI(const u8g2_cb_t *rotation, uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8G2() { + u8g2_Setup_e3keys_sb6432_1(&u8g2, rotation, u8x8_byte_arduino_2nd_hw_spi, u8x8_gpio_and_delay_arduino); + u8x8_SetPin_4Wire_HW_SPI(getU8x8(), cs, dc, reset); + } +}; +class U8G2_E3KEYS_SB6432_2_4W_SW_SPI : public U8G2 { + public: U8G2_E3KEYS_SB6432_2_4W_SW_SPI(const u8g2_cb_t *rotation, uint8_t clock, uint8_t data, uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8G2() { + u8g2_Setup_e3keys_sb6432_2(&u8g2, rotation, u8x8_byte_arduino_4wire_sw_spi, u8x8_gpio_and_delay_arduino); + u8x8_SetPin_4Wire_SW_SPI(getU8x8(), clock, data, cs, dc, reset); + } +}; +class U8G2_E3KEYS_SB6432_2_4W_HW_SPI : public U8G2 { + public: U8G2_E3KEYS_SB6432_2_4W_HW_SPI(const u8g2_cb_t *rotation, uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8G2() { + u8g2_Setup_e3keys_sb6432_2(&u8g2, rotation, u8x8_byte_arduino_hw_spi, u8x8_gpio_and_delay_arduino); + u8x8_SetPin_4Wire_HW_SPI(getU8x8(), cs, dc, reset); + } +}; +class U8G2_E3KEYS_SB6432_2_2ND_4W_HW_SPI : public U8G2 { + public: U8G2_E3KEYS_SB6432_2_2ND_4W_HW_SPI(const u8g2_cb_t *rotation, uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8G2() { + u8g2_Setup_e3keys_sb6432_2(&u8g2, rotation, u8x8_byte_arduino_2nd_hw_spi, u8x8_gpio_and_delay_arduino); + u8x8_SetPin_4Wire_HW_SPI(getU8x8(), cs, dc, reset); + } +}; +class U8G2_E3KEYS_SB6432_F_4W_SW_SPI : public U8G2 { + public: U8G2_E3KEYS_SB6432_F_4W_SW_SPI(const u8g2_cb_t *rotation, uint8_t clock, uint8_t data, uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8G2() { + u8g2_Setup_e3keys_sb6432_f(&u8g2, rotation, u8x8_byte_arduino_4wire_sw_spi, u8x8_gpio_and_delay_arduino); + u8x8_SetPin_4Wire_SW_SPI(getU8x8(), clock, data, cs, dc, reset); + } +}; +class U8G2_E3KEYS_SB6432_F_4W_HW_SPI : public U8G2 { + public: U8G2_E3KEYS_SB6432_F_4W_HW_SPI(const u8g2_cb_t *rotation, uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8G2() { + u8g2_Setup_e3keys_sb6432_f(&u8g2, rotation, u8x8_byte_arduino_hw_spi, u8x8_gpio_and_delay_arduino); + u8x8_SetPin_4Wire_HW_SPI(getU8x8(), cs, dc, reset); + } +}; +class U8G2_E3KEYS_SB6432_F_2ND_4W_HW_SPI : public U8G2 { + public: U8G2_E3KEYS_SB6432_F_2ND_4W_HW_SPI(const u8g2_cb_t *rotation, uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8G2() { + u8g2_Setup_e3keys_sb6432_f(&u8g2, rotation, u8x8_byte_arduino_2nd_hw_spi, u8x8_gpio_and_delay_arduino); + u8x8_SetPin_4Wire_HW_SPI(getU8x8(), cs, dc, reset); + } +}; /* Arduino constructor list end */ diff --git a/cppsrc/U8x8lib.h b/cppsrc/U8x8lib.h index 37c57c5ff..6ef3acade 100644 --- a/cppsrc/U8x8lib.h +++ b/cppsrc/U8x8lib.h @@ -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); } @@ -5967,6 +5970,24 @@ class U8X8_MAX7219_8X8_2ND_4W_HW_SPI : public U8X8 { u8x8_SetPin_4Wire_HW_SPI(getU8x8(), cs, dc, reset); } }; +class U8X8_E3KEYS_SB6432_4W_SW_SPI : public U8X8 { + public: U8X8_E3KEYS_SB6432_4W_SW_SPI(uint8_t clock, uint8_t data, uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8X8() { + u8x8_Setup(getU8x8(), u8x8_d_e3keys_sb6432, u8x8_cad_empty, u8x8_byte_arduino_4wire_sw_spi, u8x8_gpio_and_delay_arduino); + u8x8_SetPin_4Wire_SW_SPI(getU8x8(), clock, data, cs, dc, reset); + } +}; +class U8X8_E3KEYS_SB6432_4W_HW_SPI : public U8X8 { + public: U8X8_E3KEYS_SB6432_4W_HW_SPI(uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8X8() { + u8x8_Setup(getU8x8(), u8x8_d_e3keys_sb6432, u8x8_cad_empty, u8x8_byte_arduino_hw_spi, u8x8_gpio_and_delay_arduino); + u8x8_SetPin_4Wire_HW_SPI(getU8x8(), cs, dc, reset); + } +}; +class U8X8_E3KEYS_SB6432_2ND_4W_HW_SPI : public U8X8 { + public: U8X8_E3KEYS_SB6432_2ND_4W_HW_SPI(uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8X8() { + u8x8_Setup(getU8x8(), u8x8_d_e3keys_sb6432, u8x8_cad_empty, u8x8_byte_arduino_2nd_hw_spi, u8x8_gpio_and_delay_arduino); + u8x8_SetPin_4Wire_HW_SPI(getU8x8(), cs, dc, reset); + } +}; // constructor list end diff --git a/csrc/u8g2.h b/csrc/u8g2.h index 1d9c66286..1211b7a9c 100644 --- a/csrc/u8g2.h +++ b/csrc/u8g2.h @@ -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); @@ -1183,6 +1184,9 @@ void u8g2_Setup_max7219_8x8_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_ void u8g2_Setup_a2printer_384x240_1(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); void u8g2_Setup_a2printer_384x240_2(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); void u8g2_Setup_a2printer_384x240_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); +void u8g2_Setup_e3keys_sb6432_1(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); +void u8g2_Setup_e3keys_sb6432_2(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); +void u8g2_Setup_e3keys_sb6432_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); /* u8g2_d_setup.c generated code end */ diff --git a/csrc/u8g2_d_setup.c b/csrc/u8g2_d_setup.c index 8eeb0bc16..bc8cf280a 100644 --- a/csrc/u8g2_d_setup.c +++ b/csrc/u8g2_d_setup.c @@ -5515,4 +5515,32 @@ void u8g2_Setup_a2printer_384x240_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x buf = u8g2_m_48_30_f(&tile_buf_height); u8g2_SetupBuffer(u8g2, buf, tile_buf_height, u8g2_ll_hvline_horizontal_right_lsb, rotation); } +/* e3keys */ +/* e3keys 1 */ +void u8g2_Setup_e3keys_sb6432_1(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb) +{ + uint8_t tile_buf_height; + uint8_t *buf; + u8g2_SetupDisplay(u8g2, u8x8_d_e3keys_sb6432, u8x8_cad_empty, byte_cb, gpio_and_delay_cb); + buf = u8g2_m_8_4_1(&tile_buf_height); + u8g2_SetupBuffer(u8g2, buf, tile_buf_height, u8g2_ll_hvline_vertical_top_lsb, rotation); +} +/* e3keys 2 */ +void u8g2_Setup_e3keys_sb6432_2(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb) +{ + uint8_t tile_buf_height; + uint8_t *buf; + u8g2_SetupDisplay(u8g2, u8x8_d_e3keys_sb6432, u8x8_cad_empty, byte_cb, gpio_and_delay_cb); + buf = u8g2_m_8_4_2(&tile_buf_height); + u8g2_SetupBuffer(u8g2, buf, tile_buf_height, u8g2_ll_hvline_vertical_top_lsb, rotation); +} +/* e3keys f */ +void u8g2_Setup_e3keys_sb6432_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb) +{ + uint8_t tile_buf_height; + uint8_t *buf; + u8g2_SetupDisplay(u8g2, u8x8_d_e3keys_sb6432, u8x8_cad_empty, byte_cb, gpio_and_delay_cb); + buf = u8g2_m_8_4_f(&tile_buf_height); + u8g2_SetupBuffer(u8g2, buf, tile_buf_height, u8g2_ll_hvline_vertical_top_lsb, rotation); +} /* end of generated code */ diff --git a/csrc/u8x8.h b/csrc/u8x8.h index e96ccedf6..8bba9d77c 100644 --- a/csrc/u8x8.h +++ b/csrc/u8x8.h @@ -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 @@ -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 @@ -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: @@ -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 /* @@ -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 */ @@ -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); @@ -934,6 +948,7 @@ uint8_t u8x8_d_max7219_64x8(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *ar uint8_t u8x8_d_max7219_32x8(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr); uint8_t u8x8_d_max7219_16x16(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr); uint8_t u8x8_d_max7219_8x8(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr); +uint8_t u8x8_d_e3keys_sb6432(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr); diff --git a/csrc/u8x8_d_e3keys.c b/csrc/u8x8_d_e3keys.c new file mode 100644 index 000000000..c4f750698 --- /dev/null +++ b/csrc/u8x8_d_e3keys.c @@ -0,0 +1,196 @@ +/* + + u8x8_d_e3keys.c + + Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) + + Copyright (c) 2020, me@sephalon.net + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list + of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or other + materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + + +#include "u8x8.h" + + +static const u8x8_display_info_t u8x8_e3keys_sb6432_display_info = +{ + /* chip_enable_level = */ 0, /* not applicable */ + /* chip_disable_level = */ 1, /* not applicable */ + + /* post_chip_enable_wait_ns = */ 0, /* not applicable */ + /* pre_chip_disable_wait_ns = */ 0, /* not applicable */ + /* reset_pulse_width_ms = */ 0, /* not applicable */ + /* post_reset_wait_ms = */ 0, /* not applicable */ + /* sda_setup_time_ns = */ 140, + /* sck_pulse_width_ns = */ 250, + /* sck_clock_hz = */ 2000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ + /* spi_mode = */ 2, /* active low, falling edge */ + /* i2c_bus_clock_100kHz = */ 0, /* not applicable */ + /* data_setup_time_ns = */ 0, /* not applicable */ + /* write_pulse_width_ns = */ 0, /* not applicable */ + /* tile_width = */ 8, + /* tile_hight = */ 4, + /* default_x_offset = */ 0, + /* flipmode_x_offset = */ 0, + /* pixel_width = */ 64, + /* pixel_height = */ 32 +}; + + +#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 +#define E3KEYS_AT_EXT_CMD_SET_MODE 0x01 + + +/* + * Set Mode extended command data layout: + * D_7 D_6 D_5 D_4 D_3 D_2 D_1 D_0 + * + * D_7: =1 set Group /=0 only if group matches + * D_6: =1 Display ON /=0 Display OFF + * D_5: =1 Backlite ON /=0 Backlite OFF + * D_4: Reserve + * D_3..0: Group Number + */ + +static const uint8_t u8x8_d_e3keys_sb6432_powersave0_seq[] = { + U8X8_START_TRANSFER(), + U8X8_C(E3KEYS_AT_EXT_CMD_START), + U8X8_C(E3KEYS_AT_EXT_CMD_SET_MODE), + U8X8_D1((1 << 6) | (1 << 5)), + U8X8_C(E3KEYS_AT_CMD_END_TRANSMISSION), + U8X8_DLY(1), /* only 2us required */ + U8X8_END_TRANSFER(), + U8X8_END() +}; + +static const uint8_t u8x8_d_e3keys_sb6432_powersave1_seq[] = { + U8X8_START_TRANSFER(), + U8X8_C(E3KEYS_AT_EXT_CMD_START), + U8X8_C(E3KEYS_AT_EXT_CMD_SET_MODE), + U8X8_D1(0x0), + U8X8_C(E3KEYS_AT_CMD_END_TRANSMISSION), + U8X8_DLY(1), /* only 2us required */ + U8X8_END_TRANSFER(), + U8X8_END() +}; + + +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; + const uint16_t upper_left_addr = d_info->pixel_width * (d_info->pixel_height / 4) - y_addr_offset; + + switch(msg) + { + case U8X8_MSG_DISPLAY_SETUP_MEMORY: + u8x8_d_helper_display_setup_memory(u8x8, &u8x8_e3keys_sb6432_display_info); + break; + case U8X8_MSG_DISPLAY_INIT: + u8x8_d_helper_display_init(u8x8); + break; + case U8X8_MSG_DISPLAY_SET_POWER_SAVE: + if (arg_int) + u8x8_cad_SendSequence(u8x8, u8x8_d_e3keys_sb6432_powersave1_seq); + 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; + + u8x8_cad_StartTransfer(u8x8); + for (int i = 0; i < arg_int; i++) { + for (int c = 0; c < tile->cnt; c++) { + for (int j = 0; j < 8; j++) { + /* Add x position */ + uint16_t addr = upper_left_addr - (tile->x_pos + c + i) * 8 * 8; + /* Add y position */ + if (tile->y_pos < (d_info->tile_height / 2)) /* upper half */ + addr += tile->y_pos * 2; + else /* lower half */ + addr += (tile->y_pos - (d_info->tile_height / 2)) * 2 - y_addr_offset; + /* Add tile offset */ + addr -= j * 8; + + /* + * Set Display Address & Write Display Data command data layout: + * 0 0 0 0 0 0 0 A_8 + * 0 0 0 0 A_7 A_6 A_5 A_4 + * 0 0 0 0 A_3 A_2 A_1 A_0 + * 0 0 0 0 D_3 D_2 D_1 D_0 + */ + uint8_t addr_bytes[3], data_bytes[2]; + addr_bytes[0] = (addr >> 8) & 0x01; + addr_bytes[1] = (addr >> 4) & 0x0f; + addr_bytes[2] = addr & 0x0f; + data_bytes[0] = tile->tile_ptr[c * 8 + j] & 0x0f; + data_bytes[1] = (tile->tile_ptr[c * 8 + j] >> 4) & 0x0f; + + u8x8_cad_SendCmd(u8x8, E3KEYS_AT_CMD_SET_DISPLAY_ADDR_WRITE_DATA); + u8x8_cad_SendData(u8x8, 3, addr_bytes); + u8x8_cad_SendData(u8x8, 2, data_bytes); + }; + }; + }; + u8x8_cad_SendCmd(u8x8, E3KEYS_AT_CMD_END_TRANSMISSION); + u8x8_cad_EndTransfer(u8x8); + break; + default: + return 0; + } + return 1; +} diff --git a/csrc/u8x8_display.c b/csrc/u8x8_display.c index 4f4d4f7ad..9c8602242 100644 --- a/csrc/u8x8_display.c +++ b/csrc/u8x8_display.c @@ -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); @@ -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); } -} \ No newline at end of file +} diff --git a/tools/codebuild/codebuild.c b/tools/codebuild/codebuild.c index caccc1846..a9022d634 100644 --- a/tools/codebuild/codebuild.c +++ b/tools/codebuild/codebuild.c @@ -1463,6 +1463,14 @@ struct controller controller_list[] = { "384x240" }, { NULL } } + }, + { + "e3keys", 8, 4, "u8g2_ll_hvline_vertical_top_lsb", "u8x8_cad_empty", "", COM_4WSPI, + "", /* is_generate_u8g2_class= */ 1, + { + { "sb6432" }, + { NULL } + } } };