From a56d5adb77248799517dc4cd7089a3ee00bc5e2d Mon Sep 17 00:00:00 2001 From: Markus Krause Date: Thu, 27 Apr 2023 18:37:22 +0200 Subject: [PATCH] fix SPI assignment across generations --- lib/CMT2300a/cmt_spi3.c | 9 +++------ src/InverterSettings.cpp | 10 ++++++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/CMT2300a/cmt_spi3.c b/lib/CMT2300a/cmt_spi3.c index c9017f29..95954e4e 100644 --- a/lib/CMT2300a/cmt_spi3.c +++ b/lib/CMT2300a/cmt_spi3.c @@ -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; diff --git a/src/InverterSettings.cpp b/src/InverterSettings.cpp index 13862f15..52a37b5d 100644 --- a/src/InverterSettings.cpp +++ b/src/InverterSettings.cpp @@ -9,8 +9,14 @@ #include "SunPosition.h" #include +// 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); }