diff options
| author | Ulf Lilleengen <[email protected]> | 2024-05-21 08:11:34 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-05-21 08:11:34 +0000 |
| commit | cd27439fca0332ca1c20931ce587471f53e1b0ec (patch) | |
| tree | 8dd446c12202d5e242ba287f54cdf737ef29bd96 /docs/examples/layer-by-layer/blinky-pac/src | |
| parent | 51d553092550059afb22b2620cea14bbed21abff (diff) | |
| parent | bb9c687a39c0675bd622f612a645b16229cb9024 (diff) | |
Merge pull request #2958 from embassy-rs/embassy-book-refactor
Embassy book refactor
Diffstat (limited to 'docs/examples/layer-by-layer/blinky-pac/src')
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-pac/src/main.rs | 53 |
1 files changed, 53 insertions, 0 deletions
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 | |||
| 4 | use pac::gpio::vals; | ||
| 5 | use {defmt_rtt as _, panic_probe as _, stm32_metapac as pac}; | ||
| 6 | |||
| 7 | #[cortex_m_rt::entry] | ||
| 8 | fn 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 | } | ||
