From e6bff6bf9e0d6425775e08833689f49903d37238 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 14 Feb 2021 13:06:19 +0100 Subject: [PATCH] Standardize on unconnected pin being -1 --- tasmota/support.ino | 10 +++++----- tasmota/support_tasmota.ino | 6 +++--- tasmota/xdrv_23_zigbee_A_impl.ino | 6 +++--- tasmota/xdrv_36_keeloq.ino | 4 ++-- tasmota/xdrv_81_esp32_webcam.ino | 4 ++-- tasmota/xdrv_82_esp32_ethernet.ino | 2 +- tasmota/xdsp_02_ssd1306.ino | 9 ++------- tasmota/xdsp_04_ili9341.ino | 18 +++--------------- tasmota/xdsp_08_ILI9488.ino | 2 +- tasmota/xdsp_12_ST7789.ino | 14 ++------------ tasmota/xdsp_14_SSD1331.ino | 9 ++------- tasmota/xlgt_02_my92x1.ino | 4 ++-- tasmota/xlgt_03_sm16716.ino | 12 ++++++------ tasmota/xnrg_15_teleinfo.ino | 6 +++--- tasmota/xsns_05_ds18x20.ino | 4 ++-- tasmota/xsns_06_dht.ino | 2 +- tasmota/xsns_07_sht1x.ino | 4 ++-- tasmota/xsns_28_tm1638.ino | 6 +++--- tasmota/xsns_34_hx711.ino | 4 ++-- tasmota/xsns_36_mgc3130.ino | 4 ++-- 20 files changed, 49 insertions(+), 81 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 93b78acfb..d58e19f0f 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1320,8 +1320,8 @@ void DumpConvertTable(void) { */ #endif // ESP8266 -uint32_t ICACHE_RAM_ATTR Pin(uint32_t gpio, uint32_t index = 0); -uint32_t ICACHE_RAM_ATTR Pin(uint32_t gpio, uint32_t index) { +int ICACHE_RAM_ATTR Pin(uint32_t gpio, uint32_t index = 0); +int ICACHE_RAM_ATTR Pin(uint32_t gpio, uint32_t index) { uint16_t real_gpio = gpio << 5; uint16_t mask = 0xFFE0; if (index < GPIO_ANY) { @@ -1333,12 +1333,12 @@ uint32_t ICACHE_RAM_ATTR Pin(uint32_t gpio, uint32_t index) { return i; // Pin number configured for gpio } } - return 99; // No pin used for gpio + return -1; // No pin used for gpio } bool PinUsed(uint32_t gpio, uint32_t index = 0); bool PinUsed(uint32_t gpio, uint32_t index) { - return (Pin(gpio, index) < 99); + return (Pin(gpio, index) > -1); } uint32_t GetPin(uint32_t lpin) { @@ -1569,7 +1569,7 @@ bool ValidSpiPinUsed(uint32_t gpio) { // ESP8266: If SPI pin selected chk if it's not one of the three Hardware SPI pins (12..14) bool result = false; if (PinUsed(gpio)) { - uint32_t pin = Pin(gpio); + int pin = Pin(gpio); result = ((pin < 12) || (pin > 14)); } return result; diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 7318b9076..634405322 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -407,12 +407,12 @@ void SetLedPowerAll(uint32_t state) void SetLedLink(uint32_t state) { - uint32_t led_pin = Pin(GPIO_LEDLNK); + int led_pin = Pin(GPIO_LEDLNK); uint32_t led_inv = TasmotaGlobal.ledlnk_inverted; - if (99 == led_pin) { // Legacy - LED1 is status + if (-1 == led_pin) { // Legacy - LED1 is status SetLedPowerIdx(0, state); } - else if (led_pin < 99) { + else if (led_pin > -1) { if (state) { state = 1; } digitalWrite(led_pin, (led_inv) ? !state : state); } diff --git a/tasmota/xdrv_23_zigbee_A_impl.ino b/tasmota/xdrv_23_zigbee_A_impl.ino index 925a35cd1..560745b2d 100644 --- a/tasmota/xdrv_23_zigbee_A_impl.ino +++ b/tasmota/xdrv_23_zigbee_A_impl.ino @@ -1334,7 +1334,7 @@ void CmndZbScan(void) { buf.add32(0x07FFF800); // standard channels 11-26 buf.add8(0x04); // duration 2 ^ 4 ZigbeeEZSPSendCmd(buf.getBuffer(), buf.len()); - + #endif // USE_ZIGBEE_EZSP ResponseCmndDone(); } @@ -1516,8 +1516,8 @@ void ZigbeeGlowPermitJoinLight(void) { } // change the led state - uint32_t led_pin = Pin(GPIO_LEDLNK); - if (led_pin < 99) { + int led_pin = Pin(GPIO_LEDLNK); + if (led_pin > -1) { analogWrite(led_pin, TasmotaGlobal.ledlnk_inverted ? 1023 - led_power : led_power); } } diff --git a/tasmota/xdrv_36_keeloq.ino b/tasmota/xdrv_36_keeloq.ino index 0703190ca..d34d5971c 100644 --- a/tasmota/xdrv_36_keeloq.ino +++ b/tasmota/xdrv_36_keeloq.ino @@ -54,8 +54,8 @@ struct JAROLIFT_DEVICE { uint64_t pack = 0; // Contains data to send. int count = 0; uint32_t serial = 0x0; - uint8_t port_tx; - uint8_t port_rx; + int8_t port_tx; + int8_t port_rx; } jaroliftDevice; void CmdSet(void) diff --git a/tasmota/xdrv_81_esp32_webcam.ino b/tasmota/xdrv_81_esp32_webcam.ino index f7a5a5713..8f653efc9 100644 --- a/tasmota/xdrv_81_esp32_webcam.ino +++ b/tasmota/xdrv_81_esp32_webcam.ino @@ -204,8 +204,8 @@ uint32_t WcSetup(int32_t fsiz) { config.pin_href = Pin(GPIO_WEBCAM_HREF); // HREF_GPIO_NUM; config.pin_sscb_sda = Pin(GPIO_WEBCAM_SIOD); // SIOD_GPIO_NUM; config.pin_sscb_scl = Pin(GPIO_WEBCAM_SIOC); // SIOC_GPIO_NUM; - config.pin_pwdn = (PinUsed(GPIO_WEBCAM_PWDN)) ? Pin(GPIO_WEBCAM_PWDN) : -1; // PWDN_GPIO_NUM; - config.pin_reset = (PinUsed(GPIO_WEBCAM_RESET)) ? Pin(GPIO_WEBCAM_RESET) : -1; // RESET_GPIO_NUM; + config.pin_pwdn = Pin(GPIO_WEBCAM_PWDN); // PWDN_GPIO_NUM; + config.pin_reset = Pin(GPIO_WEBCAM_RESET); // RESET_GPIO_NUM; AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: User template")); } else { diff --git a/tasmota/xdrv_82_esp32_ethernet.ino b/tasmota/xdrv_82_esp32_ethernet.ino index 4872f194c..9e4b0261e 100644 --- a/tasmota/xdrv_82_esp32_ethernet.ino +++ b/tasmota/xdrv_82_esp32_ethernet.ino @@ -133,7 +133,7 @@ void EthernetInit(void) { WiFi.onEvent(EthernetEvent); - int eth_power = (PinUsed(GPIO_ETH_PHY_POWER)) ? Pin(GPIO_ETH_PHY_POWER) : -1; + int eth_power = Pin(GPIO_ETH_PHY_POWER); int eth_mdc = Pin(GPIO_ETH_PHY_MDC); int eth_mdio = Pin(GPIO_ETH_PHY_MDIO); if (!ETH.begin(Settings.eth_address, eth_power, eth_mdc, eth_mdio, (eth_phy_type_t)Settings.eth_type, (eth_clock_mode_t)Settings.eth_clk_mode)) { diff --git a/tasmota/xdsp_02_ssd1306.ino b/tasmota/xdsp_02_ssd1306.ino index a3e9bb8f5..1698f00f6 100644 --- a/tasmota/xdsp_02_ssd1306.ino +++ b/tasmota/xdsp_02_ssd1306.ino @@ -70,11 +70,6 @@ void SSD1306InitDriver(void) Settings.display_height = 64; } - uint8_t reset_pin = -1; - if (PinUsed(GPIO_OLED_RESET)) { - reset_pin = Pin(GPIO_OLED_RESET); - } - // allocate screen buffer if (buffer) { free(buffer); } buffer = (unsigned char*)calloc((Settings.display_width * Settings.display_height) / 8,1); @@ -82,8 +77,8 @@ void SSD1306InitDriver(void) // init renderer // oled1306 = new Adafruit_SSD1306(SSD1306_LCDWIDTH,SSD1306_LCDHEIGHT); - oled1306 = new Adafruit_SSD1306(Settings.display_width, Settings.display_height, &Wire, reset_pin); - oled1306->begin(SSD1306_SWITCHCAPVCC, Settings.display_address[0], reset_pin >= 0); + oled1306 = new Adafruit_SSD1306(Settings.display_width, Settings.display_height, &Wire, Pin(GPIO_OLED_RESET)); + oled1306->begin(SSD1306_SWITCHCAPVCC, Settings.display_address[0], Pin(GPIO_OLED_RESET) >= 0); renderer = oled1306; renderer->DisplayInit(DISPLAY_INIT_MODE, Settings.display_size, Settings.display_rotate, Settings.display_font); renderer->setTextColor(1,0); diff --git a/tasmota/xdsp_04_ili9341.ino b/tasmota/xdsp_04_ili9341.ino index 018c3c921..c5087c290 100644 --- a/tasmota/xdsp_04_ili9341.ino +++ b/tasmota/xdsp_04_ili9341.ino @@ -69,29 +69,17 @@ void ILI9341_InitDriver() ili9341_2 = new ILI9341_2(5, -2, 15, -2); #else - // There are displays without CS - int8_t spi_cs_pin = -1; - if (PinUsed(GPIO_ILI9341_CS)) { - spi_cs_pin = Pin(GPIO_ILI9341_CS); - } - int8_t backlight_pin = -1; - if (PinUsed(GPIO_BACKLIGHT)) { - backlight_pin = Pin(GPIO_BACKLIGHT); - } - int8_t oled_reset_pin = -1; - if (PinUsed(GPIO_OLED_RESET)) { - oled_reset_pin = Pin(GPIO_OLED_RESET); - } + // There are displays without CS // check for special case with 2 SPI busses (ESP32 bitcoin) if (TasmotaGlobal.soft_spi_enabled) { // Init renderer, may use hardware spi, however we use SSPI defintion because SD card uses SPI definition (2 spi busses) if (PinUsed(GPIO_SSPI_MOSI) && PinUsed(GPIO_SSPI_MISO) && PinUsed(GPIO_SSPI_SCLK)) { - ili9341_2 = new ILI9341_2(spi_cs_pin, Pin(GPIO_SSPI_MOSI), Pin(GPIO_SSPI_MISO), Pin(GPIO_SSPI_SCLK), oled_reset_pin, Pin(GPIO_ILI9341_DC), backlight_pin, 2); + ili9341_2 = new ILI9341_2(Pin(GPIO_ILI9341_CS), Pin(GPIO_SSPI_MOSI), Pin(GPIO_SSPI_MISO), Pin(GPIO_SSPI_SCLK), Pin(GPIO_OLED_RESET), Pin(GPIO_ILI9341_DC), Pin(GPIO_BACKLIGHT), 2); } } else if (TasmotaGlobal.spi_enabled) { if (PinUsed(GPIO_ILI9341_DC)) { - ili9341_2 = new ILI9341_2(spi_cs_pin, Pin(GPIO_SPI_MOSI), Pin(GPIO_SPI_MISO), Pin(GPIO_SPI_CLK), oled_reset_pin, Pin(GPIO_ILI9341_DC), backlight_pin, 1); + ili9341_2 = new ILI9341_2(Pin(GPIO_ILI9341_CS), Pin(GPIO_SPI_MOSI), Pin(GPIO_SPI_MISO), Pin(GPIO_SPI_CLK), Pin(GPIO_OLED_RESET), Pin(GPIO_ILI9341_DC), Pin(GPIO_BACKLIGHT), 1); } } #endif // USE_M5STACK_CORE2 diff --git a/tasmota/xdsp_08_ILI9488.ino b/tasmota/xdsp_08_ILI9488.ino index bb423097c..05235bae6 100644 --- a/tasmota/xdsp_08_ILI9488.ino +++ b/tasmota/xdsp_08_ILI9488.ino @@ -65,7 +65,7 @@ void ILI9488_InitDriver(void) { fg_color = ILI9488_WHITE; bg_color = ILI9488_BLACK; - uint8_t bppin = BACKPLANE_PIN; + int8_t bppin = BACKPLANE_PIN; if (PinUsed(GPIO_BACKLIGHT)) { bppin = Pin(GPIO_BACKLIGHT); } diff --git a/tasmota/xdsp_12_ST7789.ino b/tasmota/xdsp_12_ST7789.ino index 9b285418f..c4541641f 100644 --- a/tasmota/xdsp_12_ST7789.ino +++ b/tasmota/xdsp_12_ST7789.ino @@ -86,22 +86,12 @@ void ST7789_InitDriver(void) { bppin = Pin(GPIO_BACKLIGHT); } - int8_t reset = -1; - if (PinUsed(GPIO_OLED_RESET)) { - reset = Pin(GPIO_OLED_RESET); - } - - int8_t cs = -1; - if (PinUsed(GPIO_ST7789_CS)) { - cs = Pin(GPIO_ST7789_CS); - } - // init renderer, may use hardware spi if (TasmotaGlobal.soft_spi_enabled) { - st7789 = new Arduino_ST7789(Pin(GPIO_ST7789_DC), reset, Pin(GPIO_SSPI_MOSI), Pin(GPIO_SSPI_SCLK), cs, bppin); + st7789 = new Arduino_ST7789(Pin(GPIO_ST7789_DC), Pin(GPIO_OLED_RESET), Pin(GPIO_SSPI_MOSI), Pin(GPIO_SSPI_SCLK), Pin(GPIO_ST7789_CS), bppin); } else if (TasmotaGlobal.spi_enabled) { - st7789 = new Arduino_ST7789(Pin(GPIO_ST7789_DC), reset, cs, bppin); + st7789 = new Arduino_ST7789(Pin(GPIO_ST7789_DC), Pin(GPIO_OLED_RESET), Pin(GPIO_ST7789_CS), bppin); } st7789->init(Settings.display_width,Settings.display_height); diff --git a/tasmota/xdsp_14_SSD1331.ino b/tasmota/xdsp_14_SSD1331.ino index 4d297cab8..3cfa436c9 100644 --- a/tasmota/xdsp_14_SSD1331.ino +++ b/tasmota/xdsp_14_SSD1331.ino @@ -61,17 +61,12 @@ void SSD1331_InitDriver() { fg_color = SSD1331_WHITE; bg_color = SSD1331_BLACK; - int8_t reset = -1; - if (PinUsed(GPIO_OLED_RESET)) { - reset = Pin(GPIO_OLED_RESET); - } - // init renderer if (TasmotaGlobal.soft_spi_enabled) { - ssd1331 = new Adafruit_SSD1331(Pin(GPIO_SSD1331_CS), Pin(GPIO_SSD1331_DC), Pin(GPIO_SSPI_MOSI), Pin(GPIO_SSPI_SCLK), reset); + ssd1331 = new Adafruit_SSD1331(Pin(GPIO_SSD1331_CS), Pin(GPIO_SSD1331_DC), Pin(GPIO_SSPI_MOSI), Pin(GPIO_SSPI_SCLK), Pin(GPIO_OLED_RESET)); } else if (TasmotaGlobal.spi_enabled) { - ssd1331 = new Adafruit_SSD1331(&SPI, Pin(GPIO_SSD1331_CS), Pin(GPIO_SSD1331_DC), reset); + ssd1331 = new Adafruit_SSD1331(&SPI, Pin(GPIO_SSD1331_CS), Pin(GPIO_SSD1331_DC), Pin(GPIO_OLED_RESET)); } delay(100); diff --git a/tasmota/xlgt_02_my92x1.ino b/tasmota/xlgt_02_my92x1.ino index fe8ca1270..2c851a9b1 100644 --- a/tasmota/xlgt_02_my92x1.ino +++ b/tasmota/xlgt_02_my92x1.ino @@ -26,8 +26,8 @@ #define XLGT_02 2 struct MY92X1 { - uint8_t pdi_pin = 0; - uint8_t pdcki_pin = 0; + int8_t pdi_pin = 0; + int8_t pdcki_pin = 0; uint8_t model = 0; } My92x1; diff --git a/tasmota/xlgt_03_sm16716.ino b/tasmota/xlgt_03_sm16716.ino index 66c714075..540b6d392 100644 --- a/tasmota/xlgt_03_sm16716.ino +++ b/tasmota/xlgt_03_sm16716.ino @@ -31,9 +31,9 @@ #define D_LOG_SM16716 "SM16716: " struct SM16716 { - uint8_t pin_clk = 0; - uint8_t pin_dat = 0; - uint8_t pin_sel = 0; + int8_t pin_clk = 0; + int8_t pin_dat = 0; + int8_t pin_sel = 0; bool enabled = false; } Sm16716; @@ -62,7 +62,7 @@ void SM16716_SendByte(uint8_t v) void SM16716_Update(uint8_t duty_r, uint8_t duty_g, uint8_t duty_b) { - if (Sm16716.pin_sel < 99) { + if (Sm16716.pin_sel > -1) { bool should_enable = (duty_r | duty_g | duty_b); if (!Sm16716.enabled && should_enable) { DEBUG_DRIVER_LOG(PSTR(D_LOG_SM16716 "turning color on")); @@ -104,7 +104,7 @@ bool SM16716_ModuleSelected(void) Sm16716.pin_dat = Pin(GPIO_SM16716_DAT); Sm16716.pin_sel = Pin(GPIO_SM16716_SEL); DEBUG_DRIVER_LOG(PSTR(D_LOG_SM16716 "ModuleSelected; clk_pin=%d, dat_pin=%d)"), Sm16716.pin_clk, Sm16716.pin_dat); - return (Sm16716.pin_clk < 99) && (Sm16716.pin_dat < 99); + return (Sm16716.pin_clk > -1) && (Sm16716.pin_dat > -1); } */ @@ -165,7 +165,7 @@ void Sm16716ModuleSelected(void) pinMode(Sm16716.pin_dat, OUTPUT); digitalWrite(Sm16716.pin_dat, LOW); - if (Sm16716.pin_sel < 99) { + if (Sm16716.pin_sel > -1) { pinMode(Sm16716.pin_sel, OUTPUT); digitalWrite(Sm16716.pin_sel, LOW); // no need to call SM16716_Init here, it will be called after sel goes HIGH diff --git a/tasmota/xnrg_15_teleinfo.ino b/tasmota/xnrg_15_teleinfo.ino index ed1aebb45..29e502cec 100755 --- a/tasmota/xnrg_15_teleinfo.ino +++ b/tasmota/xnrg_15_teleinfo.ino @@ -456,12 +456,12 @@ void TInfoInit(void) } if (PinUsed(GPIO_TELEINFO_RX)) { - uint8_t rx_pin = Pin(GPIO_TELEINFO_RX); + int8_t rx_pin = Pin(GPIO_TELEINFO_RX); AddLog(LOG_LEVEL_INFO, PSTR("TIC: RX on GPIO%d, baudrate %d"), rx_pin, baudrate); // Enable Teleinfo pin used, control it if (PinUsed(GPIO_TELEINFO_ENABLE)) { - uint8_t en_pin = Pin(GPIO_TELEINFO_ENABLE); + int8_t en_pin = Pin(GPIO_TELEINFO_ENABLE); pinMode(en_pin, OUTPUT); digitalWrite(en_pin, HIGH); AddLog(LOG_LEVEL_INFO, PSTR("TIC: Enable with GPIO%d"), en_pin); @@ -484,7 +484,7 @@ void TInfoInit(void) // this is not working, need to call SetSerialConfig after if (TInfoSerial->begin(baudrate)) { - + #ifdef ESP8266 if (TInfoSerial->hardwareSerial() ) { ClaimSerial(); diff --git a/tasmota/xsns_05_ds18x20.ino b/tasmota/xsns_05_ds18x20.ino index f5cd6a3f9..b95523cd9 100644 --- a/tasmota/xsns_05_ds18x20.ino +++ b/tasmota/xsns_05_ds18x20.ino @@ -54,8 +54,8 @@ struct DS18X20STRUCT { float temperature; } ds18x20_sensor[DS18X20_MAX_SENSORS]; uint8_t ds18x20_sensors = 0; -uint8_t ds18x20_pin = 0; // Shelly GPIO3 input only -uint8_t ds18x20_pin_out = 0; // Shelly GPIO00 output only +int8_t ds18x20_pin = 0; // Shelly GPIO3 input only +int8_t ds18x20_pin_out = 0; // Shelly GPIO00 output only bool ds18x20_dual_mode = false; // Single pin mode char ds18x20_types[17]; #ifdef W1_PARASITE_POWER diff --git a/tasmota/xsns_06_dht.ino b/tasmota/xsns_06_dht.ino index 3abfd001a..9a7e9e048 100644 --- a/tasmota/xsns_06_dht.ino +++ b/tasmota/xsns_06_dht.ino @@ -39,7 +39,7 @@ bool dht_active = true; // DHT configured bool dht_dual_mode = false; // Single pin mode struct DHTSTRUCT { - uint8_t pin; + int8_t pin; uint8_t type; uint8_t lastresult; char stype[12]; diff --git a/tasmota/xsns_07_sht1x.ino b/tasmota/xsns_07_sht1x.ino index 7d3bc06e7..6fe5c51db 100644 --- a/tasmota/xsns_07_sht1x.ino +++ b/tasmota/xsns_07_sht1x.ino @@ -37,8 +37,8 @@ enum { SHT1X_CMD_SOFT_RESET = B00011110 }; -uint8_t sht_sda_pin; -uint8_t sht_scl_pin; +int8_t sht_sda_pin; +int8_t sht_scl_pin; uint8_t sht_type = 0; char sht_types[] = "SHT1X"; uint8_t sht_valid = 0; diff --git a/tasmota/xsns_28_tm1638.ino b/tasmota/xsns_28_tm1638.ino index 2579a1703..44da51dde 100644 --- a/tasmota/xsns_28_tm1638.ino +++ b/tasmota/xsns_28_tm1638.ino @@ -33,9 +33,9 @@ #define TM1638_CLOCK_DELAY 1 // uSec uint8_t tm1638_type = 1; -uint8_t tm1638_clock_pin = 0; -uint8_t tm1638_data_pin = 0; -uint8_t tm1638_strobe_pin = 0; +int8_t tm1638_clock_pin = 0; +int8_t tm1638_data_pin = 0; +int8_t tm1638_strobe_pin = 0; uint8_t tm1638_displays = 8; uint8_t tm1638_active_display = 1; uint8_t tm1638_intensity = 0; diff --git a/tasmota/xsns_34_hx711.ino b/tasmota/xsns_34_hx711.ino index db89f432e..9a22ad0e8 100644 --- a/tasmota/xsns_34_hx711.ino +++ b/tasmota/xsns_34_hx711.ino @@ -78,8 +78,8 @@ struct HX { uint8_t calibrate_step = HX_CAL_END; uint8_t calibrate_timer = 0; uint8_t calibrate_msg = 0; - uint8_t pin_sck; - uint8_t pin_dout; + int8_t pin_sck; + int8_t pin_dout; bool tare_flg = false; bool weight_changed = false; uint16_t weight_delta = 4; diff --git a/tasmota/xsns_36_mgc3130.ino b/tasmota/xsns_36_mgc3130.ino index 584b214d2..1c50b412f 100644 --- a/tasmota/xsns_36_mgc3130.ino +++ b/tasmota/xsns_36_mgc3130.ino @@ -39,8 +39,8 @@ #define MGC3130_I2C_ADDR 0x42 -uint8_t MGC3130_xfer = 0; -uint8_t MGC3130_reset = 0; +int8_t MGC3130_xfer = 0; +int8_t MGC3130_reset = 0; bool MGC3130_type = false; char MGC3130stype[] = "MGC3130";