Skip to content

Commit b461e01

Browse files
UltimumControllucasssvazpre-commit-ci-lite[bot]
authored
New SPI invert hardware SS function in hall-spi and SPI library (#11297)
* Add files via upload * Add files via upload * Update SPI.h * Update esp32-hal-spi.c renamed invert_out to ss_invert to be more intuitive * Update esp32-hal-spi.h Removed the out from the function name spiSSInvertout. * Update SPI.cpp Removed the out from the function name spiSSInvertout. * Update cores/esp32/esp32-hal-spi.c Co-authored-by: Lucas Saavedra Vaz <[email protected]> * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: Lucas Saavedra Vaz <[email protected]> Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 9193c9d commit b461e01

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

cores/esp32/esp32-hal-spi.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct spi_struct_t {
7474
int8_t miso;
7575
int8_t mosi;
7676
int8_t ss;
77+
bool ss_invert;
7778
};
7879

7980
#if CONFIG_IDF_TARGET_ESP32S2
@@ -365,7 +366,7 @@ bool spiAttachSS(spi_t *spi, uint8_t ss_num, int8_t ss) {
365366
return false;
366367
}
367368
pinMode(ss, OUTPUT);
368-
pinMatrixOutAttach(ss, SPI_SS_IDX(spi->num, ss_num), false, false);
369+
pinMatrixOutAttach(ss, SPI_SS_IDX(spi->num, ss_num), spi->ss_invert, false);
369370
spiEnableSSPins(spi, (1 << ss_num));
370371
spi->ss = ss;
371372
if (!perimanSetPinBus(ss, ESP32_BUS_TYPE_SPI_MASTER_SS, (void *)(spi->num + 1), spi->num, -1)) {
@@ -435,6 +436,12 @@ void spiSSDisable(spi_t *spi) {
435436
SPI_MUTEX_UNLOCK();
436437
}
437438

439+
void spiSSInvert(spi_t *spi, bool invert) {
440+
if (spi) {
441+
spi->ss_invert = invert;
442+
}
443+
}
444+
438445
void spiSSSet(spi_t *spi) {
439446
if (!spi) {
440447
return;

cores/esp32/esp32-hal-spi.h

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ void spiSSSet(spi_t *spi);
9797
void spiSSClear(spi_t *spi);
9898

9999
void spiWaitReady(spi_t *spi);
100+
//invert hardware SS
101+
void spiSSInvert(spi_t *spi, bool invert);
100102

101103
uint32_t spiGetClockDiv(spi_t *spi);
102104
uint8_t spiGetDataMode(spi_t *spi);

libraries/SPI/src/SPI.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ void SPIClass::setHwCs(bool use) {
144144
_use_hw_ss = use;
145145
}
146146

147+
void SPIClass::setSSInvert(bool invert) {
148+
if (_spi) {
149+
spiSSInvert(_spi, invert);
150+
}
151+
}
152+
147153
void SPIClass::setFrequency(uint32_t freq) {
148154
SPI_PARAM_LOCK();
149155
//check if last freq changed

libraries/SPI/src/SPI.h

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class SPIClass {
6565
void end();
6666

6767
void setHwCs(bool use);
68+
void setSSInvert(bool invert); //use before setHwCS for change to be used by setHwCs
6869
void setBitOrder(uint8_t bitOrder);
6970
void setDataMode(uint8_t dataMode);
7071
void setFrequency(uint32_t freq);

0 commit comments

Comments
 (0)