Description
What MCU/Processor/Board and compiler are you using?
Teensy, Arduino IDE
What LVGL version are you using?
8.3.10 and tft-espi 2.5.33
What do you want to achieve?
I have a landscape app where calibrated it was with setrotation(1). I have designed with squareline a landscape ux. Width 320, height 240, rotation 0 degrees.
When I measure the touch points across the screen horizontally, they vary from approx 17 to 240. This suggests to me that the touch framework and the lvgl frame of reference are 90 degrees out of phase?
Correction?
What have you tried so far?
Lots, but this is the first time I saw that touch was not 0-320…
Some further data. Simple UX developed with SquareLine:
-
screen, 1 panel and 5 buttons with labels. (tried to attach the .prj, but not allowed)
photos:
-
Printout of X/Y going from left (button 1) to right (button 5) (bounces removed)
Button 1
Data x 5
Data y 290
button 2
Data x 20
Data y 314
button 3
Data x 99
Data y 301
Button 4
Data x 146
Data y 313
Button 5
Data x 193
Data y 319
Y is close to 340 and at top of screen, X goes to almost 240… I expected 0-340 on X and 0 on Y.
No calibration data. And setRotation is 1.
This is a teensy 4.0 on a custom board. Other data needed? This one is driving me nutts…
Thanks!
Mark
.
This is the initiation code from the original app where the issue first appeared. The code generated by SquareLine is unmodified except for enabling Touch. BTW: On Teensy, there is no need for Serial.begin() (happens automatically) and if you do, you take a 1.5 second penalty for a timeout.
It should also be noted that when using the TFT-eSPI calirbation app (no lgvl code), the x,y is correct (rotation set to 1, x varies from 0-320, y varies from 0-240)
#include <lvgl.h>
#include <TFT_eSPI.h>
#include "src/ui.h" //all the squareline files are in src/
/*Change to your screen resolution*/
static const uint16_t screenWidth = 320;
static const uint16_t screenHeight = 240;
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 */
/* 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 );
tft.startWrite();
tft.setAddrWindow( area->x1, area->y1, w, h );
tft.pushColors( ( uint16_t * )&color_p->full, w * h, true );
tft.endWrite();
lv_disp_flush_ready( disp );
}
/*Read the touchpad*/
void my_touchpad_read( lv_indev_drv_t * indev_driver, lv_indev_data_t * data )
{
uint16_t touchX = 0, touchY = 0;
bool touched = tft.getTouch( &touchX, &touchY, 600 );
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.print( "Data x " );
Serial.println( touchX );
Serial.print( "Data y " );
Serial.println( touchY );
}
}
void LCDTFT240x320_Init()
{
lv_init();
tft.begin(); /* TFT init */
tft.setRotation( 1 ); /* Landscape orientation, flipped */
lv_disp_draw_buf_init( &draw_buf, buf, NULL, screenWidth * screenHeight / 10 );
/*Initialize the display*/
static lv_disp_drv_t disp_drv;
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 (dummy) 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 = my_touchpad_read;
lv_indev_drv_register( &indev_drv );
uint16_t calData[5] = { 404, 3486, 346, 3433, 7 };
tft.setTouch(calData);
ui_init();
}
OK, i got this working.
For anybody that has a similar problem, you need to do one thing:
Change:
TFT_eSPI tft = TFT_eSPI(screenWidth, screenHeight); /* TFT instance */
To:
TFT_eSPI tft = TFT_eSPI(screenHeight,screenWidth ); /* TFT instance */
Perhaps I misconfigured something in the SquareLine preferences and this would have been auto generated? In any case,this change of reversing height and width on the TFT creation call got me operational.
Mark