forked from stm32-rs/stm32h7xx-hal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtic.rs
62 lines (52 loc) · 1.65 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
60
61
62
#![deny(warnings)]
#![deny(unsafe_code)]
#![no_std]
#![no_main]
#[macro_use]
mod utilities;
#[rtic::app(device = stm32h7xx_hal::stm32, peripherals = true)]
mod app {
use stm32h7xx_hal::gpio::gpioc::{PC13, PC3};
use stm32h7xx_hal::gpio::{Edge, ExtiPin, Input};
use stm32h7xx_hal::gpio::{Output, PushPull};
use stm32h7xx_hal::prelude::*;
use super::*;
#[shared]
struct SharedResources {}
#[local]
struct LocalResources {
button: PC13<Input>,
led: PC3<Output<PushPull>>,
}
#[init]
fn init(
mut ctx: init::Context,
) -> (SharedResources, LocalResources, init::Monotonics) {
utilities::logger::init();
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);
// 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);
(
SharedResources {},
LocalResources {
button,
led: gpioc.pc3.into_push_pull_output(),
},
init::Monotonics(),
)
}
#[task(binds = EXTI15_10, local = [button, led])]
fn button_click(ctx: button_click::Context) {
ctx.local.button.clear_interrupt_pending_bit();
ctx.local.led.toggle();
}
}