From e3347e3cb55e7f66309665556369845b53c0e562 Mon Sep 17 00:00:00 2001 From: chenghongyao <1253146300@qq.com> Date: Sun, 15 Aug 2021 12:52:34 +0800 Subject: [PATCH 01/33] fix data length overflow --- lvgl_tft/st7789.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index 962eb44..3e47a59 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -35,7 +35,7 @@ typedef struct { **********************/ static void st7789_set_orientation(uint8_t orientation); -static void st7789_send_color(void *data, uint16_t length); +static void st7789_send_color(void *data, size_t length); /********************** * STATIC VARIABLES @@ -167,7 +167,7 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo /*Memory write*/ st7789_send_cmd(ST7789_RAMWR); - uint32_t size = lv_area_get_width(area) * lv_area_get_height(area); + size_t size = (size_t)lv_area_get_width(area) * (size_t)lv_area_get_height(area); st7789_send_color((void*)color_map, size * 2); @@ -190,7 +190,7 @@ void st7789_send_data(void * data, uint16_t length) disp_spi_send_data(data, length); } -static void st7789_send_color(void * data, uint16_t length) +static void st7789_send_color(void * data, size_t length) { disp_wait_for_pending_transactions(); gpio_set_level(ST7789_DC, 1); From 7c956f1442d00a08e6683c2c44f9a0c09eeee5d1 Mon Sep 17 00:00:00 2001 From: Kevin Sidwar Date: Fri, 30 Jul 2021 15:29:18 -0600 Subject: [PATCH 02/33] Fix orientation config define --- lvgl_tft/Kconfig | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lvgl_tft/Kconfig b/lvgl_tft/Kconfig index f42351e..61be22a 100644 --- a/lvgl_tft/Kconfig +++ b/lvgl_tft/Kconfig @@ -195,24 +195,24 @@ menu "LVGL TFT Display controller" # Used in display init function to send display orientation commands choice DISPLAY_ORIENTATION prompt "Display orientation" - default DISPLAY_ORIENTATION_PORTRAIT if !LV_TFT_DISPLAY_CONTROLLER_SSD1306 - default DISPLAY_ORIENTATION_LANDSCAPE if LV_TFT_DISPLAY_CONTROLLER_SSD1306 - config DISPLAY_ORIENTATION_PORTRAIT + default LV_DISPLAY_ORIENTATION_PORTRAIT if !LV_TFT_DISPLAY_CONTROLLER_SSD1306 + default LV_DISPLAY_ORIENTATION_LANDSCAPE if LV_TFT_DISPLAY_CONTROLLER_SSD1306 + config LV_DISPLAY_ORIENTATION_PORTRAIT bool "Portrait" if !LV_TFT_DISPLAY_CONTROLLER_SSD1306 - config DISPLAY_ORIENTATION_PORTRAIT_INVERTED + config LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED bool "Portrait inverted" if !LV_TFT_DISPLAY_CONTROLLER_SSD1306 - config DISPLAY_ORIENTATION_LANDSCAPE + config LV_DISPLAY_ORIENTATION_LANDSCAPE bool "Landscape" - config DISPLAY_ORIENTATION_LANDSCAPE_INVERTED + config LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED bool "Landscape inverted" endchoice config LV_DISPLAY_ORIENTATION int - default 0 if DISPLAY_ORIENTATION_PORTRAIT - default 1 if DISPLAY_ORIENTATION_PORTRAIT_INVERTED - default 2 if DISPLAY_ORIENTATION_LANDSCAPE - default 3 if DISPLAY_ORIENTATION_LANDSCAPE_INVERTED + default 0 if LV_DISPLAY_ORIENTATION_PORTRAIT + default 1 if LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED + default 2 if LV_DISPLAY_ORIENTATION_LANDSCAPE + default 3 if LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED config LV_TFT_DISPLAY_OFFSETS bool From 31f340d864183fa046de58acf041467c8967e781 Mon Sep 17 00:00:00 2001 From: Kevin Sidwar Date: Thu, 12 Aug 2021 23:48:23 -0600 Subject: [PATCH 03/33] Change config naming for ssd1306 to use LV_ prefix --- lvgl_tft/Kconfig | 8 ++++---- lvgl_tft/ssd1306.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lvgl_tft/Kconfig b/lvgl_tft/Kconfig index 61be22a..140c173 100644 --- a/lvgl_tft/Kconfig +++ b/lvgl_tft/Kconfig @@ -222,15 +222,15 @@ menu "LVGL TFT Display controller" config LV_TFT_DISPLAY_X_OFFSET depends on LV_TFT_DISPLAY_OFFSETS int "X offset" - default 40 if LV_PREDEFINED_DISPLAY_TTGO && (DISPLAY_ORIENTATION_LANDSCAPE || DISPLAY_ORIENTATION_LANDSCAPE_INVERTED) - default 53 if LV_PREDEFINED_DISPLAY_TTGO && (DISPLAY_ORIENTATION_PORTRAIT || DISPLAY_ORIENTATION_PORTRAIT_INVERTED) + 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 "Y offset" - default 53 if LV_PREDEFINED_DISPLAY_TTGO && (DISPLAY_ORIENTATION_LANDSCAPE || DISPLAY_ORIENTATION_LANDSCAPE_INVERTED) - default 40 if LV_PREDEFINED_DISPLAY_TTGO && (DISPLAY_ORIENTATION_PORTRAIT || DISPLAY_ORIENTATION_PORTRAIT_INVERTED) + 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 diff --git a/lvgl_tft/ssd1306.c b/lvgl_tft/ssd1306.c index d282a7f..1700d02 100644 --- a/lvgl_tft/ssd1306.c +++ b/lvgl_tft/ssd1306.c @@ -99,10 +99,10 @@ void ssd1306_init(void) uint8_t orientation_1 = 0; uint8_t orientation_2 = 0; -#if defined (CONFIG_DISPLAY_ORIENTATION_LANDSCAPE) +#if defined (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE) orientation_1 = OLED_CMD_SET_SEGMENT_REMAP; orientation_2 = OLED_CMD_SET_COM_SCAN_MODE_REMAP; -#elif defined (CONFIG_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED) +#elif defined (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED) orientation_1 = 0xA0; orientation_2 = OLED_CMD_SET_COM_SCAN_MODE_NORMAL; #else From 0b09769dcc45b5bfdb9dde3d92f5755c75f0c1ea Mon Sep 17 00:00:00 2001 From: C47D Date: Mon, 17 May 2021 09:29:32 -0500 Subject: [PATCH 04/33] ST7789: Hardware abstraction layer prototype --- lvgl_tft/st7789.c | 84 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 21 deletions(-) diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index 3e47a59..7fa75f0 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -37,6 +37,13 @@ static void st7789_set_orientation(uint8_t orientation); static void st7789_send_color(void *data, size_t length); +static void st7789_reset(void); +/* The user should init all the hardware related to the display in this + * function, maybe it's better to do this outside the display code, e.g. + * in main before calling anything related to LVGL. + * Some platforms, like STM32CubeIDE init and configure all the hardware + * with auto generated code. */ +static void bsp_init_hardware(void); /********************** * STATIC VARIABLES **********************/ @@ -50,6 +57,8 @@ static void st7789_send_color(void *data, size_t length); **********************/ void st7789_init(void) { + bsp_init_hardware(); + lcd_init_cmd_t st7789_init_cmds[] = { {0xCF, {0x00, 0x83, 0X30}, 3}, {0xED, {0x64, 0x03, 0X12, 0X81}, 4}, @@ -85,24 +94,7 @@ void st7789_init(void) {0, {0}, 0xff}, }; - //Initialize non-SPI GPIOs - gpio_pad_select_gpio(ST7789_DC); - gpio_set_direction(ST7789_DC, GPIO_MODE_OUTPUT); - -#if !defined(ST7789_SOFT_RST) - gpio_pad_select_gpio(ST7789_RST); - gpio_set_direction(ST7789_RST, GPIO_MODE_OUTPUT); -#endif - - //Reset the display -#if !defined(ST7789_SOFT_RST) - gpio_set_level(ST7789_RST, 0); - vTaskDelay(100 / portTICK_RATE_MS); - gpio_set_level(ST7789_RST, 1); - vTaskDelay(100 / portTICK_RATE_MS); -#else - st7789_send_cmd(ST7789_SWRESET); -#endif + st7789_reset(); printf("ST7789 initialization.\n"); @@ -179,24 +171,37 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo void st7789_send_cmd(uint8_t cmd) { disp_wait_for_pending_transactions(); - gpio_set_level(ST7789_DC, 0); + bsp_gpio_dc(0); disp_spi_send_data(&cmd, 1); } void st7789_send_data(void * data, uint16_t length) { disp_wait_for_pending_transactions(); - gpio_set_level(ST7789_DC, 1); + bsp_gpio_dc(1); disp_spi_send_data(data, length); } static void st7789_send_color(void * data, size_t length) { disp_wait_for_pending_transactions(); - gpio_set_level(ST7789_DC, 1); + bsp_gpio_dc(1); disp_spi_send_colors(data, length); } +/* Reset the display, if we don't have a reset pin we use software reset */ +static void st7789_reset(void) +{ +#if !defined(CONFIG_LV_DISP_ST7789_SOFT_RESET) + bsp_gpio_rst(0); + bsp_delay(100); + bsp_gpio_rst(1); + bsp_delay(100); +#else + st7789_send_cmd(ST7789_SWRESET); +#endif +} + static void st7789_set_orientation(uint8_t orientation) { // ESP_ASSERT(orientation < 4); @@ -221,3 +226,40 @@ static void st7789_set_orientation(uint8_t orientation) st7789_send_cmd(ST7789_MADCTL); st7789_send_data((void *) &data[orientation], 1); } + +static void bsp_delay(uint32_t delay_ms) +{ + vTaskDelay(delay_ms / portTICK_RATE_MS); +} + +static void bsp_backlight(uint8_t state) +{ + gpio_set_level(ST7789_BCKL, state); +} + +static void bsp_gpio_dc(uint8_t state) +{ + gpio_set_level(ST7789_DC, state); +} + +static void bsp_gpio_rst(uint8_t state) +{ + gpio_set_level(ST7789_RST, state); +} + +static void bsp_init_hardware(void) +{ + //Initialize non-SPI GPIOs + gpio_pad_select_gpio(ST7789_DC); + gpio_set_direction(ST7789_DC, GPIO_MODE_OUTPUT); + +#if !defined(CONFIG_LV_DISP_ST7789_SOFT_RESET) + gpio_pad_select_gpio(ST7789_RST); + gpio_set_direction(ST7789_RST, GPIO_MODE_OUTPUT); +#endif + +#if ST7789_ENABLE_BACKLIGHT_CONTROL + gpio_pad_select_gpio(ST7789_BCKL); + gpio_set_direction(ST7789_BCKL, GPIO_MODE_OUTPUT); +#endif +} From 49a3ba84b4e94f494ab375135c3802170dc77aeb Mon Sep 17 00:00:00 2001 From: C47D Date: Thu, 29 Jul 2021 18:56:22 -0500 Subject: [PATCH 05/33] display bsp: Move ESP32 pin specific code to display_bsp --- lvgl_tft/display_bsp.c | 33 +++++++++++++++++++++++++++++++++ lvgl_tft/display_bsp.h | 9 +++++++++ 2 files changed, 42 insertions(+) create mode 100644 lvgl_tft/display_bsp.c create mode 100644 lvgl_tft/display_bsp.h diff --git a/lvgl_tft/display_bsp.c b/lvgl_tft/display_bsp.c new file mode 100644 index 0000000..965d64f --- /dev/null +++ b/lvgl_tft/display_bsp.c @@ -0,0 +1,33 @@ +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + +#include "display_bsp.h" + +#include "sdkconfig.h" +#include "driver/gpio.h" + +void display_bsp_delay(uint32_t delay_ms) +{ + vTaskDelay(pdMS_TO_TICKS(delay_ms)); +} + +void display_bsp_backlight(uint8_t state) +{ +#ifdef CONFIG_LV_DISP_PIN_BCKL + gpio_set_level(CONFIG_LV_DISP_PIN_BCKL, state); +#endif +} + +void display_bsp_gpio_dc(uint8_t state) +{ +#ifdef CONFIG_LV_DISPLAY_USE_DC + gpio_set_level(CONFIG_LV_DISP_PIN_DC, state); +#endif +} + +void display_bsp_gpio_rst(uint8_t state) +{ +#ifdef CONFIG_LV_DISP_USE_RST + gpio_set_level(CONFIG_LV_DISP_PIN_RST, state); +#endif +} diff --git a/lvgl_tft/display_bsp.h b/lvgl_tft/display_bsp.h new file mode 100644 index 0000000..3de8795 --- /dev/null +++ b/lvgl_tft/display_bsp.h @@ -0,0 +1,9 @@ +#ifndef DISPLAY_BSP_H_ +#define DISPLAY_BSP_H_ + +void display_bsp_delay(uint32_t delay_ms); +void display_bsp_backlight(uint8_t state); +void display_bsp_gpio_dc(uint8_t state); +void display_bsp_gpio_rst(uint8_t state); + +#endif From 6122d139de3ef280ccad39e9be4c8d7936622197 Mon Sep 17 00:00:00 2001 From: C47D Date: Thu, 29 Jul 2021 19:04:39 -0500 Subject: [PATCH 06/33] display_bsp: Move IO initialization here --- lvgl_tft/display_bsp.c | 18 ++++++++++++++++++ lvgl_tft/display_bsp.h | 1 + 2 files changed, 19 insertions(+) diff --git a/lvgl_tft/display_bsp.c b/lvgl_tft/display_bsp.c index 965d64f..d41d849 100644 --- a/lvgl_tft/display_bsp.c +++ b/lvgl_tft/display_bsp.c @@ -6,6 +6,24 @@ #include "sdkconfig.h" #include "driver/gpio.h" +void display_bsp_init_io(void) +{ +#ifdef CONFIG_LV_DISPLAY_USE_DC + gpio_pad_select_gpio(CONFIG_LV_DISP_PIN_DC); + gpio_set_direction(CONFIG_LV_DISP_PIN_DC, GPIO_MODE_OUTPUT); +#endif + +#ifdef CONFIG_LV_DISP_USE_RST + gpio_pad_select_gpio(CONFIG_LV_DISP_PIN_RST); + gpio_set_direction(CONFIG_LV_DISP_PIN_RST, GPIO_MODE_OUTPUT); +#endif + +#ifdef CONFIG_LV_DISP_PIN_BCKL + gpio_pad_select_gpio(CONFIG_LV_DISP_PIN_BCKL); + gpio_set_direction(CONFIG_LV_DISP_PIN_BCKL, GPIO_MODE_OUTPUT); +#endif +} + void display_bsp_delay(uint32_t delay_ms) { vTaskDelay(pdMS_TO_TICKS(delay_ms)); diff --git a/lvgl_tft/display_bsp.h b/lvgl_tft/display_bsp.h index 3de8795..4bf8f2c 100644 --- a/lvgl_tft/display_bsp.h +++ b/lvgl_tft/display_bsp.h @@ -1,6 +1,7 @@ #ifndef DISPLAY_BSP_H_ #define DISPLAY_BSP_H_ +void display_bsp_init_io(void); void display_bsp_delay(uint32_t delay_ms); void display_bsp_backlight(uint8_t state); void display_bsp_gpio_dc(uint8_t state); From 2629b6d86aa703c614d91c16681230bddcbc17d9 Mon Sep 17 00:00:00 2001 From: C47D Date: Thu, 29 Jul 2021 19:05:17 -0500 Subject: [PATCH 07/33] Update to use display_bsp --- lvgl_tft/st7789.c | 88 ++++++++++++++++------------------------------- 1 file changed, 29 insertions(+), 59 deletions(-) diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index 7fa75f0..3829a8e 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -4,21 +4,19 @@ * Mostly taken from lbthomsen/esp-idf-littlevgl github. */ -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" #include "sdkconfig.h" - #include "esp_log.h" #include "st7789.h" #include "disp_spi.h" -#include "driver/gpio.h" +#include "display_bsp.h" /********************* * DEFINES *********************/ -#define TAG "st7789" +#define TAG "ST7789" + /********************** * TYPEDEFS **********************/ @@ -38,12 +36,6 @@ static void st7789_set_orientation(uint8_t orientation); static void st7789_send_color(void *data, size_t length); static void st7789_reset(void); -/* The user should init all the hardware related to the display in this - * function, maybe it's better to do this outside the display code, e.g. - * in main before calling anything related to LVGL. - * Some platforms, like STM32CubeIDE init and configure all the hardware - * with auto generated code. */ -static void bsp_init_hardware(void); /********************** * STATIC VARIABLES **********************/ @@ -57,7 +49,7 @@ static void bsp_init_hardware(void); **********************/ void st7789_init(void) { - bsp_init_hardware(); + display_bsp_init_io(); lcd_init_cmd_t st7789_init_cmds[] = { {0xCF, {0x00, 0x83, 0X30}, 3}, @@ -96,7 +88,7 @@ void st7789_init(void) st7789_reset(); - printf("ST7789 initialization.\n"); + ESP_LOGI(TAG, "Initialization.\n"); //Send all the commands uint16_t cmd = 0; @@ -104,7 +96,7 @@ void st7789_init(void) st7789_send_cmd(st7789_init_cmds[cmd].cmd); st7789_send_data(st7789_init_cmds[cmd].data, st7789_init_cmds[cmd].databytes&0x1F); if (st7789_init_cmds[cmd].databytes & 0x80) { - vTaskDelay(100 / portTICK_RATE_MS); + display_bsp_delay(100); } cmd++; } @@ -112,6 +104,22 @@ void st7789_init(void) st7789_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION); } +void st7789_enable_backlight(bool backlight) +{ +#if ST7789_ENABLE_BACKLIGHT_CONTROL + ESP_LOGI(TAG, "%s backlight.\n", backlight ? "Enabling" : "Disabling"); + uint32_t tmp = 0; + +#if (ST7789_BCKL_ACTIVE_LVL==1) + tmp = backlight ? 1 : 0; +#else + tmp = backlight ? 0 : 1; +#endif + + display_bsp_backlight(tmp); +#endif +} + /* The ST7789 display controller can drive 320*240 displays, when using a 240*240 * display there's a gap of 80px, we need to edit the coordinates to take into * account that gap, this is not necessary in all orientations. */ @@ -171,21 +179,21 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo void st7789_send_cmd(uint8_t cmd) { disp_wait_for_pending_transactions(); - bsp_gpio_dc(0); + display_bsp_gpio_dc(0); disp_spi_send_data(&cmd, 1); } void st7789_send_data(void * data, uint16_t length) { disp_wait_for_pending_transactions(); - bsp_gpio_dc(1); + display_bsp_gpio_dc(1); disp_spi_send_data(data, length); } static void st7789_send_color(void * data, size_t length) { disp_wait_for_pending_transactions(); - bsp_gpio_dc(1); + display_bsp_gpio_dc(1); disp_spi_send_colors(data, length); } @@ -193,10 +201,10 @@ static void st7789_send_color(void * data, size_t length) static void st7789_reset(void) { #if !defined(CONFIG_LV_DISP_ST7789_SOFT_RESET) - bsp_gpio_rst(0); - bsp_delay(100); - bsp_gpio_rst(1); - bsp_delay(100); + display_bsp_gpio_rst(0); + display_bsp_delay(100); + display_bsp_gpio_rst(1); + display_bsp_delay(100); #else st7789_send_cmd(ST7789_SWRESET); #endif @@ -204,8 +212,6 @@ static void st7789_reset(void) static void st7789_set_orientation(uint8_t orientation) { - // ESP_ASSERT(orientation < 4); - const char *orientation_str[] = { "PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED" }; @@ -227,39 +233,3 @@ static void st7789_set_orientation(uint8_t orientation) st7789_send_data((void *) &data[orientation], 1); } -static void bsp_delay(uint32_t delay_ms) -{ - vTaskDelay(delay_ms / portTICK_RATE_MS); -} - -static void bsp_backlight(uint8_t state) -{ - gpio_set_level(ST7789_BCKL, state); -} - -static void bsp_gpio_dc(uint8_t state) -{ - gpio_set_level(ST7789_DC, state); -} - -static void bsp_gpio_rst(uint8_t state) -{ - gpio_set_level(ST7789_RST, state); -} - -static void bsp_init_hardware(void) -{ - //Initialize non-SPI GPIOs - gpio_pad_select_gpio(ST7789_DC); - gpio_set_direction(ST7789_DC, GPIO_MODE_OUTPUT); - -#if !defined(CONFIG_LV_DISP_ST7789_SOFT_RESET) - gpio_pad_select_gpio(ST7789_RST); - gpio_set_direction(ST7789_RST, GPIO_MODE_OUTPUT); -#endif - -#if ST7789_ENABLE_BACKLIGHT_CONTROL - gpio_pad_select_gpio(ST7789_BCKL); - gpio_set_direction(ST7789_BCKL, GPIO_MODE_OUTPUT); -#endif -} From 7cebfdd671721e286a3f31a44fc572d094e84610 Mon Sep 17 00:00:00 2001 From: C47D Date: Wed, 25 Aug 2021 14:43:24 -0500 Subject: [PATCH 08/33] Rename display_bsp to display_hal The implementation of display hal is MCU dependant, in this example we implement it using the ESP-IDF framework --- lvgl_tft/display_bsp.h | 10 --------- ...{display_bsp.c => display_espressif_hal.c} | 0 lvgl_tft/display_hal.h | 10 +++++++++ lvgl_tft/st7789.c | 22 +++++++++---------- 4 files changed, 21 insertions(+), 21 deletions(-) delete mode 100644 lvgl_tft/display_bsp.h rename lvgl_tft/{display_bsp.c => display_espressif_hal.c} (100%) create mode 100644 lvgl_tft/display_hal.h diff --git a/lvgl_tft/display_bsp.h b/lvgl_tft/display_bsp.h deleted file mode 100644 index 4bf8f2c..0000000 --- a/lvgl_tft/display_bsp.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef DISPLAY_BSP_H_ -#define DISPLAY_BSP_H_ - -void display_bsp_init_io(void); -void display_bsp_delay(uint32_t delay_ms); -void display_bsp_backlight(uint8_t state); -void display_bsp_gpio_dc(uint8_t state); -void display_bsp_gpio_rst(uint8_t state); - -#endif diff --git a/lvgl_tft/display_bsp.c b/lvgl_tft/display_espressif_hal.c similarity index 100% rename from lvgl_tft/display_bsp.c rename to lvgl_tft/display_espressif_hal.c diff --git a/lvgl_tft/display_hal.h b/lvgl_tft/display_hal.h new file mode 100644 index 0000000..fedb203 --- /dev/null +++ b/lvgl_tft/display_hal.h @@ -0,0 +1,10 @@ +#ifndef DISPLAY_HAL_H_ +#define DISPLAY_HAL_H_ + +void display_hal_init_io(void); +void display_hal_delay(uint32_t delay_ms); +void display_hal_backlight(uint8_t state); +void display_hal_gpio_dc(uint8_t state); +void display_hal_gpio_rst(uint8_t state); + +#endif diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index 3829a8e..4483df0 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -10,7 +10,7 @@ #include "st7789.h" #include "disp_spi.h" -#include "display_bsp.h" +#include "display_hal.h" /********************* * DEFINES @@ -49,7 +49,7 @@ static void st7789_reset(void); **********************/ void st7789_init(void) { - display_bsp_init_io(); + display_hal_init_io(); lcd_init_cmd_t st7789_init_cmds[] = { {0xCF, {0x00, 0x83, 0X30}, 3}, @@ -96,7 +96,7 @@ void st7789_init(void) st7789_send_cmd(st7789_init_cmds[cmd].cmd); st7789_send_data(st7789_init_cmds[cmd].data, st7789_init_cmds[cmd].databytes&0x1F); if (st7789_init_cmds[cmd].databytes & 0x80) { - display_bsp_delay(100); + display_hal_delay(100); } cmd++; } @@ -116,7 +116,7 @@ void st7789_enable_backlight(bool backlight) tmp = backlight ? 0 : 1; #endif - display_bsp_backlight(tmp); + display_hal_backlight(tmp); #endif } @@ -179,21 +179,21 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo void st7789_send_cmd(uint8_t cmd) { disp_wait_for_pending_transactions(); - display_bsp_gpio_dc(0); + display_hal_gpio_dc(0); disp_spi_send_data(&cmd, 1); } void st7789_send_data(void * data, uint16_t length) { disp_wait_for_pending_transactions(); - display_bsp_gpio_dc(1); + display_hal_gpio_dc(1); disp_spi_send_data(data, length); } static void st7789_send_color(void * data, size_t length) { disp_wait_for_pending_transactions(); - display_bsp_gpio_dc(1); + display_hal_gpio_dc(1); disp_spi_send_colors(data, length); } @@ -201,10 +201,10 @@ static void st7789_send_color(void * data, size_t length) static void st7789_reset(void) { #if !defined(CONFIG_LV_DISP_ST7789_SOFT_RESET) - display_bsp_gpio_rst(0); - display_bsp_delay(100); - display_bsp_gpio_rst(1); - display_bsp_delay(100); + display_hal_gpio_rst(0); + display_hal_delay(100); + display_hal_gpio_rst(1); + display_hal_delay(100); #else st7789_send_cmd(ST7789_SWRESET); #endif From 413721182c55115e08e121d0d0dd58d2caf026ec Mon Sep 17 00:00:00 2001 From: C47D Date: Wed, 25 Aug 2021 15:16:47 -0500 Subject: [PATCH 09/33] Remove GPIO initialization from display init, they must be initialized by the user in main.c --- lvgl_tft/st7789.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index 4483df0..056ecc2 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -49,8 +49,6 @@ static void st7789_reset(void); **********************/ void st7789_init(void) { - display_hal_init_io(); - lcd_init_cmd_t st7789_init_cmds[] = { {0xCF, {0x00, 0x83, 0X30}, 3}, {0xED, {0x64, 0x03, 0X12, 0X81}, 4}, From 0f1a6d490ed7d11aa17bda8a85661d867b15c408 Mon Sep 17 00:00:00 2001 From: C47D Date: Thu, 26 Aug 2021 10:42:26 -0500 Subject: [PATCH 10/33] Add pointer to lv_disp_drv_t as first parameter to HAL functions --- lvgl_tft/display_espressif_hal.c | 18 +++++--- lvgl_tft/display_hal.h | 28 ++++++++++-- lvgl_tft/st7789.c | 77 ++++++++++++++++---------------- lvgl_tft/st7789.h | 6 +-- 4 files changed, 78 insertions(+), 51 deletions(-) diff --git a/lvgl_tft/display_espressif_hal.c b/lvgl_tft/display_espressif_hal.c index d41d849..f7ec6c1 100644 --- a/lvgl_tft/display_espressif_hal.c +++ b/lvgl_tft/display_espressif_hal.c @@ -1,7 +1,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "display_bsp.h" +#include "display_hal.h" #include "sdkconfig.h" #include "driver/gpio.h" @@ -24,27 +24,35 @@ void display_bsp_init_io(void) #endif } -void display_bsp_delay(uint32_t delay_ms) +void display_bsp_delay(lv_disp_drv_t *drv, uint32_t delay_ms) { + (void) drv; + vTaskDelay(pdMS_TO_TICKS(delay_ms)); } -void display_bsp_backlight(uint8_t state) +void display_bsp_backlight(lv_disp_drv_t *drv, uint8_t state) { + (void) drv; + #ifdef CONFIG_LV_DISP_PIN_BCKL gpio_set_level(CONFIG_LV_DISP_PIN_BCKL, state); #endif } -void display_bsp_gpio_dc(uint8_t state) +void display_bsp_gpio_dc(lv_disp_drv_t *drv, uint8_t state) { + (void) drv; + #ifdef CONFIG_LV_DISPLAY_USE_DC gpio_set_level(CONFIG_LV_DISP_PIN_DC, state); #endif } -void display_bsp_gpio_rst(uint8_t state) +void display_bsp_gpio_rst(lv_disp_drv_t *drv, uint8_t state) { + (void) drv; + #ifdef CONFIG_LV_DISP_USE_RST gpio_set_level(CONFIG_LV_DISP_PIN_RST, state); #endif diff --git a/lvgl_tft/display_hal.h b/lvgl_tft/display_hal.h index fedb203..e7f6041 100644 --- a/lvgl_tft/display_hal.h +++ b/lvgl_tft/display_hal.h @@ -1,10 +1,30 @@ #ifndef DISPLAY_HAL_H_ #define DISPLAY_HAL_H_ +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifdef LV_LVGL_H_INCLUDE_SIMPLE +#include "lvgl.h" +#else +#include "lvgl/lvgl.h" +#endif + +/* NOTE We could remove this function from here, because it's used to + * initialize the GPIOS on the MCU */ void display_hal_init_io(void); -void display_hal_delay(uint32_t delay_ms); -void display_hal_backlight(uint8_t state); -void display_hal_gpio_dc(uint8_t state); -void display_hal_gpio_rst(uint8_t state); + +/* NOTE drv parameter is meant to be used in multi display projects, so the + * user could distinguish multiple displays on their hal implementation */ +void display_hal_delay(lv_disp_drv_t *drv, uint32_t delay_ms); +void display_hal_backlight(lv_disp_drv_t *drv, uint8_t state); +void display_hal_gpio_dc(lv_disp_drv_t *drv, uint8_t state); +void display_hal_gpio_rst(lv_disp_drv_t *drv, uint8_t state); + +#ifdef __cplusplus +} /* extern "C" */ +#endif #endif diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index 056ecc2..fd44baa 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -33,9 +33,11 @@ typedef struct { **********************/ static void st7789_set_orientation(uint8_t orientation); -static void st7789_send_color(void *data, size_t length); +static void st7789_send_cmd(lv_disp_drv_t * drv, uint8_t cmd); +static void st7789_send_data(lv_disp_drv_t * drv, void *data, uint16_t length); +static void st7789_send_color(lv_disp_drv_t * drv, void *data, uint16_t length); -static void st7789_reset(void); +static void st7789_reset(lv_disp_drv_t * drv); /********************** * STATIC VARIABLES **********************/ @@ -47,7 +49,7 @@ static void st7789_reset(void); /********************** * GLOBAL FUNCTIONS **********************/ -void st7789_init(void) +void st7789_init(lv_disp_drv_t *drv) { lcd_init_cmd_t st7789_init_cmds[] = { {0xCF, {0x00, 0x83, 0X30}, 3}, @@ -84,25 +86,27 @@ void st7789_init(void) {0, {0}, 0xff}, }; - st7789_reset(); + st7789_reset(drv); ESP_LOGI(TAG, "Initialization.\n"); //Send all the commands uint16_t cmd = 0; while (st7789_init_cmds[cmd].databytes!=0xff) { - st7789_send_cmd(st7789_init_cmds[cmd].cmd); - st7789_send_data(st7789_init_cmds[cmd].data, st7789_init_cmds[cmd].databytes&0x1F); + st7789_send_cmd(drv, st7789_init_cmds[cmd].cmd); + st7789_send_data(drv, st7789_init_cmds[cmd].data, st7789_init_cmds[cmd].databytes&0x1F); if (st7789_init_cmds[cmd].databytes & 0x80) { - display_hal_delay(100); + display_hal_delay(drv, 100); } cmd++; } - st7789_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION); + st7789_enable_backlight(drv, true); + + st7789_set_orientation(drv, CONFIG_LV_DISPLAY_ORIENTATION); } -void st7789_enable_backlight(bool backlight) +void st7789_enable_backlight(lv_disp_drv_t *drv, bool backlight) { #if ST7789_ENABLE_BACKLIGHT_CONTROL ESP_LOGI(TAG, "%s backlight.\n", backlight ? "Enabling" : "Disabling"); @@ -114,7 +118,7 @@ void st7789_enable_backlight(bool backlight) tmp = backlight ? 0 : 1; #endif - display_hal_backlight(tmp); + display_hal_backlight(drv, tmp); #endif } @@ -129,6 +133,7 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo uint16_t offsetx2 = area->x2; uint16_t offsety1 = area->y1; uint16_t offsety2 = area->y2; + uint32_t size = lv_area_get_width(area) * lv_area_get_height(area); #if (CONFIG_LV_TFT_DISPLAY_OFFSETS) offsetx1 += CONFIG_LV_TFT_DISPLAY_X_OFFSET; @@ -147,68 +152,64 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo #endif /*Column addresses*/ - st7789_send_cmd(ST7789_CASET); + st7789_send_cmd(drv, ST7789_CASET); data[0] = (offsetx1 >> 8) & 0xFF; data[1] = offsetx1 & 0xFF; data[2] = (offsetx2 >> 8) & 0xFF; data[3] = offsetx2 & 0xFF; - st7789_send_data(data, 4); + st7789_send_data(drv, data, 4); /*Page addresses*/ - st7789_send_cmd(ST7789_RASET); + st7789_send_cmd(drv, ST7789_RASET); data[0] = (offsety1 >> 8) & 0xFF; data[1] = offsety1 & 0xFF; data[2] = (offsety2 >> 8) & 0xFF; data[3] = offsety2 & 0xFF; - st7789_send_data(data, 4); + st7789_send_data(drv, data, 4); /*Memory write*/ - st7789_send_cmd(ST7789_RAMWR); - - size_t size = (size_t)lv_area_get_width(area) * (size_t)lv_area_get_height(area); - - st7789_send_color((void*)color_map, size * 2); - + st7789_send_cmd(drv, ST7789_RAMWR); + st7789_send_color(drv, (void*) color_map, size * 2); } /********************** * STATIC FUNCTIONS **********************/ -void st7789_send_cmd(uint8_t cmd) +static void st7789_send_cmd(lv_disp_drv_t *drv, uint8_t cmd) { disp_wait_for_pending_transactions(); - display_hal_gpio_dc(0); - disp_spi_send_data(&cmd, 1); + display_hal_gpio_dc(drv, 0); + disp_spi_send_data(drv, &cmd, 1); } -void st7789_send_data(void * data, uint16_t length) +static void st7789_send_data(lv_disp_drv_t *drv, void * data, uint16_t length) { disp_wait_for_pending_transactions(); - display_hal_gpio_dc(1); - disp_spi_send_data(data, length); + display_hal_gpio_dc(drv, 1); + disp_spi_send_data(drv, data, length); } -static void st7789_send_color(void * data, size_t length) +static void st7789_send_color(lv_disp_drv_t *drv, void * data, uint16_t length) { disp_wait_for_pending_transactions(); - display_hal_gpio_dc(1); - disp_spi_send_colors(data, length); + display_hal_gpio_dc(drv, 1); + disp_spi_send_colors(drv, data, length); } /* Reset the display, if we don't have a reset pin we use software reset */ -static void st7789_reset(void) +static void st7789_reset(lv_disp_drv_t *drv) { #if !defined(CONFIG_LV_DISP_ST7789_SOFT_RESET) - display_hal_gpio_rst(0); - display_hal_delay(100); - display_hal_gpio_rst(1); - display_hal_delay(100); + display_hal_gpio_rst(drv, 0); + display_hal_delay(drv, 100); + display_hal_gpio_rst(drv, 1); + display_hal_delay(drv, 100); #else - st7789_send_cmd(ST7789_SWRESET); + st7789_send_cmd(drv, ST7789_SWRESET); #endif } -static void st7789_set_orientation(uint8_t orientation) +static void st7789_set_orientation(lv_disp_drv_t *drv, uint8_t orientation) { const char *orientation_str[] = { "PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED" @@ -227,7 +228,7 @@ static void st7789_set_orientation(uint8_t orientation) ESP_LOGI(TAG, "0x36 command value: 0x%02X", data[orientation]); - st7789_send_cmd(ST7789_MADCTL); - st7789_send_data((void *) &data[orientation], 1); + st7789_send_cmd(drv, ST7789_MADCTL); + st7789_send_data(drv, (void *) &data[orientation], 1); } diff --git a/lvgl_tft/st7789.h b/lvgl_tft/st7789.h index cacb31b..49411e8 100644 --- a/lvgl_tft/st7789.h +++ b/lvgl_tft/st7789.h @@ -110,11 +110,9 @@ extern "C" #define ST7789_NVMSET 0xFC // NVM setting #define ST7789_PROMACT 0xFE // Program action -void st7789_init(void); +void st7789_init(lv_disp_drv_t *drv); void st7789_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map); - -void st7789_send_cmd(uint8_t cmd); -void st7789_send_data(void *data, uint16_t length); +void st7789_enable_backlight(lv_disp_drv_t *drv, bool backlight); #ifdef __cplusplus } /* extern "C" */ From 37da744873a8fc940488db962c00708308d0950b Mon Sep 17 00:00:00 2001 From: C47D Date: Thu, 26 Aug 2021 18:50:26 -0500 Subject: [PATCH 11/33] cmake: Add initial display hal implementation for espressif MCUs to the build --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bd2b3b5..701a787 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,9 @@ file(GLOB SOURCES *.c) set(LVGL_INCLUDE_DIRS . lvgl_tft) list(APPEND SOURCES "lvgl_tft/disp_driver.c") list(APPEND SOURCES "lvgl_tft/esp_lcd_backlight.c") +list(APPEND SOURCES "lvgl_tft/display_espressif_hal.c") + +#@todo add SimleInclude macro here # Build all display drivers list(APPEND SOURCES "lvgl_tft/ili9341.c") From 0ae3f76097a4ca8cb3d203722165a74487808326 Mon Sep 17 00:00:00 2001 From: C47D Date: Thu, 26 Aug 2021 18:51:35 -0500 Subject: [PATCH 12/33] hal: Fix typo on function signatures --- lvgl_tft/display_espressif_hal.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/lvgl_tft/display_espressif_hal.c b/lvgl_tft/display_espressif_hal.c index f7ec6c1..a5888f3 100644 --- a/lvgl_tft/display_espressif_hal.c +++ b/lvgl_tft/display_espressif_hal.c @@ -6,32 +6,14 @@ #include "sdkconfig.h" #include "driver/gpio.h" -void display_bsp_init_io(void) -{ -#ifdef CONFIG_LV_DISPLAY_USE_DC - gpio_pad_select_gpio(CONFIG_LV_DISP_PIN_DC); - gpio_set_direction(CONFIG_LV_DISP_PIN_DC, GPIO_MODE_OUTPUT); -#endif - -#ifdef CONFIG_LV_DISP_USE_RST - gpio_pad_select_gpio(CONFIG_LV_DISP_PIN_RST); - gpio_set_direction(CONFIG_LV_DISP_PIN_RST, GPIO_MODE_OUTPUT); -#endif - -#ifdef CONFIG_LV_DISP_PIN_BCKL - gpio_pad_select_gpio(CONFIG_LV_DISP_PIN_BCKL); - gpio_set_direction(CONFIG_LV_DISP_PIN_BCKL, GPIO_MODE_OUTPUT); -#endif -} - -void display_bsp_delay(lv_disp_drv_t *drv, uint32_t delay_ms) +void display_hal_delay(lv_disp_drv_t *drv, uint32_t delay_ms) { (void) drv; vTaskDelay(pdMS_TO_TICKS(delay_ms)); } -void display_bsp_backlight(lv_disp_drv_t *drv, uint8_t state) +void display_hal_backlight(lv_disp_drv_t *drv, uint8_t state) { (void) drv; @@ -40,7 +22,7 @@ void display_bsp_backlight(lv_disp_drv_t *drv, uint8_t state) #endif } -void display_bsp_gpio_dc(lv_disp_drv_t *drv, uint8_t state) +void display_hal_gpio_dc(lv_disp_drv_t *drv, uint8_t state) { (void) drv; @@ -49,7 +31,7 @@ void display_bsp_gpio_dc(lv_disp_drv_t *drv, uint8_t state) #endif } -void display_bsp_gpio_rst(lv_disp_drv_t *drv, uint8_t state) +void display_hal_gpio_rst(lv_disp_drv_t *drv, uint8_t state) { (void) drv; From 0c6975954f5e043061060e2ca41c5cd382ada01a Mon Sep 17 00:00:00 2001 From: C47D Date: Thu, 26 Aug 2021 18:53:13 -0500 Subject: [PATCH 13/33] helpers: Remove display initialization from lvgl_driver_init --- lvgl_helpers.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lvgl_helpers.c b/lvgl_helpers.c index edc522f..c8a76b6 100644 --- a/lvgl_helpers.c +++ b/lvgl_helpers.c @@ -105,7 +105,6 @@ void lvgl_driver_init(void) DISP_SPI_IO2, DISP_SPI_IO3); disp_spi_add_device(TFT_SPI_HOST); - disp_driver_init(); #elif defined (CONFIG_LV_I2C_DISPLAY) disp_driver_init(); From e314c7563bd77eae089cad182113c5afef339056 Mon Sep 17 00:00:00 2001 From: C47D Date: Thu, 26 Aug 2021 18:54:15 -0500 Subject: [PATCH 14/33] disp_driver: Add pointer to lv_disp_drv_t as parameter to disp_driver_init --- lvgl_tft/disp_driver.c | 4 ++-- lvgl_tft/disp_driver.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lvgl_tft/disp_driver.c b/lvgl_tft/disp_driver.c index f62a947..c0b7c8d 100644 --- a/lvgl_tft/disp_driver.c +++ b/lvgl_tft/disp_driver.c @@ -7,7 +7,7 @@ #include "esp_lcd_backlight.h" #include "sdkconfig.h" -void *disp_driver_init(void) +void disp_driver_init(lv_disp_drv_t *drv) { #if defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341 ili9341_init(); @@ -16,7 +16,7 @@ void *disp_driver_init(void) #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488 ili9488_init(); #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7789 - st7789_init(); + st7789_init(drv); #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7796S st7796s_init(); #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7735S diff --git a/lvgl_tft/disp_driver.h b/lvgl_tft/disp_driver.h index 8c70fda..f4929bf 100644 --- a/lvgl_tft/disp_driver.h +++ b/lvgl_tft/disp_driver.h @@ -67,7 +67,7 @@ extern "C" { **********************/ /* Initialize display */ -void *disp_driver_init(void); +void disp_driver_init(lv_disp_drv_t *drv); /* Display flush callback */ void disp_driver_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map); From 64832c41363bc73978c71ff035f18fc90b1d14e3 Mon Sep 17 00:00:00 2001 From: C47D Date: Thu, 26 Aug 2021 18:58:36 -0500 Subject: [PATCH 15/33] fix(st7789): Remove extra parameter on disp_spi_send_colors and disp_spi_send_data --- lvgl_tft/st7789.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index fd44baa..e81844f 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -31,7 +31,7 @@ typedef struct { /********************** * STATIC PROTOTYPES **********************/ -static void st7789_set_orientation(uint8_t orientation); +static void st7789_set_orientation(lv_disp_drv_t *drv, uint8_t orientation); static void st7789_send_cmd(lv_disp_drv_t * drv, uint8_t cmd); static void st7789_send_data(lv_disp_drv_t * drv, void *data, uint16_t length); @@ -179,21 +179,21 @@ static void st7789_send_cmd(lv_disp_drv_t *drv, uint8_t cmd) { disp_wait_for_pending_transactions(); display_hal_gpio_dc(drv, 0); - disp_spi_send_data(drv, &cmd, 1); + disp_spi_send_data(&cmd, 1); } static void st7789_send_data(lv_disp_drv_t *drv, void * data, uint16_t length) { disp_wait_for_pending_transactions(); display_hal_gpio_dc(drv, 1); - disp_spi_send_data(drv, data, length); + disp_spi_send_data(data, length); } static void st7789_send_color(lv_disp_drv_t *drv, void * data, uint16_t length) { disp_wait_for_pending_transactions(); display_hal_gpio_dc(drv, 1); - disp_spi_send_colors(drv, data, length); + disp_spi_send_colors(data, length); } /* Reset the display, if we don't have a reset pin we use software reset */ From aa8a78f72a0813decee40db70abddf6912eabc6b Mon Sep 17 00:00:00 2001 From: C47D Date: Tue, 7 Sep 2021 00:11:21 -0500 Subject: [PATCH 16/33] helpers: Remove display initialization when using SPI --- lvgl_helpers.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lvgl_helpers.c b/lvgl_helpers.c index c8a76b6..538b085 100644 --- a/lvgl_helpers.c +++ b/lvgl_helpers.c @@ -105,7 +105,6 @@ void lvgl_driver_init(void) DISP_SPI_IO2, DISP_SPI_IO3); disp_spi_add_device(TFT_SPI_HOST); - disp_driver_init(); #elif defined (CONFIG_LV_I2C_DISPLAY) disp_driver_init(); #else From c7975623219773b9cbedb6241c73b588b75d0f3b Mon Sep 17 00:00:00 2001 From: C47D Date: Tue, 7 Sep 2021 19:12:53 -0500 Subject: [PATCH 17/33] port; Move display_espressif_hal to new lv_port directory --- CMakeLists.txt | 6 +++++- {lvgl_tft => lv_port}/display_espressif_hal.c | 0 2 files changed, 5 insertions(+), 1 deletion(-) rename {lvgl_tft => lv_port}/display_espressif_hal.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 701a787..b0010ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,11 @@ file(GLOB SOURCES *.c) set(LVGL_INCLUDE_DIRS . lvgl_tft) list(APPEND SOURCES "lvgl_tft/disp_driver.c") list(APPEND SOURCES "lvgl_tft/esp_lcd_backlight.c") -list(APPEND SOURCES "lvgl_tft/display_espressif_hal.c") + +# This are the source files used for mcu abstraction +set(LV_PORT_PATH "lv_port") + +list(APPEND SOURCES "${LV_PORT_PATH}/display_espressif_hal.c") #@todo add SimleInclude macro here diff --git a/lvgl_tft/display_espressif_hal.c b/lv_port/display_espressif_hal.c similarity index 100% rename from lvgl_tft/display_espressif_hal.c rename to lv_port/display_espressif_hal.c From f6307afabc910bd6462a8a9db08dbab39cfa5e88 Mon Sep 17 00:00:00 2001 From: C47D Date: Tue, 7 Sep 2021 19:30:31 -0500 Subject: [PATCH 18/33] Rename display_espressif_hal.c to lv_port_display_espressif.c --- CMakeLists.txt | 2 +- .../{display_espressif_hal.c => lv_port_display_espressif.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename lv_port/{display_espressif_hal.c => lv_port_display_espressif.c} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b0010ba..d6a67f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ list(APPEND SOURCES "lvgl_tft/esp_lcd_backlight.c") # This are the source files used for mcu abstraction set(LV_PORT_PATH "lv_port") -list(APPEND SOURCES "${LV_PORT_PATH}/display_espressif_hal.c") +list(APPEND SOURCES "${LV_PORT_PATH}/lv_port_display_espressif.c") #@todo add SimleInclude macro here diff --git a/lv_port/display_espressif_hal.c b/lv_port/lv_port_display_espressif.c similarity index 100% rename from lv_port/display_espressif_hal.c rename to lv_port/lv_port_display_espressif.c From 83c08f6a2af65ddb2248239a643f8f1e682479a1 Mon Sep 17 00:00:00 2001 From: C47D Date: Tue, 7 Sep 2021 19:44:01 -0500 Subject: [PATCH 19/33] st7789: Remove unused symbols Removed `ST7789_DC` and `ST7789_RST` symbols as they are no longer used. --- lvgl_tft/st7789.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/lvgl_tft/st7789.h b/lvgl_tft/st7789.h index 49411e8..8c29765 100644 --- a/lvgl_tft/st7789.h +++ b/lvgl_tft/st7789.h @@ -21,9 +21,6 @@ extern "C" #include "sdkconfig.h" -#define ST7789_DC CONFIG_LV_DISP_PIN_DC -#define ST7789_RST CONFIG_LV_DISP_PIN_RST - #if CONFIG_LV_DISP_USE_RST #if CONFIG_LV_DISP_ST7789_SOFT_RESET #define ST7789_SOFT_RST From dfe54e8573c71ab23395df33b959a5d4973fb7d8 Mon Sep 17 00:00:00 2001 From: C47D Date: Wed, 8 Sep 2021 22:59:52 -0500 Subject: [PATCH 20/33] ST7789: Add template for update_cb We might use this callback to be able to rotate the display at runtime using the displa controller configuration bytes --- lvgl_tft/st7789.c | 5 +++++ lvgl_tft/st7789.h | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index e81844f..c85107b 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -232,3 +232,8 @@ static void st7789_set_orientation(lv_disp_drv_t *drv, uint8_t orientation) st7789_send_data(drv, (void *) &data[orientation], 1); } +/* Display update callback, we could update the orientation in here */ +void st7789_update_cb(lv_disp_drv_t *drv) +{ + (void) drv; +} diff --git a/lvgl_tft/st7789.h b/lvgl_tft/st7789.h index 8c29765..e09f6a7 100644 --- a/lvgl_tft/st7789.h +++ b/lvgl_tft/st7789.h @@ -107,10 +107,37 @@ extern "C" #define ST7789_NVMSET 0xFC // NVM setting #define ST7789_PROMACT 0xFE // Program action +/** + * Initialize the ST7789 display controller with default configuration + * + * @param drv Pointer to lv_disp_drv_t being used + */ void st7789_init(lv_disp_drv_t *drv); + +/** + * Send buffer content to display + * + * @param drv Pointer to lv_disp_drv_t being used + * @param area Pointer to area to be sent + * @param color_map Pointer to color map + */ void st7789_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map); + +/** + * Control display backlight + * + * @param drv Pointer to lv_disp_drv_t being used + * @param backlight Backlight control + */ void st7789_enable_backlight(lv_disp_drv_t *drv, bool backlight); +/** + * Display updated callback + * + * @param drv Pointer to lv_disp_drv_t being used + */ +void st7789_update_cb(lv_disp_drv_t *drv) + #ifdef __cplusplus } /* extern "C" */ #endif From d79b68bdf6ceb1c85ad2638f6cb819118901f9dd Mon Sep 17 00:00:00 2001 From: C47D Date: Wed, 8 Sep 2021 23:01:01 -0500 Subject: [PATCH 21/33] ST7789: Cleanup Remove logging and unneccesary includes --- lvgl_tft/st7789.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index c85107b..36fb81d 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -4,9 +4,6 @@ * Mostly taken from lbthomsen/esp-idf-littlevgl github. */ -#include "sdkconfig.h" -#include "esp_log.h" - #include "st7789.h" #include "disp_spi.h" @@ -88,8 +85,6 @@ void st7789_init(lv_disp_drv_t *drv) st7789_reset(drv); - ESP_LOGI(TAG, "Initialization.\n"); - //Send all the commands uint16_t cmd = 0; while (st7789_init_cmds[cmd].databytes!=0xff) { @@ -103,13 +98,13 @@ void st7789_init(lv_disp_drv_t *drv) st7789_enable_backlight(drv, true); - st7789_set_orientation(drv, CONFIG_LV_DISPLAY_ORIENTATION); + /* FIXME We're setting up the initial orientation in the cmd array */ + st7789_set_orientation(drv, ST7789_INITIAL_ORIENTATION); } void st7789_enable_backlight(lv_disp_drv_t *drv, bool backlight) { #if ST7789_ENABLE_BACKLIGHT_CONTROL - ESP_LOGI(TAG, "%s backlight.\n", backlight ? "Enabling" : "Disabling"); uint32_t tmp = 0; #if (ST7789_BCKL_ACTIVE_LVL==1) @@ -211,12 +206,6 @@ static void st7789_reset(lv_disp_drv_t *drv) static void st7789_set_orientation(lv_disp_drv_t *drv, uint8_t orientation) { - const char *orientation_str[] = { - "PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED" - }; - - ESP_LOGI(TAG, "Display orientation: %s", orientation_str[orientation]); - uint8_t data[] = { #if CONFIG_LV_PREDEFINED_DISPLAY_TTGO @@ -226,8 +215,6 @@ static void st7789_set_orientation(lv_disp_drv_t *drv, uint8_t orientation) #endif }; - ESP_LOGI(TAG, "0x36 command value: 0x%02X", data[orientation]); - st7789_send_cmd(drv, ST7789_MADCTL); st7789_send_data(drv, (void *) &data[orientation], 1); } From 2a3157b8fcb6cf14c8a6b74f26a14a1ba297cabd Mon Sep 17 00:00:00 2001 From: C47D Date: Wed, 8 Sep 2021 23:02:47 -0500 Subject: [PATCH 22/33] ST7789: Move configuration to display_config.h --- display_config.h | 29 +++++++++++++++++++++++++++++ lvgl_tft/st7789.h | 16 ++++------------ 2 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 display_config.h diff --git a/display_config.h b/display_config.h new file mode 100644 index 0000000..37e6387 --- /dev/null +++ b/display_config.h @@ -0,0 +1,29 @@ +#ifndef DISPLAY_CONFIG_H_ +#define DISPLAY_CONFIG_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "sdkconfig.h" + +/* Configuration options for ST7789 display controllers */ +#if CONFIG_LV_DISP_USE_RST + #if CONFIG_LV_DISP_ST7789_SOFT_RESET + #define ST7789_SOFT_RST + #endif +#else + #define ST7789_SOFT_RST +#endif + +#if defined (CONFIG_LV_INVERT_COLORS) +#define ST7789_INVERT_COLORS 1U +#endif + +#define ST7789_INITIAL_ORIENTATION CONFIG_LV_DISPLAY_ORIENTATION + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* DISPLAY_CONFIG_H_ */ diff --git a/lvgl_tft/st7789.h b/lvgl_tft/st7789.h index e09f6a7..d48da96 100644 --- a/lvgl_tft/st7789.h +++ b/lvgl_tft/st7789.h @@ -17,19 +17,11 @@ extern "C" #else #include "lvgl/lvgl.h" #endif -#include "../lvgl_helpers.h" -#include "sdkconfig.h" - -#if CONFIG_LV_DISP_USE_RST - #if CONFIG_LV_DISP_ST7789_SOFT_RESET - #define ST7789_SOFT_RST - #endif -#else - #define ST7789_SOFT_RST -#endif - -#define ST7789_INVERT_COLORS CONFIG_LV_INVERT_COLORS +/* For SPI transfers */ +#include "lvgl_helpers.h" +/* For ST7789 particular configurations */ +#include "display_config.h" /* ST7789 commands */ #define ST7789_NOP 0x00 From b6e1f91ed1346d690a23d77afaeb4d2baa2ab85f Mon Sep 17 00:00:00 2001 From: C47D Date: Wed, 8 Sep 2021 23:08:18 -0500 Subject: [PATCH 23/33] ST7789: Use new configuration option for software reset --- lvgl_tft/st7789.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index 36fb81d..4f0d229 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -194,7 +194,7 @@ static void st7789_send_color(lv_disp_drv_t *drv, void * data, uint16_t length) /* Reset the display, if we don't have a reset pin we use software reset */ static void st7789_reset(lv_disp_drv_t *drv) { -#if !defined(CONFIG_LV_DISP_ST7789_SOFT_RESET) +#if !defined(ST7789_SOFT_RST) display_hal_gpio_rst(drv, 0); display_hal_delay(drv, 100); display_hal_gpio_rst(drv, 1); From 2134cdcfb566f5f323499e72f53f48415c81860d Mon Sep 17 00:00:00 2001 From: C47D Date: Thu, 9 Sep 2021 18:08:58 -0500 Subject: [PATCH 24/33] fix(st7789.h): Add missing ; to st7789_update_cb --- lvgl_tft/st7789.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lvgl_tft/st7789.h b/lvgl_tft/st7789.h index d48da96..86576e4 100644 --- a/lvgl_tft/st7789.h +++ b/lvgl_tft/st7789.h @@ -128,7 +128,7 @@ void st7789_enable_backlight(lv_disp_drv_t *drv, bool backlight); * * @param drv Pointer to lv_disp_drv_t being used */ -void st7789_update_cb(lv_disp_drv_t *drv) +void st7789_update_cb(lv_disp_drv_t *drv); #ifdef __cplusplus } /* extern "C" */ From 9b1e3d1198b98d2fad613c6c442aa3df45a12dcc Mon Sep 17 00:00:00 2001 From: C47D Date: Thu, 9 Sep 2021 18:10:10 -0500 Subject: [PATCH 25/33] fix(disp_driver): Update disp_driver_init API signature The signature was changed when I was rebasing master into this branch, this commit fixes it :) --- lvgl_tft/disp_driver.c | 2 +- lvgl_tft/disp_driver.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lvgl_tft/disp_driver.c b/lvgl_tft/disp_driver.c index c0b7c8d..634ee93 100644 --- a/lvgl_tft/disp_driver.c +++ b/lvgl_tft/disp_driver.c @@ -7,7 +7,7 @@ #include "esp_lcd_backlight.h" #include "sdkconfig.h" -void disp_driver_init(lv_disp_drv_t *drv) +void *disp_driver_init(lv_disp_drv_t *drv) { #if defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341 ili9341_init(); diff --git a/lvgl_tft/disp_driver.h b/lvgl_tft/disp_driver.h index f4929bf..8636153 100644 --- a/lvgl_tft/disp_driver.h +++ b/lvgl_tft/disp_driver.h @@ -67,7 +67,7 @@ extern "C" { **********************/ /* Initialize display */ -void disp_driver_init(lv_disp_drv_t *drv); +void *disp_driver_init(lv_disp_drv_t *drv); /* Display flush callback */ void disp_driver_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map); From ffae578a39a01e30350547e3b21f5f88adbe37a9 Mon Sep 17 00:00:00 2001 From: C47D Date: Thu, 9 Sep 2021 19:36:32 -0500 Subject: [PATCH 26/33] chore(st7789.h): Add note to st7789_update_cb --- lvgl_tft/st7789.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index 4f0d229..4b3b718 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -219,7 +219,8 @@ static void st7789_set_orientation(lv_disp_drv_t *drv, uint8_t orientation) st7789_send_data(drv, (void *) &data[orientation], 1); } -/* Display update callback, we could update the orientation in here */ +/* Display update callback, we could update the orientation in here + * NOTE Available only for LVGL v8 */ void st7789_update_cb(lv_disp_drv_t *drv) { (void) drv; From 0e29128b3b30f2ea16d060385e2b758c34cca043 Mon Sep 17 00:00:00 2001 From: C47D Date: Thu, 9 Sep 2021 22:47:47 -0500 Subject: [PATCH 27/33] feat(st7789.c): Initial support for display rotation control using LVGL --- lvgl_tft/st7789.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index 4b3b718..e990c06 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -122,6 +122,22 @@ void st7789_enable_backlight(lv_disp_drv_t *drv, bool backlight) * account that gap, this is not necessary in all orientations. */ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map) { + static lv_disp_rot_t prev_rotation = LV_DISP_ROT_NONE; + + lv_disp_t *display = (lv_disp_t *) drv; + lv_disp_rot_t rotation = lv_disp_get_rotation(display); + + if (rotation != prev_rotation) { + /* Update rotation */ + + /* TODO Handle all other rotations */ + if (LV_DISP_ROT_180 == rotation) { + st7789_set_orientation(drv, 1); + } + + prev_rotation = rotation; + } + uint8_t data[4] = {0}; uint16_t offsetx1 = area->x1; @@ -138,8 +154,13 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo #elif (LV_HOR_RES_MAX == 240) && (LV_VER_RES_MAX == 240) #if (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT) - offsetx1 += 80; - offsetx2 += 80; + if (LV_DISP_ROT_NONE == rotation) { + offsetx1 += 80; + offsetx2 += 80; + } + else { + + } #elif (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED) offsety1 += 80; offsety2 += 80; From 20438187b14e96a1f53bab3faa60dc946d2d73fb Mon Sep 17 00:00:00 2001 From: C47D Date: Sat, 11 Sep 2021 13:51:21 -0500 Subject: [PATCH 28/33] Revert "feat(st7789.c): Initial support for display rotation control using LVGL" This reverts commit 704f9a2c7f65dac47ba9b1a69aaf4d8dfe5c53ee. --- lvgl_tft/st7789.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index e990c06..4b3b718 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -122,22 +122,6 @@ void st7789_enable_backlight(lv_disp_drv_t *drv, bool backlight) * account that gap, this is not necessary in all orientations. */ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map) { - static lv_disp_rot_t prev_rotation = LV_DISP_ROT_NONE; - - lv_disp_t *display = (lv_disp_t *) drv; - lv_disp_rot_t rotation = lv_disp_get_rotation(display); - - if (rotation != prev_rotation) { - /* Update rotation */ - - /* TODO Handle all other rotations */ - if (LV_DISP_ROT_180 == rotation) { - st7789_set_orientation(drv, 1); - } - - prev_rotation = rotation; - } - uint8_t data[4] = {0}; uint16_t offsetx1 = area->x1; @@ -154,13 +138,8 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo #elif (LV_HOR_RES_MAX == 240) && (LV_VER_RES_MAX == 240) #if (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT) - if (LV_DISP_ROT_NONE == rotation) { - offsetx1 += 80; - offsetx2 += 80; - } - else { - - } + offsetx1 += 80; + offsetx2 += 80; #elif (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED) offsety1 += 80; offsety2 += 80; From 359dcb92bad08c2d38ffd4673ad8b0866fde07f6 Mon Sep 17 00:00:00 2001 From: C47D Date: Sat, 11 Sep 2021 13:56:32 -0500 Subject: [PATCH 29/33] feat(st7789.c): Add delay after sending software reset command --- lvgl_tft/st7789.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index 4b3b718..30ef730 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -201,6 +201,7 @@ static void st7789_reset(lv_disp_drv_t *drv) display_hal_delay(drv, 100); #else st7789_send_cmd(drv, ST7789_SWRESET); + display_hal_delay(drv, 5); #endif } From 9d9fadf45015e58721d5065eaeb06f3afbc02c95 Mon Sep 17 00:00:00 2001 From: C47D Date: Sat, 11 Sep 2021 14:21:08 -0500 Subject: [PATCH 30/33] fix(display_port): Rename display_hal_* to display_port_* Also updates the display drivers that used it --- lv_port/lv_port_display_espressif.c | 10 +++--- lvgl_tft/display_hal.h | 30 ----------------- lvgl_tft/display_port.h | 51 +++++++++++++++++++++++++++++ lvgl_tft/st7789.c | 22 ++++++------- 4 files changed, 67 insertions(+), 46 deletions(-) delete mode 100644 lvgl_tft/display_hal.h create mode 100644 lvgl_tft/display_port.h diff --git a/lv_port/lv_port_display_espressif.c b/lv_port/lv_port_display_espressif.c index a5888f3..9f6f4b1 100644 --- a/lv_port/lv_port_display_espressif.c +++ b/lv_port/lv_port_display_espressif.c @@ -1,19 +1,19 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "display_hal.h" +#include "display_port.h" #include "sdkconfig.h" #include "driver/gpio.h" -void display_hal_delay(lv_disp_drv_t *drv, uint32_t delay_ms) +void display_port_delay(lv_disp_drv_t *drv, uint32_t delay_ms) { (void) drv; vTaskDelay(pdMS_TO_TICKS(delay_ms)); } -void display_hal_backlight(lv_disp_drv_t *drv, uint8_t state) +void display_port_backlight(lv_disp_drv_t *drv, uint8_t state) { (void) drv; @@ -22,7 +22,7 @@ void display_hal_backlight(lv_disp_drv_t *drv, uint8_t state) #endif } -void display_hal_gpio_dc(lv_disp_drv_t *drv, uint8_t state) +void display_port_gpio_dc(lv_disp_drv_t *drv, uint8_t state) { (void) drv; @@ -31,7 +31,7 @@ void display_hal_gpio_dc(lv_disp_drv_t *drv, uint8_t state) #endif } -void display_hal_gpio_rst(lv_disp_drv_t *drv, uint8_t state) +void display_port_gpio_rst(lv_disp_drv_t *drv, uint8_t state) { (void) drv; diff --git a/lvgl_tft/display_hal.h b/lvgl_tft/display_hal.h deleted file mode 100644 index e7f6041..0000000 --- a/lvgl_tft/display_hal.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef DISPLAY_HAL_H_ -#define DISPLAY_HAL_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" -#else -#include "lvgl/lvgl.h" -#endif - -/* NOTE We could remove this function from here, because it's used to - * initialize the GPIOS on the MCU */ -void display_hal_init_io(void); - -/* NOTE drv parameter is meant to be used in multi display projects, so the - * user could distinguish multiple displays on their hal implementation */ -void display_hal_delay(lv_disp_drv_t *drv, uint32_t delay_ms); -void display_hal_backlight(lv_disp_drv_t *drv, uint8_t state); -void display_hal_gpio_dc(lv_disp_drv_t *drv, uint8_t state); -void display_hal_gpio_rst(lv_disp_drv_t *drv, uint8_t state); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/lvgl_tft/display_port.h b/lvgl_tft/display_port.h new file mode 100644 index 0000000..2136ec6 --- /dev/null +++ b/lvgl_tft/display_port.h @@ -0,0 +1,51 @@ +#ifndef DISPLAY_PORT_H_ +#define DISPLAY_PORT_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifdef LV_LVGL_H_INCLUDE_SIMPLE +#include "lvgl.h" +#else +#include "lvgl/lvgl.h" +#endif + +/** + * Busy wait delay port + * + * @param drv Pointer to driver See @ref lv_disp_drv_t + * @param delay_ms Delay duration in milliseconds + */ +void display_port_delay(lv_disp_drv_t *drv, uint32_t delay_ms); + +/** + * Backlight control port + * + * @param drv Pointer to driver See @ref lv_disp_drv_t + * @param state State of the backlight signal + */ +void display_port_backlight(lv_disp_drv_t *drv, uint8_t state); + +/** + * DC signal control port + * + * @param drv Pointer to driver See @ref lv_disp_drv_t + * @param state State of the DC signal, 1 for logic high, 0 for logic low + */ +void display_port_gpio_dc(lv_disp_drv_t *drv, uint8_t state); + +/** + * Hardware reset control port + * + * @param drv Pointer to driver See @ref lv_disp_drv_t + * @param state State of the reset signal, 1 for logic high, 0 for logic low + */ +void display_port_gpio_rst(lv_disp_drv_t *drv, uint8_t state); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index 30ef730..690e44c 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -7,7 +7,7 @@ #include "st7789.h" #include "disp_spi.h" -#include "display_hal.h" +#include "display_port.h" /********************* * DEFINES @@ -91,7 +91,7 @@ void st7789_init(lv_disp_drv_t *drv) st7789_send_cmd(drv, st7789_init_cmds[cmd].cmd); st7789_send_data(drv, st7789_init_cmds[cmd].data, st7789_init_cmds[cmd].databytes&0x1F); if (st7789_init_cmds[cmd].databytes & 0x80) { - display_hal_delay(drv, 100); + display_port_delay(drv, 100); } cmd++; } @@ -113,7 +113,7 @@ void st7789_enable_backlight(lv_disp_drv_t *drv, bool backlight) tmp = backlight ? 0 : 1; #endif - display_hal_backlight(drv, tmp); + display_port_backlight(drv, tmp); #endif } @@ -173,21 +173,21 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo static void st7789_send_cmd(lv_disp_drv_t *drv, uint8_t cmd) { disp_wait_for_pending_transactions(); - display_hal_gpio_dc(drv, 0); + display_port_gpio_dc(drv, 0); disp_spi_send_data(&cmd, 1); } static void st7789_send_data(lv_disp_drv_t *drv, void * data, uint16_t length) { disp_wait_for_pending_transactions(); - display_hal_gpio_dc(drv, 1); + display_port_gpio_dc(drv, 1); disp_spi_send_data(data, length); } static void st7789_send_color(lv_disp_drv_t *drv, void * data, uint16_t length) { disp_wait_for_pending_transactions(); - display_hal_gpio_dc(drv, 1); + display_port_gpio_dc(drv, 1); disp_spi_send_colors(data, length); } @@ -195,13 +195,13 @@ static void st7789_send_color(lv_disp_drv_t *drv, void * data, uint16_t length) static void st7789_reset(lv_disp_drv_t *drv) { #if !defined(ST7789_SOFT_RST) - display_hal_gpio_rst(drv, 0); - display_hal_delay(drv, 100); - display_hal_gpio_rst(drv, 1); - display_hal_delay(drv, 100); + display_port_gpio_rst(drv, 0); + display_port_delay(drv, 100); + display_port_gpio_rst(drv, 1); + display_port_delay(drv, 100); #else st7789_send_cmd(drv, ST7789_SWRESET); - display_hal_delay(drv, 5); + display_port_delay(drv, 5); #endif } From 3980e51f074e5477531cc42b1aa199a2f04bb439 Mon Sep 17 00:00:00 2001 From: C47D Date: Sat, 11 Sep 2021 14:27:14 -0500 Subject: [PATCH 31/33] fix(st7789): Remove backlight control from driver Use backlight control introduced in #95 --- lvgl_tft/st7789.c | 17 ----------------- lvgl_tft/st7789.h | 8 -------- 2 files changed, 25 deletions(-) diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index 690e44c..1aa1b75 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -96,27 +96,10 @@ void st7789_init(lv_disp_drv_t *drv) cmd++; } - st7789_enable_backlight(drv, true); - /* FIXME We're setting up the initial orientation in the cmd array */ st7789_set_orientation(drv, ST7789_INITIAL_ORIENTATION); } -void st7789_enable_backlight(lv_disp_drv_t *drv, bool backlight) -{ -#if ST7789_ENABLE_BACKLIGHT_CONTROL - uint32_t tmp = 0; - -#if (ST7789_BCKL_ACTIVE_LVL==1) - tmp = backlight ? 1 : 0; -#else - tmp = backlight ? 0 : 1; -#endif - - display_port_backlight(drv, tmp); -#endif -} - /* The ST7789 display controller can drive 320*240 displays, when using a 240*240 * display there's a gap of 80px, we need to edit the coordinates to take into * account that gap, this is not necessary in all orientations. */ diff --git a/lvgl_tft/st7789.h b/lvgl_tft/st7789.h index 86576e4..be86c21 100644 --- a/lvgl_tft/st7789.h +++ b/lvgl_tft/st7789.h @@ -115,14 +115,6 @@ void st7789_init(lv_disp_drv_t *drv); */ void st7789_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map); -/** - * Control display backlight - * - * @param drv Pointer to lv_disp_drv_t being used - * @param backlight Backlight control - */ -void st7789_enable_backlight(lv_disp_drv_t *drv, bool backlight); - /** * Display updated callback * From 85f70cb688bd3b6cb9da904b9f4c9943637c7a59 Mon Sep 17 00:00:00 2001 From: C47D Date: Sat, 11 Sep 2021 14:46:02 -0500 Subject: [PATCH 32/33] feat(disp_driver): Move backlight configuration to it's own API --- lvgl_tft/disp_driver.c | 5 +++++ lvgl_tft/disp_driver.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/lvgl_tft/disp_driver.c b/lvgl_tft/disp_driver.c index 634ee93..95569a8 100644 --- a/lvgl_tft/disp_driver.c +++ b/lvgl_tft/disp_driver.c @@ -45,6 +45,11 @@ void *disp_driver_init(lv_disp_drv_t *drv) ili9163c_init(); #endif + return disp_backlight_init(); +} + +void *disp_backlight_init(void) +{ // We still use menuconfig for these settings // It will be set up during runtime in the future #if (defined(CONFIG_LV_DISP_BACKLIGHT_SWITCH) || defined(CONFIG_LV_DISP_BACKLIGHT_PWM)) diff --git a/lvgl_tft/disp_driver.h b/lvgl_tft/disp_driver.h index 8636153..a4a282b 100644 --- a/lvgl_tft/disp_driver.h +++ b/lvgl_tft/disp_driver.h @@ -79,6 +79,8 @@ void disp_driver_rounder(lv_disp_drv_t * disp_drv, lv_area_t * area); void disp_driver_set_px(lv_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); +/* Display backlight configuration */ +void *disp_backlight_init(void); /********************** * MACROS **********************/ From cd999e34cd209b014c612a1dac50fe15356a99dc Mon Sep 17 00:00:00 2001 From: C47D Date: Tue, 14 Sep 2021 18:06:36 -0500 Subject: [PATCH 33/33] fix(lvgl_helpers): Remove all references to disp_driver_init in lvgl_driver_init --- lvgl_helpers.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/lvgl_helpers.c b/lvgl_helpers.c index 538b085..02f4017 100644 --- a/lvgl_helpers.c +++ b/lvgl_helpers.c @@ -69,7 +69,6 @@ void lvgl_driver_init(void) DISP_SPI_IO2, DISP_SPI_IO3); disp_spi_add_device(TFT_SPI_HOST); - disp_driver_init(); #if defined (CONFIG_LV_TOUCH_CONTROLLER_FT81X) touch_driver_init(); @@ -89,7 +88,6 @@ void lvgl_driver_init(void) disp_spi_add_device(TFT_SPI_HOST); tp_spi_add_device(TOUCH_SPI_HOST); - disp_driver_init(); touch_driver_init(); return; @@ -106,7 +104,6 @@ void lvgl_driver_init(void) disp_spi_add_device(TFT_SPI_HOST); #elif defined (CONFIG_LV_I2C_DISPLAY) - disp_driver_init(); #else #error "No protocol defined for display controller" #endif