Add support for I2S MCLK. (#594)
This commit is contained in:
1 parent
0b5da0e9dd
commit
4ba7df1928
2 files changed
+39
-3
No files matched your search
+35
-3
@@ -49,6 +49,7 @@ AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int
|
||||
bclkPin = 26;
|
||||
wclkPin = 25;
|
||||
doutPin = 22;
|
||||
mclkPin = 0;
|
||||
SetGain(1.0);
|
||||
}
|
||||
|
||||
@@ -61,6 +62,8 @@ AudioOutputI2S::AudioOutputI2S(long sampleRate, pin_size_t sck, pin_size_t data)
|
||||
hertz = sampleRate;
|
||||
bclkPin = sck;
|
||||
doutPin = data;
|
||||
mclkPin = 0;
|
||||
use_mclk = false;
|
||||
SetGain(1.0);
|
||||
}
|
||||
#endif
|
||||
@@ -78,7 +81,7 @@ bool AudioOutputI2S::SetPinout()
|
||||
|
||||
i2s_pin_config_t pins = {
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
|
||||
.mck_io_num = 0, // Unused
|
||||
.mck_io_num = mclkPin,
|
||||
#endif
|
||||
.bck_io_num = bclkPin,
|
||||
.ws_io_num = wclkPin,
|
||||
@@ -90,6 +93,8 @@ bool AudioOutputI2S::SetPinout()
|
||||
(void)bclkPin;
|
||||
(void)wclkPin;
|
||||
(void)doutPin;
|
||||
(void)mclkPin;
|
||||
(void)use_mclk;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
@@ -104,6 +109,22 @@ bool AudioOutputI2S::SetPinout(int bclk, int wclk, int dout)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AudioOutputI2S::SetPinout(int bclk, int wclk, int dout, int mclk)
|
||||
{
|
||||
bclkPin = bclk;
|
||||
wclkPin = wclk;
|
||||
doutPin = dout;
|
||||
#ifdef ESP32
|
||||
mclkPin = mclk;
|
||||
if (i2sOn)
|
||||
return SetPinout();
|
||||
#else
|
||||
(void)mclk;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AudioOutputI2S::SetRate(int hz)
|
||||
{
|
||||
// TODO - have a list of allowable rates from constructor, check them
|
||||
@@ -147,6 +168,17 @@ bool AudioOutputI2S::SetLsbJustified(bool lsbJustified)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AudioOutputI2S::SetMclk(bool enabled){
|
||||
(void)enabled;
|
||||
#ifdef ESP32
|
||||
if (output_mode == INTERNAL_DAC || output_mode == INTERNAL_PDM)
|
||||
return false; // Not allowed
|
||||
|
||||
use_mclk = enabled;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AudioOutputI2S::begin(bool txDAC)
|
||||
{
|
||||
#ifdef ESP32
|
||||
@@ -219,9 +251,9 @@ bool AudioOutputI2S::begin(bool txDAC)
|
||||
.dma_buf_len = 128,
|
||||
.use_apll = use_apll, // Use audio PLL
|
||||
.tx_desc_auto_clear = true, // Silence on underflow
|
||||
.fixed_mclk = 0, // Unused
|
||||
.fixed_mclk = use_mclk, // Unused
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
|
||||
.mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT, // Unused
|
||||
.mclk_multiple = I2S_MCLK_MULTIPLE_256, // Unused
|
||||
.bits_per_chan = I2S_BITS_PER_CHAN_DEFAULT // Use bits per sample
|
||||
#endif
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user