Files
iroBot/main/main.c
Neil Arora a87cf44759 Remove GIF decoder and add swipe gesture support
Deleted GIF decoder files (app_gifdec.c/h) and blink emotion asset. Added swipe_gesture.c/h for new gesture handling. Updated CMakeLists and emotion_manager to reflect these changes. Added Geist font asset.
2026-01-14 20:05:02 +05:30

655 lines
20 KiB
C

/*
* LVGL GIF display for ESP32-S3 Touch AMOLED 1.8" (SH8601)
* Ported from ST7789 to SH8601 QSPI AMOLED display
* Enhanced with smooth Apple-style splash screen
*/
/* Standard Includes */
#include <stdint.h>
#include <stdio.h>
#include <time.h>
/* ESP-IDF Includes */
#include "driver/adc.h"
#include "driver/gpio.h"
#include "driver/i2c.h"
#include "driver/spi_master.h"
#include "esp_check.h"
#include "esp_err.h"
#include "esp_heap_caps.h"
#include "esp_log.h"
#include "esp_timer.h"
/* Local & Managed Component Includes */
#include "esp_io_expander.h"
#include "esp_io_expander_tca9554.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_ops.h"
#include "esp_lcd_panel_vendor.h"
#include "esp_lcd_sh8601.h"
#include "esp_lcd_touch.h"
#include "esp_lcd_touch_ft5x06.h"
/* FreeRTOS Includes */
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
/* LVGL Includes */
#include "lvgl.h"
/* Project Assets */
/* Project Assets */
#include "../assets/logoIroScreen.c"
#include "emotion_manager.h"
#include "swipe_gesture.h"
// Emotions handled by emotion_manager
static const char *TAG = "LVGL_AMOLED";
/* LCD Host */
#define LCD_HOST SPI2_HOST
#define TOUCH_HOST I2C_NUM_0
/* Color depth configuration */
#if CONFIG_LV_COLOR_DEPTH == 32
#define LCD_BIT_PER_PIXEL (24)
#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)
#define PIN_NUM_BK_LIGHT (-1)
/* 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)
#define PIN_NUM_TOUCH_INT (GPIO_NUM_21)
#define USE_TOUCH 1
/* IO Expander Pins */
#define IO_EXPANDER_PIN_NUM_0 (1 << 0)
#define IO_EXPANDER_PIN_NUM_1 (1 << 1)
#define IO_EXPANDER_PIN_NUM_2 (1 << 2)
#define IO_EXPANDER_OUTPUT (1)
/* LVGL configuration */
#define LVGL_BUF_HEIGHT (LCD_V_RES / 4)
#define LVGL_TICK_PERIOD_MS 1
#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 10
static esp_lcd_panel_io_handle_t lcd_io = NULL;
static esp_lcd_panel_handle_t lcd_panel = NULL;
#if USE_TOUCH
static esp_lcd_touch_handle_t tp = NULL;
#endif
static SemaphoreHandle_t lvgl_mux = NULL;
static bool lvgl_lock(int timeout_ms) {
const TickType_t timeout_ticks =
(timeout_ms == -1) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms);
return xSemaphoreTakeRecursive(lvgl_mux, timeout_ticks) == pdTRUE;
}
static void lvgl_unlock(void) { xSemaphoreGiveRecursive(lvgl_mux); }
static QueueHandle_t g_event_queue = NULL;
static lv_obj_t *g_label_time = NULL;
static lv_obj_t *g_label_batt = NULL;
typedef enum {
EVENT_TYPE_BUTTON,
EVENT_TYPE_BATTERY_LOW,
EVENT_TYPE_REFRESH_WATCHFACE
} ui_event_type_t;
typedef struct {
ui_event_type_t type;
int value;
} ui_event_t;
/* 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},
{0x2B, (uint8_t[]){0x00, 0x00, 0x01, 0xBF}, 4, 0},
{0x51, (uint8_t[]){0x00}, 1, 10},
{0x29, (uint8_t[]){0x00}, 0, 10},
{0x51, (uint8_t[]){0xFF}, 1, 0},
};
static lv_disp_drv_t disp_drv;
/* -------------------------------------------------------------------------
* Animation Helper Functions
* ------------------------------------------------------------------------- */
static lv_color_t g_splash_bg_color;
static void scr_bg_fade_in_cb(void *var, int32_t v) {
lv_obj_t *scr = (lv_obj_t *)var;
lv_color_t black = lv_color_hex(0x000000);
/* v: 0 (black) to 255 (target) */
lv_obj_set_style_bg_color(scr, lv_color_mix(g_splash_bg_color, black, v),
LV_PART_MAIN);
}
static void scr_bg_fade_out_cb(void *var, int32_t v) {
lv_obj_t *scr = (lv_obj_t *)var;
lv_color_t black = lv_color_hex(0x000000);
/* v: 0 (target) to 255 (black) */
lv_obj_set_style_bg_color(scr, lv_color_mix(black, g_splash_bg_color, v),
LV_PART_MAIN);
}
static void img_opa_anim_cb(void *obj, int32_t v) {
lv_obj_set_style_img_opa((lv_obj_t *)obj, (lv_opa_t)v, 0);
}
static void img_zoom_anim_cb(void *obj, int32_t v) {
lv_img_set_zoom((lv_obj_t *)obj, (uint16_t)v);
}
static int power_get_battery_percent(void) {
static bool adc_init = false;
if (!adc_init) {
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_11);
adc_init = true;
}
int raw = adc1_get_raw(ADC1_CHANNEL_0);
if (raw >= 0) {
/* Voltage divider: Vbatt -> R1 (100k) -> ADC -> R2 (100k) -> GND */
/* Vadj = Vraw * (3300/4095) * 2.0. */
int voltage = (raw * 6600) / 4095;
/* Map 3400mV-4200mV to 0-100% */
if (voltage >= 4200)
return 100;
if (voltage <= 3400)
return 0;
return (voltage - 3400) * 100 / (4200 - 3400);
}
return 0;
}
static void update_watch_face(void) {
/* No clock or battery display as requested */
}
static void start_watch_face(void) {
lv_obj_t *scr = lv_obj_create(NULL);
lv_obj_set_scrollbar_mode(scr, LV_SCROLLBAR_MODE_OFF);
lv_obj_set_style_bg_color(scr, lv_color_hex(0x000000), LV_PART_MAIN);
/* Initialize Emotion Manager */
emotion_manager_init(scr);
/* Initialize swipe gesture handling */
swipe_gesture_init(scr);
/* Load the watch face screen immediately */
lv_scr_load(scr);
}
#if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
static void cpu_stats_task(void *arg) {
char *stats_buffer = malloc(1024);
if (stats_buffer == NULL) {
ESP_LOGE(TAG, "Failed to allocate buffer for CPU stats");
vTaskDelete(NULL);
}
while (1) {
vTaskGetRunTimeStats(stats_buffer);
ESP_LOGI(TAG, "CPU Usage:\nTask Abs Time %% Time\n%s",
stats_buffer);
vTaskDelay(pdMS_TO_TICKS(5000));
}
}
#endif
static void start_main_app(void) {
if (lvgl_lock(-1)) {
ESP_LOGI(TAG, "Application Running");
start_watch_face();
lvgl_unlock();
#if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
xTaskCreate(cpu_stats_task, "cpu_stats", 4096, NULL, 1, NULL);
#endif
}
}
// The original `start_main_app` content was replaced by the new
// `start_watch_face` call. The GIF creation part is removed as per the
// instruction to make `start_watch_face` the main screen.
static void start_main_app_timer_cb(lv_timer_t *t) {
start_main_app();
lv_timer_del(t);
}
static void splash_finished_cb(lv_anim_t *a) {
lv_obj_t *logo = (lv_obj_t *)a->var;
if (logo) {
lv_obj_del(logo);
}
/* Re-enable input devices after splash completes */
lv_indev_t *indev = lv_indev_get_next(NULL);
while (indev) {
lv_indev_enable(indev, true);
indev = lv_indev_get_next(indev);
}
/* Defer main app start to avoid calling lv_scr_load from within an animation
* callback, preventing the LoadProhibited crash. */
lv_timer_t *start_timer = lv_timer_create(start_main_app_timer_cb, 10, NULL);
lv_timer_set_repeat_count(start_timer, 1);
}
static void start_fadeout_anim(lv_timer_t *t) {
lv_obj_t *logo = (lv_obj_t *)t->user_data;
lv_obj_t *scr = lv_scr_act();
if (!logo)
return;
/* 1. Logo Fade Out */
lv_anim_t a_opa;
lv_anim_init(&a_opa);
lv_anim_set_var(&a_opa, logo);
lv_anim_set_exec_cb(&a_opa, img_opa_anim_cb);
lv_anim_set_values(&a_opa, 255, 0);
lv_anim_set_time(&a_opa, 1200);
lv_anim_set_path_cb(&a_opa, lv_anim_path_ease_in);
lv_anim_set_ready_cb(&a_opa, splash_finished_cb);
lv_anim_start(&a_opa);
/* 2. Background Fade to Black */
lv_anim_t a_bg;
lv_anim_init(&a_bg);
lv_anim_set_var(&a_bg, scr);
lv_anim_set_exec_cb(&a_bg, scr_bg_fade_out_cb);
lv_anim_set_values(&a_bg, 0, 255);
lv_anim_set_time(&a_bg, 1200);
lv_anim_set_path_cb(&a_bg, lv_anim_path_ease_in);
lv_anim_start(&a_bg);
}
/* -------------------------------------------------------------------------
* LVGL Callbacks & Core Logic
* ------------------------------------------------------------------------- */
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) {
lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
lv_disp_flush_ready(disp_driver);
return false;
}
static void lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area,
lv_color_t *color_map) {
esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data;
#if LCD_BIT_PER_PIXEL == 24
/* Convert LVGL 32-bit color format (ARGB8888) to RGB888 (24-bit) for SH8601
*/
uint8_t *to = (uint8_t *)color_map;
uint32_t pixel_num = (area->x2 - area->x1 + 1) * (area->y2 - area->y1 + 1);
/* Pack pixels into 24-bit (3 bytes) buffer in-place */
for (uint32_t i = 0; i < pixel_num; i++) {
/* Use explicit extraction to avoid struct packing issues */
uint32_t c = color_map[i].full;
*to++ = (uint8_t)(c >> 16); /* R */
*to++ = (uint8_t)(c >> 8); /* G */
*to++ = (uint8_t)c; /* B */
}
#endif
esp_lcd_panel_draw_bitmap(panel_handle, area->x1, area->y1, area->x2 + 1,
area->y2 + 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) {
area->x1 = (area->x1 >> 1) << 1;
area->y1 = (area->y1 >> 1) << 1;
area->x2 = ((area->x2 >> 1) << 1) + 1;
area->y2 = ((area->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;
uint16_t tp_x, 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;
} else {
data->state = LV_INDEV_STATE_RELEASED;
}
}
#endif
static void increase_lvgl_tick(void *arg) { lv_tick_inc(LVGL_TICK_PERIOD_MS); }
static void ui_task(void *arg) {
uint32_t task_delay_ms = LVGL_TASK_MAX_DELAY_MS;
uint32_t last_tick = 0;
while (1) {
uint32_t now = xTaskGetTickCount() * portTICK_PERIOD_MS;
if (lvgl_lock(-1)) {
task_delay_ms = lv_timer_handler();
/* 1Hz Refresh logic (every 1000ms) */
if (now - last_tick >= 1000) {
update_watch_face();
last_tick = now;
}
/* Process Event Queue */
ui_event_t ev;
/*
if (xQueueReceive(g_event_queue, &ev, 0) == pdTRUE) {
// Handle UI events here
}
*/
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));
}
}
/* -------------------------------------------------------------------------
* App Main
* ------------------------------------------------------------------------- */
void app_main(void) {
esp_log_level_set("lcd_panel.io.i2c", ESP_LOG_DEBUG);
esp_log_level_set("FT5x06", ESP_LOG_DEBUG);
esp_log_level_set("esp_lcd_touch", ESP_LOG_DEBUG);
static lv_disp_draw_buf_t disp_buf;
/* I2C Setup */
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));
/* Run a quick I2C scan to list devices on the bus for diagnostics */
{
ESP_LOGI("I2C_SCAN", "Starting I2C scan on port %d", TOUCH_HOST);
for (int addr = 1; addr < 0x7F; addr++) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (addr << 1) | I2C_MASTER_WRITE, true);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(TOUCH_HOST, cmd, pdMS_TO_TICKS(50));
i2c_cmd_link_delete(cmd);
if (ret == ESP_OK) {
ESP_LOGI("I2C_SCAN", "Found device at 0x%02X", addr);
}
}
ESP_LOGI("I2C_SCAN", "I2C scan complete");
}
/* IO Expander Setup */
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_io_expander_set_dir(io_expander,
IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1 |
IO_EXPANDER_PIN_NUM_2,
IO_EXPANDER_OUTPUT);
/* Vendor Init Sequence: Toggle all pins Low -> High with 200ms delay */
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);
/* Add delay to allow Touch IC to wake up and stabilize after reset high */
vTaskDelay(pdMS_TO_TICKS(200));
/* LCD Setup */
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));
esp_lcd_panel_io_spi_config_t io_config = SH8601_PANEL_IO_QSPI_CONFIG(
PIN_NUM_LCD_CS, notify_lvgl_flush_ready, &disp_drv);
io_config.pclk_hz = 80 * 1000 * 1000; /* Boost to 80MHz for 60FPS */
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)LCD_HOST,
&io_config, &lcd_io));
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},
};
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));
/* Touch Driver Setup (FT5x06) */
#if USE_TOUCH
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
/* Overriding default address (usually 0x38) with 0x34 found in scan */
esp_lcd_panel_io_i2c_config_t tp_io_config =
ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG();
tp_io_config.dev_addr = 0x34;
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)TOUCH_HOST,
&tp_io_config, &tp_io_handle));
esp_lcd_touch_config_t tp_cfg = {
.x_max = 368,
.y_max = 448,
.rst_gpio_num = -1, // Reset handled by IO Expander logic above
.int_gpio_num = PIN_NUM_TOUCH_INT,
.levels =
{
.reset = 0,
.interrupt = 0,
},
.flags =
{
.swap_xy = 0,
.mirror_x = 0,
.mirror_y = 0,
},
};
esp_lcd_touch_handle_t tp = NULL;
ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_ft5x06(tp_io_handle, &tp_cfg, &tp));
#endif
/* LVGL Init */
lv_init();
lv_color_t *buf1 = heap_caps_malloc(
LCD_H_RES * LVGL_BUF_HEIGHT * sizeof(lv_color_t), MALLOC_CAP_DMA);
lv_color_t *buf2 = heap_caps_malloc(
LCD_H_RES * LVGL_BUF_HEIGHT * sizeof(lv_color_t), MALLOC_CAP_DMA);
lv_disp_draw_buf_init(&disp_buf, buf1, buf2, LCD_H_RES * LVGL_BUF_HEIGHT);
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);
/* Increase refresh frequency to 60fps (16ms) */
lv_disp_set_bg_color(disp, lv_color_hex(0x000000));
#if LVGL_VERSION_MAJOR >= 8
/* For LVGL v8, we can set default refresh period if not set in sdkconfig */
/* This is usually done via disp_drv, but it can be changed globally */
#endif
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
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
lvgl_mux = xSemaphoreCreateRecursiveMutex();
g_event_queue = xQueueCreate(10, sizeof(ui_event_t));
/* ui_task pinned to Core 0 for maximum responsiveness */
xTaskCreatePinnedToCore(ui_task, "UI Task", LVGL_TASK_STACK_SIZE, NULL,
LVGL_TASK_PRIORITY, NULL, 0);
/* --- Start Premium Splash Screen Sequence --- */
if (lvgl_lock(-1)) {
lv_obj_t *scr = lv_scr_act();
/* New asset is ARGB8888 (4 bytes per pixel) */
if (logoIro.data) {
const uint8_t *d = (const uint8_t *)logoIro.data;
/* ARGB: d[0]=B, d[1]=G, d[2]=R (Little Endian) */
uint32_t bg_hex = (d[2] << 16) | (d[1] << 8) | d[0];
g_splash_bg_color = lv_color_hex(bg_hex);
} else {
g_splash_bg_color = lv_color_hex(0x000000);
}
/* Set Background to Black Initially */
lv_obj_set_style_bg_color(scr, lv_color_hex(0x000000), LV_PART_MAIN);
lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, LV_PART_MAIN);
/* Create Fullscreen Logo */
lv_obj_t *logo_img = lv_img_create(scr);
lv_img_set_src(logo_img, &logoIro);
lv_obj_align(logo_img, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_style_img_opa(logo_img, 0, 0);
/* Interaction lock */
lv_obj_clear_flag(logo_img, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE);
lv_obj_clear_flag(scr, LV_OBJ_FLAG_SCROLLABLE | LV_OBJ_FLAG_CLICKABLE);
lv_indev_t *indev = lv_indev_get_next(NULL);
while (indev) {
lv_indev_enable(indev, false);
indev = lv_indev_get_next(indev);
}
/* 1. Coordinated Fade In (1.5s) */
lv_anim_t a_logo_in;
lv_anim_init(&a_logo_in);
lv_anim_set_var(&a_logo_in, logo_img);
lv_anim_set_exec_cb(&a_logo_in, img_opa_anim_cb);
lv_anim_set_values(&a_logo_in, 0, 255);
lv_anim_set_time(&a_logo_in, 1500);
lv_anim_set_path_cb(&a_logo_in, lv_anim_path_ease_out);
lv_anim_start(&a_logo_in);
lv_anim_t a_bg_in;
lv_anim_init(&a_bg_in);
lv_anim_set_var(&a_bg_in, scr);
lv_anim_set_exec_cb(&a_bg_in, scr_bg_fade_in_cb);
lv_anim_set_values(&a_bg_in, 0, 255);
lv_anim_set_time(&a_bg_in, 1500);
lv_anim_set_path_cb(&a_bg_in, lv_anim_path_ease_out);
lv_anim_start(&a_bg_in);
/* 2. Hold and Fade Out after 3s (Must be one-shot) */
lv_timer_t *hold_timer =
lv_timer_create(start_fadeout_anim, 3000, logo_img);
lv_timer_set_repeat_count(hold_timer, 1);
lvgl_unlock();
}
ESP_LOGI(TAG, "Application Running");
}