@@ -21,17 +21,10 @@ Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaste
21
21
bool Cst816S::Init () {
22
22
nrf_gpio_cfg_output (PinMap::Cst816sReset);
23
23
nrf_gpio_pin_clear (PinMap::Cst816sReset);
24
- vTaskDelay (5 );
24
+ vTaskDelay (10 );
25
25
nrf_gpio_pin_set (PinMap::Cst816sReset);
26
26
vTaskDelay (50 );
27
27
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
-
35
28
// Read the device ids, and use the chip ID to know which variant is used.
36
29
ReadDeviceIds ();
37
30
@@ -50,17 +43,28 @@ bool Cst816S::Init() {
50
43
[4] EnMotion - When the detected gesture is pulsed Low.
51
44
[0] OnceWLP - Press gesture only issue a pulse signal is low.
52
45
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.
54
48
Although the CST18S supports mode switching, the CST716 can only done one (permanently configured by the factory).
55
49
CST716 default is report mode.
56
50
*/
57
- static constexpr uint8_t irqCtl = 0b01110000 ;
51
+
52
+ static constexpr uint8_t irqCtl = 0x70 ;
58
53
twiMaster.Write (twiAddress, 0xFA , &irqCtl, 1 );
59
54
60
55
return true ;
61
56
}
62
57
63
58
Cst816S::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
+
64
68
Cst816S::TouchInfos info;
65
69
uint8_t touchData[7 ];
66
70
@@ -103,27 +107,13 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() {
103
107
}
104
108
105
109
void 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.
107
111
// During this auto-sleep, it can wake up by touch but has its I2C interface disabled.
108
112
// The Cst716 cannot wake up by touch, and can only come out of sleep by resetting it.
109
113
// 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 );
127
117
}
128
118
129
119
NRF_LOG_INFO (" [TOUCHPANEL] Sleep" );
0 commit comments