Skip to content

Commit 96d5c03

Browse files
author
Louis Beaudoin
committed
bus_wrapper improvements for SPI output
- Identifying ESP32 hardware SPI by pin number is broken and flawed, replace with temporary hack instead until a better method of assigned resources can be devised - NeoPixelBus doesn't support HSPI, only VSPI right now, so matching HSPI pins to enable a non-existent VSPI driver is broken - ESP32 SPI peripherals can use alternate pins, so choosing to use hardware SPI only on the default pins is flawed - Specify pins during Begin() call to allow for alternate pins and avoid driving the chip select signal - Dotstar Software/Hardware output tested on ESP32, other SPI protocols and ESP8266 support was not tested
1 parent 3a03bc4 commit 96d5c03

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

wled00/bus_manager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class BusDigital : public Bus {
122122
//Fix for turning off onboard LED breaking bus
123123
#ifdef LED_BUILTIN
124124
if (_bri == 0 && b > 0) {
125-
if (_pins[0] == LED_BUILTIN || _pins[1] == LED_BUILTIN) PolyBus::begin(_busPtr, _iType);
125+
if (_pins[0] == LED_BUILTIN || _pins[1] == LED_BUILTIN) PolyBus::begin(_busPtr, _iType, _pins);
126126
}
127127
#endif
128128
_bri = b;
@@ -159,7 +159,7 @@ class BusDigital : public Bus {
159159
}
160160

161161
void reinit() {
162-
PolyBus::begin(_busPtr, _iType);
162+
PolyBus::begin(_busPtr, _iType, _pins);
163163
}
164164

165165
void cleanup() {

wled00/bus_wrapper.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
//handles pointer type conversion for all possible bus types
192192
class PolyBus {
193193
public:
194-
static void begin(void* busPtr, uint8_t busType) {
194+
static void begin(void* busPtr, uint8_t busType, uint8_t* pins) {
195195
switch (busType) {
196196
case I_NONE: break;
197197
#ifdef ESP8266
@@ -211,6 +211,10 @@ class PolyBus {
211211
case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->Begin(); break;
212212
case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->Begin(); break;
213213
case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->Begin(); break;
214+
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Begin(); break;
215+
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->Begin(); break;
216+
case I_HS_WS1_3: (static_cast<B_HS_WS1_3*>(busPtr))->Begin(); break;
217+
case I_HS_P98_3: (static_cast<B_HS_P98_3*>(busPtr))->Begin(); break;
214218
#endif
215219
#ifdef ARDUINO_ARCH_ESP32
216220
case I_32_R0_NEO_3: (static_cast<B_32_R0_NEO_3*>(busPtr))->Begin(); break;
@@ -253,14 +257,15 @@ class PolyBus {
253257
case I_32_R7_TM1_4: (static_cast<B_32_R7_TM1_4*>(busPtr))->Begin(); break;
254258
case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->Begin(); break;
255259
case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->Begin(); break;
260+
// ESP32 can (and should, to avoid inadvertantly driving the chip select signal) specify the pins used for SPI, but only in begin()
261+
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Begin(pins[1], -1, pins[0], -1); break;
262+
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->Begin(pins[1], -1, pins[0], -1); break;
263+
case I_HS_WS1_3: (static_cast<B_HS_WS1_3*>(busPtr))->Begin(pins[1], -1, pins[0], -1); break;
264+
case I_HS_P98_3: (static_cast<B_HS_P98_3*>(busPtr))->Begin(pins[1], -1, pins[0], -1); break;
256265
#endif
257-
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Begin(); break;
258266
case I_SS_DOT_3: (static_cast<B_SS_DOT_3*>(busPtr))->Begin(); break;
259-
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->Begin(); break;
260267
case I_SS_LPD_3: (static_cast<B_SS_LPD_3*>(busPtr))->Begin(); break;
261-
case I_HS_WS1_3: (static_cast<B_HS_WS1_3*>(busPtr))->Begin(); break;
262268
case I_SS_WS1_3: (static_cast<B_SS_WS1_3*>(busPtr))->Begin(); break;
263-
case I_HS_P98_3: (static_cast<B_HS_P98_3*>(busPtr))->Begin(); break;
264269
case I_SS_P98_3: (static_cast<B_SS_P98_3*>(busPtr))->Begin(); break;
265270
}
266271
};
@@ -338,7 +343,7 @@ class PolyBus {
338343
case I_HS_P98_3: busPtr = new B_HS_P98_3(len, pins[1], pins[0]); break;
339344
case I_SS_P98_3: busPtr = new B_SS_P98_3(len, pins[1], pins[0]); break;
340345
}
341-
begin(busPtr, busType);
346+
begin(busPtr, busType, pins);
342347
return busPtr;
343348
};
344349
static void show(void* busPtr, uint8_t busType) {
@@ -831,8 +836,7 @@ class PolyBus {
831836
#ifdef ESP8266
832837
if (pins[0] == P_8266_HS_MOSI && pins[1] == P_8266_HS_CLK) isHSPI = true;
833838
#else
834-
if (pins[0] == P_32_HS_MOSI && pins[1] == P_32_HS_CLK) isHSPI = true;
835-
if (pins[0] == P_32_VS_MOSI && pins[1] == P_32_VS_CLK) isHSPI = true;
839+
if(!num) isHSPI = true; // temporary hack to limit use of hardware SPI to a single SPI peripheral: only allow ESP32 hardware serial on segment 0
836840
#endif
837841
uint8_t t = I_NONE;
838842
switch (busType) {

0 commit comments

Comments
 (0)