Merge pull request #3 from tore-espressif/feature/color-inversion

Feature/color inversion
This commit is contained in:
Tomas Rezucha 2021-02-12 12:07:07 +01:00 committed by GitHub
commit b58a41ebc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 92 additions and 55 deletions

29
.editorconfig Normal file
View file

@ -0,0 +1,29 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[{*.md,*.rst}]
trim_trailing_whitespace = false
[{Makefile,*.mk,*.bat}]
indent_style = tab
indent_size = 2
[{*.cmake,CMakeLists.txt}]
indent_style = space
indent_size = 4
max_line_length = 120
[{*.sh,*.yml}]
indent_style = space
indent_size = 2

View file

@ -109,7 +109,7 @@ menu "LVGL TFT Display controller"
bool
help
ST7789 display controller.
config LV_TFT_DISPLAY_CONTROLLER_GC9A01
bool
help
@ -211,14 +211,14 @@ menu "LVGL TFT Display controller"
config LV_TFT_DISPLAY_X_OFFSET
depends on LV_TFT_DISPLAY_OFFSETS
int
int
default 40 if LV_PREDEFINED_DISPLAY_TTGO && (LV_DISPLAY_ORIENTATION_LANDSCAPE || LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED)
default 53 if LV_PREDEFINED_DISPLAY_TTGO && (LV_DISPLAY_ORIENTATION_PORTRAIT || LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED)
default 0
config LV_TFT_DISPLAY_Y_OFFSET
depends on LV_TFT_DISPLAY_OFFSETS
int
int
default 53 if LV_PREDEFINED_DISPLAY_TTGO && (LV_DISPLAY_ORIENTATION_LANDSCAPE || LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED)
default 40 if LV_PREDEFINED_DISPLAY_TTGO && (LV_DISPLAY_ORIENTATION_PORTRAIT || LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED)
default 0
@ -284,7 +284,7 @@ menu "LVGL TFT Display controller"
config LV_TFT_DISPLAY_USER_CONTROLLER_GC9A01
bool "GC9A01"
select LV_TFT_DISPLAY_CONTROLLER_GC9A01
select LV_TFT_DISPLAY_PROTOCOL_SPI
select LV_TFT_DISPLAY_PROTOCOL_SPI
config LV_TFT_DISPLAY_USER_CONTROLLER_ST7735S
bool "ST7735S"
select LV_TFT_DISPLAY_CONTROLLER_ST7735S
@ -441,7 +441,7 @@ menu "LVGL TFT Display controller"
config LV_FT81X_CONFIG_EVE_SUNFLOWER
bool "EVE_SUNFLOWER"
config LV_FT81X_CONFIG_EVE_CONNECTEVE
bool "EVE_CONNECTEVE"
bool "EVE_CONNECTEVE"
endchoice
choice
@ -579,16 +579,17 @@ menu "LVGL TFT Display controller"
default 2
config LV_INVERT_DISPLAY
bool "IN DEPRECATION - Invert display."
default y if LV_PREDEFINED_DISPLAY_M5STACK
bool "IN DEPRECATION - Invert display." if LV_TFT_DISPLAY_CONTROLLER_RA8875
default n
help
If text is backwards on your display, try enabling this.
config LV_INVERT_COLORS
bool "Invert colors in display" if LV_TFT_DISPLAY_CONTROLLER_ILI9341 || LV_TFT_DISPLAY_CONTROLLER_ST7735S || LV_TFT_DISPLAY_CONTROLLER_ILI9481
bool "Invert colors in display" if LV_TFT_DISPLAY_CONTROLLER_ILI9341 || LV_TFT_DISPLAY_CONTROLLER_ST7735S || LV_TFT_DISPLAY_CONTROLLER_ILI9481 || LV_TFT_DISPLAY_CONTROLLER_ST7789 || LV_TFT_DISPLAY_CONTROLLER_SSD1306 || LV_TFT_DISPLAY_CONTROLLER_SH1107 || LV_TFT_DISPLAY_CONTROLLER_HX8357
default y if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICKC
help
If the colors look inverted on your display, try enabling this.
If it didn't help try LVGL configuration -> Swap the 2 bytes of RGB565 color.
config LV_M5STICKC_HANDLE_AXP192
bool "Handle Backlight and TFT power for M5StickC using AXP192." if LV_PREDEFINED_DISPLAY_M5STICKC || LV_TFT_DISPLAY_CONTROLLER_ST7735S
@ -769,7 +770,7 @@ menu "LVGL TFT Display controller"
depends on LV_DISPLAY_USE_SPI_MISO
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
default 19 if LV_PREDEFINED_PINS_TKOALA
default 0
@ -790,7 +791,7 @@ menu "LVGL TFT Display controller"
depends on LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
range -1 39 if IDF_TARGET_ESP32
range -1 43 if IDF_TARGET_ESP32S2
default 22 if LV_PREDEFINED_PINS_TKOALA && LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
default -1
help
@ -801,7 +802,7 @@ menu "LVGL TFT Display controller"
depends on LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
range -1 39 if IDF_TARGET_ESP32
range -1 43 if IDF_TARGET_ESP32S2
default 21 if LV_PREDEFINED_PINS_TKOALA && LV_TFT_DISPLAY_SPI_TRANS_MODE_QIO
default -1
help
@ -811,7 +812,7 @@ menu "LVGL TFT Display controller"
int "GPIO for CLK (SCK / Serial Clock)" if LV_TFT_DISPLAY_PROTOCOL_SPI
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
default 18 if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICK
default 13 if LV_PREDEFINED_DISPLAY_M5STICKC
default 18 if LV_PREDEFINED_DISPLAY_ATAG
@ -838,7 +839,7 @@ menu "LVGL TFT Display controller"
depends on LV_DISPLAY_USE_SPI_CS
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
default 5 if LV_PREDEFINED_PINS_38V1
default 14 if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICK
default 5 if LV_PREDEFINED_DISPLAY_M5STICKC
@ -865,7 +866,7 @@ menu "LVGL TFT Display controller"
int "GPIO for DC (Data / Command)" if LV_TFT_DISPLAY_PROTOCOL_SPI
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
depends on LV_DISPLAY_USE_DC
default 19 if LV_PREDEFINED_PINS_38V1
default 17 if LV_PREDEFINED_PINS_38V4
@ -887,7 +888,7 @@ menu "LVGL TFT Display controller"
int "GPIO for Reset" if LV_TFT_DISPLAY_PROTOCOL_SPI
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
default 18 if LV_PREDEFINED_PINS_38V1
default 25 if LV_PREDEFINED_PINS_38V4
default 33 if LV_PREDEFINED_DISPLAY_M5STACK || LV_PREDEFINED_DISPLAY_M5STICK
@ -908,7 +909,7 @@ menu "LVGL TFT Display controller"
int "GPIO for Busy" if LV_TFT_DISPLAY_CONTROLLER_IL3820 || LV_TFT_DISPLAY_CONTROLLER_JD79653A || LV_TFT_DISPLAY_CONTROLLER_UC8151D
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
default 35 if LV_TFT_DISPLAY_CONTROLLER_IL3820 || LV_TFT_DISPLAY_CONTROLLER_JD79653A || LV_TFT_DISPLAY_CONTROLLER_UC8151D
default 35
@ -946,7 +947,7 @@ menu "LVGL TFT Display controller"
depends on LV_ENABLE_BACKLIGHT_CONTROL
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
default 23 if LV_PREDEFINED_PINS_38V1
default 26 if LV_PREDEFINED_PINS_38V4
default 32 if LV_PREDEFINED_DISPLAY_M5STACK
@ -966,7 +967,7 @@ menu "LVGL TFT Display controller"
int "GPIO for I2C SDA" if LV_TFT_DISPLAY_PROTOCOL_I2C
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
default 5 if LV_PREDEFINED_DISPLAY_WEMOS_LOLIN
default 5
@ -977,7 +978,7 @@ menu "LVGL TFT Display controller"
int "GPIO for I2C SCL" if LV_TFT_DISPLAY_PROTOCOL_I2C
range 0 39 if IDF_TARGET_ESP32
range 0 43 if IDF_TARGET_ESP32S2
default 4 if LV_PREDEFINED_DISPLAY_WEMOS_LOLIN
default 4

View file

@ -7,7 +7,7 @@
* Adafruit 3.5" TFT 320x480 + Touchscreen Breakout
* http://www.adafruit.com/products/2050
*
* Adafruit TFT FeatherWing - 3.5" 480x320 Touchscreen for Feathers
* Adafruit TFT FeatherWing - 3.5" 480x320 Touchscreen for Feathers
* https://www.adafruit.com/product/3651
*
*/
@ -177,7 +177,7 @@ void hx8357_init(void)
vTaskDelay(120 / portTICK_RATE_MS);
ESP_LOGI(TAG, "Initialization.");
//Send all the commands
const uint8_t *addr = (displayType == HX8357B) ? initb : initd;
uint8_t cmd, x, numArgs;
@ -199,9 +199,11 @@ void hx8357_init(void)
}
hx8357_set_rotation(1);
#if HX8357_INVERT_DISPLAY
hx8357_send_cmd(HX8357_INVON);;
#if HX8357_INVERT_COLORS
hx8357_send_cmd(HX8357_INVON);
#else
hx8357_send_cmd(HX8357_INVOFF);
#endif
hx8357_enable_backlight(true);
@ -211,7 +213,7 @@ void hx8357_init(void)
void hx8357_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map)
{
uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);
/* Column addresses */
uint8_t xb[] = {
(uint8_t) (area->x1 >> 8) & 0xFF,
@ -219,7 +221,7 @@ void hx8357_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
(uint8_t) (area->x2 >> 8) & 0xFF,
(uint8_t) (area->x2) & 0xFF,
};
/* Page addresses */
uint8_t yb[] = {
(uint8_t) (area->y1 >> 8) & 0xFF,
@ -261,7 +263,7 @@ void hx8357_enable_backlight(bool backlight)
void hx8357_set_rotation(uint8_t r)
{
r = r & 3; // can't be higher than 3
switch(r) {
case 0:
r = MADCTL_MX | MADCTL_MY | MADCTL_RGB;
@ -276,7 +278,7 @@ void hx8357_set_rotation(uint8_t r)
r = MADCTL_MX | MADCTL_MV | MADCTL_RGB;
break;
}
hx8357_send_cmd(HX8357_MADCTL);
hx8357_send_data(&r, 1);
}

View file

@ -7,7 +7,7 @@
* Adafruit 3.5" TFT 320x480 + Touchscreen Breakout
* http://www.adafruit.com/products/2050
*
* Adafruit TFT FeatherWing - 3.5" 480x320 Touchscreen for Feathers
* Adafruit TFT FeatherWing - 3.5" 480x320 Touchscreen for Feathers
* https://www.adafruit.com/product/3651
*
*/
@ -40,6 +40,7 @@ extern "C" {
#define HX8357_BCKL CONFIG_LV_DISP_PIN_BCKL
#define HX8357_ENABLE_BACKLIGHT_CONTROL CONFIG_LV_ENABLE_BACKLIGHT_CONTROL
#define HX8357_INVERT_COLORS CONFIG_LV_INVERT_COLORS
#if CONFIG_LV_BACKLIGHT_ACTIVE_LVL
#define HX8357_BCKL_ACTIVE_LVL 1
@ -47,9 +48,6 @@ extern "C" {
#define HX8357_BCKL_ACTIVE_LVL 0
#endif
// if text/images are backwards, try setting this to 1
#define HX8357_INVERT_DISPLAY CONFIG_LV_INVERT_DISPLAY
/*******************
* HX8357B/D REGS

View file

@ -62,8 +62,8 @@ void sh1107_init(void)
{0x81, {0}, 0}, // Set display contrast
{0x2F, {0}, 0}, // ...value
{0x20, {0}, 0}, // Set memory mode
{0xA0, {0}, 0}, // Non-rotated display
#if defined CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE
{0xA0, {0}, 0}, // Non-rotated display
#if defined CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE
{0xC8, {0}, 0}, // flipped vertical
#elif defined CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT
{0xC7, {0}, 0}, // flipped vertical
@ -82,11 +82,11 @@ void sh1107_init(void)
{0xDA, {0}, 0}, // Set com pins
{0x12, {0}, 0}, // ...value
{0xA4, {0}, 0}, // output ram to display
#if defined CONFIG_LV_INVERT_DISPLAY
#if defined CONFIG_LV_INVERT_COLORS
{0xA7, {0}, 0}, // inverted display
#else
{0xA6, {0}, 0}, // Non-inverted display
#endif
#endif
{0xAF, {0}, 0}, // Turn display on
{0, {0}, 0xff},
};
@ -116,14 +116,14 @@ void sh1107_init(void)
}
void sh1107_set_px_cb(struct _disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
lv_color_t color, lv_opa_t opa)
lv_color_t color, lv_opa_t opa)
{
/* buf_w will be ignored, the configured CONFIG_LV_DISPLAY_HEIGHT and _WIDTH,
and CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE and _PORTRAIT will be used. */
and CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE and _PORTRAIT will be used. */
uint16_t byte_index = 0;
uint8_t bit_index = 0;
#if defined CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE
#if defined CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE
byte_index = y + (( x>>3 ) * LV_VER_RES_MAX);
bit_index = x & 0x7;
#elif defined CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT
@ -146,10 +146,10 @@ void sh1107_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
uint32_t size = 0;
void *ptr;
#if defined CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE
#if defined CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE
row1 = area->x1>>3;
row2 = area->x2>>3;
#else
#else
row1 = area->y1>>3;
row2 = area->y2>>3;
#endif
@ -158,9 +158,9 @@ void sh1107_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
sh1107_send_cmd(0x00 | columnLow); // Set Lower Column Start Address for Page Addressing Mode
sh1107_send_cmd(0xB0 | i); // Set Page Start Address for Page Addressing Mode
size = area->y2 - area->y1 + 1;
#if defined CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE
#if defined CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE
ptr = color_map + i * LV_VER_RES_MAX;
#else
#else
ptr = color_map + i * LV_HOR_RES_MAX;
#endif
if(i != row2){

View file

@ -3,10 +3,10 @@
*
* Code from https://github.com/yanbe/ssd1306-esp-idf-i2c.git is used as a starting point,
* in addition to code from https://github.com/espressif/esp-iot-solution.
*
*
* Definitions are borrowed from:
* http://robotcantalk.blogspot.com/2015/03/interfacing-arduino-with-ssd1306-driven.html
*
*
* For LVGL the forum has been used, in particular: https://blog.littlevgl.com/2019-05-06/oled
*/
@ -113,7 +113,7 @@ void ssd1306_init(void)
uint8_t display_mode = 0;
#if defined CONFIG_LV_INVERT_DISPLAY
#if defined CONFIG_LV_INVERT_COLORS
display_mode = OLED_CMD_DISPLAY_INVERTED;
#else
display_mode = OLED_CMD_DISPLAY_NORMAL;
@ -130,7 +130,7 @@ void ssd1306_init(void)
0xFF,
OLED_CMD_DISPLAY_ON
};
uint8_t err = send_data(NULL, conf, sizeof(conf));
assert(0 == err);
}
@ -213,7 +213,7 @@ static uint8_t send_data(lv_disp_drv_t *disp_drv, void *bytes, size_t bytes_len)
uint8_t *data = (uint8_t *) bytes;
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (OLED_I2C_ADDRESS << 1) | I2C_MASTER_WRITE, true);
@ -222,7 +222,7 @@ static uint8_t send_data(lv_disp_drv_t *disp_drv, void *bytes, size_t bytes_len)
}
i2c_master_stop(cmd);
/* Send queued commands */
err = i2c_master_cmd_begin(DISP_I2C_PORT, cmd, 10 / portTICK_PERIOD_MS);
i2c_cmd_link_delete(cmd);
@ -234,7 +234,7 @@ static uint8_t send_pixels(lv_disp_drv_t *disp_drv, void *color_buffer, size_t b
{
(void) disp_drv;
esp_err_t err;
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (OLED_I2C_ADDRESS << 1) | I2C_MASTER_WRITE, true);
@ -242,7 +242,7 @@ static uint8_t send_pixels(lv_disp_drv_t *disp_drv, void *color_buffer, size_t b
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_DATA_STREAM, true);
i2c_master_write(cmd, (uint8_t *) color_buffer, buffer_len, true);
i2c_master_stop(cmd);
/* Send queued commands */
err = i2c_master_cmd_begin(DISP_I2C_PORT, cmd, 10 / portTICK_PERIOD_MS);
i2c_cmd_link_delete(cmd);

View file

@ -65,7 +65,13 @@ void st7789_init(void)
{ST7789_CABCCTRL, {0xBE}, 1},
{ST7789_MADCTL, {0x00}, 1}, // Set to 0x28 if your display is flipped
{ST7789_COLMOD, {0x55}, 1},
{ST7789_INVON, {0}, 0},
#if ST7789_INVERT_COLORS == 1
{ST7789_INVON, {0}, 0}, // set inverted mode
#else
{ST7789_INVOFF, {0}, 0}, // set non-inverted mode
#endif
{ST7789_RGBCTRL, {0x00, 0x1B}, 2},
{0xF2, {0x08}, 1},
{ST7789_GAMSET, {0x01}, 1},
@ -86,7 +92,7 @@ void st7789_init(void)
gpio_set_direction(ST7789_DC, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(ST7789_RST);
gpio_set_direction(ST7789_RST, GPIO_MODE_OUTPUT);
#if ST7789_ENABLE_BACKLIGHT_CONTROL
gpio_pad_select_gpio(ST7789_BCKL);
gpio_set_direction(ST7789_BCKL, GPIO_MODE_OUTPUT);
@ -219,7 +225,7 @@ static void st7789_set_orientation(uint8_t orientation)
ESP_LOGI(TAG, "Display orientation: %s", orientation_str[orientation]);
uint8_t data[] =
uint8_t data[] =
{
#if CONFIG_LV_PREDEFINED_DISPLAY_TTGO
0x60, 0xA0, 0x00, 0xC0
@ -227,7 +233,7 @@ static void st7789_set_orientation(uint8_t orientation)
0xC0, 0x00, 0x60, 0xA0
#endif
};
ESP_LOGI(TAG, "0x36 command value: 0x%02X", data[orientation]);
st7789_send_cmd(ST7789_MADCTL);

View file

@ -26,6 +26,7 @@ extern "C"
#define ST7789_BCKL CONFIG_LV_DISP_PIN_BCKL
#define ST7789_ENABLE_BACKLIGHT_CONTROL CONFIG_LV_ENABLE_BACKLIGHT_CONTROL
#define ST7789_INVERT_COLORS CONFIG_LV_INVERT_COLORS
#if CONFIG_LV_BACKLIGHT_ACTIVE_LVL
#define ST7789_BCKL_ACTIVE_LVL 1