Skip to content

Commit

Permalink
Fixed CSTxxx Can't dected chip id
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Sep 8, 2023
1 parent cc80f3a commit f648afa
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ void setup()
Serial.println("Could't find touch chip!"); delay(1000);
}

// Select touch model
touch.setModel(TouchDrvCSTXXX::DRV_CST226SE);
// touch.setModel(TouchDrvCSTXXX::DRV_CST816T);

touch.setPins(SENSOR_RST, SENSOR_IRQ);
touch.init(Wire, SENSOR_SDA, SENSOR_SCL, address);

Expand Down
76 changes: 55 additions & 21 deletions src/TouchDrvCSTXXX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class TouchDrvCSTXXX :
public:


enum TouchModel {
DRV_CST226SE,
DRV_CST816T,
};

#if defined(ARDUINO)
TouchDrvCSTXXX(TwoWire &w,
int sda = DEFAULT_SDA,
Expand Down Expand Up @@ -115,9 +120,9 @@ class TouchDrvCSTXXX :
uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point = 1)
{
switch (__model) {
case CST816T_MODEL_ID:
case DRV_CST816T:
return __getCST816T(x_array, y_array, get_point);
case CST226SE_MODEL_ID:
case DRV_CST226SE:
return __getCST226SE(x_array, y_array, get_point);
default:
return 0;
Expand Down Expand Up @@ -150,9 +155,9 @@ class TouchDrvCSTXXX :
const char *getModelName()
{
switch (__model) {
case CST816T_MODEL_ID:
case DRV_CST816T:
return "CST816T";
case CST226SE_MODEL_ID:
case DRV_CST226SE:
return "CST226SE";
default:
return "UNKONW";
Expand Down Expand Up @@ -205,6 +210,24 @@ class TouchDrvCSTXXX :
this->user_data = user_data;
}



void setModel(enum TouchModel model)
{
__model = model;
switch (__model) {
case DRV_CST816T:
__maxPoint = 1;
break;
case DRV_CST226SE:
__maxPoint = 5;
break;
default:
__maxPoint = 1;
break;
}
}

private:

uint8_t __getCST226SE(int16_t *x_array, int16_t *y_array, uint8_t get_point)
Expand Down Expand Up @@ -240,6 +263,7 @@ class TouchDrvCSTXXX :
if (buffer[5] == 0x80) {
return 0;
}

uint8_t point = buffer[5] & 0x7F;
if (point > 5 || !point) {
writeRegister(0x00, 0xAB);
Expand All @@ -257,7 +281,7 @@ class TouchDrvCSTXXX :
LOG_PORT.printf("[%d] --> X:%d Y:%d \n", i, x_array[i], y_array[i]);
}
#endif
return 0;
return point;
}


Expand Down Expand Up @@ -299,6 +323,17 @@ class TouchDrvCSTXXX :

}

/*
void dumpRegister()
{
for (int i = 0xA5; i < 0xAD; ++i) {
int val = readRegister(i);
Serial.print("REG:0x"); Serial.print(i, HEX);
Serial.print(" Value:0x"); Serial.println(val, HEX);
}
}
*/

bool initImpl()
{
setReadRegisterSendStop(false);
Expand All @@ -317,22 +352,21 @@ class TouchDrvCSTXXX :
//Model ID Register : 0xA8
//CST816T : 0X22 , One point
//CST226SE : 0X08 , five point
__model = readRegister(CSTXXX_REG_MODEL_ID);

switch (__model) {
case CST816T_MODEL_ID:
Serial.println("Find CST816T");
__maxPoint = 1;
break;
case CST226SE_MODEL_ID:
Serial.println("Find CST226SE");
__maxPoint = 5;
break;
default:
Serial.print("Find device ID :"); Serial.println(__model);
__maxPoint = 1;
break;
}
// __model = readRegister(CSTXXX_REG_MODEL_ID);
// switch (__model) {
// case DRV_CST816T:
// Serial.println("Find CST816T");
// __maxPoint = 1;
// break;
// case DRV_CST226SE:
// Serial.println("Find CST226SE");
// __maxPoint = 5;
// break;
// default:
// Serial.print("Find device ID :"); Serial.println(__model);
// __maxPoint = 1;
// break;
// }

return probe();
}
Expand Down

0 comments on commit f648afa

Please sign in to comment.