Skip to main content

EncoderCallback

Trait EncoderCallback 

Source
pub trait EncoderCallback {
    type Item;

    // Required method
    fn encode(
        &mut self,
        input_data: &[Self::Item],
        buffer: &mut SymbolBuffer<'_>,
    ) -> Result<(), NotEnoughSpace>;
}
Expand description

Trait that is implemented by types that can be used as callbacks for the SimpleEncoder.

Required Associated Types§

Source

type Item

The type of input data that the encoder can encode.

Required Methods§

Source

fn encode( &mut self, input_data: &[Self::Item], buffer: &mut SymbolBuffer<'_>, ) -> Result<(), NotEnoughSpace>

This function encodes the provided input data into RMT symbols and writes them into the provided SymbolBuffer.

To do this, a buffer is allocated in which the resulting symbols can be written. It might happen that there is not enough space in the buffer to encode all input data. In this case, the function has two options:

  1. It can immediately return NotEnoughSpace to indicate that the buffer is too small. The function will later be called again with a larger buffer. You should eventually process the data, and not return NotEnoughSpace forever.

  2. It can start encoding the input data, and write symbols into the buffer until it runs out of space. It should return with NotEnoughSpace. The function will later be called again with more space, making it possible to continue encoding the remaining input data.

The function takes a slice of input data of your chosen type EncoderCallback::Item, this is the same data that is passed to the RMT driver when sending data. The slice will not change between unfinished calls.

For example, if you start processing an input_data of 10 elements, and you return with NotEnoughSpace after encoding 4 elements, the next time the function is called, the input_data will still be the same 10 elements.

It is your responsibility to keep track of how many input elements you have already processed. If the number of output symbols are a multiple of the number of input elements, you can use SymbolBuffer::position to track how many input elements have been processed so far: 1 input element = 8 output symbols -> position / 8 = number of input elements processed.

Once you have processed all input elements, you should return with [Ok].

§ISR Safety

This function is called from an ISR context. Care should be taken not to call std, libc or FreeRTOS APIs (except for a few allowed ones).

You are not allowed to block, but you are allowed to call FreeRTOS APIs with the FromISR suffix.

Implementors§