Skip to content

Commit c5d2095

Browse files
toybuilderdpgeorge
authored andcommitted
esp32/espneopixel: Add support for GPIO32 and GPIO33.
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 micropython#7221.
1 parent a18f695 commit c5d2095

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Diff for: ports/esp32/espneopixel.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@
1111

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

16-
pinMask = 1 << pin;
16+
if (pin < 32) {
17+
pinMask = 1 << pin;
18+
gpio_reg_set = GPIO_OUT_W1TS_REG;
19+
gpio_reg_clear = GPIO_OUT_W1TC_REG;
20+
} else {
21+
pinMask = 1 << (pin - 32);
22+
gpio_reg_set = GPIO_OUT1_W1TS_REG;
23+
gpio_reg_clear = GPIO_OUT1_W1TC_REG;
24+
}
1725
p = pixels;
1826
end = p + numBytes;
1927
pix = *p++;
@@ -42,12 +50,12 @@ void IRAM_ATTR esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numByte
4250
while (((c = mp_hal_ticks_cpu()) - startTime) < period) {
4351
; // Wait for bit start
4452
}
45-
GPIO_REG_WRITE(GPIO_OUT_W1TS_REG, pinMask); // Set high
53+
GPIO_REG_WRITE(gpio_reg_set, pinMask); // Set high
4654
startTime = c; // Save start time
4755
while (((c = mp_hal_ticks_cpu()) - startTime) < t) {
4856
; // Wait high duration
4957
}
50-
GPIO_REG_WRITE(GPIO_OUT_W1TC_REG, pinMask); // Set low
58+
GPIO_REG_WRITE(gpio_reg_clear, pinMask); // Set low
5159
if (!(mask >>= 1)) { // Next bit/byte
5260
if (p >= end) {
5361
break;

0 commit comments

Comments
 (0)