Skip to main content

Module lsm303dlhc

Module lsm303dlhc 

Source
Expand description

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

May be used with NineDof and Temperature

I2C Interface

https://www.st.com/en/mems-and-sensors/lsm303dlhc.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::Lsm303dlhcI2CComponent::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
Lsm303dlhcI2C

Constants§

DRIVER_NUM
Syscall driver number.