diff --git a/crates/cansat-stm32f4/src/main.rs b/crates/cansat-stm32f4/src/main.rs index 82359c1..f5b1094 100644 --- a/crates/cansat-stm32f4/src/main.rs +++ b/crates/cansat-stm32f4/src/main.rs @@ -13,8 +13,8 @@ mod tasks; use heapless::Vec; pub use sd_logger::SdLogger; pub use startup::{ - Bme280, Bme280Error, Buzzer, Delay, Gps, I2c1Devices, Led, Lora, LoraError, SdmmcController, - SdmmcError, + Bme280, Bme280Error, Buzzer, Delay, Gps, I2c1Devices, IgnitePins, Led, Lora, LoraError, + SdmmcController, SdmmcError, }; #[cfg(debug_assertions)] @@ -46,6 +46,7 @@ mod app { pub tracker: accelerometer::Tracker, pub i2c1_devices: I2c1Devices, pub lora: Option, + pub ignite_pins: IgnitePins, } #[init(local = [statik: startup::Statik = startup::Statik::new()])] @@ -69,5 +70,7 @@ mod app { async fn blink(ctx: blink::Context); #[task(local = [buzzer], priority = 1)] async fn buzz(ctx: buzz::Context); + #[task(local = [ignite_pins], priority = 1)] + async fn ignite(ctx: ignite::Context, pin: u8); } } diff --git a/crates/cansat-stm32f4/src/startup.rs b/crates/cansat-stm32f4/src/startup.rs index 70ab76c..a7e1a83 100644 --- a/crates/cansat-stm32f4/src/startup.rs +++ b/crates/cansat-stm32f4/src/startup.rs @@ -27,8 +27,11 @@ pub type SdmmcError = embedded_sdmmc::Error; pub type Bme280 = bme280::i2c::BME280; pub type Bme280Error = bme280::Error; -//pub type Lis3dh = lis3dh::Lis3dh>; -//pub type Lis3dhError = lis3dh::Error; +pub struct IgnitePins { + pub pb0: gpio::gpiob::PB0>, + pub pb1: gpio::gpiob::PB1>, + pub pb2: gpio::gpiob::PB2>, +} pub type Mpu = mpu6050::Mpu6050; pub type Mpu6050Error = mpu6050::Mpu6050Error; @@ -54,6 +57,8 @@ pub fn init(ctx: app::init::Context) -> (app::Shared, app::Local) { app::blink::spawn().unwrap(); app::buzz::spawn().unwrap(); app::send_meas::spawn().unwrap(); + //this line is for testing purposes + app::ignite::spawn(1).unwrap(); let shared = app::Shared { gps: cansat.gps, @@ -67,6 +72,7 @@ pub fn init(ctx: app::init::Context) -> (app::Shared, app::Local) { tracker: cansat.tracker, i2c1_devices: cansat.i2c1_devices, lora: cansat.lora, + ignite_pins: cansat.ignite_pins, }; (shared, local) @@ -81,6 +87,7 @@ struct Drivers { pub sd_logger: Option, pub tracker: accelerometer::Tracker, pub i2c1_devices: I2c1Devices, + pub ignite_pins: IgnitePins, } pub struct I2c1Devices { @@ -97,6 +104,7 @@ struct Board { pub serial6: Serial6, pub spi2: Spi2, pub cs2: Cs2, + pub ignite_pins: IgnitePins, } /// Static memory needed for startup. @@ -152,6 +160,7 @@ fn init_drivers(mut board: Board, statik: &'static mut Statik) -> Result Board { let led = gpioc.pc13.into_push_pull_output(); let buzzer = gpioa.pa8.into_push_pull_output(); - let i2c1 = { let scl1 = gpiob .pb8 @@ -297,6 +305,13 @@ fn init_board(device: pac::Peripherals) -> Board { .expect("Invalid USART6 config") }; + let ignite_pins = { + let pb0 = gpiob.pb0.into_push_pull_output(); + let pb1 = gpiob.pb1.into_push_pull_output(); + let pb2 = gpiob.pb2.into_push_pull_output(); + IgnitePins { pb0, pb1, pb2 } + }; + Board { delay, led, @@ -306,6 +321,7 @@ fn init_board(device: pac::Peripherals) -> Board { serial6, spi2, cs2, + ignite_pins, } } diff --git a/crates/cansat-stm32f4/src/tasks.rs b/crates/cansat-stm32f4/src/tasks.rs index a051526..b2f9f86 100644 --- a/crates/cansat-stm32f4/src/tasks.rs +++ b/crates/cansat-stm32f4/src/tasks.rs @@ -158,3 +158,27 @@ pub async fn buzz(ctx: app::buzz::Context<'_>) { Systick::delay(3.secs()).await; } } +//turns on the gio pin for 1 second + +pub async fn ignite(ctx: app::ignite::Context<'_>, stage: u8) { + //this delay is for testing purposes + Systick::delay(1.secs()).await; + match stage { + 1 => ctx.local.ignite_pins.pb0.set_high(), + 2 => ctx.local.ignite_pins.pb1.set_high(), + 3 => ctx.local.ignite_pins.pb2.set_high(), + _ => { + defmt::error!("Invalid stage when igniting"); + return; + } + } + Systick::delay(1.secs()).await; + match stage { + 1 => ctx.local.ignite_pins.pb0.set_low(), + 2 => ctx.local.ignite_pins.pb1.set_low(), + 3 => ctx.local.ignite_pins.pb2.set_low(), + _ => { + defmt::error!("Invalid stage when deigniting"); + } + } +}