diff options
| author | Joseph Chiu <joechiu@joechiu.com> | 2021-05-05 03:43:42 -0700 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2021-05-30 23:36:50 +1000 |
| commit | c5d2095e593e5f0834179b04fcb7b3675524408d (patch) | |
| tree | 0b76e1ee9e9d1dd6761769cdb90de59e74fb2b2b | |
| parent | a18f695e294baf22bd7862e5be57aa0c820c7c77 (diff) | |
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 #7221.
| -rw-r--r-- | ports/esp32/espneopixel.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/ports/esp32/espneopixel.c b/ports/esp32/espneopixel.c index bcdf38873..a5937b9c6 100644 --- a/ports/esp32/espneopixel.c +++ b/ports/esp32/espneopixel.c @@ -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++; @@ -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; |
