mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 08:38:38 +08:00
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
This commit is contained in:
parent
fcba68513d
commit
a5a3b919a0
5 changed files with 99 additions and 28 deletions
|
@ -339,7 +339,9 @@ static void i2s_rx_schedule(struct esp32_i2s_s *priv,
|
|||
|
||||
static uint32_t i2s_set_datawidth(struct esp32_i2s_s *priv);
|
||||
static uint32_t i2s_set_clock(struct esp32_i2s_s *priv);
|
||||
static uint32_t i2s_mclkfrequency(struct i2s_dev_s *dev, uint32_t frequency);
|
||||
static uint32_t i2s_getmclkfrequency(struct i2s_dev_s *dev);
|
||||
static uint32_t i2s_setmclkfrequency(struct i2s_dev_s *dev,
|
||||
uint32_t frequency);
|
||||
static int i2s_ioctl(struct i2s_dev_s *dev, int cmd, unsigned long arg);
|
||||
|
||||
#ifdef I2S_HAVE_TX
|
||||
|
@ -385,7 +387,8 @@ static const struct i2s_ops_s g_i2sops =
|
|||
#endif /* I2S_HAVE_RX */
|
||||
|
||||
.i2s_ioctl = i2s_ioctl,
|
||||
.i2s_mclkfrequency = i2s_mclkfrequency,
|
||||
.i2s_getmclkfrequency = i2s_getmclkfrequency,
|
||||
.i2s_setmclkfrequency = i2s_setmclkfrequency,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_ESP32_I2S0
|
||||
|
@ -1654,7 +1657,7 @@ static void i2s_configure(struct esp32_i2s_s *priv)
|
|||
* by the number of bytes from a sample, i.e, for 24 bits, the
|
||||
* multiplier should be divisible by 3. NOTE: the MCLK frequency can
|
||||
* be adjusted on runtime, so this value remains valid only if the
|
||||
* upper half does not implement the `i2s_mclkfrequency` method.
|
||||
* upper half does not implement the `i2s_setmclkfrequency` method.
|
||||
*/
|
||||
|
||||
if (priv->config->data_width == I2S_DATA_BIT_WIDTH_24BIT)
|
||||
|
@ -1666,8 +1669,8 @@ static void i2s_configure(struct esp32_i2s_s *priv)
|
|||
priv->mclk_multiple = I2S_MCLK_MULTIPLE_256;
|
||||
}
|
||||
|
||||
i2s_mclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
|
||||
priv->mclk_multiple));
|
||||
i2s_setmclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
|
||||
priv->mclk_multiple));
|
||||
|
||||
priv->rate = priv->config->rate;
|
||||
i2s_set_clock(priv);
|
||||
|
@ -1774,7 +1777,7 @@ static void i2s_configure(struct esp32_i2s_s *priv)
|
|||
* by the number of bytes from a sample, i.e, for 24 bits, the
|
||||
* multiplier should be divisible by 3. NOTE: the MCLK frequency can
|
||||
* be adjusted on runtime, so this value remains valid only if the
|
||||
* upper half does not implement the `i2s_mclkfrequency` method.
|
||||
* upper half does not implement the `i2s_setmclkfrequency` method.
|
||||
*/
|
||||
|
||||
if (priv->config->data_width == I2S_DATA_BIT_WIDTH_24BIT)
|
||||
|
@ -1786,8 +1789,8 @@ static void i2s_configure(struct esp32_i2s_s *priv)
|
|||
priv->mclk_multiple = I2S_MCLK_MULTIPLE_256;
|
||||
}
|
||||
|
||||
i2s_mclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
|
||||
priv->mclk_multiple));
|
||||
i2s_setmclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
|
||||
priv->mclk_multiple));
|
||||
|
||||
priv->rate = priv->config->rate;
|
||||
i2s_set_clock(priv);
|
||||
|
@ -2305,7 +2308,28 @@ static int i2s_interrupt(int irq, void *context, void *arg)
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: i2s_mclkfrequency
|
||||
* Name: i2s_getmclkfrequency
|
||||
*
|
||||
* Description:
|
||||
* Get the current master clock frequency.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
*
|
||||
* Returned Value:
|
||||
* Returns the current master clock.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static uint32_t i2s_getmclkfrequency(struct i2s_dev_s *dev)
|
||||
{
|
||||
struct esp32_i2s_s *priv = (struct esp32_i2s_s *)dev;
|
||||
|
||||
return priv->mclk_freq;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: i2s_setmclkfrequency
|
||||
*
|
||||
* Description:
|
||||
* 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)
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static uint32_t i2s_mclkfrequency(struct i2s_dev_s *dev, uint32_t frequency)
|
||||
static uint32_t i2s_setmclkfrequency(struct i2s_dev_s *dev,
|
||||
uint32_t frequency)
|
||||
{
|
||||
struct esp32_i2s_s *priv = (struct esp32_i2s_s *)dev;
|
||||
|
||||
|
|
|
@ -323,7 +323,9 @@ static void i2s_rx_schedule(struct esp32s2_i2s_s *priv,
|
|||
|
||||
static uint32_t i2s_set_datawidth(struct esp32s2_i2s_s *priv);
|
||||
static uint32_t i2s_set_clock(struct esp32s2_i2s_s *priv);
|
||||
static uint32_t i2s_mclkfrequency(struct i2s_dev_s *dev, uint32_t frequency);
|
||||
static uint32_t i2s_getmclkfrequency(struct i2s_dev_s *dev);
|
||||
static uint32_t i2s_setmclkfrequency(struct i2s_dev_s *dev,
|
||||
uint32_t frequency);
|
||||
static int i2s_ioctl(struct i2s_dev_s *dev, int cmd, unsigned long arg);
|
||||
|
||||
#ifdef I2S_HAVE_TX
|
||||
|
@ -369,7 +371,8 @@ static const struct i2s_ops_s g_i2sops =
|
|||
#endif /* I2S_HAVE_RX */
|
||||
|
||||
.i2s_ioctl = i2s_ioctl,
|
||||
.i2s_mclkfrequency = i2s_mclkfrequency,
|
||||
.i2s_getmclkfrequency = i2s_getmclkfrequency,
|
||||
.i2s_setmclkfrequency = i2s_setmclkfrequency,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_ESP32S2_I2S
|
||||
|
@ -1455,7 +1458,7 @@ static void i2s_configure(struct esp32s2_i2s_s *priv)
|
|||
* by the number of bytes from a sample, i.e, for 24 bits, the
|
||||
* multiplier should be divisible by 3. NOTE: the MCLK frequency can
|
||||
* be adjusted on runtime, so this value remains valid only if the
|
||||
* upper half does not implement the `i2s_mclkfrequency` method.
|
||||
* upper half does not implement the `i2s_setmclkfrequency` method.
|
||||
*/
|
||||
|
||||
if (priv->config->data_width == I2S_DATA_BIT_WIDTH_24BIT)
|
||||
|
@ -1467,8 +1470,8 @@ static void i2s_configure(struct esp32s2_i2s_s *priv)
|
|||
priv->mclk_multiple = I2S_MCLK_MULTIPLE_256;
|
||||
}
|
||||
|
||||
i2s_mclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
|
||||
priv->mclk_multiple));
|
||||
i2s_setmclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
|
||||
priv->mclk_multiple));
|
||||
|
||||
priv->rate = priv->config->rate;
|
||||
i2s_set_clock(priv);
|
||||
|
@ -1556,7 +1559,7 @@ static void i2s_configure(struct esp32s2_i2s_s *priv)
|
|||
* by the number of bytes from a sample, i.e, for 24 bits, the
|
||||
* multiplier should be divisible by 3. NOTE: the MCLK frequency can
|
||||
* be adjusted on runtime, so this value remains valid only if the
|
||||
* upper half does not implement the `i2s_mclkfrequency` method.
|
||||
* upper half does not implement the `i2s_setmclkfrequency` method.
|
||||
*/
|
||||
|
||||
if (priv->config->data_width == I2S_DATA_BIT_WIDTH_24BIT)
|
||||
|
@ -1568,8 +1571,8 @@ static void i2s_configure(struct esp32s2_i2s_s *priv)
|
|||
priv->mclk_multiple = I2S_MCLK_MULTIPLE_256;
|
||||
}
|
||||
|
||||
i2s_mclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
|
||||
priv->mclk_multiple));
|
||||
i2s_setmclkfrequency((struct i2s_dev_s *)priv, (priv->config->rate *
|
||||
priv->mclk_multiple));
|
||||
|
||||
priv->rate = priv->config->rate;
|
||||
i2s_set_clock(priv);
|
||||
|
@ -2054,7 +2057,28 @@ static int i2s_interrupt(int irq, void *context, void *arg)
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: i2s_mclkfrequency
|
||||
* Name: i2s_getmclkfrequency
|
||||
*
|
||||
* Description:
|
||||
* Get the current master clock frequency.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
*
|
||||
* Returned Value:
|
||||
* Returns the current master clock.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static uint32_t i2s_getmclkfrequency(struct i2s_dev_s *dev)
|
||||
{
|
||||
struct esp32s2_i2s_s *priv = (struct esp32s2_i2s_s *)dev;
|
||||
|
||||
return priv->mclk_freq;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: i2s_setmclkfrequency
|
||||
*
|
||||
* Description:
|
||||
* 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)
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static uint32_t i2s_mclkfrequency(struct i2s_dev_s *dev, uint32_t frequency)
|
||||
static uint32_t i2s_setmclkfrequency(struct i2s_dev_s *dev,
|
||||
uint32_t frequency)
|
||||
{
|
||||
struct esp32s2_i2s_s *priv = (struct esp32s2_i2s_s *)dev;
|
||||
|
||||
|
|
|
@ -278,7 +278,7 @@ static int cs4344_setmclkfrequency(FAR struct cs4344_dev_s *priv)
|
|||
|
||||
if (priv->mclk_freq != 0)
|
||||
{
|
||||
ret = I2S_MCLKFREQUENCY(priv->i2s, priv->mclk_freq);
|
||||
ret = I2S_SETMCLKFREQUENCY(priv->i2s, priv->mclk_freq);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -527,7 +527,7 @@ static void es8388_setmclkfrequency(FAR struct es8388_dev_s *priv)
|
|||
{
|
||||
audinfo("MCLK Freq: %u\n", priv->mclk);
|
||||
|
||||
int ret = I2S_MCLKFREQUENCY(priv->i2s, priv->mclk);
|
||||
int ret = I2S_SETMCLKFREQUENCY(priv->i2s, priv->mclk);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
|
|
|
@ -226,7 +226,27 @@
|
|||
((d)->ops->i2s_send ? (d)->ops->i2s_send(d,b,c,a,t) : -ENOTTY)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: I2S_MCLKFREQUENCY
|
||||
* Name: I2S_GETMCLKFREQUENCY
|
||||
*
|
||||
* Description:
|
||||
* Get the current master clock frequency. NOTE: this parameter may not
|
||||
* be implemented on I2S driver. If not implemented, the I2S may set
|
||||
* internally any value to the master clock (or even does not support it).
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
*
|
||||
* Returned Value:
|
||||
* Returns the current master clock.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define I2S_GETMCLKFREQUENCY(d) \
|
||||
((d)->ops->i2s_getmclkfrequency ? \
|
||||
(d)->ops->i2s_getmclkfrequency(d) : -ENOTTY)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: I2S_SETMCLKFREQUENCY
|
||||
*
|
||||
* Description:
|
||||
* Set the master clock frequency. Usually, the MCLK is a multiple of the
|
||||
|
@ -244,9 +264,9 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define I2S_MCLKFREQUENCY(d,f) \
|
||||
((d)->ops->i2s_mclkfrequency ? \
|
||||
(d)->ops->i2s_mclkfrequency(d,f) : -ENOTTY)
|
||||
#define I2S_SETMCLKFREQUENCY(d,f) \
|
||||
((d)->ops->i2s_setmclkfrequency ? \
|
||||
(d)->ops->i2s_setmclkfrequency(d,f) : -ENOTTY)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: I2S_IOCTL
|
||||
|
@ -311,8 +331,9 @@ struct i2s_ops_s
|
|||
|
||||
/* Master Clock methods */
|
||||
|
||||
CODE uint32_t (*i2s_mclkfrequency)(FAR struct i2s_dev_s *dev,
|
||||
uint32_t frequency);
|
||||
CODE uint32_t (*i2s_getmclkfrequency)(FAR struct i2s_dev_s *dev);
|
||||
CODE uint32_t (*i2s_setmclkfrequency)(FAR struct i2s_dev_s *dev,
|
||||
uint32_t frequency);
|
||||
|
||||
/* Ioctl */
|
||||
|
||||
|
|
Loading…
Reference in a new issue