Skip to content

Commit

Permalink
Add ability to SwapClocks(bool) on I2S. rp2040 only. (#639)
Browse files Browse the repository at this point in the history
Fixes #638
  • Loading branch information
nils-trubkin committed Jun 30, 2023
1 parent 12131e9 commit 0abcf71
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/AudioOutputI2S.cpp
Expand Up @@ -64,6 +64,7 @@ AudioOutputI2S::AudioOutputI2S(long sampleRate, pin_size_t sck, pin_size_t data)
doutPin = data;
mclkPin = 0;
use_mclk = false;
swap_clocks = false;
SetGain(1.0);
}
#endif
Expand Down Expand Up @@ -168,6 +169,15 @@ bool AudioOutputI2S::SetLsbJustified(bool lsbJustified)
return true;
}

bool AudioOutputI2S::SwapClocks(bool swap_clocks)
{
if (i2sOn) {
return false; // Not allowed
}
this->swap_clocks = swap_clocks;
return true;
}

bool AudioOutputI2S::SetMclk(bool enabled){
(void)enabled;
#ifdef ESP32
Expand Down Expand Up @@ -302,6 +312,9 @@ bool AudioOutputI2S::begin(bool txDAC)
if (!i2sOn) {
i2s.setBCLK(bclkPin);
i2s.setDATA(doutPin);
if (swap_clocks) {
i2s.swapClocks();
}
i2s.begin(hertz);
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/AudioOutputI2S.h
Expand Up @@ -52,6 +52,7 @@ class AudioOutputI2S : public AudioOutput
bool SetOutputModeMono(bool mono); // Force mono output no matter the input
bool SetLsbJustified(bool lsbJustified); // Allow supporting non-I2S chips, e.g. PT8211
bool SetMclk(bool enabled); // Enable MCLK output (if supported)
bool SwapClocks(bool swap_clocks); // Swap BCLK and WCLK

protected:
bool SetPinout();
Expand All @@ -64,6 +65,7 @@ class AudioOutputI2S : public AudioOutput
int dma_buf_count;
int use_apll;
bool use_mclk;
bool swap_clocks;
// We can restore the old values and free up these pins when in NoDAC mode
uint32_t orig_bck;
uint32_t orig_ws;
Expand Down

0 comments on commit 0abcf71

Please sign in to comment.