four-line-display: make SPI work again

This commit is contained in:
Frank
2023-03-26 14:00:16 +02:00
parent 762c639fc8
commit 361a3b1cb3
2 changed files with 13 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
#include <Arduino.h> // WLEDMM: make sure that I2C drivers have the "right" Wire Object #include <Arduino.h> // WLEDMM: make sure that I2C drivers have the "right" Wire Object
#include <Wire.h> #include <Wire.h>
#include <SPI.h>
#undef U8X8_NO_HW_I2C // WLEDMM: we do want I2C hardware drivers - if possible #undef U8X8_NO_HW_I2C // WLEDMM: we do want I2C hardware drivers - if possible
//#define WIRE_INTERFACES_COUNT 2 // experimental - tell U8x8Lib that there is a second Wire unit //#define WIRE_INTERFACES_COUNT 2 // experimental - tell U8x8Lib that there is a second Wire unit
@@ -427,6 +428,7 @@ class FourLineDisplayUsermod : public Usermod {
isHW = (ioPin[0]==spi_sclk && ioPin[1]==spi_mosi); isHW = (ioPin[0]==spi_sclk && ioPin[1]==spi_mosi);
if ((ioPin[0] == -1) || (ioPin[1] == -1)) isHW = true; // WLEDMM "use global" = hardware if ((ioPin[0] == -1) || (ioPin[1] == -1)) isHW = true; // WLEDMM "use global" = hardware
if ((spi_sclk <0) || (spi_mosi < 0)) isHW = false; // no global pins - use software emulation
PinManagerPinType cspins[3] = { { ioPin[2], true }, { ioPin[3], true }, { ioPin[4], true } }; PinManagerPinType cspins[3] = { { ioPin[2], true }, { ioPin[3], true }, { ioPin[4], true } };
if (!pinManager.allocateMultiplePins(cspins, 3, PinOwner::UM_FourLineDisplay)) { typeOK=false; strcpy(errorMessage, PSTR("SPI3 alloc pins failed")); return; } if (!pinManager.allocateMultiplePins(cspins, 3, PinOwner::UM_FourLineDisplay)) { typeOK=false; strcpy(errorMessage, PSTR("SPI3 alloc pins failed")); return; }
if (isHW) po = PinOwner::HW_SPI; // allow multiple allocations of HW I2C bus pins if (isHW) po = PinOwner::HW_SPI; // allow multiple allocations of HW I2C bus pins
@@ -437,6 +439,13 @@ class FourLineDisplayUsermod : public Usermod {
strcpy(errorMessage, PSTR("SPI2 alloc pins failed")); strcpy(errorMessage, PSTR("SPI2 alloc pins failed"));
return; return;
} }
// start SPI now!
#ifdef ARDUINO_ARCH_ESP32
if (isHW) SPI.begin(spi_sclk, spi_miso, spi_mosi); // ESP32 - will silently fail if SPI alread active.
#else
if (isHW) SPI.begin(); // ESP8266 - SPI pins are fixed
#endif
} else { } else {
//if (ioPin[0] < 0 || ioPin[1] < 0) { //WLEDMM do _not_ copy global pins !! //if (ioPin[0] < 0 || ioPin[1] < 0) { //WLEDMM do _not_ copy global pins !!
// ioPin[0] = i2c_scl; // ioPin[0] = i2c_scl;
@@ -1396,6 +1405,8 @@ class FourLineDisplayUsermod : public Usermod {
if (isSPI) { if (isSPI) {
pinManager.deallocateMultiplePins((const uint8_t *)(&oldPin[2]), 3, po); pinManager.deallocateMultiplePins((const uint8_t *)(&oldPin[2]), 3, po);
bool isHW = (oldPin[0]==spi_sclk && oldPin[1]==spi_mosi); bool isHW = (oldPin[0]==spi_sclk && oldPin[1]==spi_mosi);
if (oldPin[0]==-1 && oldPin[1]==-1) isHW = true; // WLEDMM "use global" means hardware driver
if (spi_sclk==-1 && spi_mosi==-1) isHW = false; // WLEDMM global pins not set -> software driver
if (isHW) po = PinOwner::HW_SPI; if (isHW) po = PinOwner::HW_SPI;
} else { } else {
//bool isHW = (oldPin[0]==i2c_scl && oldPin[1]==i2c_sda); //bool isHW = (oldPin[0]==i2c_scl && oldPin[1]==i2c_sda);

View File

@@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2303250 #define VERSION 2303260
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG