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
10 changes: 5 additions & 5 deletions firmware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ net-ble = ["esp-wifi/ble", "dep:bleps"]
net-stubbed = [] # Stubs out network

# Supported IMUs
imu-bmi160 = ["dep:bmi160"]
imu-mpu6050 = ["dep:mpu6050-dmp"]
imu-stubbed = [] # Stubs out the IMU
imu-bmi160 = []
imu-mpu6050 = []
imu-stubbed = [] # Stubs out the IMU

# Supported defmt loggers
log-rtt = ["dep:defmt-rtt"]
Expand Down Expand Up @@ -191,8 +191,8 @@ panic_defmt = { path = "crates/panic_defmt" }
defmt-bbq = { version = "0.1", optional = true }

# Peripheral drivers
mpu6050-dmp = { version = "0.2", optional = true }
bmi160 = { version = "0.1", optional = true }
mpu6050-dmp = "0.2"
bmi160 = "0.1"

# Other crates
static_cell = "1"
Expand Down
1 change: 1 addition & 0 deletions firmware/src/imu/drivers/bmi160/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl<I: I2c> FusedImu for Bmi160<I> {
}
}

#[allow(dead_code)]
pub fn new_imu(
i2c: impl crate::aliases::I2c,
delay: &mut impl DelayMs<u32>,
Expand Down
17 changes: 3 additions & 14 deletions firmware/src/imu/drivers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
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 ඞ;
pub mod bmi160;
pub mod mpu6050;
pub mod stubbed;
3 changes: 2 additions & 1 deletion firmware/src/imu/drivers/mpu6050.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ impl<I: I2c> FusedImu for Mpu6050<I> {
}
}

#[allow(dead_code)]
pub fn new_imu(
i2c: impl crate::aliases::I2c,
delay: &mut impl DelayMs<u32>,
) -> impl crate::imu::FusedImu {
Mpu6050::new(i2c, delay).expect("Failed to initialize MPU6050")
Mpu6050::new(i2c, delay).expect("Failed to create mpu6050")
}
16 changes: 15 additions & 1 deletion firmware/src/imu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async fn imu_task_inner(
mut delay: impl crate::aliases::Delay,
) -> ! {
debug!("Imu task");
let mut imu = self::drivers::ඞ::new_imu(i2c, &mut delay);
let mut imu = new_imu(i2c, &mut delay);
info!("Initialized IMU!");

loop {
Expand All @@ -61,3 +61,17 @@ async fn imu_task_inner(
yield_now().await // Yield to ensure fairness
}
}

fn new_imu(
i2c: impl crate::aliases::I2c,
delay: &mut impl crate::aliases::Delay,
) -> impl FusedImu {
use crate::imu::drivers as d;

#[cfg(feature = "imu-bmi160")]
return d::bmi160::new_imu(i2c, delay);
#[cfg(feature = "imu-mpu6050")]
return d::mpu6050::new_imu(i2c, delay);
#[cfg(feature = "imu-stubbed")]
return d::stubbed::new_imu(i2c, delay);
}