aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32l4
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-01-14 22:02:00 +0100
committerDario Nieuwenhuis <[email protected]>2022-01-19 17:59:55 +0100
commit58fc64722c65bbdc209ae0fd1700f03702bbcd08 (patch)
tree77f9412b47259cd4cf4170b0a257b371398d4f2c /examples/stm32l4
parent52e156b429417bde59d0ea67d11256866f1dcec9 (diff)
stm32/gpio: expose all functionality as inherent methods.
Diffstat (limited to 'examples/stm32l4')
-rw-r--r--examples/stm32l4/src/bin/blinky.rs5
-rw-r--r--examples/stm32l4/src/bin/button.rs3
-rw-r--r--examples/stm32l4/src/bin/spi.rs5
-rw-r--r--examples/stm32l4/src/bin/spi_blocking_async.rs9
-rw-r--r--examples/stm32l4/src/bin/spi_dma.rs9
5 files changed, 13 insertions, 18 deletions
diff --git a/examples/stm32l4/src/bin/blinky.rs b/examples/stm32l4/src/bin/blinky.rs
index 8a65858f8..030283756 100644
--- a/examples/stm32l4/src/bin/blinky.rs
+++ b/examples/stm32l4/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -18,9 +17,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
18 let mut led = Output::new(p.PB14, Level::High, Speed::Low); 17 let mut led = Output::new(p.PB14, Level::High, Speed::Low);
19 18
20 loop { 19 loop {
21 unwrap!(led.set_high()); 20 led.set_high();
22 Timer::after(Duration::from_millis(300)).await; 21 Timer::after(Duration::from_millis(300)).await;
23 unwrap!(led.set_low()); 22 led.set_low();
24 Timer::after(Duration::from_millis(300)).await; 23 Timer::after(Duration::from_millis(300)).await;
25 } 24 }
26} 25}
diff --git a/examples/stm32l4/src/bin/button.rs b/examples/stm32l4/src/bin/button.rs
index fd8674549..6073c137e 100644
--- a/examples/stm32l4/src/bin/button.rs
+++ b/examples/stm32l4/src/bin/button.rs
@@ -5,7 +5,6 @@
5#[path = "../example_common.rs"] 5#[path = "../example_common.rs"]
6mod example_common; 6mod example_common;
7use embassy_stm32::gpio::{Input, Pull}; 7use embassy_stm32::gpio::{Input, Pull};
8use embedded_hal::digital::v2::InputPin;
9use example_common::*; 8use example_common::*;
10 9
11#[cortex_m_rt::entry] 10#[cortex_m_rt::entry]
@@ -17,7 +16,7 @@ fn main() -> ! {
17 let button = Input::new(p.PC13, Pull::Up); 16 let button = Input::new(p.PC13, Pull::Up);
18 17
19 loop { 18 loop {
20 if unwrap!(button.is_high()) { 19 if button.is_high() {
21 info!("high"); 20 info!("high");
22 } else { 21 } else {
23 info!("low"); 22 info!("low");
diff --git a/examples/stm32l4/src/bin/spi.rs b/examples/stm32l4/src/bin/spi.rs
index 5b9ae1ce0..1b6e3946e 100644
--- a/examples/stm32l4/src/bin/spi.rs
+++ b/examples/stm32l4/src/bin/spi.rs
@@ -10,7 +10,6 @@ use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::spi::{Config, Spi}; 10use embassy_stm32::spi::{Config, Spi};
11use embassy_stm32::time::Hertz; 11use embassy_stm32::time::Hertz;
12use embedded_hal::blocking::spi::Transfer; 12use embedded_hal::blocking::spi::Transfer;
13use embedded_hal::digital::v2::OutputPin;
14use example_common::*; 13use example_common::*;
15 14
16#[cortex_m_rt::entry] 15#[cortex_m_rt::entry]
@@ -34,9 +33,9 @@ fn main() -> ! {
34 33
35 loop { 34 loop {
36 let mut buf = [0x0Au8; 4]; 35 let mut buf = [0x0Au8; 4];
37 unwrap!(cs.set_low()); 36 cs.set_low();
38 unwrap!(spi.transfer(&mut buf)); 37 unwrap!(spi.transfer(&mut buf));
39 unwrap!(cs.set_high()); 38 cs.set_high();
40 info!("xfer {=[u8]:x}", buf); 39 info!("xfer {=[u8]:x}", buf);
41 } 40 }
42} 41}
diff --git a/examples/stm32l4/src/bin/spi_blocking_async.rs b/examples/stm32l4/src/bin/spi_blocking_async.rs
index f092706d4..3be3f21c9 100644
--- a/examples/stm32l4/src/bin/spi_blocking_async.rs
+++ b/examples/stm32l4/src/bin/spi_blocking_async.rs
@@ -12,7 +12,6 @@ use embassy_stm32::spi::{Config, Spi};
12use embassy_stm32::time::Hertz; 12use embassy_stm32::time::Hertz;
13use embassy_stm32::Peripherals; 13use embassy_stm32::Peripherals;
14use embassy_traits::{adapter::BlockingAsync, spi::FullDuplex}; 14use embassy_traits::{adapter::BlockingAsync, spi::FullDuplex};
15use embedded_hal::digital::v2::{InputPin, OutputPin};
16use example_common::*; 15use example_common::*;
17 16
18#[embassy::main] 17#[embassy::main]
@@ -41,17 +40,17 @@ async fn main(_spawner: Spawner, p: Peripherals) {
41 let ready = Input::new(p.PE1, Pull::Up); 40 let ready = Input::new(p.PE1, Pull::Up);
42 41
43 cortex_m::asm::delay(100_000); 42 cortex_m::asm::delay(100_000);
44 unwrap!(reset.set_high()); 43 reset.set_high();
45 cortex_m::asm::delay(100_000); 44 cortex_m::asm::delay(100_000);
46 45
47 while unwrap!(ready.is_low()) { 46 while ready.is_low() {
48 info!("waiting for ready"); 47 info!("waiting for ready");
49 } 48 }
50 49
51 let write = [0x0A; 10]; 50 let write = [0x0A; 10];
52 let mut read = [0; 10]; 51 let mut read = [0; 10];
53 unwrap!(cs.set_low()); 52 cs.set_low();
54 spi.read_write(&mut read, &write).await.ok(); 53 spi.read_write(&mut read, &write).await.ok();
55 unwrap!(cs.set_high()); 54 cs.set_high();
56 info!("xfer {=[u8]:x}", read); 55 info!("xfer {=[u8]:x}", read);
57} 56}
diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs
index 4b74c7d7d..d6464bbfa 100644
--- a/examples/stm32l4/src/bin/spi_dma.rs
+++ b/examples/stm32l4/src/bin/spi_dma.rs
@@ -11,7 +11,6 @@ use embassy_stm32::spi::{Config, Spi};
11use embassy_stm32::time::Hertz; 11use embassy_stm32::time::Hertz;
12use embassy_stm32::Peripherals; 12use embassy_stm32::Peripherals;
13use embassy_traits::spi::FullDuplex; 13use embassy_traits::spi::FullDuplex;
14use embedded_hal::digital::v2::{InputPin, OutputPin};
15use example_common::*; 14use example_common::*;
16 15
17#[embassy::main] 16#[embassy::main]
@@ -38,17 +37,17 @@ async fn main(_spawner: Spawner, p: Peripherals) {
38 let ready = Input::new(p.PE1, Pull::Up); 37 let ready = Input::new(p.PE1, Pull::Up);
39 38
40 cortex_m::asm::delay(100_000); 39 cortex_m::asm::delay(100_000);
41 unwrap!(reset.set_high()); 40 reset.set_high();
42 cortex_m::asm::delay(100_000); 41 cortex_m::asm::delay(100_000);
43 42
44 while unwrap!(ready.is_low()) { 43 while ready.is_low() {
45 info!("waiting for ready"); 44 info!("waiting for ready");
46 } 45 }
47 46
48 let write = [0x0A; 10]; 47 let write = [0x0A; 10];
49 let mut read = [0; 10]; 48 let mut read = [0; 10];
50 unwrap!(cs.set_low()); 49 cs.set_low();
51 spi.read_write(&mut read, &write).await.ok(); 50 spi.read_write(&mut read, &write).await.ok();
52 unwrap!(cs.set_high()); 51 cs.set_high();
53 info!("xfer {=[u8]:x}", read); 52 info!("xfer {=[u8]:x}", read);
54} 53}