From c4c03b7c1bcc14f940aeb5f33963d30f29d79ea7 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 20 May 2022 11:38:11 +0200 Subject: [PATCH] Add pinmode once for digitalwrite --- tasmota/support.ino | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 6f0e39c35..a7c08eeda 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1327,9 +1327,18 @@ 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 + if (PinUsed(gpio_pin, index)) { uint32_t pin = Pin(gpio_pin, index); - pinMode(pin, OUTPUT); + if (!bitRead(pinmode_init, pin)) { + pinMode(pin, OUTPUT); + bitSet(pinmode_init, pin); + } digitalWrite(pin, state &1); } }