Neopixel fix (#8845)
* improve neopixel definition for all boards * Improve NeoPixel definition for all boards * neopixelWrite uses Peirpheral Manager now The function can now be used for many GPIOs in the same sketch by using Peripheral Manager attach/detach, not being necesary to worry about initialization. * improve error message * check if pin is RGB_BUILTIN * fixes boards that don't RGB_BUILTIN
This commit is contained in:
parent
2ac1c06809
commit
de7cac11ae
3 changed files with 18 additions and 32 deletions
|
|
@ -3,22 +3,15 @@
|
|||
|
||||
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val){
|
||||
rmt_data_t led_data[24];
|
||||
static bool initialized = false;
|
||||
|
||||
uint8_t _pin = pin;
|
||||
// Verify if the pin used is RGB_BUILTIN and fix GPIO number
|
||||
#ifdef RGB_BUILTIN
|
||||
if(pin == RGB_BUILTIN){
|
||||
_pin = RGB_BUILTIN - SOC_GPIO_PIN_COUNT;
|
||||
}
|
||||
pin = pin == RGB_BUILTIN ? pin - SOC_GPIO_PIN_COUNT : pin;
|
||||
#endif
|
||||
|
||||
if(!initialized){
|
||||
if (!rmtInit(_pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)){
|
||||
log_e("RGB LED driver initialization failed!");
|
||||
if (!rmtInit(pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)) {
|
||||
log_e("RGB LED driver initialization failed for GPIO%d!", pin);
|
||||
return;
|
||||
}
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
int color[] = {green_val, red_val, blue_val}; // Color coding is in order GREEN, RED, BLUE
|
||||
int i = 0;
|
||||
|
|
@ -40,5 +33,5 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue
|
|||
i++;
|
||||
}
|
||||
}
|
||||
rmtWrite(_pin, led_data, RMT_SYMBOLS_OF(led_data), RMT_WAIT_FOR_EVER);
|
||||
rmtWrite(pin, led_data, RMT_SYMBOLS_OF(led_data), RMT_WAIT_FOR_EVER);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,15 +19,11 @@
|
|||
* Parameters can be changed by the user. In a single LED circuit, it will just blink.
|
||||
*/
|
||||
|
||||
// The effect seen in ESP32C3, ESP32S2 and ESP32S3 is like a Blink of RGB LED
|
||||
#if CONFIG_IDF_TARGET_ESP32S2
|
||||
#define BUILTIN_RGBLED_PIN 18
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#define BUILTIN_RGBLED_PIN 48 // 48 or 38
|
||||
#elif CONFIG_IDF_TARGET_ESP32C3
|
||||
#define BUILTIN_RGBLED_PIN 8
|
||||
// The effect seen in (Espressif devkits) ESP32C6, ESP32H2, ESP32C3, ESP32S2 and ESP32S3 is like a Blink of RGB LED
|
||||
#ifdef PIN_NEOPIXEL
|
||||
#define BUILTIN_RGBLED_PIN PIN_NEOPIXEL
|
||||
#else
|
||||
#define BUILTIN_RGBLED_PIN 21 // ESP32 has no builtin RGB LED
|
||||
#define BUILTIN_RGBLED_PIN 21 // ESP32 has no builtin RGB LED (PIN_NEOPIXEL)
|
||||
#endif
|
||||
|
||||
#define NR_OF_LEDS 8*4
|
||||
|
|
|
|||
|
|
@ -26,14 +26,11 @@
|
|||
|
||||
|
||||
// Default DevKit RGB LED GPIOs:
|
||||
#if CONFIG_IDF_TARGET_ESP32S2
|
||||
#define MY_LED_GPIO 18
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#define MY_LED_GPIO 48 // 48 or 38
|
||||
#elif CONFIG_IDF_TARGET_ESP32C3
|
||||
#define MY_LED_GPIO 8
|
||||
// The effect seen in (Espressif devkits) ESP32C6, ESP32H2, ESP32C3, ESP32S2 and ESP32S3 is like a Blink of RGB LED
|
||||
#ifdef PIN_NEOPIXEL
|
||||
#define MY_LED_GPIO PIN_NEOPIXEL
|
||||
#else
|
||||
#define MY_LED_GPIO 21 // Any, ESP32 has no RGB LED - depends on circuit setup
|
||||
#define MY_LED_GPIO 21 // ESP32 has no builtin RGB LED (PIN_NEOPIXEL)
|
||||
#endif
|
||||
|
||||
// Set the correct GPIO to any necessary by changing RGB_LED_GPIO value
|
||||
|
|
|
|||
Loading…
Reference in a new issue