Move dmx_input pin allocations from wled.cpp to dmx.cpp

This commit is contained in:
Arne 2023-08-14 13:58:22 +02:00 committed by Will Tatam
parent 9e2268bd74
commit a0ca243955
5 changed files with 36 additions and 14 deletions

View File

@ -88,9 +88,25 @@ bool dmxInputInitialized = false; //true once initDmx finished successfully
void initDMX() {
if(dmxInputReceivePin > 0 && dmxInputEnablePin > 0 && dmxInputTransmitPin > 0)
{
const managed_pin_type pins[] = {
{dmxInputTransmitPin, false}, //these are not used as gpio pins, this isOutput is always false.
{dmxInputReceivePin, false},
{dmxInputEnablePin, false}
};
const bool pinsAllocated = pinManager.allocateMultiplePins(pins, 3, PinOwner::DMX_INPUT);
if(!pinsAllocated)
{
USER_PRINTF("Error: Failed to allocate pins for DMX_INPUT. Pins already in use:\n");
USER_PRINTF("rx in use by: %s\n", pinManager.getPinOwnerText(dmxInputReceivePin).c_str());
USER_PRINTF("tx in use by: %s\n", pinManager.getPinOwnerText(dmxInputTransmitPin).c_str());
USER_PRINTF("en in use by: %s\n", pinManager.getPinOwnerText(dmxInputEnablePin).c_str());
return;
}
dmx_config_t config{
255, /*alloc_size*/
0, /*model_id*/

View File

@ -141,7 +141,9 @@ bool PinManager::allocateMultiplePins(const managed_pin_type * mptArray, byte ar
bool PinManager::allocatePin(byte gpio, bool output, PinOwner tag)
{
// HW I2C & SPI pins have to be allocated using allocateMultiplePins variant since there is always SCL/SDA pair
if (!isPinOk(gpio, output) || (gpio >= WLED_NUM_PINS) || tag==PinOwner::HW_I2C || tag==PinOwner::HW_SPI) {
// DMX_INPUT pins have to be allocated using allocateMultiplePins variant since there is always RX/TX/EN triple
if (!isPinOk(gpio, output) || (gpio >= WLED_NUM_PINS) || tag==PinOwner::HW_I2C || tag==PinOwner::HW_SPI
|| tag==PinOwner::DMX_INPUT) {
#ifdef WLED_DEBUG
if (gpio < 255) { // 255 (-1) is the "not defined GPIO"
if (!isPinOk(gpio, output)) {

View File

@ -35,15 +35,16 @@ enum struct PinOwner : uint8_t {
Ethernet = 0x81,
BusDigital = 0x82,
BusOnOff = 0x83,
BusPwm = 0x84, // 'BusP' == PWM output using BusPwm
Button = 0x85, // 'Butn' == button from configuration
IR = 0x86, // 'IR' == IR receiver pin from configuration
Relay = 0x87, // 'Rly' == Relay pin from configuration
SPI_RAM = 0x88, // 'SpiR' == SPI RAM
DebugOut = 0x89, // 'Dbg' == debug output always IO1
DMX = 0x8A, // 'DMX' == hard-coded to IO2
HW_I2C = 0x8B, // 'I2C' == hardware I2C pins (4&5 on ESP8266, 21&22 on ESP32)
HW_SPI = 0x8C, // 'SPI' == hardware (V)SPI pins (13,14&15 on ESP8266, 5,18&23 on ESP32)
BusPwm = 0x84, // 'BusP' == PWM output using BusPwm
Button = 0x85, // 'Butn' == button from configuration
IR = 0x86, // 'IR' == IR receiver pin from configuration
Relay = 0x87, // 'Rly' == Relay pin from configuration
SPI_RAM = 0x88, // 'SpiR' == SPI RAM
DebugOut = 0x89, // 'Dbg' == debug output always IO1
DMX = 0x8A, // 'DMX' == hard-coded to IO2
HW_I2C = 0x8B, // 'I2C' == hardware I2C pins (4&5 on ESP8266, 21&22 on ESP32)
HW_SPI = 0x8C, // 'SPI' == hardware (V)SPI pins (13,14&15 on ESP8266, 5,18&23 on ESP32)
DMX_INPUT = 0x8D, // 'DMX_INPUT' == DMX input via serial
// Use UserMod IDs from const.h here
UM_Unspecified = USERMOD_ID_UNSPECIFIED, // 0x01
UM_Example = USERMOD_ID_EXAMPLE, // 0x02 // Usermod "usermod_v2_example.h"

View File

@ -423,11 +423,14 @@ void WLED::setup()
#ifdef WLED_ENABLE_DMX //reserve GPIO2 as hardcoded DMX pin
PinManager::allocatePin(2, true, PinOwner::DMX);
#endif
<<<<<<< HEAD
#ifdef WLED_ENABLE_DMX_INPUT
if(dmxInputTransmitPin > 0) PinManager::allocatePin(dmxInputTransmitPin, true, PinOwner::DMX);
if(dmxInputReceivePin > 0) PinManager::allocatePin(dmxInputReceivePin, true, PinOwner::DMX);
if(dmxInputEnablePin > 0) PinManager::allocatePin(dmxInputEnablePin, true, PinOwner::DMX);
#endif
=======
>>>>>>> a516a7b8 (Move dmx_input pin allocations from wled.cpp to dmx.cpp)
DEBUG_PRINTLN(F("Registering usermods ..."));
registerUsermods();

View File

@ -437,12 +437,12 @@ void getSettingsJS(byte subPage, Print& settingsScript)
printSetFormCheckbox(settingsScript,PSTR("EM"),e131Multicast);
printSetFormValue(settingsScript,PSTR("EU"),e131Universe);
#ifdef WLED_ENABLE_DMX
oappend(SET_F("hideNoDMX();")); // WLEDMM hide "not compiled in" message
settingsScript.print(SET_F("hideNoDMX();")); // hide "not compiled in" message
#endif
#ifndef WLED_ENABLE_DMX_INPUT
oappend(SET_F("hideDMXInput();")); // WLEDMM hide "dmx input" settings
settingsScript.print(SET_F("hideDMXInput();")); // hide "dmx input" settings
#else
oappend(SET_F("hideNoDMXInput();")); // WLEDMM hide "not compiled in" message
settingsScript.print(SET_F("hideNoDMXInput();")); //hide "not comp iled in" message
sappend('v',SET_F("IDMT"),dmxInputTransmitPin);
sappend('v',SET_F("IDMR"),dmxInputReceivePin);
sappend('v',SET_F("IDME"),dmxInputEnablePin);