Skip to content

Commit 5cda32b

Browse files
committed
raspberrypi: PDMIn: Free resources when failing to construct.
This ensures that after using an invalid sample rate, the pin objects and pio object are deinitialized.
1 parent c95cbea commit 5cda32b

File tree

1 file changed

+1
-0
lines changed
  • ports/raspberrypi/common-hal/audiobusio

1 file changed

+1
-0
lines changed

ports/raspberrypi/common-hal/audiobusio/PDMIn.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t *self,
6565
PIO_MOV_STATUS_DEFAULT, PIO_MOV_N_DEFAULT);
6666
uint32_t actual_frequency = common_hal_rp2pio_statemachine_get_frequency(&self->state_machine);
6767
if (actual_frequency < 2 * MIN_MIC_CLOCK) { // 2 PIO samples per audio clock
68+
common_hal_audiobusio_pdmin_deinit(self);
6869
mp_raise_ValueError(MP_ERROR_TEXT("sampling rate out of range"));
6970
}
7071

0 commit comments

Comments
 (0)