Skip to content

Commit

Permalink
esp32/espneopixel: Add support for GPIO32 and GPIO33.
Browse files Browse the repository at this point in the history
Adds support for NeoPixels on GPIO32 and GPIO33 on ESP32.  Otherwise,
NeoPixels wired to GPIO32/33 wll silently fail without any hints to the
user.

With thanks to @robert-hh.

Fixes issue #7221.
  • Loading branch information
toybuilder authored and dpgeorge committed May 30, 2021
1 parent a18f695 commit c5d2095
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ports/esp32/espneopixel.c
Expand Up @@ -11,9 +11,17 @@

void IRAM_ATTR esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes, uint8_t timing) {
uint8_t *p, *end, pix, mask;
uint32_t t, time0, time1, period, c, startTime, pinMask;
uint32_t t, time0, time1, period, c, startTime, pinMask, gpio_reg_set, gpio_reg_clear;

pinMask = 1 << pin;
if (pin < 32) {
pinMask = 1 << pin;
gpio_reg_set = GPIO_OUT_W1TS_REG;
gpio_reg_clear = GPIO_OUT_W1TC_REG;
} else {
pinMask = 1 << (pin - 32);
gpio_reg_set = GPIO_OUT1_W1TS_REG;
gpio_reg_clear = GPIO_OUT1_W1TC_REG;
}
p = pixels;
end = p + numBytes;
pix = *p++;
Expand Down Expand Up @@ -42,12 +50,12 @@ void IRAM_ATTR esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numByte
while (((c = mp_hal_ticks_cpu()) - startTime) < period) {
; // Wait for bit start
}
GPIO_REG_WRITE(GPIO_OUT_W1TS_REG, pinMask); // Set high
GPIO_REG_WRITE(gpio_reg_set, pinMask); // Set high
startTime = c; // Save start time
while (((c = mp_hal_ticks_cpu()) - startTime) < t) {
; // Wait high duration
}
GPIO_REG_WRITE(GPIO_OUT_W1TC_REG, pinMask); // Set low
GPIO_REG_WRITE(gpio_reg_clear, pinMask); // Set low
if (!(mask >>= 1)) { // Next bit/byte
if (p >= end) {
break;
Expand Down

0 comments on commit c5d2095

Please sign in to comment.