Skip to content

Commit b94e0ef

Browse files
authored
Merge pull request wled#2955 from ezcGman/i2c-build-flags
Add build flags for global i2c & SPI pins
2 parents e8a7802 + 00fed4f commit b94e0ef

File tree

2 files changed

+58
-16
lines changed

2 files changed

+58
-16
lines changed

wled00/const.h

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,41 @@
392392

393393
#define INTERFACE_UPDATE_COOLDOWN 2000 //time in ms to wait between websockets, alexa, and MQTT updates
394394

395+
// HW_PIN_SCL & HW_PIN_SDA are used for information in usermods settings page and usermods themselves
396+
// which GPIO pins are actually used in a hardwarea layout (controller board)
397+
#if defined(I2CSCLPIN) && !defined(HW_PIN_SCL)
398+
#define HW_PIN_SCL I2CSCLPIN
399+
#endif
400+
#if defined(I2CSDAPIN) && !defined(HW_PIN_SDA)
401+
#define HW_PIN_SDA I2CSDAPIN
402+
#endif
403+
// you cannot change HW I2C pins on 8266
395404
#if defined(ESP8266) && defined(HW_PIN_SCL)
396405
#undef HW_PIN_SCL
397406
#endif
398407
#if defined(ESP8266) && defined(HW_PIN_SDA)
399408
#undef HW_PIN_SDA
400409
#endif
410+
// defaults for 1st I2C on ESP32 (Wire global)
401411
#ifndef HW_PIN_SCL
402412
#define HW_PIN_SCL SCL
403413
#endif
404414
#ifndef HW_PIN_SDA
405415
#define HW_PIN_SDA SDA
406416
#endif
407417

418+
// HW_PIN_SCLKSPI & HW_PIN_MOSISPI & HW_PIN_MISOSPI are used for information in usermods settings page and usermods themselves
419+
// which GPIO pins are actually used in a hardwarea layout (controller board)
420+
#if defined(SPISCLKPIN) && !defined(HW_PIN_CLOCKSPI)
421+
#define HW_PIN_CLOCKSPI SPISCLKPIN
422+
#endif
423+
#if defined(SPIMOSIPIN) && !defined(HW_PIN_MOSISPI)
424+
#define HW_PIN_MOSISPI SPIMOSIPIN
425+
#endif
426+
#if defined(SPIMISOPIN) && !defined(HW_PIN_MISOSPI)
427+
#define HW_PIN_MISOSPI SPIMISOPIN
428+
#endif
429+
// you cannot change HW SPI pins on 8266
408430
#if defined(ESP8266) && defined(HW_PIN_CLOCKSPI)
409431
#undef HW_PIN_CLOCKSPI
410432
#endif
@@ -414,10 +436,7 @@
414436
#if defined(ESP8266) && defined(HW_PIN_MISOSPI)
415437
#undef HW_PIN_MISOSPI
416438
#endif
417-
#if defined(ESP8266) && defined(HW_PIN_CSSPI)
418-
#undef HW_PIN_CSSPI
419-
#endif
420-
// defaults for VSPI
439+
// defaults for VSPI on ESP32 (SPI global, SPI.cpp) as HSPI is used by WLED (bus_wrapper.h)
421440
#ifndef HW_PIN_CLOCKSPI
422441
#define HW_PIN_CLOCKSPI SCK
423442
#endif
@@ -427,8 +446,5 @@
427446
#ifndef HW_PIN_MISOSPI
428447
#define HW_PIN_MISOSPI MISO
429448
#endif
430-
#ifndef HW_PIN_CSSPI
431-
#define HW_PIN_CSSPI SS
432-
#endif
433449

434450
#endif

wled00/wled.h

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
#include "src/dependencies/dmx/ESPDMX.h"
131131
#else //ESP32
132132
#include "src/dependencies/dmx/SparkFunDMX.h"
133-
#endif
133+
#endif
134134
#endif
135135

136136
#include "src/dependencies/e131/ESPAsyncE131.h"
@@ -393,8 +393,8 @@ WLED_GLOBAL bool arlsForceMaxBri _INIT(false); // enable to f
393393
#ifdef ESP8266
394394
WLED_GLOBAL DMXESPSerial dmx;
395395
#else //ESP32
396-
WLED_GLOBAL SparkFunDMX dmx;
397-
#endif
396+
WLED_GLOBAL SparkFunDMX dmx;
397+
#endif
398398
WLED_GLOBAL uint16_t e131ProxyUniverse _INIT(0); // output this E1.31 (sACN) / ArtNet universe via MAX485 (0 = disabled)
399399
#endif
400400
WLED_GLOBAL uint16_t e131Universe _INIT(1); // settings for E1.31 (sACN) protocol (only DMX_MODE_MULTIPLE_* can span over consequtive universes)
@@ -578,7 +578,7 @@ WLED_GLOBAL int16_t currentPlaylist _INIT(-1);
578578
//still used for "PL=~" HTTP API command
579579
WLED_GLOBAL byte presetCycCurr _INIT(0);
580580
WLED_GLOBAL byte presetCycMin _INIT(1);
581-
WLED_GLOBAL byte presetCycMax _INIT(5);
581+
WLED_GLOBAL byte presetCycMax _INIT(5);
582582

583583
// realtime
584584
WLED_GLOBAL byte realtimeMode _INIT(REALTIME_MODE_INACTIVE);
@@ -676,11 +676,37 @@ WLED_GLOBAL uint16_t ledMaps _INIT(0); // bitfield representation of available l
676676
// Usermod manager
677677
WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager());
678678

679-
WLED_GLOBAL int8_t i2c_sda _INIT(-1); // global I2C SDA pin [HW_PIN_SDA] (used for usermods)
680-
WLED_GLOBAL int8_t i2c_scl _INIT(-1); // global I2C SCL pin [HW_PIN_SCL] (used for usermods)
681-
WLED_GLOBAL int8_t spi_mosi _INIT(-1); // global SPI DATA/MOSI pin [HW_PIN_DATASPI] (used for usermods)
682-
WLED_GLOBAL int8_t spi_miso _INIT(-1); // global SPI DATA/MISO pin [HW_PIN_MISOSPI] (used for usermods)
683-
WLED_GLOBAL int8_t spi_sclk _INIT(-1); // global SPI CLOCK/SCLK pin [HW_PIN_CLOCKSPI] (used for usermods)
679+
// global I2C SDA pin (used for usermods)
680+
#ifndef I2CSDAPIN
681+
WLED_GLOBAL int8_t i2c_sda _INIT(-1);
682+
#else
683+
WLED_GLOBAL int8_t i2c_sda _INIT(I2CSDAPIN);
684+
#endif
685+
// global I2C SCL pin (used for usermods)
686+
#ifndef I2CSCLPIN
687+
WLED_GLOBAL int8_t i2c_scl _INIT(-1);
688+
#else
689+
WLED_GLOBAL int8_t i2c_scl _INIT(I2CSCLPIN);
690+
#endif
691+
692+
// global SPI DATA/MOSI pin (used for usermods)
693+
#ifndef SPIMOSIPIN
694+
WLED_GLOBAL int8_t spi_mosi _INIT(-1);
695+
#else
696+
WLED_GLOBAL int8_t spi_mosi _INIT(SPIMOSIPIN);
697+
#endif
698+
// global SPI DATA/MISO pin (used for usermods)
699+
#ifndef SPIMISOPIN
700+
WLED_GLOBAL int8_t spi_miso _INIT(-1);
701+
#else
702+
WLED_GLOBAL int8_t spi_miso _INIT(SPIMISOPIN);
703+
#endif
704+
// global SPI CLOCK/SCLK pin (used for usermods)
705+
#ifndef SPISCLKPIN
706+
WLED_GLOBAL int8_t spi_sclk _INIT(-1);
707+
#else
708+
WLED_GLOBAL int8_t spi_sclk _INIT(SPISCLKPIN);
709+
#endif
684710

685711
// global ArduinoJson buffer
686712
WLED_GLOBAL StaticJsonDocument<JSON_BUFFER_SIZE> doc;

0 commit comments

Comments
 (0)