Skip to main content

TxChannelDriver

Struct TxChannelDriver 

Source
pub struct TxChannelDriver<'d> { /* private fields */ }

Implementations§

Source§

impl<'d> TxChannelDriver<'d>

Source

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.

Source

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 argument
  • ESP_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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn queue<E: Encoder>( &mut self, encoders: impl IntoIterator<Item = E>, ) -> TxQueue<'_, 'd, E>

Creates a new queue for transmitting multiple signals with the given encoders.

For more information, see TxQueue.

§Panics

If no encoders are provided.

Source

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.

Source

pub fn queue_size(&self) -> usize

Returns the number of currently pending transmissions.

This will be updated when a transmission is started or finished.

Source

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 argument
  • ESP_ERR_NOT_SUPPORTED: Some feature is not supported by hardware e.g. unsupported loop count
  • ESP_FAIL: Because of other errors

Trait Implementations§

Source§

impl<'d> Debug for TxChannelDriver<'d>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'d> Drop for TxChannelDriver<'d>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'d> RmtChannel for TxChannelDriver<'d>

Source§

fn handle(&self) -> rmt_channel_handle_t

Returns the underlying rmt_channel_handle_t.
Source§

fn is_enabled(&self) -> bool

Returns whether the channel is currently enabled.
Source§

fn enable(&mut self) -> Result<(), EspError>

Must be called in advance before transmitting or receiving RMT symbols. For TX channels, enabling a channel enables a specific interrupt and prepares the hardware to dispatch transactions. Read more
Source§

fn disable(&mut self) -> Result<(), EspError>

Disables the interrupt and clearing any pending interrupts. The transmitter and receiver are disabled as well. Read more
Source§

fn apply_carrier( &mut self, carrier_config: Option<&CarrierConfig>, ) -> Result<(), EspError>

Apply (de)modulation feature for the channel. Read more
Source§

impl<'d> Send for TxChannelDriver<'d>

Source§

impl<'d> Sync for TxChannelDriver<'d>

Auto Trait Implementations§

§

impl<'d> Freeze for TxChannelDriver<'d>

§

impl<'d> !RefUnwindSafe for TxChannelDriver<'d>

§

impl<'d> Unpin for TxChannelDriver<'d>

§

impl<'d> UnsafeUnpin for TxChannelDriver<'d>

§

impl<'d> !UnwindSafe for TxChannelDriver<'d>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.