Skip to main content

PeripheralHandle

Trait PeripheralHandle 

Source
pub trait PeripheralHandle: Send {
    // Required methods
    fn read(&mut self, buffer: &mut [u8]) -> Result<usize>;
    fn write(&mut self, buffer: &[u8]) -> Result<usize>;

    // Provided methods
    fn flush(&mut self) -> Result<()> { ... }
    fn control(
        &mut self,
        _command: ControlCommandIdentifier,
        _input: &AnyByLayout,
        _output: &mut AnyByLayout,
    ) -> Result<()> { ... }
}
Expand description

Class-specific handle wrapped by PeripheralDevice.

Every method is a single synchronous attempt. It must return promptly without waiting for hardware, because it runs on the executor. A peripheral that would have to wait returns IoErrorKind::WouldBlock (for example when a UART reports WouldBlock), and the caller decides whether to retry. Callers do not retain buffers past the call.

control forwards command identifiers that the class defined itself. The base never interprets them.

Required Methods§

Source

fn read(&mut self, buffer: &mut [u8]) -> Result<usize>

Read available bytes into buffer. Ok(0) means end of stream.

Source

fn write(&mut self, buffer: &[u8]) -> Result<usize>

Write bytes from buffer and return the number accepted.

Provided Methods§

Source

fn flush(&mut self) -> Result<()>

Push queued output without waiting for the device to drain, if supported.

Source

fn control( &mut self, _command: ControlCommandIdentifier, _input: &AnyByLayout, _output: &mut AnyByLayout, ) -> Result<()>

Class-defined control. The default rejects every command.

Implementors§