make sure setrate can be called for default value
This commit is contained in:
parent
f72d75e267
commit
4d76f39878
|
@ -33,6 +33,7 @@ AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int
|
||||||
{
|
{
|
||||||
this->portNo = port;
|
this->portNo = port;
|
||||||
this->i2sOn = false;
|
this->i2sOn = false;
|
||||||
|
this->i2sRateSet = false;
|
||||||
this->dma_buf_count = dma_buf_count;
|
this->dma_buf_count = dma_buf_count;
|
||||||
if (output_mode != EXTERNAL_I2S && output_mode != INTERNAL_DAC && output_mode != INTERNAL_PDM) {
|
if (output_mode != EXTERNAL_I2S && output_mode != INTERNAL_DAC && output_mode != INTERNAL_PDM) {
|
||||||
output_mode = EXTERNAL_I2S;
|
output_mode = EXTERNAL_I2S;
|
||||||
|
@ -56,6 +57,7 @@ AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int
|
||||||
#elif defined(ARDUINO_ARCH_RP2040)
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
AudioOutputI2S::AudioOutputI2S(long sampleRate, pin_size_t sck, pin_size_t data) {
|
AudioOutputI2S::AudioOutputI2S(long sampleRate, pin_size_t sck, pin_size_t data) {
|
||||||
i2sOn = false;
|
i2sOn = false;
|
||||||
|
i2sRateSet = false;
|
||||||
mono = false;
|
mono = false;
|
||||||
bps = 16;
|
bps = 16;
|
||||||
channels = 2;
|
channels = 2;
|
||||||
|
@ -130,11 +132,12 @@ bool AudioOutputI2S::SetRate(int hz)
|
||||||
{
|
{
|
||||||
// TODO - have a list of allowable rates from constructor, check them
|
// TODO - have a list of allowable rates from constructor, check them
|
||||||
|
|
||||||
if(this->hertz == hz){ // hz already set to this
|
if(this->hertz == hz && this->i2sRateSet){ // hz already set to this
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->hertz = hz;
|
this->hertz = hz;
|
||||||
|
|
||||||
if (i2sOn)
|
if (i2sOn)
|
||||||
{
|
{
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
|
@ -145,6 +148,10 @@ bool AudioOutputI2S::SetRate(int hz)
|
||||||
i2s.setFrequency(hz);
|
i2s.setFrequency(hz);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!this->i2sRateSet){
|
||||||
|
this->i2sRateSet = true;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,5 +413,6 @@ bool AudioOutputI2S::stop()
|
||||||
i2s.end();
|
i2s.end();
|
||||||
#endif
|
#endif
|
||||||
i2sOn = false;
|
i2sOn = false;
|
||||||
|
i2sRateSet = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,10 +62,12 @@ class AudioOutputI2S : public AudioOutput
|
||||||
bool mono;
|
bool mono;
|
||||||
int lsb_justified;
|
int lsb_justified;
|
||||||
bool i2sOn;
|
bool i2sOn;
|
||||||
|
bool i2sRateSet;
|
||||||
int dma_buf_count;
|
int dma_buf_count;
|
||||||
int use_apll;
|
int use_apll;
|
||||||
bool use_mclk;
|
bool use_mclk;
|
||||||
bool swap_clocks;
|
bool swap_clocks;
|
||||||
|
|
||||||
// We can restore the old values and free up these pins when in NoDAC mode
|
// We can restore the old values and free up these pins when in NoDAC mode
|
||||||
uint32_t orig_bck;
|
uint32_t orig_bck;
|
||||||
uint32_t orig_ws;
|
uint32_t orig_ws;
|
||||||
|
|
Loading…
Reference in New Issue