Skip to main content

Encoder

Trait Encoder 

Source
pub trait Encoder {
    type Item;

    // Required methods
    fn encode(
        &mut self,
        handle: &mut RmtChannelHandle,
        primary_data: &[Self::Item],
    ) -> (usize, EncoderState);
    fn reset(&mut self) -> Result<(), EspError>;
}
Expand description

A trait for implementing custom RMT encoders in rust.

An RMT encoder is part of the RMT TX transaction, whose responsibility is to generate and write the correct RMT symbols into hardware memory or DMA buffer at a specific time.

There are some special restrictions for an encoding function:

  • During a single transaction, the encoding function may be called multiple times. This is necessary because the target RMT memory block cannot hold all the artifacts at once. To overcome this limitation, the driver utilizes a ping-pong approach, where the encoding session is divided into multiple parts. This means that the encoder needs to keep track of its state to continue encoding from where it left off in the previous part.
  • The encoding function is running in the ISR context. To speed up the encoding session, it is highly recommended to put the encoding function into IRAM. This can also avoid the cache miss during encoding.

Required Associated Types§

Source

type Item

The type of input data the encoder can encode.

Required Methods§

Source

fn encode( &mut self, handle: &mut RmtChannelHandle, primary_data: &[Self::Item], ) -> (usize, EncoderState)

Encode the user data into RMT symbols and write into RMT memory.

This function might be called multiple times within a single transaction. The encode function should return the state of the current encoding session.

The supported states are listed in EncoderState. If the result contains EncoderState::EncodingComplete, it means the current encoder has finished work.

If the result contains EncoderState::EncodingMemoryFull, the program needs to yield from the current session, as there is no space to save more encoding artifacts.

§Note

It is recommended to put this function implementation in the IRAM, to achieve a high performance and less interrupt latency.

§ISR Safety

The encoding function will also be called from an ISR context, thus the function must not call any blocking API.

Source

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

Reset encoding state.

§Errors

With ESP_FAIL when it fails to reset the encoder.

Implementors§