mirror of
https://github.com/wled/WLED.git
synced 2025-07-23 18:56:41 +00:00
fixed touch buttons for ESP32 S2 and S3
touch is implemented differently on S2 and S3, these changes make touch buttons work on S2 and S3
This commit is contained in:
parent
d937d473f9
commit
c8f48168b4
@ -99,7 +99,17 @@ bool isButtonPressed(uint8_t i)
|
|||||||
case BTN_TYPE_TOUCH:
|
case BTN_TYPE_TOUCH:
|
||||||
case BTN_TYPE_TOUCH_SWITCH:
|
case BTN_TYPE_TOUCH_SWITCH:
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3)
|
#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||||
if (digitalPinToTouchChannel(btnPin[i]) >= 0 && touchRead(pin) <= touchThreshold) return true;
|
#ifdef SOC_TOUCH_VERSION_2 //ESP32 S2 and S3 provide a function to check touch state (state is updated in interrupt)
|
||||||
|
if (touchInterruptGetLastStatus(pin))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (digitalPinToTouchChannel(btnPin[i]) >= 0 && touchRead(pin) <= touchThreshold)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -406,3 +416,12 @@ void handleIO()
|
|||||||
offMode = true;
|
offMode = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IRAM_ATTR touchButtonISR()
|
||||||
|
{
|
||||||
|
|
||||||
|
#if defined SOC_TOUCH_VERSION_1 //ESP32 original
|
||||||
|
touchInterruptSetThresholdDirection(flase); //todo: need to flip direction, for that proably need to read current state or something.
|
||||||
|
#endif
|
||||||
|
// For S2 and S3: nothing to do, ISR is just used to update registers of HAL driver
|
||||||
|
}
|
@ -228,6 +228,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
|
|
||||||
// read multiple button configuration
|
// read multiple button configuration
|
||||||
JsonObject btn_obj = hw["btn"];
|
JsonObject btn_obj = hw["btn"];
|
||||||
|
CJSON(touchThreshold, btn_obj[F("tt")]);
|
||||||
bool pull = btn_obj[F("pull")] | (!disablePullUp); // if true, pullup is enabled
|
bool pull = btn_obj[F("pull")] | (!disablePullUp); // if true, pullup is enabled
|
||||||
disablePullUp = !pull;
|
disablePullUp = !pull;
|
||||||
JsonArray hw_btn_ins = btn_obj["ins"];
|
JsonArray hw_btn_ins = btn_obj["ins"];
|
||||||
@ -252,6 +253,14 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
btnPin[s] = -1;
|
btnPin[s] = -1;
|
||||||
pinManager.deallocatePin(pin,PinOwner::Button);
|
pinManager.deallocatePin(pin,PinOwner::Button);
|
||||||
}
|
}
|
||||||
|
//if touch pin, enable the touch interrupt on ESP32 S2 & S3
|
||||||
|
#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))
|
||||||
|
{
|
||||||
|
touchAttachInterrupt(btnPin[s], touchButtonISR, touchThreshold<<2); //threshold on Touch V2 is much higher (TODO: may need shift by 3 if very noisy)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@ -299,7 +308,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CJSON(touchThreshold,btn_obj[F("tt")]);
|
|
||||||
CJSON(buttonPublishMqtt,btn_obj["mqtt"]);
|
CJSON(buttonPublishMqtt,btn_obj["mqtt"]);
|
||||||
|
|
||||||
int hw_ir_pin = hw["ir"]["pin"] | -2; // 4
|
int hw_ir_pin = hw["ir"]["pin"] | -2; // 4
|
||||||
|
@ -20,6 +20,7 @@ void doublePressAction(uint8_t b=0);
|
|||||||
bool isButtonPressed(uint8_t b=0);
|
bool isButtonPressed(uint8_t b=0);
|
||||||
void handleButton();
|
void handleButton();
|
||||||
void handleIO();
|
void handleIO();
|
||||||
|
void IRAM_ATTR touchButtonISR();
|
||||||
|
|
||||||
//cfg.cpp
|
//cfg.cpp
|
||||||
bool deserializeConfig(JsonObject doc, bool fromFS = false);
|
bool deserializeConfig(JsonObject doc, bool fromFS = false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user