@@ -101,29 +101,42 @@ static void __touchInit()
101
101
if (initialized ){
102
102
return ;
103
103
}
104
- initialized = true;
104
+
105
+ esp_err_t err = ESP_OK ;
105
106
106
107
#if SOC_TOUCH_VERSION_1 // ESP32
107
- touch_pad_init ();
108
- // the next two lines will drive the touch reading values
109
- touch_pad_set_voltage (TOUCH_HVOLT_2V7 , TOUCH_LVOLT_0V5 , TOUCH_HVOLT_ATTEN_0V );
108
+ err = touch_pad_init ();
109
+ if (err != ESP_OK ) {
110
+ goto err ;
111
+ }
112
+ // the next two lines will drive the touch reading values -- both will return ESP_OK
113
+ touch_pad_set_voltage (TOUCH_HVOLT_2V7 , TOUCH_LVOLT_0V5 , TOUCH_HVOLT_ATTEN_0V );
110
114
touch_pad_set_meas_time (__touchMeasureCycles , __touchSleepCycles );
111
115
// Touch Sensor Timer initiated
112
- touch_pad_set_fsm_mode (TOUCH_FSM_MODE_TIMER );
113
- touch_pad_filter_start (10 );
116
+ touch_pad_set_fsm_mode (TOUCH_FSM_MODE_TIMER ); // returns ESP_OK
117
+ err = touch_pad_filter_start (10 );
118
+ if (err != ESP_OK ) {
119
+ goto err ;
120
+ }
114
121
// Initial no Threshold and setup
115
122
for (int i = 0 ; i < SOC_TOUCH_SENSOR_NUM ; i ++ ) {
116
123
__touchInterruptHandlers [i ].fn = NULL ;
117
- touch_pad_config (i , SOC_TOUCH_PAD_THRESHOLD_MAX );
124
+ touch_pad_config (i , SOC_TOUCH_PAD_THRESHOLD_MAX ); // returns ESP_OK
118
125
}
119
126
// keep ISR activated - it can run all together (ISR + touchRead())
120
- touch_pad_isr_register (__touchISR , NULL );
121
- touch_pad_intr_enable ();
127
+ err = touch_pad_isr_register (__touchISR , NULL );
128
+ if (err != ESP_OK ) {
129
+ goto err ;
130
+ }
131
+ touch_pad_intr_enable (); // returns ESP_OK
122
132
#endif
123
133
124
134
#if SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3
125
- touch_pad_init ();
126
- // the next two lines will drive the touch reading values
135
+ err = touch_pad_init ();
136
+ if (err != ESP_OK ) {
137
+ goto err ;
138
+ }
139
+ // the next lines will drive the touch reading values -- all os them return ESP_OK
127
140
touch_pad_set_meas_time (TOUCH_PAD_SLEEP_CYCLE_DEFAULT , TOUCH_PAD_MEASURE_CYCLE_DEFAULT );
128
141
touch_pad_set_voltage (TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD , TOUCH_PAD_LOW_VOLTAGE_THRESHOLD , TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD );
129
142
touch_pad_set_idle_channel_connect (TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT );
@@ -134,18 +147,28 @@ static void __touchInit()
134
147
touch_pad_denoise_set_config (& denoise );
135
148
touch_pad_denoise_enable ();
136
149
// Touch Sensor Timer initiated
137
- touch_pad_set_fsm_mode (TOUCH_FSM_MODE_TIMER );
138
- touch_pad_fsm_start ();
150
+ touch_pad_set_fsm_mode (TOUCH_FSM_MODE_TIMER ); // returns ESP_OK
151
+ touch_pad_fsm_start (); // returns ESP_OK
139
152
140
153
// Initial no Threshold and setup - TOUCH0 is internal denoise channel
141
- for (int i = 0 ; i < SOC_TOUCH_SENSOR_NUM ; i ++ ) {
154
+ for (int i = 1 ; i < SOC_TOUCH_SENSOR_NUM ; i ++ ) {
142
155
__touchInterruptHandlers [i ].fn = NULL ;
143
- touch_pad_config (i );
156
+ touch_pad_config (i ); // returns ESP_OK
144
157
}
145
158
// keep ISR activated - it can run all together (ISR + touchRead())
146
- touch_pad_isr_register (__touchISR , NULL , TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE );
147
- touch_pad_intr_enable (TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE );
159
+ err = touch_pad_isr_register (__touchISR , NULL , TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE );
160
+ if (err != ESP_OK ) {
161
+ goto err ;
162
+ }
163
+ touch_pad_intr_enable (TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE ); // returns ESP_OK
148
164
#endif
165
+
166
+ initialized = true;
167
+ return ;
168
+ err :
169
+ log_e (" Touch sensor initialization error." );
170
+ initialized = false;
171
+ return ;
149
172
}
150
173
151
174
static uint32_t __touchRead (uint8_t pin )
0 commit comments