Skip to content

Commit

Permalink
Update CST9217 jumpCheck method
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Aug 10, 2024
1 parent f273b3b commit ed08766
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 24 deletions.
14 changes: 11 additions & 3 deletions examples/TouchDrv_CST9217_GetPoint/TouchDrv_CST9217_GetPoint.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
21 changes: 13 additions & 8 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
49 changes: 36 additions & 13 deletions src/TouchDrvCST92xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
#if defined(ARDUINO)
TouchDrvCST92xx::TouchDrvCST92xx():
__center_btn_x(0),
__center_btn_y(0)
__center_btn_y(0),
__jump_check(false)
{
}

Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/TouchDrvCST92xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -167,6 +170,7 @@ class TouchDrvCST92xx : public TouchDrvInterface,
protected:
int16_t __center_btn_x;
int16_t __center_btn_y;
bool __jump_check;
};


Expand Down

0 comments on commit ed08766

Please sign in to comment.