From 37f42b474f7116dcac40aeba218161303f486edb Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:13:43 +0100 Subject: [PATCH] Fix DALI init sequence (#22371) --- tasmota/tasmota_xdrv_driver/xdrv_75_dali.ino | 44 +++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_75_dali.ino b/tasmota/tasmota_xdrv_driver/xdrv_75_dali.ino index e553dd594..4fe44e7a1 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_75_dali.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_75_dali.ino @@ -860,29 +860,33 @@ bool DaliSetChannels(void) { /*-------------------------------------------------------------------------------------------*/ bool DaliInit(void) { + int pin_tx = -1; + bool invert_tx = false; + if (PinUsed(GPIO_DALI_TX)) { + pin_tx = Pin(GPIO_DALI_TX); + } + else if (PinUsed(GPIO_DALI_TX_INV)) { + pin_tx = Pin(GPIO_DALI_TX_INV); + invert_tx = true; + } + int pin_rx = -1; + bool invert_rx = false; + if (PinUsed(GPIO_DALI_RX)) { + pin_rx = Pin(GPIO_DALI_RX); + } + else if (PinUsed(GPIO_DALI_RX_INV)) { + pin_rx = Pin(GPIO_DALI_RX_INV); + invert_rx = true; + } + if ((-1 == pin_tx) || (-1 == pin_rx)) { return false; } + Dali = (DALI*)calloc(sizeof(DALI), 1); if (!Dali) { return false; } - Dali->pin_tx = 255; - if (PinUsed(GPIO_DALI_TX)) { - Dali->pin_tx = Pin(GPIO_DALI_TX); - } - else if (PinUsed(GPIO_DALI_TX_INV)) { - Dali->pin_tx = Pin(GPIO_DALI_TX_INV); - Dali->invert_tx = true; - } - Dali->pin_rx = 255; - if (PinUsed(GPIO_DALI_RX)) { - Dali->pin_rx = Pin(GPIO_DALI_RX); - } - else if (PinUsed(GPIO_DALI_RX_INV)) { - Dali->pin_rx = Pin(GPIO_DALI_RX_INV); - Dali->invert_rx = true; - } - if ((255 == Dali->pin_tx) || (255 == Dali->pin_rx)) { - free(Dali); - return false; - } + Dali->pin_tx = pin_tx; + Dali->invert_tx = invert_tx; + Dali->pin_rx = pin_rx; + Dali->invert_rx = invert_rx; AddLog(LOG_LEVEL_INFO, PSTR("DLI: GPIO%d(RX%s) and GPIO%d(TX%s)"), Dali->pin_rx, (Dali->invert_rx)?"i":"", Dali->pin_tx, (Dali->invert_tx)?"i":"");