@@ -37,19 +37,19 @@ typedef struct {
37
37
static TouchInterruptHandle_t __touchInterruptHandlers [SOC_TOUCH_SENSOR_NUM ] = {
38
38
0 ,
39
39
};
40
- #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
41
- static uint8_t _sample_num = 1 ; // only one sample configuration supported
40
+ #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
41
+ static uint8_t _sample_num = 1 ; // only one sample configuration supported
42
42
static float _duration_ms = 5.0f ;
43
43
static touch_volt_lim_l_t _volt_low = TOUCH_VOLT_LIM_L_0V5 ;
44
44
static touch_volt_lim_h_t _volt_high = TOUCH_VOLT_LIM_H_1V7 ;
45
45
static touch_intr_trig_mode_t _intr_trig_mode = TOUCH_INTR_TRIG_ON_BELOW_THRESH ;
46
- #elif SOC_TOUCH_SENSOR_VERSION == 2 // ESP32S2, ESP32S3
47
- static uint8_t _sample_num = 1 ; // only one sample configuration supported
46
+ #elif SOC_TOUCH_SENSOR_VERSION == 2 // ESP32S2, ESP32S3
47
+ static uint8_t _sample_num = 1 ; // only one sample configuration supported
48
48
static uint32_t _chg_times = 500 ;
49
49
static touch_volt_lim_l_t _volt_low = TOUCH_VOLT_LIM_L_0V5 ;
50
50
static touch_volt_lim_h_t _volt_high = TOUCH_VOLT_LIM_H_2V2 ;
51
- #elif SOC_TOUCH_SENSOR_VERSION == 3 // ESP32P4
52
- static uint8_t _sample_num = 1 ; // TODO: can be extended to multiple samples
51
+ #elif SOC_TOUCH_SENSOR_VERSION == 3 // ESP32P4
52
+ static uint8_t _sample_num = 1 ; // TODO: can be extended to multiple samples
53
53
static uint32_t _div_num = 1 ;
54
54
static uint8_t _coarse_freq_tune = 1 ;
55
55
static uint8_t _fine_freq_tune = 1 ;
@@ -169,27 +169,27 @@ bool touchBenchmarkThreshold(uint8_t pad) {
169
169
170
170
// Reconfigure passed pad with new threshold
171
171
uint32_t benchmark [_sample_num ] = {};
172
- #if SOC_TOUCH_SUPPORT_BENCHMARK // ESP32S2, ESP32S3,ESP32P4
172
+ #if SOC_TOUCH_SUPPORT_BENCHMARK // ESP32S2, ESP32S3,ESP32P4
173
173
if (touch_channel_read_data (touch_channel_handle [pad ], TOUCH_CHAN_DATA_TYPE_BENCHMARK , benchmark ) != ESP_OK ) {
174
174
log_e ("Touch channel read data failed!" );
175
175
return false;
176
176
}
177
- #else
177
+ #else
178
178
if (touch_channel_read_data (touch_channel_handle [pad ], TOUCH_CHAN_DATA_TYPE_SMOOTH , benchmark ) != ESP_OK ) {
179
179
log_e ("Touch channel read data failed!" );
180
180
return false;
181
181
}
182
- #endif
182
+ #endif
183
183
184
184
/* Calculate the proper active thresholds regarding the initial benchmark */
185
185
touch_channel_config_t chan_cfg = TOUCH_CHANNEL_DEFAULT_CONFIG ();
186
186
for (int i = 0 ; i < _sample_num ; i ++ ) {
187
- #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
187
+ #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
188
188
chan_cfg .abs_active_thresh [i ] = (uint32_t )(benchmark [i ] * (1 - s_thresh2bm_ratio ));
189
- log_v ("Configured [CH %d] sample %d: benchmark = %" PRIu32 ", threshold = %" PRIu32 "\t" , pad , i , benchmark [i ], chan_cfg .abs_active_thresh [i ]);
189
+ log_v ("Configured [CH %d] sample %d: benchmark = %" PRIu32 ", threshold = %" PRIu32 "\t" , pad , i , benchmark [i ], chan_cfg .abs_active_thresh [i ]);
190
190
#else
191
191
chan_cfg .active_thresh [i ] = (uint32_t )(benchmark [i ] * s_thresh2bm_ratio );
192
- log_v ("Configured [CH %d] sample %d: benchmark = %" PRIu32 ", threshold = %" PRIu32 "\t" , pad , i , benchmark [i ], chan_cfg .active_thresh [i ]);
192
+ log_v ("Configured [CH %d] sample %d: benchmark = %" PRIu32 ", threshold = %" PRIu32 "\t" , pad , i , benchmark [i ], chan_cfg .active_thresh [i ]);
193
193
#endif
194
194
}
195
195
/* Update the channel configuration */
@@ -221,8 +221,7 @@ static bool touchDetachBus(void *pin) {
221
221
return false;
222
222
}
223
223
initialized = false;
224
- }
225
- else {
224
+ } else {
226
225
touchEnable ();
227
226
touchStart ();
228
227
}
@@ -234,31 +233,31 @@ static void __touchInit() {
234
233
return ;
235
234
}
236
235
// Support only one sample configuration for now
237
- #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
236
+ #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
238
237
touch_sensor_sample_config_t single_sample_cfg = TOUCH_SENSOR_V1_DEFAULT_SAMPLE_CONFIG (_duration_ms , _volt_low , _volt_high );
239
- #elif SOC_TOUCH_SENSOR_VERSION == 2 // ESP32S2, ESP32S3
238
+ #elif SOC_TOUCH_SENSOR_VERSION == 2 // ESP32S2, ESP32S3
240
239
touch_sensor_sample_config_t single_sample_cfg = TOUCH_SENSOR_V2_DEFAULT_SAMPLE_CONFIG (_chg_times , _volt_low , _volt_high );
241
- #elif SOC_TOUCH_SENSOR_VERSION == 3 // ESP32P4
240
+ #elif SOC_TOUCH_SENSOR_VERSION == 3 // ESP32P4
242
241
touch_sensor_sample_config_t single_sample_cfg = TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG (_div_num , _coarse_freq_tune , _fine_freq_tune );
243
242
#endif
244
243
touch_sensor_sample_config_t sample_cfg [_sample_num ] = {};
245
244
sample_cfg [0 ] = single_sample_cfg ;
246
245
247
246
touch_sensor_config_t sens_cfg = {
248
- #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
247
+ #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
249
248
.power_on_wait_us = __touchSleepTime ,
250
249
.meas_interval_us = __touchMeasureTime ,
251
250
.intr_trig_mode = _intr_trig_mode ,
252
251
.intr_trig_group = TOUCH_INTR_TRIG_GROUP_BOTH ,
253
252
.sample_cfg_num = _sample_num ,
254
253
.sample_cfg = sample_cfg ,
255
- #elif SOC_TOUCH_SENSOR_VERSION == 2 // ESP32S2, ESP32S3
254
+ #elif SOC_TOUCH_SENSOR_VERSION == 2 // ESP32S2, ESP32S3
256
255
.power_on_wait_us = __touchSleepTime ,
257
256
.meas_interval_us = __touchMeasureTime ,
258
257
.max_meas_time_us = 0 ,
259
258
.sample_cfg_num = _sample_num ,
260
259
.sample_cfg = sample_cfg ,
261
- #elif SOC_TOUCH_SENSOR_VERSION == 3 // ESP32P4
260
+ #elif SOC_TOUCH_SENSOR_VERSION == 3 // ESP32P4
262
261
.power_on_wait_us = __touchSleepTime ,
263
262
.meas_interval_us = __touchMeasureTime ,
264
263
.max_meas_time_us = 0 ,
@@ -305,7 +304,7 @@ static void __touchChannelInit(int pad) {
305
304
__touchInterruptHandlers [pad ].fn = NULL ;
306
305
307
306
touch_channel_config_t chan_cfg = TOUCH_CHANNEL_DEFAULT_CONFIG ();
308
-
307
+
309
308
if (!touchStop () || !touchDisable ()) {
310
309
log_e ("Touch sensor stop and disable failed!" );
311
310
return ;
@@ -400,7 +399,7 @@ static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Ar
400
399
401
400
touch_channel_config_t chan_cfg = {};
402
401
for (int i = 0 ; i < _sample_num ; i ++ ) {
403
- #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
402
+ #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
404
403
chan_cfg .abs_active_thresh [i ] = threshold ;
405
404
#else
406
405
chan_cfg .active_thresh [i ] = threshold ;
@@ -470,9 +469,9 @@ void touchSleepWakeUpEnable(uint8_t pin, touch_value_t threshold) {
470
469
471
470
touch_sleep_config_t deep_slp_cfg = {
472
471
.slp_wakeup_lvl = TOUCH_DEEP_SLEEP_WAKEUP ,
473
- #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
474
- .deep_slp_sens_cfg = NULL , // Use the original touch sensor configuration
475
- #else // SOC_TOUCH_SENSOR_VERSION 2 and 3// ESP32S2, ESP32S3, ESP32P4
472
+ #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
473
+ .deep_slp_sens_cfg = NULL , // Use the original touch sensor configuration
474
+ #else // SOC_TOUCH_SENSOR_VERSION 2 and 3// ESP32S2, ESP32S3, ESP32P4
476
475
.deep_slp_chan = touch_channel_handle [pad ],
477
476
.deep_slp_thresh = {threshold },
478
477
.deep_slp_sens_cfg = NULL , // Use the original touch sensor configuration
@@ -503,7 +502,7 @@ void touchSetTiming(float measure, uint32_t sleep) {
503
502
__touchMeasureTime = measure ;
504
503
}
505
504
506
- #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
505
+ #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
507
506
void touchSetConfig (float duration_ms , touch_volt_lim_l_t volt_low , touch_volt_lim_h_t volt_high ) {
508
507
if (initialized ) {
509
508
log_e ("Touch sensor already initialized. Cannot set configuration." );
@@ -514,7 +513,7 @@ void touchSetConfig(float duration_ms, touch_volt_lim_l_t volt_low, touch_volt_l
514
513
_volt_high = volt_high ;
515
514
}
516
515
517
- #elif SOC_TOUCH_SENSOR_VERSION == 2 // ESP32S2, ESP32S3
516
+ #elif SOC_TOUCH_SENSOR_VERSION == 2 // ESP32S2, ESP32S3
518
517
void touchSetConfig (uint32_t chg_times , touch_volt_lim_l_t volt_low , touch_volt_lim_h_t volt_high ) {
519
518
if (initialized ) {
520
519
log_e ("Touch sensor already initialized. Cannot set configuration." );
@@ -525,7 +524,7 @@ void touchSetConfig(uint32_t chg_times, touch_volt_lim_l_t volt_low, touch_volt_
525
524
_volt_high = volt_high ;
526
525
}
527
526
528
- #elif SOC_TOUCH_SENSOR_VERSION == 3 // ESP32P4
527
+ #elif SOC_TOUCH_SENSOR_VERSION == 3 // ESP32P4
529
528
void touchSetConfig (uint32_t div_num , uint8_t coarse_freq_tune , uint8_t fine_freq_tune ) {
530
529
if (initialized ) {
531
530
log_e ("Touch sensor already initialized. Cannot set configuration." );
@@ -537,7 +536,7 @@ void touchSetConfig(uint32_t div_num, uint8_t coarse_freq_tune, uint8_t fine_fre
537
536
}
538
537
#endif
539
538
540
- #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
539
+ #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
541
540
void touchInterruptSetThresholdDirection (bool mustbeLower ) {
542
541
if (mustbeLower ) {
543
542
_intr_trig_mode = TOUCH_INTR_TRIG_ON_BELOW_THRESH ;
0 commit comments