Skip to content
Open
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
7 changes: 5 additions & 2 deletions crates/cansat-stm32f4/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -46,6 +46,7 @@ mod app {
pub tracker: accelerometer::Tracker,
pub i2c1_devices: I2c1Devices,
pub lora: Option<Lora>,
pub ignite_pins: IgnitePins,
}

#[init(local = [statik: startup::Statik = startup::Statik::new()])]
Expand All @@ -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);
}
}
22 changes: 19 additions & 3 deletions crates/cansat-stm32f4/src/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ pub type SdmmcError = embedded_sdmmc::Error<embedded_sdmmc::SdMmcError>;
pub type Bme280 = bme280::i2c::BME280<I2c1Proxy>;
pub type Bme280Error = bme280::Error<i2c::Error>;

//pub type Lis3dh = lis3dh::Lis3dh<lis3dh::Lis3dhI2C<I2c1Proxy>>;
//pub type Lis3dhError = lis3dh::Error<i2c::Error, Infallible>;
pub struct IgnitePins {
pub pb0: gpio::gpiob::PB0<gpio::Output<gpio::PushPull>>,
pub pb1: gpio::gpiob::PB1<gpio::Output<gpio::PushPull>>,
pub pb2: gpio::gpiob::PB2<gpio::Output<gpio::PushPull>>,
}

pub type Mpu = mpu6050::Mpu6050<I2c1Proxy>;
pub type Mpu6050Error = mpu6050::Mpu6050Error<i2c::Error>;
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -81,6 +87,7 @@ struct Drivers {
pub sd_logger: Option<SdLogger>,
pub tracker: accelerometer::Tracker,
pub i2c1_devices: I2c1Devices,
pub ignite_pins: IgnitePins,
}

pub struct I2c1Devices {
Expand All @@ -97,6 +104,7 @@ struct Board {
pub serial6: Serial6,
pub spi2: Spi2,
pub cs2: Cs2,
pub ignite_pins: IgnitePins,
}

/// Static memory needed for startup.
Expand Down Expand Up @@ -152,6 +160,7 @@ fn init_drivers(mut board: Board, statik: &'static mut Statik) -> Result<Drivers
sd_logger,
tracker,
i2c1_devices: I2c1Devices { bme280, mpu },
ignite_pins: board.ignite_pins,
})
}

Expand Down Expand Up @@ -244,7 +253,6 @@ fn init_board(device: pac::Peripherals) -> Board {

let led = gpioc.pc13.into_push_pull_output();
let buzzer = gpioa.pa8.into_push_pull_output();

let i2c1 = {
let scl1 = gpiob
.pb8
Expand Down Expand Up @@ -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,
Expand All @@ -306,6 +321,7 @@ fn init_board(device: pac::Peripherals) -> Board {
serial6,
spi2,
cs2,
ignite_pins,
}
}

Expand Down
24 changes: 24 additions & 0 deletions crates/cansat-stm32f4/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}