Hello community,
I'm trying to integrate LVGL 9.3.0 with the touch screen on M5Stack CoreS3, but I'm facing an issue: touch events are not being registered correctly in LVGL, even though the touch screen works fine when tested using M5Stack's official example code.
๐ Software versions I'm using: โ M5Stack CoreS3 (ESP32-S3-based hardware) โ LVGL version: 9.3.0 โ M5Unified library version: Latest available version (checked via Arduino IDE) โ LovyanGFX library version: Latest available version โ Arduino IDE version: 1.8.19 โ ESP32 Board Support Package: Latest version installed via Board Manager
๐ What Iโve tested so far: โ The touch screen works correctly using CoreS3.Touch.getDetail(). โ LVGL is not detecting touches, suggesting a possible misconfiguration in lv_indev_t. โ I've implemented synchronization with CoreS3.update(), but LVGL still does not process touch events.
๐ Current code I'm using:
#include <M5CoreS3.h>
#include <lvgl.h>
// ๐ Screen instance
M5GFX display;
// ๐ Callback function for display update in LVGL
void flush_cb(lv_display_t *disp_drv, const lv_area_t *area, uint8_t *color_p) {
display.pushImage(area->x1, area->y1, area->x2 - area->x1 + 1, area->y2 - area->y1 + 1, (uint16_t*)color_p);
lv_display_flush_ready(disp_drv);
}
// ๐ Touch event handling using CoreS3 and advanced debugging
void my_input_read(lv_indev_t *indev, lv_indev_data_t *data) {
CoreS3.update();
auto t = CoreS3.Touch.getDetail();
data->point.x = t.x;
data->point.y = t.y;
Serial.print("๐ Touch state: "); Serial.println((int)t.state);
Serial.print("๐ Coordinates โ X: "); Serial.print(t.x);
Serial.print(" Y: "); Serial.println(t.y);
if (t.state == m5::touch_state_t::touch_begin || t.state == m5::touch_state_t::hold_begin || t.state == m5::touch_state_t::drag_begin) {
data->state = LV_INDEV_STATE_PR;
Serial.println("โ
LVGL has detected the touch!");
} else {
data->state = LV_INDEV_STATE_REL;
}
}
// ๐ Creating a test button in LVGL
void create_button(lv_obj_t *parent) {
lv_obj_t *btn = lv_btn_create(parent);
lv_obj_set_size(btn, 100, 50);
lv_obj_align(btn, LV_ALIGN_CENTER, 0, 0);
lv_obj_t *label = lv_label_create(btn);
lv_label_set_text(label, "Press");
lv_obj_center(label);
lv_obj_add_flag(btn, LV_OBJ_FLAG_CLICKABLE);
}
// ๐ System initial setup
void setup() {
auto cfg = M5.config();
CoreS3.begin(cfg);
Serial.begin(115200);
Serial.println("\n๐ M5Stack CoreS3 initialized with LVGL 9.3.0 ๐\n");
display.init();
lv_init();
display.begin();
display.setColorDepth(16);
static lv_display_t *disp_drv = lv_display_create(320, 240);
lv_display_set_flush_cb(disp_drv, flush_cb);
// ๐ Dynamic memory allocation to optimize RAM usage
static lv_color_t *buf1 = (lv_color_t*)malloc(320 * 50 * sizeof(lv_color_t));
if (buf1 == NULL) {
Serial.println("โ Error: Failed to allocate memory.");
return;
}
lv_display_set_buffers(disp_drv, buf1, NULL, 320 * 50 * sizeof(lv_color_t), LV_DISPLAY_RENDER_MODE_PARTIAL);
// ๐ Properly initialize the touch input handler in LVGL
lv_indev_t *indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev, my_input_read);
// ๐ Create a test button in LVGL
create_button(lv_scr_act());
Serial.println("โ
LVGL initialized correctly, waiting for interaction...");
}
// ๐ Main loop for touch updates and LVGL handling
void loop() {
CoreS3.update();
lv_timer_handler();
delay(5);
}
๐ก Has anyone successfully enabled touch detection in LVGL with M5Stack CoreS3? If you have any suggestions, insights, or working code examples, Iโd really appreciate your help. ๐
Thanks in advance for any assistance! ๐ Letโs get this working! ๐ช๐ฅ