mirror of
https://github.com/wled/WLED.git
synced 2025-04-26 15:57:18 +00:00
PinManager: Make in to namespace
Namespaces are the C++ language construct for grouping global functions.
This commit is contained in:
parent
95b4bde918
commit
32eee3365a
@ -13,6 +13,16 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Pin management state variables
|
||||||
|
#ifdef ESP8266
|
||||||
|
static uint32_t pinAlloc = 0UL; // 1 bit per pin, we use first 17bits
|
||||||
|
#else
|
||||||
|
static uint64_t pinAlloc = 0ULL; // 1 bit per pin, we use 50 bits on ESP32-S3
|
||||||
|
static uint16_t ledcAlloc = 0; // up to 16 LEDC channels (WLED_MAX_ANALOG_CHANNELS)
|
||||||
|
#endif
|
||||||
|
static uint8_t i2cAllocCount = 0; // allow multiple allocation of I2C bus pins but keep track of allocations
|
||||||
|
static uint8_t spiAllocCount = 0; // allow multiple allocation of SPI bus pins but keep track of allocations
|
||||||
|
static PinOwner ownerTag[WLED_NUM_PINS] = { PinOwner::None };
|
||||||
|
|
||||||
/// Actual allocation/deallocation routines
|
/// Actual allocation/deallocation routines
|
||||||
bool PinManager::deallocatePin(byte gpio, PinOwner tag)
|
bool PinManager::deallocatePin(byte gpio, PinOwner tag)
|
||||||
@ -273,13 +283,3 @@ void PinManager::deallocateLedc(byte pos, byte channels)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ESP8266
|
|
||||||
uint32_t PinManager::pinAlloc = 0UL;
|
|
||||||
#else
|
|
||||||
uint64_t PinManager::pinAlloc = 0ULL;
|
|
||||||
uint16_t PinManager::ledcAlloc = 0;
|
|
||||||
#endif
|
|
||||||
uint8_t PinManager::i2cAllocCount = 0;
|
|
||||||
uint8_t PinManager::spiAllocCount = 0;
|
|
||||||
PinOwner PinManager::ownerTag[WLED_NUM_PINS] = { PinOwner::None };
|
|
||||||
|
@ -9,6 +9,12 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "const.h" // for USERMOD_* values
|
#include "const.h" // for USERMOD_* values
|
||||||
|
|
||||||
|
#ifdef ESP8266
|
||||||
|
#define WLED_NUM_PINS (GPIO_PIN_COUNT+1) // somehow they forgot GPIO 16 (0-16==17)
|
||||||
|
#else
|
||||||
|
#define WLED_NUM_PINS (GPIO_PIN_COUNT)
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct PinManagerPinType {
|
typedef struct PinManagerPinType {
|
||||||
int8_t pin;
|
int8_t pin;
|
||||||
bool isOutput;
|
bool isOutput;
|
||||||
@ -70,52 +76,38 @@ enum struct PinOwner : uint8_t {
|
|||||||
};
|
};
|
||||||
static_assert(0u == static_cast<uint8_t>(PinOwner::None), "PinOwner::None must be zero, so default array initialization works as expected");
|
static_assert(0u == static_cast<uint8_t>(PinOwner::None), "PinOwner::None must be zero, so default array initialization works as expected");
|
||||||
|
|
||||||
class PinManager {
|
namespace PinManager {
|
||||||
private:
|
|
||||||
#ifdef ESP8266
|
|
||||||
#define WLED_NUM_PINS (GPIO_PIN_COUNT+1) // somehow they forgot GPIO 16 (0-16==17)
|
|
||||||
static uint32_t pinAlloc; // 1 bit per pin, we use first 17bits
|
|
||||||
#else
|
|
||||||
#define WLED_NUM_PINS (GPIO_PIN_COUNT)
|
|
||||||
static uint64_t pinAlloc; // 1 bit per pin, we use 50 bits on ESP32-S3
|
|
||||||
static uint16_t ledcAlloc; // up to 16 LEDC channels (WLED_MAX_ANALOG_CHANNELS)
|
|
||||||
#endif
|
|
||||||
static uint8_t i2cAllocCount; // allow multiple allocation of I2C bus pins but keep track of allocations
|
|
||||||
static uint8_t spiAllocCount; // allow multiple allocation of SPI bus pins but keep track of allocations
|
|
||||||
static PinOwner ownerTag[WLED_NUM_PINS];
|
|
||||||
|
|
||||||
public:
|
|
||||||
// De-allocates a single pin
|
// De-allocates a single pin
|
||||||
static bool deallocatePin(byte gpio, PinOwner tag);
|
bool deallocatePin(byte gpio, PinOwner tag);
|
||||||
// De-allocates multiple pins but only if all can be deallocated (PinOwner has to be specified)
|
// De-allocates multiple pins but only if all can be deallocated (PinOwner has to be specified)
|
||||||
static bool deallocateMultiplePins(const uint8_t *pinArray, byte arrayElementCount, PinOwner tag);
|
bool deallocateMultiplePins(const uint8_t *pinArray, byte arrayElementCount, PinOwner tag);
|
||||||
static bool deallocateMultiplePins(const managed_pin_type *pinArray, byte arrayElementCount, PinOwner tag);
|
bool deallocateMultiplePins(const managed_pin_type *pinArray, byte arrayElementCount, PinOwner tag);
|
||||||
// Allocates a single pin, with an owner tag.
|
// Allocates a single pin, with an owner tag.
|
||||||
// De-allocation requires the same owner tag (or override)
|
// De-allocation requires the same owner tag (or override)
|
||||||
static bool allocatePin(byte gpio, bool output, PinOwner tag);
|
bool allocatePin(byte gpio, bool output, PinOwner tag);
|
||||||
// Allocates all the pins, or allocates none of the pins, with owner tag.
|
// Allocates all the pins, or allocates none of the pins, with owner tag.
|
||||||
// Provided to simplify error condition handling in clients
|
// Provided to simplify error condition handling in clients
|
||||||
// using more than one pin, such as I2C, SPI, rotary encoders,
|
// using more than one pin, such as I2C, SPI, rotary encoders,
|
||||||
// ethernet, etc..
|
// ethernet, etc..
|
||||||
static bool allocateMultiplePins(const managed_pin_type * mptArray, byte arrayElementCount, PinOwner tag );
|
bool allocateMultiplePins(const managed_pin_type * mptArray, byte arrayElementCount, PinOwner tag );
|
||||||
|
|
||||||
[[deprecated("Replaced by three-parameter allocatePin(gpio, output, ownerTag), for improved debugging")]]
|
[[deprecated("Replaced by three-parameter allocatePin(gpio, output, ownerTag), for improved debugging")]]
|
||||||
static inline bool allocatePin(byte gpio, bool output = true) { return allocatePin(gpio, output, PinOwner::None); }
|
inline bool allocatePin(byte gpio, bool output = true) { return allocatePin(gpio, output, PinOwner::None); }
|
||||||
[[deprecated("Replaced by two-parameter deallocatePin(gpio, ownerTag), for improved debugging")]]
|
[[deprecated("Replaced by two-parameter deallocatePin(gpio, ownerTag), for improved debugging")]]
|
||||||
static inline void deallocatePin(byte gpio) { deallocatePin(gpio, PinOwner::None); }
|
inline void deallocatePin(byte gpio) { deallocatePin(gpio, PinOwner::None); }
|
||||||
|
|
||||||
// will return true for reserved pins
|
// will return true for reserved pins
|
||||||
static bool isPinAllocated(byte gpio, PinOwner tag = PinOwner::None);
|
bool isPinAllocated(byte gpio, PinOwner tag = PinOwner::None);
|
||||||
// will return false for reserved pins
|
// will return false for reserved pins
|
||||||
static bool isPinOk(byte gpio, bool output = true);
|
bool isPinOk(byte gpio, bool output = true);
|
||||||
|
|
||||||
static bool isReadOnlyPin(byte gpio);
|
bool isReadOnlyPin(byte gpio);
|
||||||
|
|
||||||
static PinOwner getPinOwner(byte gpio);
|
PinOwner getPinOwner(byte gpio);
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
static byte allocateLedc(byte channels);
|
byte allocateLedc(byte channels);
|
||||||
static void deallocateLedc(byte pos, byte channels);
|
void deallocateLedc(byte pos, byte channels);
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user