From 75699fe203202a2832fbc81d73862828a8cbbc2b Mon Sep 17 00:00:00 2001 From: Ajith Vasudevan Date: Mon, 22 Feb 2021 15:12:48 +0530 Subject: [PATCH] Removed the need for SPI for TM1637 to work --- tasmota/support_tasmota.ino | 4 +--- tasmota/tasmota.ino | 5 ++++- tasmota/xdrv_13_display.ino | 2 +- tasmota/xdsp_interface.ino | 15 ++++++++++++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 4742537a2..af9aca1e2 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1678,9 +1678,7 @@ void GpioInit(void) ValidSpiPinUsed(GPIO_ST7789_DC) || // ST7789 CS may be omitted so chk DC too ValidSpiPinUsed(GPIO_ST7789_CS) || (ValidSpiPinUsed(GPIO_SSD1331_CS) && ValidSpiPinUsed(GPIO_SSD1331_DC)) || - ValidSpiPinUsed(GPIO_SDCARD_CS) || - (ValidSpiPinUsed(GPIO_TM1637CLK) && ValidSpiPinUsed(GPIO_TM1637DIO)) || - (ValidSpiPinUsed(GPIO_TM1638CLK) && ValidSpiPinUsed(GPIO_TM1638DIO) && ValidSpiPinUsed(GPIO_TM1638STB)) + ValidSpiPinUsed(GPIO_SDCARD_CS) ); // If SPI_CS and/or SPI_DC is used they must be valid TasmotaGlobal.spi_enabled = (valid_cs) ? SPI_MOSI_MISO : SPI_NONE; diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index c0b7b4669..7d52e5a44 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -147,6 +147,7 @@ struct { bool module_changed; // Indicate module changed since last restart bool wifi_stay_asleep; // Allow sleep only incase of ESP32 BLE bool no_autoexec; // Disable autoexec + bool tm1637_enabled; // TM1637 driver enabled StateBitfield global_state; // Global states (currently Wifi and Mqtt) (8 bits) uint8_t spi_enabled; // SPI configured @@ -227,7 +228,9 @@ void setup(void) { TasmotaGlobal.tele_period = 9999; TasmotaGlobal.active_device = 1; TasmotaGlobal.global_state.data = 0xF; // Init global state (wifi_down, mqtt_down) to solve possible network issues - +#if defined(USE_DISPLAY) && defined(USE_DISPLAY_TM1637) + TasmotaGlobal.tm1637_enabled = true; +#endif RtcRebootLoad(); if (!RtcRebootValid()) { RtcReboot.fast_reboot_count = 0; diff --git a/tasmota/xdrv_13_display.ino b/tasmota/xdrv_13_display.ino index 54aaca31c..fafeb0452 100755 --- a/tasmota/xdrv_13_display.ino +++ b/tasmota/xdrv_13_display.ino @@ -2779,7 +2779,7 @@ bool Xdrv13(uint8_t function) { bool result = false; - if ((TasmotaGlobal.i2c_enabled || TasmotaGlobal.spi_enabled || TasmotaGlobal.soft_spi_enabled) && XdspPresent()) { + if ((TasmotaGlobal.i2c_enabled || TasmotaGlobal.spi_enabled || TasmotaGlobal.soft_spi_enabled || TasmotaGlobal.tm1637_enabled) && XdspPresent()) { switch (function) { case FUNC_PRE_INIT: DisplayInitDriver(); diff --git a/tasmota/xdsp_interface.ino b/tasmota/xdsp_interface.ino index 3ca49f3d6..42907ae15 100644 --- a/tasmota/xdsp_interface.ino +++ b/tasmota/xdsp_interface.ino @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#if defined(USE_I2C) || defined(USE_SPI) +#if defined(USE_I2C) || defined(USE_SPI) || defined(USE_DISPLAY_TM1637) #ifdef USE_DISPLAY #ifdef XFUNC_PTR_IN_ROM @@ -26,6 +26,8 @@ bool (* const xdsp_func_ptr[])(uint8_t) PROGMEM = { // Display Function Pointe bool (* const xdsp_func_ptr[])(uint8_t) = { // Display Function Pointers #endif +#if defined(USE_I2C) || defined(USE_SPI) + #ifdef XDSP_01 &Xdsp01, #endif @@ -82,10 +84,18 @@ bool (* const xdsp_func_ptr[])(uint8_t) = { // Display Function Pointers &Xdsp14, #endif +#endif // #if defined(USE_I2C) || defined(USE_SPI) + +#ifdef USE_DISPLAY_TM1637 + #ifdef XDSP_15 &Xdsp15, #endif +#endif // USE_DISPLAY_TM1637 + +#if defined(USE_I2C) || defined(USE_SPI) + #ifdef XDSP_16 &Xdsp16, #endif @@ -153,6 +163,9 @@ bool (* const xdsp_func_ptr[])(uint8_t) = { // Display Function Pointers #ifdef XDSP_32 &Xdsp32 #endif + +#endif // #if defined(USE_I2C) || defined(USE_SPI) + }; const uint8_t xdsp_present = sizeof(xdsp_func_ptr) / sizeof(xdsp_func_ptr[0]); // Number of drivers found