aboutsummaryrefslogtreecommitdiff
path: root/docs/examples/layer-by-layer/blinky-pac
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2024-05-18 10:17:03 +0200
committerUlf Lilleengen <[email protected]>2024-05-21 10:05:21 +0200
commit739e5861c2e47db251725163fcd91cd822cf97b7 (patch)
tree947dc7961ca7c42ec216056fc2adf616ab812b10 /docs/examples/layer-by-layer/blinky-pac
parent51d553092550059afb22b2620cea14bbed21abff (diff)
convert from antora to asciidoctor
Diffstat (limited to 'docs/examples/layer-by-layer/blinky-pac')
-rw-r--r--docs/examples/layer-by-layer/blinky-pac/Cargo.toml14
-rw-r--r--docs/examples/layer-by-layer/blinky-pac/src/main.rs53
2 files changed, 67 insertions, 0 deletions
diff --git a/docs/examples/layer-by-layer/blinky-pac/Cargo.toml b/docs/examples/layer-by-layer/blinky-pac/Cargo.toml
new file mode 100644
index 000000000..f872b94cb
--- /dev/null
+++ b/docs/examples/layer-by-layer/blinky-pac/Cargo.toml
@@ -0,0 +1,14 @@
1[package]
2name = "blinky-pac"
3version = "0.1.0"
4edition = "2021"
5license = "MIT OR Apache-2.0"
6
7[dependencies]
8cortex-m = "0.7"
9cortex-m-rt = "0.7"
10stm32-metapac = { version = "1", features = ["stm32l475vg", "memory-x"] }
11
12defmt = "0.3.0"
13defmt-rtt = "0.3.0"
14panic-probe = { version = "0.3.0", features = ["print-defmt"] }
diff --git a/docs/examples/layer-by-layer/blinky-pac/src/main.rs b/docs/examples/layer-by-layer/blinky-pac/src/main.rs
new file mode 100644
index 000000000..990d46cb6
--- /dev/null
+++ b/docs/examples/layer-by-layer/blinky-pac/src/main.rs
@@ -0,0 +1,53 @@
1#![no_std]
2#![no_main]
3
4use pac::gpio::vals;
5use {defmt_rtt as _, panic_probe as _, stm32_metapac as pac};
6
7#[cortex_m_rt::entry]
8fn main() -> ! {
9 // Enable GPIO clock
10 let rcc = pac::RCC;
11 unsafe {
12 rcc.ahb2enr().modify(|w| {
13 w.set_gpioben(true);
14 w.set_gpiocen(true);
15 });
16
17 rcc.ahb2rstr().modify(|w| {
18 w.set_gpiobrst(true);
19 w.set_gpiocrst(true);
20 w.set_gpiobrst(false);
21 w.set_gpiocrst(false);
22 });
23 }
24
25 // Setup button
26 let gpioc = pac::GPIOC;
27 const BUTTON_PIN: usize = 13;
28 unsafe {
29 gpioc.pupdr().modify(|w| w.set_pupdr(BUTTON_PIN, vals::Pupdr::PULLUP));
30 gpioc.otyper().modify(|w| w.set_ot(BUTTON_PIN, vals::Ot::PUSHPULL));
31 gpioc.moder().modify(|w| w.set_moder(BUTTON_PIN, vals::Moder::INPUT));
32 }
33
34 // Setup LED
35 let gpiob = pac::GPIOB;
36 const LED_PIN: usize = 14;
37 unsafe {
38 gpiob.pupdr().modify(|w| w.set_pupdr(LED_PIN, vals::Pupdr::FLOATING));
39 gpiob.otyper().modify(|w| w.set_ot(LED_PIN, vals::Ot::PUSHPULL));
40 gpiob.moder().modify(|w| w.set_moder(LED_PIN, vals::Moder::OUTPUT));
41 }
42
43 // Main loop
44 loop {
45 unsafe {
46 if gpioc.idr().read().idr(BUTTON_PIN) == vals::Idr::LOW {
47 gpiob.bsrr().write(|w| w.set_bs(LED_PIN, true));
48 } else {
49 gpiob.bsrr().write(|w| w.set_br(LED_PIN, true));
50 }
51 }
52 }
53}