Throw an error when we cannot allocate PWM pixel buffer

This commit is contained in:
Scott Shawcroft 2020-01-03 15:15:36 -08:00
parent 6afb8dadbc
commit f6ec1ea172
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E
1 changed files with 11 additions and 1 deletions

View File

@ -129,8 +129,18 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
if ( pwm != NULL ) { if ( pwm != NULL ) {
if (pattern_size <= sizeof(one_pixel)) { if (pattern_size <= sizeof(one_pixel)) {
pixels_pattern = (uint16_t *) one_pixel; pixels_pattern = (uint16_t *) one_pixel;
} else {
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 { } else {
pixels_pattern = (uint16_t *) m_malloc_maybe(pattern_size, false); pixels_pattern = (uint16_t *) m_malloc_maybe(pattern_size, false);
}
pattern_on_heap = true; pattern_on_heap = true;
} }
} }