From 51af8611bbc461de5af5f4ff879b128602b7d4c6 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 20 May 2022 12:10:46 +0200 Subject: [PATCH] Fix max 32-bit bitRead/bitSet size issue --- tasmota/support.ino | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) 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); }