diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-06-02 01:30:07 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-06-02 01:32:19 +0200 |
| commit | dff03ecfc74d6af716637888338ebfa99ab7a027 (patch) | |
| tree | c06bf2b0a2e6657c3427c956dbd27a4e45211aaa /examples/stm32f4/src/bin/button_exti.rs | |
| parent | a0c5f7137fe0c45b8db0aad2a116aea91e6a93f7 (diff) | |
Move examples to a subdirectory
Diffstat (limited to 'examples/stm32f4/src/bin/button_exti.rs')
| -rw-r--r-- | examples/stm32f4/src/bin/button_exti.rs | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/examples/stm32f4/src/bin/button_exti.rs b/examples/stm32f4/src/bin/button_exti.rs new file mode 100644 index 000000000..8fc889dad --- /dev/null +++ b/examples/stm32f4/src/bin/button_exti.rs | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(trait_alias)] | ||
| 4 | #![feature(min_type_alias_impl_trait)] | ||
| 5 | #![feature(impl_trait_in_bindings)] | ||
| 6 | #![feature(type_alias_impl_trait)] | ||
| 7 | #![allow(incomplete_features)] | ||
| 8 | |||
| 9 | #[path = "../example_common.rs"] | ||
| 10 | mod example_common; | ||
| 11 | use embassy::executor::Executor; | ||
| 12 | use embassy::time::Clock; | ||
| 13 | use embassy::util::Forever; | ||
| 14 | use embassy_stm32::exti::ExtiInput; | ||
| 15 | use embassy_stm32::gpio::{Input, Pull}; | ||
| 16 | use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge}; | ||
| 17 | use example_common::*; | ||
| 18 | |||
| 19 | use cortex_m_rt::entry; | ||
| 20 | use stm32f4::stm32f429 as pac; | ||
| 21 | |||
| 22 | #[embassy::task] | ||
| 23 | async fn main_task() { | ||
| 24 | let p = embassy_stm32::init(Default::default()); | ||
| 25 | |||
| 26 | let button = Input::new(p.PC13, Pull::Down); | ||
| 27 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 28 | |||
| 29 | info!("Press the USER button..."); | ||
| 30 | |||
| 31 | loop { | ||
| 32 | button.wait_for_rising_edge().await; | ||
| 33 | info!("Pressed!"); | ||
| 34 | button.wait_for_falling_edge().await; | ||
| 35 | info!("Released!"); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | struct ZeroClock; | ||
| 40 | |||
| 41 | impl Clock for ZeroClock { | ||
| 42 | fn now(&self) -> u64 { | ||
| 43 | 0 | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 48 | |||
| 49 | #[entry] | ||
| 50 | fn main() -> ! { | ||
| 51 | info!("Hello World!"); | ||
| 52 | |||
| 53 | let pp = pac::Peripherals::take().unwrap(); | ||
| 54 | |||
| 55 | pp.DBGMCU.cr.modify(|_, w| { | ||
| 56 | w.dbg_sleep().set_bit(); | ||
| 57 | w.dbg_standby().set_bit(); | ||
| 58 | w.dbg_stop().set_bit() | ||
| 59 | }); | ||
| 60 | pp.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled()); | ||
| 61 | |||
| 62 | pp.RCC.ahb1enr.modify(|_, w| { | ||
| 63 | w.gpioaen().enabled(); | ||
| 64 | w.gpioben().enabled(); | ||
| 65 | w.gpiocen().enabled(); | ||
| 66 | w.gpioden().enabled(); | ||
| 67 | w.gpioeen().enabled(); | ||
| 68 | w.gpiofen().enabled(); | ||
| 69 | w | ||
| 70 | }); | ||
| 71 | pp.RCC.apb2enr.modify(|_, w| { | ||
| 72 | w.syscfgen().enabled(); | ||
| 73 | w | ||
| 74 | }); | ||
| 75 | |||
| 76 | unsafe { embassy::time::set_clock(&ZeroClock) }; | ||
| 77 | |||
| 78 | let executor = EXECUTOR.put(Executor::new()); | ||
| 79 | |||
| 80 | executor.run(|spawner| { | ||
| 81 | unwrap!(spawner.spawn(main_task())); | ||
| 82 | }) | ||
| 83 | } | ||
