Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LVGL 9.2.2 FN6206 Support #7941

Open
ats3788 opened this issue Mar 17, 2025 · 0 comments
Open

LVGL 9.2.2 FN6206 Support #7941

ats3788 opened this issue Mar 17, 2025 · 0 comments

Comments

@ats3788
Copy link

ats3788 commented Mar 17, 2025

Problem to solve

Hello I try to make the Touch FN6206 to work but with no success yet. This is my code so far but something is missing. Any clue Thx Martin Michael

#include <lvgl.h>

/*  Install the "TFT_eSPI" library by Bodmer to interface with the TFT Display - https://github.com/Bodmer/TFT_eSPI
    *** IMPORTANT: User_Setup.h available on the internet will probably NOT work with the examples available at Random Nerd Tutorials ***
    *** YOU MUST USE THE User_Setup.h FILE PROVIDED IN THE LINK BELOW IN ORDER TO USE THE EXAMPLES FROM RANDOM NERD TUTORIALS ***
    FULL INSTRUCTIONS AVAILABLE ON HOW CONFIGURE THE LIBRARY: https://RandomNerdTutorials.com/cyd-lvgl/ or https://RandomNerdTutorials.com/esp32-tft-lvgl/   */
// #include <TFT_eSPI.h>

// Install the "XPT2046_Touchscreen" library by Paul Stoffregen to use the Touchscreen - https://github.com/PaulStoffregen/XPT2046_Touchscreen - Note: this library doesn't require further configuration
//#include <XPT2046_Touchscreen.h>
#include "ui/ui.h"
#if bXPT2046==true
#include <XPT2046_Touchscreen.h>
#else
#include <Adafruit_FT6206.h>
Adafruit_FT6206 ctp = Adafruit_FT6206();
#endif


lv_indev_t * indev_touchpad;
 
// The FT6206 uses hardware I2C (SCL/SDA)


#define MAX_IMAGE_WIDTH 240 // Sets rendering line buffer lengths, adjust for your images

#if bXPT2046==true
SPIClass touchscreenSPI = SPIClass(VSPI);
XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ);
#endif


// Touchscreen coordinates: (x, y) and pressure (z)
int x, y, z;

#define DRAW_BUF_SIZE (ScreenWidth * ScreenHeight / 10 * (LV_COLOR_DEPTH / 8))
uint32_t draw_buf[DRAW_BUF_SIZE / 4];

// If logging is enabled, it will inform the user about what is happening in the library




void lv_Init();

void touchscreen_read(lv_indev_t * indev, lv_indev_data_t * data);
void CheckToutchFT6206();
void log_print(lv_log_level_t level, const char * buf);

void setup() {
  String LVGL_Arduino = String("LVGL Library Version: ") + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
  Serial.begin(115200);
  Serial.println(LVGL_Arduino);
  lv_Init();

  #if bXPT2046==false
  if (! ctp.begin(40)) {  // pass in 'sensitivity' coefficient
    Serial.println("Couldn't start FT6206 touchscreen controller");
    while (1);
  }
 #endif

}

void loop() {
  lv_task_handler();  // let the GUI do its work
  lv_tick_inc(5);     // tell LVGL how much time has passed
  delay(5);           // let this time pass
  #if bXPT2046==false
   // Wait for a touch
   if (! ctp.touched()) {
    delay(10); // Speeds up the simulation
    return;
    
  }

  CheckToutchFT6206();
  #endif
}



  void lv_Init()
  {
  // Start LVGL
  lv_init();
  // Register print function for debugging
  lv_log_register_print_cb(log_print);

  // Start the SPI for the touchscreen and init the touchscreen
  #if bXPT2046==true
  touchscreenSPI.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
  touchscreen.begin(touchscreenSPI);
  // Set the Touchscreen rotation in landscape mode
  // Note: in some displays, the touchscreen might be upside down, so you might need to set the rotation to 0: touchscreen.setRotation(0);
  touchscreen.setRotation(2);
  #endif
  
 

  // Create a display object
  lv_display_t * disp;
  // Initialize the TFT display using the TFT_eSPI library
  disp = lv_tft_espi_create(ScreenWidth, ScreenHeight, draw_buf, sizeof(draw_buf));
  lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_270);
    
  // Initialize an LVGL input device object (Touchscreen)
  lv_indev_t * indev = lv_indev_create();
  lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
 
  // Set the callback function to read Touchscreen input

  lv_indev_set_read_cb(indev, touchscreen_read);

  LV_LOG_USER("Event Button");

  // Function to draw the GUI (text, buttons and sliders)
    ui_init();
  }

  #if bXPT2046==true
void touchscreen_read(lv_indev_t * indev, lv_indev_data_t * data) 
{
  // Checks if Touchscreen was touched, and prints X, Y and Pressure (Z)
  if(touchscreen.tirqTouched() && touchscreen.touched()) {
    // Get Touchscreen points
    TS_Point p = touchscreen.getPoint();
    // Calibrate Touchscreen points with map function to the correct width and height
    x = map(p.x, 200, 3700, 1, ScreenWidth);
    y = map(p.y, 240, 3800, 1, ScreenHeight);
    z = p.z;

    data->state = LV_INDEV_STATE_PRESSED;

    // Set the coordinates
    data->point.x = x;
    data->point.y = y;

    // Print Touchscreen info about X, Y and Pressure (Z) on the Serial Monitor
     Serial.print("X = ");
    Serial.print(x);
    Serial.print(" | Y = ");
    Serial.print(y);
    Serial.print(" | Pressure = ");
    Serial.print(z);
    Serial.println();
  }
  else {
    data->state = LV_INDEV_STATE_RELEASED;
  }
}
#else
void touchscreen_read(lv_indev_t * indev, lv_indev_data_t * data) 
 {
  
  TS_Point p = ctp.getPoint();
  data->state = LV_INDEV_STATE_PRESSED;
  data->point.x = p.x;
  data->point.y = p.y;
  data->state = ((p.z > 10) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL);
  // flip it around to match the screen.
p.x = map(p.x, 0, 240, 240, 0);
p.y = map(p.y, 0, 320, 320, 0);

// Print out the remapped (rotated) coordinates
Serial.print("("); Serial.print(p.x);
Serial.print(", "); Serial.print(p.y);
Serial.println(")");
  LV_LOG_USER("p.x :%d-p.y :%d", p.x, p.y );
}
#endif

void log_print(lv_log_level_t level, const char * buf) 
{
  LV_UNUSED(level);
  Serial.println(buf);
  Serial.flush();
}

#if bXPT2046==false
void CheckToutchFT6206()
{
lv_indev_data_t touch_data;
touchscreen_read(NULL, &touch_data); // Übergib die Adresse der Struktur
return;
// Wait for a touch
if (! ctp.touched()) {
delay(10); // Speeds up the simulation
return;
}
}
#endif

Success criteria

Toch Screen FN6206 with LVGL 9.2.2

Solution outline

"C" in the Arduino world

Rabbit holes

n/a

Testing

https://wokwi.com/projects/376598893440863233

Teaching

Example are alway good

Considerations

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant