From 692a0198f941e34aa02e53079694a10e4ce35fc9 Mon Sep 17 00:00:00 2001 From: Kajetan Rzepecki Date: Fri, 5 Apr 2019 06:17:14 +0200 Subject: [PATCH] Fix SPISettings frequency parameters in ESP32 HW SPI (#13573) --- Marlin/src/HAL/HAL_ESP32/HAL_spi_ESP32.cpp | 26 ++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Marlin/src/HAL/HAL_ESP32/HAL_spi_ESP32.cpp b/Marlin/src/HAL/HAL_ESP32/HAL_spi_ESP32.cpp index 7beb9b4991..d48b14d610 100644 --- a/Marlin/src/HAL/HAL_ESP32/HAL_spi_ESP32.cpp +++ b/Marlin/src/HAL/HAL_ESP32/HAL_spi_ESP32.cpp @@ -44,6 +44,15 @@ static SPISettings spiConfig; // Public functions // -------------------------------------------------------------------------- +#if ENABLED(SOFTWARE_SPI) + + // -------------------------------------------------------------------------- + // Software SPI + // -------------------------------------------------------------------------- + #error "Software SPI not supported for ESP32. Use Hardware SPI." + +#else + // -------------------------------------------------------------------------- // Hardware SPI // -------------------------------------------------------------------------- @@ -61,13 +70,14 @@ void spiInit(uint8_t spiRate) { uint32_t clock; switch (spiRate) { - case SPI_FULL_SPEED: clock = SPI_CLOCK_DIV2; break; - case SPI_HALF_SPEED: clock = SPI_CLOCK_DIV4; break; - case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8; break; - case SPI_EIGHTH_SPEED: clock = SPI_CLOCK_DIV16; break; - case SPI_SPEED_5: clock = SPI_CLOCK_DIV32; break; - case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break; - default: clock = SPI_CLOCK_DIV2; // Default from the SPI library + case SPI_FULL_SPEED: clock = 16000000; break; + case SPI_HALF_SPEED: clock = 8000000; break; + case SPI_QUARTER_SPEED: clock = 4000000; break; + case SPI_EIGHTH_SPEED: clock = 2000000; break; + case SPI_SIXTEENTH_SPEED: clock = 1000000; break; + case SPI_SPEED_5: clock = 500000; break; + case SPI_SPEED_6: clock = 250000; break; + default: clock = 1000000; // Default from the SPI library } spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0); @@ -106,4 +116,6 @@ void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) SPI.beginTransaction(spiConfig); } +#endif // !SOFTWARE_SPI + #endif // ARDUINO_ARCH_ESP32