eez-open / studio

Cross-platform low-code GUI and automation
https://www.envox.eu/studio/studio-introduction/
GNU General Public License v3.0
308 stars 69 forks source link

touch sreen use with eez-flow and lvgl in Arduino IDE #372

Closed vinxy254 closed 1 month ago

vinxy254 commented 1 month ago

I would like to know any extra steps required to get the touch screen driver working with an eez-flow lvgl Arduino IDE project. Previous bugs mentioned in #361 are fixed in code and the screen is running as expected. However the touch screen is not responding despite following the steps described by lvgl https://github.com/lvgl/lvgl/blob/master/docs/porting/indev.rst . I used a custom touch driver library in code.

#include <eez-framework.h>
#include <lvgl.h>
#include <TFT_eSPI.h>
#include "ui.h"
#include <FT6236.h>            //touch panel driver library

//touch definations
#define TOUCH_THRESHOLD 80
#define I2C_SDA 38
#define I2C_SCL  39

#define TS_MINX 150
#define TS_MAXX 3800

#define TS_MINY 130
#define TS_MAXY 4000

//ft6236 declaration
FT6236 ts = FT6236();

setup section

void setup()
{

    Serial.begin( 115200 ); /* prepare for possible serial debug */

//touch driver initialize
     if (!ts.begin(TOUCH_THRESHOLD, I2C_SDA, I2C_SCL)){
      Serial.println("Unable to start the capacitive touchscreen.");
    }  

    lv_init();

    tft.begin();          /* TFT init */
    tft.setRotation( 3 ); /* 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 );

    ui_init();

    Serial.println( "Setup done" );

}

touch coordinates function

void my_touchpad_read( lv_indev_drv_t * indev_driver, lv_indev_data_t * data )
{
    uint16_t touchX = 0, touchY = 0;
    uint8_t rotation = 2;

    bool touched = false;

    if( !ts.touched() )
    {
        data->state = LV_INDEV_STATE_REL;
    }
    else
    {
      for(int i=0; i< ts.touched(); i++){
          TS_Point p = ts.getPoint(i);     //get coordinates from driver

          data->state = LV_INDEV_STATE_PR;

          touchX = tft.width()-p.y;    //read  X coordinates, rotate 90 degrees to match landscape
          touchY = p.x;                    //read  Y coordinates to map in landscape

          data->point.x = touchX;
          data->point.y = touchY;

          Serial.print("raw touch X");
          Serial.println(touchX);

          Serial.print("raw touch y: ");
          Serial.println(touchY);  
      }
    }
}

loop function

void loop()
{
  lv_task_handler();
  ui_tick();
  delay(5);
}

The above method is the standard method described by lvgl to add a custom touch panel driver, it is however unclear if it persists when used when lvgl is used with eez-flow.

mvladic commented 1 month ago

These types of questions are better to be asked on our Discord server.