Skip to content

Commit 2d4ac41

Browse files
authored
Merge pull request #5377 from tonhuisman/feature/SPI-add-support-for-multiple-buses
[SPI] Add support for multiple SPI buses
2 parents a67a3d0 + ee123ae commit 2d4ac41

File tree

86 files changed

+2954
-2406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2954
-2406
lines changed

lib/Adafruit_ILI9341/Adafruit_ILI9341.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@
111111
@param cs Chip select pin # (OK to pass -1 if CS tied to GND).
112112
@param dc Data/Command pin # (required).
113113
@param rst Reset pin # (optional, pass -1 if unused).
114+
@param model The display model to initiailize.
115+
@param w Widht of the display in pixels.
116+
@param h Height of the display in pixels.
114117
*/
115118

116119
/**************************************************************************/
@@ -133,14 +136,20 @@ Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t rst, uint8_t mod
133136
@param cs Chip select pin # (optional, pass -1 if unused and
134137
CS is tied to GND).
135138
@param rst Reset pin # (optional, pass -1 if unused).
139+
@param model The display model to initiailize.
140+
@param w Widht of the display in pixels.
141+
@param h Height of the display in pixels.
136142
*/
137143

138144
/**************************************************************************/
139145

140-
// Adafruit_ILI9341::Adafruit_ILI9341(SPIClass *spiClass, int8_t dc, int8_t cs,
141-
// int8_t rst)
142-
// : Adafruit_SPITFT(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT, spiClass, cs, dc,
143-
// rst) {}
146+
Adafruit_ILI9341::Adafruit_ILI9341(SPIClass *spiClass, int8_t dc, int8_t cs,
147+
int8_t rst, uint8_t model, uint16_t w, uint16_t h)
148+
: Adafruit_SPITFT(w, h, spiClass, cs, dc, rst) {
149+
_model = model;
150+
_w = w;
151+
_h = h;
152+
}
144153
#endif // end !ESP8266
145154

146155
/**************************************************************************/

lib/Adafruit_ILI9341/Adafruit_ILI9341.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ class Adafruit_ILI9341 : public Adafruit_SPITFT {
163163

164164
#if !defined(ESP8266)
165165

166-
// Adafruit_ILI9341(SPIClass *spiClass, int8_t dc, int8_t cs = -1,
167-
// int8_t rst = -1);
166+
Adafruit_ILI9341(SPIClass *spiClass, int8_t dc, int8_t cs = -1,
167+
int8_t rst = -1, uint8_t model = 0, uint16_t w = 0, uint16_t h = 0);
168168
#endif // end !ESP8266
169169
// Adafruit_ILI9341(tftBusWidth busWidth, int8_t d0, int8_t wr, int8_t dc,
170170
// int8_t cs = -1, int8_t rst = -1, int8_t rd = -1);

lib/Itho/CC1101.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "CC1101.h"
66

77
// default constructor
8-
CC1101::CC1101(int8_t CSpin, int8_t MISOpin) : _CSpin(CSpin), _MISOpin(MISOpin)
8+
CC1101::CC1101(int8_t CSpin, int8_t MISOpin, SPIClass& spi) : _CSpin(CSpin), _MISOpin(MISOpin), _spi(spi)
99
{
1010
// SPI.begin(); // Done already by ESPEasy
1111
pinMode(_CSpin, OUTPUT);
@@ -51,7 +51,7 @@ void CC1101::reset()
5151
select();
5252

5353
spi_waitMiso();
54-
SPI.transfer(CC1101_SRES);
54+
_spi.transfer(CC1101_SRES);
5555
delay(10);
5656
spi_waitMiso();
5757
deselect();
@@ -63,7 +63,7 @@ uint8_t CC1101::writeCommand(uint8_t command)
6363

6464
select();
6565
spi_waitMiso();
66-
result = SPI.transfer(command);
66+
result = _spi.transfer(command);
6767
deselect();
6868

6969
return result;
@@ -73,8 +73,8 @@ void CC1101::writeRegister(uint8_t address, uint8_t data)
7373
{
7474
select();
7575
spi_waitMiso();
76-
SPI.transfer(address);
77-
SPI.transfer(data);
76+
_spi.transfer(address);
77+
_spi.transfer(data);
7878
deselect();
7979
}
8080

@@ -84,8 +84,8 @@ uint8_t CC1101::readRegister(uint8_t address)
8484

8585
select();
8686
spi_waitMiso();
87-
SPI.transfer(address);
88-
val = SPI.transfer(0);
87+
_spi.transfer(address);
88+
val = _spi.transfer(0);
8989
deselect();
9090

9191
return val;
@@ -97,12 +97,12 @@ uint8_t CC1101::readRegisterMedian3(uint8_t address)
9797

9898
select();
9999
spi_waitMiso();
100-
SPI.transfer(address);
101-
val1 = SPI.transfer(0);
102-
SPI.transfer(address);
103-
val2 = SPI.transfer(0);
104-
SPI.transfer(address);
105-
val3 = SPI.transfer(0);
100+
_spi.transfer(address);
101+
val1 = _spi.transfer(0);
102+
_spi.transfer(address);
103+
val2 = _spi.transfer(0);
104+
_spi.transfer(address);
105+
val3 = _spi.transfer(0);
106106
deselect();
107107

108108
// reverse sort (largest in val1) because this is te expected order for TX_BUFFER
@@ -162,10 +162,10 @@ void CC1101::writeBurstRegister(uint8_t address, uint8_t *data, uint8_t length)
162162

163163
select();
164164
spi_waitMiso();
165-
SPI.transfer(address | CC1101_WRITE_BURST);
165+
_spi.transfer(address | CC1101_WRITE_BURST);
166166

167167
for (i = 0; i < length; i++) {
168-
SPI.transfer(pgm_read_byte(&(data[i])));
168+
_spi.transfer(pgm_read_byte(&(data[i])));
169169
}
170170
deselect();
171171
}
@@ -176,10 +176,10 @@ void CC1101::readBurstRegister(uint8_t *buffer, uint8_t address, uint8_t length)
176176

177177
select();
178178
spi_waitMiso();
179-
SPI.transfer(address | CC1101_READ_BURST);
179+
_spi.transfer(address | CC1101_READ_BURST);
180180

181181
for (i = 0; i < length; i++) {
182-
buffer[i] = SPI.transfer(0x00);
182+
buffer[i] = _spi.transfer(0x00);
183183
}
184184

185185
deselect();

lib/Itho/CC1101.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ class CC1101 {
191191

192192
public:
193193

194-
CC1101(int8_t CSpin = PIN_SPI_SS,
195-
int8_t MISOpin = MISO);
194+
CC1101(int8_t CSpin = PIN_SPI_SS,
195+
int8_t MISOpin = MISO,
196+
SPIClass& spi = SPI);
196197
virtual ~CC1101();
197198

198199
// spi
@@ -230,6 +231,7 @@ class CC1101 {
230231

231232
int8_t _CSpin = PIN_SPI_SS;
232233
int8_t _MISOpin;
234+
SPIClass& _spi = SPI;
233235

234236
protected:
235237

lib/Itho/IthoCC1101.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#define MDMCFG2 0x02 // 16bit sync word / 16bit specific
4343

4444
// default constructor
45-
IthoCC1101::IthoCC1101(int8_t CSpin, int8_t MISOpin, uint8_t counter, uint8_t sendTries) : CC1101(CSpin, MISOpin)
45+
IthoCC1101::IthoCC1101(int8_t CSpin, int8_t MISOpin, SPIClass& spi, uint8_t counter, uint8_t sendTries) : CC1101(CSpin, MISOpin, spi)
4646
{
4747
this->outIthoPacket.counter = counter;
4848
this->sendTries = sendTries;

lib/Itho/IthoCC1101.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ class IthoCC1101 : protected CC1101 {
7878

7979
public:
8080

81-
IthoCC1101(int8_t CSpin = PIN_SPI_SS,
82-
int8_t MISOpin = MISO,
83-
uint8_t counter = 0,
84-
uint8_t sendTries = 3); // set initial counter value
81+
IthoCC1101(int8_t CSpin = PIN_SPI_SS,
82+
int8_t MISOpin = MISO,
83+
SPIClass& spi = SPI,
84+
uint8_t counter = 0,
85+
uint8_t sendTries = 3); // set initial counter value
8586
~IthoCC1101();
8687

8788
// init
@@ -90,7 +91,8 @@ class IthoCC1101 : protected CC1101 {
9091
initReceive();
9192
} // init,reset CC1101
9293

93-
void initReceive();
94+
void initReceive();
95+
9496
// uint8_t getLastCounter() const {
9597
// return outIthoPacket.counter;
9698
// } // counter is increased before sending a command
@@ -104,7 +106,7 @@ class IthoCC1101 : protected CC1101 {
104106
}
105107

106108
// receive
107-
bool checkForNewPacket(); // check RX fifo for new data
109+
bool checkForNewPacket(); // check RX fifo for new data
108110
// IthoPacket getLastPacket() const {
109111
// return inIthoPacket;
110112
// } // retrieve last received/parsed packet from remote
@@ -120,14 +122,15 @@ class IthoCC1101 : protected CC1101 {
120122
// uint8_t ReadRSSI();
121123
// bool checkID(const uint8_t *id) const;
122124
// int* getLastID();
123-
String getLastIDstr(bool ashex = true);
125+
String getLastIDstr(bool ashex = true);
126+
124127
// String getLastMessagestr(bool ashex = true);
125128
// String LastMessageDecoded() const;
126129

127130
// send
128-
void sendCommand(IthoCommand command,
129-
uint8_t srcId[3] = 0,
130-
uint8_t destId[3] = 0);
131+
void sendCommand(IthoCommand command,
132+
uint8_t srcId[3] = 0,
133+
uint8_t destId[3] = 0);
131134

132135
void enableOrcon(bool state);
133136

lib/LOLIN_EPD/src/LOLIN_EPD.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "Adafruit_GFX.h"
1717
#include "LOLIN_EPD.h"
1818

19-
LOLIN_EPD::LOLIN_EPD(int width, int height, int8_t spi_mosi, int8_t spi_clock, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY):Adafruit_GFX(width, height)
19+
LOLIN_EPD::LOLIN_EPD(int width, int height, int8_t spi_mosi, int8_t spi_clock, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY, SPIClass& spi):Adafruit_GFX(width, height)
2020
{
2121
cs = CS;
2222
rst = RST;
@@ -26,9 +26,10 @@ LOLIN_EPD::LOLIN_EPD(int width, int height, int8_t spi_mosi, int8_t spi_clock, i
2626
busy = BUSY;
2727
hwSPI = false;
2828
singleByteTxns = false;
29+
_spi = spi;
2930
}
3031

31-
LOLIN_EPD::LOLIN_EPD(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY):Adafruit_GFX(width, height)
32+
LOLIN_EPD::LOLIN_EPD(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY, SPIClass& spi):Adafruit_GFX(width, height)
3233
{
3334

3435
dc = DC;
@@ -37,6 +38,7 @@ LOLIN_EPD::LOLIN_EPD(int width, int height, int8_t DC, int8_t RST, int8_t CS, in
3738
busy = BUSY;
3839
hwSPI = true;
3940
singleByteTxns = false;
41+
_spi = spi;
4042
}
4143

4244
/**************************************************************************/
@@ -90,9 +92,9 @@ void LOLIN_EPD::begin(bool reset)
9092
}
9193
else
9294
{
93-
SPI.begin();
95+
// _spi.begin(); // Already done by ESPEasy
9496
#ifndef SPI_HAS_TRANSACTION
95-
SPI.setClockDivider(4);
97+
_spi.setClockDivider(4);
9698
#endif
9799
}
98100

@@ -194,12 +196,12 @@ uint8_t LOLIN_EPD::fastSPIwrite(uint8_t d)
194196
{
195197
uint8_t b;
196198
csLow();
197-
b = SPI.transfer(d);
199+
b = _spi.transfer(d);
198200
csHigh();
199201
return b;
200202
}
201203
else
202-
return SPI.transfer(d);
204+
return _spi.transfer(d);
203205
}
204206
else
205207
{
@@ -234,7 +236,7 @@ uint8_t LOLIN_EPD::fastSPIwrite(uint8_t d)
234236
void LOLIN_EPD::csHigh()
235237
{
236238
#ifdef SPI_HAS_TRANSACTION
237-
SPI.endTransaction();
239+
_spi.endTransaction();
238240
#endif
239241
#ifdef HAVE_PORTREG
240242
*csport |= cspinmask;
@@ -251,7 +253,7 @@ void LOLIN_EPD::csHigh()
251253
void LOLIN_EPD::csLow()
252254
{
253255
#ifdef SPI_HAS_TRANSACTION
254-
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
256+
_spi.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
255257
#endif
256258
#ifdef HAVE_PORTREG
257259
*csport &= ~cspinmask;

lib/LOLIN_EPD/src/LOLIN_EPD.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ enum
6060
class LOLIN_EPD: public Adafruit_GFX
6161
{
6262
public:
63-
LOLIN_EPD(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1);
64-
LOLIN_EPD(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1);
63+
LOLIN_EPD(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1, SPIClass& spi = SPI);
64+
LOLIN_EPD(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1, SPIClass& spi = SPI);
6565

6666
virtual ~LOLIN_EPD();
6767
virtual void begin(bool reset = true);
@@ -111,6 +111,7 @@ class LOLIN_EPD: public Adafruit_GFX
111111
void dcLow();
112112

113113
private:
114+
SPIClass& _spi = SPI;
114115
};
115116

116117
#include "LOLIN_IL3897.h"

lib/LOLIN_EPD/src/LOLIN_IL3897.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ const unsigned char LUT_DATA_part[] PROGMEM = {
184184
@param BUSY the busy pin to use
185185
*/
186186
/**************************************************************************/
187-
LOLIN_IL3897::LOLIN_IL3897(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY) : LOLIN_EPD(width, height, SID, SCLK, DC, RST, CS, BUSY)
187+
LOLIN_IL3897::LOLIN_IL3897(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY, SPIClass& spi) : LOLIN_EPD(width, height, SID, SCLK, DC, RST, CS, BUSY, spi)
188188
{
189189

190190
if ((height % 8) > 0)
@@ -202,7 +202,7 @@ LOLIN_IL3897::LOLIN_IL3897(int width, int height, int8_t SID, int8_t SCLK, int8_
202202
red_bufsize = bw_bufsize;
203203
}
204204

205-
LOLIN_IL3897::LOLIN_IL3897(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY) : LOLIN_EPD(width, height, DC, RST, CS, BUSY)
205+
LOLIN_IL3897::LOLIN_IL3897(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY, SPIClass& spi) : LOLIN_EPD(width, height, DC, RST, CS, BUSY, spi)
206206
{
207207

208208
if ((height % 8) > 0)

lib/LOLIN_EPD/src/LOLIN_IL3897.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
class LOLIN_IL3897 : public LOLIN_EPD {
2121
public:
2222

23-
LOLIN_IL3897(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1);
24-
LOLIN_IL3897(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1);
23+
LOLIN_IL3897(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1, SPIClass& spi = SPI);
24+
LOLIN_IL3897(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1, SPIClass& spi = SPI);
2525

2626
void begin(bool reset=true);
2727

0 commit comments

Comments
 (0)