pub struct TxChannelDriver<'d> { /* private fields */ }Implementations§
Source§impl<'d> TxChannelDriver<'d>
impl<'d> TxChannelDriver<'d>
Sourcepub fn new(
pin: impl OutputPin + 'd,
config: &TxChannelConfig,
) -> Result<Self, EspError>
pub fn new( pin: impl OutputPin + 'd, config: &TxChannelConfig, ) -> Result<Self, EspError>
Creates a new RMT TX channel.
§Note
When multiple RMT channels are allocated at the same time, the group’s prescale is determined based on the resolution of the first channel. The driver then selects the appropriate prescale from low to high. To avoid prescale conflicts when allocating multiple channels, allocate channels in order of their target resolution, either from highest to lowest or lowest to highest.
§Panics
This function will panic if called from an ISR context.
Sourcepub fn wait_all_done(
&mut self,
timeout: Option<Duration>,
) -> Result<(), EspError>
pub fn wait_all_done( &mut self, timeout: Option<Duration>, ) -> Result<(), EspError>
Wait for all pending TX transactions to finish.
If timeout is None, it will wait indefinitely. If timeout is Some(duration),
it will wait for at most duration.
§Note
This function will block forever if the pending transaction can’t
be finished within a limited time (e.g. an infinite loop transaction).
See also Self::disable for how to terminate a working channel.
If the given timeout converted to milliseconds is larger than i32::MAX,
it will be treated as None (wait indefinitely).
§Errors
ESP_ERR_INVALID_ARG: Flush transactions failed because of invalid argumentESP_FAIL: Flush transactions failed because of other error
§Polling
When polling this function (calling with a timeout duration of 0ms), esp-idf will log flush timeout errors to the console. This issue is tracked in https://github.com/espressif/esp-idf/issues/17527 and should be fixed in future esp-idf versions.
Sourcepub fn subscribe(
&mut self,
callback: impl FnMut(TxDoneEventData) + Send + 'static,
)
pub fn subscribe( &mut self, callback: impl FnMut(TxDoneEventData) + Send + 'static, )
Define the ISR handler for when a transmission is done.
The callback will be called with the number of transmitted symbols, including one EOF symbol, which is appended by the driver to mark the end of the transmission. For a loop transmission, this value only counts for one round.
There is only one callback possible, you can not subscribe multiple callbacks.
§Panics
This function will panic if called from an ISR context or while the channel is enabled.
§ISR Safety
Care should be taken not to call std, libc or FreeRTOS APIs (except for a few allowed ones) in the callback passed to this function, as it is executed in an ISR context.
You are not allowed to block, but you are allowed to call FreeRTOS APIs with the FromISR suffix.
Sourcepub unsafe fn subscribe_nonstatic(
&mut self,
callback: impl FnMut(TxDoneEventData) + Send + 'd,
)
pub unsafe fn subscribe_nonstatic( &mut self, callback: impl FnMut(TxDoneEventData) + Send + 'd, )
Subscribe a non-’static callback for when a transmission is done.
§Safety
You must not forget the channel driver (for example through [mem::forget]),
while the callback is still subscribed, otherwise this would lead to undefined behavior.
Sourcepub fn unsubscribe(&mut self)
pub fn unsubscribe(&mut self)
Remove the ISR handler for when a transmission is done.
§Panics
This function will panic if called from an ISR context or while the channel is enabled.
Sourcepub unsafe fn start_send<E: RawEncoder>(
&mut self,
encoder: &mut E,
signal: &[E::Item],
config: &TransmitConfig,
) -> Result<(), EspError>
pub unsafe fn start_send<E: RawEncoder>( &mut self, encoder: &mut E, signal: &[E::Item], config: &TransmitConfig, ) -> Result<(), EspError>
Starts transmitting the signal using the specified encoder and config.
§Safety
This function is a thin wrapper around the rmt_transmit function, it assumes that
- the encoder (the returned pointer of
RawEncoder::handle) is valid until the transmission is done, if not, it is guaranteed to crash - the signal is valid until the transmission is done
- the encoder and signal are not modified during the transmission
The caller must ensure that the encoder and signal live long enough and are not moved.
Sourcepub fn send_iter<E: Encoder, S: AsRef<[E::Item]>>(
&mut self,
encoders: impl IntoIterator<Item = E>,
iter: impl Iterator<Item = S>,
config: &TransmitConfig,
) -> Result<(), EspError>where
E::Item: Clone,
pub fn send_iter<E: Encoder, S: AsRef<[E::Item]>>(
&mut self,
encoders: impl IntoIterator<Item = E>,
iter: impl Iterator<Item = S>,
config: &TransmitConfig,
) -> Result<(), EspError>where
E::Item: Clone,
Transmits the signals provided by the iterator using the specified encoder and config.
This is a convenience function that will create a TxQueue, push all signals from the iterator
to the queue, and then drop the queue, waiting for all transmissions to finish.
§Non blocking behavior
It is not recommended to use this function with TransmitConfig::queue_non_blocking set to true,
because it will drop the queue if it would block, resulting in it blocking until all pending transmissions
are done.
Therefore, one should use TxChannelDriver::queue for a non-blocking use case.
Sourcepub fn queue<E: Encoder>(
&mut self,
encoders: impl IntoIterator<Item = E>,
) -> TxQueue<'_, 'd, E>
pub fn queue<E: Encoder>( &mut self, encoders: impl IntoIterator<Item = E>, ) -> TxQueue<'_, 'd, E>
Sourcepub async fn wait_for_progress(&self)
pub async fn wait_for_progress(&self)
Asynchronously waits until the next pending transmission has finished.
If there are no pending transmissions, this function will wait indefinitely.
Sourcepub fn queue_size(&self) -> usize
pub fn queue_size(&self) -> usize
Returns the number of currently pending transmissions.
This will be updated when a transmission is started or finished.
Sourcepub fn send_and_wait<E: Encoder>(
&mut self,
encoder: E,
signal: &[E::Item],
config: &TransmitConfig,
) -> Result<(), EspError>where
E::Item: Clone,
pub fn send_and_wait<E: Encoder>(
&mut self,
encoder: E,
signal: &[E::Item],
config: &TransmitConfig,
) -> Result<(), EspError>where
E::Item: Clone,
Transmits the signal and waits for the transmission to finish.
If the channel is not enabled yet, it will be enabled automatically.
§Queue blocking behavior
This function constructs a transaction descriptor then pushes to a queue. The transaction
will not start immediately if there’s another one under processing. Based on the setting
of TransmitConfig::queue_non_blocking, if there’re too many transactions pending in the
queue, this function can block until it has free slot, otherwise just return quickly.
§Errors
ESP_ERR_INVALID_ARG: Transmit failed because of invalid argumentESP_ERR_NOT_SUPPORTED: Some feature is not supported by hardware e.g. unsupported loop countESP_FAIL: Because of other errors
Trait Implementations§
Source§impl<'d> Debug for TxChannelDriver<'d>
impl<'d> Debug for TxChannelDriver<'d>
Source§impl<'d> Drop for TxChannelDriver<'d>
impl<'d> Drop for TxChannelDriver<'d>
Source§impl<'d> RmtChannel for TxChannelDriver<'d>
impl<'d> RmtChannel for TxChannelDriver<'d>
Source§fn handle(&self) -> rmt_channel_handle_t
fn handle(&self) -> rmt_channel_handle_t
rmt_channel_handle_t.