Skip to main content

Module lsm303agr

Module lsm303agr 

Source
Expand description

SyscallDriver for the LSM303AGR 3D accelerometer and 3D magnetometer sensor.

May be used with NineDof and Temperature

I2C Interface

https://www.st.com/en/mems-and-sensors/lsm303agr.html

The syscall interface is described in lsm303dlhc.md

§Usage

let mux_i2c = components::i2c::I2CMuxComponent::new(&stm32f3xx::i2c::I2C1)
    .finalize(components::i2c_mux_component_helper!());

let lsm303dlhc = components::lsm303dlhc::Lsm303agrI2CComponent::new()
   .finalize(components::lsm303dlhc_i2c_component_helper!(mux_i2c));

lsm303dlhc.configure(
   lsm303dlhc::Lsm303AccelDataRate::DataRate25Hz,
   false,
   lsm303dlhc::Lsm303Scale::Scale2G,
   false,
   true,
   lsm303dlhc::Lsm303MagnetoDataRate::DataRate3_0Hz,
   lsm303dlhc::Lsm303Range::Range4_7G,
);

NideDof Example

let grant_cap = create_capability!(capabilities::MemoryAllocationCapability);
let grant_ninedof = board_kernel.create_grant(&grant_cap);

// use as primary NineDof Sensor
let ninedof = static_init!(
   capsules::ninedof::NineDof<'static>,
   capsules::ninedof::NineDof::new(lsm303dlhc, grant_ninedof)
);

hil::sensors::NineDof::set_client(lsm303dlhc, ninedof);

// use as secondary NineDof Sensor
let lsm303dlhc_secondary = static_init!(
   capsules::ninedof::NineDofNode<'static, &'static dyn hil::sensors::NineDof>,
   capsules::ninedof::NineDofNode::new(lsm303dlhc)
);
ninedof.add_secondary_driver(lsm303dlhc_secondary);
hil::sensors::NineDof::set_client(lsm303dlhc, ninedof);

Temperature Example

let grant_cap = create_capability!(capabilities::MemoryAllocationCapability);
let grant_temp = board_kernel.create_grant(&grant_cap);

lsm303dlhc.configure(
   lsm303dlhc::Lsm303AccelDataRate::DataRate25Hz,
   false,
   lsm303dlhc::Lsm303Scale::Scale2G,
   false,
   true,
   lsm303dlhc::Lsm303MagnetoDataRate::DataRate3_0Hz,
   lsm303dlhc::Lsm303Range::Range4_7G,
);
let temp = static_init!(
capsules::temperature::TemperatureSensor<'static>,
    capsules::temperature::TemperatureSensor::new(lsm303dlhc, grant_temperature));
kernel::hil::sensors::TemperatureDriver::set_client(lsm303dlhc, temp);

Author: Alexandru Radovici msg4alex@gmail.com

Structs§

App
Lsm303agrI2C

Enums§

AgrAccelerometerRegisters

Constants§

DRIVER_NUM
Syscall driver number.