sbox support

This commit is contained in:
gemu2015 2022-07-07 13:27:48 +02:00
parent 61734674c5
commit c3856a6873
2 changed files with 40 additions and 12 deletions

32
lib/lib_audio/ESP8266Audio/src/AudioOutputI2S.cpp Normal file → Executable file
View File

@ -1,7 +1,7 @@
/*
AudioOutputI2S
Base class for I2S interface port
Copyright (C) 2017 Earle F. Philhower, III
This program is free software: you can redistribute it and/or modify
@ -59,10 +59,13 @@ bool AudioOutputI2S::SetPinout()
return false; // Not allowed
i2s_pin_config_t pins = {
.mck_io_num = mclkPin,
.bck_io_num = bclkPin,
.ws_io_num = wclkPin,
.data_out_num = doutPin,
.data_in_num = I2S_PIN_NO_CHANGE};
.data_in_num = dinPin
};
//.data_in_num = I2S_PIN_NO_CHANGE};
i2s_set_pin((i2s_port_t)portNo, &pins);
return true;
#else
@ -73,11 +76,15 @@ bool AudioOutputI2S::SetPinout()
#endif
}
bool AudioOutputI2S::SetPinout(int bclk, int wclk, int dout)
bool AudioOutputI2S::SetPinout(int bclk, int wclk, int dout, int mclk, int din)
{
bclkPin = bclk;
wclkPin = wclk;
doutPin = dout;
mclkPin = mclk;
dinPin = din;
if (i2sOn)
return SetPinout();
@ -178,7 +185,7 @@ bool AudioOutputI2S::begin(bool txDAC)
#if CONFIG_IDF_TARGET_ESP32
mode = (i2s_mode_t)(mode | I2S_MODE_DAC_BUILT_IN);
#else
return false;
return false;
#endif
}
else if (output_mode == INTERNAL_PDM)
@ -186,7 +193,7 @@ bool AudioOutputI2S::begin(bool txDAC)
#if CONFIG_IDF_TARGET_ESP32
mode = (i2s_mode_t)(mode | I2S_MODE_PDM);
#else
return false;
return false;
#endif
}
@ -212,6 +219,14 @@ bool AudioOutputI2S::begin(bool txDAC)
#endif
}
if (mclkPin != I2S_PIN_NO_CHANGE) {
use_apll = false;
}
if (dinPin != I2S_PIN_NO_CHANGE) {
mode = (i2s_mode_t) (I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_RX);
}
i2s_config_t i2s_config_dac = {
.mode = mode,
.sample_rate = 44100,
@ -221,7 +236,12 @@ bool AudioOutputI2S::begin(bool txDAC)
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // lowest interrupt priority
.dma_buf_count = dma_buf_count,
.dma_buf_len = 128,
.use_apll = use_apll // Use audio PLL
.use_apll = use_apll, // Use audio PLL
.tx_desc_auto_clear = true,
.fixed_mclk = 0,
//.mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT,
.mclk_multiple = I2S_MCLK_MULTIPLE_128,
.bits_per_chan = I2S_BITS_PER_CHAN_16BIT,
};
audioLogger->printf("+%d %p\n", portNo, &i2s_config_dac);
if (i2s_driver_install((i2s_port_t)portNo, &i2s_config_dac, 0, NULL) != ESP_OK)

20
lib/lib_audio/ESP8266Audio/src/AudioOutputI2S.h Normal file → Executable file
View File

@ -1,7 +1,7 @@
/*
AudioOutputI2S
Base class for an I2S output port
Copyright (C) 2017 Earle F. Philhower, III
This program is free software: you can redistribute it and/or modify
@ -19,15 +19,21 @@
*/
#pragma once
#ifdef ESP32
#include <driver/i2s.h>
#endif
#include "AudioOutput.h"
#ifndef I2S_PIN_NO_CHANGE
#define I2S_PIN_NO_CHANGE -1
#endif
class AudioOutputI2S : public AudioOutput
{
public:
#if defined(ESP32) || defined(ESP8266)
AudioOutputI2S(int port=0, int output_mode=EXTERNAL_I2S, int dma_buf_count = 8, int use_apll=APLL_DISABLE);
bool SetPinout(int bclkPin, int wclkPin, int doutPin);
bool SetPinout(int bclkPin, int wclkPin, int doutPin, int mclk = I2S_PIN_NO_CHANGE, int din = I2S_PIN_NO_CHANGE);
enum : int { APLL_AUTO = -1, APLL_ENABLE = 1, APLL_DISABLE = 0 };
enum : int { EXTERNAL_I2S = 0, INTERNAL_DAC = 1, INTERNAL_PDM = 2 };
#elif defined(ARDUINO_ARCH_RP2040)
@ -41,10 +47,10 @@ class AudioOutputI2S : public AudioOutput
virtual bool ConsumeSample(int16_t sample[2]) override;
virtual void flush() override;
virtual bool stop() override;
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
bool SetLsbJustified(bool lsbJustified); // Allow supporting non-I2S chips, e.g. PT8211
protected:
bool SetPinout();
@ -59,8 +65,10 @@ class AudioOutputI2S : public AudioOutput
// We can restore the old values and free up these pins when in NoDAC mode
uint32_t orig_bck;
uint32_t orig_ws;
uint8_t bclkPin;
uint8_t wclkPin;
uint8_t doutPin;
uint8_t dinPin;
uint8_t mclkPin;
};