Skip to content

Commit ee2207d

Browse files
authored
Merge pull request #8291 from tannewt/i2s_mclk
Add I2S MCLK support to iMX RT
2 parents af91625 + ab70f8e commit ee2207d

File tree

23 files changed

+124
-11
lines changed

23 files changed

+124
-11
lines changed

ports/atmel-samd/common-hal/audiobusio/I2SOut.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ void i2sout_reset(void) {
9898
// Caller validates that pins are free.
9999
void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self,
100100
const mcu_pin_obj_t *bit_clock, const mcu_pin_obj_t *word_select,
101-
const mcu_pin_obj_t *data, bool left_justified) {
101+
const mcu_pin_obj_t *data, const mcu_pin_obj_t *main_clock, bool left_justified) {
102+
if (main_clock != NULL) {
103+
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_main_clock);
104+
}
102105
uint8_t serializer = 0xff;
103106
uint8_t bc_clock_unit = 0xff;
104107
uint8_t ws_clock_unit = 0xff;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@
4949
// Caller validates that pins are free.
5050
void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self,
5151
const mcu_pin_obj_t *bit_clock, const mcu_pin_obj_t *word_select,
52-
const mcu_pin_obj_t *data, bool left_justified) {
53-
52+
const mcu_pin_obj_t *data, const mcu_pin_obj_t *main_clock, bool left_justified) {
53+
if (main_clock != NULL) {
54+
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_main_clock);
55+
}
5456
port_i2s_allocate_init(&self->peripheral, left_justified);
5557

5658
i2s_pin_config_t i2s_pin_config = {

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,22 @@ STATIC void config_periph_pin(const mcu_periph_obj_t *periph) {
7474
// Caller validates that pins are free.
7575
void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self,
7676
const mcu_pin_obj_t *bit_clock, const mcu_pin_obj_t *word_select,
77-
const mcu_pin_obj_t *data, bool left_justified) {
77+
const mcu_pin_obj_t *data, const mcu_pin_obj_t *main_clock, bool left_justified) {
7878

7979
int instance = -1;
8080
const mcu_periph_obj_t *bclk_periph = find_pin_function(mcu_i2s_tx_bclk_list, bit_clock, &instance, MP_QSTR_bit_clock);
8181
const mcu_periph_obj_t *sync_periph = find_pin_function(mcu_i2s_tx_sync_list, word_select, &instance, MP_QSTR_word_select);
8282
const mcu_periph_obj_t *data_periph = find_pin_function(mcu_i2s_tx_data0_list, data, &instance, MP_QSTR_data);
8383

84+
if (main_clock != NULL) {
85+
const mcu_periph_obj_t *mclk_periph = find_pin_function(mcu_i2s_mclk_list, main_clock, &instance, MP_QSTR_main_clock);
86+
self->mclk = main_clock;
87+
claim_pin(main_clock);
88+
config_periph_pin(mclk_periph);
89+
IOMUXC_GPR->GPR1 |= IOMUXC_GPR_GPR1_SAI1_MCLK_DIR_MASK << (instance - 1);
90+
}
91+
self->instance = instance;
92+
8493
sai_transceiver_t config;
8594
SAI_GetClassicI2SConfig(&config, 16, kSAI_Stereo, 1);
8695
config.syncMode = kSAI_ModeAsync;
@@ -121,6 +130,13 @@ void common_hal_audiobusio_i2sout_deinit(audiobusio_i2sout_obj_t *self) {
121130

122131
common_hal_reset_pin(self->data);
123132
self->data = NULL;
133+
134+
if (self->mclk != NULL) {
135+
IOMUXC_GPR->GPR1 &= ~(IOMUXC_GPR_GPR1_SAI1_MCLK_DIR_MASK << (self->instance - 1));
136+
137+
common_hal_reset_pin(self->mclk);
138+
self->mclk = NULL;
139+
}
124140
}
125141

126142
void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t *self,

ports/mimxrt10xx/common-hal/audiobusio/I2SOut.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ typedef struct {
3939
const mcu_pin_obj_t *bit_clock;
4040
const mcu_pin_obj_t *word_select;
4141
const mcu_pin_obj_t *data;
42+
const mcu_pin_obj_t *mclk;
43+
uint8_t instance;
4244
} audiobusio_i2sout_obj_t;
4345

4446
#endif

ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ const mcu_periph_obj_t mcu_i2s_tx_sync_list[2] = {
174174
PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_SD_00),
175175
};
176176

177+
const mcu_periph_obj_t mcu_i2s_mclk_list[2] = {
178+
PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_08),
179+
180+
PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_00),
181+
};
182+
177183
const mcu_periph_obj_t mcu_mqs_left_list[1] = {
178184
PERIPH_PIN(3, 4, 0, 0, &pin_GPIO_AD_01),
179185
};

ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[2];
5656
extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[2];
5757
extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[2];
5858
extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[2];
59+
extern const mcu_periph_obj_t mcu_i2s_mclk_list[2];
5960

6061
extern const mcu_periph_obj_t mcu_mqs_left_list[1];
6162
extern const mcu_periph_obj_t mcu_mqs_right_list[1];

ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@ const mcu_periph_obj_t mcu_i2s_tx_sync_list[4] = {
159159
PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B1_07),
160160
};
161161

162+
const mcu_periph_obj_t mcu_i2s_mclk_list[5] = {
163+
PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_20),
164+
PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B0_03),
165+
166+
PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_16),
167+
168+
PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_17),
169+
PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B1_05),
170+
};
171+
162172
const mcu_periph_obj_t mcu_mqs_left_list[2] = {
163173
PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_17),
164174
PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_07),

ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[3];
5656
extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[4];
5757
extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[4];
5858
extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[4];
59+
extern const mcu_periph_obj_t mcu_i2s_mclk_list[5];
5960

6061
extern const mcu_periph_obj_t mcu_mqs_left_list[2];
6162
extern const mcu_periph_obj_t mcu_mqs_right_list[2];

ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,20 @@ const mcu_periph_obj_t mcu_i2s_tx_sync_list[7] = {
268268
PERIPH_PIN(3, 3, kIOMUXC_SAI3_TX_SYNC_SELECT_INPUT, 1, &pin_GPIO_EMC_34),
269269
};
270270

271+
const mcu_periph_obj_t mcu_i2s_mclk_list[9] = {
272+
PERIPH_PIN(1, 2, kIOMUXC_SAI1_MCLK_SELECT_INPUT, 0, &pin_GPIO_SD_B0_00),
273+
PERIPH_PIN(1, 3, kIOMUXC_SAI1_MCLK_SELECT_INPUT, 1, &pin_GPIO_AD_B0_03),
274+
PERIPH_PIN(1, 3, kIOMUXC_SAI1_MCLK_SELECT_INPUT, 2, &pin_GPIO_AD_B1_00),
275+
PERIPH_PIN(1, 3, kIOMUXC_SAI1_MCLK_SELECT_INPUT, 3, &pin_GPIO_EMC_20),
276+
277+
PERIPH_PIN(2, 3, kIOMUXC_SAI2_MCLK_SELECT_INPUT, 0, &pin_GPIO_SD_B0_00),
278+
PERIPH_PIN(2, 3, kIOMUXC_SAI2_MCLK_SELECT_INPUT, 1, &pin_GPIO_EMC_16),
279+
280+
PERIPH_PIN(3, 3, kIOMUXC_SAI3_MCLK_SELECT_INPUT, 0, &pin_GPIO_SD_B1_05),
281+
PERIPH_PIN(3, 3, kIOMUXC_SAI3_MCLK_SELECT_INPUT, 1, &pin_GPIO_EMC_17),
282+
PERIPH_PIN(3, 3, kIOMUXC_SAI3_MCLK_SELECT_INPUT, 2, &pin_GPIO_EMC_28),
283+
};
284+
271285
const mcu_periph_obj_t mcu_mqs_left_list[3] = {
272286
PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_17),
273287
PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_38),

ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[7];
5656
extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[7];
5757
extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[7];
5858
extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[7];
59+
extern const mcu_periph_obj_t mcu_i2s_mclk_list[9];
5960

6061
extern const mcu_periph_obj_t mcu_mqs_left_list[3];
6162
extern const mcu_periph_obj_t mcu_mqs_right_list[3];

0 commit comments

Comments
 (0)