Skip to content

feat(spi): Add return values to SPI begin + comments on SPI buses #11477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cores/esp32/esp32-hal-spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 VSPI 3 //SPI 3 bus normally attached to pins 5, 18, 19 and 23, but can be matrixed to any pins
#else
#define FSPI 0
#define HSPI 1
#define FSPI 0 // ESP32C2, C3, C6, H2, S3, P4 - SPI 2 bus
#define HSPI 1 // ESP32S3, P4 - SPI 3 bus
#endif

// This defines are not representing the real Divider of the ESP32
Expand Down
9 changes: 5 additions & 4 deletions libraries/SPI/src/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ SPIClass::~SPIClass() {
#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) {
return;
return true;
}

if (!_div) {
Expand All @@ -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);
if (!_spi) {
return;
return false;
}

if (sck == -1 && miso == -1 && mosi == -1 && ss == -1) {
Expand Down Expand Up @@ -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)) {
goto err;
}
return;
return true;

err:
log_e("Attaching pins to SPI failed.");
return false;
}

void SPIClass::end() {
Expand Down
2 changes: 1 addition & 1 deletion libraries/SPI/src/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SPIClass {
public:
SPIClass(uint8_t spi_bus = HSPI);
~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 setHwCs(bool use);
Expand Down
Loading