diff --git a/tasmota/support.ino b/tasmota/support.ino index a7c08eeda..a09a6fe59 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1327,17 +1327,13 @@ void SetPin(uint32_t lpin, uint32_t gpio) { } void DigitalWrite(uint32_t gpio_pin, uint32_t index, uint32_t state) { -#ifdef ESP8266 - static uint32_t pinmode_init = 0; // Pins 0 to 31 !!! - saves 40 bytes code space compared to uint64_t -#else - static uint64_t pinmode_init = 0; // Pins 0 to 63 !!! -#endif + static uint32_t pinmode_init[2] = { 0 }; // Pins 0 to 63 !!! if (PinUsed(gpio_pin, index)) { - uint32_t pin = Pin(gpio_pin, index); - if (!bitRead(pinmode_init, pin)) { + uint32_t pin = Pin(gpio_pin, index) & 0x3F; // Fix possible overflow over 63 gpios + if (!bitRead(pinmode_init[pin / 32], pin % 32)) { + bitSet(pinmode_init[pin / 32], pin % 32); pinMode(pin, OUTPUT); - bitSet(pinmode_init, pin); } digitalWrite(pin, state &1); }