Trait Device

Source
pub trait Device {
    type Error;

    // Required methods
    fn ce_enable(&mut self);
    fn ce_disable(&mut self);
    async fn send_command<C: Command>(
        &mut self,
        command: &C,
    ) -> Result<(Status, C::Response), Self::Error>;
    async fn write_register<R: Register>(
        &mut self,
        register: R,
    ) -> Result<Status, Self::Error>;
    async fn read_register<R: Register>(
        &mut self,
    ) -> Result<(Status, R), Self::Error>;
    async fn update_config<F, R>(&mut self, f: F) -> Result<R, Self::Error>
       where F: FnOnce(&mut Config) -> R;

    // Provided methods
    fn with_ce_disabled<F, R>(&mut self, f: F) -> R
       where F: FnOnce(&mut Self) -> R { ... }
    async fn update_register<Reg, F, R>(
        &mut self,
        f: F,
    ) -> Result<R, Self::Error>
       where Reg: Register + PartialEq + Clone,
             F: FnOnce(&mut Reg) -> R { ... }
}
Expand description

Trait that hides all the GPIO/SPI type parameters for use by the operation modes

Required Associated Types§

Source

type Error

Error from the SPI implementation

Required Methods§

Source

fn ce_enable(&mut self)

Set CE pin high

Source

fn ce_disable(&mut self)

Set CE pin low

Source

async fn send_command<C: Command>( &mut self, command: &C, ) -> Result<(Status, C::Response), Self::Error>

Send a command via SPI

Source

async fn write_register<R: Register>( &mut self, register: R, ) -> Result<Status, Self::Error>

Send W_REGISTER command

Source

async fn read_register<R: Register>( &mut self, ) -> Result<(Status, R), Self::Error>

Send R_REGISTER command

Source

async fn update_config<F, R>(&mut self, f: F) -> Result<R, Self::Error>
where F: FnOnce(&mut Config) -> R,

Modify the (cached) CONFIG register and write if it has changed.

Provided Methods§

Source

fn with_ce_disabled<F, R>(&mut self, f: F) -> R
where F: FnOnce(&mut Self) -> R,

Helper; the receiving during RX and sending during TX require CE to be low.

Source

async fn update_register<Reg, F, R>(&mut self, f: F) -> Result<R, Self::Error>
where Reg: Register + PartialEq + Clone, F: FnOnce(&mut Reg) -> R,

Read, and modify a register, and write it back if it has been changed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<E: Debug, CE: OutputPin<Error = E>, SPI: SpiDevice<u8, Error = SPIE>, SPIE: Debug> Device for NRF24L01<E, CE, SPI>

Source§

type Error = Error<SPIE>