XTP2046 unable to make it work

Hi!,
I have a problem with XTP2046 driver, I always have the same error with
(i uses nucleo l476rg,Arduino IDE)

  indev_drv.read_cb = my_input_read

my includes

#include “Adafruit_GFX.h”
#include “Adafruit_ILI9341.h”
#include “lvgl.h”
#include <Wire.h>
#include “Adafruit_SPIDevice.h”
#include <XPT2046_Touchscreen.h>

bool my_input_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
{
if (ts.touched()) {
TS_Point p = ts.getPoint();
x = map(p.x, 220, 3850, 1, 480);
y = map(p.y, 310, 3773, 1, 320);
data->point.x = x;
data->point.y = y;
data->state = LV_INDEV_STATE_PR;
} else {
data->state = LV_INDEV_STATE_REL;
}
return false; //No buffering now so no more data read//
}

and in the setup

lv_indev_drv_t indev_drv;
lv_indev_drv_register( &indev_drv );
indev_drv.type = LV_INDEV_TYPE_POINTER;
//indev_drv.read_cb = my_input_read; // ← Problem, commented compile
lv_indev_drv_register(&indev_drv);

and I have this error

error: invalid conversion from ‘bool ()(lv_indev_drv_t, lv_indev_data_t*)’ {aka ‘bool ()(_lv_indev_drv_t, lv_indev_data_t*)’} to ‘void ()(_lv_indev_drv_t, lv_indev_data_t*)’ [- fpermissive]

everything works except the touchscreen,

any help would be appreciated

Thanks in advance

Hello,

input read function should not return bool, but void (nothing).

Try making the return value void instead of bool.

void my_input_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
{
if (ts.touched()) {
TS_Point p = ts.getPoint();
x = map(p.x, 220, 3850, 1, 480);
y = map(p.y, 310, 3773, 1, 320);
data->point.x = x;
data->point.y = y;
data->state = LV_INDEV_STATE_PR;
} else {
data->state = LV_INDEV_STATE_REL;
}
}
1 Like

Thanks Tinus,
Now Compile with your Solution, and added this :

static lv_disp_drv_t disp_drv; //added static ,forgotted…
lv_indev_drv_init(&indev_drv); //added ,seem to work whitout.

x = map(p.x, 220, 3850, 1, 320); //adjusted
y = map(p.y, 310, 3773, 1, 240); //adjusted

i ve tried your solution before,but forgot to remove

return false; //No buffering now so no more data read//

and Many Thanks Tinus,surely this will help Other People in a marvellous world of LGVL