aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f4/src/bin/button.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-06-02 01:30:07 +0200
committerDario Nieuwenhuis <[email protected]>2021-06-02 01:32:19 +0200
commitdff03ecfc74d6af716637888338ebfa99ab7a027 (patch)
treec06bf2b0a2e6657c3427c956dbd27a4e45211aaa /examples/stm32f4/src/bin/button.rs
parenta0c5f7137fe0c45b8db0aad2a116aea91e6a93f7 (diff)
Move examples to a subdirectory
Diffstat (limited to 'examples/stm32f4/src/bin/button.rs')
-rw-r--r--examples/stm32f4/src/bin/button.rs59
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"]
10mod example_common;
11use embassy_stm32::gpio::{Input, Level, Output, Pull};
12use embedded_hal::digital::v2::{InputPin, OutputPin};
13use example_common::*;
14
15use cortex_m_rt::entry;
16use stm32f4::stm32f429 as pac;
17
18#[entry]
19fn 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}