I have 8 bit unsigned, 44100 Hz. 1 Channel (mono) WAV files that I want to play through the built in DAC using I2S.
Initialization is done as follows:
Code: Select all
i2s_port_t i2s_num = I2S_NUM_0;
i2s_config_t i2s_config =
{
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN),
.sample_rate = 44100,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, /* the DAC module will only take the 8bits from MSB */
.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT,
.communication_format = I2S_COMM_FORMAT_I2S_MSB,
.intr_alloc_flags = 0,
.dma_buf_count = 2,
.dma_buf_len = 512,
.use_apll = false,
};
i2s_driver_install(i2s_num, &i2s_config, 0, NULL);
i2s_set_dac_mode(I2S_DAC_CHANNEL_RIGHT_EN /** GPIO25 */);
However I am unsure of the value to use for channel_format and how it affects the way I should write samples using i2s_write.
What does I2S_CHANNEL_FMT_ONLY_RIGHT mean exactly? Does it mean the I2S driver will only use the Right sample and skips the Left sample? If so, Am I supposed to write an empty Left sample using i2s_write?
Should I be using I2S_CHANNEL_FMT_ALL_RIGHT instead or even I2S_CHANNEL_FMT_RIGHT_LEFT?