Skip to content

Commit 69f0968

Browse files
ci(pre-commit): Apply automatic fixes
1 parent da31968 commit 69f0968

File tree

5 files changed

+84
-80
lines changed

5 files changed

+84
-80
lines changed

Diff for: cores/esp32/esp32-hal-touch-ng.c

+58-55
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ typedef struct {
3434
bool lastStatusIsPressed;
3535
} TouchInterruptHandle_t;
3636

37-
static TouchInterruptHandle_t __touchInterruptHandlers[SOC_TOUCH_SENSOR_NUM] = { 0,};
37+
static TouchInterruptHandle_t __touchInterruptHandlers[SOC_TOUCH_SENSOR_NUM] = {
38+
0,
39+
};
3840

3941
static uint8_t _sample_num = 1;
4042
static uint32_t _div_num = 1;
@@ -52,7 +54,7 @@ static bool enabled = false;
5254
static bool running = false;
5355
static bool channels_initialized[SOC_TOUCH_SENSOR_NUM] = {false};
5456

55-
static touch_sensor_handle_t touch_sensor_handle = NULL;
57+
static touch_sensor_handle_t touch_sensor_handle = NULL;
5658
static touch_channel_handle_t touch_channel_handle[SOC_TOUCH_SENSOR_NUM] = {};
5759

5860
// Active threshold to benchmark ratio. (i.e., touch will be activated when data >= benchmark * (1 + ratio))
@@ -61,7 +63,7 @@ static float s_thresh2bm_ratio = 0.015f; // 1.5% for all channels
6163
static bool ARDUINO_ISR_ATTR __touchOnActiveISR(touch_sensor_handle_t sens_handle, const touch_active_event_data_t *event, void *user_ctx) {
6264
uint8_t pad_num = (uint8_t)event->chan_id;
6365
__touchInterruptHandlers[pad_num].lastStatusIsPressed = true;
64-
if(__touchInterruptHandlers[pad_num].fn) {
66+
if (__touchInterruptHandlers[pad_num].fn) {
6567
// keeping backward compatibility with "void cb(void)" and with new "void cb(void *)"
6668
if (__touchInterruptHandlers[pad_num].callWithArgs) {
6769
((voidArgFuncPtr)__touchInterruptHandlers[pad_num].fn)(__touchInterruptHandlers[pad_num].arg);
@@ -75,7 +77,7 @@ static bool ARDUINO_ISR_ATTR __touchOnActiveISR(touch_sensor_handle_t sens_handl
7577
static bool ARDUINO_ISR_ATTR __touchOnInactiveISR(touch_sensor_handle_t sens_handle, const touch_inactive_event_data_t *event, void *user_ctx) {
7678
uint8_t pad_num = (uint8_t)event->chan_id;
7779
__touchInterruptHandlers[pad_num].lastStatusIsPressed = false;
78-
if(__touchInterruptHandlers[pad_num].fn) {
80+
if (__touchInterruptHandlers[pad_num].fn) {
7981
// keeping backward compatibility with "void cb(void)" and with new "void cb(void *)"
8082
if (__touchInterruptHandlers[pad_num].callWithArgs) {
8183
((voidArgFuncPtr)__touchInterruptHandlers[pad_num].fn)(__touchInterruptHandlers[pad_num].arg);
@@ -87,10 +89,10 @@ static bool ARDUINO_ISR_ATTR __touchOnInactiveISR(touch_sensor_handle_t sens_han
8789
}
8890

8991
bool touchStop() {
90-
if (!running) { // Already stopped
92+
if (!running) { // Already stopped
9193
return true;
9294
}
93-
if(touch_sensor_stop_continuous_scanning(touch_sensor_handle) != ESP_OK) {
95+
if (touch_sensor_stop_continuous_scanning(touch_sensor_handle) != ESP_OK) {
9496
log_e("Touch sensor stop scanning failed!");
9597
return false;
9698
}
@@ -99,10 +101,10 @@ bool touchStop() {
99101
}
100102

101103
bool touchDisable() {
102-
if (!enabled) { // Already disabled
104+
if (!enabled) { // Already disabled
103105
return true;
104106
}
105-
if(!running && (touch_sensor_disable(touch_sensor_handle) != ESP_OK)) {
107+
if (!running && (touch_sensor_disable(touch_sensor_handle) != ESP_OK)) {
106108
log_e("Touch sensor still running or disable failed!");
107109
return false;
108110
}
@@ -111,10 +113,10 @@ bool touchDisable() {
111113
}
112114

113115
bool touchStart() {
114-
if (running) { // Already running
116+
if (running) { // Already running
115117
return true;
116118
}
117-
if(enabled && (touch_sensor_start_continuous_scanning(touch_sensor_handle) != ESP_OK)) {
119+
if (enabled && (touch_sensor_start_continuous_scanning(touch_sensor_handle) != ESP_OK)) {
118120
log_e("Touch sensor not enabled or failed to start continuous scanning failed!");
119121
return false;
120122
}
@@ -123,10 +125,10 @@ bool touchStart() {
123125
}
124126

125127
bool touchEnable() {
126-
if (enabled) { // Already enabled
128+
if (enabled) { // Already enabled
127129
return true;
128130
}
129-
if(touch_sensor_enable(touch_sensor_handle) != ESP_OK) {
131+
if (touch_sensor_enable(touch_sensor_handle) != ESP_OK) {
130132
log_e("Touch sensor enable failed!");
131133
return false;
132134
}
@@ -135,33 +137,37 @@ bool touchEnable() {
135137
}
136138

137139
bool touchBenchmarkThreshold(uint8_t pad) {
138-
if (!touchEnable()) {return false;}
140+
if (!touchEnable()) {
141+
return false;
142+
}
139143

140144
/* Scan the enabled touch channels for several times, to make sure the initial channel data is stable */
141145
for (int i = 0; i < 3; i++) {
142-
if(touch_sensor_trigger_oneshot_scanning(touch_sensor_handle, 2000) != ESP_OK) {
146+
if (touch_sensor_trigger_oneshot_scanning(touch_sensor_handle, 2000) != ESP_OK) {
143147
log_e("Touch sensor trigger oneshot scanning failed!");
144148
return false;
145149
}
146150
}
147151

148152
/* Disable the touch channel to rollback the state */
149-
if (!touchDisable()) {return false;}
153+
if (!touchDisable()) {
154+
return false;
155+
}
150156

151157
// Reconfigure passed pad with new threshold
152158
uint32_t benchmark[_sample_num] = {};
153-
if(touch_channel_read_data(touch_channel_handle[pad], TOUCH_CHAN_DATA_TYPE_BENCHMARK, benchmark) != ESP_OK) {
159+
if (touch_channel_read_data(touch_channel_handle[pad], TOUCH_CHAN_DATA_TYPE_BENCHMARK, benchmark) != ESP_OK) {
154160
log_e("Touch channel read data failed!");
155161
return false;
156162
}
157163
/* Calculate the proper active thresholds regarding the initial benchmark */
158164
touch_channel_config_t chan_cfg = {};
159165
for (int i = 0; i < _sample_num; i++) {
160166
chan_cfg.active_thresh[i] = (uint32_t)(benchmark[i] * s_thresh2bm_ratio);
161-
log_v("Configured [CH %d] sample %d: benchmark = %"PRIu32", threshold = %"PRIu32"\t", pad, i, benchmark[i], chan_cfg.active_thresh[i]);
167+
log_v("Configured [CH %d] sample %d: benchmark = %" PRIu32 ", threshold = %" PRIu32 "\t", pad, i, benchmark[i], chan_cfg.active_thresh[i]);
162168
}
163169
/* Update the channel configuration */
164-
if(touch_sensor_reconfig_channel(touch_channel_handle[pad], &chan_cfg) != ESP_OK) {
170+
if (touch_sensor_reconfig_channel(touch_channel_handle[pad], &chan_cfg) != ESP_OK) {
165171
log_e("Touch sensor threshold reconfig channel failed!");
166172
return false;
167173
}
@@ -187,8 +193,6 @@ static bool touchDetachBus(void *pin) {
187193
return true;
188194
}
189195

190-
191-
192196
static void __touchInit() {
193197
if (initialized) {
194198
return;
@@ -199,9 +203,9 @@ static void __touchInit() {
199203
sample_cfg[0] = single_sample_cfg;
200204

201205
/* Allocate new touch controller handle */
202-
touch_sensor_config_t sens_cfg = {
206+
touch_sensor_config_t sens_cfg = {
203207
.power_on_wait_us = __touchSleepTime,
204-
.meas_interval_us = __touchMeasureTime,
208+
.meas_interval_us = __touchMeasureTime,
205209
.max_meas_time_us = 0,
206210
.output_mode = TOUCH_PAD_OUT_AS_CLOCK,
207211
.sample_cfg_num = _sample_num,
@@ -250,10 +254,10 @@ static void __touchChannelInit(int pad) {
250254
__touchInterruptHandlers[pad].fn = NULL;
251255

252256
touch_channel_config_t chan_cfg = {
253-
.active_thresh = {1000} // default threshold, will be updated after benchmark
257+
.active_thresh = {1000} // default threshold, will be updated after benchmark
254258
};
255-
256-
if(!touchStop() || !touchDisable()) {
259+
260+
if (!touchStop() || !touchDisable()) {
257261
log_e("Touch sensor stop and disable failed!");
258262
return;
259263
}
@@ -272,7 +276,7 @@ static void __touchChannelInit(int pad) {
272276
channels_initialized[pad] = true;
273277
used_pads++;
274278

275-
if(!touchEnable() || !touchStart()) {
279+
if (!touchEnable() || !touchStart()) {
276280
log_e("Touch sensor enable and start failed!");
277281
}
278282
}
@@ -300,9 +304,9 @@ static touch_value_t __touchRead(uint8_t pin) {
300304

301305
uint32_t touch_read[_sample_num] = {};
302306
touch_channel_read_data(touch_channel_handle[pad], TOUCH_CHAN_DATA_TYPE_SMOOTH, touch_read);
303-
touch_value_t touch_value = touch_read[0]; // only one sample configuration for now
307+
touch_value_t touch_value = touch_read[0]; // only one sample configuration for now
304308

305-
return touch_value;
309+
return touch_value;
306310
}
307311

308312
static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Args, bool callWithArgs, touch_value_t threshold) {
@@ -326,25 +330,25 @@ static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Ar
326330
__touchInterruptHandlers[pad].arg = Args;
327331
}
328332

329-
if(threshold != 0) {
330-
if(!touchStop() || !touchDisable()) {
331-
log_e("Touch sensor stop and disable failed!");
332-
return;
333-
}
333+
if (threshold != 0) {
334+
if (!touchStop() || !touchDisable()) {
335+
log_e("Touch sensor stop and disable failed!");
336+
return;
337+
}
334338

335-
touch_channel_config_t chan_cfg = {};
336-
for (int i = 0; i < _sample_num; i++) {
337-
chan_cfg.active_thresh[i] = threshold;
338-
}
339+
touch_channel_config_t chan_cfg = {};
340+
for (int i = 0; i < _sample_num; i++) {
341+
chan_cfg.active_thresh[i] = threshold;
342+
}
339343

340-
if(touch_sensor_reconfig_channel(touch_channel_handle[pad], &chan_cfg) != ESP_OK) {
341-
log_e("Touch sensor threshold reconfig channel failed!");
342-
}
344+
if (touch_sensor_reconfig_channel(touch_channel_handle[pad], &chan_cfg) != ESP_OK) {
345+
log_e("Touch sensor threshold reconfig channel failed!");
346+
}
343347

344-
if(!touchEnable() || !touchStart()) {
345-
log_e("Touch sensor enable and start failed!");
348+
if (!touchEnable() || !touchStart()) {
349+
log_e("Touch sensor enable and start failed!");
350+
}
346351
}
347-
}
348352
}
349353

350354
// it keeps backwards compatibility
@@ -394,36 +398,35 @@ void touchSleepWakeUpEnable(uint8_t pin, touch_value_t threshold) {
394398
}
395399

396400
log_v("Touch sensor deep sleep wake-up configuration for pad %d with threshold %d", pad, threshold);
397-
if(!touchStop() || !touchDisable()) {
401+
if (!touchStop() || !touchDisable()) {
398402
log_e("Touch sensor stop and disable failed!");
399403
return;
400404
}
401405

402406
touch_sleep_config_t deep_slp_cfg = {
403-
.slp_wakeup_lvl = TOUCH_DEEP_SLEEP_WAKEUP,
404-
.deep_slp_chan = touch_channel_handle[pad],
405-
.deep_slp_thresh = {threshold},
406-
.deep_slp_sens_cfg = NULL, // Use the original touch sensor configuration
407+
.slp_wakeup_lvl = TOUCH_DEEP_SLEEP_WAKEUP,
408+
.deep_slp_chan = touch_channel_handle[pad],
409+
.deep_slp_thresh = {threshold},
410+
.deep_slp_sens_cfg = NULL, // Use the original touch sensor configuration
407411
};
408412

409413
// Register the deep sleep wake-up
410-
if(touch_sensor_config_sleep_wakeup(touch_sensor_handle, &deep_slp_cfg) != ESP_OK) {
411-
log_e("Touch sensor deep sleep wake-up failed!");
412-
return;
414+
if (touch_sensor_config_sleep_wakeup(touch_sensor_handle, &deep_slp_cfg) != ESP_OK) {
415+
log_e("Touch sensor deep sleep wake-up failed!");
416+
return;
413417
}
414418

415-
if(!touchEnable() || !touchStart()) {
419+
if (!touchEnable() || !touchStart()) {
416420
log_e("Touch sensor enable and start failed!");
417421
}
418-
419422
}
420423

421424
void touchSetDefaultThreshold(float percentage) {
422425
s_thresh2bm_ratio = (float)percentage / 100.0f;
423426
}
424427

425428
void touchSetTiming(float measure, uint32_t sleep) {
426-
if(initialized) {
429+
if (initialized) {
427430
log_e("Touch sensor already initialized. Cannot set cycles.");
428431
return;
429432
}
@@ -432,7 +435,7 @@ void touchSetTiming(float measure, uint32_t sleep) {
432435
}
433436

434437
void touchSetConfig(uint32_t div_num, uint8_t coarse_freq_tune, uint8_t fine_freq_tune) {
435-
if(initialized) {
438+
if (initialized) {
436439
log_e("Touch sensor already initialized. Cannot set configuration.");
437440
return;
438441
}

Diff for: cores/esp32/esp32-hal-touch.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
Internal Private Touch Data Structure and Functions
2525
*/
2626

27-
#if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
27+
#if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
2828
static uint16_t __touchSleepCycles = 0x1000;
2929
static uint16_t __touchMeasureCycles = 0x1000;
3030
#elif SOC_TOUCH_SENSOR_VERSION == 2 // ESP32S2, ESP32S3
@@ -53,7 +53,7 @@ static bool initialized = false;
5353
static bool channels_initialized[SOC_TOUCH_SENSOR_NUM] = {false};
5454

5555
static void ARDUINO_ISR_ATTR __touchISR(void *arg) {
56-
#if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
56+
#if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
5757
uint32_t pad_intr = touch_pad_get_status();
5858
//clear interrupt
5959
touch_pad_clear_status();
@@ -95,7 +95,7 @@ static void ARDUINO_ISR_ATTR __touchISR(void *arg) {
9595
static void __touchSetCycles(uint16_t measure, uint16_t sleep) {
9696
__touchSleepCycles = sleep;
9797
__touchMeasureCycles = measure;
98-
#if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
98+
#if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
9999
touch_pad_set_measurement_clock_cycles(measure);
100100
#elif SOC_TOUCH_SENSOR_VERSION == 2 // ESP32S2, ESP32S3
101101
touch_pad_set_charge_discharge_times(measure);
@@ -125,7 +125,7 @@ static void __touchInit() {
125125

126126
esp_err_t err = ESP_OK;
127127

128-
#if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
128+
#if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
129129
err = touch_pad_init();
130130
if (err != ESP_OK) {
131131
goto err;
@@ -145,7 +145,7 @@ static void __touchInit() {
145145
if (err != ESP_OK) {
146146
goto err;
147147
}
148-
touch_pad_intr_enable(); // returns ESP_OK
148+
touch_pad_intr_enable(); // returns ESP_OK
149149
#elif SOC_TOUCH_SENSOR_VERSION == 2 // ESP32S2, ESP32S3
150150
err = touch_pad_init();
151151
if (err != ESP_OK) {
@@ -180,11 +180,11 @@ static void __touchChannelInit(int pad) {
180180
return;
181181
}
182182

183-
#if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
183+
#if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
184184
// Initial no Threshold and setup
185185
__touchInterruptHandlers[pad].fn = NULL;
186186
touch_pad_config(pad, TOUCH_PAD_THRESHOLD_MAX); // returns ESP_OK
187-
#elif SOC_TOUCH_SENSOR_VERSION == 2 // ESP32S2, ESP32S3
187+
#elif SOC_TOUCH_SENSOR_VERSION == 2 // ESP32S2, ESP32S3
188188
// Initial no Threshold and setup
189189
__touchInterruptHandlers[pad].fn = NULL;
190190
touch_pad_config(pad); // returns ESP_OK
@@ -271,7 +271,7 @@ static void __touchDettachInterrupt(uint8_t pin) {
271271
External Public Touch API Functions
272272
*/
273273

274-
#if SOC_TOUCH_SENSOR_VERSION == 1 // Only for ESP32 SoC
274+
#if SOC_TOUCH_SENSOR_VERSION == 1 // Only for ESP32 SoC
275275
void touchInterruptSetThresholdDirection(bool mustbeLower) {
276276
if (mustbeLower) {
277277
touch_pad_set_trigger_mode(TOUCH_TRIGGER_BELOW);

Diff for: libraries/ESP32/examples/DeepSleep/TouchWakeUp/TouchWakeUp.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ Pranav Cherukupalli <[email protected]>
1515
*/
1616

1717
#if CONFIG_IDF_TARGET_ESP32
18-
#define THRESHOLD 40 /* Greater the value, more the sensitivity */
18+
#define THRESHOLD 40 /* Greater the value, more the sensitivity */
1919
#elif (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3)
2020
#define THRESHOLD 5000 /* Lower the value, more the sensitivity */
21-
#else // ESP32-P4 + default for other chips (to be adjusted) */
21+
#else // ESP32-P4 + default for other chips (to be adjusted) */
2222
#define THRESHOLD 500 /* Lower the value, more the sensitivity */
2323
#endif
2424

Diff for: libraries/ESP32/examples/Touch/TouchInterrupt/TouchInterrupt.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ The bigger the threshold, the more sensible is the touch
44
*/
55

66
#if CONFIG_IDF_TARGET_ESP32P4
7-
int threshold = 0; // when 0 is used, the benchmarked value will be used
8-
#else
7+
int threshold = 0; // when 0 is used, the benchmarked value will be used
8+
#else
99
int threshold = 40;
1010
#endif
1111

0 commit comments

Comments
 (0)