diff --git a/.github/workflows/build_examples.yml b/.github/workflows/build_examples.yml new file mode 100644 index 0000000..6e040f9 --- /dev/null +++ b/.github/workflows/build_examples.yml @@ -0,0 +1,29 @@ +name: 'build' + +on: [push, pull_request] + +jobs: + build: + strategy: + matrix: + idf_ver: ["v4.1", "v4.2", "v4.3"] + idf_target: ["esp32"] + include: + - idf_ver: "v4.2" + idf_target: esp32s2 + - idf_ver: "v4.3" + idf_target: esp32c3 + runs-on: ubuntu-20.04 + container: espressif/idf:release-${{ matrix.idf_ver }} + steps: + - uses: actions/checkout@v1 + with: + submodules: recursive + - name: Build ESP examples + env: + IDF_TARGET: ${{ matrix.idf_target }} + shell: bash + run: | + cd examples/wemos_lolin_oled/hello_world + . ${IDF_PATH}/export.sh + idf.py build diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..61a933b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "examples/common_components/lvgl"] + path = examples/common_components/lvgl + url = https://github.com/lvgl/lvgl.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 78870dd..d6a67f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,46 +5,32 @@ set(LVGL_INCLUDE_DIRS . lvgl_tft) list(APPEND SOURCES "lvgl_tft/disp_driver.c") list(APPEND SOURCES "lvgl_tft/esp_lcd_backlight.c") -# Include only the source file of the selected -# display controller. -if(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341) +# This are the source files used for mcu abstraction +set(LV_PORT_PATH "lv_port") + +list(APPEND SOURCES "${LV_PORT_PATH}/lv_port_display_espressif.c") + +#@todo add SimleInclude macro here + +# Build all display drivers list(APPEND SOURCES "lvgl_tft/ili9341.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9481) list(APPEND SOURCES "lvgl_tft/ili9481.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9486) list(APPEND SOURCES "lvgl_tft/ili9486.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488) list(APPEND SOURCES "lvgl_tft/ili9488.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7789) list(APPEND SOURCES "lvgl_tft/st7789.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7735S) list(APPEND SOURCES "lvgl_tft/st7735s.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7796S) list(APPEND SOURCES "lvgl_tft/st7796s.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_HX8357) list(APPEND SOURCES "lvgl_tft/hx8357.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_SH1107) list(APPEND SOURCES "lvgl_tft/sh1107.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_SSD1306) list(APPEND SOURCES "lvgl_tft/ssd1306.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X) list(APPEND SOURCES "lvgl_tft/EVE_commands.c") list(APPEND SOURCES "lvgl_tft/FT81x.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_IL3820) list(APPEND SOURCES "lvgl_tft/il3820.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_JD79653A) list(APPEND SOURCES "lvgl_tft/jd79653a.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D) list(APPEND SOURCES "lvgl_tft/uc8151d.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_RA8875) list(APPEND SOURCES "lvgl_tft/ra8875.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_GC9A01) list(APPEND SOURCES "lvgl_tft/GC9A01.c") -elseif(CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9163C) list(APPEND SOURCES "lvgl_tft/ili9163c.c") -else() - message(WARNING "LVGL ESP32 drivers: Display controller not defined.") -endif() if(CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI) list(APPEND SOURCES "lvgl_tft/disp_spi.c") diff --git a/display_config.h b/display_config.h new file mode 100644 index 0000000..7452b43 --- /dev/null +++ b/display_config.h @@ -0,0 +1,43 @@ +#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 +#define ILI9341_INVERT_COLORS 1U +#endif + +#define ST7789_INITIAL_ORIENTATION CONFIG_LV_DISPLAY_ORIENTATION + +#if CONFIG_LV_DISP_USE_RST +#define ILI9341_USE_RST +#endif + +#define ILI9341_INITIAL_ORIENTATION CONFIG_LV_DISPLAY_ORIENTATION + +/* ILI9488 Configuration */ +#if CONFIG_LV_DISP_USE_RST +#define ILI9488_USE_RST +#endif + +#define ILI9488_INITIAL_ORIENTATION CONFIG_LV_DISPLAY_ORIENTATION + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* DISPLAY_CONFIG_H_ */ diff --git a/examples/common_components/lvgl b/examples/common_components/lvgl new file mode 160000 index 0000000..ec9de51 --- /dev/null +++ b/examples/common_components/lvgl @@ -0,0 +1 @@ +Subproject commit ec9de515b36641be565d7bace5863ab631ce3b69 diff --git a/examples/wemos_lolin_oled/hello_world/CMakeLists.txt b/examples/wemos_lolin_oled/hello_world/CMakeLists.txt new file mode 100644 index 0000000..b65f74e --- /dev/null +++ b/examples/wemos_lolin_oled/hello_world/CMakeLists.txt @@ -0,0 +1,9 @@ +# For more information about build system see +# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html +# The following five lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +set(EXTRA_COMPONENT_DIRS ../../common_components ../../..) +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(hello_world) diff --git a/examples/wemos_lolin_oled/hello_world/main/CMakeLists.txt b/examples/wemos_lolin_oled/hello_world/main/CMakeLists.txt new file mode 100644 index 0000000..4e8dbcf --- /dev/null +++ b/examples/wemos_lolin_oled/hello_world/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "hello_world.c" + INCLUDE_DIRS ".") diff --git a/examples/wemos_lolin_oled/hello_world/main/hello_world.c b/examples/wemos_lolin_oled/hello_world/main/hello_world.c new file mode 100644 index 0000000..3b0e6b4 --- /dev/null +++ b/examples/wemos_lolin_oled/hello_world/main/hello_world.c @@ -0,0 +1,98 @@ +/* Hello world on Wemos Lolin32 board + * + * This example code is in the Public Domain (or CC0 licensed, at your option.) + * + * Unless required by applicable law or agreed to in writing, this + * software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. + */ +#include +#include +#include +#include + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_freertos_hooks.h" +#include "freertos/semphr.h" +#include "esp_system.h" +#include "driver/gpio.h" + +/* Littlevgl specific */ +#ifdef LV_LVGL_H_INCLUDE_SIMPLE +#include "lvgl.h" +#else +#include "lvgl/lvgl.h" +#endif + +#include "lvgl_helpers.h" + +/********************* + * DEFINES + *********************/ +#define LV_TICK_PERIOD_MS 1 + +/********************** + * STATIC PROTOTYPES + **********************/ +static void lvgl_tick_inc(void *arg); +static void guiTask(void *pvParameter); + +/********************** + * APPLICATION MAIN + **********************/ +void app_main() +{ + xTaskCreatePinnedToCore(guiTask, "gui", 4096*2, NULL, 0, NULL, 1); +} + +static void guiTask(void *pvParameter) +{ + (void) pvParameter; + lv_init(); + lvgl_driver_init(); + + lv_color_t* buf1 = heap_caps_malloc(DISP_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA); + assert(buf1 != NULL); + + static lv_disp_buf_t disp_buf; + lv_disp_buf_init(&disp_buf, buf1, NULL, DISP_BUF_SIZE * 8); + + lv_disp_drv_t disp_drv; + lv_disp_drv_init(&disp_drv); + disp_drv.flush_cb = disp_driver_flush; + disp_drv.rounder_cb = disp_driver_rounder; + disp_drv.set_px_cb = disp_driver_set_px; + disp_drv.buffer = &disp_buf; + lv_disp_drv_register(&disp_drv); + + /* Create and start a periodic timer interrupt to call lv_tick_inc */ + const esp_timer_create_args_t periodic_timer_args = { + .callback = &lvgl_tick_inc, + .name = "lvgl_tick" + }; + esp_timer_handle_t periodic_timer; + ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &periodic_timer)); + ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, LV_TICK_PERIOD_MS * 1000)); + + /* Create a Hellow World label on the currently active screen */ + lv_obj_t *scr = lv_disp_get_scr_act(NULL); + lv_obj_t *label1 = lv_label_create(scr, NULL); + lv_label_set_text(label1, "Hello\nworld"); + + /* Align the Label to the center + * NULL means align on parent (which is the screen now) + * 0, 0 at the end means an x, y offset after alignment*/ + lv_obj_align(label1, NULL, LV_ALIGN_CENTER, 0, 0); + + while (1) { + vTaskDelay(pdMS_TO_TICKS(10)); + lv_task_handler(); + } + free(buf1); +} + +static void lvgl_tick_inc(void *arg) { + (void) arg; + lv_tick_inc(LV_TICK_PERIOD_MS); +} diff --git a/examples/wemos_lolin_oled/hello_world/sdkconfig.defaults b/examples/wemos_lolin_oled/hello_world/sdkconfig.defaults new file mode 100644 index 0000000..b92d2d5 --- /dev/null +++ b/examples/wemos_lolin_oled/hello_world/sdkconfig.defaults @@ -0,0 +1,11 @@ +CONFIG_LV_HOR_RES_MAX=128 +CONFIG_LV_VER_RES_MAX=64 +CONFIG_LV_COLOR_DEPTH_1=y +CONFIG_LV_THEME_MONO=y + +CONFIG_LV_PREDEFINED_DISPLAY_WEMOS_LOLIN=y + +CONFIG_I2C_MANAGER_0_ENABLED=y +CONFIG_I2C_MANAGER_0_SDA=5 +CONFIG_I2C_MANAGER_0_SCL=4 +CONFIG_I2C_MANAGER_0_FREQ_HZ=100000 diff --git a/lv_port/lv_port_display_espressif.c b/lv_port/lv_port_display_espressif.c new file mode 100644 index 0000000..def8991 --- /dev/null +++ b/lv_port/lv_port_display_espressif.c @@ -0,0 +1,110 @@ +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + +#include "display_port.h" + +#include "sdkconfig.h" +#include "driver/gpio.h" + +#include "disp_spi.h" +#include "lvgl_i2c/i2c_manager.h" + +/* TODO: This is ssd1306 specific */ +#define OLED_I2C_PORT (CONFIG_LV_I2C_DISPLAY_PORT) +#define OLED_I2C_ADDRESS 0x3C + +#define LV_DISPLAY_DC_CMD_MODE 0 +#define LV_DISPLAY_DC_DATA_MODE 1 + +void display_port_delay(lv_disp_drv_t *drv, uint32_t delay_ms) +{ + (void) drv; + + vTaskDelay(pdMS_TO_TICKS(delay_ms)); +} + +void display_port_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_port_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_port_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 +} + +bool display_port_gpio_is_busy(lv_disp_drv_t *drv) +{ + (void) drv; + + bool device_busy = false; + +#ifdef CONFIG_LV_DISP_PIN_BUSY + /* FIXME Assuming the busy signal in logic 1 means the device is busy */ + if (gpio_get_level(CONFIG_LV_DISP_PIN_BUSY) == 1) { + device_busy = true; + } +#endif + + return device_busy; +} + +void display_interface_send_cmd(lv_disp_drv_t *drv, uint32_t cmd, cmd_width_t cmd_width, void *args, size_t args_len) +{ + (void) drv; + +#if defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI) + disp_wait_for_pending_transactions(); + display_port_gpio_dc(drv, LV_DISPLAY_DC_CMD_MODE); + + if (CMD_WIDTH_8BITS == cmd_width) { + disp_spi_send_data(&cmd, 1); + } + else if (CMD_WIDTH_16BITS == cmd_width) { + /* Send 16bits cmd */ + } + else { + /* Unsupported cmd size */ + } + + if (args != NULL) { + display_port_gpio_dc(drv, LV_DISPLAY_DC_DATA_MODE); + disp_spi_send_data(args, args_len); + } +#elif defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_I2C) + uint8_t *data = (uint8_t *) args; + + lvgl_i2c_write(OLED_I2C_PORT, OLED_I2C_ADDRESS, cmd, data, args_len); +#endif +} + +void display_interface_send_data(lv_disp_drv_t *drv, void *data, size_t len) +{ + (void) drv; + +#if defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI) + disp_wait_for_pending_transactions(); + display_port_gpio_dc(drv, LV_DISPLAY_DC_DATA_MODE); + disp_spi_send_colors(data, len); + /* lv_disp_flush is called in the SPI xfer done callback */ +#elif defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_I2C) + lvgl_i2c_write(OLED_I2C_PORT, OLED_I2C_ADDRESS, OLED_CONTROL_BYTE_DATA_STREAM, data, len); +#endif +} diff --git a/lvgl_helpers.c b/lvgl_helpers.c index edc522f..ab83275 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; @@ -105,10 +103,7 @@ 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 #error "No protocol defined for display controller" #endif @@ -139,6 +134,39 @@ void lvgl_driver_init(void) #endif } +void display_bsp_init_io(void) +{ + esp_err_t err = ESP_OK; + gpio_config_t io_conf; + +#ifdef CONFIG_LV_DISPLAY_USE_DC + io_conf.mode = GPIO_MODE_OUTPUT; + io_conf.pin_bit_mask = (1ULL << CONFIG_LV_DISP_PIN_DC); + err = gpio_config(&io_conf); + ESP_ERROR_CHECK(err); +#endif + +#ifdef CONFIG_LV_DISP_USE_RST + io_conf.mode = GPIO_MODE_OUTPUT; + io_conf.pin_bit_mask = (1ULL << CONFIG_LV_DISP_PIN_RST); + err = gpio_config(&io_conf); + ESP_ERROR_CHECK(err); +#endif + +#if !defined(CONFIG_LV_DISP_BACKLIGHT_OFF) && defined(CONFIG_LV_DISP_PIN_BCKL) + io_conf.mode = GPIO_MODE_OUTPUT; + io_conf.pin_bit_mask = (1ULL << CONFIG_LV_DISP_PIN_BCKL); + err = gpio_config(&io_conf); + ESP_ERROR_CHECK(err); +#endif + +#ifdef CONFIG_LV_DISP_PIN_BUSY + io_conf.mode = GPIO_MODE_INPUT; + io_conf.pin_bit_mask = (1ULL << CONFIG_LV_DISP_PIN_BUSY); + err = gpio_config(&io_conf); + ESP_ERROR_CHECK(err); +#endif +} /* Initialize spi bus master * diff --git a/lvgl_helpers.h b/lvgl_helpers.h index 5fd6f09..439bd6b 100644 --- a/lvgl_helpers.h +++ b/lvgl_helpers.h @@ -98,6 +98,8 @@ void lvgl_driver_init(void); bool lvgl_spi_driver_init(int host, int miso_pin, int mosi_pin, int sclk_pin, int max_transfer_sz, int dma_channel, int quadwp_pin, int quadhd_pin); +/* Initialize display GPIOs, e.g. DC and RST pins */ +void display_bsp_init_io(void); /********************** * MACROS **********************/ diff --git a/lvgl_i2c/Kconfig b/lvgl_i2c/Kconfig index 4011bcf..48df924 100644 --- a/lvgl_i2c/Kconfig +++ b/lvgl_i2c/Kconfig @@ -6,8 +6,10 @@ menu "I2C Port 0" if I2C_MANAGER_0_ENABLED config I2C_MANAGER_0_SDA int "SDA (GPIO pin)" + default 0 config I2C_MANAGER_0_SCL int "SCL (GPIO pin)" + default 0 config I2C_MANAGER_0_FREQ_HZ int "Frequency (Hz)" default 400000 diff --git a/lvgl_i2c/README.md b/lvgl_i2c/README.md index fb74e27..90f3728 100644 --- a/lvgl_i2c/README.md +++ b/lvgl_i2c/README.md @@ -8,9 +8,11 @@ ### I2C Manager support -`lvgl_esp32_drivers` integrates [I2C Manager](https://github.com/ropg/i2c_manager), which is used in case you select a touch sensor or screen that uses the I2C bus. If you're just using LVGL you don't need to do anything special. +`lvgl_esp32_drivers` integrates [I2C Manager](https://github.com/ropg/i2c_manager), which is used in case you select a touch sensor or screen that uses the I2C bus. -I2C Manager can help if you are in a situation where you want to avoid "bus conflicts" on the I2C bus. Suppose you use LVGL with a touch sensor that uses I2C, and your device also has another I2C device that needs to be read frequently, such as a 3D-accelerometer. ESP-IDF is not inherently "thread-safe". So if you read that from another task than the one LVGL uses to read the touch data, you need some kind of mechanism to keep these communications from interfering. +I2C Manager is also available as a separate ESP-IDF component and can help if you are in a situation where you want to avoid "bus conflicts" on the I2C bus. **If in your application nothing outside of LVGL needs to talk to the I2C bus, you can stop reading here.** + +Suppose you use LVGL with a touch sensor that uses I2C, and your device also has another I2C device that needs to be read frequently, such as a 3D-accelerometer. ESP-IDF is not inherently "thread-safe". So if you read that from another task than the one LVGL uses to read the touch data, you need some kind of mechanism to keep these communications from interfering. If you have (or write) a driver for that 3D-accelerometer that can use I2C Manager (or the I2C HAL and i2cdev abstraction layers that I2C Manager is compatible with) then put I2C Manager in your components directory by cloning the repository from below and in your main program do: diff --git a/lvgl_tft/EVE_commands.c b/lvgl_tft/EVE_commands.c index 2a93efa..8765609 100644 --- a/lvgl_tft/EVE_commands.c +++ b/lvgl_tft/EVE_commands.c @@ -41,6 +41,11 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include +#include + +#if defined (BT81X_ENABLE) +#include +#endif #include "EVE.h" #include "EVE_commands.h" @@ -50,19 +55,8 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include "driver/gpio.h" #include "esp_log.h" #include "soc/soc_memory_layout.h" - -#include "esp_log.h" - #include "disp_spi.h" -#include - -#if defined (BT81X_ENABLE) -#include -#endif - -#define TAG_LOG "FT81X" - /* data structure for SPI reading that has (optional) space for inserted dummy byte */ typedef struct _spi_read_data { #if defined(DISP_SPI_FULL_DUPLEX) @@ -875,13 +869,13 @@ uint8_t EVE_init(void) /* The most reliable DIO/QIO switching point is after EVE start up but before reading the ChipID. */ #if defined(DISP_SPI_TRANS_MODE_DIO) - ESP_LOGI(TAG_LOG, "Switching to DIO mode"); + LV_LOG_INFO("Switching to DIO mode"); DELAY_MS(20); /* different boards may take a different delay but this generally seems to work */ EVE_memWrite16(REG_SPI_WIDTH, SPI_WIDTH_DIO); SPIInherentSendFlags = DISP_SPI_MODE_DIO | DISP_SPI_MODE_DIOQIO_ADDR; SPIDummyReadBits = 4; /* Esp32 DMA SPI transaction dummy_bits works more like clock cycles, so in DIO 4 dummy_bits == 8 total bits */ #elif defined(DISP_SPI_TRANS_MODE_QIO) - ESP_LOGI(TAG_LOG, "Switching to QIO mode"); + LV_LOG_INFO("Switching to QIO mode"); DELAY_MS(20); /* different boards may take a different delay but this generally seems to work */ EVE_memWrite16(REG_SPI_WIDTH, SPI_WIDTH_QIO); SPIInherentSendFlags = DISP_SPI_MODE_QIO | DISP_SPI_MODE_DIOQIO_ADDR; @@ -897,7 +891,7 @@ uint8_t EVE_init(void) timeout++; if(timeout > 400) { - ESP_LOGI(TAG_LOG, "Failed to read ChipID...aborting initialization."); + LV_LOG_WARN("Failed to read ChipID...aborting initialization."); return 0; } } @@ -909,7 +903,7 @@ uint8_t EVE_init(void) timeout++; if(timeout > 50) /* experimental, 10 was the lowest value to get the BT815 started with, the touch-controller was the last to get out of reset */ { - ESP_LOGI(TAG_LOG, "Failed to read CPU status...aborting initialization."); + LV_LOG_WARN("Failed to read CPU status...aborting initialization."); return 0; } } diff --git a/lvgl_tft/EVE_config.h b/lvgl_tft/EVE_config.h index 386edb9..a15e746 100644 --- a/lvgl_tft/EVE_config.h +++ b/lvgl_tft/EVE_config.h @@ -208,6 +208,8 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #define EVE_SUNFLOWER #elif defined(CONFIG_LV_FT81X_CONFIG_EVE_CONNECTEVE) #define EVE_CONNECTEVE +#else +#define EVE_EVE2_35 // Define something if there is no Kconfig option selected #endif /* display timing parameters below */ diff --git a/lvgl_tft/GC9A01.c b/lvgl_tft/GC9A01.c index c807233..81a71d3 100644 --- a/lvgl_tft/GC9A01.c +++ b/lvgl_tft/GC9A01.c @@ -16,7 +16,6 @@ /********************* * DEFINES *********************/ - #define TAG "GC9A01" /********************** * TYPEDEFS @@ -126,7 +125,7 @@ void GC9A01_init(void) vTaskDelay(100 / portTICK_RATE_MS); #endif - ESP_LOGI(TAG, "Initialization."); + LV_LOG_INFO("Initialization."); //Send all the commands uint16_t cmd = 0; @@ -220,23 +219,23 @@ static void GC9A01_send_color(void * data, uint16_t length) static void GC9A01_set_orientation(uint8_t orientation) { - // ESP_ASSERT(orientation < 4); + assert(orientation < 4); const char *orientation_str[] = { "PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED" }; - ESP_LOGI(TAG, "Display orientation: %s", orientation_str[orientation]); + LV_LOG_INFO("Display orientation: %s", orientation_str[orientation]); #if defined CONFIG_LV_PREDEFINED_DISPLAY_M5STACK - uint8_t data[] = {0x68, 0x68, 0x08, 0x08}; /// + const uint8_t data[] = {0x68, 0x68, 0x08, 0x08}; #elif defined (CONFIG_LV_PREDEFINED_DISPLAY_WROVER4) - uint8_t data[] = {0x4C, 0x88, 0x28, 0xE8}; /// -#elif defined (CONFIG_LV_PREDEFINED_DISPLAY_NONE) - uint8_t data[] = {0x08, 0xC8, 0x68, 0xA8}; ///ggggg + const uint8_t data[] = {0x4C, 0x88, 0x28, 0xE8}; +#else + const uint8_t data[] = {0x08, 0xC8, 0x68, 0xA8}; #endif - ESP_LOGI(TAG, "0x36 command value: 0x%02X", data[orientation]); + LV_LOG_INFO("0x36 command value: 0x%02X", data[orientation]); GC9A01_send_cmd(0x36); GC9A01_send_data((void *) &data[orientation], 1); diff --git a/lvgl_tft/Kconfig b/lvgl_tft/Kconfig index f42351e..140c173 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 @@ -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/disp_driver.c b/lvgl_tft/disp_driver.c index f62a947..08db79a 100644 --- a/lvgl_tft/disp_driver.c +++ b/lvgl_tft/disp_driver.c @@ -7,16 +7,16 @@ #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(); + ili9341_init(drv); #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9481 ili9481_init(); #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488 - ili9488_init(); + ili9488_init(drv); #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 @@ -28,7 +28,7 @@ void *disp_driver_init(void) #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SH1107 sh1107_init(); #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SSD1306 - ssd1306_init(); + ssd1306_init(drv); #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X FT81x_init(); #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_IL3820 @@ -45,6 +45,11 @@ void *disp_driver_init(void) 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 8c70fda..a4a282b 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); @@ -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 **********************/ diff --git a/lvgl_tft/display_port.h b/lvgl_tft/display_port.h new file mode 100644 index 0000000..210e9ff --- /dev/null +++ b/lvgl_tft/display_port.h @@ -0,0 +1,93 @@ +#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 + +#include +#include + +enum { + CMD_WIDTH_8BITS, + CMD_WIDTH_16BITS, + CMD_WIDTH_INVALID, +}; + +typedef uint8_t cmd_width_t; + +/** + * 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); + +/** + * Display is busy port + * + * @param drv Pointer to driver See @ref lv_disp_drv_t + * + * @retval Returns false when display is not busy, true otherwise. + */ +bool display_port_gpio_is_busy(lv_disp_drv_t *drv); + +/** + * Send cmd to display + * + * @param drv Pointer to driver + * @param cmd Command to send + * @param cmd_width Width of the command (in bits) to be sent, see @ref cmd_width_t + * @param args Pointer to arguments, use NULL to send command without arguments + * @param args_len Arguments length (in bytes) to be sent + */ +void display_interface_send_cmd(lv_disp_drv_t *drv, uint32_t cmd, cmd_width_t cmd_width, void *args, size_t args_len); + +/** + * Send (image) data to display + * + * User must call lv_disp_flush after the image is sent + * + * @param drv Pointer to driver + * @param data Pointer to data to be sent + * @param len Data length (in bytes) to be sent + */ +void display_interface_send_data(lv_disp_drv_t *drv, void *data, size_t len); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/lvgl_tft/hx8357.c b/lvgl_tft/hx8357.c index bb9ea58..a22287b 100644 --- a/lvgl_tft/hx8357.c +++ b/lvgl_tft/hx8357.c @@ -18,15 +18,12 @@ #include "hx8357.h" #include "disp_spi.h" #include "driver/gpio.h" -#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" /********************* * DEFINES *********************/ -#define TAG "HX8357" - #define MADCTL_MY 0x80 ///< Bottom to top #define MADCTL_MX 0x40 ///< Right to left #define MADCTL_MV 0x20 ///< Reverse Mode @@ -174,7 +171,7 @@ void hx8357_init(void) vTaskDelay(120 / portTICK_RATE_MS); #endif - ESP_LOGI(TAG, "Initialization."); + LV_LOG_INFO("Initialization."); //Send all the commands const uint8_t *addr = (displayType == HX8357B) ? initb : initd; diff --git a/lvgl_tft/il3820.c b/lvgl_tft/il3820.c index 1ce0b39..31fea55 100644 --- a/lvgl_tft/il3820.c +++ b/lvgl_tft/il3820.c @@ -30,7 +30,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH *********************/ #include "disp_spi.h" #include "driver/gpio.h" -#include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -39,7 +38,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH /********************* * DEFINES *********************/ - #define TAG "IL3820" /** * SSD1673, SSD1608 compatible EPD controller driver. @@ -180,7 +178,9 @@ void il3820_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t* buf, BIT_CLEAR(buf[byte_index], 7 - bit_index); } #else -#error "Unsupported orientation used" + (void)byte_index; + (void)bit_index; + assert(false); // Unsupported orientation configured. Crash if we get here, but allow compilation for CI #endif } @@ -277,7 +277,7 @@ static void il3820_waitbusy(int wait_ms) vTaskDelay(10 / portTICK_RATE_MS); } - ESP_LOGE( TAG, "busy exceeded %dms", i*10 ); + LV_LOG_ERROR("Busy exceeded %dms", i*10 ); } /* Set DC signal to command mode */ diff --git a/lvgl_tft/ili9163c.c b/lvgl_tft/ili9163c.c index 059d076..56b9fca 100644 --- a/lvgl_tft/ili9163c.c +++ b/lvgl_tft/ili9163c.c @@ -9,7 +9,6 @@ #include "ili9163c.h" #include "disp_spi.h" #include "driver/gpio.h" -#include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "assert.h" @@ -17,8 +16,6 @@ /********************* * DEFINES *********************/ -#define TAG "ILI9163C" - // ILI9163C specific commands used in init #define ILI9163C_NOP 0x00 #define ILI9163C_SWRESET 0x01 @@ -69,7 +66,7 @@ #define ST77XX_MADCTL_MY 0x80 #define ST77XX_MADCTL_MX 0x40 -#define ST77XX_MADCTL_MV 0x20 #define +#define ST77XX_MADCTL_MV 0x20 #define ST77XX_MADCTL_ML 0x10 #define ST77XX_MADCTL_RGB 0x00 #define ST77XX_MADCTL_BGR 0x08 @@ -94,7 +91,7 @@ static void ili9163c_set_orientation(uint8_t orientation); static void ili9163c_send_cmd(uint8_t cmd); static void ili9163c_send_data(void *data, uint16_t length); static void ili9163c_send_color(void *data, uint16_t length); - +static void ili9163c_reset(void); /********************** * STATIC VARIABLES **********************/ @@ -109,7 +106,7 @@ static void ili9163c_send_color(void *data, uint16_t length); void ili9163c_init(void) { - ESP_LOGD(TAG, "Init"); + LV_LOG_INFO("Init"); lcd_init_cmd_t ili_init_cmds[] = { {ILI9163C_SWRESET, {0}, 0x80}, // Software reset, 0 args, w/delay 120ms @@ -136,18 +133,8 @@ void ili9163c_init(void) {ILI9163C_DISPON, {0}, 0x80}, // Main screen turn on, no args w/delay 100 ms delay {0, {0}, 0xff} }; - - //Initialize non-SPI GPIOs - gpio_pad_select_gpio(ILI9163C_DC); - gpio_set_direction(ILI9163C_DC, GPIO_MODE_OUTPUT); - gpio_pad_select_gpio(ILI9163C_RST); - gpio_set_direction(ILI9163C_RST, GPIO_MODE_OUTPUT); - - //Reset the display - gpio_set_level(ILI9163C_RST, 0); - vTaskDelay(100 / portTICK_RATE_MS); - gpio_set_level(ILI9163C_RST, 1); - vTaskDelay(150 / portTICK_RATE_MS); + + ili9163c_reset(); //Send all the commands uint16_t cmd = 0; @@ -239,10 +226,21 @@ static void ili9163c_set_orientation(uint8_t orientation) const char *orientation_str[] = { "PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED"}; - ESP_LOGD(TAG, "Display orientation: %s", orientation_str[orientation]); + LV_LOG_INFO("Display orientation: %s", orientation_str[orientation]); uint8_t data[] = {0x48, 0x88, 0xA8, 0x68}; ili9163c_send_cmd(ILI9163C_MADCTL); ili9163c_send_data((void *)&data[orientation], 1); } + +static void ili9163c_reset(void) +{ +#if CONFIG_LV_DISP_USE_RST + gpio_set_level(ILI9163C_RST, 0); + vTaskDelay(100 / portTICK_RATE_MS); + gpio_set_level(ILI9163C_RST, 1); + vTaskDelay(150 / portTICK_RATE_MS); +#else +#endif +} diff --git a/lvgl_tft/ili9341.c b/lvgl_tft/ili9341.c index e91680f..49e1185 100644 --- a/lvgl_tft/ili9341.c +++ b/lvgl_tft/ili9341.c @@ -7,22 +7,23 @@ * INCLUDES *********************/ #include "ili9341.h" -#include "disp_spi.h" -#include "driver/gpio.h" -#include "esp_log.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" + +#include "display_port.h" /********************* * DEFINES *********************/ - #define TAG "ILI9341" +#define END_OF_CMD_MARKER 0xFFU + +#define MEMORY_ACCESS_CONTROL_REG 0x36U +#define SOFTWARE_RESET_REG 0x01U /********************** * TYPEDEFS **********************/ /*The LCD needs a bunch of command/argument values to be initialized. They are stored in this struct. */ + typedef struct { uint8_t cmd; uint8_t data[16]; @@ -32,12 +33,8 @@ typedef struct { /********************** * STATIC PROTOTYPES **********************/ -static void ili9341_set_orientation(uint8_t orientation); - -static void ili9341_send_cmd(uint8_t cmd); -static void ili9341_send_data(void * data, uint16_t length); -static void ili9341_send_color(void * data, uint16_t length); - +static void ili9341_set_orientation(lv_disp_drv_t * drv, uint8_t orientation); +static void ili9341_reset(lv_disp_drv_t * drv); /********************** * STATIC VARIABLES **********************/ @@ -50,162 +47,143 @@ static void ili9341_send_color(void * data, uint16_t length); * GLOBAL FUNCTIONS **********************/ -void ili9341_init(void) +void ili9341_init(lv_disp_drv_t * drv) { - 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}, - {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*/ - {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}, - {0x11, {0}, 0x80}, - {0x29, {0}, 0x80}, - {0, {0}, 0xff}, - }; + 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}, + /* Power control */ + {0xC0, {0x26}, 1}, + /* Power control */ + {0xC1, {0x11}, 1}, + /* VCOM control */ + {0xC5, {0x35, 0x3E}, 2}, + /* VCOM control */ + {0xC7, {0xBE}, 1}, + /* Memory Access Control */ + {0x36, {0x28}, 1}, + /* Pixel Format Set */ + {0x3A, {0x55}, 1}, + {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}, + {0x11, {0}, 0x80}, + {0x29, {0}, 0x80}, + {0, {0}, END_OF_CMD_MARKER}, + }; - //Initialize non-SPI GPIOs - gpio_pad_select_gpio(ILI9341_DC); - gpio_set_direction(ILI9341_DC, GPIO_MODE_OUTPUT); + ili9341_reset(drv); -#if ILI9341_USE_RST - gpio_pad_select_gpio(ILI9341_RST); - gpio_set_direction(ILI9341_RST, GPIO_MODE_OUTPUT); + //Send all the commands + uint16_t idx = 0; + while (ili_init_cmds[idx].databytes != END_OF_CMD_MARKER) { + uint8_t cmd = ili_init_cmds[idx].cmd; + void *args = ili_init_cmds[idx].data; + size_t args_len = ili_init_cmds[idx].databytes & 0x1F; - //Reset the display - gpio_set_level(ILI9341_RST, 0); - vTaskDelay(100 / portTICK_RATE_MS); - gpio_set_level(ILI9341_RST, 1); - vTaskDelay(100 / portTICK_RATE_MS); -#endif + display_interface_send_cmd(drv, cmd, CMD_WIDTH_8BITS, args, args_len); + + if (ili_init_cmds[idx].databytes & 0x80) { + display_port_delay(drv, 100); + } - ESP_LOGI(TAG, "Initialization."); + idx++; + } - //Send all the commands - uint16_t cmd = 0; - while (ili_init_cmds[cmd].databytes!=0xff) { - ili9341_send_cmd(ili_init_cmds[cmd].cmd); - ili9341_send_data(ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes&0x1F); - if (ili_init_cmds[cmd].databytes & 0x80) { - vTaskDelay(100 / portTICK_RATE_MS); - } - cmd++; - } + ili9341_set_orientation(drv, ILI9341_INITIAL_ORIENTATION); - ili9341_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION); - -#if ILI9341_INVERT_COLORS == 1 - ili9341_send_cmd(0x21); +#if ILI9341_INVERT_COLORS == 1U + display_interface_send_cmd(drv, 0x21, CMD_WIDTH_8BITS, NULL, 0); #else - ili9341_send_cmd(0x20); + display_interface_send_cmd(drv, 0x20, CMD_WIDTH_8BITS, NULL, 0); #endif } void ili9341_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map) { - uint8_t data[4]; + uint8_t data[4] = {0}; + uint32_t size = lv_area_get_width(area) * lv_area_get_height(area); - /*Column addresses*/ - ili9341_send_cmd(0x2A); - data[0] = (area->x1 >> 8) & 0xFF; - data[1] = area->x1 & 0xFF; - data[2] = (area->x2 >> 8) & 0xFF; - data[3] = area->x2 & 0xFF; - ili9341_send_data(data, 4); +#if LV_COLOR_DEPTH == 16 + /* Each pixel is 2bytes */ + size *= 2; +#endif - /*Page addresses*/ - ili9341_send_cmd(0x2B); - data[0] = (area->y1 >> 8) & 0xFF; - data[1] = area->y1 & 0xFF; - data[2] = (area->y2 >> 8) & 0xFF; - data[3] = area->y2 & 0xFF; - ili9341_send_data(data, 4); + /*Column addresses*/ + data[0] = (area->x1 >> 8) & 0xFF; + data[1] = area->x1 & 0xFF; + data[2] = (area->x2 >> 8) & 0xFF; + data[3] = area->x2 & 0xFF; + + display_interface_send_cmd(drv, 0x2A, CMD_WIDTH_8BITS, data, sizeof(data)); - /*Memory write*/ - ili9341_send_cmd(0x2C); - uint32_t size = lv_area_get_width(area) * lv_area_get_height(area); - ili9341_send_color((void*)color_map, size * 2); + /* Page addresses */ + data[0] = (area->y1 >> 8) & 0xFF; + data[1] = area->y1 & 0xFF; + data[2] = (area->y2 >> 8) & 0xFF; + data[3] = area->y2 & 0xFF; + + display_interface_send_cmd(drv, 0x2B, CMD_WIDTH_8BITS, data, sizeof(data)); + + /* Memory write */ + display_interface_send_cmd(drv, 0x2C, CMD_WIDTH_8BITS, NULL, 0); + display_interface_send_data(drv, color_map, size); } -void ili9341_sleep_in() +void ili9341_sleep_in(lv_disp_drv_t * drv) { - uint8_t data[] = {0x08}; - ili9341_send_cmd(0x10); - ili9341_send_data(&data, 1); + uint8_t data[] = {0x08}; + display_interface_send_cmd(drv, 0x10, CMD_WIDTH_8BITS, data, 1); } -void ili9341_sleep_out() +void ili9341_sleep_out(lv_disp_drv_t * drv) { - uint8_t data[] = {0x08}; - ili9341_send_cmd(0x11); - ili9341_send_data(&data, 1); + uint8_t data[] = {0x08}; + display_interface_send_cmd(drv, 0x11, CMD_WIDTH_8BITS, data, 1); } /********************** * STATIC FUNCTIONS **********************/ - - -static void ili9341_send_cmd(uint8_t cmd) +static void ili9341_set_orientation(lv_disp_drv_t *drv, uint8_t orientation) { - disp_wait_for_pending_transactions(); - gpio_set_level(ILI9341_DC, 0); /*Command mode*/ - disp_spi_send_data(&cmd, 1); -} - -static void ili9341_send_data(void * data, uint16_t length) -{ - disp_wait_for_pending_transactions(); - gpio_set_level(ILI9341_DC, 1); /*Data mode*/ - disp_spi_send_data(data, length); -} - -static void ili9341_send_color(void * data, uint16_t length) -{ - disp_wait_for_pending_transactions(); - gpio_set_level(ILI9341_DC, 1); /*Data mode*/ - disp_spi_send_colors(data, length); -} - -static void ili9341_set_orientation(uint8_t orientation) -{ - // ESP_ASSERT(orientation < 4); - - const char *orientation_str[] = { - "PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED" - }; - - ESP_LOGI(TAG, "Display orientation: %s", orientation_str[orientation]); + assert(orientation < 4); #if defined CONFIG_LV_PREDEFINED_DISPLAY_M5STACK - uint8_t data[] = {0x68, 0x68, 0x08, 0x08}; + const uint8_t data[] = {0x68, 0x68, 0x08, 0x08}; #elif defined (CONFIG_LV_PREDEFINED_DISPLAY_M5CORE2) - uint8_t data[] = {0x08, 0x88, 0x28, 0xE8}; + const 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}; + const uint8_t data[] = {0x6C, 0xEC, 0xCC, 0x4C}; +#else + const uint8_t data[] = {0x48, 0x88, 0x28, 0xE8}; #endif - ESP_LOGI(TAG, "0x36 command value: 0x%02X", data[orientation]); - - ili9341_send_cmd(0x36); - ili9341_send_data((void *) &data[orientation], 1); + display_interface_send_cmd(drv, MEMORY_ACCESS_CONTROL_REG, CMD_WIDTH_8BITS, &data[orientation], 1); +} + +/* Reset the display, if we don't have a reset pin we use software reset */ +static void ili9341_reset(lv_disp_drv_t *drv) +{ +#if defined(ILI9341_USE_RST) + display_port_gpio_rst(drv, 0); + display_port_delay(drv, 100); + display_port_gpio_rst(drv, 1); + display_port_delay(drv, 100); +#else + display_interface_send_cmd(drv, SOFTWARE_RESET_REG, CMD_WIDTH_8BITS, NULL, 0); + display_port_delay(drv, 5); +#endif } diff --git a/lvgl_tft/ili9341.h b/lvgl_tft/ili9341.h index 62317e8..0f8c58b 100644 --- a/lvgl_tft/ili9341.h +++ b/lvgl_tft/ili9341.h @@ -13,23 +13,17 @@ extern "C" { /********************* * INCLUDES *********************/ -#include - #ifdef LV_LVGL_H_INCLUDE_SIMPLE #include "lvgl.h" #else #include "lvgl/lvgl.h" #endif -#include "sdkconfig.h" +#include "display_config.h" /********************* * DEFINES *********************/ -#define ILI9341_DC CONFIG_LV_DISP_PIN_DC -#define ILI9341_USE_RST CONFIG_LV_DISP_USE_RST -#define ILI9341_RST CONFIG_LV_DISP_PIN_RST -#define ILI9341_INVERT_COLORS CONFIG_LV_INVERT_COLORS /********************** * TYPEDEFS @@ -39,10 +33,10 @@ extern "C" { * GLOBAL PROTOTYPES **********************/ -void ili9341_init(void); +void ili9341_init(lv_disp_drv_t * drv); void ili9341_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map); -void ili9341_sleep_in(void); -void ili9341_sleep_out(void); +void ili9341_sleep_in(lv_disp_drv_t * drv); +void ili9341_sleep_out(lv_disp_drv_t *drv); /********************** * MACROS diff --git a/lvgl_tft/ili9481.c b/lvgl_tft/ili9481.c index 74bda98..a599059 100644 --- a/lvgl_tft/ili9481.c +++ b/lvgl_tft/ili9481.c @@ -8,16 +8,13 @@ #include "ili9481.h" #include "disp_spi.h" #include "driver/gpio.h" -#include "esp_log.h" #include "esp_heap_caps.h" - #include "freertos/FreeRTOS.h" #include "freertos/task.h" /********************* * DEFINES *********************/ - #define TAG "ILI9481" /********************** * TYPEDEFS @@ -88,7 +85,7 @@ void ili9481_init(void) vTaskDelay(100 / portTICK_RATE_MS); #endif - ESP_LOGI(TAG, "ILI9481 initialization."); + LV_LOG_INFO("Initialization."); // Exit sleep ili9481_send_cmd(0x01); /* Software reset */ @@ -117,7 +114,7 @@ void ili9481_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col uint8_t *mybuf; do { mybuf = (uint8_t *) heap_caps_malloc(3 * size * sizeof(uint8_t), MALLOC_CAP_DMA); - if (mybuf == NULL) ESP_LOGW(TAG, "Could not allocate enough DMA memory!"); + if (mybuf == NULL) LV_LOG_WARN("Could not allocate enough DMA memory!"); } while (mybuf == NULL); uint32_t LD = 0; @@ -196,7 +193,7 @@ static void ili9481_set_orientation(uint8_t orientation) "PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED" }; - ESP_LOGI(TAG, "Display orientation: %s", orientation_str[orientation]); + LV_LOG_INFO("Display orientation: %s", orientation_str[orientation]); uint8_t data[] = {0x48, 0x4B, 0x28, 0x2B}; ili9481_send_cmd(ILI9481_CMD_MEMORY_ACCESS_CONTROL); diff --git a/lvgl_tft/ili9486.c b/lvgl_tft/ili9486.c index 829f0bd..b4e3a0a 100644 --- a/lvgl_tft/ili9486.c +++ b/lvgl_tft/ili9486.c @@ -9,14 +9,12 @@ #include "ili9486.h" #include "disp_spi.h" #include "driver/gpio.h" -#include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" /********************* * DEFINES *********************/ - #define TAG "ILI9486" /********************** * TYPEDEFS @@ -80,7 +78,7 @@ void ili9486_init(void) vTaskDelay(100 / portTICK_RATE_MS); #endif - ESP_LOGI(TAG, "ILI9486 Initialization."); + LV_LOG_INFO("ILI9486 Initialization."); //Send all the commands uint16_t cmd = 0; @@ -165,19 +163,17 @@ static void ili9486_send_color(void * data, uint16_t length) static void ili9486_set_orientation(uint8_t orientation) { - // ESP_ASSERT(orientation < 4); + assert(orientation < 4); const char *orientation_str[] = { "PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED" }; - ESP_LOGI(TAG, "Display orientation: %s", orientation_str[orientation]); + LV_LOG_INFO("Display orientation: %s", orientation_str[orientation]); -#if defined (CONFIG_LV_PREDEFINED_DISPLAY_NONE) - uint8_t data[] = {0x48, 0x88, 0x28, 0xE8}; -#endif + const uint8_t data[] = {0x48, 0x88, 0x28, 0xE8}; - ESP_LOGI(TAG, "0x36 command value: 0x%02X", data[orientation]); + LV_LOG_INFO("0x36 command value: 0x%02X", data[orientation]); ili9486_send_cmd(0x36); ili9486_send_data((void *) &data[orientation], 1); diff --git a/lvgl_tft/ili9488.c b/lvgl_tft/ili9488.c index feb9fba..1f67391 100644 --- a/lvgl_tft/ili9488.c +++ b/lvgl_tft/ili9488.c @@ -6,18 +6,14 @@ * INCLUDES *********************/ #include "ili9488.h" -#include "disp_spi.h" -#include "driver/gpio.h" -#include "esp_log.h" -#include "esp_heap_caps.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" +#include "disp_spi.h" +#include "display_port.h" +#include "esp_heap_caps.h" /********************* * DEFINES *********************/ - #define TAG "ILI9488" /********************** * TYPEDEFS @@ -33,11 +29,12 @@ typedef struct { /********************** * STATIC PROTOTYPES **********************/ -static void ili9488_set_orientation(uint8_t orientation); +static void ili9488_set_orientation(lv_disp_drv_t * drv, uint8_t orientation); -static void ili9488_send_cmd(uint8_t cmd); -static void ili9488_send_data(void * data, uint16_t length); -static void ili9488_send_color(void * data, uint16_t length); +static void ili9488_send_cmd(lv_disp_drv_t * drv, uint8_t cmd); +static void ili9488_send_data(lv_disp_drv_t * drv, void * data, uint16_t length); +static void ili9488_send_color(lv_disp_drv_t * drv, void * data, uint16_t length); +static void ili9488_reset(lv_disp_drv_t * drv); /********************** * STATIC VARIABLES @@ -52,62 +49,47 @@ static void ili9488_send_color(void * data, uint16_t length); **********************/ // From github.com/jeremyjh/ESP32_TFT_library // From github.com/mvturnho/ILI9488-lvgl-ESP32-WROVER-B -void ili9488_init(void) +void ili9488_init(lv_disp_drv_t * drv) { - lcd_init_cmd_t ili_init_cmds[]={ - {ILI9488_CMD_SLEEP_OUT, {0x00}, 0x80}, - {ILI9488_CMD_POSITIVE_GAMMA_CORRECTION, {0x00, 0x03, 0x09, 0x08, 0x16, 0x0A, 0x3F, 0x78, 0x4C, 0x09, 0x0A, 0x08, 0x16, 0x1A, 0x0F}, 15}, - {ILI9488_CMD_NEGATIVE_GAMMA_CORRECTION, {0x00, 0x16, 0x19, 0x03, 0x0F, 0x05, 0x32, 0x45, 0x46, 0x04, 0x0E, 0x0D, 0x35, 0x37, 0x0F}, 15}, - {ILI9488_CMD_POWER_CONTROL_1, {0x17, 0x15}, 2}, - {ILI9488_CMD_POWER_CONTROL_2, {0x41}, 1}, - {ILI9488_CMD_VCOM_CONTROL_1, {0x00, 0x12, 0x80}, 3}, - {ILI9488_CMD_MEMORY_ACCESS_CONTROL, {(0x20 | 0x08)}, 1}, - {ILI9488_CMD_COLMOD_PIXEL_FORMAT_SET, {0x66}, 1}, - {ILI9488_CMD_INTERFACE_MODE_CONTROL, {0x00}, 1}, - {ILI9488_CMD_FRAME_RATE_CONTROL_NORMAL, {0xA0}, 1}, - {ILI9488_CMD_DISPLAY_INVERSION_CONTROL, {0x02}, 1}, - {ILI9488_CMD_DISPLAY_FUNCTION_CONTROL, {0x02, 0x02}, 2}, - {ILI9488_CMD_SET_IMAGE_FUNCTION, {0x00}, 1}, - {ILI9488_CMD_WRITE_CTRL_DISPLAY, {0x28}, 1}, - {ILI9488_CMD_WRITE_DISPLAY_BRIGHTNESS, {0x7F}, 1}, - {ILI9488_CMD_ADJUST_CONTROL_3, {0xA9, 0x51, 0x2C, 0x02}, 4}, - {ILI9488_CMD_DISPLAY_ON, {0x00}, 0x80}, - {0, {0}, 0xff}, - }; + lcd_init_cmd_t ili_init_cmds[]={ + {ILI9488_CMD_SLEEP_OUT, {0x00}, 0x80}, + {ILI9488_CMD_POSITIVE_GAMMA_CORRECTION, {0x00, 0x03, 0x09, 0x08, 0x16, 0x0A, 0x3F, 0x78, 0x4C, 0x09, 0x0A, 0x08, 0x16, 0x1A, 0x0F}, 15}, + {ILI9488_CMD_NEGATIVE_GAMMA_CORRECTION, {0x00, 0x16, 0x19, 0x03, 0x0F, 0x05, 0x32, 0x45, 0x46, 0x04, 0x0E, 0x0D, 0x35, 0x37, 0x0F}, 15}, + {ILI9488_CMD_POWER_CONTROL_1, {0x17, 0x15}, 2}, + {ILI9488_CMD_POWER_CONTROL_2, {0x41}, 1}, + {ILI9488_CMD_VCOM_CONTROL_1, {0x00, 0x12, 0x80}, 3}, + {ILI9488_CMD_MEMORY_ACCESS_CONTROL, {(0x20 | 0x08)}, 1}, + {ILI9488_CMD_COLMOD_PIXEL_FORMAT_SET, {0x66}, 1}, + {ILI9488_CMD_INTERFACE_MODE_CONTROL, {0x00}, 1}, + {ILI9488_CMD_FRAME_RATE_CONTROL_NORMAL, {0xA0}, 1}, + {ILI9488_CMD_DISPLAY_INVERSION_CONTROL, {0x02}, 1}, + {ILI9488_CMD_DISPLAY_FUNCTION_CONTROL, {0x02, 0x02}, 2}, + {ILI9488_CMD_SET_IMAGE_FUNCTION, {0x00}, 1}, + {ILI9488_CMD_WRITE_CTRL_DISPLAY, {0x28}, 1}, + {ILI9488_CMD_WRITE_DISPLAY_BRIGHTNESS, {0x7F}, 1}, + {ILI9488_CMD_ADJUST_CONTROL_3, {0xA9, 0x51, 0x2C, 0x02}, 4}, + {ILI9488_CMD_DISPLAY_ON, {0x00}, 0x80}, + {0, {0}, 0xff}, + }; - //Initialize non-SPI GPIOs - gpio_pad_select_gpio(ILI9488_DC); - gpio_set_direction(ILI9488_DC, GPIO_MODE_OUTPUT); + ili9488_reset(drv); -#if ILI9488_USE_RST - gpio_pad_select_gpio(ILI9488_RST); - gpio_set_direction(ILI9488_RST, GPIO_MODE_OUTPUT); + LV_LOG_INFO("ILI9488 initialization."); - //Reset the display - gpio_set_level(ILI9488_RST, 0); - vTaskDelay(100 / portTICK_RATE_MS); - gpio_set_level(ILI9488_RST, 1); - vTaskDelay(100 / portTICK_RATE_MS); -#endif + //Send all the commands + uint16_t cmd = 0; + while (ili_init_cmds[cmd].databytes!=0xff) { + ili9488_send_cmd(drv, ili_init_cmds[cmd].cmd); + ili9488_send_data(drv, ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes&0x1F); + + if (ili_init_cmds[cmd].databytes & 0x80) { + display_port_delay(drv, 100); + } - ESP_LOGI(TAG, "ILI9488 initialization."); + cmd++; + } - // Exit sleep - ili9488_send_cmd(0x01); /* Software reset */ - vTaskDelay(100 / portTICK_RATE_MS); - - //Send all the commands - uint16_t cmd = 0; - while (ili_init_cmds[cmd].databytes!=0xff) { - ili9488_send_cmd(ili_init_cmds[cmd].cmd); - ili9488_send_data(ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes&0x1F); - if (ili_init_cmds[cmd].databytes & 0x80) { - vTaskDelay(100 / portTICK_RATE_MS); - } - cmd++; - } - - ili9488_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION); + ili9488_set_orientation(drv, ILI9488_INITIAL_ORIENTATION); } // Flush function based on mvturnho repo @@ -119,7 +101,9 @@ void ili9488_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col uint8_t *mybuf; do { mybuf = (uint8_t *) heap_caps_malloc(3 * size * sizeof(uint8_t), MALLOC_CAP_DMA); - if (mybuf == NULL) ESP_LOGW(TAG, "Could not allocate enough DMA memory!"); + if (mybuf == NULL) { + LV_LOG_WARN("Could not allocate enough DMA memory!"); + } } while (mybuf == NULL); uint32_t LD = 0; @@ -152,17 +136,17 @@ void ili9488_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col }; /*Column addresses*/ - ili9488_send_cmd(ILI9488_CMD_COLUMN_ADDRESS_SET); - ili9488_send_data(xb, 4); + ili9488_send_cmd(drv, ILI9488_CMD_COLUMN_ADDRESS_SET); + ili9488_send_data(drv, xb, 4); /*Page addresses*/ - ili9488_send_cmd(ILI9488_CMD_PAGE_ADDRESS_SET); - ili9488_send_data(yb, 4); + ili9488_send_cmd(drv, ILI9488_CMD_PAGE_ADDRESS_SET); + ili9488_send_data(drv, yb, 4); /*Memory write*/ - ili9488_send_cmd(ILI9488_CMD_MEMORY_WRITE); + ili9488_send_cmd(drv, ILI9488_CMD_MEMORY_WRITE); - ili9488_send_color((void *) mybuf, size * 3); + ili9488_send_color(drv, (void *) mybuf, size * 3); heap_caps_free(mybuf); } @@ -170,44 +154,65 @@ void ili9488_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col * STATIC FUNCTIONS **********************/ +static inline void set_cmd_mode(lv_disp_drv_t * drv) +{ + display_port_gpio_dc(drv, 0); +} -static void ili9488_send_cmd(uint8_t cmd) +static inline void set_data_mode(lv_disp_drv_t * drv) +{ + display_port_gpio_dc(drv, 1); +} + +static void ili9488_send_cmd(lv_disp_drv_t * drv, uint8_t cmd) { disp_wait_for_pending_transactions(); - gpio_set_level(ILI9488_DC, 0); /*Command mode*/ + set_cmd_mode(drv); disp_spi_send_data(&cmd, 1); } -static void ili9488_send_data(void * data, uint16_t length) +static void ili9488_send_data(lv_disp_drv_t * drv, void * data, uint16_t length) { disp_wait_for_pending_transactions(); - gpio_set_level(ILI9488_DC, 1); /*Data mode*/ + set_data_mode(drv); disp_spi_send_data(data, length); } -static void ili9488_send_color(void * data, uint16_t length) +static void ili9488_send_color(lv_disp_drv_t * drv, void * data, uint16_t length) { disp_wait_for_pending_transactions(); - gpio_set_level(ILI9488_DC, 1); /*Data mode*/ + set_data_mode(drv); disp_spi_send_colors(data, length); } -static void ili9488_set_orientation(uint8_t orientation) +static void ili9488_set_orientation(lv_disp_drv_t * drv, uint8_t orientation) { - // ESP_ASSERT(orientation < 4); + assert(orientation < 4); const char *orientation_str[] = { "PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED" }; - ESP_LOGI(TAG, "Display orientation: %s", orientation_str[orientation]); + LV_LOG_INFO("Display orientation: %s", orientation_str[orientation]); -#if defined (CONFIG_LV_PREDEFINED_DISPLAY_NONE) - uint8_t data[] = {0x48, 0x88, 0x28, 0xE8}; -#endif + const uint8_t data[] = {0x48, 0x88, 0x28, 0xE8}; - ESP_LOGI(TAG, "0x36 command value: 0x%02X", data[orientation]); + LV_LOG_INFO("0x36 command value: 0x%02X", data[orientation]); - ili9488_send_cmd(0x36); - ili9488_send_data((void *) &data[orientation], 1); + ili9488_send_cmd(drv, 0x36); + ili9488_send_data(drv, (void *) &data[orientation], 1); +} + +/* Reset the display, if we don't have a reset pin we use software reset */ +static void ili9488_reset(lv_disp_drv_t *drv) +{ +#if defined(ILI9488_USE_RST) + display_port_gpio_rst(drv, 0); + display_port_delay(drv, 100); + display_port_gpio_rst(drv, 1); + display_port_delay(drv, 100); +#else + ili9341_send_cmd(drv, 0x01); + display_port_delay(drv, 5); +#endif } diff --git a/lvgl_tft/ili9488.h b/lvgl_tft/ili9488.h index 1c6c6f9..fd393b8 100644 --- a/lvgl_tft/ili9488.h +++ b/lvgl_tft/ili9488.h @@ -20,14 +20,13 @@ extern "C" { #else #include "lvgl/lvgl.h" #endif + #include "../lvgl_helpers.h" +#include "display_config.h" /********************* * DEFINES *********************/ -#define ILI9488_DC CONFIG_LV_DISP_PIN_DC -#define ILI9488_RST CONFIG_LV_DISP_PIN_RST -#define ILI9488_USE_RST CONFIG_LV_DISP_USE_RSTS /******************* * ILI9488 REGS @@ -144,7 +143,7 @@ typedef struct { * GLOBAL PROTOTYPES **********************/ -void ili9488_init(void); +void ili9488_init(lv_disp_drv_t * drv); void ili9488_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map); /********************** diff --git a/lvgl_tft/jd79653a.c b/lvgl_tft/jd79653a.c index 0f4be67..f71b673 100644 --- a/lvgl_tft/jd79653a.c +++ b/lvgl_tft/jd79653a.c @@ -29,17 +29,18 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include #include #include -#include #include "disp_spi.h" #include "jd79653a.h" -#define TAG "lv_jd79653a" - #define PIN_DC CONFIG_LV_DISP_PIN_DC #define PIN_DC_BIT ((1ULL << (uint8_t)(CONFIG_LV_DISP_PIN_DC))) + +#if defined CONFIG_LV_DISP_PIN_RST #define PIN_RST CONFIG_LV_DISP_PIN_RST #define PIN_RST_BIT ((1ULL << (uint8_t)(CONFIG_LV_DISP_PIN_RST))) +#endif + #define PIN_BUSY CONFIG_LV_DISP_PIN_BUSY #define PIN_BUSY_BIT ((1ULL << (uint8_t)(CONFIG_LV_DISP_PIN_BUSY))) #define EVT_BUSY (1UL << 0UL) @@ -123,10 +124,9 @@ static const uint8_t lut_bb1[] = { static const jd79653a_seq_t init_seq[] = { #if defined (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED) {0x00, {0xd3, 0x0e}, 2}, // Panel settings -#elif defined(CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT) - {0x00, {0xdf, 0x0e}, 2}, // Panel settings +//#elif defined(CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT) #else -#error "Unsupported orientation - only portrait modes are supported for now" + {0x00, {0xdf, 0x0e}, 2}, // Panel settings #endif {0x4d, {0x55}, 1}, // Undocumented secret from demo code {0xaa, {0x0f}, 1}, // Undocumented secret from demo code @@ -185,7 +185,7 @@ static void jd79653a_spi_send_fb(uint8_t *data, size_t len) static void jd79653a_spi_send_seq(const jd79653a_seq_t *seq, size_t len) { - ESP_LOGD(TAG, "Writing cmd/data sequence, count %u", len); + LV_LOG_INFO("Writing cmd/data sequence, count %u", len); if (!seq || len < 1) return; for (size_t cmd_idx = 0; cmd_idx < len; cmd_idx++) { @@ -241,7 +241,7 @@ static void jd79653a_load_partial_lut() static void jd79653a_partial_in() { - ESP_LOGD(TAG, "Partial in!"); + LV_LOG_INFO("Partial in!"); // Panel setting: accept LUT from registers instead of OTP #if defined (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED) @@ -249,7 +249,8 @@ static void jd79653a_partial_in() #elif defined(CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT) uint8_t pst_use_reg_lut[] = { 0xff, 0x0e }; #else -#error "Unsupported orientation - only portrait modes are supported for now" + assert(false); // Unsupported orientation configured. Crash if we get here, but allow compilation for CI + uint8_t pst_use_reg_lut[] = { 0,0 }; #endif jd79653a_spi_send_cmd(0x00); jd79653a_spi_send_data(pst_use_reg_lut, sizeof(pst_use_reg_lut)); @@ -268,7 +269,7 @@ static void jd79653a_partial_in() static void jd79653a_partial_out() { - ESP_LOGD(TAG, "Partial out!"); + LV_LOG_INFO("Partial out!"); // Panel setting: use LUT from OTP #if defined (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED) @@ -276,7 +277,8 @@ static void jd79653a_partial_out() #elif defined(CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT) uint8_t pst_use_otp_lut[] = { 0xdf, 0x0e }; #else -#error "Unsupported orientation - only portrait modes are supported for now" + assert(false); // Unsupported orientation configured. Crash if we get here, but allow compilation for CI + uint8_t pst_use_otp_lut[] = { 0,0 }; #endif jd79653a_spi_send_cmd(0x00); jd79653a_spi_send_data(pst_use_otp_lut, sizeof(pst_use_otp_lut)); @@ -294,10 +296,10 @@ static void jd79653a_update_partial(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t { jd79653a_power_on(); jd79653a_partial_in(); - ESP_LOGD(TAG, "x1: 0x%x, x2: 0x%x, y1: 0x%x, y2: 0x%x", x1, x2, y1, y2); + LV_LOG_INFO("x1: 0x%x, x2: 0x%x, y1: 0x%x, y2: 0x%x", x1, x2, y1, y2); size_t len = ((x2 - x1 + 1) * (y2 - y1 + 1)) / 8; - ESP_LOGD(TAG, "Writing PARTIAL LVGL fb with len: %u", len); + LV_LOG_INFO("Writing PARTIAL LVGL fb with len: %u", len); // Set partial window uint8_t ptl_setting[7] = { x1, x2, 0, y1, 0, y2, 0x01 }; @@ -313,16 +315,18 @@ static void jd79653a_update_partial(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t len -= EPD_ROW_LEN; } - ESP_LOGD(TAG, "Partial wait start"); + LV_LOG_INFO("Partial wait start"); jd79653a_spi_send_cmd(0x12); jd79653a_wait_busy(0); - ESP_LOGD(TAG, "Partial updated"); + LV_LOG_INFO("Partial updated"); jd79653a_partial_out(); jd79653a_power_off(); } +static void jd79653a_reset(void); + void jd79653a_fb_set_full_color(uint8_t color) { jd79653a_power_on(); @@ -353,7 +357,7 @@ void jd79653a_fb_set_full_color(uint8_t color) void jd79653a_fb_full_update(uint8_t *data, size_t len) { jd79653a_power_on(); - ESP_LOGD(TAG, "Performing full update, len: %u", len); + LV_LOG_INFO("Performing full update, len: %u", len); uint8_t *data_ptr = data; @@ -372,7 +376,7 @@ void jd79653a_fb_full_update(uint8_t *data, size_t len) len -= EPD_ROW_LEN; } - ESP_LOGD(TAG, "Rest len: %u", len); + LV_LOG_INFO("Rest len: %u", len); jd79653a_spi_send_cmd(0x12); // Issue refresh command vTaskDelay(pdMS_TO_TICKS(100)); @@ -407,13 +411,13 @@ void jd79653a_lv_fb_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t { size_t len = ((area->x2 - area->x1 + 1) * (area->y2 - area->y1 + 1)) / 8; - ESP_LOGD(TAG, "x1: 0x%x, x2: 0x%x, y1: 0x%x, y2: 0x%x", area->x1, area->x2, area->y1, area->y2); - ESP_LOGD(TAG, "Writing LVGL fb with len: %u, partial counter: %u", len, partial_counter); + LV_LOG_INFO("x1: 0x%x, x2: 0x%x, y1: 0x%x, y2: 0x%x", area->x1, area->x2, area->y1, area->y2); + LV_LOG_INFO("Writing LVGL fb with len: %u, partial counter: %u", len, partial_counter); uint8_t *buf = (uint8_t *) color_map; if (partial_counter == 0) { - ESP_LOGD(TAG, "Refreshing in FULL"); + LV_LOG_INFO("Refreshing in FULL"); jd79653a_fb_full_update(buf, ((EPD_HEIGHT * EPD_WIDTH) / 8)); partial_counter = EPD_PARTIAL_CNT; // Reset partial counter here } else { @@ -439,20 +443,10 @@ void jd79653a_init() // Initialise event group jd79653a_evts = xEventGroupCreate(); if (!jd79653a_evts) { - ESP_LOGE(TAG, "Failed when initialising event group!"); + LV_LOG_ERROR("Failed when initialising event group!"); return; } - // Setup output pins, output (PP) - gpio_config_t out_io_conf = { - .intr_type = GPIO_INTR_DISABLE, - .mode = GPIO_MODE_OUTPUT, - .pin_bit_mask = PIN_DC_BIT | PIN_RST_BIT, - .pull_down_en = 0, - .pull_up_en = 0, - }; - ESP_ERROR_CHECK(gpio_config(&out_io_conf)); - // Setup input pin, pull-up, input gpio_config_t in_io_conf = { .intr_type = GPIO_INTR_POSEDGE, @@ -465,18 +459,25 @@ void jd79653a_init() gpio_install_isr_service(0); gpio_isr_handler_add(PIN_BUSY, jd79653a_busy_intr, (void *) PIN_BUSY); - // Hardware reset - gpio_set_level(PIN_RST, 0); - vTaskDelay(pdMS_TO_TICKS(15)); // At least 10ms, leave 15ms for now just in case... - gpio_set_level(PIN_RST, 1); - vTaskDelay(pdMS_TO_TICKS(120)); + jd79653a_reset(); // Dump in initialise sequence jd79653a_spi_send_seq(init_seq, EPD_SEQ_LEN(init_seq)); - ESP_LOGI(TAG, "Panel init sequence sent"); + LV_LOG_INFO("Panel init sequence sent"); // Check BUSY status here jd79653a_wait_busy(0); - ESP_LOGI(TAG, "Panel is up!"); + LV_LOG_INFO("Panel is up!"); +} + +static void jd79653a_reset(void) +{ +#if defined CONFIG_LV_DISP_PIN_RST + gpio_set_level(PIN_RST, 0); + // At least 10ms, leave 15ms for now just in case... + vTaskDelay(pdMS_TO_TICKS(15)); + gpio_set_level(PIN_RST, 1); + vTaskDelay(pdMS_TO_TICKS(120)); +#endif } diff --git a/lvgl_tft/ra8875.c b/lvgl_tft/ra8875.c index b4f8e2a..7021a45 100644 --- a/lvgl_tft/ra8875.c +++ b/lvgl_tft/ra8875.c @@ -9,16 +9,12 @@ #include "ra8875.h" #include "disp_spi.h" #include "driver/gpio.h" -#include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" /********************* * DEFINES *********************/ -#define DEBUG false -#define TAG "RA8875" - #define DIV_ROUND_UP(n, d) (((n)+(d)-1)/(d)) #define SPI_CLOCK_SPEED_SLOW_HZ 1000000 @@ -28,13 +24,6 @@ #define RA8875_MODE_CMD_WRITE (0x80) #define RA8875_MODE_STATUS_READ (0xC0) -#if (LV_COLOR_DEPTH == 8) - #define SYSR_VAL (0x00) -#elif (LV_COLOR_DEPTH == 16) - #define SYSR_VAL (0x08) -#else - #error "Unsupported color depth (LV_COLOR_DEPTH)" -#endif #define BYTES_PER_PIXEL (LV_COLOR_DEPTH / 8) #define HDWR_VAL (LV_HOR_RES_MAX/8 - 1) @@ -43,6 +32,34 @@ #define VDIR_MASK (1 << 2) #define HDIR_MASK (1 << 3) +#ifndef CONFIG_LV_TFT_DISPLAY_CONTROLLER_RA8875 + // Use this settings if there is no Kconfig settings defined + #define SYSR_VAL (0x00) + #define DPCR_VAL (0x00) + #define PCSR_VAL (0x00) + #define HNDR_VAL (0x00) + #define HNDFTR_VAL (0x00) + #define HSTR_VAL (0x00) + #define HPW (0x00) + #define HPWR_VAL (0x00) + #define VNDR_VAL (0x00) + #define VSTR_VAL (0x00) + #define VPW (0x00) + #define VPWR_VAL (0x00) + #define CONFIG_LV_DISP_RA8875_PLLDIVM (0x00) + #define CONFIG_LV_DISP_RA8875_PLLDIVN (0x00) + #define CONFIG_LV_DISP_RA8875_PLLDIVK (0x00) + +#else + +#if (LV_COLOR_DEPTH == 8) + #define SYSR_VAL (0x00) +#elif (LV_COLOR_DEPTH == 16) + #define SYSR_VAL (0x08) +#else + #error "Unsupported color depth (LV_COLOR_DEPTH)" +#endif + #if ( CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED || CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED ) #if CONFIG_LV_INVERT_DISPLAY #define DPCR_VAL (VDIR_MASK) @@ -92,6 +109,7 @@ #else #define VPWR_VAL (VPW) #endif +#endif // CONFIG_LV_TFT_DISPLAY_CONTROLLER_RA8875 /********************** * TYPEDEFS @@ -119,6 +137,9 @@ static void ra8875_send_buffer(uint8_t * data, size_t length, bool signal_flush) void ra8875_init(void) { +#ifndef CONFIG_LV_TFT_DISPLAY_CONTROLLER_RA8875 + assert(false); // This driver is not properly configured +#endif unsigned int i = 0; struct { @@ -146,7 +167,7 @@ void ra8875_init(void) }; #define INIT_CMDS_SIZE (sizeof(init_cmds)/sizeof(init_cmds[0])) - ESP_LOGI(TAG, "Initializing RA8875..."); + LV_LOG_INFO("Initializing RA8875..."); // Initialize non-SPI GPIOs @@ -180,7 +201,7 @@ void ra8875_init(void) vTaskDelay(1); } if (i == 0) { - ESP_LOGW(TAG, "WARNING: Memory clear timed out; RA8875 may be unresponsive."); + LV_LOG_WARN("WARNING: Memory clear timed out; RA8875 may be unresponsive."); } // Enable the display @@ -189,7 +210,7 @@ void ra8875_init(void) void ra8875_enable_display(bool enable) { - ESP_LOGI(TAG, "%s display.", enable ? "Enabling" : "Disabling"); + LV_LOG_INFO("%s display.", enable ? "Enabling" : "Disabling"); uint8_t val = enable ? (0x80) : (0x00); ra8875_write_cmd(RA8875_REG_PWRR, val); // Power and Display Control Register (PWRR) } @@ -205,18 +226,14 @@ void ra8875_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo size_t linelen = (area->x2 - area->x1 + 1); uint8_t * buffer = (uint8_t*)color_map; -#if DEBUG - ESP_LOGI(TAG, "flush: %d,%d at %d,%d", area->x1, area->x2, area->y1, area->y2 ); -#endif + LV_LOG_INFO("flush: %d,%d at %d,%d", area->x1, area->x2, area->y1, area->y2 ); // Get lock disp_spi_acquire(); // Set window if needed if ((x1 != area->x1) || (x2 != area->x2)) { -#if DEBUG - ESP_LOGI(TAG, "flush: set window (x1,x2): %d,%d -> %d,%d", x1, x2, area->x1, area->x2); -#endif + LV_LOG_INFO("flush: set window (x1,x2): %d,%d -> %d,%d", x1, x2, area->x1, area->x2); ra8875_set_window(area->x1, area->x2, 0, LV_VER_RES_MAX-1); x1 = area->x1; x2 = area->x2; @@ -224,9 +241,7 @@ void ra8875_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo // Set cursor if needed if ((x != area->x1) || (y != area->y1)) { -#if DEBUG - ESP_LOGI(TAG, "flush: set cursor (x,y): %d,%d -> %d,%d", x, y, area->x1, area->y1); -#endif + LV_LOG_INFO("flush: set cursor (x,y): %d,%d -> %d,%d", x, y, area->x1, area->y1); ra8875_set_memory_write_cursor(area->x1, area->y1); x = area->x1; } diff --git a/lvgl_tft/sh1107.c b/lvgl_tft/sh1107.c index d7f6067..6f787b2 100644 --- a/lvgl_tft/sh1107.c +++ b/lvgl_tft/sh1107.c @@ -16,7 +16,6 @@ /********************* * DEFINES *********************/ - #define TAG "SH1107" /********************** * TYPEDEFS diff --git a/lvgl_tft/ssd1306.c b/lvgl_tft/ssd1306.c index 5953d44..c223eb2 100644 --- a/lvgl_tft/ssd1306.c +++ b/lvgl_tft/ssd1306.c @@ -15,18 +15,13 @@ *********************/ #include "assert.h" -#include "lvgl_i2c/i2c_manager.h" - #include "ssd1306.h" +#include "display_port.h" /********************* * DEFINES *********************/ -#define TAG "SSD1306" - -#define OLED_I2C_PORT (CONFIG_LV_I2C_DISPLAY_PORT) // SLA (0x3C) + WRITE_MODE (0x00) = 0x78 (0b01111000) -#define OLED_I2C_ADDRESS 0x3C #define OLED_WIDTH 128 #define OLED_HEIGHT 64 #define OLED_COLUMNS 128 @@ -77,8 +72,6 @@ /********************** * STATIC PROTOTYPES **********************/ -static uint8_t send_data(lv_disp_drv_t *disp_drv, void *bytes, size_t bytes_len); -static uint8_t send_pixels(lv_disp_drv_t *disp_drv, void *color_buffer, size_t buffer_len); /********************** * STATIC VARIABLES @@ -94,19 +87,19 @@ static uint8_t send_pixels(lv_disp_drv_t *disp_drv, void *color_buffer, size_t b /********************** * GLOBAL FUNCTIONS **********************/ -void ssd1306_init(void) +void ssd1306_init(lv_disp_drv_t *disp_drv) { 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 - #error "Unsupported orientation" + assert(false); // Invalid configuration of SSD1306 driver #endif uint8_t display_mode = 0; @@ -129,8 +122,7 @@ void ssd1306_init(void) OLED_CMD_DISPLAY_ON }; - uint8_t err = send_data(NULL, conf, sizeof(conf)); - assert(0 == err); + display_interface_send_cmd(disp_drv, OLED_CONTROL_BYTE_CMD_STREAM, &conf[1], sizeof(conf) - 1); } void ssd1306_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, @@ -164,10 +156,8 @@ void ssd1306_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t row2, }; - uint8_t err = send_data(disp_drv, conf, sizeof(conf)); - assert(0 == err); - err = send_pixels(disp_drv, color_p, OLED_COLUMNS * (1 + row2 - row1)); - assert(0 == err); + display_interface_send_cmd(disp_drv, OLED_CONTROL_BYTE_CMD_STREAM, &conf[1], sizeof(conf) - 1); + display_interface_send_data(disp_drv, color_p, OLED_COLUMNS * (1 + row2 - row1)); lv_disp_flush_ready(disp_drv); } @@ -190,8 +180,7 @@ void ssd1306_sleep_in(void) OLED_CMD_DISPLAY_OFF }; - uint8_t err = send_data(NULL, conf, sizeof(conf)); - assert(0 == err); + display_interface_send_cmd(NULL, OLED_CONTROL_BYTE_CMD_STREAM, &conf[1], 1); } void ssd1306_sleep_out(void) @@ -201,25 +190,5 @@ void ssd1306_sleep_out(void) OLED_CMD_DISPLAY_ON }; - uint8_t err = send_data(NULL, conf, sizeof(conf)); - assert(0 == err); -} - -/********************** - * STATIC FUNCTIONS - **********************/ -static uint8_t send_data(lv_disp_drv_t *disp_drv, void *bytes, size_t bytes_len) -{ - (void) disp_drv; - - uint8_t *data = (uint8_t *) bytes; - - return lvgl_i2c_write(OLED_I2C_PORT, OLED_I2C_ADDRESS, data[0], data + 1, bytes_len - 1 ); -} - -static uint8_t send_pixels(lv_disp_drv_t *disp_drv, void *color_buffer, size_t buffer_len) -{ - (void) disp_drv; - - return lvgl_i2c_write(OLED_I2C_PORT, OLED_I2C_ADDRESS, OLED_CONTROL_BYTE_DATA_STREAM, color_buffer, buffer_len); + display_interface_send_cmd(NULL, OLED_CONTROL_BYTE_CMD_STREAM, &conf[1], 1); } diff --git a/lvgl_tft/ssd1306.h b/lvgl_tft/ssd1306.h index 62bd0e6..ea532e9 100644 --- a/lvgl_tft/ssd1306.h +++ b/lvgl_tft/ssd1306.h @@ -34,7 +34,7 @@ extern "C" { /********************** * GLOBAL PROTOTYPES **********************/ -void ssd1306_init(void); +void ssd1306_init(lv_disp_drv_t *disp_drv); void ssd1306_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map); void ssd1306_rounder(lv_disp_drv_t * disp_drv, lv_area_t *area); void ssd1306_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, diff --git a/lvgl_tft/st7735s.c b/lvgl_tft/st7735s.c index 8be725b..0f23a29 100644 --- a/lvgl_tft/st7735s.c +++ b/lvgl_tft/st7735s.c @@ -9,7 +9,6 @@ #include "st7735s.h" #include "disp_spi.h" #include "driver/gpio.h" -#include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -20,7 +19,6 @@ /********************* * DEFINES *********************/ - #define TAG "ST7735S" #define AXP192_I2C_ADDRESS 0x34 /********************** @@ -41,10 +39,13 @@ static void st7735s_send_cmd(uint8_t cmd); static void st7735s_send_data(void * data, uint16_t length); static void st7735s_send_color(void * data, uint16_t length); static void st7735s_set_orientation(uint8_t orientation); + +#ifdef CONFIG_LV_M5STICKC_HANDLE_AXP192 static void axp192_write_byte(uint8_t addr, uint8_t data); static void axp192_init(); static void axp192_sleep_in(); static void axp192_sleep_out(); +#endif /********************** * STATIC VARIABLES @@ -112,7 +113,7 @@ void st7735s_init(void) vTaskDelay(100 / portTICK_RATE_MS); #endif - ESP_LOGI(TAG, "ST7735S initialization."); + LV_LOG_INFO("ST7735S initialization."); //Send all the commands uint16_t cmd = 0; @@ -208,7 +209,7 @@ static void st7735s_set_orientation(uint8_t orientation) "PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED" }; - ESP_LOGD(TAG, "Display orientation: %s", orientation_str[orientation]); + LV_LOG_INFO("Display orientation: %s", orientation_str[orientation]); /* Portrait: 0xC8 = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST77XX_MADCTL_BGR @@ -217,7 +218,7 @@ static void st7735s_set_orientation(uint8_t orientation) */ uint8_t data[] = {0xC8, 0xC8, 0xA8, 0xA8}; - ESP_LOGD(TAG, "0x36 command value: 0x%02X", data[orientation]); + LV_LOG_INFO("0x36 command value: 0x%02X", data[orientation]); st7735s_send_cmd(ST7735_MADCTL); st7735s_send_data((void *) &data[orientation], 1); @@ -225,33 +226,33 @@ static void st7735s_set_orientation(uint8_t orientation) #ifdef CONFIG_LV_M5STICKC_HANDLE_AXP192 - static void axp192_write_byte(uint8_t addr, uint8_t data) - { - err = lvgl_i2c_write(CONFIG_LV_I2C_DISPLAY_PORT, AXP192_I2C_ADDRESS, addr, &data, 1); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "AXP192 send failed. code: 0x%.2X", ret); - } +static void axp192_write_byte(uint8_t addr, uint8_t data) +{ + err = lvgl_i2c_write(CONFIG_LV_I2C_DISPLAY_PORT, AXP192_I2C_ADDRESS, addr, &data, 1); + if (ret != ESP_OK) { + LV_LOG_ERROR("AXP192 send failed. code: 0x%.2X", ret); } +} - static void axp192_init() - { - // information on how to init and use AXP192 ifor M5StickC taken from - // https://forum.m5stack.com/topic/1025/m5stickc-turn-off-screen-completely +static void axp192_init() +{ + // information on how to init and use AXP192 ifor M5StickC taken from + // https://forum.m5stack.com/topic/1025/m5stickc-turn-off-screen-completely - axp192_write_byte(0x10, 0xFF); // OLED_VPP Enable - axp192_write_byte(0x28, 0xCC); // Enable LDO2&LDO3, LED&TFT 3.0V - axp192_sleep_out(); - ESP_LOGI(TAG, "AXP192 initialized, power enabled for LDO2 and LDO3"); - } + axp192_write_byte(0x10, 0xFF); // OLED_VPP Enable + axp192_write_byte(0x28, 0xCC); // Enable LDO2&LDO3, LED&TFT 3.0V + axp192_sleep_out(); + LV_LOG_INFO("AXP192 initialized, power enabled for LDO2 and LDO3"); +} - static void axp192_sleep_in() - { - axp192_write_byte(0x12, 0x4b); - } +static void axp192_sleep_in() +{ + axp192_write_byte(0x12, 0x4b); +} - static void axp192_sleep_out() - { - axp192_write_byte(0x12, 0x4d); - } +static void axp192_sleep_out() +{ + axp192_write_byte(0x12, 0x4d); +} #endif diff --git a/lvgl_tft/st7789.c b/lvgl_tft/st7789.c index 962eb44..ba2889a 100644 --- a/lvgl_tft/st7789.c +++ b/lvgl_tft/st7789.c @@ -4,21 +4,15 @@ * 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_port.h" /********************* * DEFINES *********************/ -#define TAG "st7789" + /********************** * TYPEDEFS **********************/ @@ -33,10 +27,13 @@ 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_color(void *data, uint16_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(lv_disp_drv_t * drv); /********************** * STATIC VARIABLES **********************/ @@ -48,7 +45,7 @@ static void st7789_send_color(void *data, uint16_t length); /********************** * 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}, @@ -85,39 +82,21 @@ 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 - - printf("ST7789 initialization.\n"); + st7789_reset(drv); //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) { - vTaskDelay(100 / portTICK_RATE_MS); + display_port_delay(drv, 100); } cmd++; } - st7789_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION); + /* FIXME We're setting up the initial orientation in the cmd array */ + st7789_set_orientation(drv, ST7789_INITIAL_ORIENTATION); } /* The ST7789 display controller can drive 320*240 displays, when using a 240*240 @@ -131,6 +110,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; @@ -149,64 +129,66 @@ 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); - - uint32_t size = lv_area_get_width(area) * 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(); - gpio_set_level(ST7789_DC, 0); + display_port_gpio_dc(drv, 0); disp_spi_send_data(&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(); - gpio_set_level(ST7789_DC, 1); + display_port_gpio_dc(drv, 1); disp_spi_send_data(data, length); } -static void st7789_send_color(void * data, uint16_t length) +static void st7789_send_color(lv_disp_drv_t *drv, void * data, uint16_t length) { disp_wait_for_pending_transactions(); - gpio_set_level(ST7789_DC, 1); + display_port_gpio_dc(drv, 1); disp_spi_send_colors(data, length); } -static void st7789_set_orientation(uint8_t orientation) +/* Reset the display, if we don't have a reset pin we use software reset */ +static void st7789_reset(lv_disp_drv_t *drv) { - // ESP_ASSERT(orientation < 4); - - const char *orientation_str[] = { - "PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED" - }; - - ESP_LOGI(TAG, "Display orientation: %s", orientation_str[orientation]); +#if !defined(ST7789_SOFT_RST) + 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_port_delay(drv, 5); +#endif +} +static void st7789_set_orientation(lv_disp_drv_t *drv, uint8_t orientation) +{ uint8_t data[] = { #if CONFIG_LV_PREDEFINED_DISPLAY_TTGO @@ -216,8 +198,13 @@ static void st7789_set_orientation(uint8_t orientation) #endif }; - 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); +} + +/* 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; } diff --git a/lvgl_tft/st7789.h b/lvgl_tft/st7789.h index cacb31b..be86c21 100644 --- a/lvgl_tft/st7789.h +++ b/lvgl_tft/st7789.h @@ -17,22 +17,11 @@ extern "C" #else #include "lvgl/lvgl.h" #endif -#include "../lvgl_helpers.h" -#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 - #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 @@ -110,11 +99,28 @@ extern "C" #define ST7789_NVMSET 0xFC // NVM setting #define ST7789_PROMACT 0xFE // Program action -void st7789_init(void); +/** + * 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); -void st7789_send_cmd(uint8_t cmd); -void st7789_send_data(void *data, uint16_t length); +/** + * 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" */ diff --git a/lvgl_tft/st7796s.c b/lvgl_tft/st7796s.c index 7de92ef..8bc07e5 100644 --- a/lvgl_tft/st7796s.c +++ b/lvgl_tft/st7796s.c @@ -9,14 +9,12 @@ #include "st7796s.h" #include "disp_spi.h" #include "driver/gpio.h" -#include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" /********************* * DEFINES *********************/ -#define TAG "ST7796S" /********************** * TYPEDEFS @@ -96,7 +94,7 @@ void st7796s_init(void) vTaskDelay(100 / portTICK_RATE_MS); #endif - ESP_LOGI(TAG, "Initialization."); + LV_LOG_INFO("Initialization."); //Send all the commands uint16_t cmd = 0; @@ -189,24 +187,24 @@ static void st7796s_send_color(void *data, uint16_t length) static void st7796s_set_orientation(uint8_t orientation) { - // ESP_ASSERT(orientation < 4); + assert(orientation < 4); const char *orientation_str[] = { "PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED"}; - ESP_LOGI(TAG, "Display orientation: %s", orientation_str[orientation]); + LV_LOG_INFO("Display orientation: %s", orientation_str[orientation]); #if defined CONFIG_LV_PREDEFINED_DISPLAY_M5STACK - uint8_t data[] = {0x68, 0x68, 0x08, 0x08}; + const uint8_t data[] = {0x68, 0x68, 0x08, 0x08}; #elif defined(CONFIG_LV_PREDEFINED_DISPLAY_WROVER4) - uint8_t data[] = {0x4C, 0x88, 0x28, 0xE8}; + const uint8_t data[] = {0x4C, 0x88, 0x28, 0xE8}; #elif defined(CONFIG_LV_PREDEFINED_DISPLAY_WT32_SC01) - uint8_t data[] = {0x48, 0x88, 0x28, 0xE8}; -#elif defined(CONFIG_LV_PREDEFINED_DISPLAY_NONE) - uint8_t data[] = {0x48, 0x88, 0x28, 0xE8}; + const uint8_t data[] = {0x48, 0x88, 0x28, 0xE8}; +#else + const uint8_t data[] = {0x48, 0x88, 0x28, 0xE8}; #endif - ESP_LOGI(TAG, "0x36 command value: 0x%02X", data[orientation]); + LV_LOG_INFO("0x36 command value: 0x%02X", data[orientation]); st7796s_send_cmd(0x36); st7796s_send_data((void *)&data[orientation], 1); diff --git a/lvgl_tft/uc8151d.c b/lvgl_tft/uc8151d.c index d353225..91a7f7a 100644 --- a/lvgl_tft/uc8151d.c +++ b/lvgl_tft/uc8151d.c @@ -29,18 +29,19 @@ #include #include #include -#include #include "disp_spi.h" #include "disp_driver.h" #include "uc8151d.h" -#define TAG "lv_uc8151d" - #define PIN_DC CONFIG_LV_DISP_PIN_DC #define PIN_DC_BIT ((1ULL << (uint8_t)(CONFIG_LV_DISP_PIN_DC))) + +#if defined CONFIG_LV_DISP_PIN_RST #define PIN_RST CONFIG_LV_DISP_PIN_RST #define PIN_RST_BIT ((1ULL << (uint8_t)(CONFIG_LV_DISP_PIN_RST))) +#endif + #define PIN_BUSY CONFIG_LV_DISP_PIN_BUSY #define PIN_BUSY_BIT ((1ULL << (uint8_t)(CONFIG_LV_DISP_PIN_BUSY))) #define EVT_BUSY (1UL << 0UL) @@ -102,7 +103,7 @@ static void uc8151d_spi_send_fb(uint8_t *data, size_t len) static void uc8151d_spi_send_seq(const uc8151d_seq_t *seq, size_t len) { - ESP_LOGD(TAG, "Writing cmd/data sequence, count %u", len); + LV_LOG_INFO("Writing cmd/data sequence, count %u", len); if (!seq || len < 1) return; for (size_t cmd_idx = 0; cmd_idx < len; cmd_idx++) { @@ -139,14 +140,13 @@ static void uc8151d_sleep() uc8151d_spi_send_data_byte(0xa5); } +static void uc8151d_reset(void); + static void uc8151d_panel_init() { // Hardware reset for 3 times - not sure why but it's from official demo code for (uint8_t cnt = 0; cnt < 3; cnt++) { - gpio_set_level(PIN_RST, 0); - vTaskDelay(pdMS_TO_TICKS(10)); // At least 10ms, leave 20ms for now just in case... - gpio_set_level(PIN_RST, 1); - vTaskDelay(pdMS_TO_TICKS(10)); + uc8151d_reset(); } // Power up @@ -198,14 +198,14 @@ void uc8151d_lv_fb_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t * { size_t len = ((area->x2 - area->x1 + 1) * (area->y2 - area->y1 + 1)) / 8; - ESP_LOGD(TAG, "x1: 0x%x, x2: 0x%x, y1: 0x%x, y2: 0x%x", area->x1, area->x2, area->y1, area->y2); - ESP_LOGD(TAG, "Writing LVGL fb with len: %u", len); + LV_LOG_INFO("x1: 0x%x, x2: 0x%x, y1: 0x%x, y2: 0x%x", area->x1, area->x2, area->y1, area->y2); + LV_LOG_INFO("Writing LVGL fb with len: %u", len); uint8_t *buf = (uint8_t *) color_map; uc8151d_full_update(buf); lv_disp_flush_ready(drv); - ESP_LOGD(TAG, "Ready"); + LV_LOG_INFO("Ready"); } void uc8151d_lv_set_fb_cb(struct _disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, @@ -217,7 +217,7 @@ void uc8151d_lv_set_fb_cb(struct _disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t if (color.full) { BIT_SET(buf[byte_index], 7 - bit_index); } else { - ESP_LOGD(TAG, "Clear at x: %u, y: %u", x, y); + LV_LOG_INFO("Clear at x: %u, y: %u", x, y); BIT_CLEAR(buf[byte_index], 7 - bit_index); } } @@ -236,20 +236,10 @@ void uc8151d_init() // Initialise event group uc8151d_evts = xEventGroupCreate(); if (!uc8151d_evts) { - ESP_LOGE(TAG, "Failed when initialising event group!"); + LV_LOG_ERROR("Failed when initialising event group!"); return; } - // Setup output pins, output (PP) - gpio_config_t out_io_conf = { - .intr_type = GPIO_INTR_DISABLE, - .mode = GPIO_MODE_OUTPUT, - .pin_bit_mask = PIN_DC_BIT | PIN_RST_BIT, - .pull_down_en = 0, - .pull_up_en = 0, - }; - ESP_ERROR_CHECK(gpio_config(&out_io_conf)); - // Setup input pin, pull-up, input gpio_config_t in_io_conf = { .intr_type = GPIO_INTR_POSEDGE, @@ -262,7 +252,18 @@ void uc8151d_init() gpio_install_isr_service(0); gpio_isr_handler_add(PIN_BUSY, uc8151d_busy_intr, (void *) PIN_BUSY); - ESP_LOGI(TAG, "IO init finished"); + LV_LOG_INFO("IO init finished"); uc8151d_panel_init(); - ESP_LOGI(TAG, "Panel initialised"); + LV_LOG_INFO("Panel initialised"); +} + +static void uc8151d_reset(void) +{ +#if defined CONFIG_LV_DISP_USE_RST + gpio_set_level(PIN_RST, 0); + // At least 10ms, leave 20ms for now just in case... + vTaskDelay(pdMS_TO_TICKS(20)); + gpio_set_level(PIN_RST, 1); + vTaskDelay(pdMS_TO_TICKS(10)); +#endif } diff --git a/lvgl_touch/Kconfig b/lvgl_touch/Kconfig index de4d17b..b9908aa 100644 --- a/lvgl_touch/Kconfig +++ b/lvgl_touch/Kconfig @@ -201,6 +201,13 @@ menu "LVGL Touch controller" prompt "Invert Y coordinate value." default n + config LV_FT6X36_COORDINATES_QUEUE + bool + prompt "Send coordinates to FreeRTOS queue." + default n + help + Receive from the FreeRTOS queue using the handle 'ft6x36_touch_queue_handle'. + endmenu menu "Touchpanel (STMPE610) Pin Assignments" diff --git a/lvgl_touch/adcraw.c b/lvgl_touch/adcraw.c index 6170b4c..c8da1b0 100644 --- a/lvgl_touch/adcraw.c +++ b/lvgl_touch/adcraw.c @@ -12,7 +12,6 @@ #if CONFIG_LV_TOUCH_CONTROLLER_ADCRAW -#define TAG "ADCRAW" #define CALIBRATIONINSET 1 // range 0 <= CALIBRATIONINSET <= 40 #define SAMPLE_CALIBRATION_POINTS 4 // use this scale factor to avoid working in floating point numbers diff --git a/lvgl_touch/ft6x36.c b/lvgl_touch/ft6x36.c index 9e34845..b968d43 100644 --- a/lvgl_touch/ft6x36.c +++ b/lvgl_touch/ft6x36.c @@ -18,27 +18,32 @@ * SOFTWARE. */ -#include #ifdef LV_LVGL_H_INCLUDE_SIMPLE #include #else #include #endif -#include "ft6x36.h" +#include "ft6x36.h" #include "lvgl_i2c/i2c_manager.h" #define TAG "FT6X36" +#define FT6X36_TOUCH_QUEUE_ELEMENTS 1 +static ft6x36_status_t ft6x36_status; +/* Set during initialization */ +static uint8_t current_dev_addr; +/* -1 coordinates to designate it was never touched */ +static ft6x36_touch_t touch_inputs = { -1, -1, LV_INDEV_STATE_REL }; -ft6x36_status_t ft6x36_status; -uint8_t current_dev_addr; // set during init +#if CONFIG_LV_FT6X36_COORDINATES_QUEUE +QueueHandle_t ft6x36_touch_queue_handle; +#endif -esp_err_t ft6x06_i2c_read8(uint8_t slave_addr, uint8_t register_addr, uint8_t *data_buf) { +static esp_err_t ft6x06_i2c_read8(uint8_t slave_addr, uint8_t register_addr, uint8_t *data_buf) { return lvgl_i2c_read(CONFIG_LV_I2C_TOUCH_PORT, slave_addr, register_addr, data_buf, 1); } - /** * @brief Read the FT6x36 gesture ID. Initialize first! * @param dev_addr: I2C FT6x36 Slave address. @@ -46,13 +51,13 @@ esp_err_t ft6x06_i2c_read8(uint8_t slave_addr, uint8_t register_addr, uint8_t *d */ uint8_t ft6x36_get_gesture_id() { if (!ft6x36_status.inited) { - ESP_LOGE(TAG, "Init first!"); + LV_LOG_ERROR("Init first!"); return 0x00; } uint8_t data_buf; esp_err_t ret; if ((ret = ft6x06_i2c_read8(current_dev_addr, FT6X36_GEST_ID_REG, &data_buf) != ESP_OK)) - ESP_LOGE(TAG, "Error reading from device: %s", esp_err_to_name(ret)); + LV_LOG_ERROR("Error reading from device: %s", esp_err_to_name(ret)); return data_buf; } @@ -67,24 +72,33 @@ void ft6x06_init(uint16_t dev_addr) { current_dev_addr = dev_addr; uint8_t data_buf; esp_err_t ret; - ESP_LOGI(TAG, "Found touch panel controller"); + LV_LOG_INFO("Found touch panel controller"); if ((ret = ft6x06_i2c_read8(dev_addr, FT6X36_PANEL_ID_REG, &data_buf) != ESP_OK)) - ESP_LOGE(TAG, "Error reading from device: %s", + LV_LOG_ERROR("Error reading from device: %s", esp_err_to_name(ret)); // Only show error the first time - ESP_LOGI(TAG, "\tDevice ID: 0x%02x", data_buf); + LV_LOG_INFO("\tDevice ID: 0x%02x", data_buf); ft6x06_i2c_read8(dev_addr, FT6X36_CHIPSELECT_REG, &data_buf); - ESP_LOGI(TAG, "\tChip ID: 0x%02x", data_buf); + LV_LOG_INFO("\tChip ID: 0x%02x", data_buf); ft6x06_i2c_read8(dev_addr, FT6X36_DEV_MODE_REG, &data_buf); - ESP_LOGI(TAG, "\tDevice mode: 0x%02x", data_buf); + LV_LOG_INFO("\tDevice mode: 0x%02x", data_buf); ft6x06_i2c_read8(dev_addr, FT6X36_FIRMWARE_ID_REG, &data_buf); - ESP_LOGI(TAG, "\tFirmware ID: 0x%02x", data_buf); + LV_LOG_INFO("\tFirmware ID: 0x%02x", data_buf); ft6x06_i2c_read8(dev_addr, FT6X36_RELEASECODE_REG, &data_buf); - ESP_LOGI(TAG, "\tRelease code: 0x%02x", data_buf); - + LV_LOG_INFO("\tRelease code: 0x%02x", data_buf); + +#if CONFIG_LV_FT6X36_COORDINATES_QUEUE + ft6x36_touch_queue_handle = xQueueCreate( FT6X36_TOUCH_QUEUE_ELEMENTS, sizeof( ft6x36_touch_t ) ); + if( ft6x36_touch_queue_handle == NULL ) + { + LV_LOG_ERROR("\tError creating touch input FreeRTOS queue" ); + return; + } + xQueueSend( ft6x36_touch_queue_handle, &touch_inputs, 0 ); +#endif } /** @@ -95,43 +109,54 @@ void ft6x06_init(uint16_t dev_addr) { */ bool ft6x36_read(lv_indev_drv_t *drv, lv_indev_data_t *data) { if (!ft6x36_status.inited) { - ESP_LOGE(TAG, "Init first!"); + LV_LOG_ERROR("Init first!"); return 0x00; } uint8_t data_buf[5]; // 1 byte status, 2 bytes X, 2 bytes Y - static int16_t last_x = 0; // 12bit pixel value - static int16_t last_y = 0; // 12bit pixel value esp_err_t ret = lvgl_i2c_read(CONFIG_LV_I2C_TOUCH_PORT, current_dev_addr, FT6X36_TD_STAT_REG, &data_buf[0], 5); if (ret != ESP_OK) { - ESP_LOGE(TAG, "Error talking to touch IC: %s", esp_err_to_name(ret)); + LV_LOG_ERROR("Error talking to touch IC: %s", esp_err_to_name(ret)); } uint8_t touch_pnt_cnt = data_buf[0]; // Number of detected touch points if (ret != ESP_OK || touch_pnt_cnt != 1) { // ignore no touch & multi touch - data->point.x = last_x; - data->point.y = last_y; - data->state = LV_INDEV_STATE_REL; + if ( touch_inputs.current_state != LV_INDEV_STATE_REL) + { + touch_inputs.current_state = LV_INDEV_STATE_REL; +#if CONFIG_LV_FT6X36_COORDINATES_QUEUE + xQueueOverwrite( ft6x36_touch_queue_handle, &touch_inputs ); +#endif + } + data->point.x = touch_inputs.last_x; + data->point.y = touch_inputs.last_y; + data->state = touch_inputs.current_state; return false; } - last_x = ((data_buf[1] & FT6X36_MSB_MASK) << 8) | (data_buf[2] & FT6X36_LSB_MASK); - last_y = ((data_buf[3] & FT6X36_MSB_MASK) << 8) | (data_buf[4] & FT6X36_LSB_MASK); + touch_inputs.current_state = LV_INDEV_STATE_PR; + touch_inputs.last_x = ((data_buf[1] & FT6X36_MSB_MASK) << 8) | (data_buf[2] & FT6X36_LSB_MASK); + touch_inputs.last_y = ((data_buf[3] & FT6X36_MSB_MASK) << 8) | (data_buf[4] & FT6X36_LSB_MASK); +#if CONFIG_LV_FT6X36_SWAPXY + int16_t swap_buf = touch_inputs.last_x; + touch_inputs.last_x = touch_inputs.last_y; + touch_inputs.last_y = swap_buf; +#endif #if CONFIG_LV_FT6X36_INVERT_X - last_x = LV_HOR_RES - last_x; + touch_inputs.last_x = LV_HOR_RES - touch_inputs.last_x; #endif #if CONFIG_LV_FT6X36_INVERT_Y - last_y = LV_VER_RES - last_y; + touch_inputs.last_y = LV_VER_RES - touch_inputs.last_y; #endif -#if CONFIG_LV_FT6X36_SWAPXY - int16_t swap_buf = last_x; - last_x = last_y; - last_y = swap_buf; + data->point.x = touch_inputs.last_x; + data->point.y = touch_inputs.last_y; + data->state = touch_inputs.current_state; + LV_LOG_INFO("X=%u Y=%u", data->point.x, data->point.y); + +#if CONFIG_LV_FT6X36_COORDINATES_QUEUE + xQueueOverwrite( ft6x36_touch_queue_handle, &touch_inputs ); #endif - data->point.x = last_x; - data->point.y = last_y; - data->state = LV_INDEV_STATE_PR; - ESP_LOGD(TAG, "X=%u Y=%u", data->point.x, data->point.y); + return false; } diff --git a/lvgl_touch/ft6x36.h b/lvgl_touch/ft6x36.h index ace2997..c4074dc 100644 --- a/lvgl_touch/ft6x36.h +++ b/lvgl_touch/ft6x36.h @@ -23,6 +23,10 @@ #include #include +#if CONFIG_LV_FT6X36_COORDINATES_QUEUE +#include "freertos/FreeRTOS.h" +#include "freertos/queue.h" +#endif #ifdef LV_LVGL_H_INCLUDE_SIMPLE #include "lvgl.h" #else @@ -145,6 +149,16 @@ typedef struct { bool inited; } ft6x36_status_t; +typedef struct +{ + int16_t last_x; + int16_t last_y; + lv_indev_state_t current_state; +} ft6x36_touch_t; + +#if CONFIG_LV_FT6X36_COORDINATES_QUEUE +extern QueueHandle_t ft6x36_touch_queue_handle; +#endif /** * @brief Initialize for FT6x36 communication via I2C * @param dev_addr: Device address on communication Bus (I2C slave address of FT6X36). diff --git a/lvgl_touch/gt911.c b/lvgl_touch/gt911.c index 03c3d9d..112b9ac 100644 --- a/lvgl_touch/gt911.c +++ b/lvgl_touch/gt911.c @@ -18,7 +18,6 @@ * SOFTWARE. */ -#include #ifdef LV_LVGL_H_INCLUDE_SIMPLE #include #else @@ -28,8 +27,6 @@ #include "lvgl_i2c/i2c_manager.h" -#define TAG "GT911" - gt911_status_t gt911_status; //TODO: handle multibyte read and refactor to just one read transaction @@ -53,9 +50,9 @@ void gt911_init(uint8_t dev_addr) { uint8_t data_buf; esp_err_t ret; - ESP_LOGI(TAG, "Checking for GT911 Touch Controller"); + LV_LOG_INFO("Checking for GT911 Touch Controller"); if ((ret = gt911_i2c_read(dev_addr, GT911_PRODUCT_ID1, &data_buf, 1) != ESP_OK)) { - ESP_LOGE(TAG, "Error reading from device: %s", + LV_LOG_ERROR("Error reading from device: %s", esp_err_to_name(ret)); // Only show error the first time return; } @@ -64,22 +61,22 @@ void gt911_init(uint8_t dev_addr) { for (int i = 0; i < GT911_PRODUCT_ID_LEN; i++) { gt911_i2c_read(dev_addr, (GT911_PRODUCT_ID1 + i), (uint8_t *)&(gt911_status.product_id[i]), 1); } - ESP_LOGI(TAG, "\tProduct ID: %s", gt911_status.product_id); + LV_LOG_INFO("\tProduct ID: %s", gt911_status.product_id); gt911_i2c_read(dev_addr, GT911_VENDOR_ID, &data_buf, 1); - ESP_LOGI(TAG, "\tVendor ID: 0x%02x", data_buf); + LV_LOG_INFO("\tVendor ID: 0x%02x", data_buf); gt911_i2c_read(dev_addr, GT911_X_COORD_RES_L, &data_buf, 1); gt911_status.max_x_coord = data_buf; gt911_i2c_read(dev_addr, GT911_X_COORD_RES_H, &data_buf, 1); gt911_status.max_x_coord |= ((uint16_t)data_buf << 8); - ESP_LOGI(TAG, "\tX Resolution: %d", gt911_status.max_x_coord); + LV_LOG_INFO("\tX Resolution: %d", gt911_status.max_x_coord); gt911_i2c_read(dev_addr, GT911_Y_COORD_RES_L, &data_buf, 1); gt911_status.max_y_coord = data_buf; gt911_i2c_read(dev_addr, GT911_Y_COORD_RES_H, &data_buf, 1); gt911_status.max_y_coord |= ((uint16_t)data_buf << 8); - ESP_LOGI(TAG, "\tY Resolution: %d", gt911_status.max_y_coord); + LV_LOG_INFO("\tY Resolution: %d", gt911_status.max_y_coord); gt911_status.inited = true; } } @@ -98,7 +95,7 @@ bool gt911_read(lv_indev_drv_t *drv, lv_indev_data_t *data) { uint8_t status_reg; gt911_i2c_read(gt911_status.i2c_dev_addr, GT911_STATUS_REG, &status_reg, 1); -// ESP_LOGI(TAG, "\tstatus: 0x%02x", status_reg); +// LV_LOG_INFO("\tstatus: 0x%02x", status_reg); touch_pnt_cnt = status_reg & 0x0F; if ((status_reg & 0x80) || (touch_pnt_cnt < 6)) { //Reset Status Reg Value @@ -112,7 +109,7 @@ bool gt911_read(lv_indev_drv_t *drv, lv_indev_data_t *data) { } // gt911_i2c_read(gt911_status.i2c_dev_addr, GT911_TRACK_ID1, &data_buf, 1); -// ESP_LOGI(TAG, "\ttrack_id: %d", data_buf); +// LV_LOG_INFO("\ttrack_id: %d", data_buf); gt911_i2c_read(gt911_status.i2c_dev_addr, GT911_PT1_X_COORD_L, &data_buf, 1); last_x = data_buf; @@ -138,7 +135,7 @@ bool gt911_read(lv_indev_drv_t *drv, lv_indev_data_t *data) { data->point.x = last_x; data->point.y = last_y; data->state = LV_INDEV_STATE_PR; - ESP_LOGI(TAG, "X=%u Y=%u", data->point.x, data->point.y); - ESP_LOGV(TAG, "X=%u Y=%u", data->point.x, data->point.y); + LV_LOG_INFO("X=%u Y=%u", data->point.x, data->point.y); + LV_LOG_INFO("X=%u Y=%u", data->point.x, data->point.y); return false; } diff --git a/lvgl_touch/ra8875_touch.c b/lvgl_touch/ra8875_touch.c index 3340e4f..b694dcd 100644 --- a/lvgl_touch/ra8875_touch.c +++ b/lvgl_touch/ra8875_touch.c @@ -5,7 +5,6 @@ /********************* * INCLUDES *********************/ -#include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -23,7 +22,6 @@ * DEFINES *********************/ #define DEBUG false -#define TAG "RA8875-Touch" #define DIV_ROUND_UP(n, d) (((n)+(d)-1)/(d)) @@ -83,7 +81,7 @@ void ra8875_touch_init(void) }; #define INIT_CMDS_SIZE (sizeof(init_cmds)/sizeof(init_cmds[0])) - ESP_LOGI(TAG, "Initializing RA8875 Touch..."); + LV_LOG_INFO("Initializing RA8875 Touch..."); // Send all the commands for (unsigned int i = 0; i < INIT_CMDS_SIZE; i++) { @@ -94,7 +92,7 @@ void ra8875_touch_init(void) void ra8875_touch_enable(bool enable) { - ESP_LOGI(TAG, "%s touch.", enable ? "Enabling" : "Disabling"); + LV_LOG_INFO("%s touch.", enable ? "Enabling" : "Disabling"); uint8_t val = enable ? (0x80 | TPCR0_VAL) : (TPCR0_VAL); ra8875_write_cmd(RA8875_REG_TPCR0, val); } @@ -122,7 +120,7 @@ bool ra8875_touch_read(lv_indev_drv_t * drv, lv_indev_data_t * data) y = (y << 2) | ((xy >> 2) & 0x03); #if DEBUG - ESP_LOGI(TAG, "Touch Poll Raw: %d,%d", x, y); + LV_LOG_INFO("Touch Poll Raw: %d,%d", x, y); #endif // Convert to display coordinates @@ -136,7 +134,7 @@ bool ra8875_touch_read(lv_indev_drv_t * drv, lv_indev_data_t * data) data->point.y = y; #if DEBUG - ESP_LOGI(TAG, "Touch Poll - Event: %d; %d,%d", data->state, data->point.x, data->point.y); + LV_LOG_INFO("Touch Poll - Event: %d; %d,%d", data->state, data->point.x, data->point.y); #endif return false; diff --git a/lvgl_touch/stmpe610.c b/lvgl_touch/stmpe610.c index 6c5ae60..f10cc6f 100644 --- a/lvgl_touch/stmpe610.c +++ b/lvgl_touch/stmpe610.c @@ -7,7 +7,6 @@ *********************/ #include "stmpe610.h" #include "esp_system.h" -#include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "driver/gpio.h" @@ -17,8 +16,6 @@ /********************* * DEFINES *********************/ -#define TAG "STMPE610" - /********************** * TYPEDEFS @@ -55,11 +52,11 @@ void stmpe610_init(void) uint8_t u8; uint16_t u16; - ESP_LOGI(TAG, "Initialization."); + LV_LOG_INFO("Initialization."); // Get the initial SPI configuration //u8 = read_8bit_reg(STMPE_SPI_CFG); - //ESP_LOGI(TAG, "SPI_CFG = 0x%x", u8); + //LV_LOG_INFO("SPI_CFG = 0x%x", u8); // Attempt a software reset write_8bit_reg(STMPE_SYS_CTRL1, STMPE_SYS_CTRL1_RESET); @@ -69,12 +66,12 @@ void stmpe610_init(void) u8 = read_8bit_reg(STMPE_SPI_CFG); write_8bit_reg(STMPE_SPI_CFG, u8 | STMPE_SPI_CFG_AA); u8 = read_8bit_reg(STMPE_SPI_CFG); - ESP_LOGI(TAG, "SPI_CFG = 0x%x", u8); + LV_LOG_INFO("SPI_CFG = 0x%x", u8); // Verify SPI communication u16 = read_16bit_reg(STMPE_CHIP_ID); if (u16 != 0x811) { - ESP_LOGE(TAG, "Incorrect version: 0x%x", u16); + LV_LOG_ERROR("Incorrect version: 0x%x", u16); } write_8bit_reg(STMPE_SYS_CTRL2, 0x00); // Disable clocks @@ -130,12 +127,12 @@ bool stmpe610_read(lv_indev_drv_t * drv, lv_indev_data_t * data) } if (c > 0) { - //ESP_LOGI(TAG, "%d: %d %d %d", c, x, y, z); + //LV_LOG_INFO("%d: %d %d %d", c, x, y, z); adjust_data(&x, &y); last_x = x; last_y = y; - //ESP_LOGI(TAG, " ==> %d %d", x, y); + //LV_LOG_INFO(" ==> %d %d", x, y); } z = read_8bit_reg(STMPE_INT_STA); // Clear interrupts @@ -144,7 +141,7 @@ bool stmpe610_read(lv_indev_drv_t * drv, lv_indev_data_t * data) // Clear the FIFO if we discover an overflow write_8bit_reg(STMPE_FIFO_STA, STMPE_FIFO_STA_RESET); write_8bit_reg(STMPE_FIFO_STA, 0); // unreset - ESP_LOGE(TAG, "Fifo overflow"); + LV_LOG_ERROR("Fifo overflow"); } } diff --git a/lvgl_touch/xpt2046.c b/lvgl_touch/xpt2046.c index 93b4329..98a5804 100644 --- a/lvgl_touch/xpt2046.c +++ b/lvgl_touch/xpt2046.c @@ -8,7 +8,6 @@ *********************/ #include "xpt2046.h" #include "esp_system.h" -#include "esp_log.h" #include "driver/gpio.h" #include "tp_spi.h" #include @@ -16,8 +15,6 @@ /********************* * DEFINES *********************/ -#define TAG "XPT2046" - #define CMD_X_READ 0b10010000 // NOTE: XPT2046 data sheet says this is actually Y #define CMD_Y_READ 0b11010000 // NOTE: XPT2046 data sheet says this is actually X #define CMD_Z1_READ 0b10110000 @@ -59,7 +56,7 @@ uint8_t avg_last; */ void xpt2046_init(void) { - ESP_LOGI(TAG, "XPT2046 Initialization"); + LV_LOG_INFO("Initialization"); #if XPT2046_TOUCH_IRQ || XPT2046_TOUCH_IRQ_PRESS gpio_config_t irq_config = { @@ -94,19 +91,19 @@ bool xpt2046_read(lv_indev_drv_t * drv, lv_indev_data_t * data) x = xpt2046_cmd(CMD_X_READ); y = xpt2046_cmd(CMD_Y_READ); - ESP_LOGI(TAG, "P(%d,%d)", x, y); + LV_LOG_INFO("P(%d,%d)", x, y); /*Normalize Data back to 12-bits*/ x = x >> 4; y = y >> 4; - ESP_LOGI(TAG, "P_norm(%d,%d)", x, y); + LV_LOG_INFO("P_norm(%d,%d)", x, y); xpt2046_corr(&x, &y); xpt2046_avg(&x, &y); last_x = x; last_y = y; - ESP_LOGI(TAG, "x = %d, y = %d", x, y); + LV_LOG_INFO("x = %d, y = %d", x, y); } else {