mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-25 19:56:30 +00:00
Prep ESP32 SPI bus 2 support
This commit is contained in:
parent
2e51860464
commit
a4c7add8df
@ -325,7 +325,8 @@ struct TasmotaGlobal_t {
|
|||||||
uint8_t busy_time; // Time in ms to allow executing of time critical functions
|
uint8_t busy_time; // Time in ms to allow executing of time critical functions
|
||||||
uint8_t init_state; // Tasmota init state
|
uint8_t init_state; // Tasmota init state
|
||||||
uint8_t heartbeat_inverted; // Heartbeat pulse inverted flag
|
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 soft_spi_enabled; // Software SPI configured
|
||||||
uint8_t blinks; // Number of LED blinks
|
uint8_t blinks; // Number of LED blinks
|
||||||
uint8_t restart_flag; // Tasmota restart flag
|
uint8_t restart_flag; // Tasmota restart flag
|
||||||
|
@ -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);
|
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) {
|
void AddLogSpi(uint32_t hardware, int clk, int mosi, int miso) {
|
||||||
// Needs optimization
|
uint32_t enabled = TasmotaGlobal.soft_spi_enabled;
|
||||||
uint32_t enabled = (hardware) ? TasmotaGlobal.spi_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) {
|
switch(enabled) {
|
||||||
case SPI_MOSI:
|
case SPI_MOSI:
|
||||||
AddLog(LOG_LEVEL_INFO, PSTR("SPI: %s using GPIO%02d(CLK) and GPIO%02d(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;
|
break;
|
||||||
case SPI_MISO:
|
case SPI_MISO:
|
||||||
AddLog(LOG_LEVEL_INFO, PSTR("SPI: %s using GPIO%02d(CLK) and GPIO%02d(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;
|
break;
|
||||||
case SPI_MOSI_MISO:
|
case SPI_MOSI_MISO:
|
||||||
AddLog(LOG_LEVEL_INFO, PSTR("SPI: %s using GPIO%02d(CLK), GPIO%02d(MOSI) and GPIO%02d(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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2150,33 +2150,19 @@ void GpioInit(void)
|
|||||||
SetPin(14, AGPIO(GPIO_SPI_CLK));
|
SetPin(14, AGPIO(GPIO_SPI_CLK));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
AddLogSpi(1, Pin(GPIO_SPI_CLK), Pin(GPIO_SPI_MOSI), Pin(GPIO_SPI_MISO));
|
||||||
#endif // ESP8266
|
#endif // ESP8266
|
||||||
#ifdef ESP32
|
#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_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;
|
uint32_t spi_miso = (PinUsed(GPIO_SPI_CLK) && PinUsed(GPIO_SPI_MISO)) ? SPI_MISO : SPI_NONE;
|
||||||
TasmotaGlobal.spi_enabled = spi_mosi + spi_miso;
|
TasmotaGlobal.spi_enabled = spi_mosi + spi_miso;
|
||||||
#endif // ESP32
|
|
||||||
AddLogSpi(1, Pin(GPIO_SPI_CLK), Pin(GPIO_SPI_MOSI), Pin(GPIO_SPI_MISO));
|
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
|
#endif // USE_SPI
|
||||||
|
|
||||||
for (uint32_t i = 0; i < nitems(TasmotaGlobal.my_module.io); i++) {
|
for (uint32_t i = 0; i < nitems(TasmotaGlobal.my_module.io); i++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user