Skip to content

Commit

Permalink
Set HSPI ports by default when HSPI is selected (#874)
Browse files Browse the repository at this point in the history
When user selected HSPI with SPIClass name(HSPI) ESP was, by default,
still using VSPI ports (the ones defined in pins_arduino.h).
With this change when user selects HSPI then HSPI default ports will be
used.
If user won't specify HSPI then VSPI default ports will be used.
If user will specify SCLK, MOSI, MISO and SS with SPI.begin() then user
defined ports will be used no matter if VSPI or HSPI is selected.
With this change fe. SD library can use default HSPI ports. It was
possible to
pass HSPI SPI instance to SD lib, however even then it was using VSPI
ports which were (probably) GPIO matrixed to HSPI.
  • Loading branch information
zipiju authored and me-no-dev committed Nov 28, 2017
1 parent aa83fca commit 3198f25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions libraries/SPI/src/SPI.cpp
Expand Up @@ -49,10 +49,17 @@ void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
return; return;
} }


_sck = sck; if(sck == -1 && miso == -1 && mosi == -1 && ss == -1) {
_miso = miso; _sck = (_spi_num == VSPI) ? SCK : 14;
_mosi = mosi; _miso = (_spi_num == VSPI) ? MISO : 12;
_ss = ss; _mosi = (_spi_num == VSPI) ? MOSI : 13;
_ss = (_spi_num == VSPI) ? SS : 15;
} else {
_sck = sck;
_miso = miso;
_mosi = mosi;
_ss = ss;
}


spiAttachSCK(_spi, _sck); spiAttachSCK(_spi, _sck);
spiAttachMISO(_spi, _miso); spiAttachMISO(_spi, _miso);
Expand Down
2 changes: 1 addition & 1 deletion libraries/SPI/src/SPI.h
Expand Up @@ -52,7 +52,7 @@ class SPIClass


public: public:
SPIClass(uint8_t spi_bus=HSPI); SPIClass(uint8_t spi_bus=HSPI);
void begin(int8_t sck=SCK, int8_t miso=MISO, int8_t mosi=MOSI, int8_t ss=-1); void 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);
Expand Down

1 comment on commit 3198f25

@dneault333
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HSPI is now selected by default, not VSPI
SPIClass(uint8_t spi_bus=HSPI);

Isn't VSPI suppose to be default, your code change suggests it should?

Please sign in to comment.