diff --git a/ports/atmel-samd/common-hal/audiobusio/I2SOut.c b/ports/atmel-samd/common-hal/audiobusio/I2SOut.c index 447252aace..9c1a00c052 100644 --- a/ports/atmel-samd/common-hal/audiobusio/I2SOut.c +++ b/ports/atmel-samd/common-hal/audiobusio/I2SOut.c @@ -98,7 +98,10 @@ void i2sout_reset(void) { // Caller validates that pins are free. 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, bool left_justified) { + const mcu_pin_obj_t *data, const mcu_pin_obj_t *main_clock, bool left_justified) { + if (main_clock != NULL) { + mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_main_clock); + } uint8_t serializer = 0xff; uint8_t bc_clock_unit = 0xff; uint8_t ws_clock_unit = 0xff; diff --git a/ports/espressif/common-hal/audiobusio/I2SOut.c b/ports/espressif/common-hal/audiobusio/I2SOut.c index 440151e881..8b03a534a4 100644 --- a/ports/espressif/common-hal/audiobusio/I2SOut.c +++ b/ports/espressif/common-hal/audiobusio/I2SOut.c @@ -49,8 +49,10 @@ // Caller validates that pins are free. 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, bool left_justified) { - + const mcu_pin_obj_t *data, const mcu_pin_obj_t *main_clock, bool left_justified) { + if (main_clock != NULL) { + mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_main_clock); + } port_i2s_allocate_init(&self->peripheral, left_justified); i2s_pin_config_t i2s_pin_config = { diff --git a/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.c b/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.c index 9ba2762f1c..cba857a495 100644 --- a/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.c +++ b/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.c @@ -74,13 +74,22 @@ STATIC void config_periph_pin(const mcu_periph_obj_t *periph) { // Caller validates that pins are free. 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, bool left_justified) { + const mcu_pin_obj_t *data, const mcu_pin_obj_t *main_clock, bool left_justified) { int instance = -1; const mcu_periph_obj_t *bclk_periph = find_pin_function(mcu_i2s_tx_bclk_list, bit_clock, &instance, MP_QSTR_bit_clock); const mcu_periph_obj_t *sync_periph = find_pin_function(mcu_i2s_tx_sync_list, word_select, &instance, MP_QSTR_word_select); const mcu_periph_obj_t *data_periph = find_pin_function(mcu_i2s_tx_data0_list, data, &instance, MP_QSTR_data); + if (main_clock != NULL) { + const mcu_periph_obj_t *mclk_periph = find_pin_function(mcu_i2s_mclk_list, main_clock, &instance, MP_QSTR_main_clock); + self->mclk = main_clock; + claim_pin(main_clock); + config_periph_pin(mclk_periph); + IOMUXC_GPR->GPR1 |= IOMUXC_GPR_GPR1_SAI1_MCLK_DIR_MASK << (instance - 1); + } + self->instance = instance; + sai_transceiver_t config; SAI_GetClassicI2SConfig(&config, 16, kSAI_Stereo, 1); config.syncMode = kSAI_ModeAsync; @@ -121,6 +130,11 @@ void common_hal_audiobusio_i2sout_deinit(audiobusio_i2sout_obj_t *self) { common_hal_reset_pin(self->data); self->data = NULL; + + IOMUXC_GPR->GPR1 &= ~(IOMUXC_GPR_GPR1_SAI1_MCLK_DIR_MASK << (self->instance - 1)); + + common_hal_reset_pin(self->mclk); + self->mclk = NULL; } void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t *self, diff --git a/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.h b/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.h index 319e52c159..3a2ed49b9a 100644 --- a/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.h +++ b/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.h @@ -39,6 +39,8 @@ 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; + uint8_t instance; } audiobusio_i2sout_obj_t; #endif diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.c index a1468971dc..8a2e95b194 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.c @@ -174,6 +174,12 @@ const mcu_periph_obj_t mcu_i2s_tx_sync_list[2] = { PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_SD_00), }; +const mcu_periph_obj_t mcu_i2s_mclk_list[2] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_08), + + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_00), +}; + const mcu_periph_obj_t mcu_mqs_left_list[1] = { PERIPH_PIN(3, 4, 0, 0, &pin_GPIO_AD_01), }; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h index f3bee9e464..b854ebe585 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h @@ -56,6 +56,7 @@ extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[2]; extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[2]; extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[2]; extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[2]; +extern const mcu_periph_obj_t mcu_i2s_mclk_list[2]; extern const mcu_periph_obj_t mcu_mqs_left_list[1]; extern const mcu_periph_obj_t mcu_mqs_right_list[1]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.c index c6b2c6b872..669109a858 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.c @@ -159,6 +159,16 @@ const mcu_periph_obj_t mcu_i2s_tx_sync_list[4] = { PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B1_07), }; +const mcu_periph_obj_t mcu_i2s_mclk_list[5] = { + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_20), + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B0_03), + + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_16), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_17), + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B1_05), +}; + const mcu_periph_obj_t mcu_mqs_left_list[2] = { PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_17), PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_07), diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.h index cef33f1ffa..51295b8965 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.h @@ -56,6 +56,7 @@ extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[3]; extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[4]; extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[4]; extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[4]; +extern const mcu_periph_obj_t mcu_i2s_mclk_list[5]; extern const mcu_periph_obj_t mcu_mqs_left_list[2]; extern const mcu_periph_obj_t mcu_mqs_right_list[2]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.c index 9129c64272..13a1ab41b2 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.c @@ -268,6 +268,20 @@ const mcu_periph_obj_t mcu_i2s_tx_sync_list[7] = { PERIPH_PIN(3, 3, kIOMUXC_SAI3_TX_SYNC_SELECT_INPUT, 1, &pin_GPIO_EMC_34), }; +const mcu_periph_obj_t mcu_i2s_mclk_list[9] = { + PERIPH_PIN(1, 2, kIOMUXC_SAI1_MCLK_SELECT_INPUT, 0, &pin_GPIO_SD_B0_00), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_MCLK_SELECT_INPUT, 1, &pin_GPIO_AD_B0_03), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_MCLK_SELECT_INPUT, 2, &pin_GPIO_AD_B1_00), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_MCLK_SELECT_INPUT, 3, &pin_GPIO_EMC_20), + + PERIPH_PIN(2, 3, kIOMUXC_SAI2_MCLK_SELECT_INPUT, 0, &pin_GPIO_SD_B0_00), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_MCLK_SELECT_INPUT, 1, &pin_GPIO_EMC_16), + + PERIPH_PIN(3, 3, kIOMUXC_SAI3_MCLK_SELECT_INPUT, 0, &pin_GPIO_SD_B1_05), + PERIPH_PIN(3, 3, kIOMUXC_SAI3_MCLK_SELECT_INPUT, 1, &pin_GPIO_EMC_17), + PERIPH_PIN(3, 3, kIOMUXC_SAI3_MCLK_SELECT_INPUT, 2, &pin_GPIO_EMC_28), +}; + const mcu_periph_obj_t mcu_mqs_left_list[3] = { PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_17), PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_38), diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h index 3dea33fa00..bb90c24250 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h @@ -56,6 +56,7 @@ extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[7]; extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[7]; extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[7]; extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[7]; +extern const mcu_periph_obj_t mcu_i2s_mclk_list[9]; extern const mcu_periph_obj_t mcu_mqs_left_list[3]; extern const mcu_periph_obj_t mcu_mqs_right_list[3]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.c index 104960b417..506e9b6fe6 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.c @@ -254,6 +254,17 @@ const mcu_periph_obj_t mcu_i2s_tx_sync_list[6] = { PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_02), }; +const mcu_periph_obj_t mcu_i2s_mclk_list[6] = { + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_B0_13), + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_SD_B1_03), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_07), + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_AD_B0_10), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_37), + PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_04), +}; + const mcu_periph_obj_t mcu_mqs_left_list[3] = { PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_14), PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_05), diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.h index 3df1a06d98..ef65ad582a 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.h @@ -56,6 +56,7 @@ extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[6]; extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[6]; extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[6]; extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[6]; +extern const mcu_periph_obj_t mcu_i2s_mclk_list[6]; extern const mcu_periph_obj_t mcu_mqs_left_list[3]; extern const mcu_periph_obj_t mcu_mqs_right_list[3]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.c index 3ff474d7f4..de0bf66129 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.c @@ -267,6 +267,17 @@ const mcu_periph_obj_t mcu_i2s_tx_sync_list[6] = { PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_39), }; +const mcu_periph_obj_t mcu_i2s_mclk_list[6] = { + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_09), + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_B0_13), + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_SD_B1_03), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_07), + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_AD_B0_10), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_37), +}; + const mcu_periph_obj_t mcu_mqs_left_list[3] = { PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_14), PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_05), diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.h index 7d428eae1c..31c8c7b7f7 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.h @@ -56,6 +56,7 @@ extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[6]; extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[6]; extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[6]; extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[6]; +extern const mcu_periph_obj_t mcu_i2s_mclk_list[6]; extern const mcu_periph_obj_t mcu_mqs_left_list[3]; extern const mcu_periph_obj_t mcu_mqs_right_list[3]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.c index ab8fb2b4d8..b995910dc1 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.c @@ -272,6 +272,18 @@ const mcu_periph_obj_t mcu_i2s_tx_sync_list[7] = { PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_02), }; +const mcu_periph_obj_t mcu_i2s_mclk_list[7] = { + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_09), + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_B0_13), + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_SD_B1_03), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_07), + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_AD_B0_10), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_37), + PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_04), +}; + const mcu_periph_obj_t mcu_mqs_left_list[3] = { PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_14), PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_05), diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h index 36a42eba64..b6372646f6 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h @@ -56,6 +56,7 @@ extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[7]; extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[7]; extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[7]; extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[7]; +extern const mcu_periph_obj_t mcu_i2s_mclk_list[7]; extern const mcu_periph_obj_t mcu_mqs_left_list[3]; extern const mcu_periph_obj_t mcu_mqs_right_list[3]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.c index f53136c94f..f5172a252a 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.c @@ -237,6 +237,15 @@ const mcu_periph_obj_t mcu_i2s_tx_sync_list[4] = { PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_B2_16), }; +const mcu_periph_obj_t mcu_i2s_mclk_list[4] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_AD_17), + PERIPH_PIN(1, 4, 0, 0, &pin_GPIO_DISP_B2_03), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_B2_04), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_B2_17), +}; + const mcu_periph_obj_t mcu_mqs_left_list[2] = { PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_B1_41), PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_DISP_B2_01), diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.h index 266300df18..63e6da95f6 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.h @@ -56,6 +56,7 @@ extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[4]; extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[4]; extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[4]; extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[4]; +extern const mcu_periph_obj_t mcu_i2s_mclk_list[4]; extern const mcu_periph_obj_t mcu_mqs_left_list[2]; extern const mcu_periph_obj_t mcu_mqs_right_list[2]; diff --git a/ports/mimxrt10xx/tools/gen_peripherals_data.py b/ports/mimxrt10xx/tools/gen_peripherals_data.py index d87e9022b2..1062bfe91c 100644 --- a/ports/mimxrt10xx/tools/gen_peripherals_data.py +++ b/ports/mimxrt10xx/tools/gen_peripherals_data.py @@ -6,7 +6,7 @@ SIGNALS = { "LPI2C": ["SDA", "SCL"], "LPSPI": ["SCK", "SDO", "SDI"], "LPUART": ["RX", "TX", "RTS", "CTS"], - "I2S": ["RX_DATA0", "RX_SYNC", "TX_BCLK", "TX_DATA0", "TX_SYNC"], + "I2S": ["RX_DATA0", "RX_SYNC", "TX_BCLK", "TX_DATA0", "TX_SYNC", "MCLK"], "MQS": ["LEFT", "RIGHT"], } diff --git a/ports/nrf/common-hal/audiobusio/I2SOut.c b/ports/nrf/common-hal/audiobusio/I2SOut.c index 6e68583a03..b03b8fb11e 100644 --- a/ports/nrf/common-hal/audiobusio/I2SOut.c +++ b/ports/nrf/common-hal/audiobusio/I2SOut.c @@ -202,7 +202,10 @@ static void i2s_buffer_fill(audiobusio_i2sout_obj_t *self) { 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, bool left_justified) { + const mcu_pin_obj_t *data, const mcu_pin_obj_t *main_clock, bool left_justified) { + if (main_clock != NULL) { + mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_main_clock); + } if (instance) { mp_raise_RuntimeError(translate("Device in use")); } diff --git a/ports/raspberrypi/common-hal/audiobusio/I2SOut.c b/ports/raspberrypi/common-hal/audiobusio/I2SOut.c index 62d4058d1d..d9c5027cbd 100644 --- a/ports/raspberrypi/common-hal/audiobusio/I2SOut.c +++ b/ports/raspberrypi/common-hal/audiobusio/I2SOut.c @@ -103,7 +103,10 @@ void i2sout_reset(void) { // Caller validates that pins are free. 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, bool left_justified) { + const mcu_pin_obj_t *data, const mcu_pin_obj_t *main_clock, bool left_justified) { + if (main_clock != NULL) { + mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_main_clock); + } if (bit_clock->number != word_select->number - 1) { mp_raise_ValueError(translate("Bit clock and word select must be sequential pins")); } diff --git a/shared-bindings/audiobusio/I2SOut.c b/shared-bindings/audiobusio/I2SOut.c index 8c6f1a3a7a..3f697c35eb 100644 --- a/shared-bindings/audiobusio/I2SOut.c +++ b/shared-bindings/audiobusio/I2SOut.c @@ -44,13 +44,15 @@ //| word_select: microcontroller.Pin, //| data: microcontroller.Pin, //| *, -//| left_justified: bool +//| main_clock: microcontroller.Pin = None, +//| left_justified: bool = False //| ) -> None: //| """Create a I2SOut object associated with the given pins. //| //| :param ~microcontroller.Pin bit_clock: The bit clock (or serial clock) pin //| :param ~microcontroller.Pin word_select: The word select (or left/right clock) pin //| :param ~microcontroller.Pin data: The data pin +//| :param ~microcontroller.Pin main_clock: The main clock pin //| :param bool left_justified: True when data bits are aligned with the word select clock. False //| when they are shifted by one to match classic I2S protocol. //| @@ -100,11 +102,12 @@ STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_a mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_I2SOut); return NULL; // Not reachable. #else - enum { ARG_bit_clock, ARG_word_select, ARG_data, ARG_left_justified }; + enum { ARG_bit_clock, ARG_word_select, ARG_data, ARG_main_clock, ARG_left_justified }; static const mp_arg_t allowed_args[] = { { MP_QSTR_bit_clock, MP_ARG_OBJ | MP_ARG_REQUIRED }, { MP_QSTR_word_select, MP_ARG_OBJ | MP_ARG_REQUIRED }, { MP_QSTR_data, MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_main_clock, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, { MP_QSTR_left_justified, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -113,10 +116,11 @@ STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_a const mcu_pin_obj_t *bit_clock = validate_obj_is_free_pin(args[ARG_bit_clock].u_obj, MP_QSTR_bit_clock); const mcu_pin_obj_t *word_select = validate_obj_is_free_pin(args[ARG_word_select].u_obj, MP_QSTR_word_select); const mcu_pin_obj_t *data = validate_obj_is_free_pin(args[ARG_data].u_obj, MP_QSTR_data); + const mcu_pin_obj_t *main_clock = validate_obj_is_free_pin_or_none(args[ARG_main_clock].u_obj, MP_QSTR_main_clock); audiobusio_i2sout_obj_t *self = m_new_obj_with_finaliser(audiobusio_i2sout_obj_t); self->base.type = &audiobusio_i2sout_type; - common_hal_audiobusio_i2sout_construct(self, bit_clock, word_select, data, args[ARG_left_justified].u_bool); + common_hal_audiobusio_i2sout_construct(self, bit_clock, word_select, data, main_clock, args[ARG_left_justified].u_bool); return MP_OBJ_FROM_PTR(self); #endif diff --git a/shared-bindings/audiobusio/I2SOut.h b/shared-bindings/audiobusio/I2SOut.h index 64dcc3bf68..4fa56b5472 100644 --- a/shared-bindings/audiobusio/I2SOut.h +++ b/shared-bindings/audiobusio/I2SOut.h @@ -37,7 +37,7 @@ extern const mp_obj_type_t audiobusio_i2sout_type; 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, - bool left_justified); + const mcu_pin_obj_t *main_clock, bool left_justified); void common_hal_audiobusio_i2sout_deinit(audiobusio_i2sout_obj_t *self); bool common_hal_audiobusio_i2sout_deinited(audiobusio_i2sout_obj_t *self);