@@ -108,6 +108,7 @@ void choose_i2s_clocking(audiobusio_i2sout_obj_t *self, uint32_t sample_rate) {
108
108
109
109
static void i2s_buffer_fill (audiobusio_i2sout_obj_t * self ) {
110
110
void * buffer = self -> buffers [self -> next_buffer ];
111
+ void * buffer_start = buffer ;
111
112
NRF_I2S -> TXD .PTR = (uintptr_t )buffer ;
112
113
self -> next_buffer = !self -> next_buffer ;
113
114
size_t bytesleft = self -> buffer_length ;
@@ -157,15 +158,17 @@ static void i2s_buffer_fill(audiobusio_i2sout_obj_t* self) {
157
158
158
159
// Find the last frame of real audio data and replicate its samples until
159
160
// you have 32 bits worth, which is the fundamental unit of nRF I2S DMA
160
- if (self -> bytes_per_sample == 1 && self -> channel_count == 1 ) {
161
- // For 8-bit mono, 4 copies of the final sample are required
162
- self -> hold_value = 0x01010101 * * (uint8_t * )(buffer - 1 );
163
- } else if (self -> bytes_per_sample == 2 && self -> channel_count == 2 ) {
164
- // For 16-bit stereo, 1 copy of the final sample is required
165
- self -> hold_value = * (uint32_t * )(buffer - 4 );
166
- } else {
167
- // For 8-bit stereo and 16-bit mono, 2 copies of the final sample are required
168
- self -> hold_value = 0x00010001 * * (uint16_t * )(buffer - 2 );
161
+ if (buffer != buffer_start ) {
162
+ if (self -> bytes_per_sample == 1 && self -> channel_count == 1 ) {
163
+ // For 8-bit mono, 4 copies of the final sample are required
164
+ self -> hold_value = 0x01010101 * * (uint8_t * )(buffer - 1 );
165
+ } else if (self -> bytes_per_sample == 2 && self -> channel_count == 2 ) {
166
+ // For 16-bit stereo, 1 copy of the final sample is required
167
+ self -> hold_value = * (uint32_t * )(buffer - 4 );
168
+ } else {
169
+ // For 8-bit stereo and 16-bit mono, 2 copies of the final sample are required
170
+ self -> hold_value = 0x00010001 * * (uint16_t * )(buffer - 2 );
171
+ }
169
172
}
170
173
171
174
// Emulate pausing and stopping by filling the DMA buffer with copies of
@@ -218,6 +221,8 @@ void common_hal_audiobusio_i2sout_deinit(audiobusio_i2sout_obj_t* self) {
218
221
if (common_hal_audiobusio_i2sout_deinited (self )) {
219
222
return ;
220
223
}
224
+ NRF_I2S -> TASKS_STOP = 1 ;
225
+ NRF_I2S -> ENABLE = I2S_ENABLE_ENABLE_Disabled ;
221
226
reset_pin_number (self -> bit_clock_pin_number );
222
227
self -> bit_clock_pin_number = 0xff ;
223
228
reset_pin_number (self -> word_select_pin_number );
0 commit comments