From 5986831bd66950eed2c74461e88f847aa27269cc Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Fri, 19 Jan 2018 09:46:20 -0800 Subject: [PATCH] Fix I2S helpers to send/nonblock properly The original I2S setup had the wrong # of bits being sent to the DAC as well as wrong timeouts specified on the write_sample wrappers. Fix those, allowing things like WebRadio.ino to work. --- src/AudioOutputI2SDAC.cpp | 4 ++-- src/AudioOutputI2SNoDAC.cpp | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/AudioOutputI2SDAC.cpp b/src/AudioOutputI2SDAC.cpp index c25c67b..9a6c47c 100644 --- a/src/AudioOutputI2SDAC.cpp +++ b/src/AudioOutputI2SDAC.cpp @@ -40,7 +40,7 @@ i2s_config_t i2s_config_dac = { .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // high interrupt priority .dma_buf_count = 8, .dma_buf_len = 64, //Interrupt level 1 - .use_apll = true // Use audio PLL + .use_apll = 1 // Use audio PLL }; i2s_pin_config_t pin_config_dac = { @@ -128,7 +128,7 @@ bool AudioOutputI2SDAC::ConsumeSample(int16_t sample[2]) } uint32_t s32 = ((Amplify(sample[RIGHTCHANNEL]))<<16) | (Amplify(sample[LEFTCHANNEL]) & 0xffff); #ifdef ESP32 - return i2s_write_bytes((i2s_port_t)i2s_num, (const char *)&s32, sizeof(uint32_t), 100); + return i2s_write_bytes((i2s_port_t)i2s_num, (const char *)&s32, sizeof(uint32_t), 0); #else return i2s_write_sample_nb(s32); // If we can't store it, return false. OTW true #endif diff --git a/src/AudioOutputI2SNoDAC.cpp b/src/AudioOutputI2SNoDAC.cpp index 4d0bf6c..20d00f0 100644 --- a/src/AudioOutputI2SNoDAC.cpp +++ b/src/AudioOutputI2SNoDAC.cpp @@ -29,15 +29,15 @@ #ifdef ESP32 i2s_config_t i2s_config = { - .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN), + .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX), .sample_rate = 44100, - .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, /* the DAC module will only take the 8bits from MSB */ + .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, .communication_format = (i2s_comm_format_t)I2S_COMM_FORMAT_I2S_MSB, .intr_alloc_flags = 0, // default interrupt priority .dma_buf_count = 8, .dma_buf_len = 64, - .use_apll = 0 + .use_apll = 1 }; i2s_pin_config_t pin_config = { @@ -157,13 +157,13 @@ void AudioOutputI2SNoDAC::DeltaSigma(int16_t sample[2], uint32_t dsBuff[4]) #ifdef ESP32 /* write sample data to I2S */ -int i2s_write_sample_nb(uint8_t sample){ - return i2s_write_bytes((i2s_port_t)0, (const char *)&sample, sizeof(uint8_t), 100); +int i2s_write_sample_nb(uint32_t sample){ + return i2s_write_bytes((i2s_port_t)0, (const char *)&sample, sizeof(sample), 0); } // how to do this blocking?? -int i2s_write_sample(uint8_t sample){ - return i2s_write_bytes((i2s_port_t)0, (const char *)&sample, sizeof(uint8_t), 100); +int i2s_write_sample(uint32_t sample){ + return i2s_write_bytes((i2s_port_t)0, (const char *)&sample, sizeof(sample), portMAX_DELAY); } #endif