mirror of
https://github.com/wled/WLED.git
synced 2025-07-15 14:56:32 +00:00
Merge pull request #4129 from Aircoookie/bus-config
Fetch LED types from Bus classes (dynamic UI)
This commit is contained in:
commit
df24fd7bf2
@ -1249,12 +1249,12 @@ void WS2812FX::finalizeInit() {
|
|||||||
//RGBW mode is enabled if at least one of the strips is RGBW
|
//RGBW mode is enabled if at least one of the strips is RGBW
|
||||||
_hasWhiteChannel |= bus->hasWhite();
|
_hasWhiteChannel |= bus->hasWhite();
|
||||||
//refresh is required to remain off if at least one of the strips requires the refresh.
|
//refresh is required to remain off if at least one of the strips requires the refresh.
|
||||||
_isOffRefreshRequired |= bus->isOffRefreshRequired();
|
_isOffRefreshRequired |= bus->isOffRefreshRequired() && !bus->isPWM(); // use refresh bit for phase shift with analog
|
||||||
unsigned busEnd = bus->getStart() + bus->getLength();
|
unsigned busEnd = bus->getStart() + bus->getLength();
|
||||||
if (busEnd > _length) _length = busEnd;
|
if (busEnd > _length) _length = busEnd;
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
// why do we need to reinitialise GPIO3???
|
// why do we need to reinitialise GPIO3???
|
||||||
//if ((!IS_DIGITAL(bus->getType()) || IS_2PIN(bus->getType()))) continue;
|
//if (!bus->isDigital() || bus->is2Pin()) continue;
|
||||||
//uint8_t pins[5];
|
//uint8_t pins[5];
|
||||||
//if (!bus->getPins(pins)) continue;
|
//if (!bus->getPins(pins)) continue;
|
||||||
//BusDigital* bd = static_cast<BusDigital*>(bus);
|
//BusDigital* bd = static_cast<BusDigital*>(bus);
|
||||||
|
@ -4,6 +4,18 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <IPAddress.h>
|
#include <IPAddress.h>
|
||||||
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
|
#include "driver/ledc.h"
|
||||||
|
#include "soc/ledc_struct.h"
|
||||||
|
#if !(defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3))
|
||||||
|
#define LEDC_MUTEX_LOCK() do {} while (xSemaphoreTake(_ledc_sys_lock, portMAX_DELAY) != pdPASS)
|
||||||
|
#define LEDC_MUTEX_UNLOCK() xSemaphoreGive(_ledc_sys_lock)
|
||||||
|
extern xSemaphoreHandle _ledc_sys_lock;
|
||||||
|
#else
|
||||||
|
#define LEDC_MUTEX_LOCK()
|
||||||
|
#define LEDC_MUTEX_UNLOCK()
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "pin_manager.h"
|
#include "pin_manager.h"
|
||||||
#include "bus_wrapper.h"
|
#include "bus_wrapper.h"
|
||||||
@ -48,38 +60,46 @@ uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, byte
|
|||||||
#define W(c) (byte((c) >> 24))
|
#define W(c) (byte((c) >> 24))
|
||||||
|
|
||||||
|
|
||||||
void ColorOrderMap::add(uint16_t start, uint16_t len, uint8_t colorOrder) {
|
bool ColorOrderMap::add(uint16_t start, uint16_t len, uint8_t colorOrder) {
|
||||||
if (_count >= WLED_MAX_COLOR_ORDER_MAPPINGS) {
|
if (count() >= WLED_MAX_COLOR_ORDER_MAPPINGS || len == 0 || (colorOrder & 0x0F) > COL_ORDER_MAX) return false; // upper nibble contains W swap information
|
||||||
return;
|
_mappings.push_back({start,len,colorOrder});
|
||||||
}
|
return true;
|
||||||
if (len == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// upper nibble contains W swap information
|
|
||||||
if ((colorOrder & 0x0F) > COL_ORDER_MAX) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_mappings[_count].start = start;
|
|
||||||
_mappings[_count].len = len;
|
|
||||||
_mappings[_count].colorOrder = colorOrder;
|
|
||||||
_count++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t IRAM_ATTR ColorOrderMap::getPixelColorOrder(uint16_t pix, uint8_t defaultColorOrder) const {
|
uint8_t IRAM_ATTR ColorOrderMap::getPixelColorOrder(uint16_t pix, uint8_t defaultColorOrder) const {
|
||||||
if (_count > 0) {
|
// upper nibble contains W swap information
|
||||||
// upper nibble contains W swap information
|
// when ColorOrderMap's upper nibble contains value >0 then swap information is used from it, otherwise global swap is used
|
||||||
// when ColorOrderMap's upper nibble contains value >0 then swap information is used from it, otherwise global swap is used
|
for (unsigned i = 0; i < count(); i++) {
|
||||||
for (unsigned i = 0; i < _count; i++) {
|
if (pix >= _mappings[i].start && pix < (_mappings[i].start + _mappings[i].len)) {
|
||||||
if (pix >= _mappings[i].start && pix < (_mappings[i].start + _mappings[i].len)) {
|
return _mappings[i].colorOrder | ((_mappings[i].colorOrder >> 4) ? 0 : (defaultColorOrder & 0xF0));
|
||||||
return _mappings[i].colorOrder | ((_mappings[i].colorOrder >> 4) ? 0 : (defaultColorOrder & 0xF0));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return defaultColorOrder;
|
return defaultColorOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t Bus::autoWhiteCalc(uint32_t c) {
|
void Bus::calculateCCT(uint32_t c, uint8_t &ww, uint8_t &cw) {
|
||||||
|
unsigned cct = 0; //0 - full warm white, 255 - full cold white
|
||||||
|
unsigned w = W(c);
|
||||||
|
|
||||||
|
if (_cct > -1) { // using RGB?
|
||||||
|
if (_cct >= 1900) cct = (_cct - 1900) >> 5; // convert K in relative format
|
||||||
|
else if (_cct < 256) cct = _cct; // already relative
|
||||||
|
} else {
|
||||||
|
cct = (approximateKelvinFromRGB(c) - 1900) >> 5; // convert K (from RGB value) to relative format
|
||||||
|
}
|
||||||
|
|
||||||
|
//0 - linear (CCT 127 = 50% warm, 50% cold), 127 - additive CCT blending (CCT 127 = 100% warm, 100% cold)
|
||||||
|
if (cct < _cctBlend) ww = 255;
|
||||||
|
else ww = ((255-cct) * 255) / (255 - _cctBlend);
|
||||||
|
if ((255-cct) < _cctBlend) cw = 255;
|
||||||
|
else cw = (cct * 255) / (255 - _cctBlend);
|
||||||
|
|
||||||
|
ww = (w * ww) / 255; //brightness scaling
|
||||||
|
cw = (w * cw) / 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Bus::autoWhiteCalc(uint32_t c) const {
|
||||||
unsigned aWM = _autoWhiteMode;
|
unsigned aWM = _autoWhiteMode;
|
||||||
if (_gAWM < AW_GLOBAL_DISABLED) aWM = _gAWM;
|
if (_gAWM < AW_GLOBAL_DISABLED) aWM = _gAWM;
|
||||||
if (aWM == RGBW_MODE_MANUAL_ONLY) return c;
|
if (aWM == RGBW_MODE_MANUAL_ONLY) return c;
|
||||||
@ -95,7 +115,7 @@ uint32_t Bus::autoWhiteCalc(uint32_t c) {
|
|||||||
return RGBW32(r, g, b, w);
|
return RGBW32(r, g, b, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *Bus::allocData(size_t size) {
|
uint8_t *Bus::allocateData(size_t size) {
|
||||||
if (_data) free(_data); // should not happen, but for safety
|
if (_data) free(_data); // should not happen, but for safety
|
||||||
return _data = (uint8_t *)(size>0 ? calloc(size, sizeof(uint8_t)) : nullptr);
|
return _data = (uint8_t *)(size>0 ? calloc(size, sizeof(uint8_t)) : nullptr);
|
||||||
}
|
}
|
||||||
@ -109,11 +129,11 @@ BusDigital::BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com)
|
|||||||
, _milliAmpsMax(bc.milliAmpsMax)
|
, _milliAmpsMax(bc.milliAmpsMax)
|
||||||
, _colorOrderMap(com)
|
, _colorOrderMap(com)
|
||||||
{
|
{
|
||||||
if (!IS_DIGITAL(bc.type) || !bc.count) return;
|
if (!isDigital(bc.type) || !bc.count) return;
|
||||||
if (!pinManager.allocatePin(bc.pins[0], true, PinOwner::BusDigital)) return;
|
if (!pinManager.allocatePin(bc.pins[0], true, PinOwner::BusDigital)) return;
|
||||||
_frequencykHz = 0U;
|
_frequencykHz = 0U;
|
||||||
_pins[0] = bc.pins[0];
|
_pins[0] = bc.pins[0];
|
||||||
if (IS_2PIN(bc.type)) {
|
if (is2Pin(bc.type)) {
|
||||||
if (!pinManager.allocatePin(bc.pins[1], true, PinOwner::BusDigital)) {
|
if (!pinManager.allocatePin(bc.pins[1], true, PinOwner::BusDigital)) {
|
||||||
cleanup();
|
cleanup();
|
||||||
return;
|
return;
|
||||||
@ -123,13 +143,16 @@ BusDigital::BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com)
|
|||||||
}
|
}
|
||||||
_iType = PolyBus::getI(bc.type, _pins, nr);
|
_iType = PolyBus::getI(bc.type, _pins, nr);
|
||||||
if (_iType == I_NONE) return;
|
if (_iType == I_NONE) return;
|
||||||
if (bc.doubleBuffer && !allocData(bc.count * Bus::getNumberOfChannels(bc.type))) return;
|
_hasRgb = hasRGB(bc.type);
|
||||||
|
_hasWhite = hasWhite(bc.type);
|
||||||
|
_hasCCT = hasCCT(bc.type);
|
||||||
|
if (bc.doubleBuffer && !allocateData(bc.count * Bus::getNumberOfChannels(bc.type))) return;
|
||||||
//_buffering = bc.doubleBuffer;
|
//_buffering = bc.doubleBuffer;
|
||||||
uint16_t lenToCreate = bc.count;
|
uint16_t lenToCreate = bc.count;
|
||||||
if (bc.type == TYPE_WS2812_1CH_X3) lenToCreate = NUM_ICS_WS2812_1CH_3X(bc.count); // only needs a third of "RGB" LEDs for NeoPixelBus
|
if (bc.type == TYPE_WS2812_1CH_X3) lenToCreate = NUM_ICS_WS2812_1CH_3X(bc.count); // only needs a third of "RGB" LEDs for NeoPixelBus
|
||||||
_busPtr = PolyBus::create(_iType, _pins, lenToCreate + _skip, nr, _frequencykHz);
|
_busPtr = PolyBus::create(_iType, _pins, lenToCreate + _skip, nr, _frequencykHz);
|
||||||
_valid = (_busPtr != nullptr);
|
_valid = (_busPtr != nullptr);
|
||||||
DEBUG_PRINTF_P(PSTR("%successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u). mA=%d/%d\n"), _valid?"S":"Uns", nr, bc.count, bc.type, _pins[0], IS_2PIN(bc.type)?_pins[1]:255, _iType, _milliAmpsPerLed, _milliAmpsMax);
|
DEBUG_PRINTF_P(PSTR("%successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u). mA=%d/%d\n"), _valid?"S":"Uns", nr, bc.count, bc.type, _pins[0], is2Pin(bc.type)?_pins[1]:255, _iType, _milliAmpsPerLed, _milliAmpsMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
//fine tune power estimation constants for your setup
|
//fine tune power estimation constants for your setup
|
||||||
@ -263,7 +286,7 @@ void BusDigital::show() {
|
|||||||
if (newBri < _bri) PolyBus::setBrightness(_busPtr, _iType, _bri);
|
if (newBri < _bri) PolyBus::setBrightness(_busPtr, _iType, _bri);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BusDigital::canShow() {
|
bool BusDigital::canShow() const {
|
||||||
if (!_valid) return true;
|
if (!_valid) return true;
|
||||||
return PolyBus::canShow(_busPtr, _iType);
|
return PolyBus::canShow(_busPtr, _iType);
|
||||||
}
|
}
|
||||||
@ -319,7 +342,7 @@ void IRAM_ATTR BusDigital::setPixelColor(uint16_t pix, uint32_t c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returns original color if global buffering is enabled, else returns lossly restored color from bus
|
// returns original color if global buffering is enabled, else returns lossly restored color from bus
|
||||||
uint32_t IRAM_ATTR BusDigital::getPixelColor(uint16_t pix) {
|
uint32_t IRAM_ATTR BusDigital::getPixelColor(uint16_t pix) const {
|
||||||
if (!_valid) return 0;
|
if (!_valid) return 0;
|
||||||
if (_data) {
|
if (_data) {
|
||||||
size_t offset = pix * getNumberOfChannels();
|
size_t offset = pix * getNumberOfChannels();
|
||||||
@ -349,9 +372,9 @@ uint32_t IRAM_ATTR BusDigital::getPixelColor(uint16_t pix) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t BusDigital::getPins(uint8_t* pinArray) {
|
uint8_t BusDigital::getPins(uint8_t* pinArray) const {
|
||||||
unsigned numPins = IS_2PIN(_type) ? 2 : 1;
|
unsigned numPins = is2Pin(_type) + 1;
|
||||||
for (unsigned i = 0; i < numPins; i++) pinArray[i] = _pins[i];
|
if (pinArray) for (unsigned i = 0; i < numPins; i++) pinArray[i] = _pins[i];
|
||||||
return numPins;
|
return numPins;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,6 +384,32 @@ void BusDigital::setColorOrder(uint8_t colorOrder) {
|
|||||||
_colorOrder = colorOrder;
|
_colorOrder = colorOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// credit @willmmiles & @netmindz https://github.com/Aircoookie/WLED/pull/4056
|
||||||
|
std::vector<LEDType> BusDigital::getLEDTypes() {
|
||||||
|
return {
|
||||||
|
{TYPE_WS2812_RGB, "D", PSTR("WS281x")},
|
||||||
|
{TYPE_SK6812_RGBW, "D", PSTR("SK6812/WS2814 RGBW")},
|
||||||
|
{TYPE_TM1814, "D", PSTR("TM1814")},
|
||||||
|
{TYPE_WS2811_400KHZ, "D", PSTR("400kHz")},
|
||||||
|
{TYPE_TM1829, "D", PSTR("TM1829")},
|
||||||
|
{TYPE_UCS8903, "D", PSTR("UCS8903")},
|
||||||
|
{TYPE_APA106, "D", PSTR("APA106/PL9823")},
|
||||||
|
{TYPE_TM1914, "D", PSTR("TM1914")},
|
||||||
|
{TYPE_FW1906, "D", PSTR("FW1906 GRBCW")},
|
||||||
|
{TYPE_UCS8904, "D", PSTR("UCS8904 RGBW")},
|
||||||
|
{TYPE_WS2805, "D", PSTR("WS2805 RGBCW")},
|
||||||
|
{TYPE_SM16825, "D", PSTR("SM16825 RGBCW")},
|
||||||
|
{TYPE_WS2812_1CH_X3, "D", PSTR("WS2811 White")},
|
||||||
|
//{TYPE_WS2812_2CH_X3, "D", PSTR("WS2811 CCT")}, // not implemented
|
||||||
|
//{TYPE_WS2812_WWA, "D", PSTR("WS2811 WWA")}, // not implemented
|
||||||
|
{TYPE_WS2801, "2P", PSTR("WS2801")},
|
||||||
|
{TYPE_APA102, "2P", PSTR("APA102")},
|
||||||
|
{TYPE_LPD8806, "2P", PSTR("LPD8806")},
|
||||||
|
{TYPE_LPD6803, "2P", PSTR("LPD6803")},
|
||||||
|
{TYPE_P9813, "2P", PSTR("PP9813")},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void BusDigital::reinit() {
|
void BusDigital::reinit() {
|
||||||
if (!_valid) return;
|
if (!_valid) return;
|
||||||
PolyBus::begin(_busPtr, _iType, _pins);
|
PolyBus::begin(_busPtr, _iType, _pins);
|
||||||
@ -399,42 +448,54 @@ void BusDigital::cleanup() {
|
|||||||
#define MAX_BIT_WIDTH SOC_LEDC_TIMER_BIT_WIDE_NUM
|
#define MAX_BIT_WIDTH SOC_LEDC_TIMER_BIT_WIDE_NUM
|
||||||
#else
|
#else
|
||||||
// ESP32: 20 bit (but in reality we would never go beyond 16 bit as the frequency would be to low)
|
// ESP32: 20 bit (but in reality we would never go beyond 16 bit as the frequency would be to low)
|
||||||
#define MAX_BIT_WIDTH 20
|
#define MAX_BIT_WIDTH 14
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BusPwm::BusPwm(BusConfig &bc)
|
BusPwm::BusPwm(BusConfig &bc)
|
||||||
: Bus(bc.type, bc.start, bc.autoWhite, 1, bc.reversed)
|
: Bus(bc.type, bc.start, bc.autoWhite, 1, bc.reversed, bc.refreshReq) // hijack Off refresh flag to indicate usage of dithering
|
||||||
{
|
{
|
||||||
if (!IS_PWM(bc.type)) return;
|
if (!isPWM(bc.type)) return;
|
||||||
unsigned numPins = NUM_PWM_PINS(bc.type);
|
unsigned numPins = numPWMPins(bc.type);
|
||||||
|
[[maybe_unused]] const bool dithering = _needsRefresh;
|
||||||
_frequency = bc.frequency ? bc.frequency : WLED_PWM_FREQ;
|
_frequency = bc.frequency ? bc.frequency : WLED_PWM_FREQ;
|
||||||
// duty cycle resolution (_depth) can be extracted from this formula: CLOCK_FREQUENCY > _frequency * 2^_depth
|
// duty cycle resolution (_depth) can be extracted from this formula: CLOCK_FREQUENCY > _frequency * 2^_depth
|
||||||
for (_depth = MAX_BIT_WIDTH; _depth > 8; _depth--) if (((CLOCK_FREQUENCY/_frequency) >> _depth) > 0) break;
|
for (_depth = MAX_BIT_WIDTH; _depth > 8; _depth--) if (((CLOCK_FREQUENCY/_frequency) >> _depth) > 0) break;
|
||||||
|
|
||||||
|
managed_pin_type pins[numPins];
|
||||||
|
for (unsigned i = 0; i < numPins; i++) pins[i] = {(int8_t)bc.pins[i], true};
|
||||||
|
if (!pinManager.allocateMultiplePins(pins, numPins, PinOwner::BusPwm)) return;
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
analogWriteRange((1<<_depth)-1);
|
analogWriteRange((1<<_depth)-1);
|
||||||
analogWriteFreq(_frequency);
|
analogWriteFreq(_frequency);
|
||||||
#else
|
#else
|
||||||
|
// for 2 pin PWM CCT strip pinManager will make sure both LEDC channels are in the same speed group and sharing the same timer
|
||||||
_ledcStart = pinManager.allocateLedc(numPins);
|
_ledcStart = pinManager.allocateLedc(numPins);
|
||||||
if (_ledcStart == 255) { //no more free LEDC channels
|
if (_ledcStart == 255) { //no more free LEDC channels
|
||||||
deallocatePins(); return;
|
pinManager.deallocateMultiplePins(pins, numPins, PinOwner::BusPwm);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
// if _needsRefresh is true (UI hack) we are using dithering (credit @dedehai & @zalatnaicsongor)
|
||||||
|
if (dithering) _depth = 12; // fixed 8 bit depth PWM with 4 bit dithering (ESP8266 has no hardware to support dithering)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (unsigned i = 0; i < numPins; i++) {
|
for (unsigned i = 0; i < numPins; i++) {
|
||||||
uint8_t currentPin = bc.pins[i];
|
_pins[i] = bc.pins[i]; // store only after allocateMultiplePins() succeeded
|
||||||
if (!pinManager.allocatePin(currentPin, true, PinOwner::BusPwm)) {
|
|
||||||
deallocatePins(); return;
|
|
||||||
}
|
|
||||||
_pins[i] = currentPin; //store only after allocatePin() succeeds
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
pinMode(_pins[i], OUTPUT);
|
pinMode(_pins[i], OUTPUT);
|
||||||
#else
|
#else
|
||||||
ledcSetup(_ledcStart + i, _frequency, _depth);
|
unsigned channel = _ledcStart + i;
|
||||||
ledcAttachPin(_pins[i], _ledcStart + i);
|
ledcSetup(channel, _frequency, _depth - (dithering*4)); // with dithering _frequency doesn't really matter as resolution is 8 bit
|
||||||
|
ledcAttachPin(_pins[i], channel);
|
||||||
|
// LEDC timer reset credit @dedehai
|
||||||
|
uint8_t group = (channel / 8), timer = ((channel / 2) % 4); // same fromula as in ledcSetup()
|
||||||
|
ledc_timer_rst((ledc_mode_t)group, (ledc_timer_t)timer); // reset timer so all timers are almost in sync (for phase shift)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
_hasRgb = hasRGB(bc.type);
|
||||||
|
_hasWhite = hasWhite(bc.type);
|
||||||
|
_hasCCT = hasCCT(bc.type);
|
||||||
_data = _pwmdata; // avoid malloc() and use stack
|
_data = _pwmdata; // avoid malloc() and use stack
|
||||||
_valid = true;
|
_valid = true;
|
||||||
DEBUG_PRINTF_P(PSTR("%successfully inited PWM strip with type %u, frequency %u, bit depth %u and pins %u,%u,%u,%u,%u\n"), _valid?"S":"Uns", bc.type, _frequency, _depth, _pins[0], _pins[1], _pins[2], _pins[3], _pins[4]);
|
DEBUG_PRINTF_P(PSTR("%successfully inited PWM strip with type %u, frequency %u, bit depth %u and pins %u,%u,%u,%u,%u\n"), _valid?"S":"Uns", bc.type, _frequency, _depth, _pins[0], _pins[1], _pins[2], _pins[3], _pins[4]);
|
||||||
@ -477,7 +538,7 @@ void BusPwm::setPixelColor(uint16_t pix, uint32_t c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//does no index check
|
//does no index check
|
||||||
uint32_t BusPwm::getPixelColor(uint16_t pix) {
|
uint32_t BusPwm::getPixelColor(uint16_t pix) const {
|
||||||
if (!_valid) return 0;
|
if (!_valid) return 0;
|
||||||
// TODO getting the reverse from CCT is involved (a quick approximation when CCT blending is ste to 0 implemented)
|
// TODO getting the reverse from CCT is involved (a quick approximation when CCT blending is ste to 0 implemented)
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
@ -499,46 +560,92 @@ uint32_t BusPwm::getPixelColor(uint16_t pix) {
|
|||||||
|
|
||||||
void BusPwm::show() {
|
void BusPwm::show() {
|
||||||
if (!_valid) return;
|
if (!_valid) return;
|
||||||
unsigned numPins = NUM_PWM_PINS(_type);
|
// if _needsRefresh is true (UI hack) we are using dithering (credit @dedehai & @zalatnaicsongor)
|
||||||
unsigned maxBri = (1<<_depth) - 1;
|
// https://github.com/Aircoookie/WLED/pull/4115 and https://github.com/zalatnaicsongor/WLED/pull/1)
|
||||||
// use CIE brightness formula
|
const bool dithering = _needsRefresh; // avoid working with bitfield
|
||||||
unsigned pwmBri = (unsigned)_bri * 100;
|
const unsigned numPins = getPins();
|
||||||
if(pwmBri < 2040) pwmBri = ((pwmBri << _depth) + 115043) / 230087; //adding '0.5' before division for correct rounding
|
const unsigned maxBri = (1<<_depth); // possible values: 16384 (14), 8192 (13), 4096 (12), 2048 (11), 1024 (10), 512 (9) and 256 (8)
|
||||||
else {
|
[[maybe_unused]] const unsigned bitShift = dithering * 4; // if dithering, _depth is 12 bit but LEDC channel is set to 8 bit (using 4 fractional bits)
|
||||||
|
|
||||||
|
// use CIE brightness formula (cubic) to fit (or approximate linearity of) human eye perceived brightness
|
||||||
|
// the formula is based on 12 bit resolution as there is no need for greater precision
|
||||||
|
// see: https://en.wikipedia.org/wiki/Lightness
|
||||||
|
unsigned pwmBri = (unsigned)_bri * 100; // enlarge to use integer math for linear response
|
||||||
|
if (pwmBri < 2040) {
|
||||||
|
// linear response for values [0-20]
|
||||||
|
pwmBri = ((pwmBri << 12) + 115043) / 230087; //adding '0.5' before division for correct rounding
|
||||||
|
} else {
|
||||||
|
// cubic response for values [21-255]
|
||||||
pwmBri += 4080;
|
pwmBri += 4080;
|
||||||
float temp = (float)pwmBri / 29580;
|
float temp = (float)pwmBri / 29580.0f;
|
||||||
temp = temp * temp * temp * (1<<_depth) - 1;
|
temp = temp * temp * temp * (float)maxBri;
|
||||||
pwmBri = (unsigned)temp;
|
pwmBri = (unsigned)temp; // pwmBri is in range [0-maxBri]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[maybe_unused]] unsigned hPoint = 0; // phase shift (0 - maxBri)
|
||||||
|
// we will be phase shifting every channel by previous pulse length (plus dead time if required)
|
||||||
|
// phase shifting is only mandatory when using H-bridge to drive reverse-polarity PWM CCT (2 wire) LED type
|
||||||
|
// CCT additive blending must be 0 (WW & CW will not overlap) otherwise signals *will* overlap
|
||||||
|
// for all other cases it will just try to "spread" the load on PSU
|
||||||
|
// Phase shifting requires that LEDC timers are synchronised (see setup()). For PWM CCT (and H-bridge) it is
|
||||||
|
// also mandatory that both channels use the same timer (pinManager takes care of that).
|
||||||
for (unsigned i = 0; i < numPins; i++) {
|
for (unsigned i = 0; i < numPins; i++) {
|
||||||
unsigned scaled = (_data[i] * pwmBri) / 255;
|
unsigned duty = (_data[i] * pwmBri) / 255;
|
||||||
if (_reversed) scaled = maxBri - scaled;
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
analogWrite(_pins[i], scaled);
|
if (_reversed) duty = maxBri - duty;
|
||||||
|
analogWrite(_pins[i], duty);
|
||||||
#else
|
#else
|
||||||
ledcWrite(_ledcStart + i, scaled);
|
int deadTime = 0;
|
||||||
|
if (_type == TYPE_ANALOG_2CH && Bus::getCCTBlend() == 0) {
|
||||||
|
// add dead time between signals (when using dithering, two full 8bit pulses are required)
|
||||||
|
deadTime = (1+dithering) << bitShift;
|
||||||
|
// we only need to take care of shortening the signal at (almost) full brightness otherwise pulses may overlap
|
||||||
|
if (_bri >= 254 && duty >= maxBri / 2 && duty < maxBri) duty -= deadTime << 1; // shorten duty of larger signal except if full on
|
||||||
|
if (_reversed) deadTime = -deadTime; // need to invert dead time to make phaseshift go the opposite way so low signals dont overlap
|
||||||
|
}
|
||||||
|
if (_reversed) duty = maxBri - duty;
|
||||||
|
unsigned channel = _ledcStart + i;
|
||||||
|
unsigned gr = channel/8; // high/low speed group
|
||||||
|
unsigned ch = channel%8; // group channel
|
||||||
|
// directly write to LEDC struct as there is no HAL exposed function for dithering
|
||||||
|
// duty has 20 bit resolution with 4 fractional bits (24 bits in total)
|
||||||
|
LEDC.channel_group[gr].channel[ch].duty.duty = duty << ((!dithering)*4); // lowest 4 bits are used for dithering, shift by 4 bits if not using dithering
|
||||||
|
LEDC.channel_group[gr].channel[ch].hpoint.hpoint = hPoint >> bitShift; // hPoint is at _depth resolution (needs shifting if dithering)
|
||||||
|
ledc_update_duty((ledc_mode_t)gr, (ledc_channel_t)ch);
|
||||||
|
hPoint += duty + deadTime; // offset to cascade the signals
|
||||||
|
if (hPoint >= maxBri) hPoint = 0; // offset it out of bounds, reset
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t BusPwm::getPins(uint8_t* pinArray) {
|
uint8_t BusPwm::getPins(uint8_t* pinArray) const {
|
||||||
if (!_valid) return 0;
|
if (!_valid) return 0;
|
||||||
unsigned numPins = NUM_PWM_PINS(_type);
|
unsigned numPins = numPWMPins(_type);
|
||||||
for (unsigned i = 0; i < numPins; i++) {
|
if (pinArray) for (unsigned i = 0; i < numPins; i++) pinArray[i] = _pins[i];
|
||||||
pinArray[i] = _pins[i];
|
|
||||||
}
|
|
||||||
return numPins;
|
return numPins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// credit @willmmiles & @netmindz https://github.com/Aircoookie/WLED/pull/4056
|
||||||
|
std::vector<LEDType> BusPwm::getLEDTypes() {
|
||||||
|
return {
|
||||||
|
{TYPE_ANALOG_1CH, "A", PSTR("PWM White")},
|
||||||
|
{TYPE_ANALOG_2CH, "AA", PSTR("PWM CCT")},
|
||||||
|
{TYPE_ANALOG_3CH, "AAA", PSTR("PWM RGB")},
|
||||||
|
{TYPE_ANALOG_4CH, "AAAA", PSTR("PWM RGBW")},
|
||||||
|
{TYPE_ANALOG_5CH, "AAAAA", PSTR("PWM RGB+CCT")},
|
||||||
|
//{TYPE_ANALOG_6CH, "AAAAAA", PSTR("PWM RGB+DCCT")}, // unimplementable ATM
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void BusPwm::deallocatePins() {
|
void BusPwm::deallocatePins() {
|
||||||
unsigned numPins = NUM_PWM_PINS(_type);
|
unsigned numPins = getPins();
|
||||||
for (unsigned i = 0; i < numPins; i++) {
|
for (unsigned i = 0; i < numPins; i++) {
|
||||||
pinManager.deallocatePin(_pins[i], PinOwner::BusPwm);
|
pinManager.deallocatePin(_pins[i], PinOwner::BusPwm);
|
||||||
if (!pinManager.isPinOk(_pins[i])) continue;
|
if (!pinManager.isPinOk(_pins[i])) continue;
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
digitalWrite(_pins[i], LOW); //turn off PWM interrupt
|
digitalWrite(_pins[i], LOW); //turn off PWM interrupt
|
||||||
#else
|
#else
|
||||||
if (_ledcStart < 16) ledcDetachPin(_pins[i]);
|
if (_ledcStart < WLED_MAX_ANALOG_CHANNELS) ledcDetachPin(_pins[i]);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
@ -551,7 +658,7 @@ BusOnOff::BusOnOff(BusConfig &bc)
|
|||||||
: Bus(bc.type, bc.start, bc.autoWhite, 1, bc.reversed)
|
: Bus(bc.type, bc.start, bc.autoWhite, 1, bc.reversed)
|
||||||
, _onoffdata(0)
|
, _onoffdata(0)
|
||||||
{
|
{
|
||||||
if (bc.type != TYPE_ONOFF) return;
|
if (!Bus::isOnOff(bc.type)) return;
|
||||||
|
|
||||||
uint8_t currentPin = bc.pins[0];
|
uint8_t currentPin = bc.pins[0];
|
||||||
if (!pinManager.allocatePin(currentPin, true, PinOwner::BusOnOff)) {
|
if (!pinManager.allocatePin(currentPin, true, PinOwner::BusOnOff)) {
|
||||||
@ -559,6 +666,9 @@ BusOnOff::BusOnOff(BusConfig &bc)
|
|||||||
}
|
}
|
||||||
_pin = currentPin; //store only after allocatePin() succeeds
|
_pin = currentPin; //store only after allocatePin() succeeds
|
||||||
pinMode(_pin, OUTPUT);
|
pinMode(_pin, OUTPUT);
|
||||||
|
_hasRgb = false;
|
||||||
|
_hasWhite = false;
|
||||||
|
_hasCCT = false;
|
||||||
_data = &_onoffdata; // avoid malloc() and use stack
|
_data = &_onoffdata; // avoid malloc() and use stack
|
||||||
_valid = true;
|
_valid = true;
|
||||||
DEBUG_PRINTF_P(PSTR("%successfully inited On/Off strip with pin %u\n"), _valid?"S":"Uns", _pin);
|
DEBUG_PRINTF_P(PSTR("%successfully inited On/Off strip with pin %u\n"), _valid?"S":"Uns", _pin);
|
||||||
@ -574,7 +684,7 @@ void BusOnOff::setPixelColor(uint16_t pix, uint32_t c) {
|
|||||||
_data[0] = bool(r|g|b|w) && bool(_bri) ? 0xFF : 0;
|
_data[0] = bool(r|g|b|w) && bool(_bri) ? 0xFF : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t BusOnOff::getPixelColor(uint16_t pix) {
|
uint32_t BusOnOff::getPixelColor(uint16_t pix) const {
|
||||||
if (!_valid) return 0;
|
if (!_valid) return 0;
|
||||||
return RGBW32(_data[0], _data[0], _data[0], _data[0]);
|
return RGBW32(_data[0], _data[0], _data[0], _data[0]);
|
||||||
}
|
}
|
||||||
@ -584,12 +694,18 @@ void BusOnOff::show() {
|
|||||||
digitalWrite(_pin, _reversed ? !(bool)_data[0] : (bool)_data[0]);
|
digitalWrite(_pin, _reversed ? !(bool)_data[0] : (bool)_data[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t BusOnOff::getPins(uint8_t* pinArray) {
|
uint8_t BusOnOff::getPins(uint8_t* pinArray) const {
|
||||||
if (!_valid) return 0;
|
if (!_valid) return 0;
|
||||||
pinArray[0] = _pin;
|
if (pinArray) pinArray[0] = _pin;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// credit @willmmiles & @netmindz https://github.com/Aircoookie/WLED/pull/4056
|
||||||
|
std::vector<LEDType> BusOnOff::getLEDTypes() {
|
||||||
|
return {
|
||||||
|
{TYPE_ONOFF, "", PSTR("On/Off")},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
BusNetwork::BusNetwork(BusConfig &bc)
|
BusNetwork::BusNetwork(BusConfig &bc)
|
||||||
: Bus(bc.type, bc.start, bc.autoWhite, bc.count)
|
: Bus(bc.type, bc.start, bc.autoWhite, bc.count)
|
||||||
@ -597,59 +713,71 @@ BusNetwork::BusNetwork(BusConfig &bc)
|
|||||||
{
|
{
|
||||||
switch (bc.type) {
|
switch (bc.type) {
|
||||||
case TYPE_NET_ARTNET_RGB:
|
case TYPE_NET_ARTNET_RGB:
|
||||||
_rgbw = false;
|
|
||||||
_UDPtype = 2;
|
_UDPtype = 2;
|
||||||
break;
|
break;
|
||||||
case TYPE_NET_ARTNET_RGBW:
|
case TYPE_NET_ARTNET_RGBW:
|
||||||
_rgbw = true;
|
|
||||||
_UDPtype = 2;
|
_UDPtype = 2;
|
||||||
break;
|
break;
|
||||||
case TYPE_NET_E131_RGB:
|
case TYPE_NET_E131_RGB:
|
||||||
_rgbw = false;
|
|
||||||
_UDPtype = 1;
|
_UDPtype = 1;
|
||||||
break;
|
break;
|
||||||
default: // TYPE_NET_DDP_RGB / TYPE_NET_DDP_RGBW
|
default: // TYPE_NET_DDP_RGB / TYPE_NET_DDP_RGBW
|
||||||
_rgbw = bc.type == TYPE_NET_DDP_RGBW;
|
|
||||||
_UDPtype = 0;
|
_UDPtype = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_UDPchannels = _rgbw ? 4 : 3;
|
_hasRgb = hasRGB(bc.type);
|
||||||
|
_hasWhite = hasWhite(bc.type);
|
||||||
|
_hasCCT = false;
|
||||||
|
_UDPchannels = _hasWhite + 3;
|
||||||
_client = IPAddress(bc.pins[0],bc.pins[1],bc.pins[2],bc.pins[3]);
|
_client = IPAddress(bc.pins[0],bc.pins[1],bc.pins[2],bc.pins[3]);
|
||||||
_valid = (allocData(_len * _UDPchannels) != nullptr);
|
_valid = (allocateData(_len * _UDPchannels) != nullptr);
|
||||||
DEBUG_PRINTF_P(PSTR("%successfully inited virtual strip with type %u and IP %u.%u.%u.%u\n"), _valid?"S":"Uns", bc.type, bc.pins[0], bc.pins[1], bc.pins[2], bc.pins[3]);
|
DEBUG_PRINTF_P(PSTR("%successfully inited virtual strip with type %u and IP %u.%u.%u.%u\n"), _valid?"S":"Uns", bc.type, bc.pins[0], bc.pins[1], bc.pins[2], bc.pins[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BusNetwork::setPixelColor(uint16_t pix, uint32_t c) {
|
void BusNetwork::setPixelColor(uint16_t pix, uint32_t c) {
|
||||||
if (!_valid || pix >= _len) return;
|
if (!_valid || pix >= _len) return;
|
||||||
if (_rgbw) c = autoWhiteCalc(c);
|
if (_hasWhite) c = autoWhiteCalc(c);
|
||||||
if (Bus::_cct >= 1900) c = colorBalanceFromKelvin(Bus::_cct, c); //color correction from CCT
|
if (Bus::_cct >= 1900) c = colorBalanceFromKelvin(Bus::_cct, c); //color correction from CCT
|
||||||
unsigned offset = pix * _UDPchannels;
|
unsigned offset = pix * _UDPchannels;
|
||||||
_data[offset] = R(c);
|
_data[offset] = R(c);
|
||||||
_data[offset+1] = G(c);
|
_data[offset+1] = G(c);
|
||||||
_data[offset+2] = B(c);
|
_data[offset+2] = B(c);
|
||||||
if (_rgbw) _data[offset+3] = W(c);
|
if (_hasWhite) _data[offset+3] = W(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t BusNetwork::getPixelColor(uint16_t pix) {
|
uint32_t BusNetwork::getPixelColor(uint16_t pix) const {
|
||||||
if (!_valid || pix >= _len) return 0;
|
if (!_valid || pix >= _len) return 0;
|
||||||
unsigned offset = pix * _UDPchannels;
|
unsigned offset = pix * _UDPchannels;
|
||||||
return RGBW32(_data[offset], _data[offset+1], _data[offset+2], (_rgbw ? _data[offset+3] : 0));
|
return RGBW32(_data[offset], _data[offset+1], _data[offset+2], (hasWhite() ? _data[offset+3] : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BusNetwork::show() {
|
void BusNetwork::show() {
|
||||||
if (!_valid || !canShow()) return;
|
if (!_valid || !canShow()) return;
|
||||||
_broadcastLock = true;
|
_broadcastLock = true;
|
||||||
realtimeBroadcast(_UDPtype, _client, _len, _data, _bri, _rgbw);
|
realtimeBroadcast(_UDPtype, _client, _len, _data, _bri, hasWhite());
|
||||||
_broadcastLock = false;
|
_broadcastLock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t BusNetwork::getPins(uint8_t* pinArray) {
|
uint8_t BusNetwork::getPins(uint8_t* pinArray) const {
|
||||||
for (unsigned i = 0; i < 4; i++) {
|
if (pinArray) for (unsigned i = 0; i < 4; i++) pinArray[i] = _client[i];
|
||||||
pinArray[i] = _client[i];
|
|
||||||
}
|
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// credit @willmmiles & @netmindz https://github.com/Aircoookie/WLED/pull/4056
|
||||||
|
std::vector<LEDType> BusNetwork::getLEDTypes() {
|
||||||
|
return {
|
||||||
|
{TYPE_NET_DDP_RGB, "N", PSTR("DDP RGB (network)")}, // should be "NNNN" to determine 4 "pin" fields
|
||||||
|
{TYPE_NET_ARTNET_RGB, "N", PSTR("Art-Net RGB (network)")},
|
||||||
|
{TYPE_NET_DDP_RGBW, "N", PSTR("DDP RGBW (network)")},
|
||||||
|
{TYPE_NET_ARTNET_RGBW, "N", PSTR("Art-Net RGBW (network)")},
|
||||||
|
// hypothetical extensions
|
||||||
|
//{TYPE_VIRTUAL_I2C_W, "V", PSTR("I2C White (virtual)")}, // allows setting I2C address in _pin[0]
|
||||||
|
//{TYPE_VIRTUAL_I2C_CCT, "V", PSTR("I2C CCT (virtual)")}, // allows setting I2C address in _pin[0]
|
||||||
|
//{TYPE_VIRTUAL_I2C_RGB, "VVV", PSTR("I2C RGB (virtual)")}, // allows setting I2C address in _pin[0] and 2 additional values in _pin[1] & _pin[2]
|
||||||
|
//{TYPE_USERMOD, "VVVVV", PSTR("Usermod (virtual)")}, // 5 data fields (see https://github.com/Aircoookie/WLED/pull/4123)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void BusNetwork::cleanup() {
|
void BusNetwork::cleanup() {
|
||||||
_type = I_NONE;
|
_type = I_NONE;
|
||||||
_valid = false;
|
_valid = false;
|
||||||
@ -659,13 +787,13 @@ void BusNetwork::cleanup() {
|
|||||||
|
|
||||||
//utility to get the approx. memory usage of a given BusConfig
|
//utility to get the approx. memory usage of a given BusConfig
|
||||||
uint32_t BusManager::memUsage(BusConfig &bc) {
|
uint32_t BusManager::memUsage(BusConfig &bc) {
|
||||||
if (bc.type == TYPE_ONOFF || IS_PWM(bc.type)) return 5;
|
if (Bus::isOnOff(bc.type) || Bus::isPWM(bc.type)) return 5;
|
||||||
|
|
||||||
unsigned len = bc.count + bc.skipAmount;
|
unsigned len = bc.count + bc.skipAmount;
|
||||||
unsigned channels = Bus::getNumberOfChannels(bc.type);
|
unsigned channels = Bus::getNumberOfChannels(bc.type);
|
||||||
unsigned multiplier = 1;
|
unsigned multiplier = 1;
|
||||||
if (IS_DIGITAL(bc.type)) { // digital types
|
if (Bus::isDigital(bc.type)) { // digital types
|
||||||
if (IS_16BIT(bc.type)) len *= 2; // 16-bit LEDs
|
if (Bus::is16bit(bc.type)) len *= 2; // 16-bit LEDs
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
if (bc.pins[0] == 3) { //8266 DMA uses 5x the mem
|
if (bc.pins[0] == 3) { //8266 DMA uses 5x the mem
|
||||||
multiplier = 5;
|
multiplier = 5;
|
||||||
@ -685,11 +813,11 @@ uint32_t BusManager::memUsage(unsigned maxChannels, unsigned maxCount, unsigned
|
|||||||
|
|
||||||
int BusManager::add(BusConfig &bc) {
|
int BusManager::add(BusConfig &bc) {
|
||||||
if (getNumBusses() - getNumVirtualBusses() >= WLED_MAX_BUSSES) return -1;
|
if (getNumBusses() - getNumVirtualBusses() >= WLED_MAX_BUSSES) return -1;
|
||||||
if (IS_VIRTUAL(bc.type)) {
|
if (Bus::isVirtual(bc.type)) {
|
||||||
busses[numBusses] = new BusNetwork(bc);
|
busses[numBusses] = new BusNetwork(bc);
|
||||||
} else if (IS_DIGITAL(bc.type)) {
|
} else if (Bus::isDigital(bc.type)) {
|
||||||
busses[numBusses] = new BusDigital(bc, numBusses, colorOrderMap);
|
busses[numBusses] = new BusDigital(bc, numBusses, colorOrderMap);
|
||||||
} else if (bc.type == TYPE_ONOFF) {
|
} else if (Bus::isOnOff(bc.type)) {
|
||||||
busses[numBusses] = new BusOnOff(bc);
|
busses[numBusses] = new BusOnOff(bc);
|
||||||
} else {
|
} else {
|
||||||
busses[numBusses] = new BusPwm(bc);
|
busses[numBusses] = new BusPwm(bc);
|
||||||
@ -697,7 +825,32 @@ int BusManager::add(BusConfig &bc) {
|
|||||||
return numBusses++;
|
return numBusses++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BusManager::useParallelOutput(void) {
|
// credit @willmmiles
|
||||||
|
static String LEDTypesToJson(const std::vector<LEDType>& types) {
|
||||||
|
String json;
|
||||||
|
for (const auto &type : types) {
|
||||||
|
// capabilities follows similar pattern as JSON API
|
||||||
|
int capabilities = Bus::hasRGB(type.id) | Bus::hasWhite(type.id)<<1 | Bus::hasCCT(type.id)<<2 | Bus::is16bit(type.id)<<4;
|
||||||
|
char str[256];
|
||||||
|
sprintf_P(str, PSTR("{i:%d,c:%d,t:\"%s\",n:\"%s\"},"), type.id, capabilities, type.type, type.name);
|
||||||
|
json += str;
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
// credit @willmmiles & @netmindz https://github.com/Aircoookie/WLED/pull/4056
|
||||||
|
String BusManager::getLEDTypesJSONString() {
|
||||||
|
String json = "[";
|
||||||
|
json += LEDTypesToJson(BusDigital::getLEDTypes());
|
||||||
|
json += LEDTypesToJson(BusOnOff::getLEDTypes());
|
||||||
|
json += LEDTypesToJson(BusPwm::getLEDTypes());
|
||||||
|
json += LEDTypesToJson(BusNetwork::getLEDTypes());
|
||||||
|
//json += LEDTypesToJson(BusVirtual::getLEDTypes());
|
||||||
|
json.setCharAt(json.length()-1, ']'); // replace last comma with bracket
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BusManager::useParallelOutput() {
|
||||||
_parallelOutputs = 8; // hardcoded since we use NPB I2S x8 methods
|
_parallelOutputs = 8; // hardcoded since we use NPB I2S x8 methods
|
||||||
PolyBus::setParallelI2S1Output();
|
PolyBus::setParallelI2S1Output();
|
||||||
}
|
}
|
||||||
@ -735,7 +888,7 @@ void BusManager::esp32RMTInvertIdle() {
|
|||||||
if (u >= _parallelOutputs + 8) return; // only 8 RMT channels
|
if (u >= _parallelOutputs + 8) return; // only 8 RMT channels
|
||||||
rmt = u - _parallelOutputs;
|
rmt = u - _parallelOutputs;
|
||||||
#endif
|
#endif
|
||||||
if (busses[u]->getLength()==0 || !IS_DIGITAL(busses[u]->getType()) || IS_2PIN(busses[u]->getType())) continue;
|
if (busses[u]->getLength()==0 || !busses[u]->isDigital() || busses[u]->is2Pin()) continue;
|
||||||
//assumes that bus number to rmt channel mapping stays 1:1
|
//assumes that bus number to rmt channel mapping stays 1:1
|
||||||
rmt_channel_t ch = static_cast<rmt_channel_t>(rmt);
|
rmt_channel_t ch = static_cast<rmt_channel_t>(rmt);
|
||||||
rmt_idle_level_t lvl;
|
rmt_idle_level_t lvl;
|
||||||
@ -754,7 +907,7 @@ void BusManager::on() {
|
|||||||
if (pinManager.getPinOwner(LED_BUILTIN) == PinOwner::BusDigital) {
|
if (pinManager.getPinOwner(LED_BUILTIN) == PinOwner::BusDigital) {
|
||||||
for (unsigned i = 0; i < numBusses; i++) {
|
for (unsigned i = 0; i < numBusses; i++) {
|
||||||
uint8_t pins[2] = {255,255};
|
uint8_t pins[2] = {255,255};
|
||||||
if (IS_DIGITAL(busses[i]->getType()) && busses[i]->getPins(pins)) {
|
if (busses[i]->isDigital() && busses[i]->getPins(pins)) {
|
||||||
if (pins[0] == LED_BUILTIN || pins[1] == LED_BUILTIN) {
|
if (pins[0] == LED_BUILTIN || pins[1] == LED_BUILTIN) {
|
||||||
BusDigital *bus = static_cast<BusDigital*>(busses[i]);
|
BusDigital *bus = static_cast<BusDigital*>(busses[i]);
|
||||||
bus->reinit();
|
bus->reinit();
|
||||||
@ -825,7 +978,7 @@ void BusManager::setSegmentCCT(int16_t cct, bool allowWBCorrection) {
|
|||||||
uint32_t BusManager::getPixelColor(uint16_t pix) {
|
uint32_t BusManager::getPixelColor(uint16_t pix) {
|
||||||
for (unsigned i = 0; i < numBusses; i++) {
|
for (unsigned i = 0; i < numBusses; i++) {
|
||||||
unsigned bstart = busses[i]->getStart();
|
unsigned bstart = busses[i]->getStart();
|
||||||
if (pix < bstart || pix >= bstart + busses[i]->getLength()) continue;
|
if (!busses[i]->containsPixel(pix)) continue;
|
||||||
return busses[i]->getPixelColor(pix - bstart);
|
return busses[i]->getPixelColor(pix - bstart);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
//colors.cpp
|
//colors.cpp
|
||||||
uint16_t approximateKelvinFromRGB(uint32_t rgb);
|
uint16_t approximateKelvinFromRGB(uint32_t rgb);
|
||||||
@ -21,6 +22,296 @@ uint16_t approximateKelvinFromRGB(uint32_t rgb);
|
|||||||
#define IC_INDEX_WS2812_2CH_3X(i) ((i)*2/3)
|
#define IC_INDEX_WS2812_2CH_3X(i) ((i)*2/3)
|
||||||
#define WS2812_2CH_3X_SPANS_2_ICS(i) ((i)&0x01) // every other LED zone is on two different ICs
|
#define WS2812_2CH_3X_SPANS_2_ICS(i) ((i)&0x01) // every other LED zone is on two different ICs
|
||||||
|
|
||||||
|
struct BusConfig; // forward declaration
|
||||||
|
|
||||||
|
// Defines an LED Strip and its color ordering.
|
||||||
|
typedef struct {
|
||||||
|
uint16_t start;
|
||||||
|
uint16_t len;
|
||||||
|
uint8_t colorOrder;
|
||||||
|
} ColorOrderMapEntry;
|
||||||
|
|
||||||
|
struct ColorOrderMap {
|
||||||
|
bool add(uint16_t start, uint16_t len, uint8_t colorOrder);
|
||||||
|
|
||||||
|
inline uint8_t count() const { return _mappings.size(); }
|
||||||
|
inline void reserve(size_t num) { _mappings.reserve(num); }
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
_mappings.clear();
|
||||||
|
_mappings.shrink_to_fit();
|
||||||
|
}
|
||||||
|
|
||||||
|
const ColorOrderMapEntry* get(uint8_t n) const {
|
||||||
|
if (n >= count()) return nullptr;
|
||||||
|
return &(_mappings[n]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[gnu::hot]] uint8_t getPixelColorOrder(uint16_t pix, uint8_t defaultColorOrder) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<ColorOrderMapEntry> _mappings;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t id;
|
||||||
|
const char *type;
|
||||||
|
const char *name;
|
||||||
|
} LEDType;
|
||||||
|
|
||||||
|
|
||||||
|
//parent class of BusDigital, BusPwm, and BusNetwork
|
||||||
|
class Bus {
|
||||||
|
public:
|
||||||
|
Bus(uint8_t type, uint16_t start, uint8_t aw, uint16_t len = 1, bool reversed = false, bool refresh = false)
|
||||||
|
: _type(type)
|
||||||
|
, _bri(255)
|
||||||
|
, _start(start)
|
||||||
|
, _len(len)
|
||||||
|
, _reversed(reversed)
|
||||||
|
, _valid(false)
|
||||||
|
, _needsRefresh(refresh)
|
||||||
|
, _data(nullptr) // keep data access consistent across all types of buses
|
||||||
|
{
|
||||||
|
_autoWhiteMode = Bus::hasWhite(type) ? aw : RGBW_MODE_MANUAL_ONLY;
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual ~Bus() {} //throw the bus under the bus
|
||||||
|
|
||||||
|
virtual void show() = 0;
|
||||||
|
virtual bool canShow() const { return true; }
|
||||||
|
virtual void setStatusPixel(uint32_t c) {}
|
||||||
|
virtual void setPixelColor(uint16_t pix, uint32_t c) = 0;
|
||||||
|
virtual void setBrightness(uint8_t b) { _bri = b; };
|
||||||
|
virtual void setColorOrder(uint8_t co) {}
|
||||||
|
virtual uint32_t getPixelColor(uint16_t pix) const { return 0; }
|
||||||
|
virtual uint8_t getPins(uint8_t* pinArray = nullptr) const { return 0; }
|
||||||
|
virtual uint16_t getLength() const { return isOk() ? _len : 0; }
|
||||||
|
virtual uint8_t getColorOrder() const { return COL_ORDER_RGB; }
|
||||||
|
virtual uint8_t skippedLeds() const { return 0; }
|
||||||
|
virtual uint16_t getFrequency() const { return 0U; }
|
||||||
|
virtual uint16_t getLEDCurrent() const { return 0; }
|
||||||
|
virtual uint16_t getUsedCurrent() const { return 0; }
|
||||||
|
virtual uint16_t getMaxCurrent() const { return 0; }
|
||||||
|
|
||||||
|
inline bool hasRGB() const { return _hasRgb; }
|
||||||
|
inline bool hasWhite() const { return _hasWhite; }
|
||||||
|
inline bool hasCCT() const { return _hasCCT; }
|
||||||
|
inline bool isDigital() const { return isDigital(_type); }
|
||||||
|
inline bool is2Pin() const { return is2Pin(_type); }
|
||||||
|
inline bool isOnOff() const { return isOnOff(_type); }
|
||||||
|
inline bool isPWM() const { return isPWM(_type); }
|
||||||
|
inline bool isVirtual() const { return isVirtual(_type); }
|
||||||
|
inline bool is16bit() const { return is16bit(_type); }
|
||||||
|
inline void setReversed(bool reversed) { _reversed = reversed; }
|
||||||
|
inline void setStart(uint16_t start) { _start = start; }
|
||||||
|
inline void setAutoWhiteMode(uint8_t m) { if (m < 5) _autoWhiteMode = m; }
|
||||||
|
inline uint8_t getAutoWhiteMode() const { return _autoWhiteMode; }
|
||||||
|
inline uint8_t getNumberOfChannels() const { return hasWhite() + 3*hasRGB() + hasCCT(); }
|
||||||
|
inline uint16_t getStart() const { return _start; }
|
||||||
|
inline uint8_t getType() const { return _type; }
|
||||||
|
inline bool isOk() const { return _valid; }
|
||||||
|
inline bool isReversed() const { return _reversed; }
|
||||||
|
inline bool isOffRefreshRequired() const { return _needsRefresh; }
|
||||||
|
inline bool containsPixel(uint16_t pix) const { return pix >= _start && pix < _start + _len; }
|
||||||
|
|
||||||
|
static inline std::vector<LEDType> getLEDTypes() { return {{TYPE_NONE, "", PSTR("None")}}; } // not used. just for reference for derived classes
|
||||||
|
static constexpr uint8_t getNumberOfPins(uint8_t type) { return isVirtual(type) ? 4 : isPWM(type) ? numPWMPins(type) : is2Pin(type) + 1; } // credit @PaoloTK
|
||||||
|
static constexpr uint8_t getNumberOfChannels(uint8_t type) { return hasWhite(type) + 3*hasRGB(type) + hasCCT(type); }
|
||||||
|
static constexpr bool hasRGB(uint8_t type) {
|
||||||
|
return !((type >= TYPE_WS2812_1CH && type <= TYPE_WS2812_WWA) || type == TYPE_ANALOG_1CH || type == TYPE_ANALOG_2CH || type == TYPE_ONOFF);
|
||||||
|
}
|
||||||
|
static constexpr bool hasWhite(uint8_t type) {
|
||||||
|
return (type >= TYPE_WS2812_1CH && type <= TYPE_WS2812_WWA) ||
|
||||||
|
type == TYPE_SK6812_RGBW || type == TYPE_TM1814 || type == TYPE_UCS8904 ||
|
||||||
|
type == TYPE_FW1906 || type == TYPE_WS2805 || type == TYPE_SM16825 || // digital types with white channel
|
||||||
|
(type > TYPE_ONOFF && type <= TYPE_ANALOG_5CH && type != TYPE_ANALOG_3CH) || // analog types with white channel
|
||||||
|
type == TYPE_NET_DDP_RGBW || type == TYPE_NET_ARTNET_RGBW; // network types with white channel
|
||||||
|
}
|
||||||
|
static constexpr bool hasCCT(uint8_t type) {
|
||||||
|
return type == TYPE_WS2812_2CH_X3 || type == TYPE_WS2812_WWA ||
|
||||||
|
type == TYPE_ANALOG_2CH || type == TYPE_ANALOG_5CH ||
|
||||||
|
type == TYPE_FW1906 || type == TYPE_WS2805 ||
|
||||||
|
type == TYPE_SM16825;
|
||||||
|
}
|
||||||
|
static constexpr bool isTypeValid(uint8_t type) { return (type > 15 && type < 128); }
|
||||||
|
static constexpr bool isDigital(uint8_t type) { return (type >= TYPE_DIGITAL_MIN && type <= TYPE_DIGITAL_MAX) || is2Pin(type); }
|
||||||
|
static constexpr bool is2Pin(uint8_t type) { return (type >= TYPE_2PIN_MIN && type <= TYPE_2PIN_MAX); }
|
||||||
|
static constexpr bool isOnOff(uint8_t type) { return (type == TYPE_ONOFF); }
|
||||||
|
static constexpr bool isPWM(uint8_t type) { return (type >= TYPE_ANALOG_MIN && type <= TYPE_ANALOG_MAX); }
|
||||||
|
static constexpr bool isVirtual(uint8_t type) { return (type >= TYPE_VIRTUAL_MIN && type <= TYPE_VIRTUAL_MAX); }
|
||||||
|
static constexpr bool is16bit(uint8_t type) { return type == TYPE_UCS8903 || type == TYPE_UCS8904 || type == TYPE_SM16825; }
|
||||||
|
static constexpr int numPWMPins(uint8_t type) { return (type - 40); }
|
||||||
|
|
||||||
|
static inline int16_t getCCT() { return _cct; }
|
||||||
|
static inline void setGlobalAWMode(uint8_t m) { if (m < 5) _gAWM = m; else _gAWM = AW_GLOBAL_DISABLED; }
|
||||||
|
static inline uint8_t getGlobalAWMode() { return _gAWM; }
|
||||||
|
static inline void setCCT(int16_t cct) { _cct = cct; }
|
||||||
|
static inline uint8_t getCCTBlend() { return _cctBlend; }
|
||||||
|
static inline void setCCTBlend(uint8_t b) {
|
||||||
|
_cctBlend = (std::min((int)b,100) * 127) / 100;
|
||||||
|
//compile-time limiter for hardware that can't power both white channels at max
|
||||||
|
#ifdef WLED_MAX_CCT_BLEND
|
||||||
|
if (_cctBlend > WLED_MAX_CCT_BLEND) _cctBlend = WLED_MAX_CCT_BLEND;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
static void calculateCCT(uint32_t c, uint8_t &ww, uint8_t &cw);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
uint8_t _type;
|
||||||
|
uint8_t _bri;
|
||||||
|
uint16_t _start;
|
||||||
|
uint16_t _len;
|
||||||
|
//struct { //using bitfield struct adds abour 250 bytes to binary size
|
||||||
|
bool _reversed;// : 1;
|
||||||
|
bool _valid;// : 1;
|
||||||
|
bool _needsRefresh;// : 1;
|
||||||
|
bool _hasRgb;// : 1;
|
||||||
|
bool _hasWhite;// : 1;
|
||||||
|
bool _hasCCT;// : 1;
|
||||||
|
//} __attribute__ ((packed));
|
||||||
|
uint8_t _autoWhiteMode;
|
||||||
|
uint8_t *_data;
|
||||||
|
// global Auto White Calculation override
|
||||||
|
static uint8_t _gAWM;
|
||||||
|
// _cct has the following menaings (see calculateCCT() & BusManager::setSegmentCCT()):
|
||||||
|
// -1 means to extract approximate CCT value in K from RGB (in calcualteCCT())
|
||||||
|
// [0,255] is the exact CCT value where 0 means warm and 255 cold
|
||||||
|
// [1900,10060] only for color correction expressed in K (colorBalanceFromKelvin())
|
||||||
|
static int16_t _cct;
|
||||||
|
// _cctBlend determines WW/CW blending:
|
||||||
|
// 0 - linear (CCT 127 => 50% warm, 50% cold)
|
||||||
|
// 63 - semi additive/nonlinear (CCT 127 => 66% warm, 66% cold)
|
||||||
|
// 127 - additive CCT blending (CCT 127 => 100% warm, 100% cold)
|
||||||
|
static uint8_t _cctBlend;
|
||||||
|
|
||||||
|
uint32_t autoWhiteCalc(uint32_t c) const;
|
||||||
|
uint8_t *allocateData(size_t size = 1);
|
||||||
|
void freeData() { if (_data != nullptr) free(_data); _data = nullptr; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class BusDigital : public Bus {
|
||||||
|
public:
|
||||||
|
BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com);
|
||||||
|
~BusDigital() { cleanup(); }
|
||||||
|
|
||||||
|
void show() override;
|
||||||
|
bool canShow() const override;
|
||||||
|
void setBrightness(uint8_t b) override;
|
||||||
|
void setStatusPixel(uint32_t c) override;
|
||||||
|
[[gnu::hot]] void setPixelColor(uint16_t pix, uint32_t c) override;
|
||||||
|
void setColorOrder(uint8_t colorOrder) override;
|
||||||
|
[[gnu::hot]] uint32_t getPixelColor(uint16_t pix) const override;
|
||||||
|
uint8_t getColorOrder() const override { return _colorOrder; }
|
||||||
|
uint8_t getPins(uint8_t* pinArray = nullptr) const override;
|
||||||
|
uint8_t skippedLeds() const override { return _skip; }
|
||||||
|
uint16_t getFrequency() const override { return _frequencykHz; }
|
||||||
|
uint16_t getLEDCurrent() const override { return _milliAmpsPerLed; }
|
||||||
|
uint16_t getUsedCurrent() const override { return _milliAmpsTotal; }
|
||||||
|
uint16_t getMaxCurrent() const override { return _milliAmpsMax; }
|
||||||
|
void reinit();
|
||||||
|
void cleanup();
|
||||||
|
|
||||||
|
static std::vector<LEDType> getLEDTypes();
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t _skip;
|
||||||
|
uint8_t _colorOrder;
|
||||||
|
uint8_t _pins[2];
|
||||||
|
uint8_t _iType;
|
||||||
|
uint16_t _frequencykHz;
|
||||||
|
uint8_t _milliAmpsPerLed;
|
||||||
|
uint16_t _milliAmpsMax;
|
||||||
|
void * _busPtr;
|
||||||
|
const ColorOrderMap &_colorOrderMap;
|
||||||
|
|
||||||
|
static uint16_t _milliAmpsTotal; // is overwitten/recalculated on each show()
|
||||||
|
|
||||||
|
inline uint32_t restoreColorLossy(uint32_t c, uint8_t restoreBri) const {
|
||||||
|
if (restoreBri < 255) {
|
||||||
|
uint8_t* chan = (uint8_t*) &c;
|
||||||
|
for (uint_fast8_t i=0; i<4; i++) {
|
||||||
|
uint_fast16_t val = chan[i];
|
||||||
|
chan[i] = ((val << 8) + restoreBri) / (restoreBri + 1); //adding _bri slightly improves recovery / stops degradation on re-scale
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t estimateCurrentAndLimitBri();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class BusPwm : public Bus {
|
||||||
|
public:
|
||||||
|
BusPwm(BusConfig &bc);
|
||||||
|
~BusPwm() { cleanup(); }
|
||||||
|
|
||||||
|
void setPixelColor(uint16_t pix, uint32_t c) override;
|
||||||
|
uint32_t getPixelColor(uint16_t pix) const override; //does no index check
|
||||||
|
uint8_t getPins(uint8_t* pinArray = nullptr) const override;
|
||||||
|
uint16_t getFrequency() const override { return _frequency; }
|
||||||
|
void show() override;
|
||||||
|
void cleanup() { deallocatePins(); }
|
||||||
|
|
||||||
|
static std::vector<LEDType> getLEDTypes();
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t _pins[5];
|
||||||
|
uint8_t _pwmdata[5];
|
||||||
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
|
uint8_t _ledcStart;
|
||||||
|
#endif
|
||||||
|
uint8_t _depth;
|
||||||
|
uint16_t _frequency;
|
||||||
|
|
||||||
|
void deallocatePins();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class BusOnOff : public Bus {
|
||||||
|
public:
|
||||||
|
BusOnOff(BusConfig &bc);
|
||||||
|
~BusOnOff() { cleanup(); }
|
||||||
|
|
||||||
|
void setPixelColor(uint16_t pix, uint32_t c) override;
|
||||||
|
uint32_t getPixelColor(uint16_t pix) const override;
|
||||||
|
uint8_t getPins(uint8_t* pinArray) const override;
|
||||||
|
void show() override;
|
||||||
|
void cleanup() { pinManager.deallocatePin(_pin, PinOwner::BusOnOff); }
|
||||||
|
|
||||||
|
static std::vector<LEDType> getLEDTypes();
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t _pin;
|
||||||
|
uint8_t _onoffdata;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class BusNetwork : public Bus {
|
||||||
|
public:
|
||||||
|
BusNetwork(BusConfig &bc);
|
||||||
|
~BusNetwork() { cleanup(); }
|
||||||
|
|
||||||
|
bool canShow() const override { return !_broadcastLock; } // this should be a return value from UDP routine if it is still sending data out
|
||||||
|
void setPixelColor(uint16_t pix, uint32_t c) override;
|
||||||
|
uint32_t getPixelColor(uint16_t pix) const override;
|
||||||
|
uint8_t getPins(uint8_t* pinArray = nullptr) const override;
|
||||||
|
void show() override;
|
||||||
|
void cleanup();
|
||||||
|
|
||||||
|
static std::vector<LEDType> getLEDTypes();
|
||||||
|
|
||||||
|
private:
|
||||||
|
IPAddress _client;
|
||||||
|
uint8_t _UDPtype;
|
||||||
|
uint8_t _UDPchannels;
|
||||||
|
bool _broadcastLock;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//temporary struct for passing bus configuration to bus
|
//temporary struct for passing bus configuration to bus
|
||||||
struct BusConfig {
|
struct BusConfig {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
@ -51,10 +342,7 @@ struct BusConfig {
|
|||||||
{
|
{
|
||||||
refreshReq = (bool) GET_BIT(busType,7);
|
refreshReq = (bool) GET_BIT(busType,7);
|
||||||
type = busType & 0x7F; // bit 7 may be/is hacked to include refresh info (1=refresh in off state, 0=no refresh)
|
type = busType & 0x7F; // bit 7 may be/is hacked to include refresh info (1=refresh in off state, 0=no refresh)
|
||||||
size_t nPins = 1;
|
size_t nPins = Bus::getNumberOfPins(type);
|
||||||
if (IS_VIRTUAL(type)) nPins = 4; //virtual network bus. 4 "pins" store IP address
|
|
||||||
else if (IS_2PIN(type)) nPins = 2;
|
|
||||||
else if (IS_PWM(type)) nPins = NUM_PWM_PINS(type);
|
|
||||||
for (size_t i = 0; i < nPins; i++) pins[i] = ppins[i];
|
for (size_t i = 0; i < nPins; i++) pins[i] = ppins[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,285 +360,6 @@ struct BusConfig {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Defines an LED Strip and its color ordering.
|
|
||||||
struct ColorOrderMapEntry {
|
|
||||||
uint16_t start;
|
|
||||||
uint16_t len;
|
|
||||||
uint8_t colorOrder;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ColorOrderMap {
|
|
||||||
void add(uint16_t start, uint16_t len, uint8_t colorOrder);
|
|
||||||
|
|
||||||
uint8_t count() const { return _count; }
|
|
||||||
|
|
||||||
void reset() {
|
|
||||||
_count = 0;
|
|
||||||
memset(_mappings, 0, sizeof(_mappings));
|
|
||||||
}
|
|
||||||
|
|
||||||
const ColorOrderMapEntry* get(uint8_t n) const {
|
|
||||||
if (n > _count) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return &(_mappings[n]);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t getPixelColorOrder(uint16_t pix, uint8_t defaultColorOrder) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint8_t _count;
|
|
||||||
ColorOrderMapEntry _mappings[WLED_MAX_COLOR_ORDER_MAPPINGS];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//parent class of BusDigital, BusPwm, and BusNetwork
|
|
||||||
class Bus {
|
|
||||||
public:
|
|
||||||
Bus(uint8_t type, uint16_t start, uint8_t aw, uint16_t len = 1, bool reversed = false, bool refresh = false)
|
|
||||||
: _type(type)
|
|
||||||
, _bri(255)
|
|
||||||
, _start(start)
|
|
||||||
, _len(len)
|
|
||||||
, _reversed(reversed)
|
|
||||||
, _valid(false)
|
|
||||||
, _needsRefresh(refresh)
|
|
||||||
, _data(nullptr) // keep data access consistent across all types of buses
|
|
||||||
{
|
|
||||||
_autoWhiteMode = Bus::hasWhite(type) ? aw : RGBW_MODE_MANUAL_ONLY;
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual ~Bus() {} //throw the bus under the bus
|
|
||||||
|
|
||||||
virtual void show() = 0;
|
|
||||||
virtual bool canShow() { return true; }
|
|
||||||
virtual void setStatusPixel(uint32_t c) {}
|
|
||||||
virtual void setPixelColor(uint16_t pix, uint32_t c) = 0;
|
|
||||||
virtual uint32_t getPixelColor(uint16_t pix) { return 0; }
|
|
||||||
virtual void setBrightness(uint8_t b) { _bri = b; };
|
|
||||||
virtual uint8_t getPins(uint8_t* pinArray) { return 0; }
|
|
||||||
virtual uint16_t getLength() { return isOk() ? _len : 0; }
|
|
||||||
virtual void setColorOrder(uint8_t co) {}
|
|
||||||
virtual uint8_t getColorOrder() { return COL_ORDER_RGB; }
|
|
||||||
virtual uint8_t skippedLeds() { return 0; }
|
|
||||||
virtual uint16_t getFrequency() { return 0U; }
|
|
||||||
virtual uint16_t getLEDCurrent() { return 0; }
|
|
||||||
virtual uint16_t getUsedCurrent() { return 0; }
|
|
||||||
virtual uint16_t getMaxCurrent() { return 0; }
|
|
||||||
virtual uint8_t getNumberOfChannels() { return hasWhite(_type) + 3*hasRGB(_type) + hasCCT(_type); }
|
|
||||||
static inline uint8_t getNumberOfChannels(uint8_t type) { return hasWhite(type) + 3*hasRGB(type) + hasCCT(type); }
|
|
||||||
inline void setReversed(bool reversed) { _reversed = reversed; }
|
|
||||||
inline uint16_t getStart() { return _start; }
|
|
||||||
inline void setStart(uint16_t start) { _start = start; }
|
|
||||||
inline uint8_t getType() { return _type; }
|
|
||||||
inline bool isOk() { return _valid; }
|
|
||||||
inline bool isReversed() { return _reversed; }
|
|
||||||
inline bool isOffRefreshRequired() { return _needsRefresh; }
|
|
||||||
bool containsPixel(uint16_t pix) { return pix >= _start && pix < _start+_len; }
|
|
||||||
|
|
||||||
virtual bool hasRGB(void) { return Bus::hasRGB(_type); }
|
|
||||||
static bool hasRGB(uint8_t type) {
|
|
||||||
if ((type >= TYPE_WS2812_1CH && type <= TYPE_WS2812_WWA) || type == TYPE_ANALOG_1CH || type == TYPE_ANALOG_2CH || type == TYPE_ONOFF) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
virtual bool hasWhite(void) { return Bus::hasWhite(_type); }
|
|
||||||
static bool hasWhite(uint8_t type) {
|
|
||||||
if ((type >= TYPE_WS2812_1CH && type <= TYPE_WS2812_WWA) ||
|
|
||||||
type == TYPE_SK6812_RGBW || type == TYPE_TM1814 || type == TYPE_UCS8904 ||
|
|
||||||
type == TYPE_FW1906 || type == TYPE_WS2805 || type == TYPE_SM16825) return true; // digital types with white channel
|
|
||||||
if (type > TYPE_ONOFF && type <= TYPE_ANALOG_5CH && type != TYPE_ANALOG_3CH) return true; // analog types with white channel
|
|
||||||
if (type == TYPE_NET_DDP_RGBW || type == TYPE_NET_ARTNET_RGBW) return true; // network types with white channel
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
virtual bool hasCCT(void) { return Bus::hasCCT(_type); }
|
|
||||||
static bool hasCCT(uint8_t type) {
|
|
||||||
if (type == TYPE_WS2812_2CH_X3 || type == TYPE_WS2812_WWA ||
|
|
||||||
type == TYPE_ANALOG_2CH || type == TYPE_ANALOG_5CH ||
|
|
||||||
type == TYPE_FW1906 || type == TYPE_WS2805 ||
|
|
||||||
type == TYPE_SM16825) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
static inline int16_t getCCT() { return _cct; }
|
|
||||||
static void setCCT(int16_t cct) {
|
|
||||||
_cct = cct;
|
|
||||||
}
|
|
||||||
static inline uint8_t getCCTBlend() { return _cctBlend; }
|
|
||||||
static void setCCTBlend(uint8_t b) {
|
|
||||||
if (b > 100) b = 100;
|
|
||||||
_cctBlend = (b * 127) / 100;
|
|
||||||
//compile-time limiter for hardware that can't power both white channels at max
|
|
||||||
#ifdef WLED_MAX_CCT_BLEND
|
|
||||||
if (_cctBlend > WLED_MAX_CCT_BLEND) _cctBlend = WLED_MAX_CCT_BLEND;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
static void calculateCCT(uint32_t c, uint8_t &ww, uint8_t &cw) {
|
|
||||||
uint8_t cct = 0; //0 - full warm white, 255 - full cold white
|
|
||||||
uint8_t w = byte(c >> 24);
|
|
||||||
|
|
||||||
if (_cct > -1) {
|
|
||||||
if (_cct >= 1900) cct = (_cct - 1900) >> 5;
|
|
||||||
else if (_cct < 256) cct = _cct;
|
|
||||||
} else {
|
|
||||||
cct = (approximateKelvinFromRGB(c) - 1900) >> 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
//0 - linear (CCT 127 = 50% warm, 50% cold), 127 - additive CCT blending (CCT 127 = 100% warm, 100% cold)
|
|
||||||
if (cct < _cctBlend) ww = 255;
|
|
||||||
else ww = ((255-cct) * 255) / (255 - _cctBlend);
|
|
||||||
if ((255-cct) < _cctBlend) cw = 255;
|
|
||||||
else cw = (cct * 255) / (255 - _cctBlend);
|
|
||||||
|
|
||||||
ww = (w * ww) / 255; //brightness scaling
|
|
||||||
cw = (w * cw) / 255;
|
|
||||||
}
|
|
||||||
inline void setAutoWhiteMode(uint8_t m) { if (m < 5) _autoWhiteMode = m; }
|
|
||||||
inline uint8_t getAutoWhiteMode() { return _autoWhiteMode; }
|
|
||||||
inline static void setGlobalAWMode(uint8_t m) { if (m < 5) _gAWM = m; else _gAWM = AW_GLOBAL_DISABLED; }
|
|
||||||
inline static uint8_t getGlobalAWMode() { return _gAWM; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
uint8_t _type;
|
|
||||||
uint8_t _bri;
|
|
||||||
uint16_t _start;
|
|
||||||
uint16_t _len;
|
|
||||||
bool _reversed;
|
|
||||||
bool _valid;
|
|
||||||
bool _needsRefresh;
|
|
||||||
uint8_t _autoWhiteMode;
|
|
||||||
uint8_t *_data;
|
|
||||||
// global Auto White Calculation override
|
|
||||||
static uint8_t _gAWM;
|
|
||||||
// _cct has the following menaings (see calculateCCT() & BusManager::setSegmentCCT()):
|
|
||||||
// -1 means to extract approximate CCT value in K from RGB (in calcualteCCT())
|
|
||||||
// [0,255] is the exact CCT value where 0 means warm and 255 cold
|
|
||||||
// [1900,10060] only for color correction expressed in K (colorBalanceFromKelvin())
|
|
||||||
static int16_t _cct;
|
|
||||||
// _cctBlend determines WW/CW blending:
|
|
||||||
// 0 - linear (CCT 127 => 50% warm, 50% cold)
|
|
||||||
// 63 - semi additive/nonlinear (CCT 127 => 66% warm, 66% cold)
|
|
||||||
// 127 - additive CCT blending (CCT 127 => 100% warm, 100% cold)
|
|
||||||
static uint8_t _cctBlend;
|
|
||||||
|
|
||||||
uint32_t autoWhiteCalc(uint32_t c);
|
|
||||||
uint8_t *allocData(size_t size = 1);
|
|
||||||
void freeData() { if (_data != nullptr) free(_data); _data = nullptr; }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class BusDigital : public Bus {
|
|
||||||
public:
|
|
||||||
BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com);
|
|
||||||
~BusDigital() { cleanup(); }
|
|
||||||
|
|
||||||
void show() override;
|
|
||||||
bool canShow() override;
|
|
||||||
void setBrightness(uint8_t b) override;
|
|
||||||
void setStatusPixel(uint32_t c) override;
|
|
||||||
void setPixelColor(uint16_t pix, uint32_t c) override;
|
|
||||||
void setColorOrder(uint8_t colorOrder) override;
|
|
||||||
uint32_t getPixelColor(uint16_t pix) override;
|
|
||||||
uint8_t getColorOrder() override { return _colorOrder; }
|
|
||||||
uint8_t getPins(uint8_t* pinArray) override;
|
|
||||||
uint8_t skippedLeds() override { return _skip; }
|
|
||||||
uint16_t getFrequency() override { return _frequencykHz; }
|
|
||||||
uint8_t estimateCurrentAndLimitBri();
|
|
||||||
uint16_t getLEDCurrent() override { return _milliAmpsPerLed; }
|
|
||||||
uint16_t getUsedCurrent() override { return _milliAmpsTotal; }
|
|
||||||
uint16_t getMaxCurrent() override { return _milliAmpsMax; }
|
|
||||||
void reinit();
|
|
||||||
void cleanup();
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint8_t _skip;
|
|
||||||
uint8_t _colorOrder;
|
|
||||||
uint8_t _pins[2];
|
|
||||||
uint8_t _iType;
|
|
||||||
uint16_t _frequencykHz;
|
|
||||||
uint8_t _milliAmpsPerLed;
|
|
||||||
uint16_t _milliAmpsMax;
|
|
||||||
void * _busPtr;
|
|
||||||
const ColorOrderMap &_colorOrderMap;
|
|
||||||
|
|
||||||
static uint16_t _milliAmpsTotal; // is overwitten/recalculated on each show()
|
|
||||||
|
|
||||||
inline uint32_t restoreColorLossy(uint32_t c, uint8_t restoreBri) {
|
|
||||||
if (restoreBri < 255) {
|
|
||||||
uint8_t* chan = (uint8_t*) &c;
|
|
||||||
for (uint_fast8_t i=0; i<4; i++) {
|
|
||||||
uint_fast16_t val = chan[i];
|
|
||||||
chan[i] = ((val << 8) + restoreBri) / (restoreBri + 1); //adding _bri slightly improves recovery / stops degradation on re-scale
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class BusPwm : public Bus {
|
|
||||||
public:
|
|
||||||
BusPwm(BusConfig &bc);
|
|
||||||
~BusPwm() { cleanup(); }
|
|
||||||
|
|
||||||
void setPixelColor(uint16_t pix, uint32_t c) override;
|
|
||||||
uint32_t getPixelColor(uint16_t pix) override; //does no index check
|
|
||||||
uint8_t getPins(uint8_t* pinArray) override;
|
|
||||||
uint16_t getFrequency() override { return _frequency; }
|
|
||||||
void show() override;
|
|
||||||
void cleanup() { deallocatePins(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint8_t _pins[5];
|
|
||||||
uint8_t _pwmdata[5];
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
|
||||||
uint8_t _ledcStart;
|
|
||||||
#endif
|
|
||||||
uint8_t _depth;
|
|
||||||
uint16_t _frequency;
|
|
||||||
|
|
||||||
void deallocatePins();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class BusOnOff : public Bus {
|
|
||||||
public:
|
|
||||||
BusOnOff(BusConfig &bc);
|
|
||||||
~BusOnOff() { cleanup(); }
|
|
||||||
|
|
||||||
void setPixelColor(uint16_t pix, uint32_t c) override;
|
|
||||||
uint32_t getPixelColor(uint16_t pix) override;
|
|
||||||
uint8_t getPins(uint8_t* pinArray) override;
|
|
||||||
void show() override;
|
|
||||||
void cleanup() { pinManager.deallocatePin(_pin, PinOwner::BusOnOff); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint8_t _pin;
|
|
||||||
uint8_t _onoffdata;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class BusNetwork : public Bus {
|
|
||||||
public:
|
|
||||||
BusNetwork(BusConfig &bc);
|
|
||||||
~BusNetwork() { cleanup(); }
|
|
||||||
|
|
||||||
bool hasRGB() override { return true; }
|
|
||||||
bool hasWhite() override { return _rgbw; }
|
|
||||||
bool canShow() override { return !_broadcastLock; } // this should be a return value from UDP routine if it is still sending data out
|
|
||||||
void setPixelColor(uint16_t pix, uint32_t c) override;
|
|
||||||
uint32_t getPixelColor(uint16_t pix) override;
|
|
||||||
uint8_t getPins(uint8_t* pinArray) override;
|
|
||||||
void show() override;
|
|
||||||
void cleanup();
|
|
||||||
|
|
||||||
private:
|
|
||||||
IPAddress _client;
|
|
||||||
uint8_t _UDPtype;
|
|
||||||
uint8_t _UDPchannels;
|
|
||||||
bool _rgbw;
|
|
||||||
bool _broadcastLock;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class BusManager {
|
class BusManager {
|
||||||
public:
|
public:
|
||||||
BusManager() {};
|
BusManager() {};
|
||||||
@ -358,27 +367,27 @@ class BusManager {
|
|||||||
//utility to get the approx. memory usage of a given BusConfig
|
//utility to get the approx. memory usage of a given BusConfig
|
||||||
static uint32_t memUsage(BusConfig &bc);
|
static uint32_t memUsage(BusConfig &bc);
|
||||||
static uint32_t memUsage(unsigned channels, unsigned count, unsigned buses = 1);
|
static uint32_t memUsage(unsigned channels, unsigned count, unsigned buses = 1);
|
||||||
static uint16_t currentMilliamps(void) { return _milliAmpsUsed; }
|
static uint16_t currentMilliamps() { return _milliAmpsUsed; }
|
||||||
static uint16_t ablMilliampsMax(void) { return _milliAmpsMax; }
|
static uint16_t ablMilliampsMax() { return _milliAmpsMax; }
|
||||||
|
|
||||||
static int add(BusConfig &bc);
|
static int add(BusConfig &bc);
|
||||||
static void useParallelOutput(void); // workaround for inaccessible PolyBus
|
static void useParallelOutput(); // workaround for inaccessible PolyBus
|
||||||
|
|
||||||
//do not call this method from system context (network callback)
|
//do not call this method from system context (network callback)
|
||||||
static void removeAll();
|
static void removeAll();
|
||||||
|
|
||||||
static void on(void);
|
static void on();
|
||||||
static void off(void);
|
static void off();
|
||||||
|
|
||||||
static void show();
|
static void show();
|
||||||
static bool canAllShow();
|
static bool canAllShow();
|
||||||
static void setStatusPixel(uint32_t c);
|
static void setStatusPixel(uint32_t c);
|
||||||
static void setPixelColor(uint16_t pix, uint32_t c);
|
[[gnu::hot]] static void setPixelColor(uint16_t pix, uint32_t c);
|
||||||
static void setBrightness(uint8_t b);
|
static void setBrightness(uint8_t b);
|
||||||
// for setSegmentCCT(), cct can only be in [-1,255] range; allowWBCorrection will convert it to K
|
// for setSegmentCCT(), cct can only be in [-1,255] range; allowWBCorrection will convert it to K
|
||||||
// WARNING: setSegmentCCT() is a misleading name!!! much better would be setGlobalCCT() or just setCCT()
|
// WARNING: setSegmentCCT() is a misleading name!!! much better would be setGlobalCCT() or just setCCT()
|
||||||
static void setSegmentCCT(int16_t cct, bool allowWBCorrection = false);
|
static void setSegmentCCT(int16_t cct, bool allowWBCorrection = false);
|
||||||
static void setMilliampsMax(uint16_t max) { _milliAmpsMax = max;}
|
static inline void setMilliampsMax(uint16_t max) { _milliAmpsMax = max;}
|
||||||
static uint32_t getPixelColor(uint16_t pix);
|
static uint32_t getPixelColor(uint16_t pix);
|
||||||
static inline int16_t getSegmentCCT() { return Bus::getCCT(); }
|
static inline int16_t getSegmentCCT() { return Bus::getCCT(); }
|
||||||
|
|
||||||
@ -386,10 +395,10 @@ class BusManager {
|
|||||||
|
|
||||||
//semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit())
|
//semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit())
|
||||||
static uint16_t getTotalLength();
|
static uint16_t getTotalLength();
|
||||||
static uint8_t getNumBusses() { return numBusses; }
|
static inline uint8_t getNumBusses() { return numBusses; }
|
||||||
|
static String getLEDTypesJSONString();
|
||||||
|
|
||||||
static void updateColorOrderMap(const ColorOrderMap &com) { memcpy(&colorOrderMap, &com, sizeof(ColorOrderMap)); }
|
static inline ColorOrderMap& getColorOrderMap() { return colorOrderMap; }
|
||||||
static const ColorOrderMap& getColorOrderMap() { return colorOrderMap; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static uint8_t numBusses;
|
static uint8_t numBusses;
|
||||||
@ -400,11 +409,11 @@ class BusManager {
|
|||||||
static uint8_t _parallelOutputs;
|
static uint8_t _parallelOutputs;
|
||||||
|
|
||||||
#ifdef ESP32_DATA_IDLE_HIGH
|
#ifdef ESP32_DATA_IDLE_HIGH
|
||||||
static void esp32RMTInvertIdle();
|
static void esp32RMTInvertIdle() ;
|
||||||
#endif
|
#endif
|
||||||
static uint8_t getNumVirtualBusses() {
|
static uint8_t getNumVirtualBusses() {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (int i=0; i<numBusses; i++) if (busses[i]->getType() >= TYPE_NET_DDP_RGB && busses[i]->getType() < 96) j++;
|
for (int i=0; i<numBusses; i++) if (busses[i]->isVirtual()) j++;
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1314,8 +1314,8 @@ class PolyBus {
|
|||||||
|
|
||||||
//gives back the internal type index (I_XX_XXX_X above) for the input
|
//gives back the internal type index (I_XX_XXX_X above) for the input
|
||||||
static uint8_t getI(uint8_t busType, uint8_t* pins, uint8_t num = 0) {
|
static uint8_t getI(uint8_t busType, uint8_t* pins, uint8_t num = 0) {
|
||||||
if (!IS_DIGITAL(busType)) return I_NONE;
|
if (!Bus::isDigital(busType)) return I_NONE;
|
||||||
if (IS_2PIN(busType)) { //SPI LED chips
|
if (Bus::is2Pin(busType)) { //SPI LED chips
|
||||||
bool isHSPI = false;
|
bool isHSPI = false;
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
if (pins[0] == P_8266_HS_MOSI && pins[1] == P_8266_HS_CLK) isHSPI = true;
|
if (pins[0] == P_8266_HS_MOSI && pins[1] == P_8266_HS_CLK) isHSPI = true;
|
||||||
|
@ -173,8 +173,8 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
for (JsonObject elm : ins) {
|
for (JsonObject elm : ins) {
|
||||||
unsigned type = elm["type"] | TYPE_WS2812_RGB;
|
unsigned type = elm["type"] | TYPE_WS2812_RGB;
|
||||||
unsigned len = elm["len"] | DEFAULT_LED_COUNT;
|
unsigned len = elm["len"] | DEFAULT_LED_COUNT;
|
||||||
if (!IS_DIGITAL(type)) continue;
|
if (!Bus::isDigital(type)) continue;
|
||||||
if (!IS_2PIN(type)) {
|
if (!Bus::is2Pin(type)) {
|
||||||
digitalCount++;
|
digitalCount++;
|
||||||
unsigned channels = Bus::getNumberOfChannels(type);
|
unsigned channels = Bus::getNumberOfChannels(type);
|
||||||
if (len > maxLedsOnBus) maxLedsOnBus = len;
|
if (len > maxLedsOnBus) maxLedsOnBus = len;
|
||||||
@ -215,7 +215,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
uint8_t maPerLed = elm[F("ledma")] | LED_MILLIAMPS_DEFAULT;
|
uint8_t maPerLed = elm[F("ledma")] | LED_MILLIAMPS_DEFAULT;
|
||||||
uint16_t maMax = elm[F("maxpwr")] | (ablMilliampsMax * length) / total; // rough (incorrect?) per strip ABL calculation when no config exists
|
uint16_t maMax = elm[F("maxpwr")] | (ablMilliampsMax * length) / total; // rough (incorrect?) per strip ABL calculation when no config exists
|
||||||
// To disable brightness limiter we either set output max current to 0 or single LED current to 0 (we choose output max current)
|
// To disable brightness limiter we either set output max current to 0 or single LED current to 0 (we choose output max current)
|
||||||
if (IS_PWM(ledType) || IS_ONOFF(ledType) || IS_VIRTUAL(ledType)) { // analog and virtual
|
if (Bus::isPWM(ledType) || Bus::isOnOff(ledType) || Bus::isVirtual(ledType)) { // analog and virtual
|
||||||
maPerLed = 0;
|
maPerLed = 0;
|
||||||
maMax = 0;
|
maMax = 0;
|
||||||
}
|
}
|
||||||
@ -244,17 +244,13 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
// read color order map configuration
|
// read color order map configuration
|
||||||
JsonArray hw_com = hw[F("com")];
|
JsonArray hw_com = hw[F("com")];
|
||||||
if (!hw_com.isNull()) {
|
if (!hw_com.isNull()) {
|
||||||
ColorOrderMap com = {};
|
BusManager::getColorOrderMap().reserve(std::min(hw_com.size(), (size_t)WLED_MAX_COLOR_ORDER_MAPPINGS));
|
||||||
unsigned s = 0;
|
|
||||||
for (JsonObject entry : hw_com) {
|
for (JsonObject entry : hw_com) {
|
||||||
if (s > WLED_MAX_COLOR_ORDER_MAPPINGS) break;
|
|
||||||
uint16_t start = entry["start"] | 0;
|
uint16_t start = entry["start"] | 0;
|
||||||
uint16_t len = entry["len"] | 0;
|
uint16_t len = entry["len"] | 0;
|
||||||
uint8_t colorOrder = (int)entry[F("order")];
|
uint8_t colorOrder = (int)entry[F("order")];
|
||||||
com.add(start, len, colorOrder);
|
if (!BusManager::getColorOrderMap().add(start, len, colorOrder)) break;
|
||||||
s++;
|
|
||||||
}
|
}
|
||||||
BusManager::updateColorOrderMap(com);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// read multiple button configuration
|
// read multiple button configuration
|
||||||
|
@ -51,27 +51,28 @@
|
|||||||
#define WLED_MAX_BUSSES 4 // will allow 3 digital & 1 analog RGB
|
#define WLED_MAX_BUSSES 4 // will allow 3 digital & 1 analog RGB
|
||||||
#define WLED_MIN_VIRTUAL_BUSSES 2
|
#define WLED_MIN_VIRTUAL_BUSSES 2
|
||||||
#else
|
#else
|
||||||
|
#define WLED_MAX_ANALOG_CHANNELS (LEDC_CHANNEL_MAX*LEDC_SPEED_MODE_MAX)
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32C3) // 2 RMT, 6 LEDC, only has 1 I2S but NPB does not support it ATM
|
#if defined(CONFIG_IDF_TARGET_ESP32C3) // 2 RMT, 6 LEDC, only has 1 I2S but NPB does not support it ATM
|
||||||
#define WLED_MAX_BUSSES 4 // will allow 2 digital & 2 analog RGB
|
#define WLED_MAX_BUSSES 4 // will allow 2 digital & 2 analog RGB
|
||||||
#define WLED_MAX_DIGITAL_CHANNELS 2
|
#define WLED_MAX_DIGITAL_CHANNELS 2
|
||||||
#define WLED_MAX_ANALOG_CHANNELS 6
|
//#define WLED_MAX_ANALOG_CHANNELS 6
|
||||||
#define WLED_MIN_VIRTUAL_BUSSES 3
|
#define WLED_MIN_VIRTUAL_BUSSES 3
|
||||||
#elif defined(CONFIG_IDF_TARGET_ESP32S2) // 4 RMT, 8 LEDC, only has 1 I2S bus, supported in NPB
|
#elif defined(CONFIG_IDF_TARGET_ESP32S2) // 4 RMT, 8 LEDC, only has 1 I2S bus, supported in NPB
|
||||||
// the 5th bus (I2S) will prevent Audioreactive usermod from functioning (it is last used though)
|
// the 5th bus (I2S) will prevent Audioreactive usermod from functioning (it is last used though)
|
||||||
#define WLED_MAX_BUSSES 7 // will allow 5 digital & 2 analog RGB
|
#define WLED_MAX_BUSSES 7 // will allow 5 digital & 2 analog RGB
|
||||||
#define WLED_MAX_DIGITAL_CHANNELS 5
|
#define WLED_MAX_DIGITAL_CHANNELS 5
|
||||||
#define WLED_MAX_ANALOG_CHANNELS 8
|
//#define WLED_MAX_ANALOG_CHANNELS 8
|
||||||
#define WLED_MIN_VIRTUAL_BUSSES 3
|
#define WLED_MIN_VIRTUAL_BUSSES 3
|
||||||
#elif defined(CONFIG_IDF_TARGET_ESP32S3) // 4 RMT, 8 LEDC, has 2 I2S but NPB does not support them ATM
|
#elif defined(CONFIG_IDF_TARGET_ESP32S3) // 4 RMT, 8 LEDC, has 2 I2S but NPB does not support them ATM
|
||||||
#define WLED_MAX_BUSSES 6 // will allow 4 digital & 2 analog RGB
|
#define WLED_MAX_BUSSES 6 // will allow 4 digital & 2 analog RGB
|
||||||
#define WLED_MAX_DIGITAL_CHANNELS 4
|
#define WLED_MAX_DIGITAL_CHANNELS 4
|
||||||
#define WLED_MAX_ANALOG_CHANNELS 8
|
//#define WLED_MAX_ANALOG_CHANNELS 8
|
||||||
#define WLED_MIN_VIRTUAL_BUSSES 4
|
#define WLED_MIN_VIRTUAL_BUSSES 4
|
||||||
#else
|
#else
|
||||||
// the last digital bus (I2S0) will prevent Audioreactive usermod from functioning
|
// the last digital bus (I2S0) will prevent Audioreactive usermod from functioning
|
||||||
#define WLED_MAX_BUSSES 20 // will allow 17 digital & 3 analog RGB
|
#define WLED_MAX_BUSSES 20 // will allow 17 digital & 3 analog RGB
|
||||||
#define WLED_MAX_DIGITAL_CHANNELS 17
|
#define WLED_MAX_DIGITAL_CHANNELS 17
|
||||||
#define WLED_MAX_ANALOG_CHANNELS 10
|
//#define WLED_MAX_ANALOG_CHANNELS 16
|
||||||
#define WLED_MIN_VIRTUAL_BUSSES 4
|
#define WLED_MIN_VIRTUAL_BUSSES 4
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -281,6 +282,7 @@
|
|||||||
#define TYPE_NONE 0 //light is not configured
|
#define TYPE_NONE 0 //light is not configured
|
||||||
#define TYPE_RESERVED 1 //unused. Might indicate a "virtual" light
|
#define TYPE_RESERVED 1 //unused. Might indicate a "virtual" light
|
||||||
//Digital types (data pin only) (16-39)
|
//Digital types (data pin only) (16-39)
|
||||||
|
#define TYPE_DIGITAL_MIN 16 // first usable digital type
|
||||||
#define TYPE_WS2812_1CH 18 //white-only chips (1 channel per IC) (unused)
|
#define TYPE_WS2812_1CH 18 //white-only chips (1 channel per IC) (unused)
|
||||||
#define TYPE_WS2812_1CH_X3 19 //white-only chips (3 channels per IC)
|
#define TYPE_WS2812_1CH_X3 19 //white-only chips (3 channels per IC)
|
||||||
#define TYPE_WS2812_2CH_X3 20 //CCT chips (1st IC controls WW + CW of 1st zone and CW of 2nd zone, 2nd IC controls WW of 2nd zone and WW + CW of 3rd zone)
|
#define TYPE_WS2812_2CH_X3 20 //CCT chips (1st IC controls WW + CW of 1st zone and CW of 2nd zone, 2nd IC controls WW of 2nd zone and WW + CW of 3rd zone)
|
||||||
@ -298,26 +300,36 @@
|
|||||||
#define TYPE_WS2805 32 //RGB + WW + CW
|
#define TYPE_WS2805 32 //RGB + WW + CW
|
||||||
#define TYPE_TM1914 33 //RGB
|
#define TYPE_TM1914 33 //RGB
|
||||||
#define TYPE_SM16825 34 //RGB + WW + CW
|
#define TYPE_SM16825 34 //RGB + WW + CW
|
||||||
|
#define TYPE_DIGITAL_MAX 39 // last usable digital type
|
||||||
//"Analog" types (40-47)
|
//"Analog" types (40-47)
|
||||||
#define TYPE_ONOFF 40 //binary output (relays etc.; NOT PWM)
|
#define TYPE_ONOFF 40 //binary output (relays etc.; NOT PWM)
|
||||||
|
#define TYPE_ANALOG_MIN 41 // first usable analog type
|
||||||
#define TYPE_ANALOG_1CH 41 //single channel PWM. Uses value of brightest RGBW channel
|
#define TYPE_ANALOG_1CH 41 //single channel PWM. Uses value of brightest RGBW channel
|
||||||
#define TYPE_ANALOG_2CH 42 //analog WW + CW
|
#define TYPE_ANALOG_2CH 42 //analog WW + CW
|
||||||
#define TYPE_ANALOG_3CH 43 //analog RGB
|
#define TYPE_ANALOG_3CH 43 //analog RGB
|
||||||
#define TYPE_ANALOG_4CH 44 //analog RGBW
|
#define TYPE_ANALOG_4CH 44 //analog RGBW
|
||||||
#define TYPE_ANALOG_5CH 45 //analog RGB + WW + CW
|
#define TYPE_ANALOG_5CH 45 //analog RGB + WW + CW
|
||||||
|
#define TYPE_ANALOG_6CH 46 //analog RGB + A + WW + CW
|
||||||
|
#define TYPE_ANALOG_MAX 47 // last usable analog type
|
||||||
//Digital types (data + clock / SPI) (48-63)
|
//Digital types (data + clock / SPI) (48-63)
|
||||||
|
#define TYPE_2PIN_MIN 48
|
||||||
#define TYPE_WS2801 50
|
#define TYPE_WS2801 50
|
||||||
#define TYPE_APA102 51
|
#define TYPE_APA102 51
|
||||||
#define TYPE_LPD8806 52
|
#define TYPE_LPD8806 52
|
||||||
#define TYPE_P9813 53
|
#define TYPE_P9813 53
|
||||||
#define TYPE_LPD6803 54
|
#define TYPE_LPD6803 54
|
||||||
|
#define TYPE_2PIN_MAX 63
|
||||||
//Network types (master broadcast) (80-95)
|
//Network types (master broadcast) (80-95)
|
||||||
|
#define TYPE_VIRTUAL_MIN 80
|
||||||
#define TYPE_NET_DDP_RGB 80 //network DDP RGB bus (master broadcast bus)
|
#define TYPE_NET_DDP_RGB 80 //network DDP RGB bus (master broadcast bus)
|
||||||
#define TYPE_NET_E131_RGB 81 //network E131 RGB bus (master broadcast bus, unused)
|
#define TYPE_NET_E131_RGB 81 //network E131 RGB bus (master broadcast bus, unused)
|
||||||
#define TYPE_NET_ARTNET_RGB 82 //network ArtNet RGB bus (master broadcast bus, unused)
|
#define TYPE_NET_ARTNET_RGB 82 //network ArtNet RGB bus (master broadcast bus, unused)
|
||||||
#define TYPE_NET_DDP_RGBW 88 //network DDP RGBW bus (master broadcast bus)
|
#define TYPE_NET_DDP_RGBW 88 //network DDP RGBW bus (master broadcast bus)
|
||||||
#define TYPE_NET_ARTNET_RGBW 89 //network ArtNet RGB bus (master broadcast bus, unused)
|
#define TYPE_NET_ARTNET_RGBW 89 //network ArtNet RGB bus (master broadcast bus, unused)
|
||||||
|
#define TYPE_VIRTUAL_MAX 95
|
||||||
|
|
||||||
|
/*
|
||||||
|
// old macros that have been moved to Bus class
|
||||||
#define IS_TYPE_VALID(t) ((t) > 15 && (t) < 128)
|
#define IS_TYPE_VALID(t) ((t) > 15 && (t) < 128)
|
||||||
#define IS_DIGITAL(t) (((t) > 15 && (t) < 40) || ((t) > 47 && (t) < 64)) //digital are 16-39 and 48-63
|
#define IS_DIGITAL(t) (((t) > 15 && (t) < 40) || ((t) > 47 && (t) < 64)) //digital are 16-39 and 48-63
|
||||||
#define IS_2PIN(t) ((t) > 47 && (t) < 64)
|
#define IS_2PIN(t) ((t) > 47 && (t) < 64)
|
||||||
@ -326,6 +338,7 @@
|
|||||||
#define IS_PWM(t) ((t) > 40 && (t) < 46) //does not include on/Off type
|
#define IS_PWM(t) ((t) > 40 && (t) < 46) //does not include on/Off type
|
||||||
#define NUM_PWM_PINS(t) ((t) - 40) //for analog PWM 41-45 only
|
#define NUM_PWM_PINS(t) ((t) - 40) //for analog PWM 41-45 only
|
||||||
#define IS_VIRTUAL(t) ((t) >= 80 && (t) < 96) //this was a poor choice a better would be 96-111
|
#define IS_VIRTUAL(t) ((t) >= 80 && (t) < 96) //this was a poor choice a better would be 96-111
|
||||||
|
*/
|
||||||
|
|
||||||
//Color orders
|
//Color orders
|
||||||
#define COL_ORDER_GRB 0 //GRB(w),defaut
|
#define COL_ORDER_GRB 0 //GRB(w),defaut
|
||||||
@ -480,7 +493,7 @@
|
|||||||
|
|
||||||
// string temp buffer (now stored in stack locally)
|
// string temp buffer (now stored in stack locally)
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
#define SETTINGS_STACK_BUF_SIZE 2048
|
#define SETTINGS_STACK_BUF_SIZE 2560
|
||||||
#else
|
#else
|
||||||
#define SETTINGS_STACK_BUF_SIZE 3840 // warning: quite a large value for stack (640 * WLED_MAX_USERMODS)
|
#define SETTINGS_STACK_BUF_SIZE 3840 // warning: quite a large value for stack (640 * WLED_MAX_USERMODS)
|
||||||
#endif
|
#endif
|
||||||
@ -520,7 +533,11 @@
|
|||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
#define WLED_PWM_FREQ 880 //PWM frequency proven as good for LEDs
|
#define WLED_PWM_FREQ 880 //PWM frequency proven as good for LEDs
|
||||||
#else
|
#else
|
||||||
#define WLED_PWM_FREQ 19531
|
#ifdef SOC_LEDC_SUPPORT_XTAL_CLOCK
|
||||||
|
#define WLED_PWM_FREQ 9765 // XTAL clock is 40MHz (this will allow 12 bit resolution)
|
||||||
|
#else
|
||||||
|
#define WLED_PWM_FREQ 19531 // APB clock is 80MHz
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -5,8 +5,9 @@
|
|||||||
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
|
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
|
||||||
<title>LED Settings</title>
|
<title>LED Settings</title>
|
||||||
<script>
|
<script>
|
||||||
var d=document,laprev=55,maxB=1,maxD=1,maxA=1,maxV=0,maxM=4000,maxPB=4096,maxL=1333,maxCO=10,maxLbquot=0; //maximum bytes for LED allocation: 4kB for 8266, 32kB for 32
|
var d=document,laprev=55,maxB=1,maxD=1,maxA=1,maxV=0,maxM=4000,maxPB=2048,maxL=1664,maxCO=5,maxLbquot=0; //maximum bytes for LED allocation: 4kB for 8266, 32kB for 32
|
||||||
var oMaxB=1;
|
var oMaxB=1;
|
||||||
|
d.ledTypes = [/*{i:22,c:1,t:"D",n:"WS2812"},{i:42,c:6,t:"AA",n:"PWM CCT"}*/]; // filled from GetV()
|
||||||
d.um_p = [];
|
d.um_p = [];
|
||||||
d.rsvd = [];
|
d.rsvd = [];
|
||||||
d.ro_gpio = [];
|
d.ro_gpio = [];
|
||||||
@ -18,14 +19,18 @@
|
|||||||
function gId(n){return d.getElementById(n);}
|
function gId(n){return d.getElementById(n);}
|
||||||
function off(n){d.getElementsByName(n)[0].value = -1;}
|
function off(n){d.getElementsByName(n)[0].value = -1;}
|
||||||
// these functions correspond to C macros found in const.h
|
// these functions correspond to C macros found in const.h
|
||||||
function isPWM(t) { return t > 40 && t < 46; } // is PWM type
|
function gT(t) { for (let type of d.ledTypes) if (t == type.i) return type; } // getType from available ledTypes
|
||||||
function isAna(t) { return t == 40 || isPWM(t); } // is analog type
|
function isPWM(t) { return gT(t).t.charAt(0) === "A"; } // is PWM type
|
||||||
function isDig(t) { return (t > 15 && t < 40) || isD2P(t); } // is digital type
|
function isAna(t) { return gT(t).t === "" || isPWM(t); } // is analog type
|
||||||
function isD2P(t) { return t > 47 && t < 64; } // is digital 2 pin type
|
function isDig(t) { return gT(t).t === "D" || isD2P(t); } // is digital type
|
||||||
function is16b(t) { return t == 26 || t == 29 || t == 34; } // is digital 16 bit type
|
function isD2P(t) { return gT(t).t === "2P"; } // is digital 2 pin type
|
||||||
function isVir(t) { return t >= 80 && t < 96; } // is virtual type
|
function isNet(t) { return gT(t).t === "N"; } // is network type
|
||||||
function hasW(t) { return (t >= 18 && t <= 21) || (t >= 28 && t <= 32) || t == 34 || (t >= 44 && t <= 45) || (t >= 88 && t <= 89); }
|
function isVir(t) { return gT(t).t === "V" || isNet(t); } // is virtual type
|
||||||
function hasCCT(t) { return t == 20 || t == 21 || t == 42 || t == 45 || t == 28 || t == 32 || t == 34; }
|
function hasRGB(t) { return !!(gT(t).c & 0x01); } // has RGB
|
||||||
|
function hasW(t) { return !!(gT(t).c & 0x02); } // has white channel
|
||||||
|
function hasCCT(t) { return !!(gT(t).c & 0x04); } // is white CCT enabled
|
||||||
|
function is16b(t) { return !!(gT(t).c & 0x10); } // is digital 16 bit type
|
||||||
|
function numPins(t){ return Math.max(gT(t).t.length, 1); } // type length determines number of GPIO pins
|
||||||
// https://www.educative.io/edpresso/how-to-dynamically-load-a-js-file-in-javascript
|
// https://www.educative.io/edpresso/how-to-dynamically-load-a-js-file-in-javascript
|
||||||
function loadJS(FILE_URL, async = true) {
|
function loadJS(FILE_URL, async = true) {
|
||||||
let scE = d.createElement("script");
|
let scE = d.createElement("script");
|
||||||
@ -56,7 +61,7 @@
|
|||||||
x.className = error ? "error":"show";
|
x.className = error ? "error":"show";
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
x.style.animation = 'none';
|
x.style.animation = 'none';
|
||||||
timeout = setTimeout(function(){ x.className = x.className.replace("show", ""); }, 2900);
|
timeout = setTimeout(()=>{ x.className = x.className.replace("show", ""); }, 2900);
|
||||||
}
|
}
|
||||||
function bLimits(b,v,p,m,l,o=5,d=2,a=6) {
|
function bLimits(b,v,p,m,l,o=5,d=2,a=6) {
|
||||||
// maxB - max buses (can be changed if using ESP32 parallel I2S)
|
// maxB - max buses (can be changed if using ESP32 parallel I2S)
|
||||||
@ -65,7 +70,7 @@
|
|||||||
// maxV - min virtual buses
|
// maxV - min virtual buses
|
||||||
// maxPB - max LEDs per bus
|
// maxPB - max LEDs per bus
|
||||||
// maxM - max LED memory
|
// maxM - max LED memory
|
||||||
// maxL - max LEDs
|
// maxL - max LEDs (will serve to determine ESP >1664 == ESP32)
|
||||||
// maxCO - max Color Order mappings
|
// maxCO - max Color Order mappings
|
||||||
oMaxB = maxB = b; maxD = d, maxA = a, maxV = v; maxM = m; maxPB = p; maxL = l; maxCO = o;
|
oMaxB = maxB = b; maxD = d, maxA = a, maxV = v; maxM = m; maxPB = p; maxL = l; maxCO = o;
|
||||||
}
|
}
|
||||||
@ -79,7 +84,7 @@
|
|||||||
let t = parseInt(d.Sf["LT"+n].value, 10); // LED type SELECT
|
let t = parseInt(d.Sf["LT"+n].value, 10); // LED type SELECT
|
||||||
// ignore IP address
|
// ignore IP address
|
||||||
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3") {
|
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3") {
|
||||||
if (t>=80) return;
|
if (isNet(t)) return;
|
||||||
}
|
}
|
||||||
//check for pin conflicts
|
//check for pin conflicts
|
||||||
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4")
|
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4")
|
||||||
@ -199,12 +204,10 @@
|
|||||||
let len = parseInt(d.getElementsByName("LC"+n)[0].value);
|
let len = parseInt(d.getElementsByName("LC"+n)[0].value);
|
||||||
len += parseInt(d.getElementsByName("SL"+n)[0].value); // skipped LEDs are allocated too
|
len += parseInt(d.getElementsByName("SL"+n)[0].value); // skipped LEDs are allocated too
|
||||||
let dbl = 0;
|
let dbl = 0;
|
||||||
let ch = 3;
|
let ch = 3*hasRGB(t) + hasW(t) + hasCCT(t);
|
||||||
let mul = 1;
|
let mul = 1;
|
||||||
if (isDig(t)) {
|
if (isDig(t)) {
|
||||||
if (is16b(t)) len *= 2; // 16 bit LEDs
|
if (is16b(t)) len *= 2; // 16 bit LEDs
|
||||||
if (t > 28 && t < 40) ch = 4; //RGBW
|
|
||||||
if (t == 28) ch = 5; //GRBCW
|
|
||||||
if (maxM < 10000 && d.getElementsByName("L0"+n)[0].value == 3) { //8266 DMA uses 5x the mem
|
if (maxM < 10000 && d.getElementsByName("L0"+n)[0].value == 3) { //8266 DMA uses 5x the mem
|
||||||
mul = 5;
|
mul = 5;
|
||||||
}
|
}
|
||||||
@ -213,7 +216,6 @@
|
|||||||
}
|
}
|
||||||
if (d.Sf.LD.checked) dbl = len * ch; // double buffering
|
if (d.Sf.LD.checked) dbl = len * ch; // double buffering
|
||||||
}
|
}
|
||||||
if (isVir(t) && t == 88) ch = 4;
|
|
||||||
return len * ch * mul + dbl;
|
return len * ch * mul + dbl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,6 +226,41 @@
|
|||||||
let sLC = 0, sPC = 0, sDI = 0, maxLC = 0;
|
let sLC = 0, sPC = 0, sDI = 0, maxLC = 0;
|
||||||
const ablEN = d.Sf.ABL.checked;
|
const ablEN = d.Sf.ABL.checked;
|
||||||
maxB = oMaxB; // TODO make sure we start with all possible buses
|
maxB = oMaxB; // TODO make sure we start with all possible buses
|
||||||
|
let setPinConfig = (n,t) => {
|
||||||
|
let p0d = "GPIO:";
|
||||||
|
let p1d = "";
|
||||||
|
let off = "Off Refresh";
|
||||||
|
switch (gT(t).t.charAt(0)) {
|
||||||
|
case '2': // 2 pin digital
|
||||||
|
p1d = "Clock "+p0d;
|
||||||
|
// fallthrough
|
||||||
|
case 'D': // digital
|
||||||
|
p0d = "Data "+p0d;
|
||||||
|
break;
|
||||||
|
case 'A': // PWM analog
|
||||||
|
if (numPins(t) > 1) p0d = "GPIOs:";
|
||||||
|
off = "Dithering";
|
||||||
|
break;
|
||||||
|
case 'N': // network
|
||||||
|
p0d = "IP address:";
|
||||||
|
break;
|
||||||
|
case 'V': // virtual/non-GPIO based
|
||||||
|
p0d = "Config:"
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
gId("p0d"+n).innerText = p0d;
|
||||||
|
gId("p1d"+n).innerText = p1d;
|
||||||
|
gId("off"+n).innerText = off;
|
||||||
|
// secondary pins show/hide (type string length is equivalent to number of pins used; except for network and on/off)
|
||||||
|
let pins = Math.max(gT(t).t.length,1) + 3*isNet(t); // fixes network pins to 4
|
||||||
|
for (let p=1; p<5; p++) {
|
||||||
|
var LK = d.Sf["L"+p+n];
|
||||||
|
if (!LK) continue;
|
||||||
|
LK.style.display = (p < pins) ? "inline" : "none";
|
||||||
|
LK.required = (p < pins);
|
||||||
|
if (p >= pins) LK.value="";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// enable/disable LED fields
|
// enable/disable LED fields
|
||||||
let LTs = d.Sf.querySelectorAll("#mLC select[name^=LT]");
|
let LTs = d.Sf.querySelectorAll("#mLC select[name^=LT]");
|
||||||
@ -232,49 +269,29 @@
|
|||||||
// is the field a LED type?
|
// is the field a LED type?
|
||||||
var n = s.name.substring(2);
|
var n = s.name.substring(2);
|
||||||
var t = parseInt(s.value);
|
var t = parseInt(s.value);
|
||||||
gId("p0d"+n).innerHTML = isVir(t) ? "IP address:" : isD2P(t) ? "Data GPIO:" : (t > 41) ? "GPIOs:" : "GPIO:";
|
|
||||||
gId("p1d"+n).innerHTML = isD2P(t) ? "Clk GPIO:" : "";
|
|
||||||
gId("abl"+n).style.display = (!ablEN || isVir(t) || isAna(t)) ? "none" : "inline";
|
|
||||||
//var LK = d.getElementsByName("L1"+n)[0]; // clock pin
|
|
||||||
|
|
||||||
memu += getMem(t, n); // calc memory
|
memu += getMem(t, n); // calc memory
|
||||||
|
setPinConfig(n,t);
|
||||||
// enumerate pins
|
gId("abl"+n).style.display = (!ablEN || isVir(t) || isAna(t)) ? "none" : "inline";
|
||||||
for (p=1; p<5; p++) {
|
|
||||||
var LK = d.Sf["L"+p+n]; // secondary pins
|
|
||||||
if (!LK) continue;
|
|
||||||
if ((isVir(t) && p<4) || (isD2P(t) && p==1) || (isPWM(t) && (p+40 < t))) // TYPE_xxxx values from const.h
|
|
||||||
{
|
|
||||||
// display pin field
|
|
||||||
LK.style.display = "inline";
|
|
||||||
LK.required = true;
|
|
||||||
} else {
|
|
||||||
// hide pin field
|
|
||||||
LK.style.display = "none";
|
|
||||||
LK.required = false;
|
|
||||||
LK.value="";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (change) {
|
if (change) {
|
||||||
gId("rf"+n).checked = (gId("rf"+n).checked || t == 31); // LEDs require data in off state
|
gId("rf"+n).checked = (gId("rf"+n).checked || t == 31); // LEDs require data in off state (mandatory for TM1814)
|
||||||
if (isAna(t)) d.Sf["LC"+n].value = 1; // for sanity change analog count just to 1 LED
|
if (isAna(t)) d.Sf["LC"+n].value = 1; // for sanity change analog count just to 1 LED
|
||||||
d.Sf["LA"+n].min = (isVir(t) || isAna(t)) ? 0 : 1;
|
d.Sf["LA"+n].min = (isVir(t) || isAna(t)) ? 0 : 1;
|
||||||
d.Sf["MA"+n].min = (isVir(t) || isAna(t)) ? 0 : 250;
|
d.Sf["MA"+n].min = (isVir(t) || isAna(t)) ? 0 : 250;
|
||||||
}
|
}
|
||||||
gId("rf"+n).onclick = (t == 31) ? (()=>{return false}) : (()=>{}); // prevent change for TM1814
|
gId("rf"+n).onclick = (t == 31) ? (()=>{return false}) : (()=>{}); // prevent change for TM1814
|
||||||
gRGBW |= hasW(t); // RGBW checkbox, TYPE_xxxx values from const.h
|
gRGBW |= hasW(t); // RGBW checkbox
|
||||||
gId("co"+n).style.display = (isVir(t) || isAna(t)) ? "none":"inline"; // hide color order for PWM
|
gId("co"+n).style.display = (isVir(t) || isAna(t)) ? "none":"inline"; // hide color order for PWM
|
||||||
gId("dig"+n+"w").style.display = (isDig(t) && hasW(t)) ? "inline":"none"; // show swap channels dropdown
|
gId("dig"+n+"w").style.display = (isDig(t) && hasW(t)) ? "inline":"none"; // show swap channels dropdown
|
||||||
gId("dig"+n+"w").querySelector("[data-opt=CCT]").disabled = !hasCCT(t); // disable WW/CW swapping
|
gId("dig"+n+"w").querySelector("[data-opt=CCT]").disabled = !hasCCT(t); // disable WW/CW swapping
|
||||||
if (!(isDig(t) && hasW(t))) d.Sf["WO"+n].value = 0; // reset swapping
|
if (!(isDig(t) && hasW(t))) d.Sf["WO"+n].value = 0; // reset swapping
|
||||||
gId("dig"+n+"c").style.display = (isAna(t)) ? "none":"inline"; // hide count for analog
|
gId("dig"+n+"c").style.display = (isAna(t)) ? "none":"inline"; // hide count for analog
|
||||||
gId("dig"+n+"r").style.display = (isVir(t)) ? "none":"inline"; // hide reversed for virtual
|
gId("dig"+n+"r").style.display = (isVir(t)) ? "none":"inline"; // hide reversed for virtual
|
||||||
gId("dig"+n+"s").style.display = (isVir(t) || isAna(t)) ? "none":"inline"; // hide skip 1st for virtual & analog
|
gId("dig"+n+"s").style.display = (isVir(t) || isAna(t)) ? "none":"inline"; // hide skip 1st for virtual & analog
|
||||||
gId("dig"+n+"f").style.display = (isDig(t)) ? "inline":"none"; // hide refresh
|
gId("dig"+n+"f").style.display = (isDig(t) || (isPWM(t) && maxL>2048)) ? "inline":"none"; // hide refresh (PWM hijacks reffresh for dithering on ESP32)
|
||||||
gId("dig"+n+"a").style.display = (hasW(t)) ? "inline":"none"; // auto calculate white
|
gId("dig"+n+"a").style.display = (hasW(t)) ? "inline":"none"; // auto calculate white
|
||||||
gId("dig"+n+"l").style.display = (isD2P(t) || isPWM(t)) ? "inline":"none"; // bus clock speed / PWM speed (relative) (not On/Off)
|
gId("dig"+n+"l").style.display = (isD2P(t) || isPWM(t)) ? "inline":"none"; // bus clock speed / PWM speed (relative) (not On/Off)
|
||||||
gId("rev"+n).innerHTML = isAna(t) ? "Inverted output":"Reversed (rotated 180°)"; // change reverse text for analog
|
gId("rev"+n).innerHTML = isAna(t) ? "Inverted output":"Reversed"; // change reverse text for analog else (rotated 180°)
|
||||||
//gId("psd"+n).innerHTML = isAna(t) ? "Index:":"Start:"; // change analog start description
|
//gId("psd"+n).innerHTML = isAna(t) ? "Index:":"Start:"; // change analog start description
|
||||||
});
|
});
|
||||||
// display global white channel overrides
|
// display global white channel overrides
|
||||||
gId("wc").style.display = (gRGBW) ? 'inline':'none';
|
gId("wc").style.display = (gRGBW) ? 'inline':'none';
|
||||||
@ -396,7 +413,7 @@
|
|||||||
let t = s.value;
|
let t = s.value;
|
||||||
if (isDig(t) && !isD2P(t)) digitalB++;
|
if (isDig(t) && !isD2P(t)) digitalB++;
|
||||||
if (isD2P(t)) twopinB++;
|
if (isD2P(t)) twopinB++;
|
||||||
if (isPWM(t)) analogB += t-40; // type defines PWM pins
|
if (isPWM(t)) analogB += numPins(t); // each GPIO is assigned to a channel
|
||||||
if (isVir(t)) virtB++;
|
if (isVir(t)) virtB++;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -408,38 +425,7 @@
|
|||||||
var cn = `<div class="iST">
|
var cn = `<div class="iST">
|
||||||
<hr class="sml">
|
<hr class="sml">
|
||||||
${i+1}:
|
${i+1}:
|
||||||
<select name="LT${s}" onchange="UI(true)">${i>=maxB && false ? '' :
|
<select name="LT${s}" onchange="UI(true)"></select><br>
|
||||||
'<option value="22" data-type="D">WS281x</option>\
|
|
||||||
<option value="30" data-type="D">SK6812/WS2814 RGBW</option>\
|
|
||||||
<option value="31" data-type="D">TM1814</option>\
|
|
||||||
<option value="24" data-type="D">400kHz</option>\
|
|
||||||
<option value="25" data-type="D">TM1829</option>\
|
|
||||||
<option value="26" data-type="D">UCS8903</option>\
|
|
||||||
<option value="27" data-type="D">APA106/PL9823</option>\
|
|
||||||
<option value="33" data-type="D">TM1914</option>\
|
|
||||||
<option value="28" data-type="D">FW1906 GRBCW</option>\
|
|
||||||
<option value="29" data-type="D">UCS8904 RGBW</option>\
|
|
||||||
<option value="32" data-type="D">WS2805 RGBCW</option>\
|
|
||||||
<option value="34" data-type="D">SM16825 RGBCW</option>\
|
|
||||||
<option value="50" data-type="2P">WS2801</option>\
|
|
||||||
<option value="51" data-type="2P">APA102</option>\
|
|
||||||
<option value="52" data-type="2P">LPD8806</option>\
|
|
||||||
<option value="54" data-type="2P">LPD6803</option>\
|
|
||||||
<option value="53" data-type="2P">P9813</option>\
|
|
||||||
<option value="19" data-type="D">WS2811 White</option>\
|
|
||||||
<option value="40">On/Off</option>\
|
|
||||||
<option value="41" data-type="A">PWM White</option>\
|
|
||||||
<option value="42" data-type="AA">PWM CCT</option>\
|
|
||||||
<option value="43" data-type="AAA">PWM RGB</option>\
|
|
||||||
<option value="44" data-type="AAAA">PWM RGBW</option>\
|
|
||||||
<option value="45" data-type="AAAAA">PWM RGB+CCT</option>\
|
|
||||||
<!--option value="46" data-type="AAAAAA">PWM RGB+DCCT</option-->'}
|
|
||||||
<option value="80" data-type="V">DDP RGB (network)</option>
|
|
||||||
<!--option value="81" data-type="V">E1.31 RGB (network)</option-->
|
|
||||||
<option value="82" data-type="V">Art-Net RGB (network)</option>
|
|
||||||
<option value="88" data-type="V">DDP RGBW (network)</option>
|
|
||||||
<option value="89" data-type="V">Art-Net RGBW (network)</option>
|
|
||||||
</select><br>
|
|
||||||
<div id="abl${s}">
|
<div id="abl${s}">
|
||||||
mA/LED: <select name="LAsel${s}" onchange="enLA(this,'${s}');UI();">
|
mA/LED: <select name="LAsel${s}" onchange="enLA(this,'${s}');UI();">
|
||||||
<option value="55" selected>55mA (typ. 5V WS281x)</option>
|
<option value="55" selected>55mA (typ. 5V WS281x)</option>
|
||||||
@ -474,10 +460,25 @@ mA/LED: <select name="LAsel${s}" onchange="enLA(this,'${s}');UI();">
|
|||||||
<span id="p4d${s}"></span><input type="number" name="L4${s}" class="s" onchange="UI();pinUpd(this);"/>
|
<span id="p4d${s}"></span><input type="number" name="L4${s}" class="s" onchange="UI();pinUpd(this);"/>
|
||||||
<div id="dig${s}r" style="display:inline"><br><span id="rev${s}">Reversed</span>: <input type="checkbox" name="CV${s}"></div>
|
<div id="dig${s}r" style="display:inline"><br><span id="rev${s}">Reversed</span>: <input type="checkbox" name="CV${s}"></div>
|
||||||
<div id="dig${s}s" style="display:inline"><br>Skip first LEDs: <input type="number" name="SL${s}" min="0" max="255" value="0" oninput="UI()"></div>
|
<div id="dig${s}s" style="display:inline"><br>Skip first LEDs: <input type="number" name="SL${s}" min="0" max="255" value="0" oninput="UI()"></div>
|
||||||
<div id="dig${s}f" style="display:inline"><br>Off Refresh: <input id="rf${s}" type="checkbox" name="RF${s}"></div>
|
<div id="dig${s}f" style="display:inline"><br><span id="off${s}">Off Refresh</span>: <input id="rf${s}" type="checkbox" name="RF${s}"></div>
|
||||||
<div id="dig${s}a" style="display:inline"><br>Auto-calculate white channel from RGB:<br><select name="AW${s}"><option value=0>None</option><option value=1>Brighter</option><option value=2>Accurate</option><option value=3>Dual</option><option value=4>Max</option></select> </div>
|
<div id="dig${s}a" style="display:inline"><br>Auto-calculate W channel from RGB:<br><select name="AW${s}"><option value=0>None</option><option value=1>Brighter</option><option value=2>Accurate</option><option value=3>Dual</option><option value=4>Max</option></select> </div>
|
||||||
</div>`;
|
</div>`;
|
||||||
f.insertAdjacentHTML("beforeend", cn);
|
f.insertAdjacentHTML("beforeend", cn);
|
||||||
|
// fill led types (credit @netmindz)
|
||||||
|
d.Sf.querySelectorAll("#mLC select[name^=LT]").forEach((sel,n)=>{
|
||||||
|
if (sel.length == 0) { // ignore already updated
|
||||||
|
for (let type of d.ledTypes) {
|
||||||
|
let opt = d.createElement("option");
|
||||||
|
opt.value = type.i;
|
||||||
|
opt.text = type.n;
|
||||||
|
if (type.t != undefined && type.t != "") {
|
||||||
|
opt.setAttribute('data-type', type.t);
|
||||||
|
}
|
||||||
|
sel.appendChild(opt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// disable inappropriate LED types
|
||||||
let sel = d.getElementsByName("LT"+s)[0]
|
let sel = d.getElementsByName("LT"+s)[0]
|
||||||
if (i >= maxB || digitalB >= maxD) disable(sel,'option[data-type="D"]');
|
if (i >= maxB || digitalB >= maxD) disable(sel,'option[data-type="D"]');
|
||||||
if (i >= maxB || twopinB >= 1) disable(sel,'option[data-type="2P"]');
|
if (i >= maxB || twopinB >= 1) disable(sel,'option[data-type="2P"]');
|
||||||
@ -908,7 +909,8 @@ Swap: <select id="xw${s}" name="XW${s}">
|
|||||||
<br>
|
<br>
|
||||||
Calculate CCT from RGB: <input type="checkbox" name="CR"><br>
|
Calculate CCT from RGB: <input type="checkbox" name="CR"><br>
|
||||||
CCT IC used (Athom 15W): <input type="checkbox" name="IC"><br>
|
CCT IC used (Athom 15W): <input type="checkbox" name="IC"><br>
|
||||||
CCT additive blending: <input type="number" class="s" min="0" max="100" name="CB" required> %
|
CCT additive blending: <input type="number" class="s" min="0" max="100" name="CB" onchange="UI()" required> %<br>
|
||||||
|
<i class="warn">WARNING: When using H-bridge for reverse polarity (2-wire) CCT LED strip<br><b>make sure this value is 0</b>.<br>(ESP32 variants only, ESP8266 does not support H-bridges)</i>
|
||||||
</div>
|
</div>
|
||||||
<h3>Advanced</h3>
|
<h3>Advanced</h3>
|
||||||
Palette wrapping:
|
Palette wrapping:
|
||||||
|
@ -32,9 +32,7 @@ bool PinManagerClass::deallocatePin(byte gpio, PinOwner tag)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte by = gpio >> 3;
|
bitWrite(pinAlloc, gpio, false);
|
||||||
byte bi = gpio - 8*by;
|
|
||||||
bitWrite(pinAlloc[by], bi, false);
|
|
||||||
ownerTag[gpio] = PinOwner::None;
|
ownerTag[gpio] = PinOwner::None;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -146,9 +144,7 @@ bool PinManagerClass::allocateMultiplePins(const managed_pin_type * mptArray, by
|
|||||||
if (gpio >= WLED_NUM_PINS)
|
if (gpio >= WLED_NUM_PINS)
|
||||||
continue; // other unexpected GPIO => avoid array bounds violation
|
continue; // other unexpected GPIO => avoid array bounds violation
|
||||||
|
|
||||||
byte by = gpio >> 3;
|
bitWrite(pinAlloc, gpio, true);
|
||||||
byte bi = gpio - 8*by;
|
|
||||||
bitWrite(pinAlloc[by], bi, true);
|
|
||||||
ownerTag[gpio] = tag;
|
ownerTag[gpio] = tag;
|
||||||
#ifdef WLED_DEBUG
|
#ifdef WLED_DEBUG
|
||||||
DEBUG_PRINT(F("PIN ALLOC: Pin "));
|
DEBUG_PRINT(F("PIN ALLOC: Pin "));
|
||||||
@ -192,9 +188,7 @@ bool PinManagerClass::allocatePin(byte gpio, bool output, PinOwner tag)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte by = gpio >> 3;
|
bitWrite(pinAlloc, gpio, true);
|
||||||
byte bi = gpio - 8*by;
|
|
||||||
bitWrite(pinAlloc[by], bi, true);
|
|
||||||
ownerTag[gpio] = tag;
|
ownerTag[gpio] = tag;
|
||||||
#ifdef WLED_DEBUG
|
#ifdef WLED_DEBUG
|
||||||
DEBUG_PRINT(F("PIN ALLOC: Pin "));
|
DEBUG_PRINT(F("PIN ALLOC: Pin "));
|
||||||
@ -213,9 +207,7 @@ bool PinManagerClass::isPinAllocated(byte gpio, PinOwner tag) const
|
|||||||
{
|
{
|
||||||
if (!isPinOk(gpio, false)) return true;
|
if (!isPinOk(gpio, false)) return true;
|
||||||
if ((tag != PinOwner::None) && (ownerTag[gpio] != tag)) return false;
|
if ((tag != PinOwner::None) && (ownerTag[gpio] != tag)) return false;
|
||||||
byte by = gpio >> 3;
|
return bitRead(pinAlloc, gpio);
|
||||||
byte bi = gpio - (by<<3);
|
|
||||||
return bitRead(pinAlloc[by], bi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* see https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/gpio.html
|
/* see https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/gpio.html
|
||||||
@ -237,7 +229,7 @@ bool PinManagerClass::isPinAllocated(byte gpio, PinOwner tag) const
|
|||||||
// Check if supplied GPIO is ok to use
|
// Check if supplied GPIO is ok to use
|
||||||
bool PinManagerClass::isPinOk(byte gpio, bool output) const
|
bool PinManagerClass::isPinOk(byte gpio, bool output) const
|
||||||
{
|
{
|
||||||
if (gpio >= WLED_NUM_PINS) return false; // catch error case, to avoid array out-of-bounds access
|
if (gpio >= WLED_NUM_PINS) return false; // catch error case, to avoid array out-of-bounds access
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
if (digitalPinIsValid(gpio)) {
|
if (digitalPinIsValid(gpio)) {
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32C3)
|
#if defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||||
@ -282,34 +274,26 @@ PinOwner PinManagerClass::getPinOwner(byte gpio) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32C3)
|
|
||||||
#define MAX_LED_CHANNELS 6
|
|
||||||
#else
|
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
|
|
||||||
#define MAX_LED_CHANNELS 8
|
|
||||||
#else
|
|
||||||
#define MAX_LED_CHANNELS 16
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
byte PinManagerClass::allocateLedc(byte channels)
|
byte PinManagerClass::allocateLedc(byte channels)
|
||||||
{
|
{
|
||||||
if (channels > MAX_LED_CHANNELS || channels == 0) return 255;
|
if (channels > WLED_MAX_ANALOG_CHANNELS || channels == 0) return 255;
|
||||||
byte ca = 0;
|
unsigned ca = 0;
|
||||||
for (unsigned i = 0; i < MAX_LED_CHANNELS; i++) {
|
for (unsigned i = 0; i < WLED_MAX_ANALOG_CHANNELS; i++) {
|
||||||
byte by = i >> 3;
|
if (bitRead(ledcAlloc, i)) { //found occupied pin
|
||||||
byte bi = i - 8*by;
|
|
||||||
if (bitRead(ledcAlloc[by], bi)) { //found occupied pin
|
|
||||||
ca = 0;
|
ca = 0;
|
||||||
} else {
|
} else {
|
||||||
ca++;
|
// if we have PWM CCT bus allocation (2 channels) we need to make sure both channels share the same timer
|
||||||
|
// for phase shifting purposes (otherwise phase shifts may not be accurate)
|
||||||
|
if (channels == 2) { // will skip odd channel for first channel for phase shifting
|
||||||
|
if (ca == 0 && i % 2 == 0) ca++; // even LEDC channels is 1st PWM channel
|
||||||
|
if (ca == 1 && i % 2 == 1) ca++; // odd LEDC channel is 2nd PWM channel
|
||||||
|
} else
|
||||||
|
ca++;
|
||||||
}
|
}
|
||||||
if (ca >= channels) { //enough free channels
|
if (ca >= channels) { //enough free channels
|
||||||
byte in = (i + 1) - ca;
|
unsigned in = (i + 1) - ca;
|
||||||
for (unsigned j = 0; j < ca; j++) {
|
for (unsigned j = 0; j < ca; j++) {
|
||||||
byte bChan = in + j;
|
bitWrite(ledcAlloc, in+j, true);
|
||||||
byte byChan = bChan >> 3;
|
|
||||||
byte biChan = bChan - 8*byChan;
|
|
||||||
bitWrite(ledcAlloc[byChan], biChan, true);
|
|
||||||
}
|
}
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
@ -319,11 +303,8 @@ byte PinManagerClass::allocateLedc(byte channels)
|
|||||||
|
|
||||||
void PinManagerClass::deallocateLedc(byte pos, byte channels)
|
void PinManagerClass::deallocateLedc(byte pos, byte channels)
|
||||||
{
|
{
|
||||||
for (unsigned j = pos; j < pos + channels; j++) {
|
for (unsigned j = pos; j < pos + channels && j < WLED_MAX_ANALOG_CHANNELS; j++) {
|
||||||
if (j > MAX_LED_CHANNELS) return;
|
bitWrite(ledcAlloc, j, false);
|
||||||
byte by = j >> 3;
|
|
||||||
byte bi = j - 8*by;
|
|
||||||
bitWrite(ledcAlloc[by], bi, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,6 +4,9 @@
|
|||||||
* Registers pins so there is no attempt for two interfaces to use the same pin
|
* Registers pins so there is no attempt for two interfaces to use the same pin
|
||||||
*/
|
*/
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
|
#include "driver/ledc.h" // needed for analog/LEDC channel counts
|
||||||
|
#endif
|
||||||
#include "const.h" // for USERMOD_* values
|
#include "const.h" // for USERMOD_* values
|
||||||
|
|
||||||
typedef struct PinManagerPinType {
|
typedef struct PinManagerPinType {
|
||||||
@ -46,7 +49,6 @@ enum struct PinOwner : uint8_t {
|
|||||||
UM_RotaryEncoderUI = USERMOD_ID_ROTARY_ENC_UI, // 0x08 // Usermod "usermod_v2_rotary_encoder_ui.h"
|
UM_RotaryEncoderUI = USERMOD_ID_ROTARY_ENC_UI, // 0x08 // Usermod "usermod_v2_rotary_encoder_ui.h"
|
||||||
// #define USERMOD_ID_AUTO_SAVE // 0x09 // Usermod "usermod_v2_auto_save.h" -- Does not allocate pins
|
// #define USERMOD_ID_AUTO_SAVE // 0x09 // Usermod "usermod_v2_auto_save.h" -- Does not allocate pins
|
||||||
// #define USERMOD_ID_DHT // 0x0A // Usermod "usermod_dht.h" -- Statically allocates pins, not compatible with pinManager?
|
// #define USERMOD_ID_DHT // 0x0A // Usermod "usermod_dht.h" -- Statically allocates pins, not compatible with pinManager?
|
||||||
// #define USERMOD_ID_MODE_SORT // 0x0B // Usermod "usermod_v2_mode_sort.h" -- Does not allocate pins
|
|
||||||
// #define USERMOD_ID_VL53L0X // 0x0C // Usermod "usermod_vl53l0x_gestures.h" -- Uses "standard" HW_I2C pins
|
// #define USERMOD_ID_VL53L0X // 0x0C // Usermod "usermod_vl53l0x_gestures.h" -- Uses "standard" HW_I2C pins
|
||||||
UM_MultiRelay = USERMOD_ID_MULTI_RELAY, // 0x0D // Usermod "usermod_multi_relay.h"
|
UM_MultiRelay = USERMOD_ID_MULTI_RELAY, // 0x0D // Usermod "usermod_multi_relay.h"
|
||||||
UM_AnimatedStaircase = USERMOD_ID_ANIMATED_STAIRCASE, // 0x0E // Usermod "Animated_Staircase.h"
|
UM_AnimatedStaircase = USERMOD_ID_ANIMATED_STAIRCASE, // 0x0E // Usermod "Animated_Staircase.h"
|
||||||
@ -64,29 +66,28 @@ enum struct PinOwner : uint8_t {
|
|||||||
UM_LDR_DUSK_DAWN = USERMOD_ID_LDR_DUSK_DAWN, // 0x2B // Usermod "usermod_LDR_Dusk_Dawn_v2.h"
|
UM_LDR_DUSK_DAWN = USERMOD_ID_LDR_DUSK_DAWN, // 0x2B // Usermod "usermod_LDR_Dusk_Dawn_v2.h"
|
||||||
UM_MAX17048 = USERMOD_ID_MAX17048, // 0x2F // Usermod "usermod_max17048.h"
|
UM_MAX17048 = USERMOD_ID_MAX17048, // 0x2F // Usermod "usermod_max17048.h"
|
||||||
UM_BME68X = USERMOD_ID_BME68X, // 0x31 // Usermod "usermod_bme68x.h -- Uses "standard" HW_I2C pins
|
UM_BME68X = USERMOD_ID_BME68X, // 0x31 // Usermod "usermod_bme68x.h -- Uses "standard" HW_I2C pins
|
||||||
UM_PIXELS_DICE_TRAY = USERMOD_ID_PIXELS_DICE_TRAY, // 0x35 // Usermod "pixels_dice_tray.h" -- Needs compile time specified 6 pins for display including SPI.
|
UM_PIXELS_DICE_TRAY = USERMOD_ID_PIXELS_DICE_TRAY // 0x35 // Usermod "pixels_dice_tray.h" -- Needs compile time specified 6 pins for display including SPI.
|
||||||
};
|
};
|
||||||
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 PinManagerClass {
|
class PinManagerClass {
|
||||||
private:
|
private:
|
||||||
#ifdef ESP8266
|
struct {
|
||||||
#define WLED_NUM_PINS 17
|
#ifdef ESP8266
|
||||||
uint8_t pinAlloc[3] = {0x00, 0x00, 0x00}; //24bit, 1 bit per pin, we use first 17bits
|
#define WLED_NUM_PINS (GPIO_PIN_COUNT+1) // somehow they forgot GPIO 16 (0-16==17)
|
||||||
PinOwner ownerTag[WLED_NUM_PINS] = { PinOwner::None };
|
uint32_t pinAlloc : 24; // 24bit, 1 bit per pin, we use first 17bits
|
||||||
#else
|
#else
|
||||||
#define WLED_NUM_PINS 50
|
#define WLED_NUM_PINS (GPIO_PIN_COUNT)
|
||||||
uint8_t pinAlloc[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // 56bit, 1 bit per pin, we use 50 bits on ESP32-S3
|
uint64_t pinAlloc : 56; // 56 bits, 1 bit per pin, we use 50 bits on ESP32-S3
|
||||||
uint8_t ledcAlloc[2] = {0x00, 0x00}; //16 LEDC channels
|
uint16_t ledcAlloc : 16; // up to 16 LEDC channels (WLED_MAX_ANALOG_CHANNELS)
|
||||||
PinOwner ownerTag[WLED_NUM_PINS] = { PinOwner::None }; // new MCU's have up to 50 GPIO
|
#endif
|
||||||
#endif
|
uint8_t i2cAllocCount : 4; // allow multiple allocation of I2C bus pins but keep track of allocations
|
||||||
struct {
|
uint8_t spiAllocCount : 4; // allow multiple allocation of SPI bus pins but keep track of allocations
|
||||||
uint8_t i2cAllocCount : 4; // allow multiple allocation of I2C bus pins but keep track of allocations
|
} __attribute__ ((packed));
|
||||||
uint8_t spiAllocCount : 4; // allow multiple allocation of SPI bus pins but keep track of allocations
|
PinOwner ownerTag[WLED_NUM_PINS] = { PinOwner::None };
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PinManagerClass() : i2cAllocCount(0), spiAllocCount(0) {}
|
PinManagerClass() : pinAlloc(0), i2cAllocCount(0), spiAllocCount(0) {}
|
||||||
// De-allocates a single pin
|
// De-allocates a single pin
|
||||||
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)
|
||||||
@ -101,13 +102,9 @@ class PinManagerClass {
|
|||||||
// ethernet, etc..
|
// ethernet, etc..
|
||||||
bool allocateMultiplePins(const managed_pin_type * mptArray, byte arrayElementCount, PinOwner tag );
|
bool allocateMultiplePins(const managed_pin_type * mptArray, byte arrayElementCount, PinOwner tag );
|
||||||
|
|
||||||
#if !defined(ESP8266) // ESP8266 compiler doesn't understand deprecated attribute
|
|
||||||
[[deprecated("Replaced by three-parameter allocatePin(gpio, output, ownerTag), for improved debugging")]]
|
[[deprecated("Replaced by three-parameter allocatePin(gpio, output, ownerTag), for improved debugging")]]
|
||||||
#endif
|
|
||||||
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); }
|
||||||
#if !defined(ESP8266) // ESP8266 compiler doesn't understand deprecated attribute
|
|
||||||
[[deprecated("Replaced by two-parameter deallocatePin(gpio, ownerTag), for improved debugging")]]
|
[[deprecated("Replaced by two-parameter deallocatePin(gpio, ownerTag), for improved debugging")]]
|
||||||
#endif
|
|
||||||
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
|
||||||
|
@ -176,7 +176,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
}
|
}
|
||||||
awmode = request->arg(aw).toInt();
|
awmode = request->arg(aw).toInt();
|
||||||
uint16_t freq = request->arg(sp).toInt();
|
uint16_t freq = request->arg(sp).toInt();
|
||||||
if (IS_PWM(type)) {
|
if (Bus::isPWM(type)) {
|
||||||
switch (freq) {
|
switch (freq) {
|
||||||
case 0 : freq = WLED_PWM_FREQ/2; break;
|
case 0 : freq = WLED_PWM_FREQ/2; break;
|
||||||
case 1 : freq = WLED_PWM_FREQ*2/3; break;
|
case 1 : freq = WLED_PWM_FREQ*2/3; break;
|
||||||
@ -185,7 +185,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
case 3 : freq = WLED_PWM_FREQ*2; break;
|
case 3 : freq = WLED_PWM_FREQ*2; break;
|
||||||
case 4 : freq = WLED_PWM_FREQ*10/3; break; // uint16_t max (19531 * 3.333)
|
case 4 : freq = WLED_PWM_FREQ*10/3; break; // uint16_t max (19531 * 3.333)
|
||||||
}
|
}
|
||||||
} else if (IS_DIGITAL(type) && IS_2PIN(type)) {
|
} else if (Bus::is2Pin(type)) {
|
||||||
switch (freq) {
|
switch (freq) {
|
||||||
default:
|
default:
|
||||||
case 0 : freq = 1000; break;
|
case 0 : freq = 1000; break;
|
||||||
@ -198,7 +198,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
freq = 0;
|
freq = 0;
|
||||||
}
|
}
|
||||||
channelSwap = Bus::hasWhite(type) ? request->arg(wo).toInt() : 0;
|
channelSwap = Bus::hasWhite(type) ? request->arg(wo).toInt() : 0;
|
||||||
if (type == TYPE_ONOFF || IS_PWM(type) || IS_VIRTUAL(type)) { // analog and virtual
|
if (Bus::isOnOff(type) || Bus::isPWM(type) || Bus::isVirtual(type)) { // analog and virtual
|
||||||
maPerLed = 0;
|
maPerLed = 0;
|
||||||
maMax = 0;
|
maMax = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -214,7 +214,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
}
|
}
|
||||||
//doInitBusses = busesChanged; // we will do that below to ensure all input data is processed
|
//doInitBusses = busesChanged; // we will do that below to ensure all input data is processed
|
||||||
|
|
||||||
ColorOrderMap com = {};
|
// we will not bother with pre-allocating ColorOrderMappings vector
|
||||||
for (int s = 0; s < WLED_MAX_COLOR_ORDER_MAPPINGS; s++) {
|
for (int s = 0; s < WLED_MAX_COLOR_ORDER_MAPPINGS; s++) {
|
||||||
int offset = s < 10 ? 48 : 55;
|
int offset = s < 10 ? 48 : 55;
|
||||||
char xs[4] = "XS"; xs[2] = offset+s; xs[3] = 0; //start LED
|
char xs[4] = "XS"; xs[2] = offset+s; xs[3] = 0; //start LED
|
||||||
@ -226,10 +226,9 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
length = request->arg(xc).toInt();
|
length = request->arg(xc).toInt();
|
||||||
colorOrder = request->arg(xo).toInt() & 0x0F;
|
colorOrder = request->arg(xo).toInt() & 0x0F;
|
||||||
colorOrder |= (request->arg(xw).toInt() & 0x0F) << 4; // add W swap information
|
colorOrder |= (request->arg(xw).toInt() & 0x0F) << 4; // add W swap information
|
||||||
com.add(start, length, colorOrder);
|
if (!BusManager::getColorOrderMap().add(start, length, colorOrder)) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BusManager::updateColorOrderMap(com);
|
|
||||||
|
|
||||||
// update other pins
|
// update other pins
|
||||||
#ifndef WLED_DISABLE_INFRARED
|
#ifndef WLED_DISABLE_INFRARED
|
||||||
|
@ -186,8 +186,8 @@ void WLED::loop()
|
|||||||
unsigned maxChannels = 0;
|
unsigned maxChannels = 0;
|
||||||
for (unsigned i = 0; i < WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES; i++) {
|
for (unsigned i = 0; i < WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES; i++) {
|
||||||
if (busConfigs[i] == nullptr) break;
|
if (busConfigs[i] == nullptr) break;
|
||||||
if (!IS_DIGITAL(busConfigs[i]->type)) continue;
|
if (!Bus::isDigital(busConfigs[i]->type)) continue;
|
||||||
if (!IS_2PIN(busConfigs[i]->type)) {
|
if (!Bus::is2Pin(busConfigs[i]->type)) {
|
||||||
digitalCount++;
|
digitalCount++;
|
||||||
unsigned channels = Bus::getNumberOfChannels(busConfigs[i]->type);
|
unsigned channels = Bus::getNumberOfChannels(busConfigs[i]->type);
|
||||||
if (busConfigs[i]->count > maxLedsOnBus) maxLedsOnBus = busConfigs[i]->count;
|
if (busConfigs[i]->count > maxLedsOnBus) maxLedsOnBus = busConfigs[i]->count;
|
||||||
|
@ -348,6 +348,8 @@ void getSettingsJS(byte subPage, char* dest)
|
|||||||
|
|
||||||
appendGPIOinfo();
|
appendGPIOinfo();
|
||||||
|
|
||||||
|
oappend(SET_F("d.ledTypes=")); oappend(BusManager::getLEDTypesJSONString().c_str()); oappend(";");
|
||||||
|
|
||||||
// set limits
|
// set limits
|
||||||
oappend(SET_F("bLimits("));
|
oappend(SET_F("bLimits("));
|
||||||
oappend(itoa(WLED_MAX_BUSSES,nS,10)); oappend(",");
|
oappend(itoa(WLED_MAX_BUSSES,nS,10)); oappend(",");
|
||||||
@ -392,7 +394,7 @@ void getSettingsJS(byte subPage, char* dest)
|
|||||||
int nPins = bus->getPins(pins);
|
int nPins = bus->getPins(pins);
|
||||||
for (int i = 0; i < nPins; i++) {
|
for (int i = 0; i < nPins; i++) {
|
||||||
lp[1] = offset+i;
|
lp[1] = offset+i;
|
||||||
if (pinManager.isPinOk(pins[i]) || IS_VIRTUAL(bus->getType())) sappend('v',lp,pins[i]);
|
if (pinManager.isPinOk(pins[i]) || bus->isVirtual()) sappend('v',lp,pins[i]);
|
||||||
}
|
}
|
||||||
sappend('v',lc,bus->getLength());
|
sappend('v',lc,bus->getLength());
|
||||||
sappend('v',lt,bus->getType());
|
sappend('v',lt,bus->getType());
|
||||||
@ -404,7 +406,7 @@ void getSettingsJS(byte subPage, char* dest)
|
|||||||
sappend('v',aw,bus->getAutoWhiteMode());
|
sappend('v',aw,bus->getAutoWhiteMode());
|
||||||
sappend('v',wo,bus->getColorOrder() >> 4);
|
sappend('v',wo,bus->getColorOrder() >> 4);
|
||||||
unsigned speed = bus->getFrequency();
|
unsigned speed = bus->getFrequency();
|
||||||
if (IS_PWM(bus->getType())) {
|
if (bus->isPWM()) {
|
||||||
switch (speed) {
|
switch (speed) {
|
||||||
case WLED_PWM_FREQ/2 : speed = 0; break;
|
case WLED_PWM_FREQ/2 : speed = 0; break;
|
||||||
case WLED_PWM_FREQ*2/3 : speed = 1; break;
|
case WLED_PWM_FREQ*2/3 : speed = 1; break;
|
||||||
@ -413,7 +415,7 @@ void getSettingsJS(byte subPage, char* dest)
|
|||||||
case WLED_PWM_FREQ*2 : speed = 3; break;
|
case WLED_PWM_FREQ*2 : speed = 3; break;
|
||||||
case WLED_PWM_FREQ*10/3 : speed = 4; break; // uint16_t max (19531 * 3.333)
|
case WLED_PWM_FREQ*10/3 : speed = 4; break; // uint16_t max (19531 * 3.333)
|
||||||
}
|
}
|
||||||
} else if (IS_DIGITAL(bus->getType()) && IS_2PIN(bus->getType())) {
|
} else if (bus->is2Pin()) {
|
||||||
switch (speed) {
|
switch (speed) {
|
||||||
case 1000 : speed = 0; break;
|
case 1000 : speed = 0; break;
|
||||||
case 2000 : speed = 1; break;
|
case 2000 : speed = 1; break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user