Merge pull request #879 from Szetya/master

TTGO T-Display S3 Touch
This commit is contained in:
fvanroie 2025-03-14 12:16:28 +01:00 committed by GitHub
commit 4c71062cf1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 14568 additions and 110 deletions

24
lib/cst816t/LICENSE Normal file
View File

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>

145
lib/cst816t/README.md Normal file
View File

@ -0,0 +1,145 @@
# cst816t capacitive touch ic
[![cst816t touch screen](extras/P169H002-CTP-small.jpg)](https://github.com/koendv/cst816t/raw/master/extras/P169H002-CTP.jpg)
This is an Arduino library for the cst816t capacitive touch ic. The cst816t capacitive touch ic is able to decode clicks, double clicks, swipes and long press in hardware. Tested on stm32duino.
The cst816t runs on voltages from 1.8V to 3.3V. Do not connect the cst816t to 5V arduinos such as Arduino UNO. Connecting the cst816t to 5V will probably damage the device.
Hardware requirements:
- power supply 2.8V to 3.6V
- power supply ripple <= 50mv;
- logic level 1.8V to 3.3V
- i2c rate 10Khz to 400Khz
## Use
Code for the cst816t consists of a setup, done once, and a loop, done repeatedly.
## Setup
The cst816t touch sensor needs an I2C bus, a reset pin and a interrupt pin:
```
#include <Wire.h>
#include "cst816t.h"
TwoWire Wire2(TP_SDA, TP_SCL);
cst816t touchpad(Wire2, TP_RST, TP_IRQ);
```
The ic can run in four modes: touch, change, fast, motion.
### mode touch
```
void setup() {
touchpad.begin(mode_touch);
}
```
In mode _touch_, if a finger touches the display the ic sends an interrupt every 10ms. After receiving the interrupt, you can read updated touch coordinates and finger count. All processing is done on the mcu.
### mode change
```
void setup() {
touchpad.begin(mode_change);
}
```
In mode _change_ the ic sends an interrupt when the finger changes position. Compared to mode touch, the number of interrupts is more moderate.
### mode fast
```
void setup() {
touchpad.begin(mode_fast);
}
```
In mode _fast_ the ic sends an interrupt when the finger has completed one of the following movements: single click, swipe up, swipe down, swipe left, swipe right.
Touch response is fast because there is no need to wait to distinguish between single click, double click and long press.
### mode motion
```
void setup() {
touchpad.begin(mode_motion);
}
```
In mode _motion_ the ic sends an interrupt when the finger has completed the following movements: single click, **double click**, swipe up, swipe down, swipe left, swipe right, **long press**. All processing is done in the cst816 touch ic. The processing in the mcu is minimal.
## Loop
Test repeatedly if there is an update from the touch panel. If there is an update from the touch panel, read gesture, (x, y) coordinates, and number of fingers touching the display.
```
void loop() {
if (touchpad.available()) {
switch (touchpad.gesture_id) {
case GESTURE_NONE:
Serial.print("NONE");
break;
case GESTURE_SWIPE_DOWN:
Serial.print("SWIPE DOWN");
break;
case GESTURE_SWIPE_UP:
Serial.print("SWIPE UP");
break;
case GESTURE_SWIPE_LEFT:
Serial.print("SWIPE LEFT");
break;
case GESTURE_SWIPE_RIGHT:
Serial.print("SWIPE RIGHT");
break;
case GESTURE_SINGLE_CLICK:
Serial.print("SINGLE CLICK");
break;
case GESTURE_DOUBLE_CLICK:
Serial.print("DOUBLE CLICK");
break;
case GESTURE_LONG_PRESS:
Serial.print("LONG PRESS");
break;
default:
Serial.print("UNKNOWN ");
break;
}
Serial.print("at (");
Serial.print(touchpad.x);
Serial.print(", ");
Serial.print(touchpad.y);
Serial.print(") fingers: ");
Serial.println(touchpad.finger_num);
}
}
```
## Examples
The library comes with three example Arduino sketches: touchme, smartwatch, and lvgl. To compile the examples, use [stm32duino](https://github.com/stm32duino/Arduino_Core_STM32/wiki).
### touchme
A simple sketch that uses the CST816T touch sensor. When the display is touched, the (x, y) coordinates and the action - click or swipe - are printed on the serial port.
### smartwatch
A small Arduino sketch for the [P169H002-CTP](https://www.google.com/search?q=P169H002-CTP) smartwatch display. The P169H002-CTP is a 1.69 inch 240x280 lcd display with an ST7789 lcd driver and a CST816T touch sensor. The sketch prints a text - "click" or "swipe" - on the spot where the display is touched.
### lvgl
[LVGL](http://www.lvgl.io) (Light and Versatile Graphics Library) is a graphics library for embedded systems. An Arduino sketch is given which draws a button on a P169H002-CTP display.
This lvgl example uses the Adafruit GFX library. For improved speed, you may wish to check if there is a library that is more optimized for the processor you use.
## Links
Arduino libraries for ST7789 tft driver:
- [Adafruit ST7789](https://github.com/adafruit/Adafruit-ST7735-Library/)
- [TFT_eSPI](https://github.com/Bodmer/TFT_eSPI)
- [ST7789-STM32](https://github.com/Floyd-Fish/ST7789-STM32)
- [ST7789-STM32-uGUI](https://github.com/deividAlfa/ST7789-STM32-uGUI)
[Schematic](extras/Schematic_drawing_2023-06-21.pdf
) for the P169H002-CTP display. VCC = 3.3V. The ambient light sensor is used to set display intensity.
The P169H002-CTP display is available from [Aliexpress](https://www.aliexpress.com/item/1005005238299349.html).

View File

@ -0,0 +1,128 @@
/* lvgl demo on P169H002-CTP display */
#include <SPI.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <Wire.h>
#include "cst816t.h" // capacitive touch
/* Note: in lv_conf.h: set lv_tick to Arduino millis() */
#include <lvgl.h>
// display
#define TFT_X 240
#define TFT_Y 280
#define TFT_CS PB1
#define TFT_RST PA4
#define TFT_DC PB0
#define TFT_MOSI PB15
#define TFT_SCLK PB13
#define TFT_LED PA8
// touch
#define TP_SDA PB11
#define TP_SCL PB10
#define TP_RST PA15
#define TP_IRQ PB3
TwoWire Wire2(TP_SDA, TP_SCL);
cst816t touchpad(Wire2, TP_RST, TP_IRQ);
SPIClass SPI_1(PB15, PB14, PB13);
Adafruit_ST7789 tft = Adafruit_ST7789(&SPI_1, TFT_CS, TFT_DC, TFT_RST);
static lv_disp_draw_buf_t disp_buf;
static lv_color_t buf_1[TFT_X * 10];
static lv_color_t buf_2[TFT_X * 10];
static lv_disp_drv_t disp_drv;
static lv_indev_drv_t indev_drv;
/* lvgl display output */
/* Using Adafruit display driver. Depending upon architecture, other drivers may be faster. */
void disp_flush_cb(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p) {
uint32_t w = 1 + area->x2 - area->x1;
uint32_t h = 1 + area->y2 - area->y1;
uint32_t len = w * h;
tft.startWrite();
tft.setAddrWindow(area->x1, area->y1, w, h);
tft.writePixels(&color_p->full, len);
tft.endWrite();
lv_disp_flush_ready(disp_drv);
}
/* lvgl touchpad input */
void touchpad_input_read(lv_indev_drv_t* drv, lv_indev_data_t* data) {
static uint32_t tp_x = 0;
static uint32_t tp_y = 0;
static uint32_t tp_fingers = 0;
if (touchpad.available()) {
tp_x = touchpad.x;
tp_y = touchpad.y;
tp_fingers = touchpad.finger_num;
}
data->point.x = tp_x;
data->point.y = tp_y;
if (tp_fingers != 0) data->state = LV_INDEV_STATE_PRESSED;
else data->state = LV_INDEV_STATE_RELEASED;
}
/* lvgl button callback */
void btn_event_cb(lv_event_t* e) {
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t* btn = lv_event_get_target(e);
if (code == LV_EVENT_CLICKED) {
static uint8_t cnt = 0;
cnt++;
/*Get the first child of the button which is the label and change its text*/
lv_obj_t* label = lv_obj_get_child(btn, 0);
lv_label_set_text_fmt(label, "Button %d", cnt);
}
}
void setup() {
Serial.begin(9600);
Serial.println("boot");
analogWriteResolution(8);
analogWrite(TFT_LED, 127); // display backlight at 50%
tft.init(240, 280); // Init ST7789 280x240
tft.fillScreen(ST77XX_BLACK);
tft.setTextColor(ST77XX_WHITE);
tft.setRotation(2);
touchpad.begin(mode_change);
/* display */
lv_init();
lv_disp_draw_buf_init(&disp_buf, buf_1, buf_2, TFT_X * 10);
lv_disp_drv_init(&disp_drv);
disp_drv.draw_buf = &disp_buf;
disp_drv.flush_cb = disp_flush_cb;
disp_drv.hor_res = TFT_X;
disp_drv.ver_res = TFT_Y;
lv_disp_t* disp;
disp = lv_disp_drv_register(&disp_drv);
/* touchpad */
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = touchpad_input_read;
lv_indev_t* my_indev = lv_indev_drv_register(&indev_drv);
/* button */
lv_obj_t* btn = lv_btn_create(lv_scr_act());
lv_obj_center(btn);
lv_obj_set_size(btn, 120, 50);
lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL);
lv_obj_t* label = lv_label_create(btn);
lv_label_set_text(label, "Button");
lv_obj_center(label);
}
void loop() {
lv_timer_handler();
}

View File

@ -0,0 +1,87 @@
/*
demo of P168H002-CTP display.
*/
#include <SPI.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <Wire.h>
#include "cst816t.h" // capacitive touch
// display
#define TFT_X 240
#define TFT_Y 280
#define TFT_CS PB1
#define TFT_RST PA4
#define TFT_DC PB0
#define TFT_MOSI PB15
#define TFT_SCLK PB13
#define TFT_LED PA8
// touch
#define TP_SDA PB11
#define TP_SCL PB10
#define TP_RST PA15
#define TP_IRQ PB3
TwoWire Wire2(TP_SDA, TP_SCL);
cst816t touchpad(Wire2, TP_RST, TP_IRQ);
SPIClass SPI_1(PB15, PB14, PB13);
Adafruit_ST7789 tft = Adafruit_ST7789(&SPI_1, TFT_CS, TFT_DC, TFT_RST);
void setup() {
Serial.begin(9600);
Serial.println("boot");
analogWriteResolution(8);
analogWrite(TFT_LED, 127); // display backlight at 50%
tft.init(240, 280); // Init ST7789 280x240
tft.fillScreen(ST77XX_BLACK);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(0);
tft.setRotation(2);
touchpad.begin(mode_motion);
tft.setCursor(TFT_X / 2, TFT_Y / 2);
tft.println(touchpad.version());
}
void loop() {
if (touchpad.available()) {
tft.setCursor(touchpad.x, touchpad.y);
tft.fillScreen(ST77XX_BLACK);
switch (touchpad.gesture_id) {
case GESTURE_NONE:
tft.print("NONE");
break;
case GESTURE_SWIPE_DOWN:
tft.print("SWIPE DOWN");
break;
case GESTURE_SWIPE_UP:
tft.print("SWIPE UP");
break;
case GESTURE_SWIPE_LEFT:
tft.print("SWIPE LEFT");
break;
case GESTURE_SWIPE_RIGHT:
tft.print("SWIPE RIGHT");
break;
case GESTURE_SINGLE_CLICK:
tft.print("SINGLE CLICK");
break;
case GESTURE_DOUBLE_CLICK:
tft.print("DOUBLE CLICK");
break;
case GESTURE_LONG_PRESS:
tft.print("LONG PRESS");
break;
default:
tft.print("?");
break;
}
}
}

View File

@ -0,0 +1,23 @@
/* demo for the CST816T capacitive touch ic */
#include <Wire.h>
#include "cst816t.h"
#define TP_SDA PB11
#define TP_SCL PB10
#define TP_RST PA15
#define TP_IRQ PB3
TwoWire Wire2(TP_SDA, TP_SCL);
cst816t touchpad(Wire2, TP_RST, TP_IRQ);
void setup() {
// decode everything: single click, double click, long press, swipe up, swipe down, swipe left, swipe right
touchpad.begin(mode_motion);
Serial.println(touchpad.version());
}
void loop() {
if (touchpad.available())
Serial.println(touchpad.state());
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 555 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,11 @@
name=cst816t
version=1.5.1
author=koendv
maintainer=koendv
sentence=cst816t capacitive touch screen
paragraph=An Arduino library for the cst816t capacitive touch screen IC
category=Other
url=https://github.com/koendv/cst816t
architectures=*
includes=cst816t.h

203
lib/cst816t/src/cst816t.cpp Normal file
View File

@ -0,0 +1,203 @@
/* CST816T capacitive touch-screen driver.
Koen De Vleeschauwer, 2023
Literature:
DS-CST816T-V2.2.pdf datasheet
AN-CST816T-v1.pdf register description
CST78XX-V1.0.pdf firmware upgrade how-to
*/
#include "cst816t.h"
#include <stdint.h>
#define CST816T_ADDRESS 0x15
#define REG_GESTURE_ID 0x01
#define REG_FINGER_NUM 0x02
#define REG_XPOS_H 0x03
#define REG_XPOS_L 0x04
#define REG_YPOS_H 0x05
#define REG_YPOS_L 0x06
#define REG_CHIP_ID 0xA7
#define REG_PROJ_ID 0xA8
#define REG_FW_VERSION 0xA9
#define REG_FACTORY_ID 0xAA
#define REG_SLEEP_MODE 0xE5
#define REG_IRQ_CTL 0xFA
#define REG_LONG_PRESS_TICK 0xEB
#define REG_MOTION_MASK 0xEC
#define REG_DIS_AUTOSLEEP 0xFE
#define MOTION_MASK_CONTINUOUS_LEFT_RIGHT 0b100
#define MOTION_MASK_CONTINUOUS_UP_DOWN 0b010
#define MOTION_MASK_DOUBLE_CLICK 0b001
#define IRQ_EN_TOUCH 0x40
#define IRQ_EN_CHANGE 0x20
#define IRQ_EN_MOTION 0x10
#define IRQ_EN_LONGPRESS 0x01
static bool tp_event = false;
static void tp_isr() {
tp_event = true;
}
cst816t::cst816t(TwoWire &_wire, int8_t _rst, int8_t _irq)
: wire(_wire) {
rst = _rst;
irq = _irq;
chip_id = 0;
firmware_version = 0;
tp_event = false;
gesture_id = 0;
finger_num = 0;
x = 0;
y = 0;
}
bool cst816t::begin(touchpad_mode tp_mode) {
uint8_t dta[4];
pinMode(irq, INPUT);
if (rst >= 0) {
pinMode(rst, OUTPUT);
digitalWrite(rst, HIGH);
delay(100);
digitalWrite(rst, LOW);
delay(10);
digitalWrite(rst, HIGH);
delay(100);
}
wire.begin();
if (i2c_read(CST816T_ADDRESS, REG_CHIP_ID, dta, sizeof(dta))) {
Serial.println("i2c error");
return false; // Sikertelen inicializálás
}
chip_id = dta[0];
firmware_version = dta[3];
uint8_t irq_en = 0x0;
uint8_t motion_mask = 0x0;
switch (tp_mode) {
case mode_touch:
irq_en = IRQ_EN_TOUCH;
break;
case mode_change:
irq_en = IRQ_EN_CHANGE;
break;
case mode_fast:
irq_en = IRQ_EN_MOTION;
break;
case mode_motion:
irq_en = IRQ_EN_MOTION | IRQ_EN_LONGPRESS;
motion_mask = MOTION_MASK_DOUBLE_CLICK;
break;
default:
return false; // Érvénytelen mód esetén sikertelen inicializálás
}
if (i2c_write(CST816T_ADDRESS, REG_IRQ_CTL, &irq_en, 1) ||
i2c_write(CST816T_ADDRESS, REG_MOTION_MASK, &motion_mask, 1)) {
Serial.println("i2c write error");
return false;
}
attachInterrupt(digitalPinToInterrupt(irq), tp_isr, FALLING);
// Disable auto sleep
uint8_t dis_auto_sleep = 0xFF;
if (i2c_write(CST816T_ADDRESS, REG_DIS_AUTOSLEEP, &dis_auto_sleep, 1)) {
Serial.println("Failed to disable auto sleep");
return false;
}
return true; // Sikeres inicializálás
}
bool cst816t::available() {
uint8_t dta[6];
if (tp_event && !i2c_read(CST816T_ADDRESS, REG_GESTURE_ID, dta, sizeof(dta))) {
tp_event = false;
gesture_id = dta[0];
finger_num = dta[1];
x = (((uint16_t)dta[2] & 0x0f) << 8) | (uint16_t)dta[3];
y = (((uint16_t)dta[4] & 0x0f) << 8) | (uint16_t)dta[5];
return true;
}
return false;
}
uint8_t cst816t::i2c_read(uint16_t addr, uint8_t reg_addr, uint8_t *reg_data, uint32_t length) {
wire.beginTransmission(addr);
wire.write(reg_addr);
if (wire.endTransmission(true)) return -1;
wire.requestFrom((uint8_t)addr, (size_t)length, (bool)true);
for (int i = 0; i < length; i++) {
*reg_data++ = wire.read();
}
return 0;
}
uint8_t cst816t::i2c_write(uint8_t addr, uint8_t reg_addr, const uint8_t *reg_data, uint32_t length) {
wire.beginTransmission(addr);
wire.write(reg_addr);
for (int i = 0; i < length; i++) {
wire.write(*reg_data++);
}
if (wire.endTransmission(true)) return -1;
return 0;
}
String cst816t::version() {
String tp_version;
switch (chip_id) {
case CHIPID_CST716: tp_version = "CST716"; break;
case CHIPID_CST816S: tp_version = "CST816S"; break;
case CHIPID_CST816T: tp_version = "CST816T"; break;
case CHIPID_CST816D: tp_version = "CST816D"; break;
default:
tp_version = "? 0x" + String(chip_id, HEX);
break;
}
tp_version += " firmware " + String(firmware_version);
return tp_version;
}
String cst816t::state() {
String s;
switch (gesture_id) {
case GESTURE_NONE:
s = "NONE";
break;
case GESTURE_SWIPE_DOWN:
s = "SWIPE DOWN";
break;
case GESTURE_SWIPE_UP:
s = "SWIPE UP";
break;
case GESTURE_SWIPE_LEFT:
s = "SWIPE LEFT";
break;
case GESTURE_SWIPE_RIGHT:
s = "SWIPE RIGHT";
break;
case GESTURE_SINGLE_CLICK:
s = "SINGLE CLICK";
break;
case GESTURE_DOUBLE_CLICK:
s = "DOUBLE CLICK";
break;
case GESTURE_LONG_PRESS:
s = "LONG PRESS";
break;
default:
s = "UNKNOWN 0x";
s += String(gesture_id, HEX);
break;
}
s += '\t' + String(x) + '\t' + String(y);
return s;
}

56
lib/cst816t/src/cst816t.h Normal file
View File

@ -0,0 +1,56 @@
#ifndef _CST816T_H_
#define _CST816T_H_
#include <Arduino.h>
#include <Wire.h>
#include <stdint.h>
#define CHIPID_CST716 0x20
#define CHIPID_CST816S 0xB4
#define CHIPID_CST816T 0xB5
#define CHIPID_CST816D 0xB6
#define GESTURE_NONE 0x00
#define GESTURE_SWIPE_UP 0x01
#define GESTURE_SWIPE_DOWN 0x02
#define GESTURE_SWIPE_LEFT 0x03
#define GESTURE_SWIPE_RIGHT 0x04
#define GESTURE_SINGLE_CLICK 0x05
#define GESTURE_DOUBLE_CLICK 0x0B
#define GESTURE_LONG_PRESS 0x0C
enum touchpad_mode {
mode_touch,
mode_change,
mode_fast,
mode_motion
};
class cst816t {
public:
cst816t(TwoWire &_wire, int8_t _rst, int8_t _irq);
/*
mode_touch: interrupt every 10ms when a touch is detected
mode_change: interrupt when a touch change is detected
mode_fast: interrupt when a click or swipe is detected
mode_motion: interrupt when a click, swipe, double click, or long press is detected
*/
bool begin(touchpad_mode tp_mode = mode_change);
bool available();
String version();
String state();
uint8_t chip_id;
uint8_t firmware_version;
uint8_t gesture_id;
uint8_t finger_num;
uint16_t x;
uint16_t y;
private:
TwoWire& wire;
int8_t rst;
int8_t irq;
uint8_t i2c_read(uint16_t addr, uint8_t reg_addr, uint8_t *reg_data, uint32_t length);
uint8_t i2c_write(uint8_t addr, uint8_t reg_addr, const uint8_t *reg_data, uint32_t length);
};
#endif

View File

@ -82,6 +82,8 @@ extra_default_envs =
; yeacreate-nscreen32
; wz2432r028
; ws_esp32_s3_touch_lcd_4p3
; ttgo-t-display-s3_st7789_16MB
; ttgo-t-display-s3_st7789_touch_16MB
;endregion
;region -- Define your local COM ports for each environment ---

View File

@ -93,6 +93,9 @@ class BaseTouch {
#elif TOUCH_DRIVER == 0x3240
#warning Building for CST3240
#include "touch_driver_cst3240.h"
#elif TOUCH_DRIVER == 0x816
#warning Building for CST816S
#include "touch_driver_cst816.h"
#else
#warning Building for Generic Touch
using dev::BaseTouch;

View File

@ -0,0 +1,70 @@
/* MIT License - Copyright (c) 2019-2024 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#if defined(ARDUINO) && (TOUCH_DRIVER == 0x816)
#include <Arduino.h>
#include "ArduinoLog.h"
#include "hasp_conf.h"
#include "touch_driver_cst816.h"
#include <Wire.h>
#include "cst816t.h"
#include "touch_driver.h" // base class
#include "touch_helper.h" // i2c scanner
#include "../../hasp/hasp.h" // for hasp_sleep_state
extern uint8_t hasp_sleep_state;
cst816t touchpad(Wire, TOUCH_RST, TOUCH_IRQ);
namespace dev {
IRAM_ATTR bool TouchCst816::read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data)
{
if(touchpad.available()) {
if(hasp_sleep_state != HASP_SLEEP_OFF) hasp_update_sleep_state(); // update Idle
//LOG_INFO(TAG_DRVR, "CST816 touched x:%d, y:%d", touchpad.x, touchpad.y);
#ifdef TOUCH_WIDTH
data->point.x = map(touchpad.x, 0, TOUCH_WIDTH - 1, 0, TFT_WIDTH - 1);
#else
data->point.x = touchpad.x;
#endif
#ifdef TOUCH_HEIGHT
data->point.y = map(touchpad.y, 0, TOUCH_HEIGHT - 1, 0, TFT_HEIGHT - 1);
#else
data->point.y = touchpad.y;
#endif
data->state = LV_INDEV_STATE_PR;
hasp_set_sleep_offset(0); // Reset the offset
} else {
data->state = LV_INDEV_STATE_REL;
}
/*Return `false` because we are not buffering and no more data to read*/
return false;
}
void TouchCst816::init(int w, int h)
{
Wire.begin(TOUCH_SDA, TOUCH_SCL, (uint32_t)I2C_TOUCH_FREQUENCY);
if(touchpad.begin(mode_touch) == true) {
LOG_INFO(TAG_DRVR, "CST816 %s (170X320)", D_SERVICE_STARTED);
} else {
LOG_WARNING(TAG_DRVR, "CST816 %s", D_SERVICE_START_FAILED);
}
Wire.begin(TOUCH_SDA, TOUCH_SCL, (uint32_t)I2C_TOUCH_FREQUENCY);
touch_scan(Wire); // The address could change during begin, so scan afterwards
}
} // namespace dev
dev::TouchCst816 haspTouch;
#endif // ARDUINO

View File

@ -0,0 +1,27 @@
/* MIT License - Copyright (c) 2019-2024 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_CST816_TOUCH_DRIVER_H
#define HASP_CST816_TOUCH_DRIVER_H
#ifdef ARDUINO
#include "lvgl.h"
#include "touch_driver.h"
namespace dev {
class TouchCst816 : public BaseTouch {
public:
IRAM_ATTR bool read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data);
void init(int w, int h);
};
} // namespace dev
using dev::TouchCst816;
extern dev::TouchCst816 haspTouch;
#endif // ARDUINO
#endif // HASP_CST816_TOUCH_DRIVER_H

View File

@ -0,0 +1,77 @@
;***************************************************;
; TTGO T-Display-S3 with ST7789 ;
; - TTGO T7 S3 v1.1 Mini esp32 s3 board ;
; - ST7789 TFT ;
; - CST816S touch controller ;
;***************************************************;
[ttgo-t-display-s3_st7789]
extends = arduino_esp32s3_v2
board = lilygo-t-display-s3
board_build.arduino.memory_type = qio_opi
build_flags =
${env.build_flags}
${esp32s3.build_flags}
${esp32s3.ps_ram}
-D HASP_MODEL="TTGO T-Display S3"
;-Wno-macro-redefined
-D ARDUINO_USB_MODE=0 ; If USB MODE 1, the device will only boot when a serial port is opened.
-D ARDUINO_USB_CDC_ON_BOOT
-D USE_USB_CDC_CONSOLE
;region -- TFT_eSPI build options ------------------------
-D USER_SETUP_LOADED=1
-D ST7789_DRIVER=1
-D CGRAM_OFFSET=1 ; Library will add offsets required
; -D TFT_SDA_READ ; Read from display, it only provides an SDA pin
-D TFT_WIDTH=170
-D TFT_HEIGHT=320
; -D TFT_ROTATION=2 ; see TFT_ROTATION values
; -D TFT_INVERSION_OFF ; for normal colors
-D TFT_INVERSION_ON
-D TFT_RGB_ORDER=0 ; Colour order Blue-Green-Red
-D INVERT_COLORS=1 ; for inverted colors
-D DISABLE_ALL_LIBRARY_WARNINGS ; Disable TFTeSPI log warning
; -D INIT_SEQUENCE_3 ; Using this initialisation sequence improves the display image
-D TFT_PARALLEL_8_BIT
-D TFT_DC=7
-D TFT_RST=5
-D TFT_WR=8
-D TFT_RD=9
-D TFT_D0=39
-D TFT_D1=40
-D TFT_D2=41
-D TFT_D3=42
-D TFT_D4=45
-D TFT_D5=46
-D TFT_D6=47
-D TFT_D7=48
-D TFT_BCKL=38
; Touch Settings
-D TOUCH_DRIVER=0x816
-D TOUCH_SDA=18
-D TOUCH_SCL=17
-D TOUCH_RST=21
-D TOUCH_IRQ=16
-D I2C_TOUCH_FREQUENCY=400000
-D I2C_TOUCH_ADDRESS=0x15
; End Touch Settings
;endregion
;region -- Library options -------------------------------
lib_deps =
${env.lib_deps}
${esp32s3.lib_deps}
${arduino_esp32s3_v2.lib_deps}
${tft_espi.lib_deps}
lib_ignore =
${env.lib_ignore}
${esp32s3.lib_ignore}
${arduino_esp32s3_v2.lib_ignore}
;endregion
[env:ttgo-t-display-s3_st7789_touch_16MB]
extends = ttgo-t-display-s3_st7789, flash_16mb