From ed2860239f80eb8ac0ba0fb8aeb00820f3589269 Mon Sep 17 00:00:00 2001 From: Bassam Date: Sun, 7 Aug 2022 00:31:06 +0300 Subject: [PATCH 1/8] added the implementation of CST816 touch sensor --- CMakeLists.txt | 4 +- lvgl_helpers.h | 6 ++ lvgl_touch/CST816.c | 132 ++++++++++++++++++++++++++++++++++++++ lvgl_touch/CST816.h | 64 ++++++++++++++++++ lvgl_touch/Kconfig | 36 +++++++++++ lvgl_touch/touch_driver.c | 4 ++ lvgl_touch/touch_driver.h | 2 + 7 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 lvgl_touch/CST816.c create mode 100644 lvgl_touch/CST816.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 407802a..724553f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,8 @@ if(CONFIG_LV_TOUCH_CONTROLLER) list(APPEND SOURCES "lvgl_touch/ra8875_touch.c") elseif(CONFIG_LV_TOUCH_CONTROLLER_GT911) list(APPEND SOURCES "lvgl_touch/gt911.c") + elseif(CONFIG_LV_TOUCH_CONTROLLER_CST816) + list(APPEND SOURCES "lvgl_touch/CST816.c") endif() if(CONFIG_LV_TOUCH_DRIVER_PROTOCOL_SPI) @@ -86,7 +88,7 @@ endif() idf_component_register(SRCS ${SOURCES} INCLUDE_DIRS ${LVGL_INCLUDE_DIRS} - REQUIRES lvgl) + REQUIRES lvgl band_audio_hal) target_compile_definitions(${COMPONENT_LIB} PUBLIC "-DLV_LVGL_H_INCLUDE_SIMPLE") diff --git a/lvgl_helpers.h b/lvgl_helpers.h index c010174..99e35f8 100644 --- a/lvgl_helpers.h +++ b/lvgl_helpers.h @@ -34,6 +34,12 @@ extern "C" { * color format being used, for RGB565 each pixel needs 2 bytes. * When using the mono theme, the display pixels can be represented in one bit, * so the buffer size can be divided by 8, e.g. see SSD1306 display size. */ + +//[BJ] Source: https://github.com/lvgl/lvgl_esp32_drivers/issues/202 +# define LV_HOR_RES_MAX 320 +# define LV_VER_RES_MAX 240 +# define SPI_HOST_MAX 3 + #if defined (CONFIG_CUSTOM_DISPLAY_BUFFER_SIZE) #define DISP_BUF_SIZE CONFIG_CUSTOM_DISPLAY_BUFFER_BYTES #else diff --git a/lvgl_touch/CST816.c b/lvgl_touch/CST816.c new file mode 100644 index 0000000..dd4fc7f --- /dev/null +++ b/lvgl_touch/CST816.c @@ -0,0 +1,132 @@ +/* +* Copyright © 2022 Band Industries Inc. + +* Permission is hereby granted, free of charge, to any person obtaining a copy of this +* software and associated documentation files (the “Software”), to deal in the Software +* without restriction, including without limitation the rights to use, copy, modify, merge, +* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +* to whom the Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include +#ifdef LV_LVGL_H_INCLUDE_SIMPLE +#include +#else +#include +#endif +#include "CST816.h" + +#include "lvgl_i2c/i2c_manager.h" +#include "band_es8388.h" + +#define TAG "CST816" + +cst816_status_t cst816_status; + +//[BJ] TODO: Below functions are ADF specific, if I am to contribute to main repo this needs to be resolved! +static esp_err_t _cst816_i2c_read(uint8_t slave_addr, uint8_t register_addr, uint8_t *data_buf, uint8_t len) { + return band_i2c_read(slave_addr, register_addr, data_buf, len); + //return lvgl_i2c_read(CONFIG_LV_I2C_TOUCH_PORT, slave_addr, register_addr | I2C_REG_16, data_buf, len); +} + +static esp_err_t _cst816_i2c_write8(uint8_t slave_addr, uint8_t register_addr, uint8_t data) { + //uint8_t buffer = data; + return band_i2c_write(slave_addr, register_addr, &data, 1); + //return lvgl_i2c_write(CONFIG_LV_I2C_TOUCH_PORT, slave_addr, register_addr | I2C_REG_16, &buffer, 1); +} + +/** + * @brief Initialize for cst816 communication via I2C + * @param dev_addr: Device address on communication Bus (I2C slave address of cst816). + * @retval None + */ +void cst816_init(uint8_t dev_addr) { + if (!cst816_status.inited) + { + cst816_status.i2c_dev_addr = dev_addr; + uint8_t version; + uint8_t versionInfo[3]; + esp_err_t ret; + ESP_LOGI(TAG, "Initializing cst816 %d", dev_addr); + if ((ret = _cst816_i2c_read(dev_addr, 0x15, &version, 1) != ESP_OK)) + { + ESP_LOGE(TAG, "Error reading version from device: %s", + esp_err_to_name(ret)); // Only show error the first time + return; + } + if ((ret = _cst816_i2c_read(dev_addr, 0xA7, versionInfo, 3) != ESP_OK)) + { + ESP_LOGE(TAG, "Error reading versionInfo from device: %s", + esp_err_to_name(ret)); // Only show error the first time + return; + } + ESP_LOGI(TAG, "CST816 version %d, versionInfo: %d.%d.%d", version, versionInfo[0], versionInfo[1], versionInfo[2]); + cst816_status.inited = true; + } +} + +/** + * @brief Get the touch screen X and Y positions values. Ignores multi touch + * @param drv: + * @param data: Store data here + * @retval Always false + */ +#define SWAPXY 1 +#define INVERTX 1 +#define INVERTY 0 + + + +bool cst816_read(lv_indev_drv_t *drv, lv_indev_data_t *data) { + + uint8_t data_raw[8]; + _cst816_i2c_read(cst816_status.i2c_dev_addr, 0x01, data_raw, 6); + + + + uint8_t gestureID = data_raw[0]; + uint8_t points = data_raw[1]; + uint8_t event = data_raw[2] >> 6; + uint16_t point_x = 0; + uint16_t point_y = 0; + if(points == 0) + { + data->state = LV_INDEV_STATE_RELEASED; + return false; + + } + + data->state = LV_INDEV_STATE_PRESSED; + point_x = (data_raw[3] | ((data_raw[2] & 0x0F) << 8)); + point_y = (data_raw[5] | ((data_raw[4] & 0x0F) << 8)); + +#if CONFIG_LV_SWAPXY_CST816 + int temp; + temp = point_y; + point_y = point_x; + point_x = temp; +#endif + +#if CONFIG_LV_INVERT_X_CST816 + point_x = CONFIG_LV_TOUCH_X_MAX_CST816 - point_x; +#endif + +#if CONFIG_LV_INVERT_Y_CST816 + point_y = CONFIG_LV_TOUCH_Y_MAX_CST816 - point_y; +#endif + + data->point.x = point_x; + data->point.y = point_y; + ESP_LOGI(TAG, "gestureID %d, points %d, event %d X=%u Y=%u", gestureID, points, event, data->point.x, data->point.y); + return false; +} diff --git a/lvgl_touch/CST816.h b/lvgl_touch/CST816.h new file mode 100644 index 0000000..c8085b5 --- /dev/null +++ b/lvgl_touch/CST816.h @@ -0,0 +1,64 @@ +#ifndef __CST816_H +/* +* Copyright © 2022 Band Industries Inc. + +* Permission is hereby granted, free of charge, to any person obtaining a copy of this +* software and associated documentation files (the “Software”), to deal in the Software +* without restriction, including without limitation the rights to use, copy, modify, merge, +* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +* to whom the Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#define __CST816_H + +#include +#include +#ifdef LV_LVGL_H_INCLUDE_SIMPLE +#include "lvgl.h" +#else +#include "lvgl/lvgl.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#define CST816_I2C_SLAVE_ADDR 0x15<<1 + +#define CST816_PRODUCT_ID_LEN 4 + + +typedef struct { + bool inited; + uint8_t i2c_dev_addr; +} cst816_status_t; + +/** + * @brief Initialize for cst816 communication via I2C + * @param dev_addr: Device address on communication Bus (I2C slave address of CST816). + * @retval None + */ +void cst816_init(uint8_t dev_addr); + +/** + * @brief Get the touch screen X and Y positions values. Ignores multi touch + * @param drv: + * @param data: Store data here + * @retval Always false + */ +bool cst816_read(lv_indev_drv_t *drv, lv_indev_data_t *data); + +#ifdef __cplusplus +} +#endif +#endif /* __CST816_H */ diff --git a/lvgl_touch/Kconfig b/lvgl_touch/Kconfig index b793adb..dfa0ab9 100644 --- a/lvgl_touch/Kconfig +++ b/lvgl_touch/Kconfig @@ -10,6 +10,7 @@ menu "LVGL Touch controller" default 5 if LV_TOUCH_CONTROLLER_FT81X default 6 if LV_TOUCH_CONTROLLER_RA8875 default 7 if LV_TOUCH_CONTROLLER_GT911 + default 8 if LV_TOUCH_CONTROLLER_CST816 choice prompt "Select a touch panel controller model." @@ -40,6 +41,9 @@ menu "LVGL Touch controller" config LV_TOUCH_CONTROLLER_GT911 select LV_I2C_TOUCH bool "GT911" + config LV_TOUCH_CONTROLLER_CST816 + select LV_I2C_TOUCH + bool "CST816" endchoice config LV_TOUCH_DRIVER_PROTOCOL_SPI @@ -441,6 +445,38 @@ menu "LVGL Touch controller" endmenu + menu "Touchpanel Configuration (CST816)" + depends on LV_TOUCH_CONTROLLER_CST816 + + config LV_TOUCH_X_MAX_CST816 + int + prompt "Maximum X coordinate ADC value" + range 0 1023 + default 320 + + config LV_TOUCH_Y_MAX_CST816 + int + prompt "Maximum Y coordinate ADC value" + range 0 1023 + default 240 + + config LV_SWAPXY_CST816 + bool + prompt "Swap X with Y coordinate." + default y + + config LV_INVERT_X_CST816 + bool + prompt "Invert X coordinate value." + default y + + config LV_INVERT_Y_CST816 + bool + prompt "Invert Y coordinate value." + default n + + endmenu + menu "Touchpanel Configuration (GT911)" depends on LV_TOUCH_CONTROLLER_GT911 diff --git a/lvgl_touch/touch_driver.c b/lvgl_touch/touch_driver.c index 35fcc6b..87b6063 100644 --- a/lvgl_touch/touch_driver.c +++ b/lvgl_touch/touch_driver.c @@ -22,6 +22,8 @@ void touch_driver_init(void) ra8875_touch_init(); #elif defined (CONFIG_LV_TOUCH_CONTROLLER_GT911) gt911_init(GT911_I2C_SLAVE_ADDR); +#elif defined (CONFIG_LV_TOUCH_CONTROLLER_CST816) + cst816_init(CST816_I2C_SLAVE_ADDR); #endif } @@ -47,6 +49,8 @@ bool touch_driver_read(lv_indev_drv_t *drv, lv_indev_data_t *data) res = ra8875_touch_read(drv, data); #elif defined (CONFIG_LV_TOUCH_CONTROLLER_GT911) res = gt911_read(drv, data); +#elif defined (CONFIG_LV_TOUCH_CONTROLLER_CST816) + res = cst816_read(drv, data); #endif #if LVGL_VERSION_MAJOR >= 8 diff --git a/lvgl_touch/touch_driver.h b/lvgl_touch/touch_driver.h index 0d014e2..72ed17c 100644 --- a/lvgl_touch/touch_driver.h +++ b/lvgl_touch/touch_driver.h @@ -34,6 +34,8 @@ extern "C" { #include "ra8875_touch.h" #elif defined (CONFIG_LV_TOUCH_CONTROLLER_GT911) #include "gt911.h" +#elif defined (CONFIG_LV_TOUCH_CONTROLLER_CST816) +#include "CST816.h" #endif /********************* From 1afab3cd91a6ac7df4dd484ff8d63f3c406a0888 Mon Sep 17 00:00:00 2001 From: Bassam Date: Thu, 11 Aug 2022 00:06:19 +0300 Subject: [PATCH 2/8] added support for S3 --- lvgl_helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lvgl_helpers.c b/lvgl_helpers.c index 57ab7dd..083a200 100644 --- a/lvgl_helpers.c +++ b/lvgl_helpers.c @@ -175,7 +175,7 @@ bool lvgl_spi_driver_init(int host, }; ESP_LOGI(TAG, "Initializing SPI bus..."); - #if defined (CONFIG_IDF_TARGET_ESP32C3) + #if defined (CONFIG_IDF_TARGET_ESP32C3) || defined (CONFIG_IDF_TARGET_ESP32S3) dma_channel = SPI_DMA_CH_AUTO; #endif esp_err_t ret = spi_bus_initialize(host, &buscfg, (spi_dma_chan_t)dma_channel); From f29723c80023536bbd0a13255d47dc0e09fa6780 Mon Sep 17 00:00:00 2001 From: Bassam Date: Fri, 12 Aug 2022 13:07:15 +0300 Subject: [PATCH 3/8] reverted back to using the lvgl i2c_manager --- CMakeLists.txt | 2 +- lvgl_touch/CST816.c | 63 +++++++++++++++++---------------------------- lvgl_touch/CST816.h | 10 +------ 3 files changed, 26 insertions(+), 49 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 724553f..71c4f28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,7 +88,7 @@ endif() idf_component_register(SRCS ${SOURCES} INCLUDE_DIRS ${LVGL_INCLUDE_DIRS} - REQUIRES lvgl band_audio_hal) + REQUIRES lvgl) target_compile_definitions(${COMPONENT_LIB} PUBLIC "-DLV_LVGL_H_INCLUDE_SIMPLE") diff --git a/lvgl_touch/CST816.c b/lvgl_touch/CST816.c index dd4fc7f..54dad47 100644 --- a/lvgl_touch/CST816.c +++ b/lvgl_touch/CST816.c @@ -27,23 +27,18 @@ #include "CST816.h" #include "lvgl_i2c/i2c_manager.h" -#include "band_es8388.h" #define TAG "CST816" -cst816_status_t cst816_status; +uint8_t CST816_addr; -//[BJ] TODO: Below functions are ADF specific, if I am to contribute to main repo this needs to be resolved! static esp_err_t _cst816_i2c_read(uint8_t slave_addr, uint8_t register_addr, uint8_t *data_buf, uint8_t len) { - return band_i2c_read(slave_addr, register_addr, data_buf, len); - //return lvgl_i2c_read(CONFIG_LV_I2C_TOUCH_PORT, slave_addr, register_addr | I2C_REG_16, data_buf, len); + return lvgl_i2c_read(CONFIG_LV_I2C_TOUCH_PORT, slave_addr, register_addr, data_buf, len); } -static esp_err_t _cst816_i2c_write8(uint8_t slave_addr, uint8_t register_addr, uint8_t data) { - //uint8_t buffer = data; - return band_i2c_write(slave_addr, register_addr, &data, 1); - //return lvgl_i2c_write(CONFIG_LV_I2C_TOUCH_PORT, slave_addr, register_addr | I2C_REG_16, &buffer, 1); -} +// static esp_err_t _cst816_i2c_write8(uint8_t slave_addr, uint8_t register_addr, uint8_t data) { +// return lvgl_i2c_write(CONFIG_LV_I2C_TOUCH_PORT, slave_addr, register_addr, &data, 1); +// } /** * @brief Initialize for cst816 communication via I2C @@ -51,28 +46,24 @@ static esp_err_t _cst816_i2c_write8(uint8_t slave_addr, uint8_t register_addr, u * @retval None */ void cst816_init(uint8_t dev_addr) { - if (!cst816_status.inited) - { - cst816_status.i2c_dev_addr = dev_addr; - uint8_t version; - uint8_t versionInfo[3]; - esp_err_t ret; - ESP_LOGI(TAG, "Initializing cst816 %d", dev_addr); - if ((ret = _cst816_i2c_read(dev_addr, 0x15, &version, 1) != ESP_OK)) - { - ESP_LOGE(TAG, "Error reading version from device: %s", - esp_err_to_name(ret)); // Only show error the first time - return; - } - if ((ret = _cst816_i2c_read(dev_addr, 0xA7, versionInfo, 3) != ESP_OK)) - { - ESP_LOGE(TAG, "Error reading versionInfo from device: %s", - esp_err_to_name(ret)); // Only show error the first time - return; - } - ESP_LOGI(TAG, "CST816 version %d, versionInfo: %d.%d.%d", version, versionInfo[0], versionInfo[1], versionInfo[2]); - cst816_status.inited = true; + CST816_addr = dev_addr; + uint8_t version; + uint8_t versionInfo[3]; + esp_err_t ret; + ESP_LOGI(TAG, "Initializing cst816 %d", dev_addr); + if ((ret = _cst816_i2c_read(dev_addr, 0x15, &version, 1) != ESP_OK)) + { + ESP_LOGE(TAG, "Error reading version from device: %s", + esp_err_to_name(ret)); // Only show error the first time + return; } + if ((ret = _cst816_i2c_read(dev_addr, 0xA7, versionInfo, 3) != ESP_OK)) + { + ESP_LOGE(TAG, "Error reading versionInfo from device: %s", + esp_err_to_name(ret)); // Only show error the first time + return; + } + ESP_LOGI(TAG, "CST816 version %d, versionInfo: %d.%d.%d", version, versionInfo[0], versionInfo[1], versionInfo[2]); } /** @@ -81,18 +72,12 @@ void cst816_init(uint8_t dev_addr) { * @param data: Store data here * @retval Always false */ -#define SWAPXY 1 -#define INVERTX 1 -#define INVERTY 0 - - bool cst816_read(lv_indev_drv_t *drv, lv_indev_data_t *data) { - uint8_t data_raw[8]; - _cst816_i2c_read(cst816_status.i2c_dev_addr, 0x01, data_raw, 6); - + uint8_t data_raw[8] ; + _cst816_i2c_read(CST816_addr, 0x01, data_raw, 6); uint8_t gestureID = data_raw[0]; uint8_t points = data_raw[1]; diff --git a/lvgl_touch/CST816.h b/lvgl_touch/CST816.h index c8085b5..e02e089 100644 --- a/lvgl_touch/CST816.h +++ b/lvgl_touch/CST816.h @@ -33,15 +33,7 @@ extern "C" { #endif -#define CST816_I2C_SLAVE_ADDR 0x15<<1 - -#define CST816_PRODUCT_ID_LEN 4 - - -typedef struct { - bool inited; - uint8_t i2c_dev_addr; -} cst816_status_t; +#define CST816_I2C_SLAVE_ADDR 0x15 /** * @brief Initialize for cst816 communication via I2C From 33cc74a9f0e90625e1d323bf62ecf74e636ed55a Mon Sep 17 00:00:00 2001 From: Bassam Date: Wed, 19 Oct 2022 12:56:21 +0300 Subject: [PATCH 4/8] reverted back to default coordinates for CST826 --- lvgl_touch/CST816.c | 6 ++++++ lvgl_touch/Kconfig | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lvgl_touch/CST816.c b/lvgl_touch/CST816.c index 54dad47..e119b0e 100644 --- a/lvgl_touch/CST816.c +++ b/lvgl_touch/CST816.c @@ -78,6 +78,12 @@ bool cst816_read(lv_indev_drv_t *drv, lv_indev_data_t *data) { uint8_t data_raw[8] ; _cst816_i2c_read(CST816_addr, 0x01, data_raw, 6); + // printf("Touch data: "); + // for(int i = 0; i < 6; i++) + // { + // printf("0x%02X ", data_raw[i]); + // } + // printf("\r\n"); uint8_t gestureID = data_raw[0]; uint8_t points = data_raw[1]; diff --git a/lvgl_touch/Kconfig b/lvgl_touch/Kconfig index dfa0ab9..267a66d 100644 --- a/lvgl_touch/Kconfig +++ b/lvgl_touch/Kconfig @@ -463,12 +463,12 @@ menu "LVGL Touch controller" config LV_SWAPXY_CST816 bool prompt "Swap X with Y coordinate." - default y + default n config LV_INVERT_X_CST816 bool prompt "Invert X coordinate value." - default y + default n config LV_INVERT_Y_CST816 bool From a4128e1d414ae47d7710789fa065169029df31b8 Mon Sep 17 00:00:00 2001 From: Bassam Date: Mon, 31 Oct 2022 00:31:22 +0200 Subject: [PATCH 5/8] commented out a line that I think made the display slower --- 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 de7b35a..70af85d 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -208,7 +208,7 @@ void st7789_send_data(void * data, uint16_t length) static void st7789_send_color(void * data, size_t length) { - disp_wait_for_pending_transactions(); + //disp_wait_for_pending_transactions(); [BJ] noticed that commenting this made the display slightly faster. gpio_set_level(ST7789_DC, 1); disp_spi_send_colors(data, length); } From 24cabb1523beee390db874e44174e697740ef51a Mon Sep 17 00:00:00 2001 From: Bassam Date: Thu, 3 Nov 2022 22:51:25 +0200 Subject: [PATCH 6/8] added support for TE pin on the st7789 driver --- lvgl_tft/Kconfig | 14 ++++++++++++++ lvgl_tft/st7789.c | 15 ++++++++++++++- lvgl_tft/st7789.h | 2 ++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lvgl_tft/Kconfig b/lvgl_tft/Kconfig index 4a74ad2..fc62cfb 100644 --- a/lvgl_tft/Kconfig +++ b/lvgl_tft/Kconfig @@ -739,6 +739,20 @@ menu "LVGL TFT Display controller" help Use software reset and ignores configured reset pin (some hardware does not use a reset pin). + config LV_DISPLAY_USE_TE_PIN + bool "Enable TE (Tearing effect) pin" + default y + help + Enable the TE pin to control the display. You can disable + it when the display does not need MISO signal to be controlled. + + config LV_DISPLAY_TE_PIN + int "GPIO for TE (Tearing effect) pin" + depends on LV_DISPLAY_USE_TE_PIN + default 38 + help + Configure the display TE pin here. + endmenu # menu will be visible only when LV_PREDEFINED_DISPLAY_NONE is y diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index 70af85d..5c7212c 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -82,6 +82,14 @@ void st7789_init(void) {0xB6, {0x0A, 0x82, 0x27, 0x00}, 4}, {ST7789_SLPOUT, {0}, 0x80}, {ST7789_DISPON, {0}, 0x80}, + #ifdef CONFIG_LV_DISPLAY_USE_TE_PIN + {ST7789_TEON, {0}, 1}, //[BJ] turn on TE + #endif + //----------- + //[BJ] Below I am trying to change refresh rate of the screen so the tearing is not prominent + //{ST7789_FRCTR2,{0x1F},1}, //[BJ] set the refresh rate + {ST7789_FRCTRL1,{0x01, 0x0F, 0x0F},3}, //[BJ] divide the refresh by 2. + // ---------------------------------------- {0, {0}, 0xff}, }; @@ -94,6 +102,11 @@ void st7789_init(void) gpio_set_direction(ST7789_RST, GPIO_MODE_OUTPUT); #endif +#ifdef CONFIG_LV_DISPLAY_USE_TE_PIN + gpio_pad_select_gpio(ST7789_TE); + gpio_set_direction(ST7789_TE, GPIO_MODE_INPUT); +#endif + //Reset the display #if !defined(ST7789_SOFT_RST) gpio_set_level(ST7789_RST, 0); @@ -208,7 +221,7 @@ void st7789_send_data(void * data, uint16_t length) static void st7789_send_color(void * data, size_t length) { - //disp_wait_for_pending_transactions(); [BJ] noticed that commenting this made the display slightly faster. + // disp_wait_for_pending_transactions(); gpio_set_level(ST7789_DC, 1); disp_spi_send_colors(data, length); } diff --git a/lvgl_tft/st7789.h b/lvgl_tft/st7789.h index cacb31b..362f98c 100644 --- a/lvgl_tft/st7789.h +++ b/lvgl_tft/st7789.h @@ -23,6 +23,8 @@ extern "C" #define ST7789_DC CONFIG_LV_DISP_PIN_DC #define ST7789_RST CONFIG_LV_DISP_PIN_RST +#define ST7789_TE CONFIG_LV_DISPLAY_TE_PIN + #if CONFIG_LV_DISP_USE_RST #if CONFIG_LV_DISP_ST7789_SOFT_RESET From 32296b4fa604ce7b0df9275390015ae5cf46f196 Mon Sep 17 00:00:00 2001 From: Bassam Date: Fri, 4 Nov 2022 00:02:17 +0200 Subject: [PATCH 7/8] not changing screen refresh --- lvgl_tft/st7789.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index 5c7212c..56ff64f 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -86,9 +86,9 @@ void st7789_init(void) {ST7789_TEON, {0}, 1}, //[BJ] turn on TE #endif //----------- - //[BJ] Below I am trying to change refresh rate of the screen so the tearing is not prominent + //[BJ] Below I am trying to change refresh rate of the screen //{ST7789_FRCTR2,{0x1F},1}, //[BJ] set the refresh rate - {ST7789_FRCTRL1,{0x01, 0x0F, 0x0F},3}, //[BJ] divide the refresh by 2. + //{ST7789_FRCTRL1,{0x01, 0x0F, 0x0F},3}, //[BJ] divide the refresh by 2. // ---------------------------------------- {0, {0}, 0xff}, }; From dd78dccca4e2d10337f5bf317c30ad77f408cd5b Mon Sep 17 00:00:00 2001 From: Bassam Date: Thu, 24 Nov 2022 10:09:23 +0200 Subject: [PATCH 8/8] support for ILI9342 in the ILI9341.c file --- lvgl_tft/ili9341.c | 70 +++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/lvgl_tft/ili9341.c b/lvgl_tft/ili9341.c index e91680f..6629ec4 100644 --- a/lvgl_tft/ili9341.c +++ b/lvgl_tft/ili9341.c @@ -53,28 +53,28 @@ static void ili9341_send_color(void * data, uint16_t length); void ili9341_init(void) { lcd_init_cmd_t ili_init_cmds[]={ - {0xCF, {0x00, 0x83, 0X30}, 3}, - {0xED, {0x64, 0x03, 0X12, 0X81}, 4}, - {0xE8, {0x85, 0x01, 0x79}, 3}, - {0xCB, {0x39, 0x2C, 0x00, 0x34, 0x02}, 5}, - {0xF7, {0x20}, 1}, - {0xEA, {0x00, 0x00}, 2}, + // {0xCF, {0x00, 0x83, 0X30}, 3}, + // {0xED, {0x64, 0x03, 0X12, 0X81}, 4}, + // {0xE8, {0x85, 0x01, 0x79}, 3}, + // {0xCB, {0x39, 0x2C, 0x00, 0x34, 0x02}, 5}, + // {0xF7, {0x20}, 1}, + // {0xEA, {0x00, 0x00}, 2}, {0xC0, {0x26}, 1}, /*Power control*/ {0xC1, {0x11}, 1}, /*Power control */ {0xC5, {0x35, 0x3E}, 2}, /*VCOM control*/ {0xC7, {0xBE}, 1}, /*VCOM control*/ - {0x36, {0x28}, 1}, /*Memory Access Control*/ + {0x36, {0x08}, 1}, //{0x36, {0x28}, 1}, /*Memory Access Control*/ {0x3A, {0x55}, 1}, /*Pixel Format Set*/ - {0xB1, {0x00, 0x1B}, 2}, - {0xF2, {0x08}, 1}, - {0x26, {0x01}, 1}, - {0xE0, {0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0X87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00}, 15}, - {0XE1, {0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F}, 15}, - {0x2A, {0x00, 0x00, 0x00, 0xEF}, 4}, - {0x2B, {0x00, 0x00, 0x01, 0x3f}, 4}, - {0x2C, {0}, 0}, - {0xB7, {0x07}, 1}, - {0xB6, {0x0A, 0x82, 0x27, 0x00}, 4}, + {0xB1, {0x00, 0x18}, 2},//{0xB1, {0x00, 0x1B}, 2}, //[BJ] frame rate. + //{0xF2, {0x08}, 1}, + {0x26, {0x01}, 1}, //[BJ] Gamma set + {0xE0, {0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0X87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00}, 15},//[BJ] + Gamma correction + {0XE1, {0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F}, 15},//[BJ] - Gamma correction + {0x2A, {0x00, 0x00, 0x00, 0xEF}, 4}, //[BJ] column address set + {0x2B, {0x00, 0x00, 0x01, 0x3f}, 4},//[BJ] page address set + {0x2C, {0}, 0},//[BJ] memory write. + {0xB7, {0x07}, 1},//[BJ] Entry mode set + {0xB6, {0x0A, 0x82, 0x27, 0x00}, 4}, //[BJ] display function control {0x11, {0}, 0x80}, {0x29, {0}, 0x80}, {0, {0}, 0xff}, @@ -108,7 +108,7 @@ void ili9341_init(void) cmd++; } - ili9341_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION); + // ili9341_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION); #if ILI9341_INVERT_COLORS == 1 ili9341_send_cmd(0x21); @@ -187,25 +187,25 @@ static void ili9341_send_color(void * data, uint16_t length) static void ili9341_set_orientation(uint8_t orientation) { // ESP_ASSERT(orientation < 4); +// orientation = 2; +// const char *orientation_str[] = { +// "PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED" +// }; - const char *orientation_str[] = { - "PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED" - }; +// ESP_LOGI(TAG, "Display orientation: %s", orientation_str[orientation]); - ESP_LOGI(TAG, "Display orientation: %s", orientation_str[orientation]); +// #if defined CONFIG_LV_PREDEFINED_DISPLAY_M5STACK +// uint8_t data[] = {0x68, 0x68, 0x08, 0x08}; +// #elif defined (CONFIG_LV_PREDEFINED_DISPLAY_M5CORE2) +// uint8_t data[] = {0x08, 0x88, 0x28, 0xE8}; +// #elif defined (CONFIG_LV_PREDEFINED_DISPLAY_WROVER4) +// uint8_t data[] = {0x6C, 0xEC, 0xCC, 0x4C}; +// #elif defined (CONFIG_LV_PREDEFINED_DISPLAY_NONE) +// uint8_t data[] = {0x48, 0x88, 0x28, 0xE8}; +// #endif -#if defined CONFIG_LV_PREDEFINED_DISPLAY_M5STACK - uint8_t data[] = {0x68, 0x68, 0x08, 0x08}; -#elif defined (CONFIG_LV_PREDEFINED_DISPLAY_M5CORE2) - uint8_t data[] = {0x08, 0x88, 0x28, 0xE8}; -#elif defined (CONFIG_LV_PREDEFINED_DISPLAY_WROVER4) - uint8_t data[] = {0x6C, 0xEC, 0xCC, 0x4C}; -#elif defined (CONFIG_LV_PREDEFINED_DISPLAY_NONE) - uint8_t data[] = {0x48, 0x88, 0x28, 0xE8}; -#endif +// ESP_LOGI(TAG, "0x36 command value: 0x%02X", data[orientation]); - ESP_LOGI(TAG, "0x36 command value: 0x%02X", data[orientation]); - - ili9341_send_cmd(0x36); - ili9341_send_data((void *) &data[orientation], 1); +// ili9341_send_cmd(0x36); +// ili9341_send_data((void *) &data[orientation], 1); }