fix pointer lifetime for SPIClass

This commit is contained in:
Markus Krause 2023-03-26 16:00:40 +02:00
parent e598865114
commit 29315b9b42

View file

@ -103,14 +103,14 @@ class HmRadio {
#ifdef ESP32 #ifdef ESP32
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
SPIClass* mSpi = new SPIClass(FSPI); mSpi = new SPIClass(FSPI);
#else #else
SPIClass* mSpi = new SPIClass(VSPI); mSpi = new SPIClass(VSPI);
#endif #endif
mSpi->begin(sclk, miso, mosi, cs); mSpi->begin(sclk, miso, mosi, cs);
#else #else
//the old ESP82xx cannot freely place their SPI pins //the old ESP82xx cannot freely place their SPI pins
SPIClass* mSpi = new SPIClass(); mSpi = new SPIClass();
mSpi->begin(); mSpi->begin();
#endif #endif
mNrf24.begin(mSpi, ce, cs); mNrf24.begin(mSpi, ce, cs);
@ -363,6 +363,7 @@ class HmRadio {
uint8_t mTxChIdx; uint8_t mTxChIdx;
uint8_t mRxChIdx; uint8_t mRxChIdx;
SPIClass* mSpi;
RF24 mNrf24; RF24 mNrf24;
uint8_t mTxBuf[MAX_RF_PAYLOAD_SIZE]; uint8_t mTxBuf[MAX_RF_PAYLOAD_SIZE];
}; };