diff --git a/src/conversions.rs b/src/conversions.rs new file mode 100644 index 0000000..f6325bc --- /dev/null +++ b/src/conversions.rs @@ -0,0 +1,50 @@ +use core::ops::Add; +use crate::{OutXHigh, OutXLow, OutYHigh, OutYLow, OutZHigh, OutZLow}; + +impl Add for OutXLow { + type Output = i16; + + fn add(self, hi: OutXHigh) -> Self::Output { + (hi.bits() as i16) << 8 | (self.bits() as i16) + } +} + +impl Add for OutXHigh { + type Output = i16; + + fn add(self, lo: OutXLow) -> Self::Output { + lo.add(self) + } +} + +impl Add for OutYLow { + type Output = i16; + + fn add(self, hi: OutYHigh) -> Self::Output { + (hi.bits() as i16) << 8 | (self.bits() as i16) + } +} + +impl Add for OutYHigh { + type Output = i16; + + fn add(self, lo: OutYLow) -> Self::Output { + lo.add(self) + } +} + +impl Add for OutZLow { + type Output = i16; + + fn add(self, hi: OutZHigh) -> Self::Output { + (hi.bits() as i16) << 8 | (self.bits() as i16) + } +} + +impl Add for OutZHigh { + type Output = i16; + + fn add(self, lo: OutZLow) -> Self::Output { + lo.add(self) + } +} \ No newline at end of file diff --git a/src/gyro.rs b/src/gyro.rs index 33ef2d7..1a183bd 100644 --- a/src/gyro.rs +++ b/src/gyro.rs @@ -296,6 +296,7 @@ writable_register!(ReferenceRegister, RegisterAddress::REFERENCE); #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct TemperatureRegister { /// Temperature data (1LSB/deg - 8-bit resolution). The value is expressed as two's complement. + /// Updates at a rate of 1 Hz. #[bits(8, access = RO)] pub temp: u8, } @@ -359,6 +360,8 @@ pub struct OutXLow { /// Low byte of the X-axis value. /// /// Together with [`OutXHigh`] this forms a reading expressed in two's complement. + /// + /// Sensitivity in mdps/digit as well as error depend on [`Sensitivity`] and [`Bandwidth`]. #[bits(8, access = RO)] pub bits: u8, } @@ -382,6 +385,8 @@ pub struct OutXHigh { /// High byte of the X-axis value. /// /// Together with [`OutXLowA`] this forms a reading expressed in two's complement. + /// + /// Sensitivity in mdps/digit as well as error depend on [`Sensitivity`] and [`Bandwidth`]. #[bits(8, access = RO)] pub bits: u8, } @@ -405,6 +410,8 @@ pub struct OutYLow { /// Low byte of the Y-axis angular rate value. /// /// Together with [`OutYHigh`] this forms a reading expressed in two's complement. + /// + /// Sensitivity in mdps/digit as well as error depend on [`Sensitivity`] and [`Bandwidth`]. #[bits(8, access = RO)] pub bits: u8, } @@ -428,6 +435,8 @@ pub struct OutYHigh { /// High byte of the Y-axis angular rate value. /// /// Together with [`OutYLow`] this forms a reading expressed in two's complement. + /// + /// Sensitivity in mdps/digit as well as error depend on [`Sensitivity`] and [`Bandwidth`]. #[bits(8, access = RO)] pub bits: u8, } @@ -451,6 +460,8 @@ pub struct OutZLow { /// Low byte of the Z-axis angular rate value. /// /// Together with [`OutZHigh`] this forms a reading expressed in two's complement. + /// + /// Sensitivity in mdps/digit as well as error depend on [`Sensitivity`] and [`Bandwidth`]. #[bits(8, access = RO)] pub bits: u8, } @@ -473,7 +484,9 @@ readable_register!(OutZLow, RegisterAddress::OUT_Z_L); pub struct OutZHigh { /// High byte of the Z-axis angular rate value. /// - /// Together with [`OutZLowA`] this forms a reading expressed in two's complement. + /// Together with [`OutZLow`] this forms a reading expressed in two's complement. + /// + /// Sensitivity in mdps/digit as well as error depend on [`Sensitivity`] and [`Bandwidth`]. #[bits(8, access = RO)] pub bits: u8, } diff --git a/src/lib.rs b/src/lib.rs index 35aefc7..d719654 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,6 +78,7 @@ macro_rules! writable_register { }; } +mod conversions; mod gyro; mod types; diff --git a/src/types.rs b/src/types.rs index 4832c67..807f18e 100644 --- a/src/types.rs +++ b/src/types.rs @@ -37,25 +37,41 @@ impl OutputDataRate { #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum Bandwidth { + /// Selects the narrowest filter bandwidth. + /// /// * 12.5 at 95 Hz ([`OutputDataRate::Hz95`]) /// * 12.5 at 190 Hz ([`OutputDataRate::Hz190`]) /// * 20 at 380 Hz ([`OutputDataRate::Hz380`]) /// * 30 at 760 Hz ([`OutputDataRate::Hz760`]) + /// + /// Rate noise density: 0.03 ips/√Hz Narrowest = 0b00, + /// Selects a narrow filter bandwidth. + /// /// * 25 at 95 Hz ([`OutputDataRate::Hz95`]) /// * 25 at 190 Hz ([`OutputDataRate::Hz190`]) /// * 25 at 380 Hz ([`OutputDataRate::Hz380`]) /// * 35 at 760 Hz ([`OutputDataRate::Hz760`]) + /// + /// Rate noise density: 0.03 ips/√Hz Narrow = 0b01, + /// Selects a medium filter bandwidth. + /// /// * 25 at 95 Hz ([`OutputDataRate::Hz95`]) /// * 50 at 190 Hz ([`OutputDataRate::Hz190`]) /// * 50 at 380 Hz ([`OutputDataRate::Hz380`]) /// * 50 at 760 Hz ([`OutputDataRate::Hz760`]) + /// + /// Rate noise density: 0.03 ips/√Hz Medium = 0b10, + /// Selects a wide filter bandwidth. + /// /// * 25 at 95 Hz ([`OutputDataRate::Hz95`]) /// * 70 at 190 Hz ([`OutputDataRate::Hz190`]) /// * 100 at 380 Hz ([`OutputDataRate::Hz380`]) /// * 100 at 760 Hz ([`OutputDataRate::Hz760`]) + /// + /// Rate noise density: 0.03 ips/√Hz Wide = 0b11, } @@ -114,13 +130,21 @@ impl HighpassFilterMode { #[repr(u8)] pub enum Sensitivity { /// 250 dps - G250 = 0b00, + /// + /// 8.75 mdps/digit; ±10 dps at zero-rate level + D250 = 0b00, /// 500 dps - G500 = 0b01, + /// + /// 17.50 mdps/digit; ±15 dps at zero-rate level + D500 = 0b01, /// 2000 dps - G2000 = 0b10, + /// + /// 70 mdps/digit; ±75 dps at zero-rate level + D2000 = 0b10, /// 2000 dps - G2000_11 = 0b11, + /// + /// 70 mdps/digit; ±75 dps at zero-rate level + D2000_11 = 0b11, } impl Sensitivity { @@ -131,10 +155,10 @@ impl Sensitivity { pub(crate) const fn from_bits(value: u8) -> Self { match value { - 0b00 => Sensitivity::G250, - 0b01 => Sensitivity::G500, - 0b10 => Sensitivity::G2000, - 0b11 => Sensitivity::G2000_11, + 0b00 => Sensitivity::D250, + 0b01 => Sensitivity::D500, + 0b10 => Sensitivity::D2000, + 0b11 => Sensitivity::D2000_11, _ => unreachable!(), } }