diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 122ae3eef..fb8416f68 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -325,7 +325,8 @@ struct TasmotaGlobal_t { uint8_t busy_time; // Time in ms to allow executing of time critical functions uint8_t init_state; // Tasmota init state uint8_t heartbeat_inverted; // Heartbeat pulse inverted flag - uint8_t spi_enabled; // SPI configured + uint8_t spi_enabled; // SPI configured (bus1) + uint8_t spi_enabled2; // SPI configured (bus2) uint8_t soft_spi_enabled; // Software SPI configured uint8_t blinks; // Number of LED blinks uint8_t restart_flag; // Tasmota restart flag diff --git a/tasmota/tasmota_support/support.ino b/tasmota/tasmota_support/support.ino index bd2b5f788..0552a30d1 100755 --- a/tasmota/tasmota_support/support.ino +++ b/tasmota/tasmota_support/support.ino @@ -2651,21 +2651,34 @@ void AddLogMissed(const char *sensor, uint32_t misses) AddLog(LOG_LEVEL_DEBUG, PSTR("SNS: %s missed %d"), sensor, SENSOR_MAX_MISS - misses); } -void AddLogSpi(bool hardware, uint32_t clk, uint32_t mosi, uint32_t miso) { - // Needs optimization - uint32_t enabled = (hardware) ? TasmotaGlobal.spi_enabled : TasmotaGlobal.soft_spi_enabled; +void AddLogSpi(uint32_t hardware, int clk, int mosi, int miso) { + uint32_t enabled = TasmotaGlobal.soft_spi_enabled; + char hwswbus[8]; + if (hardware) { +#ifdef ESP8266 + strcpy_P(hwswbus, PSTR("Hard")); + enabled = TasmotaGlobal.spi_enabled; +#endif +#ifdef ESP32 + strcpy_P(hwswbus, PSTR("Bus0")); + hwswbus[3] += (char)hardware; + enabled = (1 == hardware) ? TasmotaGlobal.spi_enabled : TasmotaGlobal.spi_enabled2; +#endif + } else { + strcpy_P(hwswbus, PSTR("Soft")); + } switch(enabled) { case SPI_MOSI: AddLog(LOG_LEVEL_INFO, PSTR("SPI: %s using GPIO%02d(CLK) and GPIO%02d(MOSI)"), - (hardware) ? PSTR("Hardware") : PSTR("Software"), clk, mosi); + hwswbus, clk, mosi); break; case SPI_MISO: AddLog(LOG_LEVEL_INFO, PSTR("SPI: %s using GPIO%02d(CLK) and GPIO%02d(MISO)"), - (hardware) ? PSTR("Hardware") : PSTR("Software"), clk, miso); + hwswbus, clk, miso); break; case SPI_MOSI_MISO: AddLog(LOG_LEVEL_INFO, PSTR("SPI: %s using GPIO%02d(CLK), GPIO%02d(MOSI) and GPIO%02d(MISO)"), - (hardware) ? PSTR("Hardware") : PSTR("Software"), clk, mosi, miso); + hwswbus, clk, mosi, miso); break; } } diff --git a/tasmota/tasmota_support/support_tasmota.ino b/tasmota/tasmota_support/support_tasmota.ino index c8e3de1b9..8f1df5b95 100644 --- a/tasmota/tasmota_support/support_tasmota.ino +++ b/tasmota/tasmota_support/support_tasmota.ino @@ -2150,33 +2150,19 @@ void GpioInit(void) SetPin(14, AGPIO(GPIO_SPI_CLK)); } } + AddLogSpi(1, Pin(GPIO_SPI_CLK), Pin(GPIO_SPI_MOSI), Pin(GPIO_SPI_MISO)); #endif // ESP8266 #ifdef ESP32 -/* - if (PinUsed(GPIO_SPI_CS) || - PinUsed(GPIO_RC522_CS) || - PinUsed(GPIO_NRF24_CS) || - PinUsed(GPIO_ILI9341_CS) || - PinUsed(GPIO_EPAPER29_CS) || - PinUsed(GPIO_EPAPER42_CS) || - PinUsed(GPIO_ILI9488_CS) || - PinUsed(GPIO_SSD1351_CS) || - PinUsed(GPIO_RA8876_CS) || - PinUsed(GPIO_ST7789_DC) || // ST7789 CS may be omitted so chk DC too - PinUsed(GPIO_ST7789_CS) || - PinUsed(GPIO_SSD1331_CS) || - PinUsed(GPIO_SDCARD_CS) - ) { - uint32_t spi_mosi = (PinUsed(GPIO_SPI_CLK) && PinUsed(GPIO_SPI_MOSI)) ? SPI_MOSI : SPI_NONE; - uint32_t spi_miso = (PinUsed(GPIO_SPI_CLK) && PinUsed(GPIO_SPI_MISO)) ? SPI_MISO : SPI_NONE; - TasmotaGlobal.spi_enabled = spi_mosi + spi_miso; - } -*/ uint32_t spi_mosi = (PinUsed(GPIO_SPI_CLK) && PinUsed(GPIO_SPI_MOSI)) ? SPI_MOSI : SPI_NONE; uint32_t spi_miso = (PinUsed(GPIO_SPI_CLK) && PinUsed(GPIO_SPI_MISO)) ? SPI_MISO : SPI_NONE; TasmotaGlobal.spi_enabled = spi_mosi + spi_miso; -#endif // ESP32 AddLogSpi(1, Pin(GPIO_SPI_CLK), Pin(GPIO_SPI_MOSI), Pin(GPIO_SPI_MISO)); + + spi_mosi = (PinUsed(GPIO_SPI_CLK, 1) && PinUsed(GPIO_SPI_MOSI, 1)) ? SPI_MOSI : SPI_NONE; + spi_miso = (PinUsed(GPIO_SPI_CLK, 1) && PinUsed(GPIO_SPI_MISO, 1)) ? SPI_MISO : SPI_NONE; + TasmotaGlobal.spi_enabled2 = spi_mosi + spi_miso; + AddLogSpi(2, Pin(GPIO_SPI_CLK, 1), Pin(GPIO_SPI_MOSI, 1), Pin(GPIO_SPI_MISO, 1)); +#endif // ESP32 #endif // USE_SPI for (uint32_t i = 0; i < nitems(TasmotaGlobal.my_module.io); i++) {