fix SPI assignment across generations

This commit is contained in:
Markus Krause 2023-04-27 18:37:22 +02:00 committed by Thomas Basler
parent b086c6ace6
commit a56d5adb77
2 changed files with 11 additions and 8 deletions

View File

@ -9,13 +9,10 @@ SemaphoreHandle_t paramLock = NULL;
} while (xSemaphoreTake(paramLock, portMAX_DELAY) != pdPASS)
#define SPI_PARAM_UNLOCK() xSemaphoreGive(paramLock)
// as Espressif confused the hell out of everyone we need to swap the selected SPI PHY here
// as for newer generations NRF24 is exactly on the other SPI Interface and we get a collision
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#define SPI_CMT SPI3_HOST
#else
// for ESP32 this is the so-called HSPI
// for ESP32-S2/S3/C3 this nomenclature does not really exist anymore,
// it is simply the first externally usable hardware SPI master controller
#define SPI_CMT SPI2_HOST
#endif
spi_device_handle_t spi_reg, spi_fifo;

View File

@ -9,8 +9,14 @@
#include "SunPosition.h"
#include <Hoymiles.h>
// the NRF shall use the second externally usable HW SPI controller
// for ESP32 that is the so-called VSPI, for ESP32-S2/S3/C3 it is now called implicitly
// HSPI, as it has shifted places for these chip generations
// for all generations, this is equivalent to SPI3_HOST in the lower level driver
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#define VSPI FSPI
#define SPI_NRF HSPI
#else
#define SPI_NRF VSPI
#endif
InverterSettingsClass InverterSettings;
@ -27,7 +33,7 @@ void InverterSettingsClass::init()
Hoymiles.init();
if (PinMapping.isValidNrf24Config()) {
SPIClass* spiClass = new SPIClass(VSPI);
SPIClass* spiClass = new SPIClass(SPI_NRF);
spiClass->begin(pin.nrf24_clk, pin.nrf24_miso, pin.nrf24_mosi, pin.nrf24_cs);
Hoymiles.initNRF(spiClass, pin.nrf24_en, pin.nrf24_irq);
}