Struct esp_idf_svc::hal::i2s::I2sDriver
source · pub struct I2sDriver<'d, Dir> { /* private fields */ }
Expand description
Inter-IC Sound (I2S) driver.
Implementations§
source§impl<'d> I2sDriver<'d, I2sTx>
impl<'d> I2sDriver<'d, I2sTx>
sourcepub fn new_pdm_tx<I2S>(
_i2s: impl Peripheral<P = I2S> + 'd,
tx_cfg: &PdmTxConfig,
clk: impl Peripheral<P = impl OutputPin> + 'd,
dout: impl Peripheral<P = impl OutputPin> + 'd,
dout2: Option<impl Peripheral<P = impl OutputPin> + 'd>,
) -> Result<I2sDriver<'d, I2sTx>, EspError>where
I2S: I2s,
pub fn new_pdm_tx<I2S>(
_i2s: impl Peripheral<P = I2S> + 'd,
tx_cfg: &PdmTxConfig,
clk: impl Peripheral<P = impl OutputPin> + 'd,
dout: impl Peripheral<P = impl OutputPin> + 'd,
dout2: Option<impl Peripheral<P = impl OutputPin> + 'd>,
) -> Result<I2sDriver<'d, I2sTx>, EspError>where
I2S: I2s,
Create a new pulse density modulation (PDM) mode driver for the given I2S peripheral with only the transmit channel open.
source§impl<'d> I2sDriver<'d, I2sBiDir>
impl<'d> I2sDriver<'d, I2sBiDir>
sourcepub fn new_std_bidir<I2S>(
i2s: impl Peripheral<P = I2S> + 'd,
config: &StdConfig,
bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
din: impl Peripheral<P = impl InputPin> + 'd,
dout: impl Peripheral<P = impl OutputPin> + 'd,
mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>,
ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
) -> Result<I2sDriver<'d, I2sBiDir>, EspError>where
I2S: I2s,
pub fn new_std_bidir<I2S>(
i2s: impl Peripheral<P = I2S> + 'd,
config: &StdConfig,
bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
din: impl Peripheral<P = impl InputPin> + 'd,
dout: impl Peripheral<P = impl OutputPin> + 'd,
mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>,
ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
) -> Result<I2sDriver<'d, I2sBiDir>, EspError>where
I2S: I2s,
Create a new standard mode driver for the given I2S peripheral with both the receive and transmit channels open.
source§impl<'d> I2sDriver<'d, I2sRx>
impl<'d> I2sDriver<'d, I2sRx>
sourcepub fn new_std_rx<I2S>(
i2s: impl Peripheral<P = I2S> + 'd,
config: &StdConfig,
bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
din: impl Peripheral<P = impl InputPin> + 'd,
mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>,
ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
) -> Result<I2sDriver<'d, I2sRx>, EspError>where
I2S: I2s,
pub fn new_std_rx<I2S>(
i2s: impl Peripheral<P = I2S> + 'd,
config: &StdConfig,
bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
din: impl Peripheral<P = impl InputPin> + 'd,
mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>,
ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
) -> Result<I2sDriver<'d, I2sRx>, EspError>where
I2S: I2s,
Create a new standard mode driver for the given I2S peripheral with only the receive channel open.
source§impl<'d> I2sDriver<'d, I2sTx>
impl<'d> I2sDriver<'d, I2sTx>
sourcepub fn new_std_tx<I2S>(
i2s: impl Peripheral<P = I2S> + 'd,
config: &StdConfig,
bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
dout: impl Peripheral<P = impl OutputPin> + 'd,
mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>,
ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
) -> Result<I2sDriver<'d, I2sTx>, EspError>where
I2S: I2s,
pub fn new_std_tx<I2S>(
i2s: impl Peripheral<P = I2S> + 'd,
config: &StdConfig,
bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
dout: impl Peripheral<P = impl OutputPin> + 'd,
mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>,
ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
) -> Result<I2sDriver<'d, I2sTx>, EspError>where
I2S: I2s,
Create a new standard mode driver for the given I2S peripheral with only the transmit channel open.
source§impl<'d> I2sDriver<'d, I2sBiDir>
impl<'d> I2sDriver<'d, I2sBiDir>
sourcepub fn new_tdm_bidir<I2S>(
i2s: impl Peripheral<P = I2S> + 'd,
config: &TdmConfig,
bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
din: impl Peripheral<P = impl InputPin> + 'd,
dout: impl Peripheral<P = impl OutputPin> + 'd,
mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>,
ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
) -> Result<I2sDriver<'d, I2sBiDir>, EspError>where
I2S: I2s,
pub fn new_tdm_bidir<I2S>(
i2s: impl Peripheral<P = I2S> + 'd,
config: &TdmConfig,
bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
din: impl Peripheral<P = impl InputPin> + 'd,
dout: impl Peripheral<P = impl OutputPin> + 'd,
mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>,
ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
) -> Result<I2sDriver<'d, I2sBiDir>, EspError>where
I2S: I2s,
Create a new TDM mode driver for the given I2S peripheral with both the receive and transmit channels open.
source§impl<'d> I2sDriver<'d, I2sRx>
impl<'d> I2sDriver<'d, I2sRx>
sourcepub fn new_tdm_rx<I2S>(
i2s: impl Peripheral<P = I2S> + 'd,
config: &TdmConfig,
bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
din: impl Peripheral<P = impl InputPin> + 'd,
mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>,
ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
) -> Result<I2sDriver<'d, I2sRx>, EspError>where
I2S: I2s,
pub fn new_tdm_rx<I2S>(
i2s: impl Peripheral<P = I2S> + 'd,
config: &TdmConfig,
bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
din: impl Peripheral<P = impl InputPin> + 'd,
mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>,
ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
) -> Result<I2sDriver<'d, I2sRx>, EspError>where
I2S: I2s,
Create a new TDM mode driver for the given I2S peripheral with only the receive channel open.
source§impl<'d> I2sDriver<'d, I2sTx>
impl<'d> I2sDriver<'d, I2sTx>
sourcepub fn new_tdm_tx<I2S>(
i2s: impl Peripheral<P = I2S> + 'd,
config: &TdmConfig,
bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
dout: impl Peripheral<P = impl OutputPin> + 'd,
mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>,
ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
) -> Result<I2sDriver<'d, I2sTx>, EspError>where
I2S: I2s,
pub fn new_tdm_tx<I2S>(
i2s: impl Peripheral<P = I2S> + 'd,
config: &TdmConfig,
bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
dout: impl Peripheral<P = impl OutputPin> + 'd,
mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>,
ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
) -> Result<I2sDriver<'d, I2sTx>, EspError>where
I2S: I2s,
Create a new TDM mode driver for the given I2S peripheral with only the transmit channel open.
source§impl<'d, Dir> I2sDriver<'d, Dir>
impl<'d, Dir> I2sDriver<'d, Dir>
sourcepub fn as_ref(&mut self) -> I2sDriverRef<'_, Dir>
pub fn as_ref(&mut self) -> I2sDriverRef<'_, Dir>
Borrow the I2S driver by a reference
source§impl<'d, Dir> I2sDriver<'d, Dir>where
Dir: I2sRxSupported,
impl<'d, Dir> I2sDriver<'d, Dir>where
Dir: I2sRxSupported,
Functions for receive channels.
sourcepub fn rx_enable(&mut self) -> Result<(), EspError>
pub fn rx_enable(&mut self) -> Result<(), EspError>
Enable the I2S receive channel.
§Note
This can only be called when the channel is in the READY
state: initialized but not yet started from a driver
constructor, or disabled from the RUNNING
state via [rx_enable()
][I2sRxChannel::rx_disable]. The channel
will enter the RUNNING
state if it is enabled successfully.
Enabling the channel will start I2S communications on the hardware. BCLK and WS signals will be generated if this is a controller. MCLK will be generated once initialization is finished.
§Errors
This will return an EspError
with ESP_ERR_INVALID_STATE
if the channel is not in the READY
state.
sourcepub fn rx_disable(&mut self) -> Result<(), EspError>
pub fn rx_disable(&mut self) -> Result<(), EspError>
Disable the I2S receive channel.
§Note
This can only be called when the channel is in the RUNNING
state: the channel has been previously enabled
via a call to [rx_enable()
][I2sRxChannel::rx_enable]. The channel will enter the READY
state if it is
disabled successfully.
Disabling the channel will stop I2S communications on the hardware. BCLK and WS signals will stop being generated if this is a controller. MCLK will continue to be generated.
§Errors
This will return an EspError
with ESP_ERR_INVALID_STATE
if the channel is not in the RUNNING
state.
sourcepub async fn read_async(&mut self, buffer: &mut [u8]) -> Result<usize, EspError>
pub async fn read_async(&mut self, buffer: &mut [u8]) -> Result<usize, EspError>
sourcepub async fn read_uninit_async(
&mut self,
buffer: &mut [MaybeUninit<u8>],
) -> Result<usize, EspError>
pub async fn read_uninit_async( &mut self, buffer: &mut [MaybeUninit<u8>], ) -> Result<usize, EspError>
Read data from the channel into an uninitalized buffer asynchronously.
This may be called only when the channel is in the RUNNING
state.
§Returns
This returns the number of bytes read, or an EspError if an error occurred.
§Safety
Upon a successful return with Ok(n_read)
, buffer[..n_read]
will be initialized.
sourcepub fn read_uninit(
&mut self,
buffer: &mut [MaybeUninit<u8>],
timeout: u32,
) -> Result<usize, EspError>
pub fn read_uninit( &mut self, buffer: &mut [MaybeUninit<u8>], timeout: u32, ) -> Result<usize, EspError>
source§impl<'d, Dir> I2sDriver<'d, Dir>where
Dir: I2sTxSupported,
impl<'d, Dir> I2sDriver<'d, Dir>where
Dir: I2sTxSupported,
Functions for transmit channels.
sourcepub fn tx_enable(&mut self) -> Result<(), EspError>
pub fn tx_enable(&mut self) -> Result<(), EspError>
Enable the I2S transmit channel.
§Note
This can only be called when the channel is in the READY
state: initialized but not yet started from a driver
constructor, or disabled from the RUNNING
state via [tx_disable()
][I2sTxChannel::tx_disable]. The channel
will enter the RUNNING
state if it is enabled successfully.
Enabling the channel will start I2S communications on the hardware. BCLK and WS signals will be generated if this is a controller. MCLK will be generated once initialization is finished.
§Errors
This will return an EspError
with ESP_ERR_INVALID_STATE
if the channel is not in the READY
state.
sourcepub fn tx_disable(&mut self) -> Result<(), EspError>
pub fn tx_disable(&mut self) -> Result<(), EspError>
Disable the I2S transmit channel.
§Note
This can only be called when the channel is in the RUNNING
state: the channel has been previously enabled
via a call to [tx_enable()
][I2sTxChannel::tx_enable]. The channel will enter the READY
state if it is disabled
successfully.
Disabling the channel will stop I2S communications on the hardware. BCLK and WS signals will stop being generated if this is a controller. MCLK will continue to be generated.
§Errors
This will return an EspError
with ESP_ERR_INVALID_STATE
if the channel is not in the RUNNING
state.
sourcepub fn preload_data(&mut self, data: &[u8]) -> Result<usize, EspError>
pub fn preload_data(&mut self, data: &[u8]) -> Result<usize, EspError>
Preload data into the transmit channel DMA buffer.
This may be called only when the channel is in the READY
state: initialized but not yet started.
This is used to preload data into the DMA buffer so that valid data can be transmitted immediately after the
channel is enabled via [tx_enable()
][I2sTxChannel::tx_enable]. If this function is not called before enabling the channel,
empty data will be transmitted.
This function can be called multiple times before enabling the channel. Additional calls will concatenate the data to the end of the buffer until the buffer is full.
§Returns
This returns the number of bytes that have been loaded into the buffer. If this is less than the length of the data provided, the buffer is full and no more data can be loaded.
sourcepub async fn write_async(&mut self, data: &[u8]) -> Result<usize, EspError>
pub async fn write_async(&mut self, data: &[u8]) -> Result<usize, EspError>
Write data to the channel asynchronously.
This may be called only when the channel is in the RUNNING
state.
§Returns
This returns the number of bytes sent. This may be less than the length of the data provided.
sourcepub async fn write_all_async(&mut self, data: &[u8]) -> Result<(), EspError>
pub async fn write_all_async(&mut self, data: &[u8]) -> Result<(), EspError>
Write all data to the channel asynchronously.
This may be called only when the channel is in the RUNNING
state.
source§impl<'d> I2sDriver<'d, I2sBiDir>
impl<'d> I2sDriver<'d, I2sBiDir>
sourcepub fn split(&mut self) -> (I2sDriverRef<'_, I2sRx>, I2sDriverRef<'_, I2sTx>)
pub fn split(&mut self) -> (I2sDriverRef<'_, I2sRx>, I2sDriverRef<'_, I2sTx>)
Split the bidirectional I2S driver into two parts (Rx, Tx)
§Safety
It is safe to use the two parts separately
- esp-idf guarantees thread safety
- esp-idf-hal guarantees asynchronous safety
Trait Implementations§
source§impl<'d, Dir> ErrorType for I2sDriver<'d, Dir>
impl<'d, Dir> ErrorType for I2sDriver<'d, Dir>
§type Error = EspIOError
type Error = EspIOError
source§impl<'d, Dir> Read for I2sDriver<'d, Dir>where
Dir: I2sRxSupported,
impl<'d, Dir> Read for I2sDriver<'d, Dir>where
Dir: I2sRxSupported,
source§fn read(
&mut self,
buf: &mut [u8],
) -> Result<usize, <I2sDriver<'d, Dir> as ErrorType>::Error>
fn read( &mut self, buf: &mut [u8], ) -> Result<usize, <I2sDriver<'d, Dir> as ErrorType>::Error>
source§fn read_exact(
&mut self,
buf: &mut [u8],
) -> Result<(), ReadExactError<Self::Error>>
fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf
. Read moresource§impl<'d, Dir> Read for I2sDriver<'d, Dir>where
Dir: I2sRxSupported,
impl<'d, Dir> Read for I2sDriver<'d, Dir>where
Dir: I2sRxSupported,
source§async fn read(
&mut self,
buf: &mut [u8],
) -> Result<usize, <I2sDriver<'d, Dir> as ErrorType>::Error>
async fn read( &mut self, buf: &mut [u8], ) -> Result<usize, <I2sDriver<'d, Dir> as ErrorType>::Error>
source§async fn read_exact(
&mut self,
buf: &mut [u8],
) -> Result<(), ReadExactError<Self::Error>>
async fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf
. Read more