mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-13 05:46:30 +00:00
sbox support
This commit is contained in:
parent
61734674c5
commit
c3856a6873
32
lib/lib_audio/ESP8266Audio/src/AudioOutputI2S.cpp
Normal file → Executable file
32
lib/lib_audio/ESP8266Audio/src/AudioOutputI2S.cpp
Normal file → Executable file
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
AudioOutputI2S
|
AudioOutputI2S
|
||||||
Base class for I2S interface port
|
Base class for I2S interface port
|
||||||
|
|
||||||
Copyright (C) 2017 Earle F. Philhower, III
|
Copyright (C) 2017 Earle F. Philhower, III
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
@ -59,10 +59,13 @@ bool AudioOutputI2S::SetPinout()
|
|||||||
return false; // Not allowed
|
return false; // Not allowed
|
||||||
|
|
||||||
i2s_pin_config_t pins = {
|
i2s_pin_config_t pins = {
|
||||||
|
.mck_io_num = mclkPin,
|
||||||
.bck_io_num = bclkPin,
|
.bck_io_num = bclkPin,
|
||||||
.ws_io_num = wclkPin,
|
.ws_io_num = wclkPin,
|
||||||
.data_out_num = doutPin,
|
.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);
|
i2s_set_pin((i2s_port_t)portNo, &pins);
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
@ -73,11 +76,15 @@ bool AudioOutputI2S::SetPinout()
|
|||||||
#endif
|
#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;
|
bclkPin = bclk;
|
||||||
wclkPin = wclk;
|
wclkPin = wclk;
|
||||||
doutPin = dout;
|
doutPin = dout;
|
||||||
|
mclkPin = mclk;
|
||||||
|
dinPin = din;
|
||||||
|
|
||||||
|
|
||||||
if (i2sOn)
|
if (i2sOn)
|
||||||
return SetPinout();
|
return SetPinout();
|
||||||
|
|
||||||
@ -178,7 +185,7 @@ bool AudioOutputI2S::begin(bool txDAC)
|
|||||||
#if CONFIG_IDF_TARGET_ESP32
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
mode = (i2s_mode_t)(mode | I2S_MODE_DAC_BUILT_IN);
|
mode = (i2s_mode_t)(mode | I2S_MODE_DAC_BUILT_IN);
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (output_mode == INTERNAL_PDM)
|
else if (output_mode == INTERNAL_PDM)
|
||||||
@ -186,7 +193,7 @@ bool AudioOutputI2S::begin(bool txDAC)
|
|||||||
#if CONFIG_IDF_TARGET_ESP32
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
mode = (i2s_mode_t)(mode | I2S_MODE_PDM);
|
mode = (i2s_mode_t)(mode | I2S_MODE_PDM);
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,6 +219,14 @@ bool AudioOutputI2S::begin(bool txDAC)
|
|||||||
#endif
|
#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 = {
|
i2s_config_t i2s_config_dac = {
|
||||||
.mode = mode,
|
.mode = mode,
|
||||||
.sample_rate = 44100,
|
.sample_rate = 44100,
|
||||||
@ -221,7 +236,12 @@ bool AudioOutputI2S::begin(bool txDAC)
|
|||||||
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // lowest interrupt priority
|
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // lowest interrupt priority
|
||||||
.dma_buf_count = dma_buf_count,
|
.dma_buf_count = dma_buf_count,
|
||||||
.dma_buf_len = 128,
|
.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);
|
audioLogger->printf("+%d %p\n", portNo, &i2s_config_dac);
|
||||||
if (i2s_driver_install((i2s_port_t)portNo, &i2s_config_dac, 0, NULL) != ESP_OK)
|
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
20
lib/lib_audio/ESP8266Audio/src/AudioOutputI2S.h
Normal file → Executable file
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
AudioOutputI2S
|
AudioOutputI2S
|
||||||
Base class for an I2S output port
|
Base class for an I2S output port
|
||||||
|
|
||||||
Copyright (C) 2017 Earle F. Philhower, III
|
Copyright (C) 2017 Earle F. Philhower, III
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
@ -19,15 +19,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#ifdef ESP32
|
||||||
|
#include <driver/i2s.h>
|
||||||
|
#endif
|
||||||
#include "AudioOutput.h"
|
#include "AudioOutput.h"
|
||||||
|
|
||||||
|
#ifndef I2S_PIN_NO_CHANGE
|
||||||
|
#define I2S_PIN_NO_CHANGE -1
|
||||||
|
#endif
|
||||||
|
|
||||||
class AudioOutputI2S : public AudioOutput
|
class AudioOutputI2S : public AudioOutput
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
#if defined(ESP32) || defined(ESP8266)
|
#if defined(ESP32) || defined(ESP8266)
|
||||||
AudioOutputI2S(int port=0, int output_mode=EXTERNAL_I2S, int dma_buf_count = 8, int use_apll=APLL_DISABLE);
|
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 { APLL_AUTO = -1, APLL_ENABLE = 1, APLL_DISABLE = 0 };
|
||||||
enum : int { EXTERNAL_I2S = 0, INTERNAL_DAC = 1, INTERNAL_PDM = 2 };
|
enum : int { EXTERNAL_I2S = 0, INTERNAL_DAC = 1, INTERNAL_PDM = 2 };
|
||||||
#elif defined(ARDUINO_ARCH_RP2040)
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
@ -41,10 +47,10 @@ class AudioOutputI2S : public AudioOutput
|
|||||||
virtual bool ConsumeSample(int16_t sample[2]) override;
|
virtual bool ConsumeSample(int16_t sample[2]) override;
|
||||||
virtual void flush() override;
|
virtual void flush() override;
|
||||||
virtual bool stop() override;
|
virtual bool stop() override;
|
||||||
|
|
||||||
bool begin(bool txDAC);
|
bool begin(bool txDAC);
|
||||||
bool SetOutputModeMono(bool mono); // Force mono output no matter the input
|
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:
|
protected:
|
||||||
bool SetPinout();
|
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
|
// 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;
|
||||||
|
|
||||||
uint8_t bclkPin;
|
uint8_t bclkPin;
|
||||||
uint8_t wclkPin;
|
uint8_t wclkPin;
|
||||||
uint8_t doutPin;
|
uint8_t doutPin;
|
||||||
|
uint8_t dinPin;
|
||||||
|
uint8_t mclkPin;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user