diff options
| author | Bob McWhirter <[email protected]> | 2021-06-08 10:36:47 -0400 |
|---|---|---|
| committer | Bob McWhirter <[email protected]> | 2021-06-08 10:37:11 -0400 |
| commit | cf3c021c3745c3f555b650f019fd8b1d4982443b (patch) | |
| tree | b91651e5af61fd57b591df4e4c15ffe74f58751e /examples/stm32l4/src/bin/button.rs | |
| parent | b8690e5f5d7b6996e833e9866629f298f88289fe (diff) | |
Initial examples for STM32L4+
Diffstat (limited to 'examples/stm32l4/src/bin/button.rs')
| -rw-r--r-- | examples/stm32l4/src/bin/button.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/examples/stm32l4/src/bin/button.rs b/examples/stm32l4/src/bin/button.rs new file mode 100644 index 000000000..43d81715a --- /dev/null +++ b/examples/stm32l4/src/bin/button.rs | |||
| @@ -0,0 +1,58 @@ | |||
| 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 stm32l4::stm32l4x5 as pac; | ||
| 17 | |||
| 18 | |||
| 19 | #[entry] | ||
| 20 | fn main() -> ! { | ||
| 21 | info!("Hello World!"); | ||
| 22 | |||
| 23 | let pp = pac::Peripherals::take().unwrap(); | ||
| 24 | |||
| 25 | pp.DBGMCU.cr.modify(|_, w| { | ||
| 26 | w.dbg_sleep().set_bit(); | ||
| 27 | w.dbg_standby().set_bit(); | ||
| 28 | w.dbg_stop().set_bit() | ||
| 29 | }); | ||
| 30 | |||
| 31 | pp.RCC.ahb2enr.modify(|_, w| { | ||
| 32 | w.gpioaen().set_bit(); | ||
| 33 | w.gpioben().set_bit(); | ||
| 34 | w.gpiocen().set_bit(); | ||
| 35 | w.gpioden().set_bit(); | ||
| 36 | w.gpioeen().set_bit(); | ||
| 37 | w.gpiofen().set_bit(); | ||
| 38 | w | ||
| 39 | }); | ||
| 40 | |||
| 41 | let p = embassy_stm32::init(Default::default()); | ||
| 42 | |||
| 43 | let button = Input::new(p.PC13, Pull::Up); | ||
| 44 | let mut led1 = Output::new(p.PA5, Level::High); | ||
| 45 | let mut led2 = Output::new(p.PB14, Level::High); | ||
| 46 | |||
| 47 | loop { | ||
| 48 | if button.is_high().unwrap() { | ||
| 49 | info!("high"); | ||
| 50 | led1.set_high().unwrap(); | ||
| 51 | led2.set_low().unwrap(); | ||
| 52 | } else { | ||
| 53 | info!("low"); | ||
| 54 | led1.set_low().unwrap(); | ||
| 55 | led2.set_high().unwrap(); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | } | ||
