@@ -21,17 +21,10 @@ Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaste
2121bool Cst816S::Init () {
2222 nrf_gpio_cfg_output (PinMap::Cst816sReset);
2323 nrf_gpio_pin_clear (PinMap::Cst816sReset);
24- vTaskDelay (5 );
24+ vTaskDelay (10 );
2525 nrf_gpio_pin_set (PinMap::Cst816sReset);
2626 vTaskDelay (50 );
2727
28- // Wake the touchpanel up
29- uint8_t dummy;
30- twiMaster.Read (twiAddress, 0x15 , &dummy, 1 );
31- vTaskDelay (5 );
32- twiMaster.Read (twiAddress, 0xa7 , &dummy, 1 );
33- vTaskDelay (5 );
34-
3528 // Read the device ids, and use the chip ID to know which variant is used.
3629 ReadDeviceIds ();
3730
@@ -50,17 +43,28 @@ bool Cst816S::Init() {
5043 [4] EnMotion - When the detected gesture is pulsed Low.
5144 [0] OnceWLP - Press gesture only issue a pulse signal is low.
5245
53- This configures the chip in report mode (regular interrupts), instead of gesture mode.
46+ This configures the chip in report mode (regular interrupts during touch), instead of gesture mode.
47+ 0x60 = report mode, 0x11 = gesture mode, 0x71 = both.
5448 Although the CST18S supports mode switching, the CST716 can only done one (permanently configured by the factory).
5549 CST716 default is report mode.
5650 */
57- static constexpr uint8_t irqCtl = 0b01110000 ;
51+
52+ static constexpr uint8_t irqCtl = 0x70 ;
5853 twiMaster.Write (twiAddress, 0xFA , &irqCtl, 1 );
5954
6055 return true ;
6156}
6257
6358Cst816S::TouchInfos Cst816S::GetTouchInfo () {
59+ // Some chips fail to initialise even though the reset pin has been toggled.
60+ // The reset pin should wake them from auto-sleep, but it sometimes does not.
61+ // They only provide a I2C communication window after a touch interrupt,
62+ // so the first touch interrupt is used to force initialisation.
63+ if (firstEvent) {
64+ Init ();
65+ firstEvent = false ;
66+ }
67+
6468 Cst816S::TouchInfos info;
6569 uint8_t touchData[7 ];
6670
@@ -103,27 +107,13 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() {
103107}
104108
105109void Cst816S::Sleep () {
106- // The Cst816S ignores this sleep command , as is has an auto-sleep function.
110+ // The Cst816S does not need explicit sleep , as is has an auto-sleep function.
107111 // During this auto-sleep, it can wake up by touch but has its I2C interface disabled.
108112 // The Cst716 cannot wake up by touch, and can only come out of sleep by resetting it.
109113 // The accelerometer can be used instead to generate wakeup events.
110-
111- // Force a reset in case the chip went into auto-sleep mode
112- nrf_gpio_pin_clear (PinMap::Cst816sReset);
113- vTaskDelay (5 );
114- nrf_gpio_pin_set (PinMap::Cst816sReset);
115- vTaskDelay (50 );
116-
117- // The CST816 and CST716 differ in their sleep register addresses
118- uint8_t sleepRegister = 0 ;
119- if (variant == Variant::Cst816S) {
120- sleepRegister = 0xE5 ;
121- } else if (variant == Variant::Cst716) {
122- sleepRegister = 0xA5 ;
123- }
124- static constexpr uint8_t sleepValue = 0x03 ;
125- if (variant != Variant::Unknown) {
126- twiMaster.Write (twiAddress, sleepRegister, &sleepValue, 1 );
114+ if (variant == Variant::Cst716) {
115+ static constexpr uint8_t sleepValue = 0x03 ;
116+ twiMaster.Write (twiAddress, 0xA5 , &sleepValue, 1 );
127117 }
128118
129119 NRF_LOG_INFO (" [TOUCHPANEL] Sleep" );
0 commit comments