Skip to content

Commit

Permalink
Prep ESP32 SPI bus 2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed May 21, 2024
1 parent 2e51860 commit a4c7add
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
3 changes: 2 additions & 1 deletion tasmota/tasmota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 19 additions & 6 deletions tasmota/tasmota_support/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
28 changes: 7 additions & 21 deletions tasmota/tasmota_support/support_tasmota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down

0 comments on commit a4c7add

Please sign in to comment.