Skip to content

Commit 8504e3f

Browse files
Fixes for WICED Feather hardware SPI
1 parent 3d8a730 commit 8504e3f

File tree

3 files changed

+34
-66
lines changed

3 files changed

+34
-66
lines changed

Adafruit_SSD1306.cpp

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@
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
@@ -116,33 +116,25 @@
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

@@ -174,11 +166,8 @@
174166
*/
175167
Adafruit_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
*/
211200
Adafruit_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
248233
Adafruit_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
*/
284268
Adafruit_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
316296
Adafruit_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
*/
340319
Adafruit_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.
363339
inline 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

Adafruit_SSD1306.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
// (NEW CODE SHOULD IGNORE THIS, USE THE CONSTRUCTORS THAT ACCEPT WIDTH
3333
// AND HEIGHT ARGUMENTS).
3434

35+
#if defined(ARDUINO_STM32_FEATHER)
36+
typedef class HardwareSPI SPIClass;
37+
#endif
38+
3539
#include <Wire.h>
3640
#include <SPI.h>
3741
#include <Adafruit_GFX.h>
@@ -115,10 +119,8 @@ class Adafruit_SSD1306 : public Adafruit_GFX {
115119
int8_t rst_pin=-1, uint32_t res=100000L);
116120
Adafruit_SSD1306(uint8_t w, uint8_t h, int8_t mosi_pin, int8_t sclk_pin,
117121
int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);
118-
#if !defined(ARDUINO_STM32_FEATHER) // No HW SPI on WICED Feather yet
119122
Adafruit_SSD1306(uint8_t w, uint8_t h, SPIClass *spi,
120123
int8_t dc_pin, int8_t rst_pin, int8_t cs_pin, uint32_t bitrate=8000000UL);
121-
#endif
122124

123125
// DEPRECATED CONSTRUCTORS - for back compatibility, avoid in new projects
124126
Adafruit_SSD1306(int8_t mosi_pin, int8_t sclk_pin, int8_t dc_pin,
@@ -156,9 +158,7 @@ class Adafruit_SSD1306 : public Adafruit_GFX {
156158
void ssd1306_command1(uint8_t c);
157159
void ssd1306_commandList(const uint8_t *c, uint8_t n);
158160

159-
#if !defined(ARDUINO_STM32_FEATHER)
160161
SPIClass *spi;
161-
#endif
162162
TwoWire *wire;
163163
uint8_t *buffer;
164164
int8_t i2caddr, vccstate, page_end;
@@ -167,7 +167,7 @@ class Adafruit_SSD1306 : public Adafruit_GFX {
167167
PortReg *mosiPort , *clkPort , *dcPort , *csPort;
168168
PortMask mosiPinMask, clkPinMask, dcPinMask, csPinMask;
169169
#endif
170-
#if defined(SPI_HAS_TRANSACTION) && !defined(ARDUINO_STM32_FEATHER)
170+
#if defined(SPI_HAS_TRANSACTION)
171171
SPISettings spiSettings;
172172
#endif
173173
#if ARDUINO >= 157

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit SSD1306
2-
version=1.2.7
2+
version=1.2.8
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=SSD1306 oled driver library for monochrome 128x64 and 128x32 displays

0 commit comments

Comments
 (0)