Lvgl keine Events (Touch)

Hallo zusammen,

ich habe hier ein Waveshare ESP32-S3-Touch-LCD-7 ( https://www.waveshare.com/wiki/ESP32-S3-Touch-LCD-7 )
Ich versuche nun schon seit einiger Zeit mit lvgl zu arbeiten. Die Beispiele vom Hersteller sind nicht lauffähig (zumindest bekomme ich genau so wie viele andere sie nicht durch den Compiler). Mithilfe von LovyanGFX habe ich es nun geschafft. Soweit funktioniert es, in dem Beispiel erstelle ich zwei Buttons. Diese werden auch angezeigt. Touch funktioniert auch, jedoch scheint lvgl nichts davon mitzubekommen. Auf Eingaben wird nicht reagiert, die Funktionen touchpad_read und die Eventhandler werden niemals ausgeführt. Nun bin ich mit meinen Ideen am Ende. Vermutlich werde ich bei der Initialisierung etwas falsch machen.

Vielleicht kann mir jemand von euch etwas weiterhelfen. Den Code hänge ich an, ich entschuldige mich für die fehlende Ordnung, so weit bin ich noch nicht gekommen :slight_smile:

#define LGFX_USE_V1
#include <LovyanGFX.hpp>

#include <lgfx/v1/platforms/esp32s3/Panel_RGB.hpp>
#include <lgfx/v1/platforms/esp32s3/Bus_RGB.hpp>
#include <driver/i2c.h>

#include <lvgl.h>
//#include "lv_conf.h"

class LGFX : public lgfx::LGFX_Device
{
public:

lgfx::Bus_RGB _bus_instance;
lgfx::Panel_RGB _panel_instance;
lgfx::Light_PWM _light_instance;
lgfx::Touch_GT911 _touch_instance;

LGFX(void)
{
{
auto cfg = _panel_instance.config();

cfg.memory_width = 800;
cfg.memory_height = 480;
cfg.panel_width = 800;
cfg.panel_height = 480;

cfg.offset_x = 0;
cfg.offset_y = 0;

_panel_instance.config(cfg);
}

{
auto cfg = _panel_instance.config_detail();

cfg.use_psram = 1;

_panel_instance.config_detail(cfg);
}

{
auto cfg = _bus_instance.config();
cfg.panel = &_panel_instance;
cfg.pin_d0 = GPIO_NUM_14; // D0
cfg.pin_d1 = GPIO_NUM_38; // D1
cfg.pin_d2 = GPIO_NUM_18; // D2
cfg.pin_d3 = GPIO_NUM_17; // D3
cfg.pin_d4 = GPIO_NUM_10; // D4
cfg.pin_d5 = GPIO_NUM_39; // D5
cfg.pin_d6 = GPIO_NUM_0; // D6
cfg.pin_d7 = GPIO_NUM_45; // D7
cfg.pin_d8 = GPIO_NUM_48; // D8
cfg.pin_d9 = GPIO_NUM_47; // D9
cfg.pin_d10 = GPIO_NUM_21; // D10
cfg.pin_d11 = GPIO_NUM_1; // D11
cfg.pin_d12 = GPIO_NUM_2; // D12
cfg.pin_d13 = GPIO_NUM_42; // D13
cfg.pin_d14 = GPIO_NUM_41; // D14
cfg.pin_d15 = GPIO_NUM_40; // D15

cfg.pin_henable = GPIO_NUM_5; // DE
cfg.pin_vsync = GPIO_NUM_3; // VSYNC
cfg.pin_hsync = GPIO_NUM_46; // HSYNC
cfg.pin_pclk = GPIO_NUM_7; // PCLK
cfg.freq_write = 16000000; // 16 MHz

cfg.hsync_polarity = 0;
cfg.hsync_front_porch = 8;
cfg.hsync_pulse_width = 4; 
cfg.hsync_back_porch = 8;
cfg.vsync_polarity = 0;
cfg.vsync_front_porch = 8;
cfg.vsync_pulse_width = 4; 
cfg.vsync_back_porch = 8;
cfg.pclk_idle_high = 0; 
_bus_instance.config(cfg);
}
_panel_instance.setBus(&_bus_instance);

{
auto cfg = _light_instance.config();
cfg.pin_bl = GPIO_NUM_2; // Anpassen, falls notwendig
_light_instance.config(cfg);
}
_panel_instance.light(&_light_instance);

 {
 auto cfg = _touch_instance.config();
  cfg.x_min      = 0;
  cfg.y_min      = 0;
  cfg.bus_shared = false;
  cfg.offset_rotation = 0;
  // I2C connection
  cfg.i2c_port   = I2C_NUM_0;
  cfg.pin_sda    = GPIO_NUM_8;  
  cfg.pin_scl    = GPIO_NUM_9;  
  cfg.pin_int    = GPIO_NUM_NC;  
  cfg.pin_rst    = GPIO_NUM_38;  
  cfg.x_max      = 800;
  cfg.y_max      = 480;
  cfg.freq       = 100000;
  _touch_instance.config(cfg);
  _panel_instance.setTouch(&_touch_instance);
        }

setPanel(&_panel_instance);
}
};

LGFX lcd;

static const uint16_t screenWidth = 800;
static const uint16_t screenHeight = 480;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[screenWidth * 10];

/*** Function declaration ***/
void display_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p);
void touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data);
void lv_button_demo(void);

static int32_t x, y, number;
static int32_t testcounter = 0;

void setup()
{
  Serial.begin(115200);
  lcd.init();
  lv_init();

  lcd.setRotation(0);
  lcd.fillScreen(TFT_BLACK);

/* LVGL : Setting up buffer to use for display */
  lv_disp_draw_buf_init(&draw_buf, buf, NULL, screenWidth * 10);

  /*** LVGL : Setup & Initialize the display device driver ***/
  static lv_disp_drv_t disp_drv;
  lv_disp_drv_init(&disp_drv);
  disp_drv.hor_res = screenWidth;
  disp_drv.ver_res = screenHeight;
  disp_drv.flush_cb = display_flush;
  disp_drv.draw_buf = &draw_buf;
  lv_disp_drv_register(&disp_drv);

  /*** LVGL : Setup & Initialize the input device driver ***/
  static lv_indev_drv_t indev_drv;
  lv_indev_drv_init(&indev_drv);
  indev_drv.type = LV_INDEV_TYPE_POINTER;
  indev_drv.read_cb = touchpad_read;
  lv_indev_drv_register(&indev_drv);

  /*** Create simple label and show LVGL version ***/
  String LVGL_Arduino = "ESP32 with LVGL ";
  LVGL_Arduino += String('v') + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
  lv_obj_t *label = lv_label_create(lv_scr_act()); // full screen as the parent
  lv_label_set_text(label, LVGL_Arduino.c_str());  // set label text
  lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 20);      // Center but 20 from the top

  lv_button_demo();
}

void loop()
{
  lv_timer_handler(); /* let the GUI do its work */
  delay(5);
 
  if (lcd.getTouch(&x, &y))
    {
      lcd.fillRect(x - 2, y - 2, 5, 5, TFT_RED);
      lcd.setCursor(380, 0);
      lcd.printf("Touch:(%03d,%03d)", x, y);
      Serial.println("TOUCH");
    }
}

/*** Display callback to flush the buffer to screen ***/
  void display_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);

    lcd.startWrite();
    lcd.setAddrWindow(area->x1, area->y1, w, h);
    lcd.pushColors((uint16_t *)&color_p->full, w * h, true);
    lcd.endWrite();

    lv_disp_flush_ready(disp);
  }

  /*** Touchpad callback to read the touchpad ***/
  void touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
  {
    uint16_t touchX, touchY;
    bool touched = lcd.getTouch(&touchX, &touchY);
    if (!touched)
    {
      data->state = LV_INDEV_STATE_REL;
    }
    else
    {
      data->state = LV_INDEV_STATE_PR;

      /*Set the coordinates*/
      data->point.x = touchX;
      data->point.y = touchY;

      Serial.printf("Touch (x,y): (%03d,%03d)\n",touchX,touchY );
    }
  }

  /* Counter button event handler */
  static void counter_event_handler(lv_event_t * e)
  {
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t *btn = lv_event_get_target(e);
    Serial.println(code);
    if (code == LV_EVENT_CLICKED)
    {
      static uint8_t cnt = 0;
      cnt++;

      /*Get the first child of the button which is the label and change its text*/
      lv_obj_t *label = lv_obj_get_child(btn, 0);
      lv_label_set_text_fmt(label, "Button: %d", cnt);
      LV_LOG_USER("Clicked");
      Serial.println("Clicked");
    }
  }

  /* Toggle button event handler */
  static void toggle_event_handler(lv_event_t * e)
  {
    lv_event_code_t code = lv_event_get_code(e);
    if (code == LV_EVENT_VALUE_CHANGED)
    {
      LV_LOG_USER("Toggled");
      Serial.println("Toggled");
    }
  }

  void lv_button_demo(void)
  {
    lv_obj_t *label;

    // Button with counter
    lv_obj_t *btn1 = lv_btn_create(lv_scr_act());
    lv_obj_add_event_cb(btn1, counter_event_handler, LV_EVENT_ALL, NULL);

    lv_obj_set_pos(btn1, 100, 100);   /*Set its position*/
    lv_obj_set_size(btn1, 120, 50);   /*Set its size*/


    label = lv_label_create(btn1);
    lv_label_set_text(label, "Button");
    lv_obj_center(label);

    // Toggle button
    lv_obj_t *btn2 = lv_btn_create(lv_scr_act());
    lv_obj_add_event_cb(btn2, toggle_event_handler, LV_EVENT_ALL, NULL);
    lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
    lv_obj_set_pos(btn2, 250, 100);   /*Set its position*/
    lv_obj_set_size(btn2, 120, 50);   /*Set its size*/

    label = lv_label_create(btn2);
    lv_label_set_text(label, "Toggle Button");
    lv_obj_center(label);
  }

Verdammt, ein lv_tick_inc(10); im loop und alles geht...

Ich sollte mir ein anderes Hobby suchen. Aber vielleicht hilft ja jemanden der Code :slight_smile: