Skip to content

Commit f6ec1ea

Browse files
committed
Throw an error when we cannot allocate PWM pixel buffer
1 parent 6afb8da commit f6ec1ea

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ports/nrf/common-hal/neopixel_write/__init__.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,17 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
130130
if (pattern_size <= sizeof(one_pixel)) {
131131
pixels_pattern = (uint16_t *) one_pixel;
132132
} else {
133-
pixels_pattern = (uint16_t *) m_malloc_maybe(pattern_size, false);
133+
uint8_t sd_en = 0;
134+
(void) sd_softdevice_is_enabled(&sd_en);
135+
if (sd_en) {
136+
// If the soft device is enabled then we must use PWM to
137+
// transmit. This takes a bunch of memory to do so raise an
138+
// exception if we can't.
139+
pixels_pattern = (uint16_t *) m_malloc(pattern_size, false);
140+
} else {
141+
pixels_pattern = (uint16_t *) m_malloc_maybe(pattern_size, false);
142+
}
143+
134144
pattern_on_heap = true;
135145
}
136146
}

0 commit comments

Comments
 (0)