eldruin / lsm303agr-rs

Platform agnostic Rust driver for the LSM303AGR ultra-compact high-performance eCompass module: ultra-low-power 3D accelerometer and 3D magnetometer
Apache License 2.0
18 stars 14 forks source link

Add register types for temperature and temperature status. #19

Closed reitermarkus closed 2 years ago

reitermarkus commented 2 years ago

This add the register! macro and RegRead and RegWrite traits from https://github.com/eldruin/lsm303agr-rs/pull/17 as well as implements these traits for the StatusRegAuxA register and the Temperature type.

reitermarkus commented 2 years ago

The improvement is not obvious in this PR since this only includes the traits but not any other changes using them.

With the other changes, the traits will allow reading registers like this:

pub fn temperature(&mut self) -> Result<Temperature, Error<CommE, PinE>> {
    self.iface.read_accel_double_register::<Temperature>()
}

or writing configuration like this:

fn acc_enable_bdu(&mut self) -> Result<(), Error<CommE, PinE>> {
     let reg4 = self.ctrl_reg4_a | CtrlReg4A::BDU;
     self.iface.write_accel_register(reg4)?;
     self.ctrl_reg4_a = reg4;

     Ok(())
}