diff options
Diffstat (limited to 'examples/stm32f4/src/bin/button.rs')
| -rw-r--r-- | examples/stm32f4/src/bin/button.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/examples/stm32f4/src/bin/button.rs b/examples/stm32f4/src/bin/button.rs new file mode 100644 index 000000000..1ee99f527 --- /dev/null +++ b/examples/stm32f4/src/bin/button.rs | |||
| @@ -0,0 +1,59 @@ | |||
| 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_stm32::gpio::{Input, Level, Output, Pull}; | ||
| 12 | use embedded_hal::digital::v2::{InputPin, OutputPin}; | ||
| 13 | use example_common::*; | ||
| 14 | |||
| 15 | use cortex_m_rt::entry; | ||
| 16 | use stm32f4::stm32f429 as pac; | ||
| 17 | |||
| 18 | #[entry] | ||
| 19 | fn main() -> ! { | ||
| 20 | info!("Hello World!"); | ||
| 21 | |||
| 22 | let pp = pac::Peripherals::take().unwrap(); | ||
| 23 | |||
| 24 | pp.DBGMCU.cr.modify(|_, w| { | ||
| 25 | w.dbg_sleep().set_bit(); | ||
| 26 | w.dbg_standby().set_bit(); | ||
| 27 | w.dbg_stop().set_bit() | ||
| 28 | }); | ||
| 29 | pp.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled()); | ||
| 30 | |||
| 31 | pp.RCC.ahb1enr.modify(|_, w| { | ||
| 32 | w.gpioaen().enabled(); | ||
| 33 | w.gpioben().enabled(); | ||
| 34 | w.gpiocen().enabled(); | ||
| 35 | w.gpioden().enabled(); | ||
| 36 | w.gpioeen().enabled(); | ||
| 37 | w.gpiofen().enabled(); | ||
| 38 | w | ||
| 39 | }); | ||
| 40 | |||
| 41 | let p = embassy_stm32::init(Default::default()); | ||
| 42 | |||
| 43 | let button = Input::new(p.PC13, Pull::Down); | ||
| 44 | let mut led1 = Output::new(p.PB0, Level::High); | ||
| 45 | let _led2 = Output::new(p.PB7, Level::High); | ||
| 46 | let mut led3 = Output::new(p.PB14, Level::High); | ||
| 47 | |||
| 48 | loop { | ||
| 49 | if button.is_high().unwrap() { | ||
| 50 | info!("high"); | ||
| 51 | led1.set_high().unwrap(); | ||
| 52 | led3.set_low().unwrap(); | ||
| 53 | } else { | ||
| 54 | info!("low"); | ||
| 55 | led1.set_low().unwrap(); | ||
| 56 | led3.set_high().unwrap(); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | } | ||
