Skip to content
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

Esp32 s3 touch fix #3798

Merged
merged 10 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions wled00/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,19 @@ bool isButtonPressed(uint8_t i)
case BTN_TYPE_TOUCH:
case BTN_TYPE_TOUCH_SWITCH:
#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
break;
}
return false;
break;
}
return false;
}

void handleSwitch(uint8_t b)
Expand Down Expand Up @@ -406,3 +414,8 @@ void handleIO()
offMode = true;
}
}

void IRAM_ATTR touchButtonISR()
{
// used for ESP32 S2 and S3: nothing to do, ISR is just used to update registers of HAL driver
}
13 changes: 11 additions & 2 deletions wled00/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {

// read multiple button configuration
JsonObject btn_obj = hw["btn"];
CJSON(touchThreshold, btn_obj[F("tt")]);
bool pull = btn_obj[F("pull")] | (!disablePullUp); // if true, pullup is enabled
disablePullUp = !pull;
JsonArray hw_btn_ins = btn_obj["ins"];
Expand All @@ -252,8 +253,16 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
btnPin[s] = -1;
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<<4); //threshold on Touch V2 is much higher (1500 is a value given by Espressif example)
blazoncek marked this conversation as resolved.
Show resolved Hide resolved
}
#endif

else
#endif
#endif
{
if (disablePullUp) {
pinMode(btnPin[s], INPUT);
Expand Down Expand Up @@ -299,7 +308,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
}
}
}
CJSON(touchThreshold,btn_obj[F("tt")]);

CJSON(buttonPublishMqtt,btn_obj["mqtt"]);

int hw_ir_pin = hw["ir"]["pin"] | -2; // 4
Expand Down
1 change: 1 addition & 0 deletions wled00/fcn_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void doublePressAction(uint8_t b=0);
bool isButtonPressed(uint8_t b=0);
void handleButton();
void handleIO();
void IRAM_ATTR touchButtonISR();

//cfg.cpp
bool deserializeConfig(JsonObject doc, bool fromFS = false);
Expand Down
Loading