Skip to content

Adds I2S mclk support to audiobusio.I2SOut for the Espressif port #8570 #8571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions ports/espressif/common-hal/audiobusio/I2SOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,13 @@
void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self,
const mcu_pin_obj_t *bit_clock, const mcu_pin_obj_t *word_select,
const mcu_pin_obj_t *data, const mcu_pin_obj_t *main_clock, bool left_justified) {
if (main_clock != NULL) {
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_main_clock);
}
port_i2s_allocate_init(&self->i2s, left_justified);

i2s_std_config_t i2s_config = {
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(48000),
.slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO),
.gpio_cfg = {
.mclk = I2S_GPIO_UNUSED,
.mclk = main_clock != NULL ? main_clock->number : I2S_GPIO_UNUSED,
.bclk = bit_clock->number,
.ws = word_select->number,
.dout = data->number,
Expand All @@ -68,6 +65,7 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self,
CHECK_ESP_RESULT(i2s_channel_init_std_mode(self->i2s.handle, &i2s_config));
self->bit_clock = bit_clock;
self->word_select = word_select;
self->mclk = main_clock;
self->data = data;
claim_pin(bit_clock);
claim_pin(word_select);
Expand Down Expand Up @@ -97,6 +95,11 @@ void common_hal_audiobusio_i2sout_deinit(audiobusio_i2sout_obj_t *self) {
}
self->word_select = NULL;

if (self->mclk) {
reset_pin_number(self->mclk->number);
}
self->mclk = NULL;

if (self->data) {
reset_pin_number(self->data->number);
}
Expand Down
1 change: 1 addition & 0 deletions ports/espressif/common-hal/audiobusio/I2SOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef struct {
const mcu_pin_obj_t *bit_clock;
const mcu_pin_obj_t *word_select;
const mcu_pin_obj_t *data;
const mcu_pin_obj_t *mclk;
} audiobusio_i2sout_obj_t;

#endif