Skip to content

Commit

Permalink
[TouchDrv] Added CST9217/CST9220 support
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Jul 9, 2024
1 parent 293c4a9 commit 99d9f14
Show file tree
Hide file tree
Showing 8 changed files with 4,213 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/arduino_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
examples/BHI260AP_StepCounter/BHI260AP_StepCounter.ino,
examples/BMM150_GetDataExample/BMM150_GetDataExample.ino,
examples/TouchDrv_Interface_T_RGB/TouchDrv_Interface_T_RGB.ino,
examples/TouchDrv_CST9217_GetPoint/TouchDrv_CST9217_GetPoint.ino,

]

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
examples/BHI260AP_StepCounter/BHI260AP_StepCounter.ino,
examples/BMM150_GetDataExample/BMM150_GetDataExample.ino,
examples/TouchDrv_Interface_T_RGB/TouchDrv_Interface_T_RGB.ino,
examples/TouchDrv_CST9217_GetPoint/TouchDrv_CST9217_GetPoint.ino,
]

steps:
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
[![STAR](https://img.shields.io/github/stars/lewisxhe/SensorsLib)](https://github.com/lewisxhe/SensorsLib/stargazers)
[![releases](https://img.shields.io/github/release/lewisxhe/SensorsLib)](https://github.com/lewisxhe/SensorLib/releases)

![PCF8563](https://img.shields.io/badge/PCB8563-GREEN)
![PCF8563](https://img.shields.io/badge/PCF8563-GREEN)
![PCF85063](https://img.shields.io/badge/PCF85063-GREEN)
![HYM8563](https://img.shields.io/badge/HYM8563-GREEN)
![QMI8658](https://img.shields.io/badge/QMI8658-blue)
Expand All @@ -46,6 +46,8 @@
![CST226SE](https://img.shields.io/badge/CST226SE-red)
![CHSC5816](https://img.shields.io/badge/CHSC5816-red)
![GT911](https://img.shields.io/badge/GT911-red)
![CST9217](https://img.shields.io/badge/CST9217-red)
![CST9220](https://img.shields.io/badge/CST9220-red)

Support list:

Expand All @@ -71,3 +73,6 @@ Support list:
| CST226SE | Capacitive touch | ✔️ ||
| CHSC5816 | Capacitive touch | ✔️ ||
| GT911 | Capacitive touch | ✔️ ||
| CST9217 | Capacitive touch | ✔️ ||
| CST9220 | Capacitive touch | ✔️ ||

149 changes: 149 additions & 0 deletions examples/TouchDrv_CST9217_GetPoint/TouchDrv_CST9217_GetPoint.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/**
*
* @license MIT License
*
* Copyright (c) 2024 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* 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 OR COPYRIGHT HOLDERS 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.
*
* @file TouchDrv_CST9217_GetPoint.ino
* @author Lewis He (lewishe@outlook.com)
* @date 2024-07-27
*
*/
#include <Wire.h>
#include <SPI.h>
#include <Arduino.h>
#include "touch/TouchClassCST92xx.h"
#include "SensorWireHelper.h"


#ifndef SENSOR_SDA
#define SENSOR_SDA 8
#endif

#ifndef SENSOR_SCL
#define SENSOR_SCL 10
#endif

#ifndef SENSOR_IRQ
#define SENSOR_IRQ 5
#endif

#ifndef SENSOR_RST
#define SENSOR_RST -1
#endif

TouchClassCST92xx touch;
int16_t x[5], y[5];
bool isPressed = false;


void setup()
{
Serial.begin(115200);
while (!Serial);

#if SENSOR_RST != -1
pinMode(SENSOR_RST, OUTPUT);
digitalWrite(SENSOR_RST, LOW);
delay(30);
digitalWrite(SENSOR_RST, HIGH);
delay(50);
delay(1000);
#endif

#ifdef ARDUINO_ARCH_RP2040
Wire.setSCL(SENSOR_SCL);
Wire.setSDA(SENSOR_SDA);
#else
Wire.begin(SENSOR_SDA, SENSOR_SCL);
#endif

// Scan I2C devices
SensorWireHelper::dumpDevices(Wire);


touch.setPins(SENSOR_RST, SENSOR_IRQ);
bool result = touch.begin(Wire, CST92XX_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL);
if (result == false) {
Serial.println("touch is not online..."); while (1)delay(1000);
}
Serial.print("Model :"); Serial.println(touch.getModelName());

touch.setCoverScreenCallback([](void *ptr) {
Serial.print(millis());
Serial.println(" : The screen is covered");
}, NULL);

// Unable to obtain coordinates after turning on sleep
// CST9217 Work current ~= 1.3mA
// CST9217 sleep current = 3.4 uA
touch.sleep();

int i = 10;
while (i--) {
Serial.printf("Wake up after %d seconds\n", i);
delay(1000);
}

// Wakeup touch
touch.reset();

// Set touch max xy
// touch.setMaxCoordinates(240, 296);

// Set swap xy
// touch.setSwapXY(true);

// Set mirror xy
// touch.setMirrorXY(true, true);

//Register touch plane interrupt pin
attachInterrupt(SENSOR_IRQ, []() {
isPressed = true;
}, FALLING);
}

void loop()
{
if (isPressed) {
isPressed = false;
uint8_t touched = touch.getPoint(x, y, touch.getSupportTouchPoint());
if (touched) {
for (int i = 0; i < touched; ++i) {
Serial.print("X[");
Serial.print(i);
Serial.print("]:");
Serial.print(x[i]);
Serial.print(" ");
Serial.print(" Y[");
Serial.print(i);
Serial.print("]:");
Serial.print(y[i]);
Serial.print(" ");
}
Serial.println();
}
}
delay(30);
}



6 changes: 3 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
; src_dir = examples/TouchDrv_GT911_LilyGo_T_RGB
; src_dir = examples/TouchDrv_Interface_T_RGB
; src_dir = examples/TouchDrv_FT6232_GetPoint
src_dir = examples/TouchDrv_GT911_GetPoint
; src_dir = examples/TouchDrv_GT911_GetPoint
; src_dir = examples/TouchDrv_CHSC5816_GetPoint
; src_dir = examples/TouchDrv_CSTxxx_GetPoint

src_dir = examples/TouchDrv_CST9217_GetPoint

; default_envs = esp32-s3n4r2
default_envs=esp32s3-opi
Expand Down Expand Up @@ -129,7 +129,7 @@ build_flags =
-DSENSOR_IRQ=15
-DSENSOR_RST=41

-DCORE_DEBUG_LEVEL=5
-DCORE_DEBUG_LEVEL=0
-Wnarrowing
-Wtype-limits
-Werror
Expand Down
Loading

0 comments on commit 99d9f14

Please sign in to comment.