i2c_sda, i2c_scl, spi_mosi, spi_miso, spi_sclk without HW_PIN_*, bh1750

platformio: 
- add bh1750 to _max
- define rotary defaults for wemos

usermod_bh1750
- Remove HW_PIN_* and replace by i2c_sda etc
- add appendConfigData

usermods mpu6050_imu, rtc, 4ld, pinmanager
- Remove HW_PIN_* 

change SDA2:pin (etc) to SDA:pin
This commit is contained in:
Ewoud
2023-01-05 16:35:49 +01:00
parent 2ec24242db
commit 642d7d91ea
15 changed files with 75 additions and 75 deletions

View File

@@ -414,7 +414,7 @@ class Animated_Staircase : public Usermod {
}
void appendConfigData() {
oappend(SET_F("addInfo('staircase:help',0,'<button onclick=\"location.href=&quot;https://mm.kno.wled.ge/usermods/staircase&quot;\" type=\"button\">?</button>');")); // 0 is field type, 1 is actual field
oappend(SET_F("addInfo('staircase:help',0,'<button onclick=\"location.href=&quot;https://mm.kno.wled.ge/usermods/staircase&quot;\" type=\"button\">?</button>');"));
//oappend(SET_F("dd=addDropdown('staircase','selectfield');"));
//oappend(SET_F("addOption(dd,'1st value',0);"));

View File

@@ -55,17 +55,17 @@ private:
static const char _HomeAssistantDiscovery[];
// set the default pins based on the architecture, these get overridden by Usermod menu settings
#ifdef ARDUINO_ARCH_ESP32 // ESP32 boards -- WLEDMM: don't override already defined HW pins
#ifndef HW_PIN_SDA
#define HW_PIN_SCL 22
#endif
#ifndef HW_PIN_SDA
#define HW_PIN_SDA 21
#endif
#else // ESP8266 boards
#define HW_PIN_SCL 5
#define HW_PIN_SDA 4
#endif
// #ifdef ARDUINO_ARCH_ESP32 // ESP32 boards -- WLEDMM: don't override already defined HW pins
// #ifndef HW_PIN_SDA
// #define HW_PIN_SCL 22
// #endif
// #ifndef HW_PIN_SDA
// #define HW_PIN_SDA 21
// #endif
// #else // ESP8266 boards
// #define HW_PIN_SCL 5
// #define HW_PIN_SDA 4
// #endif
//int8_t ioPin[2] = {HW_PIN_SCL, HW_PIN_SDA}; // I2C pins: SCL, SDA...defaults to Arch hardware pins but overridden at setup()
int8_t ioPin[2] = {-1, -1}; // WLEDMM - I2C pins: wait until hw pins get allocated
bool initDone = false;
@@ -126,7 +126,7 @@ private:
public:
void setup()
{
bool HW_Pins_Used = (ioPin[0]==HW_PIN_SCL && ioPin[1]==HW_PIN_SDA); // note whether architecture-based hardware SCL/SDA pins used
bool HW_Pins_Used = (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda); // note whether architecture-based hardware SCL/SDA pins used
PinOwner po = PinOwner::UM_BH1750; // defaults to being pinowner for SCL/SDA pins
if (HW_Pins_Used) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins
if ((i2c_scl >= 0) && (i2c_sda >=0)) { // WLEDMM: make sure that global HW pins are used if defined
@@ -220,6 +220,14 @@ public:
}
}
void appendConfigData() {
oappend(SET_F("addInfo('BH1750:help',0,'<button onclick=\"location.href=&quot;https://mm.kno.wled.ge/usermods/BH1750&quot;\" type=\"button\">?</button>');"));
oappend(SET_F("addInfo('BH1750:pin[]',1,'','I2C SDA');"));
oappend(SET_F("rOption('BH1750:pin[]',1,'use global (")); oappendi(i2c_sda); oappend(")',-1);");
oappend(SET_F("addInfo('BH1750:pin[]',0,'','I2C SCL');"));
oappend(SET_F("rOption('BH1750:pin[]',0,'use global (")); oappendi(i2c_scl); oappend(")',-1);");
}
// (called from set.cpp) stores persistent properties to cfg.json
void addToConfig(JsonObject &root)
{
@@ -232,7 +240,7 @@ public:
top[FPSTR(_offset)] = offset;
JsonArray io_pin = top.createNestedArray(F("pin"));
for (byte i=0; i<2; i++) io_pin.add(ioPin[i]);
top[F("help4Pins")] = F("SCL,SDA"); // help for Settings page
// top[F("help4Pins")] = F("SCL,SDA"); // help for Settings page
DEBUG_PRINTLN(F("BH1750 config saved."));
}
@@ -272,7 +280,7 @@ public:
for (byte i=0; i<2; i++) if (ioPin[i] != newPin[i]) { pinsChanged = true; break; } // check if any pins changed
if (pinsChanged) { //if pins changed, deallocate old pins and allocate new ones
PinOwner po = PinOwner::UM_BH1750;
if (ioPin[0]==HW_PIN_SCL && ioPin[1]==HW_PIN_SDA) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins
if (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins
pinManager.deallocateMultiplePins((const uint8_t *)ioPin, 2, po); // deallocate pins
for (byte i=0; i<2; i++) ioPin[i] = newPin[i];
setup();

View File

@@ -414,7 +414,7 @@ public:
void appendConfigData()
{
oappend(SET_F("addInfo('PIRsensorSwitch:help',0,'<button onclick=\"location.href=&quot;https://mm.kno.wled.ge/usermods/PIRsensorSwitch&quot;\" type=\"button\">?</button>');")); // 0 is field type, 1 is actual field
oappend(SET_F("addInfo('PIRsensorSwitch:help',0,'<button onclick=\"location.href=&quot;https://mm.kno.wled.ge/usermods/PIRsensorSwitch&quot;\" type=\"button\">?</button>');"));
oappend(SET_F("addInfo('PIRsensorSwitch:HA-discovery',1,'HA=Home Assistant');")); // 0 is field type, 1 is actual field
oappend(SET_F("addInfo('PIRsensorSwitch:notifications',1,'Periodic WS updates');")); // 0 is field type, 1 is actual field

View File

@@ -16,10 +16,6 @@ class RTCUsermod : public Usermod {
void setup() {
PinManagerPinType pins[2] = { { i2c_scl, true }, { i2c_sda, true } };
#if defined(ARDUINO_ARCH_ESP32) && defined(HW_PIN_SDA) && defined(HW_PIN_SCL)
//if (pins[0].pin < 0) pins[0].pin = HW_PIN_SCL; //WLEDMM
//if (pins[1].pin < 0) pins[1].pin = HW_PIN_SDA; //WLEDMM
#endif
if (pins[1].pin < 0 || pins[0].pin < 0) { disabled=true; return; } //WLEDMM bugfix - ensure that "final" GPIO are valid and no "-1" sneaks trough
if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { disabled = true; return; }
#if defined(ARDUINO_ARCH_ESP32)

View File

@@ -1968,7 +1968,7 @@ class AudioReactive : public Usermod {
void appendConfigData()
{
oappend(SET_F("addInfo('AudioReactive:help',0,'<button onclick=\"location.href=&quot;https://mm.kno.wled.ge/soundreactive/Sound-Settings&quot;\" type=\"button\">?</button>');")); // 0 is field type, 1 is actual field
oappend(SET_F("addInfo('AudioReactive:help',0,'<button onclick=\"location.href=&quot;https://mm.kno.wled.ge/soundreactive/Sound-Settings&quot;\" type=\"button\">?</button>');"));
//WLEDMM: add defaults
#ifdef AUDIOPIN

View File

@@ -303,7 +303,7 @@ class BobLightUsermod : public Usermod {
}
void appendConfigData() {
oappend(SET_F("addInfo('BobLight:help',0,'<button onclick=\"location.href=&quot;https://mm.kno.wled.ge/usermods/BobLight&quot;\" type=\"button\">?</button>');")); // 0 is field type, 1 is actual field
oappend(SET_F("addInfo('BobLight:help',0,'<button onclick=\"location.href=&quot;https://mm.kno.wled.ge/usermods/BobLight&quot;\" type=\"button\">?</button>');"));
//oappend(SET_F("dd=addDropdown('usermod','selectfield');"));
//oappend(SET_F("addOption(dd,'1st value',0);"));

View File

@@ -119,13 +119,8 @@ class MPU6050Driver : public Usermod {
void setup() {
// WLEDMM begin
USER_PRINTLN(F("mpu setup"));
#if 0 // WLEDMM: delay I2C pin alloc
int8_t hw_scl = i2c_scl<0 ? HW_PIN_SCL : i2c_scl;
int8_t hw_sda = i2c_sda<0 ? HW_PIN_SDA : i2c_sda;
#else
int8_t hw_scl = i2c_scl;
int8_t hw_sda = i2c_sda;
#endif
PinManagerPinType pins[2] = { { hw_scl, true }, { hw_sda, true } };
if ((hw_scl < 0) || (hw_sda < 0)) {

View File

@@ -321,8 +321,8 @@ class FourLineDisplayUsermod : public Usermod {
bool isHW, isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64);
PinOwner po = PinOwner::UM_FourLineDisplay;
if (isSPI) {
int8_t hw_sclk = spi_sclk<0 ? HW_PIN_CLOCKSPI : spi_sclk;
int8_t hw_mosi = spi_mosi<0 ? HW_PIN_DATASPI : spi_mosi;
int8_t hw_sclk = spi_sclk;
int8_t hw_mosi = spi_mosi;
if (ioPin[0] < 0 || ioPin[1] < 0) {
ioPin[0] = hw_sclk;
ioPin[1] = hw_mosi;
@@ -338,8 +338,8 @@ class FourLineDisplayUsermod : public Usermod {
return;
}
} else {
int8_t hw_scl = i2c_scl<0 ? HW_PIN_SCL : i2c_scl;
int8_t hw_sda = i2c_sda<0 ? HW_PIN_SDA : i2c_sda;
int8_t hw_scl = i2c_scl;
int8_t hw_sda = i2c_sda;
if (ioPin[0] < 0 || ioPin[1] < 0) {
ioPin[0] = hw_scl;
ioPin[1] = hw_sda;
@@ -1036,7 +1036,7 @@ class FourLineDisplayUsermod : public Usermod {
//}
void appendConfigData() {
oappend(SET_F("addInfo('4LineDisplay:help',0,'<button onclick=\"location.href=&quot;https://mm.kno.wled.ge/usermods/4LineDisplay&quot;\" type=\"button\">?</button>');")); // 0 is field type, 1 is actual field
oappend(SET_F("addInfo('4LineDisplay:help',0,'<button onclick=\"location.href=&quot;https://mm.kno.wled.ge/usermods/4LineDisplay&quot;\" type=\"button\">?</button>');"));
oappend(SET_F("dd=addDropdown('4LineDisplay','type');"));
oappend(SET_F("addOption(dd,'None',0);"));
@@ -1081,11 +1081,11 @@ class FourLineDisplayUsermod : public Usermod {
// determine if we are using global HW pins (data & clock)
int8_t hw_dta, hw_clk;
if ((type == SSD1306_SPI || type == SSD1306_SPI64)) {
hw_clk = spi_sclk<0 ? HW_PIN_CLOCKSPI : spi_sclk;
hw_dta = spi_mosi<0 ? HW_PIN_DATASPI : spi_mosi;
hw_clk = spi_sclk;
hw_dta = spi_mosi;
} else {
hw_clk = i2c_scl<0 ? HW_PIN_SCL : i2c_scl;
hw_dta = i2c_sda<0 ? HW_PIN_SDA : i2c_sda;
hw_clk = i2c_scl;
hw_dta = i2c_sda;
}
JsonObject top = root.createNestedObject(FPSTR(_name));
@@ -1167,13 +1167,13 @@ class FourLineDisplayUsermod : public Usermod {
bool isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64);
if (isSPI) {
pinManager.deallocateMultiplePins((const uint8_t *)(&oldPin[2]), 3, po);
uint8_t hw_sclk = spi_sclk<0 ? HW_PIN_CLOCKSPI : spi_sclk;
uint8_t hw_mosi = spi_mosi<0 ? HW_PIN_DATASPI : spi_mosi;
uint8_t hw_sclk = spi_sclk;
uint8_t hw_mosi = spi_mosi;
bool isHW = (oldPin[0]==hw_sclk && oldPin[1]==hw_mosi);
if (isHW) po = PinOwner::HW_SPI;
} else {
uint8_t hw_scl = i2c_scl<0 ? HW_PIN_SCL : i2c_scl;
uint8_t hw_sda = i2c_sda<0 ? HW_PIN_SDA : i2c_sda;
uint8_t hw_scl = i2c_scl;
uint8_t hw_sda = i2c_sda;
bool isHW = (oldPin[0]==hw_scl && oldPin[1]==hw_sda);
if (isHW) po = PinOwner::HW_I2C;
}

View File

@@ -868,7 +868,7 @@ public:
//WLEDMM: add appendConfigData
void appendConfigData()
{
oappend(SET_F("addInfo('Rotary-Encoder:help',0,'<button onclick=\"location.href=&quot;https://mm.kno.wled.ge/usermods/Rotary-Encoder&quot;\" type=\"button\">?</button>');")); // 0 is field type, 1 is actual field
oappend(SET_F("addInfo('Rotary-Encoder:help',0,'<button onclick=\"location.href=&quot;https://mm.kno.wled.ge/usermods/Rotary-Encoder&quot;\" type=\"button\">?</button>');"));
#ifdef ENCODER_DT_PIN
oappend(SET_F("xOption('Rotary-Encoder:DT-pin',1,' ⎌',")); oappendi(ENCODER_DT_PIN); oappend(");");
#endif

View File

@@ -317,7 +317,7 @@ class WeatherUsermod : public Usermod {
void appendConfigData()
{
oappend(SET_F("addInfo('Weather:help',0,'<button onclick=\"location.href=&quot;https://mm.kno.wled.ge/moonmodules/Weather&quot;\" type=\"button\">?</button>');")); // 0 is field type, 1 is actual field
oappend(SET_F("addInfo('Weather:help',0,'<button onclick=\"location.href=&quot;https://mm.kno.wled.ge/moonmodules/Weather&quot;\" type=\"button\">?</button>');"));
oappend(SET_F("dd=addDropdown('Weather','units');"));
oappend(SET_F("addOption(dd,'Kelvin',0);"));