feat(spi): Add return values to SPI begin (#11477)

This commit is contained in:
Jan Procházka 2025-06-17 15:23:35 +02:00 committed by GitHub
parent 4bc5ffc88d
commit 6d4886cd1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 7 deletions

View file

@ -38,8 +38,8 @@ extern "C" {
#define HSPI 2 //SPI 2 bus normally mapped to pins 12 - 15, but can be matrixed to any pins #define HSPI 2 //SPI 2 bus normally mapped to pins 12 - 15, but can be matrixed to any pins
#define VSPI 3 //SPI 3 bus normally attached to pins 5, 18, 19 and 23, but can be matrixed to any pins #define VSPI 3 //SPI 3 bus normally attached to pins 5, 18, 19 and 23, but can be matrixed to any pins
#else #else
#define FSPI 0 #define FSPI 0 // ESP32C2, C3, C6, H2, S3, P4 - SPI 2 bus
#define HSPI 1 #define HSPI 1 // ESP32S3, P4 - SPI 3 bus
#endif #endif
// This defines are not representing the real Divider of the ESP32 // This defines are not representing the real Divider of the ESP32

View file

@ -63,9 +63,9 @@ SPIClass::~SPIClass() {
#endif #endif
} }
void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) { bool SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) {
if (_spi) { if (_spi) {
return; return true;
} }
if (!_div) { if (!_div) {
@ -74,7 +74,7 @@ void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) {
_spi = spiStartBus(_spi_num, _div, SPI_MODE0, SPI_MSBFIRST); _spi = spiStartBus(_spi_num, _div, SPI_MODE0, SPI_MSBFIRST);
if (!_spi) { if (!_spi) {
return; return false;
} }
if (sck == -1 && miso == -1 && mosi == -1 && ss == -1) { if (sck == -1 && miso == -1 && mosi == -1 && ss == -1) {
@ -110,10 +110,11 @@ void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) {
if (_mosi >= 0 && !spiAttachMOSI(_spi, _mosi)) { if (_mosi >= 0 && !spiAttachMOSI(_spi, _mosi)) {
goto err; goto err;
} }
return; return true;
err: err:
log_e("Attaching pins to SPI failed."); log_e("Attaching pins to SPI failed.");
return false;
} }
void SPIClass::end() { void SPIClass::end() {

View file

@ -61,7 +61,7 @@ private:
public: public:
SPIClass(uint8_t spi_bus = HSPI); SPIClass(uint8_t spi_bus = HSPI);
~SPIClass(); ~SPIClass();
void begin(int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1, int8_t ss = -1); bool begin(int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1, int8_t ss = -1);
void end(); void end();
void setHwCs(bool use); void setHwCs(bool use);