summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2019-06-25 11:35:58 -0700
committerGitHub <noreply@github.com>2019-06-25 11:35:58 -0700
commitd3adfde22a01b516bd01763441ea2a279d05c1e4 (patch)
tree7c52b33f3e98c030dbd34402b997cf6d2d3fffdc
parent863de45c0afa21619afa9a4a6c9e3b0aff726015 (diff)
parentecf24420d582d0cf754583800922a9a2645b281f (diff)
Merge pull request #1968 from adafruit/4.0.x
Merge in nrf neopixel fix
-rw-r--r--ports/nrf/common-hal/neopixel_write/__init__.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/ports/nrf/common-hal/neopixel_write/__init__.c b/ports/nrf/common-hal/neopixel_write/__init__.c
index fe2bab999..78e0038e8 100644
--- a/ports/nrf/common-hal/neopixel_write/__init__.c
+++ b/ports/nrf/common-hal/neopixel_write/__init__.c
@@ -111,18 +111,23 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
//
// If there is not enough memory, we will fall back to cycle counter
// using DWT
- uint32_t pattern_size = numBytes * 8 * sizeof(uint16_t) + 2 * sizeof(uint16_t);
+
+#define PATTERN_SIZE(numBytes) (numBytes * 8 * sizeof(uint16_t) + 2 * sizeof(uint16_t))
+
+ uint32_t pattern_size = PATTERN_SIZE(numBytes);
uint16_t* pixels_pattern = NULL;
bool pattern_on_heap = false;
// Use the stack to store 1 pixels worth of PWM data for the status led. uint32_t to ensure alignment.
- uint32_t one_pixel[8 * sizeof(uint16_t) + 1];
+ // Make it at least as big as PATTERN_SIZE(3), for one pixel of RGB data.
+ // PATTERN_SIZE is a multiple of 4, so we don't need round up to make sure one_pixel is large enough.
+ uint32_t one_pixel[PATTERN_SIZE(3)/sizeof(uint32_t)];
NRF_PWM_Type* pwm = find_free_pwm();
// only malloc if there is PWM device available
if ( pwm != NULL ) {
- if (pattern_size <= sizeof(one_pixel) * sizeof(uint32_t)) {
+ if (pattern_size <= sizeof(one_pixel)) {
pixels_pattern = (uint16_t *) one_pixel;
} else {
pixels_pattern = (uint16_t *) m_malloc_maybe(pattern_size, false);