Skip to content

Commit

Permalink
drivers: i2s_mcux_sai: clock config readability
Browse files Browse the repository at this point in the history
Change this code about the frame and bit clock to be more readable

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
  • Loading branch information
decsny authored and kartben committed Jan 9, 2025
1 parent 5a19c65 commit 9e0e41e
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions drivers/i2s/i2s_mcux_sai.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,18 +541,17 @@ static int i2s_mcux_config(const struct device *dev, enum i2s_dir dir,
config.syncMode = dev_cfg->rx_sync_mode;
}

if (i2s_cfg->options & I2S_OPT_FRAME_CLK_SLAVE) {
if (i2s_cfg->options & I2S_OPT_BIT_CLK_SLAVE) {
config.masterSlave = kSAI_Slave;
} else {
config.masterSlave = kSAI_Bclk_Master_FrameSync_Slave;
}
bool frame_clk_slave = i2s_cfg->options & I2S_OPT_FRAME_CLK_SLAVE;
bool bit_clk_slave = i2s_cfg->options & I2S_OPT_BIT_CLK_SLAVE;

if (frame_clk_slave && bit_clk_slave) {
config.masterSlave = kSAI_Slave;
} else if (frame_clk_slave && !bit_clk_slave) {
config.masterSlave = kSAI_Bclk_Master_FrameSync_Slave;
} else if (!frame_clk_slave && bit_clk_slave) {
config.masterSlave = kSAI_Bclk_Slave_FrameSync_Master;
} else {
if (i2s_cfg->options & I2S_OPT_BIT_CLK_SLAVE) {
config.masterSlave = kSAI_Bclk_Slave_FrameSync_Master;
} else {
config.masterSlave = kSAI_Master;
}
config.masterSlave = kSAI_Master;
}

/* clock signal polarity */
Expand All @@ -568,15 +567,13 @@ static int i2s_mcux_config(const struct device *dev, enum i2s_dir dir,
? kSAI_SampleOnRisingEdge
: kSAI_SampleOnFallingEdge;
break;

case I2S_FMT_CLK_IF_NB:
/* Swap frame sync polarity */
config.frameSync.frameSyncPolarity =
(config.frameSync.frameSyncPolarity == kSAI_PolarityActiveHigh)
? kSAI_PolarityActiveLow
: kSAI_PolarityActiveHigh;
break;

case I2S_FMT_CLK_IF_IB:
/* Swap frame sync and bclk polarity */
config.frameSync.frameSyncPolarity =
Expand Down

0 comments on commit 9e0e41e

Please sign in to comment.