Skip to content

Add support for I2S Slot Mask #8936

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

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 10 additions & 8 deletions libraries/ESP_I2S/src/ESP_I2S.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void I2SClass::setInvertedPdm(bool clk){
}
#endif

bool I2SClass::initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){
bool I2SClass::initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask){
// Peripheral manager deinit previous peripheral if pin was used
if (_mclk >= 0) if (!perimanClearPinBus(_mclk)){ return false; }
if (_bclk >= 0) if (!perimanClearPinBus(_bclk)){ return false; }
Expand All @@ -307,6 +307,9 @@ bool I2SClass::initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mo
}

i2s_std_config_t i2s_config = I2S_STD_CHAN_CFG(rate, bits_cfg, ch);
if(slot_mask >= 0 && (i2s_std_slot_mask_t)slot_mask <= I2S_STD_SLOT_BOTH){
i2s_config.slot_cfg.slot_mask = (i2s_std_slot_mask_t)slot_mask;
}
if (tx_chan != NULL) {
tx_sample_rate = rate;
tx_data_bit_width = bits_cfg;
Expand Down Expand Up @@ -475,11 +478,7 @@ bool I2SClass::initPDMrx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_
}
#endif

bool I2SClass::begin(i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch
#if SOC_I2S_SUPPORTS_TDM
, int8_t slot_mask
#endif
){
bool I2SClass::begin(i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask){
/* Setup I2S peripheral */
if (mode >= I2S_MODE_MAX){
log_e("Invalid I2S mode selected.");
Expand All @@ -490,7 +489,7 @@ bool I2SClass::begin(i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_c
bool init = false;
switch (_mode){
case I2S_MODE_STD:
init = initSTD(rate, bits_cfg, ch);
init = initSTD(rate, bits_cfg, ch, slot_mask);
break;
#if SOC_I2S_SUPPORTS_TDM
case I2S_MODE_TDM:
Expand Down Expand Up @@ -569,13 +568,16 @@ bool I2SClass::end(){
return true;
}

bool I2SClass::configureTX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){
bool I2SClass::configureTX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask){
/* Setup I2S channels */
if (tx_chan != NULL) {
if(tx_sample_rate == rate && tx_data_bit_width == bits_cfg && tx_slot_mode == ch){
return true;
}
i2s_std_config_t i2s_config = I2S_STD_CHAN_CFG(rate, bits_cfg, ch);
if(slot_mask >= 0 && (i2s_std_slot_mask_t)slot_mask <= I2S_STD_SLOT_BOTH){
i2s_config.slot_cfg.slot_mask = (i2s_std_slot_mask_t)slot_mask;
}
I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_disable(tx_chan));
I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_reconfig_std_clock(tx_chan, &i2s_config.clk_cfg));
tx_sample_rate = rate;
Expand Down
10 changes: 3 additions & 7 deletions libraries/ESP_I2S/src/ESP_I2S.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@ class I2SClass: public Stream {
void setInvertedPdm(bool clk);
#endif

bool begin(i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch
#if SOC_I2S_SUPPORTS_TDM
, int8_t slot_mask=-1
#endif
);
bool configureTX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch);
bool begin(i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask=-1);
bool configureTX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask=-1);
bool configureRX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, i2s_rx_transform_t transform=I2S_RX_TRANSFORM_NONE);
bool end();

Expand Down Expand Up @@ -130,7 +126,7 @@ class I2SClass: public Stream {
bool transformRX(i2s_rx_transform_t transform);

static bool i2sDetachBus(void * bus_pointer);
bool initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch);
bool initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask);
#if SOC_I2S_SUPPORTS_TDM
bool initTDM(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask);
#endif
Expand Down