#![allow(non_camel_case_types)]
use enum_primitive::cast::FromPrimitive;
use enum_primitive::enum_from_primitive;
use kernel::utilities::registers::register_bitfields;
pub const ACCELEROMETER_BASE_ADDRESS: u8 = 0x19;
pub const MAGNETOMETER_BASE_ADDRESS: u8 = 0x1e;
enum_from_primitive! {
#[derive(Clone, Copy, PartialEq)]
pub enum Lsm303AccelDataRate {
Off = 0,
DataRate1Hz = 1,
DataRate10Hz = 2,
DataRate25Hz = 3,
DataRate50Hz = 4,
DataRate100Hz = 5,
DataRate200Hz = 6,
DataRate400Hz = 7,
LowPower1620Hz = 8,
Normal1344LowPower5376Hz = 9,
}
}
enum_from_primitive! {
#[derive(Clone, Copy, PartialEq)]
pub enum Lsm303MagnetoDataRate {
DataRate0_75Hz = 0,
DataRate1_5Hz = 1,
DataRate3_0Hz = 2,
DataRate7_5Hz = 3,
DataRate15_0Hz = 4,
DataRate30_0Hz = 5,
DataRate75_0Hz = 6,
DataRate220_0Hz = 7,
}
}
enum_from_primitive! {
#[derive(Clone, Copy, PartialEq)]
pub enum Lsm303Scale {
Scale2G = 0,
Scale4G = 1,
Scale8G = 2,
Scale16G = 3
}
}
pub(crate) const SCALE_FACTOR: [u8; 4] = [2, 4, 8, 16];
enum_from_primitive! {
#[derive(Clone, Copy, PartialEq)]
pub enum Lsm303Range {
Range1G = 0,
Range1_3G = 1,
Range1_9G = 2,
Range2_5G = 3,
Range4_0G = 4,
Range4_7G = 5,
Range5_6G = 7,
Range8_1 = 8,
}
}
pub(crate) const RANGE_FACTOR_X_Y: [i16; 8] = [
1000, 1100, 855, 670, 450, 400, 330, 230,
];
pub(crate) const RANGE_FACTOR_Z: [i16; 8] = [
1000, 980, 760, 600, 400, 355, 295, 205,
];
register_bitfields![u8,
pub (crate) CTRL_REG1 [
ODR OFFSET(4) NUMBITS(4) [],
LPEN OFFSET(3) NUMBITS(1) [],
ZEN OFFSET(2) NUMBITS(1) [],
YEN OFFSET(1) NUMBITS(1) [],
XEN OFFSET(0) NUMBITS(1) []
],
pub (crate) CTRL_REG4 [
BDU OFFSET(7) NUMBITS(2) [],
BLE OFFSET(6) NUMBITS(1) [],
FS OFFSET(4) NUMBITS(2) [],
HR OFFSET(3) NUMBITS(1) [],
SIM OFFSET(0) NUMBITS(1) []
]
];
enum_from_primitive! {
pub enum AccelerometerRegisters {
CTRL_REG1 = 0x20,
CTRL_REG4 = 0x23,
OUT_X_L_A = 0x28,
OUT_X_H_A = 0x29,
OUT_Y_L_A = 0x2A,
OUT_Y_H_A = 0x2B,
OUT_Z_L_A = 0x2C,
OUT_Z_H_A = 0x2D,
}
}