Button event never enters

Description

I defined a button event but only enters a few times on loop() functions and after never works again.

What MCU/Processor/Board and compiler are you using?

ESP32-S3-DEVKIT-1 with ESP32-S3-WROOM-2

What LVGL version are you using?

8.0

What do you want to achieve?

that button event works

What have you tried so far?

I have changed from 8.3 to 8.0 considering it was a problem on library. Also I suspect that could be a problem with chip definition, 'cos I changed esp32-devkit.json file 'cos I always get a platformio error about SHA-256 comparison failed and rebooted this was solved.

Code to reproduce

v_obj_t * label;
lv_indev_drv_t indev_drv;



static void btn_event_cb(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);
    }
}



void touchpad_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
{
  static int16_t last_x = 0;
  static int16_t last_y = 0;

  if (!ts.bufferEmpty() && ts.touched()) {
    TS_Point p = ts.getPoint();
    // Calculate position 1:1 with display size
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, 480);
    p.y = map(p.y, TS_MINY, TS_MAXY, 0, 800);
    last_x = p.x;
    last_y = p.y;
    data->point.x = last_x;
    data->point.y = last_y;
    data->state = LV_INDEV_STATE_PRESSED;

    Serial.print("Touch detected, ");
    Serial.print("("); Serial.print(last_x);
    Serial.print(", "); Serial.print(last_y);
    Serial.println(")");

    //return true;
  }

  data->point.x = last_x;
  data->point.y = last_y;
  data->state = LV_INDEV_STATE_RELEASED;

  //return false;
}



/* Change to your screen resolution */
static uint32_t screenWidth = 480;
static uint32_t screenHeight = 800;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t *disp_draw_buf;
static lv_disp_drv_t disp_drv;


/* Display flushing */
void my_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);

#if (LV_COLOR_16_SWAP != 0)
   gfx->draw16bitBeRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
#else
   gfx->draw16bitRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
#endif

   lv_disp_flush_ready(disp);
}

void setup()
{
   Serial.begin(115200);
   Serial.println("LVGL Hello World");

  
  

   lv_init();
   gfx->begin();
   gfx->fillScreen(BLACK);
  
  SPI.begin(SCK,MISO,MOSI,CS_PIN);
  ts.begin();

   screenWidth = gfx->width();
   screenHeight = gfx->height();
   
   disp_draw_buf = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * screenWidth * 10, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
   
   lv_disp_draw_buf_init(&draw_buf, disp_draw_buf, NULL, screenWidth * 10);

   /* Initialize the display */
   lv_disp_drv_init(&disp_drv);
   /* Change the following line to your display resolution */
   disp_drv.hor_res = screenWidth;
   disp_drv.ver_res = screenHeight;
   disp_drv.flush_cb = my_disp_flush;
   disp_drv.draw_buf = &draw_buf;
   lv_disp_drv_register(&disp_drv);


   /*Initialize the input device driver*/
      
   lv_indev_drv_init(&indev_drv);             /*Descriptor of a input device driver*/
   indev_drv.type = LV_INDEV_TYPE_POINTER;    /*Touch pad is a pointer-like device*/
   indev_drv.read_cb = touchpad_read;         /*Set your driver function*/
   lv_indev_drv_register(&indev_drv);   


   lv_obj_t * btn = lv_btn_create(lv_scr_act());     /*Add a button the current screen*/
   lv_obj_center(btn);                            /*Set its position*/
   lv_obj_set_size(btn, 120, 50);                          /*Set its size*/
   lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL);           /*Assign a callback to the button*/

   lv_obj_t * label = lv_label_create(btn);          /*Add a label to the button*/
   lv_label_set_text(label, "Button");                     /*Set the labels text*/
   lv_obj_center(label);


  
      Serial.println("Setup done");
   
}

void loop()
{
   lv_timer_handler(); /* let the GUI do its work */
   delay(5);

}

This is the monitor terminal output:
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x1b (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
Octal Flash Mode Enabled
For OPI Flash, Use Default Flash Boot Mode
mode:SLOW_RD, clock div:1
load:0x3fcd0108,len:0x43c
load:0x403b6000,len:0xbd0
load:0x403ba000,len:0x29c8
SHA-256 comparison failed:
Calculated: 0bb45b01207a4a9e9fca8880ddfc0f79112bfa4d004bd1e6b2eaa75c5323b19d
Expected: 6eb14ec480aff4f05e39378c41406102ac163573741e63b6cfd73509ef44e3bd
Attempting to boot anyway…
entry 0x403b61d8
[ 6LVGL Hello World
34
Setup done
34
34
35
38
38
34
20
21
22
23
24
25
20
21
22
23
24
25
20
21
22
23
24
25
20
21
22
23
24
25
20
21
22
23
24
25
20
21
22
23
24
25<----- all of these are Serial.println(code) inside button event and stops here
Touch detected, (240, 431) <-------------I clicked here, touchpad_read works fine but btn_even_cb no

I finally realized that LV_EVENT_ALL fires the codes. Unfortunately the callback function never triggers due to touchscreen. I have read this is a kind of “typical problem” with some cases here. I have used lv_tick_inc() function, considering other examples. Nonetheless If I change to LV_EVENT_CLICKED the trigger never fires. So I’m considering to use other version of XPT2046 library. The callback function and touchpad_read behave independently, is like touchscreen action are not programmed at all to trigger the callback function.

Also is very difficult to jtag this module, 'cos platformio doesn’t have implemented yet JTAG thru USB for this kit, so I need to burn the bit to change JTAG permanently for using something like segger jtag.

Any help you can provide me will be really appreciated. Thanks in advance.