Skip to content

Commit fee6969

Browse files
committed
Dig Uno setup, ethernet pins as variables
Back end ======== - Ethernet: compiler directives to variables , explicitly for CONFIG_IDF_TARGET_ESP32S3 - Devices: add delete option - IO: add SPI pins, add readPins (for ethernet), add jumper1 (switch IR / ethernet for SE16), setup dig uno - Node manager: on default on
1 parent 41fea14 commit fee6969

File tree

7 files changed

+115
-53
lines changed

7 files changed

+115
-53
lines changed

lib/framework/ESP32SvelteKit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void ESP32SvelteKit::begin()
8181
_wifiSettingsService.initWiFi();
8282

8383
// SvelteKit uses a lot of handlers, so we need to increase the max_uri_handlers
84-
// WWWData has 77 Endpoints, Framework has 27, and Lighstate Demo has 4
84+
// WWWData has 77->27!! Endpoints, Framework has 27, and each module has 4 // 🌙 updated numbers
8585
_server->config.max_uri_handlers = _numberEndpoints;
8686
_server->listen(80);
8787

lib/framework/EthernetSettingsService.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,17 @@ void EthernetSettingsService::configureNetwork(ethernet_settings_t &network)
8383
ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
8484
}
8585
// (re)start ethernet
86-
#if CONFIG_IDF_TARGET_ESP32
86+
// 🌙 compiler directives to variables
87+
#if CONFIG_IDF_TARGET_ESP32S3
88+
if (v_ETH_SPI_SCK != UINT8_MAX) {
89+
// For SPI based ethernet modules like W5500, ENC28J60 etc.
90+
SPI.begin(v_ETH_SPI_SCK, v_ETH_SPI_MISO, v_ETH_SPI_MOSI);
91+
ETH.begin(v_ETH_PHY_TYPE, v_ETH_PHY_ADDR, v_ETH_PHY_CS, v_ETH_PHY_IRQ, v_ETH_PHY_RST, SPI);
92+
}
93+
#elif CONFIG_IDF_TARGET_ESP32P4 // 🌙 todo: setup in P4
94+
#else // CONFIG_IDF_TARGET_ESP32, what about S2/C3 ...
8795
// ESP32 chips with built-in ethernet MAC/PHY
8896
ETH.begin();
89-
#elif CONFIG_IDF_TARGET_ESP32P4
90-
// todo: setup in P4
91-
#else
92-
#ifdef ETH_PHY_TYPE //only if defined
93-
// For SPI based ethernet modules like W5500, ENC28J60 etc.
94-
SPI.begin(ETH_SPI_SCK, ETH_SPI_MISO, ETH_SPI_MOSI);
95-
ETH.begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_CS, ETH_PHY_IRQ, ETH_PHY_RST, SPI);
96-
#endif
9797
#endif
9898
// set hostname (again) after (re)starting ethernet due to a bug in the ESP-IDF implementation
9999
ETH.setHostname(_state.hostname.c_str());

lib/framework/EthernetSettingsService.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#define ETHERNET_EVENT_DELAY 500
3535

36-
#define ETHERNET_SETTINGS_FILE "/.config/ethernetSettings.json"
36+
#define ETHERNET_SETTINGS_FILE "/.config/ethernetSettings.json" // 🌙 MoonLight uses .config (hidden)
3737
#define ETHERNET_SETTINGS_SERVICE_PATH "/rest/ethernetSettings"
3838

3939
#define EVENT_ETHERNET "ethernet"
@@ -110,6 +110,19 @@ class EthernetSettingsService : public StatefulService<EthernetSettings>
110110
String getHostname();
111111
String getIP();
112112

113+
// 🌙 compiler directives to variables
114+
#if CONFIG_IDF_TARGET_ESP32S3
115+
uint8_t v_ETH_SPI_SCK = UINT8_MAX; //42; v_ETH_SPI_SCK is check if configured, see configureNetwork and ModuleIO
116+
uint8_t v_ETH_SPI_MISO = 44;
117+
uint8_t v_ETH_SPI_MOSI = 43;
118+
119+
eth_phy_type_t v_ETH_PHY_TYPE = ETH_PHY_W5500; //currently only one supported for S3 ...
120+
int32_t v_ETH_PHY_ADDR = 1;
121+
int v_ETH_PHY_CS = 41;
122+
int v_ETH_PHY_IRQ = 2; // -1 if you won't wire
123+
int v_ETH_PHY_RST = 1; // -1 if you won't wire
124+
#endif
125+
113126
private:
114127
PsychicHttpServer *_server;
115128
SecurityManager *_securityManager;

src/MoonBase/Modules/ModuleDevices.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ class ModuleDevices : public Module {
3333
void setupDefinition(const JsonArray& controls) override {
3434
EXT_LOGV(MB_TAG, "");
3535
JsonObject control; // state.data has one or more properties
36-
JsonArray rows; // if a control is an array, this is the rows of the array
36+
JsonArray rows; // if a control is an array, this is the rows of the array
3737

3838
control = addControl(controls, "devices", "rows");
3939
control["filter"] = "";
40-
control["crud"] = "r";
40+
control["crud"] = "rd"; // delete old devices
4141
rows = control["n"].to<JsonArray>();
4242
{
4343
addControl(rows, "name", "mdnsName", 0, 32, true);

src/MoonBase/Modules/ModuleIO.h

Lines changed: 85 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
**/
1111

1212
#ifndef ModuleIO_h
13-
#define ModuleIO_h
13+
#define ModuleIO_h
1414

15-
#if FT_MOONBASE == 1
15+
#if FT_MOONBASE == 1
1616

17-
#include "MoonBase/Module.h"
17+
#include "MoonBase/Module.h"
1818

1919
enum IO_PinUsage {
2020
pin_Unused, // 0
@@ -74,6 +74,11 @@ enum IO_PinUsage {
7474
pin_Reserved,
7575
pin_Ethernet,
7676
pin_Button_OnOff,
77+
pin_SPI_SCK,
78+
pin_SPI_MISO,
79+
pin_SPI_MOSI,
80+
pin_PHY_CS,
81+
pin_PHY_IRQ,
7782
pin_count
7883
};
7984

@@ -105,12 +110,14 @@ class ModuleIO : public Module {
105110
// #if CONFIG_IDF_TARGET_ESP32
106111
// pinMode(19, OUTPUT); digitalWrite(19, HIGH); // for serg shield boards: to be done: move to new pin manager module, switch off for S3!!!! tbd: add pin manager
107112
// #endif
113+
114+
addUpdateHandler([&](const String& originId) { readPins(sveltekit); }, false);
108115
}
109116

110117
void setupDefinition(const JsonArray& controls) override {
111118
EXT_LOGV(MB_TAG, "");
112119
JsonObject control; // state.data has one or more controls
113-
JsonArray rows; // if a control is an array, this is the rows of the array
120+
JsonArray rows; // if a control is an array, this is the rows of the array
114121

115122
control = addControl(controls, "boardPreset", "select");
116123
control["default"] = 0;
@@ -137,6 +144,8 @@ class ModuleIO : public Module {
137144
control = addControl(controls, "maxPower", "number", 0, 500, false, "Watt");
138145
control["default"] = 10;
139146

147+
control = addControl(controls, "jumper1", "checkbox");
148+
140149
control = addControl(controls, "pins", "rows");
141150
control["filter"] = "!Unused";
142151
control["crud"] = "ru";
@@ -204,6 +213,11 @@ class ModuleIO : public Module {
204213
addControlValue(control, "Reserved");
205214
addControlValue(control, "Ethernet");
206215
addControlValue(control, "Button On/Off");
216+
addControlValue(control, "SPI_SCK");
217+
addControlValue(control, "SPI_MISO");
218+
addControlValue(control, "SPI_MOSI");
219+
addControlValue(control, "PHY_CS");
220+
addControlValue(control, "PHY_IRQ");
207221

208222
addControl(rows, "summary", "text", 0, 32, true); // ro
209223
// addControl(rows, "Valid", "checkbox", false, true, true);
@@ -241,11 +255,11 @@ class ModuleIO : public Module {
241255

242256
// For RTC GPIOs, can also use RTC-specific read
243257
int rtc_level = -1;
244-
#ifndef CONFIG_IDF_TARGET_ESP32C3
258+
#ifndef CONFIG_IDF_TARGET_ESP32C3
245259
if (is_rtc_gpio) {
246260
rtc_level = rtc_gpio_get_level((gpio_num_t)gpio_num); // to do find c3 alternative
247261
}
248-
#endif
262+
#endif
249263

250264
// Get drive capability (if output capable)
251265
gpio_drive_cap_t drive_cap = GPIO_DRIVE_CAP_DEFAULT;
@@ -275,18 +289,35 @@ class ModuleIO : public Module {
275289
pins[46]["usage"] = pin_Button_OnOff;
276290
pins[8]["usage"] = pin_Voltage;
277291
pins[9]["usage"] = pin_Current;
278-
pins[5]["usage"] = pin_Infrared;
292+
293+
if (_state.data["jumper1"]) {
294+
pins[5]["usage"] = pin_Infrared;
295+
} else {
296+
pins[5]["usage"] = pin_SPI_MISO;
297+
pins[6]["usage"] = pin_SPI_MOSI;
298+
pins[7]["usage"] = pin_SPI_SCK;
299+
pins[15]["usage"] = pin_PHY_CS;
300+
pins[18]["usage"] = pin_PHY_IRQ;
301+
}
302+
279303
} else if (boardID == board_QuinLEDDigUnoV3) {
280-
object["maxPower"] = 75;
281-
pins[0]["usage"] = pin_Button_01;
282-
pins[1]["usage"] = pin_LED_01;
304+
// Dig-Uno-V3
305+
// esp32-d0 (4MB)
306+
// erase flash first
307+
// Lolin Wifi fix no -> add as board preset
308+
// you might need to reset your router if you first run WLED on the same MCU
309+
// remove fuse then flash, Nice !!!
310+
object["maxPower"] = 50; // max 75, but 10A fuse
311+
pins[16]["usage"] = pin_LED_01;
283312
pins[3]["usage"] = pin_LED_02;
284-
pins[2]["usage"] = pin_I2S_SD;
285-
pins[12]["usage"] = pin_I2S_WS;
286-
pins[13]["usage"] = pin_Temperature;
287-
pins[15]["usage"] = pin_I2S_SCK;
288-
pins[16]["usage"] = pin_LED_03;
289-
pins[32]["usage"] = pin_Exposed;
313+
pins[0]["usage"] = pin_Button_01;
314+
pins[15]["usage"] = pin_Relay;
315+
// pins[2]["usage"] = pin_I2S_SD;
316+
// pins[12]["usage"] = pin_I2S_WS;
317+
// pins[13]["usage"] = pin_Temperature;
318+
// pins[15]["usage"] = pin_I2S_SCK;
319+
// pins[16]["usage"] = pin_LED_03;
320+
// pins[32]["usage"] = pin_Exposed;
290321
} else if (boardID == board_QuinLEDDigQuadV3) {
291322
object["maxPower"] = 150;
292323
uint8_t ledPins[4] = {16, 3, 1, 4}; // LED_PINS
@@ -438,32 +469,49 @@ class ModuleIO : public Module {
438469
void loop() override {
439470
// run in sveltekit task
440471
Module::loop();
472+
441473
if (newBoardID != UINT8_MAX) {
442474
setBoardPresetDefaults(newBoardID); // run from sveltekit task
443475
newBoardID = UINT8_MAX;
444476
}
445477
}
446-
};
447478

479+
void readPins(ESP32SvelteKit* sveltekit) {
480+
EXT_LOGD(MB_TAG, "Try to configure ethernet");
481+
EthernetSettingsService* ess = sveltekit->getEthernetSettingsService();
482+
if ((uintptr_t)ess < 0x3FC00000) {
483+
EXT_LOGW(MB_TAG, "EthernetSettingsService not available");
484+
EXT_LOGW(MB_TAG, "ESS PTR = %p\n", (void*)ess);
485+
return;
486+
}
487+
#if CONFIG_IDF_TARGET_ESP32S3
488+
ess->v_ETH_SPI_SCK = UINT8_MAX;
489+
ess->v_ETH_SPI_MISO = UINT8_MAX;
490+
ess->v_ETH_SPI_MOSI = UINT8_MAX;
491+
ess->v_ETH_PHY_CS = UINT8_MAX;
492+
ess->v_ETH_PHY_IRQ = UINT8_MAX;
493+
// if ethernet pins change
494+
// find the pins needed
495+
for (JsonObject pinObject : _state.data["pins"].as<JsonArray>()) {
496+
uint8_t usage = pinObject["usage"];
497+
uint8_t gpio = pinObject["GPIO"];
498+
if (usage == pin_SPI_SCK) ess->v_ETH_SPI_SCK = gpio;
499+
if (usage == pin_SPI_MISO) ess->v_ETH_SPI_MISO = gpio;
500+
if (usage == pin_SPI_MOSI) ess->v_ETH_SPI_MOSI = gpio;
501+
if (usage == pin_PHY_CS) ess->v_ETH_PHY_CS = gpio;
502+
if (usage == pin_PHY_IRQ) ess->v_ETH_PHY_IRQ = gpio;
503+
}
504+
505+
// allocate the pins found
506+
if (ess->v_ETH_SPI_SCK != UINT8_MAX && ess->v_ETH_SPI_MISO != UINT8_MAX && ess->v_ETH_SPI_MOSI != UINT8_MAX && ess->v_ETH_PHY_CS != UINT8_MAX && ess->v_ETH_PHY_IRQ != UINT8_MAX) {
507+
// ess->v_ETH_PHY_TYPE = ETH_PHY_W5500;
508+
// ess->v_ETH_PHY_ADDR = 1;
509+
ess->v_ETH_PHY_RST = -1; // not wired
510+
ess->initEthernet(); // restart ethernet
511+
}
448512
#endif
449-
#endif
513+
}
514+
};
450515

451-
// format:
452-
// {
453-
// "pins": [
454-
// {
455-
// "GPIO": 0,
456-
// "Valid": true,
457-
// "Output": true,
458-
// "RTC": true,
459-
// "Level": "HIGH",
460-
// "DriveCap": "MEDIUM",
461-
// },
462-
// {
463-
// "GPIO": 1,
464-
// "Valid": true,
465-
// "Output": true,
466-
// "RTC": false,
467-
// "Level": "HIGH",
468-
// "DriveCap": "MEDIUM",
469-
// },
516+
#endif
517+
#endif

src/MoonBase/NodeManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ class NodeManager : public Module {
9393
// values = control["values"].to<JsonArray>();
9494
addNodes(control);
9595

96-
addControl(rows, "on", "checkbox");
96+
control = addControl(rows, "on", "checkbox");
97+
control["default"] = true;
9798
control = addControl(rows, "controls", "controls");
9899
rows = control["n"].to<JsonArray>();
99100
{

src/MoonLight/Layers/VirtualLayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ void VirtualLayer::drawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, CRGB
369369
if (depth < 2) {
370370
x1 = x0;
371371
y1 = y0;
372-
} // single pixel
372+
} // single pixel
373373
else { // shorten line
374374
x0 *= 2;
375375
y0 *= 2; // we do everything "*2" for better rounding
@@ -450,7 +450,7 @@ void VirtualLayer::drawLine3D(uint8_t x1, uint8_t y1, uint8_t z1, uint8_t x2, ui
450450
x2 = x1;
451451
y2 = y1;
452452
z2 = z1;
453-
} // single pixel
453+
} // single pixel
454454
else { // shorten line
455455
x1 *= 2;
456456
y1 *= 2;

0 commit comments

Comments
 (0)