Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neopixel fix #8845

Merged
merged 7 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 10 additions & 17 deletions cores/esp32/esp32-hal-rgb-led.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,27 @@

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!");
return;
}
initialized = true;
if (!rmtInit(pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)) {
log_e("RGB LED driver initialization failed for GPIO%d!", pin);
return;
}

int color[] = {green_val, red_val, blue_val}; // Color coding is in order GREEN, RED, BLUE
int i = 0;
for(int col=0; col<3; col++ ){
for(int bit=0; bit<8; bit++){
if((color[col] & (1<<(7-bit)))){
for (int col = 0; col < 3; col++ ) {
for (int bit = 0; bit < 8; bit++) {
if ((color[col] & (1 << (7 - bit)))) {
// HIGH bit
led_data[i].level0 = 1; // T1H
led_data[i].duration0 = 8; // 0.8us
led_data[i].level1 = 0; // T1L
led_data[i].duration1 = 4; // 0.4us
}else{
} else {
// LOW bit
led_data[i].level0 = 1; // T0H
led_data[i].duration0 = 4; // 0.4us
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down