### bandwidth Source: https://docs.rs/l3gd20/latest/l3gd20/struct.L3gd20.html Gets the current bandwidth setting. ```APIDOC ## bandwidth ### Description Get current Bandwidth. ### Method bandwidth ### Signature pub fn bandwidth(&mut self) -> Result ### Returns Result - The current bandwidth as a Bandwidth enum. ``` -------------------------------- ### scale Source: https://docs.rs/l3gd20/latest/l3gd20/struct.L3gd20.html Gets the current full scale selection (sensitivity). ```APIDOC ## scale ### Description Get the current Full Scale Selection. This is the sensitivity of the sensor, see `Scale` for more information. ### Method scale ### Signature pub fn scale(&mut self) -> Result ### Returns Result - The current scale as a Scale enum. ``` -------------------------------- ### scale() -> Result Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Gets the current full scale selection (sensitivity) from the control register. ```APIDOC ## scale() -> Result ### Description Gets the current full scale selection (sensitivity) from the control register. ### Method Method ### Parameters None ### Returns - **Result** - The current scale setting. ### Example ```rust let scale = l3gd20.scale()?; ``` ``` -------------------------------- ### odr Source: https://docs.rs/l3gd20/latest/l3gd20/struct.L3gd20.html Gets the current Output Data Rate. ```APIDOC ## odr ### Description Get the current Output Data Rate. ### Method odr ### Signature pub fn odr(&mut self) -> Result ### Returns Result - The current output data rate as an Odr enum. ``` -------------------------------- ### bandwidth() -> Result Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Gets the current bandwidth (low-pass cut-off frequency) from the control register. ```APIDOC ## bandwidth() -> Result ### Description Gets the current bandwidth (low-pass cut-off frequency) from the control register. ### Method Method ### Parameters None ### Returns - **Result** - The current bandwidth setting. ### Example ```rust let bw = l3gd20.bandwidth()?; ``` ``` -------------------------------- ### odr() -> Result Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Gets the current Output Data Rate (ODR) from the control register. ```APIDOC ## odr() -> Result ### Description Gets the current Output Data Rate (ODR) from the control register. ### Method Method ### Parameters None ### Returns - **Result** - The current ODR setting. ### Example ```rust let odr = l3gd20.odr()?; ``` ``` -------------------------------- ### new Source: https://docs.rs/l3gd20/latest/l3gd20/struct.L3gd20.html Creates a new L3gd20 driver instance from an SPI peripheral and a chip select pin. ```APIDOC ## new ### Description Creates a new driver from a SPI peripheral and a NCS pin. ### Method new ### Signature pub fn new(spi: SPI, cs: CS) -> Result ### Parameters - **spi** (SPI) - Required - SPI peripheral implementing Transfer and Write. - **cs** (CS) - Required - Chip select pin implementing OutputPin. ### Returns Result - A new L3gd20 instance or an error. ``` -------------------------------- ### new(spi, cs) -> Result Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Creates a new L3GD20 driver instance from an SPI peripheral and a chip-select pin. Powers up the sensor and enables all axes. ```APIDOC ## new(spi, cs) -> Result ### Description Creates a new L3GD20 driver from a SPI peripheral and a NCS pin. Powers up the sensor and enables all axes. ### Method Constructor ### Parameters - **spi** (SPI) - Required - SPI peripheral implementing `Transfer` and `Write` traits. - **cs** (CS) - Required - Chip-select pin implementing `OutputPin`. ### Returns - **Result** - The new driver instance or an error. ### Example ```rust let l3gd20 = L3gd20::new(spi, cs)?; ``` ``` -------------------------------- ### all Source: https://docs.rs/l3gd20/latest/l3gd20/struct.L3gd20.html Performs temperature and gyroscope measurements in one call. ```APIDOC ## all ### Description Temperature measurement + gyroscope measurements. ### Method all ### Signature pub fn all(&mut self) -> Result ### Returns Result - A Measurements struct containing both temperature and gyroscope data. ``` -------------------------------- ### Change Configuration Helper Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Updates specific bits within a register without affecting other bits, enabling a builder-like configuration pattern. ```rust fn change_config(&mut self, reg: Register, bits: B) -> Result<&mut Self, E> { // Create bit mask from width and shift of value let mask = B::mask() << B::shift(); // Extract the value as u8 let bits = (bits.value() << B::shift()) & mask; // Read current value of register let current = self.read_register(reg)?; // Use supplied mask so we don't affect more than necessary let masked = current & !mask; // Use `or` to apply the new value without affecting other parts let new_reg = masked | bits; self.write_register(reg, new_reg)?; Ok(self) } ``` -------------------------------- ### who_am_i() -> Result Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Reads the WHO_AM_I register to verify the device identity. Should return 0xD4. ```APIDOC ## who_am_i() -> Result ### Description Reads the WHO_AM_I register to verify the device identity. Should return 0xD4. ### Method Method ### Parameters None ### Returns - **Result** - The device ID (expected 0xD4). ### Example ```rust let id = l3gd20.who_am_i()?; ``` ``` -------------------------------- ### Define Data Structures Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Structures for XYZ measurements, sensor readings, and status flags. ```rust /// XYZ triple #[derive(Debug)] pub struct I16x3 { /// X component pub x: i16, /// Y component pub y: i16, /// Z component pub z: i16, } /// Several measurements #[derive(Debug)] pub struct Measurements { /// Gyroscope measurements pub gyro: I16x3, /// Temperature sensor measurement pub temp: i8, } /// Sensor status #[derive(Debug, Clone, Copy)] pub struct Status { /// Overrun (data has overwritten previously unread data) /// has occurred on at least one axis pub overrun: bool, /// Overrun occurred on Z-axis pub z_overrun: bool, /// Overrun occurred on Y-axis pub y_overrun: bool, /// Overrun occurred on X-axis pub x_overrun: bool, /// New data is available for either X, Y, Z - axis pub new_data: bool, /// New data is available on Z-axis pub z_new: bool, /// New data is available on Y-axis pub y_new: bool, /// New data is available on X-axis pub x_new: bool, } ``` -------------------------------- ### Implement Register Address Helper Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Helper to retrieve the address of a register. ```rust impl Register { fn addr(self) -> u8 { self as u8 } } ``` -------------------------------- ### Full Scale Selection Implementation Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Defines the Scale enum and its BitValue implementation for sensor configuration. ```rust pub enum Scale { /// 250 Degrees Per Second Dps250 = 0x00, /// 500 Degrees Per Second Dps500 = 0x01, /// 2000 Degrees Per Second Dps2000 = 0x03, } impl BitValue for Scale { fn width() -> u8 { 2 } fn shift() -> u8 { 4 } fn value(&self) -> u8 { *self as u8 } } impl Scale { fn from_u8(from: u8) -> Self { // Extract scale value from register, ensure that we mask with // `0b0000_0011` to extract `FS1-FS2` part of register match (from >> Scale::shift()) & Scale::mask() { x if x == Scale::Dps250 as u8 => Scale::Dps250, x if x == Scale::Dps500 as u8 => Scale::Dps500, x if x == Scale::Dps2000 as u8 => Scale::Dps2000, // Special case for Dps2000 0x02 => Scale::Dps2000, _ => unreachable!(), } } } ``` -------------------------------- ### who_am_i Source: https://docs.rs/l3gd20/latest/l3gd20/struct.L3gd20.html Reads the WHO_AM_I register to verify the device identity. ```APIDOC ## who_am_i ### Description Reads the WHO_AM_I register; should return `0xD4`. ### Method who_am_i ### Signature pub fn who_am_i(&mut self) -> Result ### Returns Result - The value of the WHO_AM_I register, expected to be 0xD4. ``` -------------------------------- ### Convert Scale Measurements Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Methods to convert raw i16 measurements into degrees or radians based on the selected scale. ```rust impl Scale { /// Convert a measurement to degrees pub fn degrees(&self, val: i16) -> f32 { match *self { Scale::Dps250 => val as f32 * 0.00875, Scale::Dps500 => val as f32 * 0.0175, Scale::Dps2000 => val as f32 * 0.07, } } /// Convert a measurement to radians pub fn radians(&self, val: i16) -> f32 { // TODO: Use `to_radians` or other built in method // NOTE: `to_radians` is only exported in `std` (07.02.18) self.degrees(val) * (core::f32::consts::PI / 180.0) } } ``` -------------------------------- ### Define Bandwidth Enum Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Defines the bandwidth configuration options for the L3GD20 sensor. ```rust #[derive(Debug, Clone, Copy)] pub enum Bandwidth { /// Lowest possible cut-off for any `Odr` configuration Low = 0x00, /// Medium cut-off, can be the same as `High` for some `Odr` configurations Medium = 0x01, /// High cut-off High = 0x02, /// Maximum cut-off for any `Odr` configuration Maximum = 0x03, } ``` -------------------------------- ### Implement BitValue for Bandwidth Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Provides bit manipulation helpers for the Bandwidth enum. ```rust impl BitValue for Bandwidth { fn width() -> u8 { 2 } fn shift() -> u8 { 4 } fn value(&self) -> u8 { *self as u8 } } ``` -------------------------------- ### L3GD20 Driver Implementation Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html The core driver structure and implementation for the L3GD20 gyroscope, utilizing embedded-hal traits for SPI communication and GPIO pin control. ```rust //! A platform agnostic driver to interface with the L3GD20 (gyroscope) //! //! This driver was built using [`embedded-hal`] traits. //! //! [`embedded-hal`]: https://docs.rs/embedded-hal/0.2 //! //! # Examples //! //! You should find at least one example in the [f3] crate. //! //! [f3]: https://docs.rs/f3/0.6 #![deny(missing_docs)] #![deny(warnings)] #![no_std] use embedded_hal::blocking::spi::{Transfer, Write}; use embedded_hal::digital::v2::OutputPin; use embedded_hal::spi::{Mode}; /// SPI mode pub const MODE: Mode = embedded_hal::spi::MODE_3; /// L3GD20 driver pub struct L3gd20 { spi: SPI, cs: CS, } impl L3gd20 where SPI: Transfer + Write, CS: OutputPin, { /// Creates a new driver from a SPI peripheral and a NCS pin pub fn new(spi: SPI, cs: CS) -> Result { let mut l3gd20 = L3gd20 { spi, cs }; // power up and enable all the axes l3gd20.write_register(Register::CTRL_REG1, 0b00_00_1_111)?; Ok(l3gd20) } /// Temperature measurement + gyroscope measurements pub fn all(&mut self) -> Result { let mut bytes = [0u8; 9]; self.read_many(Register::OUT_TEMP, &mut bytes)?; Ok(Measurements { gyro: I16x3 { x: (bytes[3] as u16 + ((bytes[4] as u16) << 8)) as i16, y: (bytes[5] as u16 + ((bytes[6] as u16) << 8)) as i16, z: (bytes[7] as u16 + ((bytes[8] as u16) << 8)) as i16, }, temp: bytes[1] as i8, }) } /// Gyroscope measurements pub fn gyro(&mut self) -> Result { let mut bytes = [0u8; 7]; self.read_many(Register::OUT_X_L, &mut bytes)?; Ok(I16x3 { x: (bytes[1] as u16 + ((bytes[2] as u16) << 8)) as i16, y: (bytes[3] as u16 + ((bytes[4] as u16) << 8)) as i16, z: (bytes[5] as u16 + ((bytes[6] as u16) << 8)) as i16, }) } /// Temperature sensor measurement pub fn temp(&mut self) -> Result { Ok(self.read_register(Register::OUT_TEMP)? as i8) } /// Reads the WHO_AM_I register; should return `0xD4` pub fn who_am_i(&mut self) -> Result { self.read_register(Register::WHO_AM_I) } /// Read `STATUS_REG` of sensor pub fn status(&mut self) -> Result { let sts = self.read_register(Register::STATUS_REG)?; Ok(Status::from_u8(sts)) } /// Get the current Output Data Rate pub fn odr(&mut self) -> Result { // Read control register let reg1 = self.read_register(Register::CTRL_REG1)?; Ok(Odr::from_u8(reg1)) } /// Set the Output Data Rate pub fn set_odr(&mut self, odr: Odr) -> Result<&mut Self, E> { self.change_config(Register::CTRL_REG1, odr) } /// Get current Bandwidth pub fn bandwidth(&mut self) -> Result { let reg1 = self.read_register(Register::CTRL_REG1)?; Ok(Bandwidth::from_u8(reg1)) } /// Set low-pass cut-off frequency (i.e. bandwidth) /// /// See `Bandwidth` for further explanation pub fn set_bandwidth(&mut self, bw: Bandwidth) -> Result<&mut Self, E> { self.change_config(Register::CTRL_REG1, bw) } /// Get the current Full Scale Selection /// /// This is the sensitivity of the sensor, see `Scale` for more information pub fn scale(&mut self) -> Result { let scl = self.read_register(Register::CTRL_REG4)?; Ok(Scale::from_u8(scl)) } /// Set the Full Scale Selection /// /// This sets the sensitivity of the sensor, see `Scale` for more /// information pub fn set_scale(&mut self, scale: Scale) -> Result<&mut Self, E> { self.change_config(Register::CTRL_REG4, scale) } fn read_register(&mut self, reg: Register) -> Result { let _ = self.cs.set_low(); let mut buffer = [reg.addr() | SINGLE | READ, 0]; self.spi.transfer(&mut buffer)?; let _ = self.cs.set_high(); Ok(buffer[1]) } /// Read multiple bytes starting from the `start_reg` register. /// This function will attempt to fill the provided buffer. fn read_many(&mut self, start_reg: Register, buffer: &mut [u8]) -> Result<(), E> { let _ = self.cs.set_low(); ``` -------------------------------- ### temp Source: https://docs.rs/l3gd20/latest/l3gd20/struct.L3gd20.html Reads the temperature sensor measurement. ```APIDOC ## temp ### Description Temperature sensor measurement. ### Method temp ### Signature pub fn temp(&mut self) -> Result ### Returns Result - The temperature reading as an 8-bit signed integer. ``` -------------------------------- ### all() -> Result Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Reads temperature and gyroscope measurements in a single operation. Returns a `Measurements` struct containing gyro axes and temperature. ```APIDOC ## all() -> Result ### Description Reads temperature and gyroscope measurements in a single operation. Returns a `Measurements` struct containing gyro axes and temperature. ### Method Method ### Parameters None ### Returns - **Result** - A `Measurements` struct with `gyro` (I16x3) and `temp` (i8) fields. ### Example ```rust let measurements = l3gd20.all()?; ``` ``` -------------------------------- ### Define Register Constants Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Constants for SPI communication flags. ```rust const READ: u8 = 1 << 7; const WRITE: u8 = 0 << 7; const MULTI: u8 = 1 << 6; const SINGLE: u8 = 0 << 6; ``` -------------------------------- ### status() -> Result Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Reads the STATUS_REG register and returns a `Status` struct representing the sensor status. ```APIDOC ## status() -> Result ### Description Reads the STATUS_REG register and returns a `Status` struct representing the sensor status. ### Method Method ### Parameters None ### Returns - **Result** - A `Status` struct parsed from the register. ### Example ```rust let status = l3gd20.status()?; ``` ``` -------------------------------- ### set_bandwidth(bw: Bandwidth) -> Result<&mut Self, E> Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Sets the low-pass cut-off frequency (bandwidth) of the sensor. Returns a mutable reference to the driver for chaining. ```APIDOC ## set_bandwidth(bw: Bandwidth) -> Result<&mut Self, E> ### Description Sets the low-pass cut-off frequency (bandwidth) of the sensor. Returns a mutable reference to the driver for chaining. ### Method Method ### Parameters - **bw** (Bandwidth) - Required - The desired bandwidth setting. ### Returns - **Result<&mut Self, E>** - A mutable reference to the driver for chaining. ### Example ```rust l3gd20.set_bandwidth(Bandwidth::Hz50)?; ``` ``` -------------------------------- ### temp() -> Result Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Reads the temperature sensor measurement. Returns the temperature as an i8 value. ```APIDOC ## temp() -> Result ### Description Reads the temperature sensor measurement. Returns the temperature as an i8 value. ### Method Method ### Parameters None ### Returns - **Result** - The temperature value. ### Example ```rust let temp = l3gd20.temp()?; ``` ``` -------------------------------- ### Convert u8 to Bandwidth Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Parses a raw u8 register value into a Bandwidth enum variant. ```rust impl Bandwidth { fn from_u8(from: u8) -> Self { // Shift and mask bandwidth of register, (ROI: 0b0011_0000) match (from >> Bandwidth::shift()) & Bandwidth::mask() { x if x == Bandwidth::Low as u8 => Bandwidth::Low, x if x == Bandwidth::Medium as u8 => Bandwidth::Medium, x if x == Bandwidth::High as u8 => Bandwidth::High, x if x == Bandwidth::Maximum as u8 => Bandwidth::Maximum, _ => unreachable!(), } } } ``` -------------------------------- ### Register Enum Definition Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Enumerates the available registers on the L3GD20 sensor. ```rust enum Register { WHO_AM_I = 0x0F, CTRL_REG1 = 0x20, CTRL_REG2 = 0x21, CTRL_REG3 = 0x22, CTRL_REG4 = 0x23, CTRL_REG5 = 0x24, REFERENCE = 0x25, OUT_TEMP = 0x26, STATUS_REG = 0x27, OUT_X_L = 0x28, OUT_X_H = 0x29, OUT_Y_L = 0x2A, OUT_Y_H = 0x2B, OUT_Z_L = 0x2C, OUT_Z_H = 0x2D, FIFO_CTRL_REG = 0x2E, FIFO_SRC_REG = 0x2F, INT1_CFG = 0x30, INT1_SRC = 0x31, INT1_TSH_XH = 0x32, INT1_TSH_XL = 0x33, INT1_TSH_YH = 0x34, INT1_TSH_YL = 0x35, INT1_TSH_ZH = 0x36, INT1_TSH_ZL = 0x37, INT1_DURATION = 0x38, } ``` -------------------------------- ### set_bandwidth Source: https://docs.rs/l3gd20/latest/l3gd20/struct.L3gd20.html Sets the low-pass cut-off frequency (bandwidth) of the sensor. ```APIDOC ## set_bandwidth ### Description Set low-pass cut-off frequency (i.e. bandwidth). See `Bandwidth` for further explanation. ### Method set_bandwidth ### Signature pub fn set_bandwidth(&mut self, bw: Bandwidth) -> Result<&mut Self, E> ### Parameters - **bw** (Bandwidth) - Required - The desired bandwidth setting. ### Returns Result<&mut Self, E> - A mutable reference to the driver for chaining, or an error. ``` -------------------------------- ### set_scale(scale: Scale) -> Result<&mut Self, E> Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Sets the full scale selection (sensitivity) of the sensor. Returns a mutable reference to the driver for chaining. ```APIDOC ## set_scale(scale: Scale) -> Result<&mut Self, E> ### Description Sets the full scale selection (sensitivity) of the sensor. Returns a mutable reference to the driver for chaining. ### Method Method ### Parameters - **scale** (Scale) - Required - The desired scale setting. ### Returns - **Result<&mut Self, E>** - A mutable reference to the driver for chaining. ### Example ```rust l3gd20.set_scale(Scale::Dps250)?; ``` ``` -------------------------------- ### set_scale Source: https://docs.rs/l3gd20/latest/l3gd20/struct.L3gd20.html Sets the full scale selection (sensitivity) of the sensor. ```APIDOC ## set_scale ### Description Set the Full Scale Selection. This sets the sensitivity of the sensor, see `Scale` for more information. ### Method set_scale ### Signature pub fn set_scale(&mut self, scale: Scale) -> Result<&mut Self, E> ### Parameters - **scale** (Scale) - Required - The desired full scale setting. ### Returns Result<&mut Self, E> - A mutable reference to the driver for chaining, or an error. ``` -------------------------------- ### Output Data Rate (ODR) Implementation Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Defines the ODR enum and its BitValue implementation for sensor configuration. ```rust pub enum Odr { /// 95 Hz data rate Hz95 = 0x00, /// 190 Hz data rate Hz190 = 0x01, /// 380 Hz data rate Hz380 = 0x02, /// 760 Hz data rate Hz760 = 0x03, } impl BitValue for Odr { fn width() -> u8 { 2 } fn shift() -> u8 { 6 } fn value(&self) -> u8 { *self as u8 } } impl Odr { fn from_u8(from: u8) -> Self { // Extract ODR value, converting to enum (ROI: 0b1100_0000) match (from >> Odr::shift()) & Odr::mask() { x if x == Odr::Hz95 as u8 => Odr::Hz95, x if x == Odr::Hz190 as u8 => Odr::Hz190, x if x == Odr::Hz380 as u8 => Odr::Hz380, x if x == Odr::Hz760 as u8 => Odr::Hz760, _ => unreachable!(), } } } ``` -------------------------------- ### Bandwidth Enum Definition Source: https://docs.rs/l3gd20/latest/l3gd20/enum.Bandwidth.html The Bandwidth enum with its variants and their meanings. ```APIDOC ## Enum Bandwidth ### Description The `Bandwidth` enum represents the bandwidth of the sensor, which is equal to the cut-off for the low-pass filter. The cut-off depends on the `Odr` of the sensor; consult the data sheet for specific information. ### Variants - **Low = 0** - Lowest possible cut-off for any `Odr` configuration. - **Medium = 1** - Medium cut-off, can be the same as `High` for some `Odr` configurations. - **High = 2** - High cut-off. - **Maximum = 3** - Maximum cut-off for any `Odr` configuration. ### Trait Implementations - `Clone` - `Copy` - `Debug` ### Example ```rust pub enum Bandwidth { Low = 0, Medium = 1, High = 2, Maximum = 3, } ``` ``` -------------------------------- ### set_odr Source: https://docs.rs/l3gd20/latest/l3gd20/struct.L3gd20.html Sets the Output Data Rate of the sensor. ```APIDOC ## set_odr ### Description Set the Output Data Rate. ### Method set_odr ### Signature pub fn set_odr(&mut self, odr: Odr) -> Result<&mut Self, E> ### Parameters - **odr** (Odr) - Required - The desired output data rate. ### Returns Result<&mut Self, E> - A mutable reference to the driver for chaining, or an error. ``` -------------------------------- ### status Source: https://docs.rs/l3gd20/latest/l3gd20/struct.L3gd20.html Reads the STATUS_REG register of the sensor. ```APIDOC ## status ### Description Read `STATUS_REG` of sensor. ### Method status ### Signature pub fn status(&mut self) -> Result ### Returns Result - The status register value as a Status type. ``` -------------------------------- ### gyro Source: https://docs.rs/l3gd20/latest/l3gd20/struct.L3gd20.html Reads gyroscope measurements from the sensor. ```APIDOC ## gyro ### Description Gyroscope measurements. ### Method gyro ### Signature pub fn gyro(&mut self) -> Result ### Returns Result - A vector of three 16-bit signed integers representing the gyroscope readings. ``` -------------------------------- ### Register Write Operation Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Writes a single byte to a specific register using SPI, managing the chip select pin state. ```rust fn write_register(&mut self, reg: Register, byte: u8) -> Result<(), E> { let _ = self.cs.set_low(); let buffer = [reg.addr() | SINGLE | WRITE, byte]; self.spi.write(&buffer)?; let _ = self.cs.set_high(); Ok(()) } ``` -------------------------------- ### Parse Status from u8 Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Parses a raw u8 value into a Status struct. ```rust impl Status { fn from_u8(from: u8) -> Self { Status { overrun: (from & 1 << 7) != 0, z_overrun: (from & 1 << 6) != 0, y_overrun: (from & 1 << 5) != 0, x_overrun: (from & 1 << 4) != 0, new_data: (from & 1 << 3) != 0, z_new: (from & 1 << 2) != 0, y_new: (from & 1 << 1) != 0, x_new: (from & 1 << 0) != 0, } } } ``` -------------------------------- ### gyro() -> Result Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Reads gyroscope measurements for all three axes. Returns an `I16x3` struct with x, y, and z values. ```APIDOC ## gyro() -> Result ### Description Reads gyroscope measurements for all three axes. Returns an `I16x3` struct with x, y, and z values. ### Method Method ### Parameters None ### Returns - **Result** - An `I16x3` struct with `x`, `y`, and `z` fields. ### Example ```rust let gyro = l3gd20.gyro()?; ``` ``` -------------------------------- ### Scale::degrees Source: https://docs.rs/l3gd20/latest/l3gd20/enum.Scale.html Converts a raw measurement value to degrees based on the selected scale. ```APIDOC ## Scale::degrees ### Description Converts a raw measurement value to degrees based on the selected scale. ### Method `pub fn degrees(&self, val: i16) -> f32` ### Parameters - `val` (i16) - Required - The raw sensor measurement value. ### Returns - (f32) - The measurement in degrees. ### Example ```rust let scale = Scale::Dps250; let degrees = scale.degrees(100); ``` ``` -------------------------------- ### Status Struct Definition Source: https://docs.rs/l3gd20/latest/l3gd20/struct.Status.html Definition of the Status struct with fields for overrun and new data flags per axis. ```APIDOC ## Struct Status ### Description Represents the sensor status of the L3GD20 gyroscope, with flags for overrun and new data on each axis. ### Definition ```rust pub struct Status { pub overrun: bool, pub z_overrun: bool, pub y_overrun: bool, pub x_overrun: bool, pub new_data: bool, pub z_new: bool, pub y_new: bool, pub x_new: bool, } ``` ### Fields - **overrun** (bool) - Overrun (data has overwritten previously unread data) has occurred on at least one axis - **z_overrun** (bool) - Overrun occurred on Z-axis - **y_overrun** (bool) - Overrun occurred on Y-axis - **x_overrun** (bool) - Overrun occurred on X-axis - **new_data** (bool) - New data is available for either X, Y, Z - axis - **z_new** (bool) - New data is available on Z-axis - **y_new** (bool) - New data is available on Y-axis - **x_new** (bool) - New data is available on X-axis ### Trait Implementations - **Clone** - Provides `clone` and `clone_from` methods. - **Copy** - Marker trait for copy semantics. - **Debug** - Provides `fmt` method for formatting. ### Auto Traits - Freeze - RefUnwindSafe - Send - Sync - Unpin - UnsafeUnpin - UnwindSafe ### Blanket Implementations - Any, Borrow, BorrowMut, CloneToUninit, From, Into, TryFrom, TryInto ``` -------------------------------- ### Scale::radians Source: https://docs.rs/l3gd20/latest/l3gd20/enum.Scale.html Converts a raw measurement value to radians based on the selected scale. ```APIDOC ## Scale::radians ### Description Converts a raw measurement value to radians based on the selected scale. ### Method `pub fn radians(&self, val: i16) -> f32` ### Parameters - `val` (i16) - Required - The raw sensor measurement value. ### Returns - (f32) - The measurement in radians. ### Example ```rust let scale = Scale::Dps500; let radians = scale.radians(100); ``` ``` -------------------------------- ### Bandwidth Enum Definition Source: https://docs.rs/l3gd20/latest/l3gd20/enum.Bandwidth.html The Bandwidth enum defines four levels of cut-off frequencies for the sensor. ```rust pub enum Bandwidth { Low = 0, Medium = 1, High = 2, Maximum = 3, } ``` -------------------------------- ### BitValue Trait Definition Source: https://docs.rs/l3gd20/latest/src/l3gd20/lib.rs.html Defines the interface for types that can be converted into bit-shifted values for sensor registers. ```rust trait BitValue { /// The width of the bitfield in bits fn width() -> u8; /// The bit 'mask' of the value fn mask() -> u8 { (1 << Self::width()) - 1 } /// The number of bits to shift the mask by fn shift() -> u8; /// Convert the type to a byte value to be sent to sensor /// /// # Note /// This value should not be bit shifted. fn value(&self) -> u8; } ``` -------------------------------- ### Odr Enum Definition Source: https://docs.rs/l3gd20/latest/l3gd20/enum.Odr.html The Odr enum with its variants and associated data rate values. ```APIDOC ## Odr Enum ### Description Represents the output data rate (ODR) settings for the L3GD20 gyroscope. ### Variants - **Hz95** = 0 - 95 Hz data rate - **Hz190** = 1 - 190 Hz data rate - **Hz380** = 2 - 380 Hz data rate - **Hz760** = 3 - 760 Hz data rate ### Usage Use this enum to configure the output data rate of the sensor. The numeric value corresponds to the register setting. ### Example ```rust let odr = Odr::Hz380; ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.