This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new 71b9c035d hw/drivers/i2s: Fix setting for bypass mode
71b9c035d is described below
commit 71b9c035d88e88cea2fd0db5dcdd7bdaf6973934
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Wed Jul 2 14:50:05 2025 +0200
hw/drivers/i2s: Fix setting for bypass mode
With this change when bypass is enabled ratio
between MSCK and BCLK is computed when needed.
Previously user could prepare mck_setup and ratio
values but now it's done automatically
Signed-off-by: Jerzy Kasenberg <[email protected]>
---
hw/drivers/i2s/i2s_nrfx/src/i2s_nrfx.c | 45 ++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/hw/drivers/i2s/i2s_nrfx/src/i2s_nrfx.c
b/hw/drivers/i2s/i2s_nrfx/src/i2s_nrfx.c
index 20cd154df..1aa446b30 100644
--- a/hw/drivers/i2s/i2s_nrfx/src/i2s_nrfx.c
+++ b/hw/drivers/i2s/i2s_nrfx/src/i2s_nrfx.c
@@ -218,6 +218,48 @@ static const struct i2s_clock_cfg mck_for_24_bit_samples[]
= {
{ NRF_I2S_MCK_32MDIV15, NRF_I2S_RATIO_48X} /* 48000: 44444.444 LRCK
error -7.4% */
};
+static void
+set_mck_setup_for_bypass(nrfx_i2s_config_t *cfg, uint32_t sample_rate)
+{
+#if NRF_I2S_HAS_CLKCONFIG
+ static const struct {
+ uint16_t ratio_val;
+ nrf_i2s_ratio_t ratio_enum;
+ } ratios[] = {
+ { 32, NRF_I2S_RATIO_32X },
+ { 48, NRF_I2S_RATIO_48X },
+ { 64, NRF_I2S_RATIO_64X },
+ { 96, NRF_I2S_RATIO_96X },
+ { 128, NRF_I2S_RATIO_128X },
+ { 192, NRF_I2S_RATIO_192X },
+ { 256, NRF_I2S_RATIO_256X },
+ { 384, NRF_I2S_RATIO_384X },
+ { 512, NRF_I2S_RATIO_512X }
+ };
+ uint32_t mclk;
+ uint16_t mclk_div;
+ size_t i;
+
+ if (cfg->enable_bypass) {
+ mclk = cfg->clksrc == NRF_I2S_CLKSRC_PCLK32M ? 32000000UL : 12288000UL;
+ mclk_div = mclk / sample_rate;
+
+ for (i = 0; i < ARRAY_SIZE(ratios); i++) {
+ if (mclk_div == ratios[i].ratio_val) {
+ /* Ratio for bit clock */
+ cfg->ratio = ratios[i].ratio_enum;
+ break;
+ }
+ }
+
+ assert(i < ARRAY_SIZE(ratios));
+
+ /* Anything, needed by NRFX */
+ cfg->mck_setup = NRF_I2S_MCK_32MDIV8;
+ }
+#endif
+}
+
static void
i2s_nrfx_select_clock_cfg(nrfx_i2s_config_t *cfg, uint32_t sample_rate)
{
@@ -227,6 +269,9 @@ i2s_nrfx_select_clock_cfg(nrfx_i2s_config_t *cfg, uint32_t
sample_rate)
float src_frq;
uint32_t ratio;
uint32_t mck;
+
+ set_mck_setup_for_bypass(cfg, sample_rate);
+
if (cfg->clksrc == I2S_CONFIG_CLKCONFIG_CLKSRC_ACLK) {
NRF_CLOCK->TASKS_HFCLKAUDIOSTOP = 1;
if (88200 / sample_rate * sample_rate == 88200) {