-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
10 changed files
with
762 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.