diff options
| author | Ulf Lilleengen <[email protected]> | 2022-02-23 09:48:32 +0100 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2022-02-23 09:48:32 +0100 |
| commit | 092eef3ae7f90e33564f09fa6a887e8fc9ed88b8 (patch) | |
| tree | 547db6b7241e749f1cad0285c12124d26de37639 /docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src | |
| parent | 4c6e61b3b1a82212510695b0d202bc8612b16b6c (diff) | |
Add documentation about the different embassy abstraction layers
The guide demonstrates the functionality offered by each
layer in Embassy, using code examples.
Diffstat (limited to 'docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src')
| -rw-r--r-- | docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs new file mode 100644 index 000000000..239eac188 --- /dev/null +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt_rtt as _; | ||
| 5 | use panic_probe as _; | ||
| 6 | |||
| 7 | use stm32_metapac as pac; | ||
| 8 | |||
| 9 | use pac::gpio::vals; | ||
| 10 | |||
| 11 | #[cortex_m_rt::entry] | ||
| 12 | fn main() -> ! { | ||
| 13 | // Enable GPIO clock | ||
| 14 | let rcc = pac::RCC; | ||
| 15 | unsafe { | ||
| 16 | rcc.ahb2enr().modify(|w| { | ||
| 17 | w.set_gpioben(true); | ||
| 18 | w.set_gpiocen(true); | ||
| 19 | }); | ||
| 20 | |||
| 21 | rcc.ahb2rstr().modify(|w| { | ||
| 22 | w.set_gpiobrst(true); | ||
| 23 | w.set_gpiocrst(true); | ||
| 24 | w.set_gpiobrst(false); | ||
| 25 | w.set_gpiocrst(false); | ||
| 26 | }); | ||
| 27 | } | ||
| 28 | |||
| 29 | // Setup button | ||
| 30 | let gpioc = pac::GPIOC; | ||
| 31 | const BUTTON_PIN: usize = 13; | ||
| 32 | unsafe { | ||
| 33 | gpioc | ||
| 34 | .pupdr() | ||
| 35 | .modify(|w| w.set_pupdr(BUTTON_PIN, vals::Pupdr::PULLUP)); | ||
| 36 | gpioc | ||
| 37 | .otyper() | ||
| 38 | .modify(|w| w.set_ot(BUTTON_PIN, vals::Ot::PUSHPULL)); | ||
| 39 | gpioc | ||
| 40 | .moder() | ||
| 41 | .modify(|w| w.set_moder(BUTTON_PIN, vals::Moder::INPUT)); | ||
| 42 | } | ||
| 43 | |||
| 44 | // Setup LED | ||
| 45 | let gpiob = pac::GPIOB; | ||
| 46 | const LED_PIN: usize = 14; | ||
| 47 | unsafe { | ||
| 48 | gpiob | ||
| 49 | .pupdr() | ||
| 50 | .modify(|w| w.set_pupdr(LED_PIN, vals::Pupdr::FLOATING)); | ||
| 51 | gpiob | ||
| 52 | .otyper() | ||
| 53 | .modify(|w| w.set_ot(LED_PIN, vals::Ot::PUSHPULL)); | ||
| 54 | gpiob | ||
| 55 | .moder() | ||
| 56 | .modify(|w| w.set_moder(LED_PIN, vals::Moder::OUTPUT)); | ||
| 57 | } | ||
| 58 | |||
| 59 | // Main loop | ||
| 60 | loop { | ||
| 61 | unsafe { | ||
| 62 | if gpioc.idr().read().idr(BUTTON_PIN) == vals::Idr::LOW { | ||
| 63 | gpiob.bsrr().write(|w| w.set_bs(LED_PIN, true)); | ||
| 64 | } else { | ||
| 65 | gpiob.bsrr().write(|w| w.set_br(LED_PIN, true)); | ||
| 66 | } | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
