Unverified Commit 5ca45beb authored by Me No Dev's avatar Me No Dev Committed by GitHub

Add support for I2S Slot Mask (#8936)

Needed for some setups, where only the right channel is being used.
parent c1417e9b
...@@ -281,7 +281,7 @@ void I2SClass::setInvertedPdm(bool clk){ ...@@ -281,7 +281,7 @@ void I2SClass::setInvertedPdm(bool clk){
} }
#endif #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 // Peripheral manager deinit previous peripheral if pin was used
if (_mclk >= 0) if (!perimanClearPinBus(_mclk)){ return false; } if (_mclk >= 0) if (!perimanClearPinBus(_mclk)){ return false; }
if (_bclk >= 0) if (!perimanClearPinBus(_bclk)){ return false; } if (_bclk >= 0) if (!perimanClearPinBus(_bclk)){ return false; }
...@@ -307,6 +307,9 @@ bool I2SClass::initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mo ...@@ -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); 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) { if (tx_chan != NULL) {
tx_sample_rate = rate; tx_sample_rate = rate;
tx_data_bit_width = bits_cfg; tx_data_bit_width = bits_cfg;
...@@ -475,11 +478,7 @@ err: ...@@ -475,11 +478,7 @@ err:
} }
#endif #endif
bool I2SClass::begin(i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch 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){
#if SOC_I2S_SUPPORTS_TDM
, int8_t slot_mask
#endif
){
/* Setup I2S peripheral */ /* Setup I2S peripheral */
if (mode >= I2S_MODE_MAX){ if (mode >= I2S_MODE_MAX){
log_e("Invalid I2S mode selected."); log_e("Invalid I2S mode selected.");
...@@ -490,7 +489,7 @@ bool I2SClass::begin(i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_c ...@@ -490,7 +489,7 @@ bool I2SClass::begin(i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_c
bool init = false; bool init = false;
switch (_mode){ switch (_mode){
case I2S_MODE_STD: case I2S_MODE_STD:
init = initSTD(rate, bits_cfg, ch); init = initSTD(rate, bits_cfg, ch, slot_mask);
break; break;
#if SOC_I2S_SUPPORTS_TDM #if SOC_I2S_SUPPORTS_TDM
case I2S_MODE_TDM: case I2S_MODE_TDM:
...@@ -569,13 +568,16 @@ bool I2SClass::end(){ ...@@ -569,13 +568,16 @@ bool I2SClass::end(){
return true; 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 */ /* Setup I2S channels */
if (tx_chan != NULL) { if (tx_chan != NULL) {
if(tx_sample_rate == rate && tx_data_bit_width == bits_cfg && tx_slot_mode == ch){ if(tx_sample_rate == rate && tx_data_bit_width == bits_cfg && tx_slot_mode == ch){
return true; return true;
} }
i2s_std_config_t i2s_config = I2S_STD_CHAN_CFG(rate, bits_cfg, ch); 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_disable(tx_chan));
I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_reconfig_std_clock(tx_chan, &i2s_config.clk_cfg)); I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_reconfig_std_clock(tx_chan, &i2s_config.clk_cfg));
tx_sample_rate = rate; tx_sample_rate = rate;
......
...@@ -56,12 +56,8 @@ class I2SClass: public Stream { ...@@ -56,12 +56,8 @@ class I2SClass: public Stream {
void setInvertedPdm(bool clk); void setInvertedPdm(bool clk);
#endif #endif
bool begin(i2s_mode_t mode, 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);
#if SOC_I2S_SUPPORTS_TDM bool configureTX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask=-1);
, int8_t slot_mask=-1
#endif
);
bool configureTX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch);
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 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(); bool end();
...@@ -130,7 +126,7 @@ class I2SClass: public Stream { ...@@ -130,7 +126,7 @@ class I2SClass: public Stream {
bool transformRX(i2s_rx_transform_t transform); bool transformRX(i2s_rx_transform_t transform);
static bool i2sDetachBus(void * bus_pointer); 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 #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); bool initTDM(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask);
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment