Skip to content

Commit

Permalink
Merge #1723
Browse files Browse the repository at this point in the history
1723: capsule for l3gd20 3 axis gyro and temperature sensor r=bradjc a=alexandruradovici

### Pull Request Overview

This pull request adds a capsule for the L3GD20 3 axis gyro and temperature sensor over SPI.

### Testing Strategy

This pull request was tested using an stm32f3discovery board

### TODO or Help Wanted

This PR adds the sensor integrated in #1674.

Any feedback is welcome.

### Documentation Updated

- [x] Updated the relevant files in `/docs`, or no updates are required.

### Formatting

- [x] Ran `make formatall`.


Co-authored-by: Alexandru Radovici <msg4alex@gmail.com>
  • Loading branch information
bors[bot] and alexandruradovici committed Apr 9, 2020
2 parents 8356731 + 4911b87 commit cfa0757
Show file tree
Hide file tree
Showing 10 changed files with 762 additions and 7 deletions.
75 changes: 75 additions & 0 deletions boards/components/src/l3gd20.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//! Components for the L3GD20 sensor.
//!
//! SPI Interface
//!
//! Usage
//! -----
//! ```rust
//! let lcd = components::l3gd20::L3gd20SpiComponent::new(board_kernel).finalize(
//! components::l3gd20_spi_component_helper!(
//! // spi type
//! stm32f4xx::spi::Spi,
//! // chip select
//! stm32f4xx::gpio::PinId::PE03,
//! // spi mux
//! spi_mux
//! )
//! );
//! ```
use capsules::l3gd20::L3gd20Spi;
use capsules::virtual_spi::VirtualSpiMasterDevice;
use core::marker::PhantomData;
use core::mem::MaybeUninit;
use kernel::component::Component;
use kernel::hil::spi;
use kernel::static_init_half;

// Setup static space for the objects.
#[macro_export]
macro_rules! l3gd20_spi_component_helper {
($A:ty, $select: expr, $spi_mux: expr) => {{
use capsules::l3gd20::L3gd20Spi;
use core::mem::MaybeUninit;
let mut l3gd20_spi: &'static capsules::virtual_spi::VirtualSpiMasterDevice<'static, $A> =
components::spi::SpiComponent::new($spi_mux, $select)
.finalize(components::spi_component_helper!($A));
static mut l3gd20spi: MaybeUninit<L3gd20Spi<'static>> = MaybeUninit::uninit();
(&mut l3gd20_spi, &mut l3gd20spi)
};};
}

pub struct L3gd20SpiComponent<S: 'static + spi::SpiMaster> {
_select: PhantomData<S>,
}

impl<S: 'static + spi::SpiMaster> L3gd20SpiComponent<S> {
pub fn new() -> L3gd20SpiComponent<S> {
L3gd20SpiComponent {
_select: PhantomData,
}
}
}

impl<S: 'static + spi::SpiMaster> Component for L3gd20SpiComponent<S> {
type StaticInput = (
&'static VirtualSpiMasterDevice<'static, S>,
&'static mut MaybeUninit<L3gd20Spi<'static>>,
);
type Output = &'static L3gd20Spi<'static>;

unsafe fn finalize(self, static_buffer: Self::StaticInput) -> Self::Output {
let l3gd20 = static_init_half!(
static_buffer.1,
L3gd20Spi<'static>,
L3gd20Spi::new(
static_buffer.0,
&mut capsules::l3gd20::TXBUFFER,
&mut capsules::l3gd20::RXBUFFER
)
);
static_buffer.0.set_client(l3gd20);
l3gd20.configure();

l3gd20
}
}
1 change: 1 addition & 0 deletions boards/components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod debug_writer;
pub mod hd44780;
pub mod i2c;
pub mod isl29035;
pub mod l3gd20;
pub mod lldb;
pub mod nrf51822;
pub mod panic_button;
Expand Down
1 change: 1 addition & 0 deletions capsules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ These implement a driver to setup and read various physical sensors.
- **[Analog Sensors](src/analog_sensor.rs)**: Single ADC pin sensors.
- **[FXOS8700CQ](src/fxos8700cq.rs)**: Accelerometer and magnetometer.
- **[ISL29035](src/isl29035.rs)**: Light sensor.
- **[L3GD20](src/l3gd20.rs)**: MEMS 3 axys digital gyroscope and temperature sensor.
- **[LPS25HB](src/lps25hb.rs)**: Pressure sensor.
- **[SI7021](src/si7021.rs)**: Temperature and humidity sensor.
- **[TMP006](src/tmp006.rs)**: Infrared temperature sensor.
Expand Down
1 change: 1 addition & 0 deletions capsules/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub enum NUM {
Tsl2561 = 0x70000,
Tmp006 = 0x70001,
Lps25hb = 0x70004,
L3gd20 = 0x70005,

// Other ICs
Ltc294x = 0x80000,
Expand Down

0 comments on commit cfa0757

Please sign in to comment.