Skip to content

Commit 4e040b0

Browse files
committed
add reset of heap to board reset for nrf port
1 parent 34c9e00 commit 4e040b0

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ static NRF_PWM_Type* find_free_pwm (void) {
9797
return NULL;
9898
}
9999

100+
static uint16_t* pixels_pattern_heap = NULL;
101+
static size_t pixels_pattern_heap_size = 0;
102+
static bool pattern_on_heap = false;
103+
// Called during reset_port() to free the pattern buffer
104+
void neopixel_write_reset(void) {
105+
pixels_pattern_heap = NULL;
106+
pixels_pattern_heap_size = 0;
107+
pattern_on_heap = false;
108+
}
109+
100110
uint64_t next_start_tick_ms = 0;
101111
uint32_t next_start_tick_us = 1000;
102112

@@ -113,12 +123,8 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
113123
// using DWT
114124

115125
#define PATTERN_SIZE(numBytes) (numBytes * 8 * sizeof(uint16_t) + 2 * sizeof(uint16_t))
116-
117126
uint32_t pattern_size = PATTERN_SIZE(numBytes);
118127
uint16_t* pixels_pattern = NULL;
119-
static uint16_t* pixels_pattern_heap = NULL;
120-
static size_t pixels_pattern_heap_size = 0;
121-
bool pattern_on_heap = false;
122128

123129
// Use the stack to store 1 pixels worth of PWM data for the status led. uint32_t to ensure alignment.
124130
// Make it at least as big as PATTERN_SIZE(3), for one pixel of RGB data.

ports/nrf/supervisor/port.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "common-hal/pulseio/PulseOut.h"
4848
#include "common-hal/pulseio/PulseIn.h"
4949
#include "common-hal/rtc/RTC.h"
50+
#include "common-hal/neopixel_write/__init__.h"
5051
#include "tick.h"
5152

5253
#include "shared-bindings/rtc/__init__.h"
@@ -106,6 +107,7 @@ void reset_port(void) {
106107
i2c_reset();
107108
spi_reset();
108109
uart_reset();
110+
neopixel_write_reset();
109111

110112
#if CIRCUITPY_AUDIOBUSIO
111113
i2s_reset();

0 commit comments

Comments
 (0)