Remove direct setup for I2C from ES8388 driver
This commit is contained in:
parent
76acb7bb58
commit
7d4fe341f1
@ -1153,7 +1153,7 @@ class AudioReactive : public Usermod {
|
|||||||
DEBUGSR_PRINTLN(F("AR: ES8388 Source"));
|
DEBUGSR_PRINTLN(F("AR: ES8388 Source"));
|
||||||
audioSource = new ES8388Source(SAMPLE_RATE, BLOCK_SIZE);
|
audioSource = new ES8388Source(SAMPLE_RATE, BLOCK_SIZE);
|
||||||
delay(100);
|
delay(100);
|
||||||
if (audioSource) audioSource->initialize(sdaPin, sclPin, i2swsPin, i2ssdPin, i2sckPin, mclkPin);
|
if (audioSource) audioSource->initialize(i2swsPin, i2ssdPin, i2sckPin, mclkPin);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
|
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||||
|
@ -433,13 +433,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
class ES8388Source : public I2SSource {
|
class ES8388Source : public I2SSource {
|
||||||
private:
|
private:
|
||||||
// I2C initialization functions for ES8388
|
|
||||||
void _es8388I2cBegin() {
|
|
||||||
bool i2c_initialized = Wire.begin(pin_ES8388_SDA, pin_ES8388_SCL, 100000U);
|
|
||||||
if (i2c_initialized == false) {
|
|
||||||
DEBUGSR_PRINTLN(F("AR: ES8388 failed to initialize I2C bus driver."));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _es8388I2cWrite(uint8_t reg, uint8_t val) {
|
void _es8388I2cWrite(uint8_t reg, uint8_t val) {
|
||||||
#ifndef ES8388_ADDR
|
#ifndef ES8388_ADDR
|
||||||
@ -464,7 +457,6 @@ class ES8388Source : public I2SSource {
|
|||||||
// Registries are decimal, settings are binary as that's how everything is listed in the docs
|
// Registries are decimal, settings are binary as that's how everything is listed in the docs
|
||||||
// ...which makes it easier to reference the docs.
|
// ...which makes it easier to reference the docs.
|
||||||
//
|
//
|
||||||
_es8388I2cBegin();
|
|
||||||
_es8388I2cWrite( 8,0b00000000); // I2S to slave
|
_es8388I2cWrite( 8,0b00000000); // I2S to slave
|
||||||
_es8388I2cWrite( 2,0b11110011); // Power down DEM and STM
|
_es8388I2cWrite( 2,0b11110011); // Power down DEM and STM
|
||||||
_es8388I2cWrite(43,0b10000000); // Set same LRCK
|
_es8388I2cWrite(43,0b10000000); // Set same LRCK
|
||||||
@ -534,49 +526,22 @@ class ES8388Source : public I2SSource {
|
|||||||
_config.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT;
|
_config.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT;
|
||||||
};
|
};
|
||||||
|
|
||||||
void initialize(int8_t sdaPin, int8_t sclPin, int8_t i2swsPin, int8_t i2ssdPin, int8_t i2sckPin, int8_t mclkPin) {
|
void initialize(int8_t i2swsPin, int8_t i2ssdPin, int8_t i2sckPin, int8_t mclkPin) {
|
||||||
|
|
||||||
// BUG: "use global I2C pins" are valid as -1, and -1 is seen as invalid here.
|
|
||||||
// Workaround: Set I2C pins here, which will also set them globally.
|
|
||||||
// Bug also exists in ES7243.
|
|
||||||
|
|
||||||
// check that pins are valid
|
|
||||||
if ((sdaPin < 0) || (sclPin < 0)) {
|
|
||||||
DEBUGSR_PRINTF("\nAR: invalid ES8388 I2C pins: SDA=%d, SCL=%d\n", sdaPin, sclPin);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((i2sckPin < 0) || (mclkPin < 0)) {
|
if ((i2sckPin < 0) || (mclkPin < 0)) {
|
||||||
DEBUGSR_PRINTF("\nAR: invalid I2S pin: SCK=%d, MCLK=%d\n", i2sckPin, mclkPin);
|
DEBUGSR_PRINTF("\nAR: invalid I2S pin: SCK=%d, MCLK=%d\n", i2sckPin, mclkPin);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reserve SDA and SCL pins of the I2C interface
|
|
||||||
PinManagerPinType es8388Pins[2] = { { sdaPin, true }, { sclPin, true } };
|
|
||||||
if (!pinManager.allocateMultiplePins(es8388Pins, 2, PinOwner::HW_I2C)) {
|
|
||||||
pinManager.deallocateMultiplePins(es8388Pins, 2, PinOwner::HW_I2C);
|
|
||||||
DEBUGSR_PRINTF("\nAR: Failed to allocate ES8388 I2C pins: SDA=%d, SCL=%d\n", sdaPin, sclPin);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pin_ES8388_SDA = sdaPin;
|
|
||||||
pin_ES8388_SCL = sclPin;
|
|
||||||
|
|
||||||
// First route mclk, then configure ADC over I2C, then configure I2S
|
// First route mclk, then configure ADC over I2C, then configure I2S
|
||||||
_es8388InitAdc();
|
_es8388InitAdc();
|
||||||
I2SSource::initialize(i2swsPin, i2ssdPin, i2sckPin, mclkPin);
|
I2SSource::initialize(i2swsPin, i2ssdPin, i2sckPin, mclkPin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deinitialize() {
|
void deinitialize() {
|
||||||
// Release SDA and SCL pins of the I2C interface
|
|
||||||
PinManagerPinType es8388Pins[2] = { { pin_ES8388_SDA, true }, { pin_ES8388_SCL, true } };
|
|
||||||
pinManager.deallocateMultiplePins(es8388Pins, 2, PinOwner::HW_I2C);
|
|
||||||
I2SSource::deinitialize();
|
I2SSource::deinitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
int8_t pin_ES8388_SDA;
|
|
||||||
int8_t pin_ES8388_SCL;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user