Added compatibility with LilyGo T-Deck-Pro V1.1

This commit is contained in:
lewisxhe
2026-01-21 17:33:50 +08:00
parent fb3bf783dd
commit 15b474172a
8 changed files with 312 additions and 7 deletions
+2 -1
View File
@@ -88,7 +88,8 @@ class ScanI2C
BH1750,
DA217,
CHSC6X,
CST226SE
CST226SE,
CST3530,
} DeviceType;
// typedef uint8_t DeviceAddress;
+26 -1
View File
@@ -508,8 +508,33 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
SCAN_SIMPLE_CASE(DFROBOT_RAIN_ADDR, DFROBOT_RAIN, "DFRobot Rain Gauge", (uint8_t)addr.address);
SCAN_SIMPLE_CASE(LTR390UV_ADDR, LTR390UV, "LTR390UV", (uint8_t)addr.address);
SCAN_SIMPLE_CASE(PCT2075_ADDR, PCT2075, "PCT2075", (uint8_t)addr.address);
case CST328_ADDR:
// Do we have the CST328 or the CST226SE
// Do we have the CST328 or the CST226SE,CST3530
{
// T-Deck pro V1.1 new touch panel use CST3530
int retry = 5;
while(retry--) {
uint8_t buffer[7];
uint8_t r_cmd[] = {0x0d0,0x03,0x00,0x00};
i2cBus->beginTransmission(addr.address);
i2cBus->write(r_cmd, sizeof(r_cmd));
if(i2cBus->endTransmission() == 0){
i2cBus->requestFrom((int)addr.address,7);
i2cBus->readBytes(buffer,7);
if(buffer[2] == 0xCA && buffer[3] == 0xCA){
logFoundDevice("CST3530", (uint8_t)addr.address);
type = CST3530;
break;
}
}
uint8_t cmd1[] = {0xD0,0x00,0x04,0x00};
i2cBus->beginTransmission(addr.address);
i2cBus->write(cmd1, sizeof(cmd1));
i2cBus->endTransmission();
delay(50);
}
}
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xAB), 1);
if (registerValue == 0xA9) {
type = CST226SE;
+3
View File
@@ -104,8 +104,11 @@ bool EInkDisplay::forceDisplay(uint32_t msecLimit)
// End the update process - virtual method, overriden in derived class
void EInkDisplay::endUpdate()
{
#ifndef EINK_NOT_HIBERNATE
// Power off display hardware, then deep-sleep (Except Wireless Paper V1.1, no deep-sleep)
adafruitDisplay->hibernate();
#endif
}
// Write the buffer to the display memory
+4
View File
@@ -413,6 +413,10 @@ void setup()
digitalWrite(SDCARD_CS, HIGH);
pinMode(PIN_EINK_CS, OUTPUT);
digitalWrite(PIN_EINK_CS, HIGH);
pinMode(PIN_EINK_RES, OUTPUT);
digitalWrite(PIN_EINK_RES, HIGH);
pinMode(CST328_PIN_RST, OUTPUT);
digitalWrite(CST328_PIN_RST, HIGH);
#elif defined(T_LORA_PAGER)
pinMode(LORA_CS, OUTPUT);
digitalWrite(LORA_CS, HIGH);
@@ -8,20 +8,126 @@
CSE_CST328 tsPanel = CSE_CST328(EINK_WIDTH, EINK_HEIGHT, &Wire, CST328_PIN_RST, CST328_PIN_INT);
static bool is_cst3530 = false;
volatile bool touch_isr = false;
#define CST3530_ADDR 0x1A
bool read_cst3530_touch(int16_t *x, int16_t *y) {
uint8_t buffer[9] = {0};
uint8_t r_cmd[] = {0xD0, 0x07, 0x00, 0x00};
uint8_t clear_cmd[] = {0xD0, 0x00, 0x02, 0xAB};
Wire.beginTransmission(CST3530_ADDR);
Wire.write(r_cmd, sizeof(r_cmd));
if (Wire.endTransmission() != 0) {
LOG_DEBUG("CST3530 I2C send addr failed");
return false;
}
int read_len = Wire.requestFrom((int)CST3530_ADDR, sizeof(buffer));
if (read_len != sizeof(buffer)) {
LOG_DEBUG("CST3530 read len error: %d (expect 9)", read_len);
return false;
}
int actual_read = Wire.readBytes(buffer, sizeof(buffer));
if (actual_read != sizeof(buffer)) {
LOG_DEBUG("CST3530 read bytes error: %d (expect 9)", actual_read);
return false;
}
uint8_t report_typ = buffer[2];
if (report_typ != 0xFF) {
return false;
}
uint8_t touch_points = buffer[3] & 0x0F;
if (touch_points == 0 || touch_points > 1) {
LOG_DEBUG("CST3530 touch points invalid: %d", touch_points);
return false;
}
*x = buffer[4] + ((uint16_t)(buffer[7] & 0x0F) << 8);
*y = buffer[5] + ((uint16_t)(buffer[7] & 0xF0) << 4);
// LOG_DEBUG("CST3530 touch: num:%d x=%d,y=%d", touch_points, *x, *y);
Wire.beginTransmission(CST3530_ADDR);
Wire.write(clear_cmd, sizeof(clear_cmd));
if (Wire.endTransmission() != 0) {
LOG_DEBUG("CST3530 clear cmd failed");
}
return true;
}
bool readTouch(int16_t *x, int16_t *y)
{
if (tsPanel.getTouches()) {
*x = tsPanel.getPoint(0).x;
*y = tsPanel.getPoint(0).y;
return true;
if(is_cst3530){
if(touch_isr){
touch_isr = false;
return read_cst3530_touch(x, y);
}
return false;
}else{
if (tsPanel.getTouches()) {
*x = tsPanel.getPoint(0).x;
*y = tsPanel.getPoint(0).y;
return true;
}
}
return false;
}
static void touchInterruptHandler(){
touch_isr = true;
}
// T-Deck Pro specific init
void lateInitVariant()
{
tsPanel.begin();
// Reset touch
pinMode(CST328_PIN_RST, OUTPUT);
digitalWrite(CST328_PIN_RST, HIGH);
delay(20);
digitalWrite(CST328_PIN_RST, LOW);
delay(80);
digitalWrite(CST328_PIN_RST, HIGH);
delay(20);
int retry = 5;
uint8_t buffer[7];
uint8_t r_cmd[] = {0x0d0,0x03,0x00,0x00};
// Probe touch chip
while(retry--) {
Wire.beginTransmission(CST3530_ADDR);
Wire.write(r_cmd, sizeof(r_cmd));
if(Wire.endTransmission() == 0){
Wire.requestFrom((int)CST3530_ADDR,7);
Wire.readBytes(buffer,7);
if(buffer[2] == 0xCA && buffer[3] == 0xCA){
LOG_DEBUG("CST3530 detected");
is_cst3530 = true;
// The CST3530 will automatically enter sleep mode;
// polling should not be used, but rather an interrupt method should be employed.
pinMode(CST328_PIN_INT, INPUT);
attachInterrupt(digitalPinToInterrupt(CST328_PIN_INT), touchInterruptHandler, FALLING);
break;
}else{
LOG_DEBUG("CST3530 not response ~!");
}
}
uint8_t cmd1[] = {0xD0,0x00,0x04,0x00};
Wire.beginTransmission(CST3530_ADDR);
Wire.write(cmd1, sizeof(cmd1));
Wire.endTransmission();
delay(50);
}
touchScreenImpl1 = new TouchScreenImpl1(EINK_WIDTH, EINK_HEIGHT, readTouch);
touchScreenImpl1->init();
}