Regarding i2s_frame_map #12510
-
Hi, Regards, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The Here is the mapping table for the STM32 port: STATIC const int8_t i2s_frame_map[NUM_I2S_USER_FORMATS][I2S_RX_FRAME_SIZE_IN_BYTES] = {
{ 0, 1, -1, -1, -1, -1, -1, -1 }, // Mono, 16-bits
{ 2, 3, 0, 1, -1, -1, -1, -1 }, // Mono, 32-bits
{ 0, 1, -1, -1, 2, 3, -1, -1 }, // Stereo, 16-bits
{ 2, 3, 0, 1, 6, 7, 4, 5 }, // Stereo, 32-bits Suppose that the I2S instance is configured for 32 bit mono. The 2nd line in the array contains the recipe for mapping the 8 bytes of stereo audio samples that come from the STM32 I2S peripheral to the desired format, 32 bit mono. Note that mono format uses only the left channel coming from the peripheral. { 2, 3, 0, 1, -1, -1, -1, -1 }, // Mono, 32-bits Each of the 8 elements correspond to one of the 8 bytes in the audio sample received from the I2S peripheral. Consider the first element. The first element maps the first byte in the 8 byte stereo audio sample to the byte location in the resulting 32 bit mono sample (which is in little endian ordering). In this case, the number '2' indicates that the first byte coming from the I2S peripheral is mapped to the 3rd byte (indicated by the '2') in the 32 bit mono sample. '3' indicates that the 2nd byte from the I2S peripheral is mapped to the 4th byte in the 32 bit mono sample. The '-1's mark the bytes that are not used. In this case, the '-1's mark the right channel bytes which are not used for the specified mono format, which uses only the left channel audio sample. The I2S peripherals in the various ports are not consistent in the sample byte ordering. The mapping tables are different for each port. For the PSoC6 port you will need to build this map by understanding the byte order that is delivered from the PSoC6 I2S peripheral. The reference manual might provide some insight. If not, you might need to use an oscilloscope to monitor the serial I2S data flowing between the microcontroller and I2S hardware device, then compare that to the data that is delivered by the I2S peripheral. Hope this helps to understand the mapping table. |
Beta Was this translation helpful? Give feedback.
-
Thanks ! This is clear now. I have other confusion regarding the different modes in I2S. According to the documentation all modes uses DMA for transfer right. Then how it exactly makes the difference between blocking & Non blocking since it's the DMA is doing the transfer & CPU is free from it. |
Beta Was this translation helpful? Give feedback.
The
i2s_frame_map[]
table is used when reading samples from an ADC, such as a MEMS microphone. Every audio sample received from an ADC is 4 bytes. There is a left and right channel sample, so 8 bytes, which is called a frame. I2S hardware devices follow the I2S protocol. Left channel is sent first, most significant bit first, followed by the Right channel. But, the I2S peripherals internal to a microcontroller do not deliver data in the same byte order that is observed in the I2S protocol. The mapping table takes the bytes received from the I2S peripheral and reorders them to make the resulting byte order consistent for all ports in MicroPython. The consistent format in MicroPython is lit…