Module capsules_extra::l3gd20

source ·
Expand description

SyscallDriver for the MEMS L3gd20Spi motion sensor, 3 axys digital output gyroscope and temperature sensor.

May be used with NineDof and Temperature

SPI Interface

https://www.pololu.com/file/0J563/L3gd20Spi.pdf

§Syscall Interface

§Command

All commands are asynchronous, they return a one shot callback when done Only one command can be issued at a time.

§command num
  • 0: Returns Ok(())
    • data: Unused.
    • Return: Success
  • 1: Is Present
    • data: unused
    • Return: Ok(()) if no other command is in progress, BUSY otherwise.
  • 2: Power On
    • data: unused
    • Return: Ok(()) if no other command is in progress, BUSY otherwise.
  • 3: Set Scale
    • data1: 0, 1 or 2
    • Return: Ok(()) if no other command is in progress, BUSY otherwise.
  • 4: Enable high pass filter
    • data: 1 for enable, 0 for disable
    • Return: Ok(()) if no other command is in progress, BUSY otherwise.
  • 5: Set High Pass Filter Mode and Divider (manual page 33)
    • data1: mode
    • data2: divider
    • Return: Ok(()) if no other command is in progress, BUSY otherwise.
  • 6: Read XYZ
    • data: unused
    • Return: Ok(()) if no other command is in progress, BUSY otherwise.
  • 7: Read Temperature
    • data: unused
    • Return: Ok(()) if no other command is in progress, BUSY otherwise.

§Subscribe

All commands call this callback when done, usually subscribes should be one time functions

§subscribe num
  • 0: Done callback
    • ’data1`: depends on command
      • 1 - 1 for is present, 0 for not present
      • 6 - X rotation
      • 7 - temperature in deg C
    • ’data2`: depends on command
      • 6 - Y rotation
    • ’data3`: depends on command
      • 6 - Z rotation

§Usage

let mux_spi = components::spi::SpiMuxComponent::new(&stm32f3xx::spi::SPI1)
    .finalize(components::spi_mux_component_helper!(stm32f3xx::spi::Spi));

let l3gd20 = components::l3gd20::L3gd20SpiComponent::new()
    .finalize(components::l3gd20_spi_component_helper!(stm32f3xx::spi::Spi, stm32f3xx::gpio::PinId::PE03, mux_spi));

NineDof Example

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

l3gd20.power_on();
let ninedof = static_init!(
    capsules::ninedof::NineDof<'static>,
    capsules::ninedof::NineDof::new(l3gd20, grant_ninedof));
hil::sensors::NineDof::set_client(l3gd20, ninedof);

Temperature Example

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

l3gd20.power_on();
let temp = static_init!(
capsules::temperature::TemperatureSensor<'static>,
    capsules::temperature::TemperatureSensor::new(l3gd20, grant_temperature));
kernel::hil::sensors::TemperatureDriver::set_client(l3gd20, temp);

Author: Alexandru Radovici msg4alex@gmail.com

Structs§

Constants§