forked from stm32-rs/stm32h7xx-hal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rtic.rs
59 lines (47 loc) · 1.63 KB
/
rtic.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#![deny(warnings)]
#![deny(unsafe_code)]
#![no_std]
#![no_main]
extern crate rtic;
use stm32h7xx_hal::hal::digital::v2::ToggleableOutputPin;
use rtic::app;
use stm32h7xx_hal::gpio::{gpioc::PC13, gpioi::PI13};
use stm32h7xx_hal::gpio::{Edge, ExtiPin, Floating, Input};
use stm32h7xx_hal::gpio::{Output, PushPull};
use stm32h7xx_hal::prelude::*;
#[macro_use]
#[path = "utilities/power.rs"]
mod power;
use panic_halt as _;
#[app(device = stm32h7xx_hal::stm32, peripherals = true)]
const APP: () = {
struct Resources {
button: PC13<Input<Floating>>,
led: PI13<Output<PushPull>>,
}
#[init]
fn init(mut ctx: init::Context) -> init::LateResources {
let pwr = ctx.device.PWR.constrain();
let pwrcfg = example_power!(pwr).freeze();
// RCC
let rcc = ctx.device.RCC.constrain();
let ccdr = rcc.sys_ck(100.mhz()).freeze(pwrcfg, &ctx.device.SYSCFG);
// GPIO
let gpioc = ctx.device.GPIOC.split(ccdr.peripheral.GPIOC);
let gpioi = ctx.device.GPIOI.split(ccdr.peripheral.GPIOI);
// Button
let mut button = gpioc.pc13.into_floating_input();
button.make_interrupt_source(&mut ctx.device.SYSCFG);
button.trigger_on_edge(&mut ctx.device.EXTI, Edge::Rising);
button.enable_interrupt(&mut ctx.device.EXTI);
init::LateResources {
button,
led: gpioi.pi13.into_push_pull_output(),
}
}
#[task(binds = EXTI15_10, resources = [button, led])]
fn button_click(ctx: button_click::Context) {
ctx.resources.button.clear_interrupt_pending_bit();
ctx.resources.led.toggle().unwrap();
}
};