From 02cae2e61ea61a8b6f840a18ef7bacbbfcd0a8d8 Mon Sep 17 00:00:00 2001 From: jdiamond Date: Thu, 25 Jul 2024 04:47:44 +0000 Subject: [PATCH 1/9] Add example runArgs to devcountainer to access serial port. --- .devcontainer/devcontainer.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f77dc4de4..b367752d9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -12,6 +12,13 @@ } }, + // To give the container access to a device serial port, you can uncomment one of the following lines. + // You can explicitly forward the port. The docker user needs to be able to access this port, and this will only work + // if the device is plugged in from the start without reconnecting. + // "runArgs": ["--device=/dev/ttyACM0", "--group-add", "dialout"], + // Alternatively, you can give more comprehensive access to the host system. + // "runArgs": ["--privileged", "-v", "/dev/bus/usb:/dev/bus/usb", "--group-add", "dialout"], + // Set *default* container specific settings.json values on container create. "settings": { "terminal.integrated.shell.linux": "/bin/bash", From 343d766ddd6336722d14ab229f80fb03e2685316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Wed, 7 Feb 2024 17:06:18 +0100 Subject: [PATCH 2/9] 2DGEQ: Getting same sized bar width on 32x32 display before a x=32 (n times of 16) had not equal sized bars, but first was a single pixel and later a bar had 3 pixel width. This solves it to have always 2 pixel sized bars. I have to admit that I did not test with other pixel dimensions. --- wled00/FX.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index cce3098e1..9e8c80729 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -7456,7 +7456,7 @@ uint16_t mode_2DGEQ(void) { // By Will Tatam. Code reduction by Ewoud Wijma. if ((fadeoutDelay <= 1 ) || ((SEGENV.call % fadeoutDelay) == 0)) SEGMENT.fadeToBlackBy(SEGMENT.speed); for (int x=0; x < cols; x++) { - uint8_t band = map(x, 0, cols-1, 0, NUM_BANDS - 1); + uint8_t band = map(x, 0, cols, 0, NUM_BANDS); if (NUM_BANDS < 16) band = map(band, 0, NUM_BANDS - 1, 0, 15); // always use full range. comment out this line to get the previous behaviour. band = constrain(band, 0, 15); unsigned colorIndex = band * 17; From 0af1ec3bde17de01946653f0e7cef9fd1d475860 Mon Sep 17 00:00:00 2001 From: Alexey Panteleev Date: Sat, 27 Jul 2024 10:44:53 -0700 Subject: [PATCH 3/9] Added a parameter for blur amount in the Fire 2012 effect. --- wled00/FX.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 4b7f9ce36..0bdcb042f 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -2106,14 +2106,17 @@ uint16_t mode_fire_2012() { for (unsigned stripNr=0; stripNr> 2; + SEGMENT.blur(blurAmount); + } if (it != SEGENV.step) SEGENV.step = it; return FRAMETIME; } -static const char _data_FX_MODE_FIRE_2012[] PROGMEM = "Fire 2012@Cooling,Spark rate,,,Boost;;!;1;sx=64,ix=160,m12=1"; // bars +static const char _data_FX_MODE_FIRE_2012[] PROGMEM = "Fire 2012@Cooling,Spark rate,,2D Blur,Boost;;!;1;sx=64,ix=160,m12=1,c2=128"; // bars // ColorWavesWithPalettes by Mark Kriegsman: https://gist.github.com/kriegsman/8281905786e8b2632aeb From 10fdf464102fe1d415040e3604150de9af91da1e Mon Sep 17 00:00:00 2001 From: jdiamond Date: Mon, 29 Jul 2024 17:34:10 +0000 Subject: [PATCH 4/9] Clarify security implicatations. --- .devcontainer/devcontainer.json | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b367752d9..305236c91 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -13,10 +13,16 @@ }, // To give the container access to a device serial port, you can uncomment one of the following lines. - // You can explicitly forward the port. The docker user needs to be able to access this port, and this will only work - // if the device is plugged in from the start without reconnecting. + // + // You can explicitly just forward the port you want to connect to. Replace `/dev/ttyACM0` with the serial port for + // your device. This will only work if the device is plugged in from the start without reconnecting. Adding the + // `dialout` group is needed if read/write permisions for the port are limitted to the dialout user. // "runArgs": ["--device=/dev/ttyACM0", "--group-add", "dialout"], - // Alternatively, you can give more comprehensive access to the host system. + // + // Alternatively, you can give more comprehensive access to the host system. This will expose all the host devices to + // the container. Adding the `dialout` group is needed if read/write permisions for the port are limitted to the + // dialout user. This could allow the container to modify unrelated serial devices, which would be a similar level of + // risk to running the build directly on the host. // "runArgs": ["--privileged", "-v", "/dev/bus/usb:/dev/bus/usb", "--group-add", "dialout"], // Set *default* container specific settings.json values on container create. From 050f7ebddfae349339f27c475d5e44458bb9da82 Mon Sep 17 00:00:00 2001 From: jdiamond Date: Mon, 29 Jul 2024 18:00:46 +0000 Subject: [PATCH 5/9] Add note for Windows. --- .devcontainer/devcontainer.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 305236c91..2a8e4712d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -13,6 +13,8 @@ }, // To give the container access to a device serial port, you can uncomment one of the following lines. + // Note: If running on Windows, you will have to do some additional steps: + // https://stackoverflow.com/questions/68527888/how-can-i-use-a-usb-com-port-inside-of-a-vscode-development-container // // You can explicitly just forward the port you want to connect to. Replace `/dev/ttyACM0` with the serial port for // your device. This will only work if the device is plugged in from the start without reconnecting. Adding the From 5c247d283357895a56e51379eff07dc9a97703bf Mon Sep 17 00:00:00 2001 From: PaoloTK Date: Thu, 1 Aug 2024 20:25:18 +0200 Subject: [PATCH 6/9] first implementation --- wled00/bus_manager.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/wled00/bus_manager.cpp b/wled00/bus_manager.cpp index 7aa3351cf..9e16e4458 100644 --- a/wled00/bus_manager.cpp +++ b/wled00/bus_manager.cpp @@ -40,6 +40,19 @@ uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, byte #define DEBUG_PRINTF_P(x...) #endif +// ESP8266 has 1 MHz clock +#ifdef ESP8266 + #define CLOCK_FREQUENCY 1e6f +#else + // Use XTAL clock if possible to avoid timer frequency error when setting APB clock < 80 Mhz + // https://github.com/espressif/arduino-esp32/blob/2.0.2/cores/esp32/esp32-hal-ledc.c + #ifdef SOC_LEDC_SUPPORT_XTAL_CLOCK + #define CLOCK_FREQUENCY 40e6f + #else + #define CLOCK_FREQUENCY 80e6f + #endif +#endif + //color mangling macros #define RGBW32(r,g,b,w) (uint32_t((byte(w) << 24) | (byte(r) << 16) | (byte(g) << 8) | (byte(b)))) #define R(c) (byte((c) >> 16)) @@ -384,12 +397,10 @@ BusPwm::BusPwm(BusConfig &bc) if (!IS_PWM(bc.type)) return; unsigned numPins = NUM_PWM_PINS(bc.type); _frequency = bc.frequency ? bc.frequency : WLED_PWM_FREQ; + // duty cycle resolution (_depth) can be extracted from this formula: CLOCK_FREQUENCY > _frequency * 2^_depth + _depth = uint8_t(log((float)CLOCK_FREQUENCY / (float)_frequency) / log(2.0)); #ifdef ESP8266 - // duty cycle resolution (_depth) can be extracted from this formula: 1MHz > _frequency * 2^_depth - if (_frequency > 1760) _depth = 8; - else if (_frequency > 880) _depth = 9; - else _depth = 10; // WLED_PWM_FREQ <= 880Hz analogWriteRange((1<<_depth)-1); analogWriteFreq(_frequency); #else @@ -397,11 +408,6 @@ BusPwm::BusPwm(BusConfig &bc) if (_ledcStart == 255) { //no more free LEDC channels deallocatePins(); return; } - // duty cycle resolution (_depth) can be extracted from this formula: 80MHz > _frequency * 2^_depth - if (_frequency > 78124) _depth = 9; - else if (_frequency > 39062) _depth = 10; - else if (_frequency > 19531) _depth = 11; - else _depth = 12; // WLED_PWM_FREQ <= 19531Hz #endif for (unsigned i = 0; i < numPins; i++) { @@ -419,7 +425,7 @@ BusPwm::BusPwm(BusConfig &bc) } _data = _pwmdata; // avoid malloc() and use stack _valid = true; - DEBUG_PRINTF_P(PSTR("%successfully inited PWM strip with type %u and pins %u,%u,%u,%u,%u\n"), _valid?"S":"Uns", bc.type, _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]); } void BusPwm::setPixelColor(uint16_t pix, uint32_t c) { From 1123d85fd2f828fdcfe4afc911bd7d0c91ac3249 Mon Sep 17 00:00:00 2001 From: PaoloTK Date: Sat, 3 Aug 2024 15:54:39 +0200 Subject: [PATCH 7/9] removed float math and log(), added max bit width --- wled00/bus_manager.cpp | 15 +-------------- wled00/const.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/wled00/bus_manager.cpp b/wled00/bus_manager.cpp index 9e16e4458..e626a2962 100644 --- a/wled00/bus_manager.cpp +++ b/wled00/bus_manager.cpp @@ -40,19 +40,6 @@ uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, byte #define DEBUG_PRINTF_P(x...) #endif -// ESP8266 has 1 MHz clock -#ifdef ESP8266 - #define CLOCK_FREQUENCY 1e6f -#else - // Use XTAL clock if possible to avoid timer frequency error when setting APB clock < 80 Mhz - // https://github.com/espressif/arduino-esp32/blob/2.0.2/cores/esp32/esp32-hal-ledc.c - #ifdef SOC_LEDC_SUPPORT_XTAL_CLOCK - #define CLOCK_FREQUENCY 40e6f - #else - #define CLOCK_FREQUENCY 80e6f - #endif -#endif - //color mangling macros #define RGBW32(r,g,b,w) (uint32_t((byte(w) << 24) | (byte(r) << 16) | (byte(g) << 8) | (byte(b)))) #define R(c) (byte((c) >> 16)) @@ -398,7 +385,7 @@ BusPwm::BusPwm(BusConfig &bc) unsigned numPins = NUM_PWM_PINS(bc.type); _frequency = bc.frequency ? bc.frequency : WLED_PWM_FREQ; // duty cycle resolution (_depth) can be extracted from this formula: CLOCK_FREQUENCY > _frequency * 2^_depth - _depth = uint8_t(log((float)CLOCK_FREQUENCY / (float)_frequency) / log(2.0)); + for (_depth=MAX_BIT_WIDTH; _depth>8; _depth--) if (((uint32_t(CLOCK_FREQUENCY)/_frequency)>>_depth) > 0) break; #ifdef ESP8266 analogWriteRange((1<<_depth)-1); diff --git a/wled00/const.h b/wled00/const.h index 0ff70e47d..110ef9f0d 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -521,6 +521,35 @@ #endif #endif +#ifndef CLOCK_FREQUENCY + #ifdef ESP8266 + // 1 MHz clock + #define CLOCK_FREQUENCY 1e6f + #else + // Use XTAL clock if possible to avoid timer frequency error when setting APB clock < 80 Mhz + // https://github.com/espressif/arduino-esp32/blob/2.0.2/cores/esp32/esp32-hal-ledc.c + #ifdef SOC_LEDC_SUPPORT_XTAL_CLOCK + #define CLOCK_FREQUENCY 40e6f + #else + #define CLOCK_FREQUENCY 80e6f + #endif + #endif +#endif + +#ifndef MAX_BIT_WIDTH + #ifdef ESP8266 + #define MAX_BIT_WIDTH 10 + #else + #ifdef SOC_LEDC_TIMER_BIT_WIDE_NUM + // C6/H2/P4: 20 bit, S2/S3/C2/C3: 14 bit + #define MAX_BIT_WIDTH SOC_LEDC_TIMER_BIT_WIDE_NUM + #else + // ESP32: 32 bit + #define MAX_BIT_WIDTH 20 + #endif + #endif +#endif + #define TOUCH_THRESHOLD 32 // limit to recognize a touch, higher value means more sensitive // Size of buffer for API JSON object (increase for more segments) From 779744bd8e4b8cb851d48dfe4d8164f80ed69af2 Mon Sep 17 00:00:00 2001 From: PaoloTK Date: Sat, 3 Aug 2024 15:56:29 +0200 Subject: [PATCH 8/9] typo in comment --- wled00/const.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/const.h b/wled00/const.h index 110ef9f0d..d792f592a 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -544,7 +544,7 @@ // C6/H2/P4: 20 bit, S2/S3/C2/C3: 14 bit #define MAX_BIT_WIDTH SOC_LEDC_TIMER_BIT_WIDE_NUM #else - // ESP32: 32 bit + // ESP32: 20 bit #define MAX_BIT_WIDTH 20 #endif #endif From 52548542d2f838208a8cbd05dc3c14dc19a13a31 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Sun, 4 Aug 2024 17:05:47 +0200 Subject: [PATCH 9/9] Remove clock/max bit overrides Move contants into bus manager --- wled00/bus_manager.cpp | 27 ++++++++++++++++++++++++++- wled00/const.h | 29 ----------------------------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/wled00/bus_manager.cpp b/wled00/bus_manager.cpp index e626a2962..d0e32b211 100644 --- a/wled00/bus_manager.cpp +++ b/wled00/bus_manager.cpp @@ -378,6 +378,31 @@ void BusDigital::cleanup() { } +#ifdef ESP8266 + // 1 MHz clock + #define CLOCK_FREQUENCY 1000000UL +#else + // Use XTAL clock if possible to avoid timer frequency error when setting APB clock < 80 Mhz + // https://github.com/espressif/arduino-esp32/blob/2.0.2/cores/esp32/esp32-hal-ledc.c + #ifdef SOC_LEDC_SUPPORT_XTAL_CLOCK + #define CLOCK_FREQUENCY 40000000UL + #else + #define CLOCK_FREQUENCY 80000000UL + #endif +#endif + +#ifdef ESP8266 + #define MAX_BIT_WIDTH 10 +#else + #ifdef SOC_LEDC_TIMER_BIT_WIDE_NUM + // C6/H2/P4: 20 bit, S2/S3/C2/C3: 14 bit + #define MAX_BIT_WIDTH SOC_LEDC_TIMER_BIT_WIDE_NUM + #else + // 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 + #endif +#endif + BusPwm::BusPwm(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite, 1, bc.reversed) { @@ -385,7 +410,7 @@ BusPwm::BusPwm(BusConfig &bc) unsigned numPins = NUM_PWM_PINS(bc.type); _frequency = bc.frequency ? bc.frequency : WLED_PWM_FREQ; // duty cycle resolution (_depth) can be extracted from this formula: CLOCK_FREQUENCY > _frequency * 2^_depth - for (_depth=MAX_BIT_WIDTH; _depth>8; _depth--) if (((uint32_t(CLOCK_FREQUENCY)/_frequency)>>_depth) > 0) break; + for (_depth = MAX_BIT_WIDTH; _depth > 8; _depth--) if (((CLOCK_FREQUENCY/_frequency) >> _depth) > 0) break; #ifdef ESP8266 analogWriteRange((1<<_depth)-1); diff --git a/wled00/const.h b/wled00/const.h index d792f592a..0ff70e47d 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -521,35 +521,6 @@ #endif #endif -#ifndef CLOCK_FREQUENCY - #ifdef ESP8266 - // 1 MHz clock - #define CLOCK_FREQUENCY 1e6f - #else - // Use XTAL clock if possible to avoid timer frequency error when setting APB clock < 80 Mhz - // https://github.com/espressif/arduino-esp32/blob/2.0.2/cores/esp32/esp32-hal-ledc.c - #ifdef SOC_LEDC_SUPPORT_XTAL_CLOCK - #define CLOCK_FREQUENCY 40e6f - #else - #define CLOCK_FREQUENCY 80e6f - #endif - #endif -#endif - -#ifndef MAX_BIT_WIDTH - #ifdef ESP8266 - #define MAX_BIT_WIDTH 10 - #else - #ifdef SOC_LEDC_TIMER_BIT_WIDE_NUM - // C6/H2/P4: 20 bit, S2/S3/C2/C3: 14 bit - #define MAX_BIT_WIDTH SOC_LEDC_TIMER_BIT_WIDE_NUM - #else - // ESP32: 20 bit - #define MAX_BIT_WIDTH 20 - #endif - #endif -#endif - #define TOUCH_THRESHOLD 32 // limit to recognize a touch, higher value means more sensitive // Size of buffer for API JSON object (increase for more segments)