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
1919enum 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
0 commit comments