Add SH8601 LCD driver and logo asset

Introduces the esp_lcd_sh8601 component with driver source, header, and configuration files. Adds a logo asset and updates project configuration and metadata to support the new display and branding.
This commit is contained in:
2026-01-13 00:09:57 +05:30
parent db572e8966
commit db70cbccaf
14 changed files with 1459 additions and 2962 deletions

View File

@@ -1,57 +1,93 @@
/*
* LVGL font rendering test
* LVGL GIF display for ESP32-S3 Touch AMOLED 1.8" (SH8601)
* Ported from ST7789 to SH8601 QSPI AMOLED display
*/
#include <stdio.h>
#include "esp_err.h"
#include "esp_log.h"
#include "esp_check.h"
#include "driver/gpio.h"
#include "driver/i2c.h"
#include "driver/spi_master.h"
#include "esp_timer.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_vendor.h"
#include "esp_lcd_panel_ops.h"
#include "esp_lvgl_port.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "esp_heap_caps.h"
#include "lvgl.h"
<<<<<<< Updated upstream
#include "src/extra/libs/gif/lv_gif.h"
#include "emotions/facetestLCD.h"
=======
#include "esp_lcd_sh8601.h"
#include "esp_lcd_touch_ft5x06.h"
>>>>>>> Stashed changes
/* LCD size */
#define LCD_H_RES (240)
#define LCD_V_RES (280)
#include "esp_io_expander_tca9554.h"
#include "../assets/logoIro.c"
/* LCD settings */
#define LCD_SPI_NUM (SPI2_HOST)
#define LCD_PIXEL_CLK_HZ (40 * 1000 * 1000)
#define LCD_CMD_BITS (8)
#define LCD_PARAM_BITS (8)
#define LCD_COLOR_SPACE (ESP_LCD_COLOR_SPACE_RGB)
#define LCD_BITS_PER_PIXEL (16)
#define LCD_DRAW_BUFF_HEIGHT (50)
/* LCD pins */
#define LCD_GPIO_SCLK (GPIO_NUM_6)
#define LCD_GPIO_MOSI (GPIO_NUM_7)
#define LCD_GPIO_RST (GPIO_NUM_8)
#define LCD_GPIO_DC (GPIO_NUM_4)
#define LCD_GPIO_CS (GPIO_NUM_5)
#define LCD_GPIO_BL (GPIO_NUM_15)
/* System enable GPIO with pullup */
#define SYS_ENABLE_GPIO ((gpio_num_t)41)
static const char *TAG = "LVGL_AMOLED";
static const char *TAG = "LVGL_FONT";
/* LCD Host */
#define LCD_HOST SPI2_HOST
#define TOUCH_HOST I2C_NUM_0
/* LCD IO and panel */
/* Color depth configuration */
#if CONFIG_LV_COLOR_DEPTH == 32
#define LCD_BIT_PER_PIXEL (24)
#elif CONFIG_LV_COLOR_DEPTH == 16
#define LCD_BIT_PER_PIXEL (16)
#else
#define LCD_BIT_PER_PIXEL (16)
#endif
/* LCD settings for ESP32-S3 Touch AMOLED 1.8" */
#define LCD_H_RES (368)
#define LCD_V_RES (448)
/* LCD QSPI pins */
#define PIN_NUM_LCD_CS (GPIO_NUM_12)
#define PIN_NUM_LCD_PCLK (GPIO_NUM_11)
#define PIN_NUM_LCD_DATA0 (GPIO_NUM_4)
#define PIN_NUM_LCD_DATA1 (GPIO_NUM_5)
#define PIN_NUM_LCD_DATA2 (GPIO_NUM_6)
#define PIN_NUM_LCD_DATA3 (GPIO_NUM_7)
#define PIN_NUM_LCD_RST (-1) /* Reset via IO expander */
#define PIN_NUM_BK_LIGHT (-1) /* Backlight via IO expander */
/* Touch I2C pins */
#define PIN_NUM_TOUCH_SCL (GPIO_NUM_14)
#define PIN_NUM_TOUCH_SDA (GPIO_NUM_15)
#define PIN_NUM_TOUCH_RST (-1) /* Reset via IO expander */
#define PIN_NUM_TOUCH_INT (GPIO_NUM_21)
/* Enable touch support */
#define USE_TOUCH 1
/* LVGL configuration */
#define LVGL_BUF_HEIGHT (LCD_V_RES / 4)
#define LVGL_TICK_PERIOD_MS 2
#define LVGL_TASK_MAX_DELAY_MS 500
#define LVGL_TASK_MIN_DELAY_MS 1
#define LVGL_TASK_STACK_SIZE (8 * 1024)
#define LVGL_TASK_PRIORITY 4
/* LCD IO and panel handles */
static esp_lcd_panel_io_handle_t lcd_io = NULL;
static esp_lcd_panel_handle_t lcd_panel = NULL;
/* LVGL display */
static lv_display_t *lvgl_disp = NULL;
#if USE_TOUCH
static esp_lcd_touch_handle_t tp = NULL;
#endif
<<<<<<< Updated upstream
static lv_obj_t *g_lvgl_gif = NULL;
static const lv_img_dsc_t g_lvgl_gif_src = {
.header.always_zero = 0,
@@ -60,160 +96,373 @@ static const lv_img_dsc_t g_lvgl_gif_src = {
.header.cf = LV_IMG_CF_RAW,
.data_size = sizeof(facetestLCD),
.data = facetestLCD,
=======
/* LVGL mutex for thread safety */
static SemaphoreHandle_t lvgl_mux = NULL;
/* LCD initialization commands for SH8601 */
static const sh8601_lcd_init_cmd_t lcd_init_cmds[] = {
{0x11, (uint8_t[]){0x00}, 0, 120},
{0x44, (uint8_t[]){0x01, 0xD1}, 2, 0},
{0x35, (uint8_t[]){0x00}, 1, 0},
{0x53, (uint8_t[]){0x20}, 1, 10},
{0x2A, (uint8_t[]){0x00, 0x00, 0x01, 0x6F}, 4, 0}, /* Column address: 0-367 */
{0x2B, (uint8_t[]){0x00, 0x00, 0x01, 0xBF}, 4, 0}, /* Row address: 0-447 */
{0x51, (uint8_t[]){0x00}, 1, 10},
{0x29, (uint8_t[]){0x00}, 0, 10},
{0x51, (uint8_t[]){0xFF}, 1, 0}, /* Max brightness */
>>>>>>> Stashed changes
};
static esp_err_t app_gif_init_lvgl(lv_obj_t *parent)
/* LVGL display driver variable (for flush callback) */
static lv_disp_drv_t disp_drv;
static bool notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
{
<<<<<<< Updated upstream
g_lvgl_gif = lv_gif_create(parent);
lv_gif_set_src(g_lvgl_gif, &g_lvgl_gif_src);
lv_obj_align(g_lvgl_gif, LV_ALIGN_CENTER, 0, 0);
return ESP_OK;
=======
lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
lv_disp_flush_ready(disp_driver);
return false;
>>>>>>> Stashed changes
}
/* FreeRTOS calls this when CONFIG_FREERTOS_USE_IDLE_HOOK=y */
void vApplicationIdleHook(void)
static void lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map)
{
/* Intentionally empty */
}
esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data;
const int offsetx1 = area->x1;
const int offsetx2 = area->x2;
const int offsety1 = area->y1;
const int offsety2 = area->y2;
static void app_gpio_init(void)
{
gpio_config_t sys_en_config = {
.pin_bit_mask = 1ULL << SYS_ENABLE_GPIO,
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = GPIO_PULLUP_ENABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE,
};
ESP_ERROR_CHECK(gpio_config(&sys_en_config));
gpio_set_level(SYS_ENABLE_GPIO, 1);
ESP_LOGI(TAG, "System enable GPIO configured");
}
#if LCD_BIT_PER_PIXEL == 24
/* Convert LVGL color format to RGB888 for 24-bit mode */
uint8_t *to = (uint8_t *)color_map;
uint8_t temp = 0;
uint16_t pixel_num = (offsetx2 - offsetx1 + 1) * (offsety2 - offsety1 + 1);
static esp_err_t app_lcd_init(void)
{
esp_err_t ret = ESP_OK;
temp = color_map[0].ch.blue;
*to++ = color_map[0].ch.red;
*to++ = color_map[0].ch.green;
*to++ = temp;
gpio_config_t bk_gpio_config = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = 1ULL << LCD_GPIO_BL,
};
ESP_ERROR_CHECK(gpio_config(&bk_gpio_config));
ESP_LOGI(TAG, "Initialize SPI bus");
const spi_bus_config_t buscfg = {
.sclk_io_num = LCD_GPIO_SCLK,
.mosi_io_num = LCD_GPIO_MOSI,
.miso_io_num = GPIO_NUM_NC,
.quadwp_io_num = GPIO_NUM_NC,
.quadhd_io_num = GPIO_NUM_NC,
.max_transfer_sz = LCD_H_RES * LCD_DRAW_BUFF_HEIGHT * sizeof(uint16_t),
};
ESP_RETURN_ON_ERROR(spi_bus_initialize(LCD_SPI_NUM, &buscfg, SPI_DMA_CH_AUTO), TAG, "SPI init failed");
ESP_LOGI(TAG, "Install panel IO");
const esp_lcd_panel_io_spi_config_t io_config = {
.dc_gpio_num = LCD_GPIO_DC,
.cs_gpio_num = LCD_GPIO_CS,
.pclk_hz = LCD_PIXEL_CLK_HZ,
.lcd_cmd_bits = LCD_CMD_BITS,
.lcd_param_bits = LCD_PARAM_BITS,
.spi_mode = 0,
.trans_queue_depth = 10,
};
ESP_GOTO_ON_ERROR(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)LCD_SPI_NUM, &io_config, &lcd_io), err, TAG, "New panel IO failed");
ESP_LOGI(TAG, "Install LCD driver");
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = LCD_GPIO_RST,
.color_space = LCD_COLOR_SPACE,
.bits_per_pixel = LCD_BITS_PER_PIXEL,
};
ESP_GOTO_ON_ERROR(esp_lcd_new_panel_st7789(lcd_io, &panel_config, &lcd_panel), err, TAG, "New panel failed");
esp_lcd_panel_reset(lcd_panel);
esp_lcd_panel_init(lcd_panel);
esp_lcd_panel_mirror(lcd_panel, true, true);
esp_lcd_panel_disp_on_off(lcd_panel, true);
ESP_ERROR_CHECK(gpio_set_level(LCD_GPIO_BL, 1));
esp_lcd_panel_set_gap(lcd_panel, 0, 20);
esp_lcd_panel_invert_color(lcd_panel, true);
return ret;
err:
if (lcd_panel) esp_lcd_panel_del(lcd_panel);
if (lcd_io) esp_lcd_panel_io_del(lcd_io);
spi_bus_free(LCD_SPI_NUM);
return ret;
}
static esp_err_t app_lvgl_init(void)
{
const lvgl_port_cfg_t lvgl_cfg = {
.task_priority = 4,
.task_stack = 8192,
.task_affinity = -1,
.task_max_sleep_ms = 500,
.timer_period_ms = 5,
};
ESP_RETURN_ON_ERROR(lvgl_port_init(&lvgl_cfg), TAG, "LVGL port initialization failed");
ESP_LOGI(TAG, "Add LCD screen");
const lvgl_port_display_cfg_t disp_cfg = {
.io_handle = lcd_io,
.panel_handle = lcd_panel,
/* Match the vendor demo sizing expression */
.buffer_size = LCD_H_RES * LCD_DRAW_BUFF_HEIGHT * sizeof(uint16_t),
.double_buffer = true,
.hres = LCD_H_RES,
.vres = LCD_V_RES,
.monochrome = false,
.rotation = {
.swap_xy = false,
.mirror_x = false,
.mirror_y = false,
},
.flags = {
.buff_dma = true,
},
};
lvgl_disp = lvgl_port_add_disp(&disp_cfg);
if (lvgl_disp == NULL) {
ESP_LOGE(TAG, "Failed to add display");
return ESP_FAIL;
for (int i = 1; i < pixel_num; i++) {
*to++ = color_map[i].ch.red;
*to++ = color_map[i].ch.green;
*to++ = color_map[i].ch.blue;
}
#endif
return ESP_OK;
esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map);
}
static void lvgl_update_cb(lv_disp_drv_t *drv)
{
esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data;
switch (drv->rotated) {
case LV_DISP_ROT_NONE:
esp_lcd_panel_swap_xy(panel_handle, false);
esp_lcd_panel_mirror(panel_handle, false, false);
break;
case LV_DISP_ROT_90:
esp_lcd_panel_swap_xy(panel_handle, true);
esp_lcd_panel_mirror(panel_handle, false, false);
break;
case LV_DISP_ROT_180:
esp_lcd_panel_swap_xy(panel_handle, false);
esp_lcd_panel_mirror(panel_handle, true, false);
break;
case LV_DISP_ROT_270:
esp_lcd_panel_swap_xy(panel_handle, true);
esp_lcd_panel_mirror(panel_handle, true, false);
break;
}
}
void lvgl_rounder_cb(struct _lv_disp_drv_t *disp_drv, lv_area_t *area)
{
/* Round coordinates to even numbers (required by SH8601) */
uint16_t x1 = area->x1;
uint16_t x2 = area->x2;
uint16_t y1 = area->y1;
uint16_t y2 = area->y2;
area->x1 = (x1 >> 1) << 1;
area->y1 = (y1 >> 1) << 1;
area->x2 = ((x2 >> 1) << 1) + 1;
area->y2 = ((y2 >> 1) << 1) + 1;
}
#if USE_TOUCH
static void lvgl_touch_cb(lv_indev_drv_t *drv, lv_indev_data_t *data)
{
esp_lcd_touch_handle_t touch_handle = (esp_lcd_touch_handle_t)drv->user_data;
assert(touch_handle);
uint16_t tp_x;
uint16_t tp_y;
uint8_t tp_cnt = 0;
esp_lcd_touch_read_data(touch_handle);
bool tp_pressed = esp_lcd_touch_get_coordinates(touch_handle, &tp_x, &tp_y, NULL, &tp_cnt, 1);
if (tp_pressed && tp_cnt > 0) {
data->point.x = tp_x;
data->point.y = tp_y;
data->state = LV_INDEV_STATE_PRESSED;
ESP_LOGD(TAG, "Touch position: %d,%d", tp_x, tp_y);
} else {
data->state = LV_INDEV_STATE_RELEASED;
}
}
#endif
static void increase_lvgl_tick(void *arg)
{
lv_tick_inc(LVGL_TICK_PERIOD_MS);
}
static bool lvgl_lock(int timeout_ms)
{
assert(lvgl_mux && "LVGL mutex not initialized");
const TickType_t timeout_ticks = (timeout_ms == -1) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms);
return xSemaphoreTake(lvgl_mux, timeout_ticks) == pdTRUE;
}
static void lvgl_unlock(void)
{
assert(lvgl_mux && "LVGL mutex not initialized");
xSemaphoreGive(lvgl_mux);
}
static void lvgl_port_task(void *arg)
{
ESP_LOGI(TAG, "Starting LVGL task");
uint32_t task_delay_ms = LVGL_TASK_MAX_DELAY_MS;
while (1) {
if (lvgl_lock(-1)) {
task_delay_ms = lv_timer_handler();
lvgl_unlock();
}
if (task_delay_ms > LVGL_TASK_MAX_DELAY_MS) {
task_delay_ms = LVGL_TASK_MAX_DELAY_MS;
} else if (task_delay_ms < LVGL_TASK_MIN_DELAY_MS) {
task_delay_ms = LVGL_TASK_MIN_DELAY_MS;
}
vTaskDelay(pdMS_TO_TICKS(task_delay_ms));
}
}
void app_main(void)
{
ESP_LOGI(TAG, "Starting LVGL font test");
app_gpio_init();
ESP_ERROR_CHECK(app_lcd_init());
ESP_ERROR_CHECK(app_lvgl_init());
/* Lock LVGL for UI creation */
lvgl_port_lock(0);
ESP_LOGI(TAG, "Starting LVGL AMOLED application");
lv_obj_t *scr = lv_scr_act();
/* Suppress some verbose logging */
esp_log_level_set("lcd_panel.io.i2c", ESP_LOG_NONE);
esp_log_level_set("FT5x06", ESP_LOG_NONE);
<<<<<<< Updated upstream
/* Background */
lv_obj_set_style_bg_color(scr, lv_color_hex(0xD6F6CD), LV_PART_MAIN);
lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, LV_PART_MAIN);
=======
static lv_disp_draw_buf_t disp_buf;
>>>>>>> Stashed changes
/* Black text samples */
/* Initialize I2C bus for touch and IO expander */
ESP_LOGI(TAG, "Initialize I2C bus");
const i2c_config_t i2c_conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = PIN_NUM_TOUCH_SDA,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_io_num = PIN_NUM_TOUCH_SCL,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = 200 * 1000,
};
ESP_ERROR_CHECK(i2c_param_config(TOUCH_HOST, &i2c_conf));
ESP_ERROR_CHECK(i2c_driver_install(TOUCH_HOST, i2c_conf.mode, 0, 0, 0));
<<<<<<< Updated upstream
ESP_ERROR_CHECK(app_gif_init_lvgl(scr));
lvgl_port_unlock();
=======
/* Initialize IO expander (TCA9554) for LCD/Touch reset and backlight */
ESP_LOGI(TAG, "Initialize IO expander");
esp_io_expander_handle_t io_expander = NULL;
ESP_ERROR_CHECK(esp_io_expander_new_i2c_tca9554(TOUCH_HOST, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000, &io_expander));
ESP_LOGI(TAG, "LVGL font test running");
/* Configure IO expander pins as outputs */
esp_io_expander_set_dir(io_expander, IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1 | IO_EXPANDER_PIN_NUM_2, IO_EXPANDER_OUTPUT);
>>>>>>> Stashed changes
/* Reset sequence: pull low then high */
esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_0, 0);
esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_1, 0);
esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_2, 0);
vTaskDelay(pdMS_TO_TICKS(200));
esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_0, 1);
esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_1, 1);
esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_2, 1);
/* Initialize QSPI bus for LCD */
ESP_LOGI(TAG, "Initialize QSPI bus");
const spi_bus_config_t buscfg = SH8601_PANEL_BUS_QSPI_CONFIG(
PIN_NUM_LCD_PCLK,
PIN_NUM_LCD_DATA0,
PIN_NUM_LCD_DATA1,
PIN_NUM_LCD_DATA2,
PIN_NUM_LCD_DATA3,
LCD_H_RES * LCD_V_RES * LCD_BIT_PER_PIXEL / 8
);
ESP_ERROR_CHECK(spi_bus_initialize(LCD_HOST, &buscfg, SPI_DMA_CH_AUTO));
/* Install panel IO */
ESP_LOGI(TAG, "Install panel IO");
const esp_lcd_panel_io_spi_config_t io_config = SH8601_PANEL_IO_QSPI_CONFIG(
PIN_NUM_LCD_CS,
notify_lvgl_flush_ready,
&disp_drv
);
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)LCD_HOST, &io_config, &lcd_io));
/* Configure vendor-specific settings */
sh8601_vendor_config_t vendor_config = {
.init_cmds = lcd_init_cmds,
.init_cmds_size = sizeof(lcd_init_cmds) / sizeof(lcd_init_cmds[0]),
.flags = {
.use_qspi_interface = 1,
},
};
/* Install SH8601 panel driver */
ESP_LOGI(TAG, "Install SH8601 panel driver");
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = PIN_NUM_LCD_RST,
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
.bits_per_pixel = LCD_BIT_PER_PIXEL,
.vendor_config = &vendor_config,
};
ESP_ERROR_CHECK(esp_lcd_new_panel_sh8601(lcd_io, &panel_config, &lcd_panel));
ESP_ERROR_CHECK(esp_lcd_panel_reset(lcd_panel));
ESP_ERROR_CHECK(esp_lcd_panel_init(lcd_panel));
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(lcd_panel, true));
#if USE_TOUCH
/* Initialize touch controller */
ESP_LOGI(TAG, "Initialize touch controller");
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG();
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)TOUCH_HOST, &tp_io_config, &tp_io_handle));
const esp_lcd_touch_config_t tp_cfg = {
.x_max = LCD_H_RES,
.y_max = LCD_V_RES,
.rst_gpio_num = PIN_NUM_TOUCH_RST,
.int_gpio_num = PIN_NUM_TOUCH_INT,
.levels = {
.reset = 0,
.interrupt = 0,
},
.flags = {
.swap_xy = 0,
.mirror_x = 0,
.mirror_y = 0,
},
};
ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_ft5x06(tp_io_handle, &tp_cfg, &tp));
#endif
/* Initialize LVGL */
ESP_LOGI(TAG, "Initialize LVGL library");
lv_init();
/* Allocate draw buffers in DMA-capable memory */
lv_color_t *buf1 = heap_caps_malloc(LCD_H_RES * LVGL_BUF_HEIGHT * sizeof(lv_color_t), MALLOC_CAP_DMA);
assert(buf1);
lv_color_t *buf2 = heap_caps_malloc(LCD_H_RES * LVGL_BUF_HEIGHT * sizeof(lv_color_t), MALLOC_CAP_DMA);
assert(buf2);
lv_disp_draw_buf_init(&disp_buf, buf1, buf2, LCD_H_RES * LVGL_BUF_HEIGHT);
/* Register display driver */
ESP_LOGI(TAG, "Register display driver");
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = LCD_H_RES;
disp_drv.ver_res = LCD_V_RES;
disp_drv.flush_cb = lvgl_flush_cb;
disp_drv.rounder_cb = lvgl_rounder_cb;
disp_drv.drv_update_cb = lvgl_update_cb;
disp_drv.draw_buf = &disp_buf;
disp_drv.user_data = lcd_panel;
lv_disp_t *disp = lv_disp_drv_register(&disp_drv);
/* Install LVGL tick timer */
ESP_LOGI(TAG, "Install LVGL tick timer");
const esp_timer_create_args_t lvgl_tick_timer_args = {
.callback = &increase_lvgl_tick,
.name = "lvgl_tick"
};
esp_timer_handle_t lvgl_tick_timer = NULL;
ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer));
ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer, LVGL_TICK_PERIOD_MS * 1000));
#if USE_TOUCH
/* Register touch input device */
ESP_LOGI(TAG, "Register touch input device");
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.disp = disp;
indev_drv.read_cb = lvgl_touch_cb;
indev_drv.user_data = tp;
lv_indev_drv_register(&indev_drv);
#endif
/* Create LVGL mutex and task */
lvgl_mux = xSemaphoreCreateMutex();
assert(lvgl_mux);
xTaskCreate(lvgl_port_task, "LVGL", LVGL_TASK_STACK_SIZE, NULL, LVGL_TASK_PRIORITY, NULL);
// Set full screen background color to #848a5d
if (lvgl_lock(-1)) {
lv_obj_t *scr = lv_scr_act();
lv_obj_set_style_bg_color(scr, lv_color_hex(0x848a5d), LV_PART_MAIN);
lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, LV_PART_MAIN);
// Create and display the logo image (scaled to cover full screen)
lv_obj_t *logo_img = lv_img_create(scr);
lv_img_set_src(logo_img, &logoIro_img);
/* Scale logo to cover the entire screen while keeping aspect ratio */
{
const lv_img_dsc_t *dsc = &logoIro_img;
int orig_w = dsc->header.w;
int orig_h = dsc->header.h;
int scr_w = lv_disp_get_hor_res(NULL);
int scr_h = lv_disp_get_ver_res(NULL);
/* Compute separate scale factors for width and height (256 == 1.0×) */
int scale_w = (scr_w * 256) / orig_w;
int scale_h = (scr_h * 256) / orig_h;
/* Use the larger scale so the image covers the whole screen (may crop) */
uint16_t zoom = (uint16_t)((scale_w > scale_h) ? scale_w : scale_h);
if (zoom == 0) zoom = 1;
lv_img_set_zoom(logo_img, zoom);
/* Center the image after zoom so it fills the display evenly */
lv_obj_align(logo_img, LV_ALIGN_CENTER, 0, 0);
}
lvgl_unlock();
}
ESP_LOGI(TAG, "LVGL AMOLED application running");
}