diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2020-01-03 15:15:36 -0800 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2020-01-03 15:15:36 -0800 |
| commit | f6ec1ea17284ce6874a79db1998df21b81bc4ebd (patch) | |
| tree | 889e56d3219ea2f2f583eaedc0185d9a743bfbe4 | |
| parent | 6afb8dadbcc91562deb413638e2ef7e17f3305a6 (diff) | |
Throw an error when we cannot allocate PWM pixel buffer
| -rw-r--r-- | ports/nrf/common-hal/neopixel_write/__init__.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/ports/nrf/common-hal/neopixel_write/__init__.c b/ports/nrf/common-hal/neopixel_write/__init__.c index 3b67778a6..3052e908d 100644 --- a/ports/nrf/common-hal/neopixel_write/__init__.c +++ b/ports/nrf/common-hal/neopixel_write/__init__.c @@ -130,7 +130,17 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout if (pattern_size <= sizeof(one_pixel)) { pixels_pattern = (uint16_t *) one_pixel; } else { - pixels_pattern = (uint16_t *) m_malloc_maybe(pattern_size, false); + uint8_t sd_en = 0; + (void) sd_softdevice_is_enabled(&sd_en); + if (sd_en) { + // If the soft device is enabled then we must use PWM to + // transmit. This takes a bunch of memory to do so raise an + // exception if we can't. + pixels_pattern = (uint16_t *) m_malloc(pattern_size, false); + } else { + pixels_pattern = (uint16_t *) m_malloc_maybe(pattern_size, false); + } + pattern_on_heap = true; } } |
