Skip to content

[BUG] I2S operations are not adhered to by lower-half implementations #19309

Description

@linguini1

Description / Steps to reproduce the issue

Some lower-half implementations of the I2S driver do not follow the correct return contract.

For instance, i2s_txsamplerate requires the return value to be the current bitrate. However, some drivers (i.e. rp2040_i2s.c) return 0 on success and a negated errno value on failure. This is not correct, it should be the bitrate on success.

/****************************************************************************
* Name: rp2040_i2s_txsamplerate
*
* Description:
* Set the I2S TX sample rate.
*
* Input Parameters:
* dev - Device-specific state data
* rate - The I2S sample rate in samples (not bits) per second
*
* Returned Value:
* OK on success; a negated errno value on failure.
*
****************************************************************************/
static uint32_t rp2040_i2s_txsamplerate(struct i2s_dev_s *dev, uint32_t rate)
{
struct rp2040_i2s_s *priv = (struct rp2040_i2s_s *)dev;
DEBUGASSERT(priv && priv->samplerate >= 0 && rate > 0);
if (rate < 8000)
{
return -EINVAL;
}
priv->samplerate = rate;
return 0;
}

/****************************************************************************
* Name: I2S_TXSAMPLERATE
*
* Description:
* Set the I2S TX sample rate. NOTE: This will have no effect if (1) the
* driver does not support an I2S transmitter or if (2) the sample rate is
* driven by the I2S frame clock. This may also have unexpected side-
* effects of the TX sample is coupled with the RX sample rate.
*
* Input Parameters:
* dev - Device-specific state data
* rate - The I2S sample rate in samples (not bits) per second
*
* Returned Value:
* Returns the resulting bitrate
*
****************************************************************************/
#define I2S_TXSAMPLERATE(d,r) \
((d)->ops->i2s_txsamplerate ? (d)->ops->i2s_txsamplerate(d,r) : -ENOTTY)

On which OS does this issue occur?

[OS: Linux]

What is the version of your OS?

Arch Linux

NuttX Version

master

Issue Architecture

[Arch: all]

Issue Area

[Area: Drivers]

Host information

No response

Verification

  • I have verified before submitting the report.

Metadata

Metadata

Labels

Arch: allIssues that apply to all architecturesArea: DriversDrivers issuesOS: LinuxIssues related to Linux (building system, etc)Type: BugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions