Skip to content

Commit 4146d6f

Browse files
authored
Merge pull request #2890 from jepler/nrf-audio-tick
nrf: put supervisor enable/disable tick in place
2 parents dd2cd6f + eb876e2 commit 4146d6f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

ports/nrf/common-hal/audiobusio/I2SOut.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "common-hal/audiobusio/I2SOut.h"
3232
#include "shared-bindings/audiobusio/I2SOut.h"
3333
#include "shared-module/audiocore/__init__.h"
34+
#include "supervisor/shared/tick.h"
3435

3536
#include "py/obj.h"
3637
#include "py/runtime.h"
@@ -158,7 +159,7 @@ static void i2s_buffer_fill(audiobusio_i2sout_obj_t* self) {
158159

159160
// Find the last frame of real audio data and replicate its samples until
160161
// you have 32 bits worth, which is the fundamental unit of nRF I2S DMA
161-
if(buffer != buffer_start) {
162+
if (buffer != buffer_start) {
162163
if (self->bytes_per_sample == 1 && self->channel_count == 1) {
163164
// For 8-bit mono, 4 copies of the final sample are required
164165
self->hold_value = 0x01010101 * *(uint8_t*)(buffer-1);
@@ -211,6 +212,8 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t* self,
211212
NRF_I2S->CONFIG.ALIGN = I2S_CONFIG_ALIGN_ALIGN_Left;
212213
NRF_I2S->CONFIG.FORMAT = left_justified ? I2S_CONFIG_FORMAT_FORMAT_Aligned
213214
: I2S_CONFIG_FORMAT_FORMAT_I2S;
215+
216+
supervisor_enable_tick();
214217
}
215218

216219
bool common_hal_audiobusio_i2sout_deinited(audiobusio_i2sout_obj_t* self) {
@@ -230,6 +233,7 @@ void common_hal_audiobusio_i2sout_deinit(audiobusio_i2sout_obj_t* self) {
230233
reset_pin_number(self->data_pin_number);
231234
self->data_pin_number = 0xff;
232235
instance = NULL;
236+
supervisor_disable_tick();
233237
}
234238

235239
void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t* self,
@@ -340,5 +344,8 @@ void i2s_reset(void) {
340344
NRF_I2S->PSEL.LRCK = 0xFFFFFFFF;
341345
NRF_I2S->PSEL.SDOUT = 0xFFFFFFFF;
342346
NRF_I2S->PSEL.SDIN = 0xFFFFFFFF;
347+
if (instance) {
348+
supervisor_disable_tick();
349+
}
343350
instance = NULL;
344351
}

ports/nrf/common-hal/audiopwmio/PWMAudioOut.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "shared-bindings/audiopwmio/PWMAudioOut.h"
3737
#include "shared-bindings/microcontroller/__init__.h"
3838
#include "shared-bindings/microcontroller/Pin.h"
39+
#include "supervisor/shared/tick.h"
3940
#include "supervisor/shared/translate.h"
4041

4142
// TODO: This should be the same size as PWMOut.c:pwms[], but there's no trivial way to accomplish that
@@ -67,6 +68,7 @@ STATIC void activate_audiopwmout_obj(audiopwmio_pwmaudioout_obj_t *self) {
6768
for (size_t i=0; i < MP_ARRAY_SIZE(active_audio); i++) {
6869
if (!active_audio[i]) {
6970
active_audio[i] = self;
71+
supervisor_enable_tick();
7072
break;
7173
}
7274
}
@@ -77,12 +79,16 @@ STATIC void deactivate_audiopwmout_obj(audiopwmio_pwmaudioout_obj_t *self) {
7779
for (size_t i=0; i < MP_ARRAY_SIZE(active_audio); i++) {
7880
if (active_audio[i] == self) {
7981
active_audio[i] = NULL;
82+
supervisor_disable_tick();
8083
}
8184
}
8285
}
8386

8487
void audiopwmout_reset() {
8588
for (size_t i=0; i < MP_ARRAY_SIZE(active_audio); i++) {
89+
if (active_audio[i]) {
90+
supervisor_disable_tick();
91+
}
8692
active_audio[i] = NULL;
8793
}
8894
}

0 commit comments

Comments
 (0)