LittleVGL input device read_cb switch on the fly

Hello, I’m building an application using littleVGL on an ESP32 with a XPT2046 touch controller. Currently the MCU crashes when the changing the callback method, then processing a touch event

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

ESP32/DoIt DevKit 1. gcc via PlatformIO. (Using the arduino framework)

I initialize the touch input system as shown in the documentation. The first step that the application needs to do is to calibrate the touchscreen. To do this, the input device driver is set to the “raw” version of the touch input callback. This is done in the read_cb member of the driver struct. Once the touch screen is calibrated, I want to use the calibrated input method. I set the new callback like this:

void set_indev(void) { lv_indev_t *indev = lv_indev_get_act(); indev->driver.read_cb = touchpad_read; }

After this is done, and the user touches, the MCU crashes with a stack trace. I think that I’m missing some kind of step to make this work correctly.

Any insights?

As the documentation mentions, lv_indev_get_act only returns a valid input device while input processing is happening (i.e. inside an input device-related event). You should probably store the return value of lv_indev_drv_register instead.

It gives the last registered indev:
lv_indev_t *indev = lv_indev_get_next(NULL);