Skip to content

Commit c7ec9c5

Browse files
committed
fixes initialization return codes
1 parent cd43edf commit c7ec9c5

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

cores/esp32/esp32-hal-touch.c

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,29 +101,42 @@ static void __touchInit()
101101
if(initialized){
102102
return;
103103
}
104-
initialized = true;
104+
105+
esp_err_t err = ESP_OK;
105106

106107
#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);
110114
touch_pad_set_meas_time(__touchMeasureCycles, __touchSleepCycles);
111115
// 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+
}
114121
// Initial no Threshold and setup
115122
for (int i = 0; i < SOC_TOUCH_SENSOR_NUM; i++) {
116123
__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
118125
}
119126
// 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
122132
#endif
123133

124134
#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
127140
touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_MEASURE_CYCLE_DEFAULT);
128141
touch_pad_set_voltage(TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD);
129142
touch_pad_set_idle_channel_connect(TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT);
@@ -134,18 +147,28 @@ static void __touchInit()
134147
touch_pad_denoise_set_config(&denoise);
135148
touch_pad_denoise_enable();
136149
// 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
139152

140153
// 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++) {
142155
__touchInterruptHandlers[i].fn = NULL;
143-
touch_pad_config(i);
156+
touch_pad_config(i); // returns ESP_OK
144157
}
145158
// 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
148164
#endif
165+
166+
initialized = true;
167+
return;
168+
err:
169+
log_e(" Touch sensor initialization error.");
170+
initialized = false;
171+
return;
149172
}
150173

151174
static uint32_t __touchRead(uint8_t pin)

0 commit comments

Comments
 (0)