Skip to content

Commit

Permalink
Final fix ESP32C3 relay toggle
Browse files Browse the repository at this point in the history
Final fix ESP32C3 relay toggle on restart (#20030)
  • Loading branch information
arendst committed Nov 17, 2023
1 parent b02a66a commit 4489dba
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions tasmota/tasmota_support/support_esp32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,11 @@ extern "C" void ARDUINO_ISR_ATTR pinMode(uint8_t pin, uint8_t mode) {
__pinMode(pin, mode);
#ifdef CONFIG_IDF_TARGET_ESP32C3
// See GpioForceHoldRelay() below
gpio_hold_dis((gpio_num_t)pin); // Allow state change
static uint64_t pin_hold_mask = 0;
if (!bitRead(pin_hold_mask, pin)) {
bitSet(pin_hold_mask, pin);
gpio_hold_dis((gpio_num_t)pin); // Allow state change
}
#endif
}

Expand All @@ -1004,10 +1008,12 @@ void GpioForceHoldRelay(void) {

// gpio_force_hold_all(); // This will hold flash/serial too so do not use

uint16_t real_gpio = GPIO_REL1 << 5;
uint16_t mask = 0xFFE0;
for (uint32_t i = 0; i < nitems(TasmotaGlobal.gpio_pin); i++) {
if ((TasmotaGlobal.gpio_pin[i] & mask) == real_gpio) {
// Use current gpio config
// for (uint32_t i = 0; i < nitems(TasmotaGlobal.gpio_pin); i++) {
// if ((TasmotaGlobal.gpio_pin[i] & 0xFFE0) == GPIO_REL1 << 5) {
// Use future gpio config
for (uint32_t i = 0; i < nitems(Settings->my_gp.io); i++) {
if ((Settings->my_gp.io[i] & 0xFFE0) == GPIO_REL1 << 5) {
gpio_hold_en((gpio_num_t)i); // Retain the state when the chip or system is reset, for example, when watchdog time-out or Deep-sleep
}
}
Expand Down

0 comments on commit 4489dba

Please sign in to comment.