Tab5, LVGL, trying to get touch working
-
Solved: somehow commented the lv_tick_inc(5); in the main loop.
Hi, I m trying to get touch working together with lvgl 8.3. I believe the code is not working. Any suggestions? ```
#include <arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <esp_now.h>
#include <lvgl.h>
#include <M5GFX.h>M5GFX display;
#define LVGL_LCD_BUF_SIZE (Screen_Width * Screen_Height)
// lvgl variables
static lv_disp_drv_t disp_drv;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t *buf;// UI objects
lv_obj_t * screen;void lv_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
uint32_t w = (area->x2 - area->x1 + 1);
uint32_t h = (area->y2 - area->y1 + 1);
//M5.Display.pushImageDMA(area->x1, area->y1, w, h, (uint16_t *)&color_p->full);
display.pushImageDMA(area->x1, area->y1, w, h, (uint16_t *)&color_p->full);
lv_disp_flush_ready(disp);
}// touch callback
static void lv_indev_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{
lgfx::touch_point_t tp[3];
// uint8_t touchpad = M5.Display.getTouchRaw(tp,3);
uint8_t touchpad = display.getTouchRaw(tp,3);
if (touchpad > 0)
{
data->state = LV_INDEV_STATE_PR;
data->point.x = tp[0].x;
data->point.y = tp[0].y;
Serial.printf("X: %d Y: %d\n", tp[0].x, tp[0].y); //for testing
}
else
{
data->state = LV_INDEV_STATE_REL;
}
}void setup() {
//auto cfg = M5.config();
//M5.begin(cfg);
//M5.Display.startWrite();
//M5.begin();
Serial.begin(115200);
delay(300);Serial.println("And we have started"); display.init(); lv_init(); buf = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * LVGL_LCD_BUF_SIZE, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); lv_disp_draw_buf_init(&draw_buf, buf, NULL, LVGL_LCD_BUF_SIZE); // set up display driver lv_disp_drv_init(&disp_drv); disp_drv.hor_res = Screen_Width; disp_drv.ver_res = Screen_Height; disp_drv.flush_cb = lv_disp_flush; disp_drv.draw_buf = &draw_buf; disp_drv.sw_rotate = 1; disp_drv.rotated = LV_DISP_ROT_90; lv_disp_drv_register(&disp_drv); // initialise touch static lv_indev_drv_t indev_drv; lv_indev_drv_init(&indev_drv); indev_drv.type = LV_INDEV_TYPE_POINTER; indev_drv.read_cb = lv_indev_read; lv_indev_drv_register(&indev_drv);}
void loop() {
lv_timer_handler();
delay(5);}