From 2bb74233cc40f77f67fd97cd33bc9963974249d5 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 7 Jan 2020 23:58:15 +0100 Subject: [PATCH] ESP32 support for solid (analog) RGB(W) stripes uses ledc funtion to drive analog RGB(W) stripes with 3, 4 or 5 channels. uses ledc funtion to drive analog RGB(W) stripes with 3, 4 or 5 channels. the define in platformio.ini needs to be "WLED_USE_ANALOG_LEDS" --- platformio.ini | 6 ++-- wled00/NpbWrapper.h | 83 +++++++++++++++++++++++++++++++-------------- 2 files changed, 60 insertions(+), 29 deletions(-) diff --git a/platformio.ini b/platformio.ini index 9d96bf4c..aa889291 100644 --- a/platformio.ini +++ b/platformio.ini @@ -197,7 +197,7 @@ build_flags = ${common.build_flags} ${common:esp8266_1M.build_flags} -D WLED_DISABLE_HUESYNC - -D WLED_ENABLE_ANALOG_LEDS + -D WLED_USE_ANALOG_LEDS lib_deps = ${common.lib_deps_external} @@ -211,7 +211,7 @@ build_flags = ${common.build_flags} ${common:esp8266_1M.build_flags} -D WLED_DISABLE_HUESYNC - -D WLED_ENABLE_ANALOG_LEDS + -D WLED_USE_ANALOG_LEDS -D WLED_USE_H801 lib_deps = ${common.lib_deps_external} @@ -226,7 +226,7 @@ build_flags = ${common.build_flags} ${common:esp8266_1M.build_flags} -D WLED_DISABLE_HUESYNC - -D WLED_ENABLE_ANALOG_LEDS + -D WLED_USE_ANALOG_LEDS -D WLED_USE_H801 -D WLED_ENABLE_5CH_LEDS lib_deps = diff --git a/wled00/NpbWrapper.h b/wled00/NpbWrapper.h index 05d73868..463f429e 100644 --- a/wled00/NpbWrapper.h +++ b/wled00/NpbWrapper.h @@ -130,41 +130,72 @@ public: _pGrbw = new NeoPixelBrightnessBus(countPixels, LEDPIN); #endif _pGrbw->Begin(); - - #ifdef WLED_USE_ANALOG_LEDS - pinMode(WPIN, OUTPUT); - #ifdef WLED_USE_5CH_LEDS - pinMode(W2PIN, OUTPUT); - #endif - #endif - break; } - #ifdef WLED_USE_ANALOG_LEDS - //init PWM pins - PINs 5,12,13,15 are used with Magic Home LED Controller - pinMode(RPIN, OUTPUT); - pinMode(GPIN, OUTPUT); - pinMode(BPIN, OUTPUT); - analogWriteRange(255); //same range as one RGB channel - analogWriteFreq(880); //PWM frequency proven as good for LEDs + #ifdef WLED_USE_ANALOG_LEDS + #ifdef ARDUINO_ARCH_ESP32 + ledcSetup(0, 5000, 8); + ledcAttachPin(RPIN, 0); + ledcSetup(1, 5000, 8); + ledcAttachPin(GPIN, 1); + ledcSetup(2, 5000, 8); + ledcAttachPin(BPIN, 2); + if(_type == NeoPixelType_Grbw) + { + ledcSetup(3, 5000, 8); + ledcAttachPin(WPIN, 3); + #ifdef WLED_USE_5CH_LEDS + ledcSetup(4, 5000, 8); + ledcAttachPin(W2PIN, 4); + #endif + } + #else // ESP8266 + //init PWM pins - PINs 5,12,13,15 are used with Magic Home LED Controller + pinMode(RPIN, OUTPUT); + pinMode(GPIN, OUTPUT); + pinMode(BPIN, OUTPUT); + if(_type == NeoPixelType_Grbw) + { + pinMode(WPIN, OUTPUT); + #ifdef WLED_USE_5CH_LEDS + pinMode(W2PIN, OUTPUT); + #endif + } + analogWriteRange(255); //same range as one RGB channel + analogWriteFreq(880); //PWM frequency proven as good for LEDs + #endif #endif } #ifdef WLED_USE_ANALOG_LEDS void SetRgbwPwm(uint8_t r, uint8_t g, uint8_t b, uint8_t w, uint8_t w2=0) { - analogWrite(RPIN, r); - analogWrite(GPIN, g); - analogWrite(BPIN, b); - switch (_type) { - case NeoPixelType_Grb: break; - #ifdef WLED_USE_5CH_LEDS - case NeoPixelType_Grbw: analogWrite(WPIN, w); analogWrite(W2PIN, w2); break; - #else - case NeoPixelType_Grbw: analogWrite(WPIN, w); break; - #endif - } + #ifdef ARDUINO_ARCH_ESP32 + ledcWrite(0, r); //RPIN + ledcWrite(1, g); //GPIN + ledcWrite(2, b); //BPIN + switch (_type) { + case NeoPixelType_Grb: break; + #ifdef WLED_USE_5CH_LEDS + case NeoPixelType_Grbw: ledcWrite(3, w); ledcWrite(4, w2); break; + #else + case NeoPixelType_Grbw: ledcWrite(3, w); break; + #endif + } + #else + analogWrite(RPIN, r); + analogWrite(GPIN, g); + analogWrite(BPIN, b); + switch (_type) { + case NeoPixelType_Grb: break; + #ifdef WLED_USE_5CH_LEDS + case NeoPixelType_Grbw: analogWrite(WPIN, w); analogWrite(W2PIN, w2); break; + #else + case NeoPixelType_Grbw: analogWrite(WPIN, w); break; + #endif + } + #endif } #endif