File tree 2 files changed +10
-0
lines changed
2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ typedef union {
42
42
SPIClass::SPIClass () {
43
43
useHwCs = false ;
44
44
pinSet = SPI_PINS_HSPI;
45
+ legacyMode2and3 = false ;
45
46
}
46
47
47
48
bool SPIClass::pins (int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
@@ -161,6 +162,13 @@ void SPIClass::setDataMode(uint8_t dataMode) {
161
162
bool CPOL = (dataMode & 0x10 ); // /< CPOL (Clock Polarity)
162
163
bool CPHA = (dataMode & 0x01 ); // /< CPHA (Clock Phase)
163
164
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
+
164
172
if (CPHA) {
165
173
SPI1U |= (SPIUSME);
166
174
} else {
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ class SPIClass {
58
58
void end ();
59
59
void setHwCs (bool use);
60
60
void setBitOrder (uint8_t bitOrder);
61
+ void restoreEsp8266LegacyMode2And3 (); // must be called *before* setDataMode()
61
62
void setDataMode (uint8_t dataMode);
62
63
void setFrequency (uint32_t freq);
63
64
void setClockDivider (uint32_t clockDiv);
@@ -77,6 +78,7 @@ class SPIClass {
77
78
private:
78
79
bool useHwCs;
79
80
uint8_t pinSet;
81
+ bool legacyMode2and3;
80
82
void writeBytes_ (const uint8_t * data, uint8_t size);
81
83
void transferBytes_ (const uint8_t * out, uint8_t * in, uint8_t size);
82
84
void transferBytesAligned_ (const uint8_t * out, uint8_t * in, uint8_t size);
You can’t perform that action at this time.
0 commit comments