Skip to content

Commit a5a3b91

Browse files
lucasssvazAlan Carvalho de Assis
authored andcommitted
audio: Add i2s_getmclkfrequency function
Rename i2s_mclkfrequency to i2s_setmclkfrequency and add i2s_getmclkfrequency for getting the current MCLK frequency from the I2S interface
1 parent fcba685 commit a5a3b91

File tree

5 files changed

+99
-28
lines changed

5 files changed

+99
-28
lines changed

arch/xtensa/src/esp32/esp32_i2s.c

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ static void i2s_rx_schedule(struct esp32_i2s_s *priv,
339339

340340
static uint32_t i2s_set_datawidth(struct esp32_i2s_s *priv);
341341
static uint32_t i2s_set_clock(struct esp32_i2s_s *priv);
342-
static uint32_t i2s_mclkfrequency(struct i2s_dev_s *dev, uint32_t frequency);
342+
static uint32_t i2s_getmclkfrequency(struct i2s_dev_s *dev);
343+
static uint32_t i2s_setmclkfrequency(struct i2s_dev_s *dev,
344+
uint32_t frequency);
343345
static int i2s_ioctl(struct i2s_dev_s *dev, int cmd, unsigned long arg);
344346

345347
#ifdef I2S_HAVE_TX
@@ -385,7 +387,8 @@ static const struct i2s_ops_s g_i2sops =
385387
#endif /* I2S_HAVE_RX */
386388

387389
.i2s_ioctl = i2s_ioctl,
388-
.i2s_mclkfrequency = i2s_mclkfrequency,
390+
.i2s_getmclkfrequency = i2s_getmclkfrequency,
391+
.i2s_setmclkfrequency = i2s_setmclkfrequency,
389392
};
390393

391394
#ifdef CONFIG_ESP32_I2S0
@@ -1654,7 +1657,7 @@ static void i2s_configure(struct esp32_i2s_s *priv)
16541657
* by the number of bytes from a sample, i.e, for 24 bits, the
16551658
* multiplier should be divisible by 3. NOTE: the MCLK frequency can
16561659
* be adjusted on runtime, so this value remains valid only if the
1657-
* upper half does not implement the `i2s_mclkfrequency` method.
1660+
* upper half does not implement the `i2s_setmclkfrequency` method.
16581661
*/
16591662

16601663
if (priv->config->data_width == I2S_DATA_BIT_WIDTH_24BIT)
@@ -1666,8 +1669,8 @@ static void i2s_configure(struct esp32_i2s_s *priv)
16661669
priv->mclk_multiple = I2S_MCLK_MULTIPLE_256;
16671670
}
16681671

1669-
i2s_mclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
1670-
priv->mclk_multiple));
1672+
i2s_setmclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
1673+
priv->mclk_multiple));
16711674

16721675
priv->rate = priv->config->rate;
16731676
i2s_set_clock(priv);
@@ -1774,7 +1777,7 @@ static void i2s_configure(struct esp32_i2s_s *priv)
17741777
* by the number of bytes from a sample, i.e, for 24 bits, the
17751778
* multiplier should be divisible by 3. NOTE: the MCLK frequency can
17761779
* be adjusted on runtime, so this value remains valid only if the
1777-
* upper half does not implement the `i2s_mclkfrequency` method.
1780+
* upper half does not implement the `i2s_setmclkfrequency` method.
17781781
*/
17791782

17801783
if (priv->config->data_width == I2S_DATA_BIT_WIDTH_24BIT)
@@ -1786,8 +1789,8 @@ static void i2s_configure(struct esp32_i2s_s *priv)
17861789
priv->mclk_multiple = I2S_MCLK_MULTIPLE_256;
17871790
}
17881791

1789-
i2s_mclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
1790-
priv->mclk_multiple));
1792+
i2s_setmclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
1793+
priv->mclk_multiple));
17911794

17921795
priv->rate = priv->config->rate;
17931796
i2s_set_clock(priv);
@@ -2305,7 +2308,28 @@ static int i2s_interrupt(int irq, void *context, void *arg)
23052308
}
23062309

23072310
/****************************************************************************
2308-
* Name: i2s_mclkfrequency
2311+
* Name: i2s_getmclkfrequency
2312+
*
2313+
* Description:
2314+
* Get the current master clock frequency.
2315+
*
2316+
* Input Parameters:
2317+
* dev - Device-specific state data
2318+
*
2319+
* Returned Value:
2320+
* Returns the current master clock.
2321+
*
2322+
****************************************************************************/
2323+
2324+
static uint32_t i2s_getmclkfrequency(struct i2s_dev_s *dev)
2325+
{
2326+
struct esp32_i2s_s *priv = (struct esp32_i2s_s *)dev;
2327+
2328+
return priv->mclk_freq;
2329+
}
2330+
2331+
/****************************************************************************
2332+
* Name: i2s_setmclkfrequency
23092333
*
23102334
* Description:
23112335
* Set the master clock frequency. Usually, the MCLK is a multiple of the
@@ -2321,7 +2345,8 @@ static int i2s_interrupt(int irq, void *context, void *arg)
23212345
*
23222346
****************************************************************************/
23232347

2324-
static uint32_t i2s_mclkfrequency(struct i2s_dev_s *dev, uint32_t frequency)
2348+
static uint32_t i2s_setmclkfrequency(struct i2s_dev_s *dev,
2349+
uint32_t frequency)
23252350
{
23262351
struct esp32_i2s_s *priv = (struct esp32_i2s_s *)dev;
23272352

arch/xtensa/src/esp32s2/esp32s2_i2s.c

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ static void i2s_rx_schedule(struct esp32s2_i2s_s *priv,
323323

324324
static uint32_t i2s_set_datawidth(struct esp32s2_i2s_s *priv);
325325
static uint32_t i2s_set_clock(struct esp32s2_i2s_s *priv);
326-
static uint32_t i2s_mclkfrequency(struct i2s_dev_s *dev, uint32_t frequency);
326+
static uint32_t i2s_getmclkfrequency(struct i2s_dev_s *dev);
327+
static uint32_t i2s_setmclkfrequency(struct i2s_dev_s *dev,
328+
uint32_t frequency);
327329
static int i2s_ioctl(struct i2s_dev_s *dev, int cmd, unsigned long arg);
328330

329331
#ifdef I2S_HAVE_TX
@@ -369,7 +371,8 @@ static const struct i2s_ops_s g_i2sops =
369371
#endif /* I2S_HAVE_RX */
370372

371373
.i2s_ioctl = i2s_ioctl,
372-
.i2s_mclkfrequency = i2s_mclkfrequency,
374+
.i2s_getmclkfrequency = i2s_getmclkfrequency,
375+
.i2s_setmclkfrequency = i2s_setmclkfrequency,
373376
};
374377

375378
#ifdef CONFIG_ESP32S2_I2S
@@ -1455,7 +1458,7 @@ static void i2s_configure(struct esp32s2_i2s_s *priv)
14551458
* by the number of bytes from a sample, i.e, for 24 bits, the
14561459
* multiplier should be divisible by 3. NOTE: the MCLK frequency can
14571460
* be adjusted on runtime, so this value remains valid only if the
1458-
* upper half does not implement the `i2s_mclkfrequency` method.
1461+
* upper half does not implement the `i2s_setmclkfrequency` method.
14591462
*/
14601463

14611464
if (priv->config->data_width == I2S_DATA_BIT_WIDTH_24BIT)
@@ -1467,8 +1470,8 @@ static void i2s_configure(struct esp32s2_i2s_s *priv)
14671470
priv->mclk_multiple = I2S_MCLK_MULTIPLE_256;
14681471
}
14691472

1470-
i2s_mclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
1471-
priv->mclk_multiple));
1473+
i2s_setmclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
1474+
priv->mclk_multiple));
14721475

14731476
priv->rate = priv->config->rate;
14741477
i2s_set_clock(priv);
@@ -1556,7 +1559,7 @@ static void i2s_configure(struct esp32s2_i2s_s *priv)
15561559
* by the number of bytes from a sample, i.e, for 24 bits, the
15571560
* multiplier should be divisible by 3. NOTE: the MCLK frequency can
15581561
* be adjusted on runtime, so this value remains valid only if the
1559-
* upper half does not implement the `i2s_mclkfrequency` method.
1562+
* upper half does not implement the `i2s_setmclkfrequency` method.
15601563
*/
15611564

15621565
if (priv->config->data_width == I2S_DATA_BIT_WIDTH_24BIT)
@@ -1568,8 +1571,8 @@ static void i2s_configure(struct esp32s2_i2s_s *priv)
15681571
priv->mclk_multiple = I2S_MCLK_MULTIPLE_256;
15691572
}
15701573

1571-
i2s_mclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
1572-
priv->mclk_multiple));
1574+
i2s_setmclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
1575+
priv->mclk_multiple));
15731576

15741577
priv->rate = priv->config->rate;
15751578
i2s_set_clock(priv);
@@ -2054,7 +2057,28 @@ static int i2s_interrupt(int irq, void *context, void *arg)
20542057
}
20552058

20562059
/****************************************************************************
2057-
* Name: i2s_mclkfrequency
2060+
* Name: i2s_getmclkfrequency
2061+
*
2062+
* Description:
2063+
* Get the current master clock frequency.
2064+
*
2065+
* Input Parameters:
2066+
* dev - Device-specific state data
2067+
*
2068+
* Returned Value:
2069+
* Returns the current master clock.
2070+
*
2071+
****************************************************************************/
2072+
2073+
static uint32_t i2s_getmclkfrequency(struct i2s_dev_s *dev)
2074+
{
2075+
struct esp32s2_i2s_s *priv = (struct esp32s2_i2s_s *)dev;
2076+
2077+
return priv->mclk_freq;
2078+
}
2079+
2080+
/****************************************************************************
2081+
* Name: i2s_setmclkfrequency
20582082
*
20592083
* Description:
20602084
* Set the master clock frequency. Usually, the MCLK is a multiple of the
@@ -2070,7 +2094,8 @@ static int i2s_interrupt(int irq, void *context, void *arg)
20702094
*
20712095
****************************************************************************/
20722096

2073-
static uint32_t i2s_mclkfrequency(struct i2s_dev_s *dev, uint32_t frequency)
2097+
static uint32_t i2s_setmclkfrequency(struct i2s_dev_s *dev,
2098+
uint32_t frequency)
20742099
{
20752100
struct esp32s2_i2s_s *priv = (struct esp32s2_i2s_s *)dev;
20762101

drivers/audio/cs4344.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ static int cs4344_setmclkfrequency(FAR struct cs4344_dev_s *priv)
278278

279279
if (priv->mclk_freq != 0)
280280
{
281-
ret = I2S_MCLKFREQUENCY(priv->i2s, priv->mclk_freq);
281+
ret = I2S_SETMCLKFREQUENCY(priv->i2s, priv->mclk_freq);
282282
}
283283
else
284284
{

drivers/audio/es8388.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ static void es8388_setmclkfrequency(FAR struct es8388_dev_s *priv)
527527
{
528528
audinfo("MCLK Freq: %u\n", priv->mclk);
529529

530-
int ret = I2S_MCLKFREQUENCY(priv->i2s, priv->mclk);
530+
int ret = I2S_SETMCLKFREQUENCY(priv->i2s, priv->mclk);
531531

532532
if (ret < 0)
533533
{

include/nuttx/audio/i2s.h

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,27 @@
226226
((d)->ops->i2s_send ? (d)->ops->i2s_send(d,b,c,a,t) : -ENOTTY)
227227

228228
/****************************************************************************
229-
* Name: I2S_MCLKFREQUENCY
229+
* Name: I2S_GETMCLKFREQUENCY
230+
*
231+
* Description:
232+
* Get the current master clock frequency. NOTE: this parameter may not
233+
* be implemented on I2S driver. If not implemented, the I2S may set
234+
* internally any value to the master clock (or even does not support it).
235+
*
236+
* Input Parameters:
237+
* dev - Device-specific state data
238+
*
239+
* Returned Value:
240+
* Returns the current master clock.
241+
*
242+
****************************************************************************/
243+
244+
#define I2S_GETMCLKFREQUENCY(d) \
245+
((d)->ops->i2s_getmclkfrequency ? \
246+
(d)->ops->i2s_getmclkfrequency(d) : -ENOTTY)
247+
248+
/****************************************************************************
249+
* Name: I2S_SETMCLKFREQUENCY
230250
*
231251
* Description:
232252
* Set the master clock frequency. Usually, the MCLK is a multiple of the
@@ -244,9 +264,9 @@
244264
*
245265
****************************************************************************/
246266

247-
#define I2S_MCLKFREQUENCY(d,f) \
248-
((d)->ops->i2s_mclkfrequency ? \
249-
(d)->ops->i2s_mclkfrequency(d,f) : -ENOTTY)
267+
#define I2S_SETMCLKFREQUENCY(d,f) \
268+
((d)->ops->i2s_setmclkfrequency ? \
269+
(d)->ops->i2s_setmclkfrequency(d,f) : -ENOTTY)
250270

251271
/****************************************************************************
252272
* Name: I2S_IOCTL
@@ -311,8 +331,9 @@ struct i2s_ops_s
311331

312332
/* Master Clock methods */
313333

314-
CODE uint32_t (*i2s_mclkfrequency)(FAR struct i2s_dev_s *dev,
315-
uint32_t frequency);
334+
CODE uint32_t (*i2s_getmclkfrequency)(FAR struct i2s_dev_s *dev);
335+
CODE uint32_t (*i2s_setmclkfrequency)(FAR struct i2s_dev_s *dev,
336+
uint32_t frequency);
316337

317338
/* Ioctl */
318339

0 commit comments

Comments
 (0)