Skip to content
Snippets Groups Projects
Commit 84c2a8d2 authored by Josef Utbult's avatar Josef Utbult
Browse files

bare7_1

parent 9a6aa7a7
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ use stm32f4xx_hal::{
gpio::{gpioa::PA5, Output, PushPull},
prelude::*,
};
;
use embedded_hal::digital::v2::{OutputPin, ToggleableOutputPin};
const OFFSET: u32 = 8_000_000;
......@@ -26,8 +26,10 @@ const OFFSET: u32 = 8_000_000;
const APP: () = {
struct Resources {
// late resources
GPIOA: stm32::GPIOA,
// led: PA5<Output<PushPull>>,
// GPIOA: stm32::GPIOA,
// Add led as a resource
led: PA5<Output<PushPull>>,
}
#[init(schedule = [toggle])]
fn init(cx: init::Context) -> init::LateResources {
......@@ -55,7 +57,10 @@ const APP: () = {
// pass on late resources
init::LateResources {
GPIOA: device.GPIOA,
// GPIOA: device.GPIOA,
// Init led as a late resource, while destroying GPIO as a variable
led: device.GPIOA.split().pa5.into_push_pull_output()
}
}
......@@ -67,15 +72,18 @@ const APP: () = {
}
}
#[task(resources = [GPIOA], schedule = [toggle])]
#[task(resources = [led], schedule = [toggle])]
fn toggle(cx: toggle::Context) {
static mut TOGGLE: bool = false;
rprintln!("toggle @ {:?}", Instant::now());
// Use led from resources
if *TOGGLE {
cx.resources.GPIOA.bsrr.write(|w| w.bs5().set_bit());
cx.resources.led.set_high();
// cx.resources.GPIOA.bsrr.write(|w| w.bs5().set_bit());
} else {
cx.resources.GPIOA.bsrr.write(|w| w.br5().set_bit());
cx.resources.led.set_low();
// cx.resources.GPIOA.bsrr.write(|w| w.br5().set_bit());
}
*TOGGLE = !*TOGGLE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment