Add LovyanGfx Touch driver

This commit is contained in:
fvanroie 2021-11-02 05:45:42 +01:00
parent ee10659e84
commit 80623c6615
14 changed files with 79 additions and 48 deletions

View File

@ -63,7 +63,7 @@ void FT6336U_init()
LOG_INFO(TAG_DRVR, F("Touch SDA : %d"), TOUCH_SDA);
LOG_INFO(TAG_DRVR, F("Touch SCL : %d"), TOUCH_SCL);
LOG_INFO(TAG_DRVR, F("Touch freq. : %d"), I2C_TOUCH_FREQUENCY);
LOG_INFO(TAG_DRVR, F("Touch address : %x"), I2C_ADDR_FT6336U);
LOG_INFO(TAG_DRVR, F("Touch address : %x"), I2C_TOUCH_ADDRESS);
touchpanel = new FT6336U(TOUCH_SDA, TOUCH_SCL, TOUCH_RST, TOUCH_IRQ);
touchpanel->begin();
@ -75,7 +75,7 @@ void FT6336U_init()
// handle these events. So instead, we set the INT wire to polled mode,
// so it simply goes low as long as there is at least one valid touch.
// touchpanel->writeByte(0xA4, 0x00);
Wire1.beginTransmission(I2C_ADDR_FT6336U);
Wire1.beginTransmission(I2C_TOUCH_ADDRESS);
Wire1.write(0xA4); // address
Wire1.write(0x00); // data
Wire1.endTransmission();

View File

@ -61,14 +61,14 @@ void LovyanGfx::init(int w, int h)
tft_driver = 0x9488;
#endif
if (tft_driver == 0x9341)
tft._panel_instance = new lgfx::Panel_ILI9341();
else if (tft_driver == 0x9481)
tft._panel_instance = new lgfx::Panel_ILI9481();
else if (tft_driver == 0x9488)
tft._panel_instance = new lgfx::Panel_ILI9488();
else if (tft_driver == 0x7796)
tft._panel_instance = new lgfx::Panel_ST7796();
if(tft_driver == 0x9341)
tft._panel_instance = new lgfx::Panel_ILI9341();
else if(tft_driver == 0x9481)
tft._panel_instance = new lgfx::Panel_ILI9481();
else if(tft_driver == 0x9488)
tft._panel_instance = new lgfx::Panel_ILI9488();
else if(tft_driver == 0x7796)
tft._panel_instance = new lgfx::Panel_ST7796();
{ // バス制御の設定を行います。
auto bus = (lgfx::v1::Bus_SPI*)tft._bus_instance;
@ -128,8 +128,9 @@ else if (tft_driver == 0x7796)
tft._panel_instance->setLight(&tft._light_instance); // バックライトをパネルにセットします。
}
tft._touch_instance = new lgfx::Touch_FT5x06();
{ // タッチスクリーン制御の設定を行います。(必要なければ削除)
auto cfg = tft._touch_instance.config();
auto cfg = tft._touch_instance->config();
cfg.x_min = 0; // タッチスクリーンから得られる最小のX値(生の値)
cfg.x_max = 319; // タッチスクリーンから得られる最大のX値(生の値)
cfg.y_min = 0; // タッチスクリーンから得られる最小のY値(生の値)
@ -137,20 +138,22 @@ else if (tft_driver == 0x7796)
cfg.pin_int = -1; // INTが接続されているピン番号
cfg.bus_shared = true; // 画面と共通のバスを使用している場合 trueを設定
cfg.offset_rotation = 0; // 表示とタッチの向きのが一致しない場合の調整 0~7の値で設定
cfg.spi_host = HSPI_HOST; // 使用するSPIを選択 (HSPI_HOST or VSPI_HOST)
cfg.pin_sclk = TFT_SCLK; // SCLKが接続されているピン番号
cfg.pin_mosi = TFT_MOSI; // MOSIが接続されているピン番号
cfg.pin_miso = TFT_MISO; // MISOが接続されているピン番号
#ifdef TOUCH_CS
cfg.pin_cs = TOUCH_CS; // CSが接続されているピン番号
cfg.freq = SPI_TOUCH_FREQUENCY; // SPIクロックを設定
cfg.spi_host = HSPI_HOST; // 使用するSPIを選択 (HSPI_HOST or VSPI_HOST)
cfg.pin_sclk = TFT_SCLK; // SCLKが接続されているピン番号
cfg.pin_mosi = TFT_MOSI; // MOSIが接続されているピン番号
cfg.pin_miso = TFT_MISO; // MISOが接続されているピン番号
cfg.pin_cs = TOUCH_CS; // CSが接続されているピン番号
cfg.freq = SPI_TOUCH_FREQUENCY; // SPIクロックを設定
#else
cfg.pin_sda = TOUCH_SDA;
cfg.pin_scl = TOUCH_SCL;
cfg.freq = I2C_TOUCH_FREQUENCY; // SPIクロックを設定
cfg.pin_sda = TOUCH_SDA;
cfg.pin_scl = TOUCH_SCL;
cfg.i2c_port = I2C_TOUCH_PORT; // 使用するI2Cを選択 (0 or 1)
cfg.i2c_addr = I2C_TOUCH_ADDRESS; // I2Cデバイスアドレス番号
cfg.freq = I2C_TOUCH_FREQUENCY; // SPIクロックを設定
#endif
tft._touch_instance.config(cfg);
tft._panel_instance->setTouch(&tft._touch_instance); // タッチスクリーンをパネルにセットします。
tft._touch_instance->config(cfg);
tft._panel_instance->setTouch(tft._touch_instance); // タッチスクリーンをパネルにセットします。
}
tft.setPanel(tft._panel_instance); // 使用するパネルをセットします。
@ -191,12 +194,20 @@ void LovyanGfx::show_info()
}
{
auto cfg = tft._touch_instance.config(); // バス設定用の構造体を取得します。
auto cfg = tft._touch_instance->config(); // バス設定用の構造体を取得します。
if(cfg.pin_cs != -1) {
tftPinInfo(F("TOUCH_CS"), cfg.pin_cs);
uint32_t freq = cfg.freq / 100000;
LOG_VERBOSE(TAG_TFT, F("Touch SPI freq. : %d.%d MHz"), freq / 10, freq % 10);
}
if(cfg.pin_sda != -1) {
tftPinInfo(F("TOUCH_SDA"), cfg.pin_sda);
}
if(cfg.pin_scl != -1) {
tftPinInfo(F("TOUCH_SCL"), cfg.pin_scl);
uint32_t freq = cfg.freq / 100000;
LOG_VERBOSE(TAG_TFT, F("Touch I2C freq. : %d.%d MHz"), freq / 10, freq % 10);
}
}
// tftPinInfo(F("TFT_WR"), tftSetup.pin_tft_wr);

View File

@ -28,7 +28,7 @@ class LGFX : public lgfx::LGFX_Device {
lgfx::Panel_LCD* _panel_instance;
lgfx::IBus* _bus_instance; // SPIバスのインスタンス
lgfx::Light_PWM _light_instance;
lgfx::Touch_XPT2046 _touch_instance;
lgfx::ITouch* _touch_instance;
LGFX(void)
{

View File

@ -48,7 +48,10 @@ class BaseTouch {
#define TOUCH_DRIVER -1 // No Touch
#endif
#if TOUCH_DRIVER == 2046 && defined(USER_SETUP_LOADED)
#if defined(LGFX_USE_V1)
#warning Building for LovyanGfx Touch
#include "touch_driver_lovyangfx.h"
#elif TOUCH_DRIVER == 2046 && defined(USER_SETUP_LOADED)
#warning Building for XPT2046
//#include "touch_driver_xpt2046.h"
#include "touch_driver_tftespi.h"

View File

@ -79,7 +79,7 @@ class TouchFt6336u : public BaseTouch {
LOG_INFO(TAG_DRVR, F("Touch SDA : %d"), TOUCH_SDA);
LOG_INFO(TAG_DRVR, F("Touch SCL : %d"), TOUCH_SCL);
LOG_INFO(TAG_DRVR, F("Touch freq. : %d"), I2C_TOUCH_FREQUENCY);
LOG_INFO(TAG_DRVR, F("Touch address : %x"), I2C_ADDR_FT6336U);
LOG_INFO(TAG_DRVR, F("Touch address : %x"), I2C_TOUCH_ADDRESS);
ft6336u_touch = new FT6336U(TOUCH_SDA, TOUCH_SCL, TOUCH_RST, TOUCH_IRQ);
ft6336u_touch->begin();
@ -91,7 +91,7 @@ class TouchFt6336u : public BaseTouch {
// handle these events. So instead, we set the INT wire to polled mode,
// so it simply goes low as long as there is at least one valid touch.
// ft6336u_touch->writeByte(0xA4, 0x00);
Wire1.beginTransmission(I2C_ADDR_FT6336U);
Wire1.beginTransmission(I2C_TOUCH_ADDRESS);
Wire1.write(0xA4); // address
Wire1.write(0x00); // data
Wire1.endTransmission();

View File

@ -6,8 +6,10 @@
#ifdef ARDUINO
#include <Arduino.h>
#include <Wire.h>
#include "touch_driver.h" // base class
#include "touch_helper.h" // wire scan
#include "dev/device.h" // for haspTft
#include "drv/tft/tft_driver.h"
@ -38,12 +40,13 @@ class TouchLovyanGfx : public BaseTouch {
int16_t touchX = 0;
int16_t touchY = 0;
if(haspTft.tft.getTouch((uint16_t*)&touchX, (uint16_t*)&touchY, 300)) {
if(haspTft.tft.getTouch((uint16_t*)&touchX, (uint16_t*)&touchY)) {
if(hasp_sleep_state != HASP_SLEEP_OFF) hasp_update_sleep_state(); // update Idle
data->point.x = touchX;
data->point.y = touchY;
data->state = LV_INDEV_STATE_PR;
LOG_VERBOSE(TAG_DRVR, F("Touch: %d %d"), touchX, touchY);
} else {
data->state = LV_INDEV_STATE_REL;
@ -53,6 +56,13 @@ class TouchLovyanGfx : public BaseTouch {
return false;
}
void init(int w, int h)
{
Wire.begin(TOUCH_SDA, TOUCH_SCL, I2C_TOUCH_FREQUENCY);
// delay(300); // already happens in touch.begin()
touch_scan(Wire);
}
void calibrate(uint16_t* calData)
{
haspTft.tft.fillScreen(TFT_BLACK);
@ -66,7 +76,7 @@ class TouchLovyanGfx : public BaseTouch {
haspTft.tft.setTextFont(1);
delay(500);
haspTft.tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15);
haspTft.tft.setTouch(calData);
// haspTft.tft.setTouch(calData);
}
};

View File

@ -196,8 +196,7 @@ void guiSetup()
PSTR(LVGL_VERSION_INFO));
/* Initialize the LVGL display driver with correct orientation */
#if TOUCH_DRIVER == 2046
#if(TOUCH_DRIVER == 2046) || defined(LGFX_USE_V1) // Use native display driver to rotate display and touch
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.buffer = &disp_buf;
@ -214,22 +213,22 @@ void guiSetup()
lv_disp_t* display = lv_disp_drv_register(&disp_drv);
lv_disp_set_rotation(display, LV_DISP_ROT_NONE);
#elif defined(LANBONL8)
/*
#elif defined(LANBONL8) // Screen is 0 deg. rotated
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.buffer = &disp_buf;
disp_drv.flush_cb = gui_flush_cb;
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.buffer = &disp_buf;
disp_drv.flush_cb = gui_flush_cb;
disp_drv.hor_res = tft_width;
disp_drv.ver_res = tft_height;
disp_drv.hor_res = tft_width;
disp_drv.ver_res = tft_height;
lv_disp_rot_t rotation[] = {LV_DISP_ROT_NONE, LV_DISP_ROT_270, LV_DISP_ROT_180, LV_DISP_ROT_90};
lv_disp_t* display = lv_disp_drv_register(&disp_drv);
lv_disp_set_rotation(display, rotation[(4 + gui_settings.rotation - TFT_ROTATION) % 4]);
#elif defined(M5STACK)
lv_disp_rot_t rotation[] = {LV_DISP_ROT_NONE, LV_DISP_ROT_270, LV_DISP_ROT_180, LV_DISP_ROT_90};
lv_disp_t* display = lv_disp_drv_register(&disp_drv);
lv_disp_set_rotation(display, rotation[(4 + gui_settings.rotation - TFT_ROTATION) % 4]);
*/
#elif defined(M5STACK) // Screen is 90 deg. rotated
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.buffer = &disp_buf;
@ -242,8 +241,7 @@ void guiSetup()
lv_disp_t* display = lv_disp_drv_register(&disp_drv);
lv_disp_set_rotation(display, rotation[(4 + gui_settings.rotation - TFT_ROTATION) % 4]);
#else
#else // Use lvgl transformations
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.buffer = &disp_buf;

View File

@ -31,6 +31,7 @@ build_flags =
-D TOUCH_IRQ=27
-D TOUCH_RST=-1 ; not used
-D I2C_TOUCH_FREQUENCY=400000
-D I2C_TOUCH_ADDRESS=0x38
-D SPI_FREQUENCY=40000000
-D SPI_READ_FREQUENCY=20000000
;endregion

View File

@ -17,6 +17,7 @@ build_flags =
;region -- TFT_eSPI build options ------------------------
-D USER_SETUP_LOADED=1
;-D LGFX_USE_V1=1
-D ILI9488_DRIVER=1
-D TFT_ROTATION=0 ; 0=0, 1=90, 2=180 or 3=270 degree
-D TFT_WIDTH=320

View File

@ -34,6 +34,7 @@ build_flags =
-D TOUCH_IRQ=-1 ; not connected
-D TOUCH_RST=-1 ; not used, connected to 3.3V on FCP pin10
-D I2C_TOUCH_FREQUENCY=400000
-D I2C_TOUCH_ADDRESS=0x38
-D LED_RED=26
-D LED_GREEN=32
-D LED_BLUE=33

View File

@ -32,6 +32,7 @@ build_flags =
-D TOUCH_IRQ=39
-D TOUCH_RST=-1 ; Managed by AXP_IO4
-D I2C_TOUCH_FREQUENCY=400000
-D I2C_TOUCH_ADDRESS=0x38
;endregion
;region -- Library options -------------------------------

View File

@ -32,7 +32,6 @@ build_flags =
;-D TFT_ROTATION=0 ; Use default, see TFT_ROTATION values
-D LGFX_USE_V1=1
;-D SUPPORT_TRANSACTIONS ; Default on ESP32
-D I2C_TOUCH_FREQUENCY=400000
-D TFT_MISO=23
-D TFT_MOSI=19
-D TFT_SCLK=18
@ -40,6 +39,9 @@ build_flags =
-D TFT_CS=5
-D TFT_RST=-1 ; RST
-D TFT_BCKL=12 ; None, configurable via web UI (e.g. 21)
-D I2C_TOUCH_FREQUENCY=400000
-D I2C_TOUCH_PORT=1
-D I2C_TOUCH_ADDRESS=0x38
-D TOUCH_DRIVER=911 ; GT911 Capacitive I2C touch panel driver
-D TOUCH_IRQ=34
-D TOUCH_RST=-1

View File

@ -33,12 +33,14 @@ build_flags =
-D TFT_CS=5
-D TFT_RST=-1 ; RST
-D TFT_BCKL=12 ; None, configurable via web UI (e.g. 21)
-D I2C_TOUCH_FREQUENCY=400000
-D I2C_TOUCH_PORT=1
-D I2C_TOUCH_ADDRESS=0x38
-D TOUCH_DRIVER=6336
-D TOUCH_IRQ=34
-D TOUCH_RST=-1
-D TOUCH_SDA=21
-D TOUCH_SCL=22
-D I2C_TOUCH_FREQUENCY=400000
;endregion
;region -- Hasp build options ----------------------------

View File

@ -33,6 +33,7 @@ build_flags =
-D TOUCH_IRQ=-1 ; not connected
-D TOUCH_RST=-1 ; not used, connected to 3.3V
-D I2C_TOUCH_FREQUENCY=400000
-D I2C_TOUCH_ADDRESS=0x38
;endregion
;region -- Library options -------------------------------