Right - fixed it and got it working. Here's the summary of what's required. Firstly, I retained TST_eSPI because it's so tightly coupled to LVLM via Squareline studio.
When it comes to handling touchpad inputs It turns out LVLM is quite well thought out. To summarise what needs to happen, you need some form of notice that the screen has been pressed, and to send an X and Y point to LVLM, all done inside the function that's already been created. For an Adafruit screen, the touch comes from a pressure value (point.z > something), and the library gives raw data for points x and y. Then, translate X and Y (as you normally would) and put the values in data->point.x and data->point.y;
So, include all the <Touchscreen.h> definitions you would need. In my case, it's this:
#include <TouchScreen.h>
/*Don't forget to set Sketchbook location in File/Preferencesto the path of your UI project (the parent foder of this INO file)*/
/*Change to your screen resolution*/
static const uint16_t screenWidth = 480;
static const uint16_t screenHeight = 320;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[screenWidth * screenHeight / 10];
TFT_eSPI tft = TFT_eSPI(screenWidth, screenHeight); /* TFT instance */
#if LV_USE_LOG != 0
/* Serial debugging */
void my_print(const char *buf) {
Serial.printf(buf);
Serial.flush();
}
#endif
/*Change to your screen resolution*/
static const uint16_t screenWidth = 480;
static const uint16_t screenHeight = 320;
// screen pins
#define YP A2 // must be an analog pin, use "An" notation!
#define XM A3 // must be an analog pin, use "An" notation!
#define YM 7 // can be a digital pin
#define XP 8 // can be a digital pin
#define TS_MINX 101
#define TS_MINY 188
#define TS_MAXX 908
#define TS_MAXY 883
#define MINPRESSURE 100
#define MAXPRESSURE 1000
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 260);
Then, there' only one place to make an alteration, which is in the "my_touchpad_read" function. All LVLM needs to be told is the x and y coordinate, after being scaled and translated for screen orientation. Here's my complete version of "my_touchpad_read":
void my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) {
uint16_t touchX = 0, touchY = 0;
//bool touched = false;//tft.getTouch( &touchX, &touchY, 600 );
TSPoint p = ts.getPoint();
bool touched = !(p.z < MINPRESSURE || p.z > MAXPRESSURE);
touchX = map(p.y, TS_MAXX, TS_MINX, 0, screenWidth - 1);
touchY = map(p.x, TS_MINY, TS_MAXY, 0, screenHeight - 1);
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;
}
}
That's it - works a treat. LVLM now sees and acts on screen touch events through the widgets.