9191 #define SSD1306_MODE_DATA digitalWrite (dcPin, HIGH); // /< Data mode
9292#endif
9393
94- #if (ARDUINO >= 157)
94+ #if (ARDUINO >= 157) && !defined(ARDUINO_STM32_FEATHER)
9595 #define SETWIRECLOCK wire->setClock (WIRECLK) // /< Set before I2C transfer
9696 #define RESWIRECLOCK wire->setClock (restoreClk) // /< Restore after I2C xfer
97- #else // setClock() is not present in older Arduino Wire lib
97+ #else // setClock() is not present in older Arduino Wire lib (or WICED)
9898 #define SETWIRECLOCK // /< Dummy stand-in define
9999 #define RESWIRECLOCK // /< keeps compiler happy
100100#endif
116116// so other I2C device types still work). All of these are encapsulated
117117// in the TRANSACTION_* macros.
118118
119- #if defined(ARDUINO_STM32_FEATHER)
120- // The WICED board currently has no SPIClass -- hardware SPI is not
121- // supported by this library there -- nor is there a Wire setClock()
122- // function, so the transaction start/end code is a little simpler...
123- #define TRANSACTION_START if (!wire) { SSD1306_SELECT; } // /< SW SPI select
124- #define TRANSACTION_END if (!wire) { SSD1306_DESELECT; } // /< SW SPI deselect
125- #else
126- // Everywhere else, check first if Wire, then hardware SPI, then soft SPI:
127- #define TRANSACTION_START \
128- if (wire) { \
129- SETWIRECLOCK; \
130- } else { \
131- if (spi) { \
132- SPI_TRANSACTION_START; \
133- } \
134- SSD1306_SELECT; \
135- } // /< Wire, SPI or bitbang transfer setup
136- #define TRANSACTION_END \
137- if (wire) { \
138- RESWIRECLOCK; \
139- } else { \
140- SSD1306_DESELECT; \
141- if (spi) { \
142- SPI_TRANSACTION_END; \
143- } \
144- } // /< Wire, SPI or bitbang transfer end
145- #endif
119+ // Check first if Wire, then hardware SPI, then soft SPI:
120+ #define TRANSACTION_START \
121+ if (wire) { \
122+ SETWIRECLOCK; \
123+ } else { \
124+ if (spi) { \
125+ SPI_TRANSACTION_START; \
126+ } \
127+ SSD1306_SELECT; \
128+ } // /< Wire, SPI or bitbang transfer setup
129+ #define TRANSACTION_END \
130+ if (wire) { \
131+ RESWIRECLOCK; \
132+ } else { \
133+ SSD1306_DESELECT; \
134+ if (spi) { \
135+ SPI_TRANSACTION_END; \
136+ } \
137+ } // /< Wire, SPI or bitbang transfer end
146138
147139// CONSTRUCTORS, DESTRUCTOR ------------------------------------------------
148140
174166*/
175167Adafruit_SSD1306::Adafruit_SSD1306 (uint8_t w, uint8_t h, TwoWire *twi,
176168 int8_t rst_pin, uint32_t res) : Adafruit_GFX(w, h),
177- wire(twi ? twi : &Wire), buffer(NULL ), mosiPin(-1 ), clkPin(-1 ), dcPin(-1 ),
178- csPin(-1 ), rstPin(rst_pin), restoreClk(res) {
179- #if !defined(ARDUINO_STM32_FEATHER)
180- spi = NULL ;
181- #endif
169+ spi(NULL ), wire(twi ? twi : &Wire), buffer(NULL ), mosiPin(-1 ), clkPin(-1 ),
170+ dcPin(-1 ), csPin(-1 ), rstPin(rst_pin), restoreClk(res) {
182171}
183172
184173/* !
@@ -210,12 +199,9 @@ Adafruit_SSD1306::Adafruit_SSD1306(uint8_t w, uint8_t h, TwoWire *twi,
210199*/
211200Adafruit_SSD1306::Adafruit_SSD1306 (uint8_t w, uint8_t h,
212201 int8_t mosi_pin, int8_t sclk_pin, int8_t dc_pin, int8_t rst_pin,
213- int8_t cs_pin) : Adafruit_GFX(w, h), wire(NULL ), buffer(NULL ),
202+ int8_t cs_pin) : Adafruit_GFX(w, h), spi( NULL ), wire(NULL ), buffer(NULL ),
214203 mosiPin(mosi_pin), clkPin(sclk_pin), dcPin(dc_pin), csPin(cs_pin),
215204 rstPin(rst_pin) {
216- #if !defined(ARDUINO_STM32_FEATHER)
217- spi = NULL ;
218- #endif
219205}
220206
221207/* !
@@ -244,7 +230,6 @@ Adafruit_SSD1306::Adafruit_SSD1306(uint8_t w, uint8_t h,
244230 @note Call the object's begin() function before use -- buffer
245231 allocation is performed there!
246232*/
247- #if !defined(ARDUINO_STM32_FEATHER) // No HW SPI on WICED Feather yet
248233Adafruit_SSD1306::Adafruit_SSD1306 (uint8_t w, uint8_t h, SPIClass *spi,
249234 int8_t dc_pin, int8_t rst_pin, int8_t cs_pin, uint32_t bitrate) :
250235 Adafruit_GFX(w, h), spi(spi ? spi : &SPI), wire(NULL ), buffer(NULL ),
@@ -253,7 +238,6 @@ Adafruit_SSD1306::Adafruit_SSD1306(uint8_t w, uint8_t h, SPIClass *spi,
253238 spiSettings = SPISettings (bitrate, MSBFIRST, SPI_MODE0);
254239#endif
255240}
256- #endif
257241
258242/* !
259243 @brief DEPRECATED constructor for SPI SSD1306 displays, using software
@@ -283,12 +267,9 @@ Adafruit_SSD1306::Adafruit_SSD1306(uint8_t w, uint8_t h, SPIClass *spi,
283267*/
284268Adafruit_SSD1306::Adafruit_SSD1306 (int8_t mosi_pin, int8_t sclk_pin,
285269 int8_t dc_pin, int8_t rst_pin, int8_t cs_pin) :
286- Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT), wire(NULL ), buffer(NULL ),
287- mosiPin(mosi_pin), clkPin(sclk_pin), dcPin(dc_pin), csPin(cs_pin),
288- rstPin(rst_pin) {
289- #if !defined(ARDUINO_STM32_FEATHER)
290- spi = NULL ;
291- #endif
270+ Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT), spi(NULL ), wire(NULL ),
271+ buffer(NULL ), mosiPin(mosi_pin), clkPin(sclk_pin), dcPin(dc_pin),
272+ csPin(cs_pin), rstPin(rst_pin) {
292273}
293274
294275/* !
@@ -312,7 +293,6 @@ Adafruit_SSD1306::Adafruit_SSD1306(int8_t mosi_pin, int8_t sclk_pin,
312293 @note Call the object's begin() function before use -- buffer
313294 allocation is performed there!
314295*/
315- #if !defined(ARDUINO_STM32_FEATHER) // No HW SPI on WICED Feather yet
316296Adafruit_SSD1306::Adafruit_SSD1306 (int8_t dc_pin, int8_t rst_pin,
317297 int8_t cs_pin) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT),
318298 spi(&SPI), wire(NULL ), buffer(NULL ), mosiPin(-1 ), clkPin(-1 ),
@@ -321,7 +301,6 @@ Adafruit_SSD1306::Adafruit_SSD1306(int8_t dc_pin, int8_t rst_pin,
321301 spiSettings = SPISettings (8000000 , MSBFIRST, SPI_MODE0);
322302#endif
323303}
324- #endif
325304
326305/* !
327306 @brief DEPRECATED constructor for I2C SSD1306 displays. Provided for
@@ -338,12 +317,9 @@ Adafruit_SSD1306::Adafruit_SSD1306(int8_t dc_pin, int8_t rst_pin,
338317 allocation is performed there!
339318*/
340319Adafruit_SSD1306::Adafruit_SSD1306 (int8_t rst_pin) :
341- Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT), wire(&Wire),
320+ Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT), spi( NULL ), wire(&Wire),
342321 buffer(NULL ), mosiPin(-1 ), clkPin(-1 ), dcPin(-1 ), csPin(-1 ),
343322 rstPin(rst_pin) {
344- #if !defined(ARDUINO_STM32_FEATHER)
345- spi = NULL ;
346- #endif
347323}
348324
349325/* !
@@ -361,11 +337,9 @@ Adafruit_SSD1306::~Adafruit_SSD1306(void) {
361337// Issue single byte out SPI, either soft or hardware as appropriate.
362338// SPI transaction/selection must be performed in calling function.
363339inline void Adafruit_SSD1306::SPIwrite (uint8_t d) {
364- #if !defined(ARDUINO_STM32_FEATHER)
365340 if (spi) {
366341 (void )spi->transfer (d);
367342 } else {
368- #endif
369343 for (uint8_t bit = 0x80 ; bit; bit >>= 1 ) {
370344#ifdef HAVE_PORTREG
371345 if (d & bit) *mosiPort |= mosiPinMask;
@@ -378,9 +352,7 @@ inline void Adafruit_SSD1306::SPIwrite(uint8_t d) {
378352 digitalWrite (clkPin , LOW);
379353#endif
380354 }
381- #if !defined(ARDUINO_STM32_FEATHER)
382355 }
383- #endif
384356}
385357
386358// Issue single command to SSD1306, using I2C or hard/soft SPI as needed.
@@ -513,12 +485,10 @@ boolean Adafruit_SSD1306::begin(uint8_t vcs, uint8_t addr, boolean reset,
513485 csPinMask = digitalPinToBitMask (csPin);
514486#endif
515487 SSD1306_DESELECT
516- #if !defined(ARDUINO_STM32_FEATHER)
517488 if (spi) { // Hardware SPI
518489 // SPI peripheral begin same as wire check above.
519490 if (periphBegin) spi->begin ();
520491 } else { // Soft SPI
521- #endif
522492 pinMode (mosiPin, OUTPUT); // MOSI and SCLK outputs
523493 pinMode (clkPin , OUTPUT);
524494#ifdef HAVE_PORTREG
@@ -530,9 +500,7 @@ boolean Adafruit_SSD1306::begin(uint8_t vcs, uint8_t addr, boolean reset,
530500#else
531501 digitalWrite (clkPin, LOW); // Clock low
532502#endif
533- #if !defined(ARDUINO_STM32_FEATHER)
534503 }
535- #endif
536504 }
537505
538506 // Reset SSD1306 if requested and reset pin specified in constructor
0 commit comments