File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ typedef union {
4242SPIClass::SPIClass () {
4343 useHwCs = false ;
4444 pinSet = SPI_PINS_HSPI;
45+ legacyMode2and3 = false ;
4546}
4647
4748bool SPIClass::pins (int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
@@ -161,6 +162,13 @@ void SPIClass::setDataMode(uint8_t dataMode) {
161162 bool CPOL = (dataMode & 0x10 ); // /< CPOL (Clock Polarity)
162163 bool CPHA = (dataMode & 0x01 ); // /< CPHA (Clock Phase)
163164
165+ if (!legacyMode2and3) {
166+ // https://github.com/esp8266/Arduino/issues/2416
167+ // https://github.com/esp8266/Arduino/pull/2418
168+ if (CPOL) // Ensure same behavior as
169+ CPHA ^= 1 ; // SAM, AVR and Intel Boards
170+ }
171+
164172 if (CPHA) {
165173 SPI1U |= (SPIUSME);
166174 } else {
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ class SPIClass {
5858 void end ();
5959 void setHwCs (bool use);
6060 void setBitOrder (uint8_t bitOrder);
61+ void restoreEsp8266LegacyMode2And3 (); // must be called *before* setDataMode()
6162 void setDataMode (uint8_t dataMode);
6263 void setFrequency (uint32_t freq);
6364 void setClockDivider (uint32_t clockDiv);
@@ -77,6 +78,7 @@ class SPIClass {
7778private:
7879 bool useHwCs;
7980 uint8_t pinSet;
81+ bool legacyMode2and3;
8082 void writeBytes_ (const uint8_t * data, uint8_t size);
8183 void transferBytes_ (const uint8_t * out, uint8_t * in, uint8_t size);
8284 void transferBytesAligned_ (const uint8_t * out, uint8_t * in, uint8_t size);
You can’t perform that action at this time.
0 commit comments