From ed087661a9d4c5b109c8069d6dc632e6b7c9d69f Mon Sep 17 00:00:00 2001 From: lewisxhe Date: Sat, 10 Aug 2024 15:31:18 +0800 Subject: [PATCH] Update CST9217 jumpCheck method --- .../TouchDrv_CST9217_GetPoint.ino | 14 ++++-- platformio.ini | 21 +++++--- src/TouchDrvCST92xx.cpp | 49 ++++++++++++++----- src/TouchDrvCST92xx.h | 4 ++ 4 files changed, 64 insertions(+), 24 deletions(-) diff --git a/examples/TouchDrv_CST9217_GetPoint/TouchDrv_CST9217_GetPoint.ino b/examples/TouchDrv_CST9217_GetPoint/TouchDrv_CST9217_GetPoint.ino index f4b4adb..aebcc8c 100644 --- a/examples/TouchDrv_CST9217_GetPoint/TouchDrv_CST9217_GetPoint.ino +++ b/examples/TouchDrv_CST9217_GetPoint/TouchDrv_CST9217_GetPoint.ino @@ -84,10 +84,16 @@ void setup() SensorWireHelper::dumpDevices(Wire); + // uint8_t touchAddress = 0x1A; // Other device addresses are determined by the touch firmware and are generally 0X5A by default. + uint8_t touchAddress = 0x5A; // The device address is determined according to the actual situation. Not all device addresses are 0X5A. There can also be other customized device addresses. + + + // Set to skip register check, used when the touch device address conflicts with other I2C device addresses [0x5A] + touch.jumpCheck(); + + touch.setPins(SENSOR_RST, SENSOR_IRQ); - // The device address is determined according to the actual situation. Not all device addresses are 0X5A. There can also be other customized device addresses. - // CST92XX_SLAVE_ADDRESS = 0x5A - bool result = touch.begin(Wire, CST92XX_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL); + bool result = touch.begin(Wire, touchAddress, SENSOR_SDA, SENSOR_SCL); if (result == false) { Serial.println("touch is not online..."); while (1)delay(1000); } @@ -98,6 +104,8 @@ void setup() Serial.println(" : The screen is covered"); }, NULL); + + Serial.println("Enter touch sleep mode."); // Unable to obtain coordinates after turning on sleep // CST9217 Work current ~= 1.3mA // CST9217 sleep current = 3.4 uA diff --git a/platformio.ini b/platformio.ini index e8e286a..a9c96d9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,6 @@ ; src_dir = examples/BHI260AP_aux_BMM150_BME280 ; src_dir = examples/BMM150_GetDataExample -src_dir = examples/BHI260AP_aux_BMM150_BME280 ; Touch devices support list ; src_dir = examples/TouchDrv_FT3267_LilyGo_T_RGB @@ -61,13 +60,13 @@ src_dir = examples/BHI260AP_aux_BMM150_BME280 ; src_dir = examples/TouchDrv_GT911_GetPoint ; src_dir = examples/TouchDrv_CHSC5816_GetPoint ; src_dir = examples/TouchDrv_CSTxxx_GetPoint -; src_dir = examples/TouchDrv_CST9217_GetPoint +src_dir = examples/TouchDrv_CST9217_GetPoint ; default_envs = esp32dev -; default_envs = esp32s3 +default_envs = esp32s3 ; default_envs = esp32c3 ; default_envs = rp2040 -default_envs = nrf52840 +; default_envs = nrf52840 ; Custom board variant boards_dir = ./board @@ -131,10 +130,16 @@ build_flags = ; -DSENSOR_IRQ=15 ; -DSENSOR_RST=41 - -DSENSOR_SDA=33 - -DSENSOR_SCL=35 - -DSENSOR_IRQ=34 - -DSENSOR_RST=-1 + ; -DSENSOR_SDA=33 + ; -DSENSOR_SCL=35 + ; -DSENSOR_IRQ=34 + ; -DSENSOR_RST=-1 + + ; T-Watch-S3-U + -DSENSOR_SDA=2 + -DSENSOR_SCL=3 + -DSENSOR_IRQ=12 + -DSENSOR_RST=46 -DCORE_DEBUG_LEVEL=0 -Wnarrowing diff --git a/src/TouchDrvCST92xx.cpp b/src/TouchDrvCST92xx.cpp index 2040a07..72eb5b8 100644 --- a/src/TouchDrvCST92xx.cpp +++ b/src/TouchDrvCST92xx.cpp @@ -31,7 +31,8 @@ #if defined(ARDUINO) TouchDrvCST92xx::TouchDrvCST92xx(): __center_btn_x(0), - __center_btn_y(0) + __center_btn_y(0), + __jump_check(false) { } @@ -1105,6 +1106,10 @@ int16_t TouchDrvCST92xx::updateFirmware(void) #endif /*DISABLE UPDATE FIRMWARE*/ +void TouchDrvCST92xx::jumpCheck() +{ + __jump_check = true; +} void TouchDrvCST92xx::setGpioCallback(gpio_mode_fptr_t mode_cb, gpio_write_fptr_t write_cb, @@ -1119,24 +1124,42 @@ bool TouchDrvCST92xx::initImpl() { int retry = 5; - while (retry > 0) { - if (enterBootloader()) { - break; + if (!__jump_check) { + while (retry > 0) { + if (enterBootloader()) { + break; + } + retry--; + delay(1000); + } + if (0 == retry) { + log_e("Enter boot loader mode failed!"); + return false; } - retry--; - delay(1000); - } - if (0 == retry) { - log_e("Enter boot loader mode failed!"); - return false; - } - chipType = getChipType(); + chipType = getChipType(); - log_d("Chip ID:0x%x", chipType); + log_d("Chip ID:0x%x", chipType); + + } else { + + log_d("Jump check setting default IC type : CST9217"); + // Jump check setting default IC type + chipType = CST9217_CHIP_ID; + + } reset(); + if(__jump_check && __addr != CST92XX_BOOT_ADDRESS){ + delay(55); + } + + if (!this->probe()) { + log_e("device is not online"); + return false; + } + if (chipType != CST9220_CHIP_ID && chipType != CST9217_CHIP_ID) { return false; } diff --git a/src/TouchDrvCST92xx.h b/src/TouchDrvCST92xx.h index 5b8da79..41c16de 100644 --- a/src/TouchDrvCST92xx.h +++ b/src/TouchDrvCST92xx.h @@ -61,6 +61,9 @@ class TouchDrvCST92xx : public TouchDrvInterface, #if defined(ARDUINO) TouchDrvCST92xx(); + + void jumpCheck(); + bool begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl); #elif defined(ESP_PLATFORM) @@ -167,6 +170,7 @@ class TouchDrvCST92xx : public TouchDrvInterface, protected: int16_t __center_btn_x; int16_t __center_btn_y; + bool __jump_check; };