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§
Required Methods§
Sourcefn ce_disable(&mut self)
fn ce_disable(&mut self)
Set CE pin low
Sourceasync fn send_command<C: Command>(
&mut self,
command: &C,
) -> Result<(Status, C::Response), Self::Error>
async fn send_command<C: Command>( &mut self, command: &C, ) -> Result<(Status, C::Response), Self::Error>
Send a command via SPI
Sourceasync fn write_register<R: Register>(
&mut self,
register: R,
) -> Result<Status, Self::Error>
async fn write_register<R: Register>( &mut self, register: R, ) -> Result<Status, Self::Error>
Send W_REGISTER
command
Sourceasync fn read_register<R: Register>(
&mut self,
) -> Result<(Status, R), Self::Error>
async fn read_register<R: Register>( &mut self, ) -> Result<(Status, R), Self::Error>
Send R_REGISTER
command
Sourceasync fn update_config<F, R>(&mut self, f: F) -> Result<R, Self::Error>where
F: FnOnce(&mut Config) -> R,
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§
Sourcefn with_ce_disabled<F, R>(&mut self, f: F) -> Rwhere
F: FnOnce(&mut Self) -> R,
fn with_ce_disabled<F, R>(&mut self, f: F) -> Rwhere
F: FnOnce(&mut Self) -> R,
Helper; the receiving during RX and sending during TX require CE
to be low.
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.