Refactor project structure and update display logic

Reorganized source files into new directories for config, drivers, sensors, emotion engine, and UI. Removed legacy assets and code related to previous eye animation implementation. Added new display and touch drivers, emotion manager, shake detector, and UI components. Updated CMake project name to 'irobot_display'.
This commit is contained in:
2026-01-24 15:21:50 +05:30
parent 2c731c72e3
commit 8aeaed8a15
69 changed files with 2650 additions and 10338 deletions

131
main/drivers/touch_driver.c Normal file
View File

@@ -0,0 +1,131 @@
/**
* @file touch_driver.c
* @brief Touch controller driver implementation for FT5x06
*
* This module handles touch controller initialization and LVGL integration.
* The touch controller uses I2C communication which must be initialized
* by the display driver before this module is used.
*/
#include "touch_driver.h"
#include "config/display_config.h"
#include "config/hardware_config.h"
#include "drivers/display_driver.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_touch_ft5x06.h"
#include "esp_log.h"
#include "lvgl.h"
static const char *TAG = "touch_driver";
#if TOUCH_ENABLED
// ----------------------------------------------------------------------------
// Private State
// ----------------------------------------------------------------------------
static esp_lcd_touch_handle_t touchHandle = NULL;
static lv_indev_drv_t inputDriver;
// ----------------------------------------------------------------------------
// Private Function Prototypes
// ----------------------------------------------------------------------------
static void touchInputCallback(lv_indev_drv_t *drv, lv_indev_data_t *data);
// ----------------------------------------------------------------------------
// Public API Implementation
// ----------------------------------------------------------------------------
bool touchDriverInit(void) {
ESP_LOGI(TAG, "Initializing touch controller");
// Create I2C IO handle for touch controller
esp_lcd_panel_io_handle_t tpIoHandle = NULL;
const esp_lcd_panel_io_i2c_config_t tpIoConfig =
ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG();
esp_err_t err = esp_lcd_new_panel_io_i2c(
(esp_lcd_i2c_bus_handle_t)I2C_MASTER_PORT, &tpIoConfig, &tpIoHandle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to create touch panel IO: %s", esp_err_to_name(err));
return false;
}
// Configure touch controller
const esp_lcd_touch_config_t touchConfig = {
.x_max = DISPLAY_WIDTH,
.y_max = DISPLAY_HEIGHT,
.rst_gpio_num = TOUCH_PIN_RST,
.int_gpio_num = TOUCH_PIN_INT,
.levels =
{
.reset = 0,
.interrupt = 0,
},
.flags =
{
.swap_xy = 0,
.mirror_x = 0,
.mirror_y = 0,
},
};
err = esp_lcd_touch_new_i2c_ft5x06(tpIoHandle, &touchConfig, &touchHandle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize touch controller: %s",
esp_err_to_name(err));
return false;
}
// Register with LVGL as input device
lv_indev_drv_init(&inputDriver);
inputDriver.type = LV_INDEV_TYPE_POINTER;
inputDriver.read_cb = touchInputCallback;
inputDriver.user_data = touchHandle;
lv_indev_drv_register(&inputDriver);
ESP_LOGI(TAG, "Touch controller initialized successfully");
return true;
}
esp_lcd_touch_handle_t touchDriverGetHandle(void) { return touchHandle; }
// ----------------------------------------------------------------------------
// Private Implementation
// ----------------------------------------------------------------------------
static void touchInputCallback(lv_indev_drv_t *drv, lv_indev_data_t *data) {
esp_lcd_touch_handle_t tp = (esp_lcd_touch_handle_t)drv->user_data;
if (tp == NULL) {
data->state = LV_INDEV_STATE_RELEASED;
return;
}
uint16_t x, y;
uint8_t count = 0;
// Read touch data from controller
esp_lcd_touch_read_data(tp);
bool pressed = esp_lcd_touch_get_coordinates(tp, &x, &y, NULL, &count, 1);
if (pressed && count > 0) {
data->point.x = x;
data->point.y = y;
data->state = LV_INDEV_STATE_PRESSED;
} else {
data->state = LV_INDEV_STATE_RELEASED;
}
}
#else // TOUCH_ENABLED == 0
bool touchDriverInit(void) {
ESP_LOGI(TAG, "Touch controller disabled in configuration");
return true;
}
esp_lcd_touch_handle_t touchDriverGetHandle(void) { return NULL; }
#endif // TOUCH_ENABLED