From 0d132c1391ae88931c5d3bdd7f33eb2261240393 Mon Sep 17 00:00:00 2001 From: Wojtek Kaniewski Date: Sat, 4 Dec 2021 03:47:01 +0100 Subject: [PATCH] Support LSB Justified DACs (e.g. PT8211) (#459) --- src/AudioOutputI2S.cpp | 19 +++++++++++++++++-- src/AudioOutputI2S.h | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/AudioOutputI2S.cpp b/src/AudioOutputI2S.cpp index 760ff1a..01a8f92 100644 --- a/src/AudioOutputI2S.cpp +++ b/src/AudioOutputI2S.cpp @@ -42,6 +42,7 @@ AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int //set defaults mono = false; + lsb_justified = false; bps = 16; channels = 2; hertz = 44100; @@ -148,6 +149,12 @@ bool AudioOutputI2S::SetOutputModeMono(bool mono) return true; } +bool AudioOutputI2S::SetLsbJustified(bool lsbJustified) +{ + this->lsb_justified = lsbJustified; + return true; +} + bool AudioOutputI2S::begin(bool txDAC) { #ifdef ESP32 @@ -183,10 +190,18 @@ bool AudioOutputI2S::begin(bool txDAC) #endif } - i2s_comm_format_t comm_fmt = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB); + i2s_comm_format_t comm_fmt; if (output_mode == INTERNAL_DAC) { - comm_fmt = (i2s_comm_format_t)I2S_COMM_FORMAT_I2S_MSB; + comm_fmt = (i2s_comm_format_t) I2S_COMM_FORMAT_I2S_MSB; + } + else if (lsb_justified) + { + comm_fmt = (i2s_comm_format_t) (I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_LSB); + } + else + { + comm_fmt = (i2s_comm_format_t) (I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB); } i2s_config_t i2s_config_dac = { diff --git a/src/AudioOutputI2S.h b/src/AudioOutputI2S.h index 90370dc..b3f621d 100644 --- a/src/AudioOutputI2S.h +++ b/src/AudioOutputI2S.h @@ -44,6 +44,7 @@ class AudioOutputI2S : public AudioOutput bool begin(bool txDAC); bool SetOutputModeMono(bool mono); // Force mono output no matter the input + bool SetLsbJustified(bool lsbJustified); // Allow supporting non-I2S chips, e.g. PT8211 protected: bool SetPinout(); @@ -51,6 +52,7 @@ class AudioOutputI2S : public AudioOutput uint8_t portNo; int output_mode; bool mono; + int lsb_justified; bool i2sOn; int dma_buf_count; int use_apll;