some tuning for touch buttons on S2/S3

now better fits the default threshold value of 32
This commit is contained in:
Damian Schneider 2024-02-21 18:38:34 +01:00
parent c8f48168b4
commit 15526bd6e8
2 changed files with 9 additions and 10 deletions

View File

@ -101,9 +101,7 @@ bool isButtonPressed(uint8_t i)
#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) #if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3)
#ifdef SOC_TOUCH_VERSION_2 //ESP32 S2 and S3 provide a function to check touch state (state is updated in interrupt) #ifdef SOC_TOUCH_VERSION_2 //ESP32 S2 and S3 provide a function to check touch state (state is updated in interrupt)
if (touchInterruptGetLastStatus(pin)) if (touchInterruptGetLastStatus(pin))
{
return true; return true;
}
#else #else
if (digitalPinToTouchChannel(btnPin[i]) >= 0 && touchRead(pin) <= touchThreshold) if (digitalPinToTouchChannel(btnPin[i]) >= 0 && touchRead(pin) <= touchThreshold)
{ {
@ -419,9 +417,10 @@ void handleIO()
void IRAM_ATTR touchButtonISR() void IRAM_ATTR touchButtonISR()
{ {
// used for ESP32 S2 and S3: nothing to do, ISR is just used to update registers of HAL driver
// asm volatile("nop" ::); //prevent compiler to remove this function (TODO: is this really needed? probably not)
#if defined SOC_TOUCH_VERSION_1 //ESP32 original // #if defined SOC_TOUCH_VERSION_1 //ESP32 original -> unused
touchInterruptSetThresholdDirection(flase); //todo: need to flip direction, for that proably need to read current state or something. // touchInterruptSetThresholdDirection(false); //todo: need to flip direction, for that proably need to read current state or something.
#endif // #endif
// For S2 and S3: nothing to do, ISR is just used to update registers of HAL driver
} }

View File

@ -257,7 +257,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
#ifdef SOC_TOUCH_VERSION_2 // ESP32 S2 and S3 have a fucntion to check touch state but need to attach an interrupt to do so #ifdef SOC_TOUCH_VERSION_2 // ESP32 S2 and S3 have a fucntion to check touch state but need to attach an interrupt to do so
else if ((buttonType[s] == BTN_TYPE_TOUCH || buttonType[s] == BTN_TYPE_TOUCH_SWITCH)) else if ((buttonType[s] == BTN_TYPE_TOUCH || buttonType[s] == BTN_TYPE_TOUCH_SWITCH))
{ {
touchAttachInterrupt(btnPin[s], touchButtonISR, touchThreshold<<2); //threshold on Touch V2 is much higher (TODO: may need shift by 3 if very noisy) touchAttachInterrupt(btnPin[s], touchButtonISR, touchThreshold<<4); //threshold on Touch V2 is much higher (1500 is a value given by Espressif example)
} }
#endif #endif