Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i2s: adds i2s_rxtxdrive_begin(enableRx, enableTx, driveRxClocks, driveTxClocks) #7748

Merged
merged 4 commits into from
Dec 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions cores/esp8266/core_esp8266_i2s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ typedef struct i2s_state {
// Callback function should be defined as 'void ICACHE_RAM_ATTR function_name()',
// and be placed in IRAM for faster execution. Avoid long computational tasks in this
// function, use it to set flags and process later.
bool txDAC;
} i2s_state_t;

// RX = I2S receive (i.e. microphone), TX = I2S transmit (i.e. DAC)
Expand Down Expand Up @@ -493,6 +494,10 @@ float i2s_get_real_rate(){
}

bool i2s_rxtx_begin(bool enableRx, bool enableTx) {
return i2s_rxtxdac_begin(enableRx, enableTx, true);
}

bool i2s_rxtxdac_begin(bool enableRx, bool enableTx, bool txDAC) {
earlephilhower marked this conversation as resolved.
Show resolved Hide resolved
if (tx || rx) {
i2s_end(); // Stop and free any ongoing stuff
}
Expand All @@ -503,9 +508,11 @@ bool i2s_rxtx_begin(bool enableRx, bool enableTx) {
// Nothing to clean up yet
return false; // OOM Error!
}
pinMode(I2SO_WS, FUNCTION_1);
pinMode(I2SO_DATA, FUNCTION_1);
pinMode(I2SO_BCK, FUNCTION_1);
if ((tx->txDAC = txDAC)) {
earlephilhower marked this conversation as resolved.
Show resolved Hide resolved
pinMode(I2SO_WS, FUNCTION_1);
pinMode(I2SO_BCK, FUNCTION_1);
}
}
if (enableRx) {
rx = (i2s_state_t*)calloc(1, sizeof(*rx));
Expand Down Expand Up @@ -579,8 +586,10 @@ void i2s_end() {

if (tx) {
pinMode(I2SO_DATA, INPUT);
pinMode(I2SO_BCK, INPUT);
pinMode(I2SO_WS, INPUT);
if (tx->txDAC) {
pinMode(I2SO_BCK, INPUT);
pinMode(I2SO_WS, INPUT);
}
free(tx);
tx = NULL;
}
Expand Down
3 changes: 3 additions & 0 deletions cores/esp8266/i2s.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#ifndef I2S_h
#define I2S_h

#define I2S_HAS_BEGIN_RXTXDAC 1

/*
How does this work? Basically, to get sound, you need to:
- Connect an I2S codec to the I2S pins on the ESP.
Expand All @@ -41,6 +43,7 @@ extern "C" {
#endif

void i2s_begin(); // Enable TX only, for compatibility
bool i2s_rxtxdac_begin(bool enableRx, bool enableTx, bool txDAC); // Allow TX and/or RX, returns false on OOM error
bool i2s_rxtx_begin(bool enableRx, bool enableTx); // Allow TX and/or RX, returns false on OOM error
void i2s_end();
void i2s_set_rate(uint32_t rate);//Sample Rate in Hz (ex 44100, 48000)
Expand Down