-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Touch change to init only selected GPIO. #6609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,11 +119,6 @@ static void __touchInit() | |
if (err != ESP_OK) { | ||
goto err; | ||
} | ||
// Initial no Threshold and setup | ||
for (int i = 0; i < SOC_TOUCH_SENSOR_NUM; i++) { | ||
__touchInterruptHandlers[i].fn = NULL; | ||
touch_pad_config(i, SOC_TOUCH_PAD_THRESHOLD_MAX); // returns ESP_OK | ||
} | ||
// keep ISR activated - it can run all together (ISR + touchRead()) | ||
err = touch_pad_isr_register(__touchISR, NULL); | ||
if (err != ESP_OK) { | ||
|
@@ -148,18 +143,7 @@ static void __touchInit() | |
// Touch Sensor Timer initiated | ||
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); // returns ESP_OK | ||
touch_pad_fsm_start(); // returns ESP_OK | ||
|
||
// Initial no Threshold and setup - TOUCH0 is internal denoise channel | ||
for (int i = 1; i < SOC_TOUCH_SENSOR_NUM; i++) { | ||
__touchInterruptHandlers[i].fn = NULL; | ||
touch_pad_config(i); // returns ESP_OK | ||
} | ||
// keep ISR activated - it can run all together (ISR + touchRead()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any downside to init ISR here? Seems that you only needed to delete There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For touch v2, the ISR needs to be inited after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah ok. |
||
err = touch_pad_isr_register(__touchISR, NULL, TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); | ||
if (err != ESP_OK) { | ||
goto err; | ||
} | ||
touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); // returns ESP_OK | ||
//ISR setup moved to __touchChannelInit | ||
#endif | ||
|
||
initialized = true; | ||
|
@@ -170,13 +154,43 @@ static void __touchInit() | |
return; | ||
} | ||
|
||
static void __touchChannelInit(int pad) | ||
{ | ||
static bool channels_initialized[SOC_TOUCH_SENSOR_NUM] = { false }; | ||
if(channels_initialized[pad]){ | ||
return; | ||
} | ||
|
||
#if SOC_TOUCH_VERSION_1 // ESP32 | ||
// Initial no Threshold and setup | ||
__touchInterruptHandlers[pad].fn = NULL; | ||
touch_pad_config(pad, SOC_TOUCH_PAD_THRESHOLD_MAX); // returns ESP_OK | ||
#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 | ||
// Initial no Threshold and setup | ||
__touchInterruptHandlers[pad].fn = NULL; | ||
touch_pad_config(pad); // returns ESP_OK | ||
// keep ISR activated - it can run all together (ISR + touchRead()) | ||
esp_err_t err = touch_pad_isr_register(__touchISR, NULL, TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); | ||
if (err != ESP_OK) { | ||
log_e(" Touch sensor initialization error."); | ||
return; | ||
} | ||
touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); // returns ESP_OK | ||
#endif | ||
|
||
channels_initialized[pad] = true; | ||
delay(20); //delay needed before reading from touch channel after config | ||
} | ||
|
||
static touch_value_t __touchRead(uint8_t pin) | ||
{ | ||
int8_t pad = digitalPinToTouchChannel(pin); | ||
if(pad < 0){ | ||
return 0; | ||
} | ||
|
||
__touchInit(); | ||
__touchChannelInit(pad); | ||
|
||
touch_value_t touch_value; | ||
touch_pad_read_raw_data(pad, &touch_value); | ||
|
@@ -198,6 +212,9 @@ static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Ar | |
} else { | ||
// attach ISR User Call | ||
__touchInit(); | ||
#if SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 | ||
__touchChannelInit(pad); | ||
#endif | ||
__touchInterruptHandlers[pad].fn = userFunc; | ||
__touchInterruptHandlers[pad].callWithArgs = callWithArgs; | ||
__touchInterruptHandlers[pad].arg = Args; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe keep this portion to init the handlers?