Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
mod math;

use self::math::discrete_to_radians;
use super::{Imu, Quat};
use self::math::{discrete_to_radians, GyroFsr};
use crate::aliases::I2c;
use crate::imu::{FusedImu, Quat};
use crate::utils;
use crate::{aliases::I2c, imu::ඞ::math::GyroFsr};

use bmi160::{AccelerometerPowerMode, GyroscopePowerMode, SensorSelector};
use ::bmi160::{AccelerometerPowerMode, GyroscopePowerMode, SensorSelector};
use defmt::{debug, trace};
use embedded_hal::blocking::delay::DelayMs;
use firmware_protocol::ImuType;
Expand Down Expand Up @@ -76,7 +76,7 @@ impl<I: I2c> Bmi160<I> {
}
}

impl<I: I2c> Imu for Bmi160<I> {
impl<I: I2c> FusedImu for Bmi160<I> {
type Error = BmiError<I>;

const IMU_TYPE: ImuType = ImuType::Bmi160;
Expand All @@ -102,6 +102,6 @@ impl<I: I2c> Imu for Bmi160<I> {
pub fn new_imu(
i2c: impl crate::aliases::I2c,
delay: &mut impl DelayMs<u32>,
) -> impl crate::imu::Imu {
) -> impl crate::imu::FusedImu {
Bmi160::new(i2c, delay).expect("Failed to initialize BMI160")
}
14 changes: 14 additions & 0 deletions firmware/src/imu/drivers/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mod stubbed;

#[cfg(feature = "imu-stubbed")]
pub mod ඞ {
pub use crate::imu::drivers::stubbed::*;
}

#[cfg(feature = "imu-mpu6050")]
#[path = "mpu6050.rs"]
pub mod ඞ;

#[cfg(feature = "imu-bmi160")]
#[path = "bmi160/mod.rs"]
pub mod ඞ;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Imu, Quat};
use crate::aliases::I2c;
use crate::imu::{FusedImu, Quat};
use crate::utils;

use defmt::{debug, trace, warn};
Expand Down Expand Up @@ -49,7 +49,7 @@ impl<I: I2c> Mpu6050<I> {
}
}

impl<I: I2c> Imu for Mpu6050<I> {
impl<I: I2c> FusedImu for Mpu6050<I> {
type Error = mpu6050_dmp::error::Error<I>;

const IMU_TYPE: ImuType = ImuType::Mpu6050;
Expand All @@ -76,6 +76,6 @@ impl<I: I2c> Imu for Mpu6050<I> {
pub fn new_imu(
i2c: impl crate::aliases::I2c,
delay: &mut impl DelayMs<u32>,
) -> impl crate::imu::Imu {
) -> impl crate::imu::FusedImu {
Mpu6050::new(i2c, delay).expect("Failed to initialize MPU6050")
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{Imu, Quat};
use crate::imu::{FusedImu, Quat};

use defmt::debug;
use embedded_hal::blocking::delay::DelayMs;
Expand All @@ -7,7 +7,7 @@ use firmware_protocol::ImuType;
/// Fakes an IMU for easier testing.
struct FakeImu;

impl Imu for FakeImu {
impl FusedImu for FakeImu {
type Error = ();

const IMU_TYPE: ImuType = ImuType::Unknown(0xFF);
Expand All @@ -21,7 +21,7 @@ impl Imu for FakeImu {
pub fn new_imu(
_i2c: impl crate::aliases::I2c,
_delay: &mut impl DelayMs<u32>,
) -> impl crate::imu::Imu {
) -> impl crate::imu::FusedImu {
debug!("Created FakeImu");
FakeImu
}
1 change: 1 addition & 0 deletions firmware/src/imu/fusion/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//! TODO: Add fusion
20 changes: 4 additions & 16 deletions firmware/src/imu/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
mod stubbed;

#[cfg(feature = "imu-stubbed")]
mod ඞ {
pub use crate::imu::stubbed::*;
}

#[cfg(feature = "imu-mpu6050")]
#[path = "mpu6050.rs"]
mod ඞ;

#[cfg(feature = "imu-bmi160")]
#[path = "bmi160/mod.rs"]
mod ඞ;
mod drivers;
mod fusion;

use defmt::{debug, info, trace, warn};
use embassy_executor::task;
Expand All @@ -25,7 +13,7 @@ use crate::{

pub type Quat = nalgebra::UnitQuaternion<f32>;

pub trait Imu {
pub trait FusedImu {
type Error: core::fmt::Debug;

const IMU_TYPE: ImuType;
Expand All @@ -51,7 +39,7 @@ async fn imu_task_inner(
mut delay: impl crate::aliases::Delay,
) -> ! {
debug!("Imu task");
let mut imu = ඞ::new_imu(i2c, &mut delay);
let mut imu = self::drivers::ඞ::new_imu(i2c, &mut delay);
info!("Initialized IMU!");

loop {
Expand Down