diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-01-19 20:47:07 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-01-19 20:47:07 +0000 |
| commit | 6b0cb0609b4bfa3e464e4603ce373a9de9886103 (patch) | |
| tree | 70a6590ad9da8c625eb69c21faddb5721bfbcea4 /examples/stm32f4/src | |
| parent | 071b034a5dbece727b28aee6362e36d66bcb763b (diff) | |
| parent | 889d757ab8bcfc10caf0a7d75ffb7733a7e71ed1 (diff) | |
Merge #581
581: stm32: expose all functionality as inherent methods. r=Dirbaio a=Dirbaio
This is the previous step to implementing both the embedded-hal 0.2 and embedded-hal 1.0 + embedded-hal-async traits.
The equivalent in nrf was done in #552
- Removes need for `unwrap` in gpio.
- Removes need for `use embedded_hal::whatever` in all cases.
Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'examples/stm32f4/src')
| -rw-r--r-- | examples/stm32f4/src/bin/blinky.rs | 5 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/button.rs | 11 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/button_exti.rs | 1 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/spi.rs | 8 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/spi_dma.rs | 3 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/usart.rs | 7 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/usart_dma.rs | 1 |
7 files changed, 14 insertions, 22 deletions
diff --git a/examples/stm32f4/src/bin/blinky.rs b/examples/stm32f4/src/bin/blinky.rs index c4857195f..00d67dac0 100644 --- a/examples/stm32f4/src/bin/blinky.rs +++ b/examples/stm32f4/src/bin/blinky.rs | |||
| @@ -8,7 +8,6 @@ use embassy::executor::Spawner; | |||
| 8 | use embassy::time::{Duration, Timer}; | 8 | use embassy::time::{Duration, Timer}; |
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | 9 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 10 | use embassy_stm32::Peripherals; | 10 | use embassy_stm32::Peripherals; |
| 11 | use embedded_hal::digital::v2::OutputPin; | ||
| 12 | use example_common::*; | 11 | use example_common::*; |
| 13 | 12 | ||
| 14 | #[embassy::main] | 13 | #[embassy::main] |
| @@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 19 | 18 | ||
| 20 | loop { | 19 | loop { |
| 21 | info!("high"); | 20 | info!("high"); |
| 22 | unwrap!(led.set_high()); | 21 | led.set_high(); |
| 23 | Timer::after(Duration::from_millis(300)).await; | 22 | Timer::after(Duration::from_millis(300)).await; |
| 24 | 23 | ||
| 25 | info!("low"); | 24 | info!("low"); |
| 26 | unwrap!(led.set_low()); | 25 | led.set_low(); |
| 27 | Timer::after(Duration::from_millis(300)).await; | 26 | Timer::after(Duration::from_millis(300)).await; |
| 28 | } | 27 | } |
| 29 | } | 28 | } |
diff --git a/examples/stm32f4/src/bin/button.rs b/examples/stm32f4/src/bin/button.rs index 95dee7c74..24eef75b2 100644 --- a/examples/stm32f4/src/bin/button.rs +++ b/examples/stm32f4/src/bin/button.rs | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | mod example_common; | 6 | mod example_common; |
| 7 | use cortex_m_rt::entry; | 7 | use cortex_m_rt::entry; |
| 8 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 8 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 9 | use embedded_hal::digital::v2::{InputPin, OutputPin}; | ||
| 10 | use example_common::*; | 9 | use example_common::*; |
| 11 | 10 | ||
| 12 | #[entry] | 11 | #[entry] |
| @@ -21,14 +20,14 @@ fn main() -> ! { | |||
| 21 | let mut led3 = Output::new(p.PB14, Level::High, Speed::Low); | 20 | let mut led3 = Output::new(p.PB14, Level::High, Speed::Low); |
| 22 | 21 | ||
| 23 | loop { | 22 | loop { |
| 24 | if unwrap!(button.is_high()) { | 23 | if button.is_high() { |
| 25 | info!("high"); | 24 | info!("high"); |
| 26 | unwrap!(led1.set_high()); | 25 | led1.set_high(); |
| 27 | unwrap!(led3.set_low()); | 26 | led3.set_low(); |
| 28 | } else { | 27 | } else { |
| 29 | info!("low"); | 28 | info!("low"); |
| 30 | unwrap!(led1.set_low()); | 29 | led1.set_low(); |
| 31 | unwrap!(led3.set_high()); | 30 | led3.set_high(); |
| 32 | } | 31 | } |
| 33 | } | 32 | } |
| 34 | } | 33 | } |
diff --git a/examples/stm32f4/src/bin/button_exti.rs b/examples/stm32f4/src/bin/button_exti.rs index 2c4318d64..852fbe3c6 100644 --- a/examples/stm32f4/src/bin/button_exti.rs +++ b/examples/stm32f4/src/bin/button_exti.rs | |||
| @@ -8,7 +8,6 @@ use embassy::executor::Spawner; | |||
| 8 | use embassy_stm32::exti::ExtiInput; | 8 | use embassy_stm32::exti::ExtiInput; |
| 9 | use embassy_stm32::gpio::{Input, Pull}; | 9 | use embassy_stm32::gpio::{Input, Pull}; |
| 10 | use embassy_stm32::Peripherals; | 10 | use embassy_stm32::Peripherals; |
| 11 | use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge}; | ||
| 12 | use example_common::*; | 11 | use example_common::*; |
| 13 | 12 | ||
| 14 | #[embassy::main] | 13 | #[embassy::main] |
diff --git a/examples/stm32f4/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs index 0192e1865..6b04f1fed 100644 --- a/examples/stm32f4/src/bin/spi.rs +++ b/examples/stm32f4/src/bin/spi.rs | |||
| @@ -10,8 +10,6 @@ use embassy_stm32::dma::NoDma; | |||
| 10 | use embassy_stm32::gpio::{Level, Output, Speed}; | 10 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 11 | use embassy_stm32::spi::{Config, Spi}; | 11 | use embassy_stm32::spi::{Config, Spi}; |
| 12 | use embassy_stm32::time::Hertz; | 12 | use embassy_stm32::time::Hertz; |
| 13 | use embedded_hal::blocking::spi::Transfer; | ||
| 14 | use embedded_hal::digital::v2::OutputPin; | ||
| 15 | use example_common::*; | 13 | use example_common::*; |
| 16 | 14 | ||
| 17 | #[entry] | 15 | #[entry] |
| @@ -35,9 +33,9 @@ fn main() -> ! { | |||
| 35 | 33 | ||
| 36 | loop { | 34 | loop { |
| 37 | let mut buf = [0x0Au8; 4]; | 35 | let mut buf = [0x0Au8; 4]; |
| 38 | unwrap!(cs.set_low()); | 36 | cs.set_low(); |
| 39 | unwrap!(spi.transfer(&mut buf)); | 37 | unwrap!(spi.blocking_transfer_in_place(&mut buf)); |
| 40 | unwrap!(cs.set_high()); | 38 | cs.set_high(); |
| 41 | info!("xfer {=[u8]:x}", buf); | 39 | info!("xfer {=[u8]:x}", buf); |
| 42 | } | 40 | } |
| 43 | } | 41 | } |
diff --git a/examples/stm32f4/src/bin/spi_dma.rs b/examples/stm32f4/src/bin/spi_dma.rs index b3bf6fc28..9171f7516 100644 --- a/examples/stm32f4/src/bin/spi_dma.rs +++ b/examples/stm32f4/src/bin/spi_dma.rs | |||
| @@ -10,7 +10,6 @@ use embassy::executor::Spawner; | |||
| 10 | use embassy_stm32::spi::{Config, Spi}; | 10 | use embassy_stm32::spi::{Config, Spi}; |
| 11 | use embassy_stm32::time::Hertz; | 11 | use embassy_stm32::time::Hertz; |
| 12 | use embassy_stm32::Peripherals; | 12 | use embassy_stm32::Peripherals; |
| 13 | use embassy_traits::spi::FullDuplex; | ||
| 14 | use example_common::*; | 13 | use example_common::*; |
| 15 | use heapless::String; | 14 | use heapless::String; |
| 16 | 15 | ||
| @@ -33,7 +32,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 33 | let mut write: String<128> = String::new(); | 32 | let mut write: String<128> = String::new(); |
| 34 | let mut read = [0; 128]; | 33 | let mut read = [0; 128]; |
| 35 | core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); | 34 | core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); |
| 36 | spi.read_write(&mut read[0..write.len()], write.as_bytes()) | 35 | spi.transfer(&mut read[0..write.len()], write.as_bytes()) |
| 37 | .await | 36 | .await |
| 38 | .ok(); | 37 | .ok(); |
| 39 | info!("read via spi+dma: {}", from_utf8(&read).unwrap()); | 38 | info!("read via spi+dma: {}", from_utf8(&read).unwrap()); |
diff --git a/examples/stm32f4/src/bin/usart.rs b/examples/stm32f4/src/bin/usart.rs index 391a8b9b0..b5ea98cca 100644 --- a/examples/stm32f4/src/bin/usart.rs +++ b/examples/stm32f4/src/bin/usart.rs | |||
| @@ -7,7 +7,6 @@ mod example_common; | |||
| 7 | use cortex_m_rt::entry; | 7 | use cortex_m_rt::entry; |
| 8 | use embassy_stm32::dma::NoDma; | 8 | use embassy_stm32::dma::NoDma; |
| 9 | use embassy_stm32::usart::{Config, Uart}; | 9 | use embassy_stm32::usart::{Config, Uart}; |
| 10 | use embedded_hal::blocking::serial::Write; | ||
| 11 | use example_common::*; | 10 | use example_common::*; |
| 12 | 11 | ||
| 13 | #[entry] | 12 | #[entry] |
| @@ -19,12 +18,12 @@ fn main() -> ! { | |||
| 19 | let config = Config::default(); | 18 | let config = Config::default(); |
| 20 | let mut usart = Uart::new(p.USART3, p.PD9, p.PD8, NoDma, NoDma, config); | 19 | let mut usart = Uart::new(p.USART3, p.PD9, p.PD8, NoDma, NoDma, config); |
| 21 | 20 | ||
| 22 | unwrap!(usart.bwrite_all(b"Hello Embassy World!\r\n")); | 21 | unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n")); |
| 23 | info!("wrote Hello, starting echo"); | 22 | info!("wrote Hello, starting echo"); |
| 24 | 23 | ||
| 25 | let mut buf = [0u8; 1]; | 24 | let mut buf = [0u8; 1]; |
| 26 | loop { | 25 | loop { |
| 27 | unwrap!(usart.read_blocking(&mut buf)); | 26 | unwrap!(usart.blocking_read(&mut buf)); |
| 28 | unwrap!(usart.bwrite_all(&buf)); | 27 | unwrap!(usart.blocking_write(&buf)); |
| 29 | } | 28 | } |
| 30 | } | 29 | } |
diff --git a/examples/stm32f4/src/bin/usart_dma.rs b/examples/stm32f4/src/bin/usart_dma.rs index 0dbdd7c05..862a91ea8 100644 --- a/examples/stm32f4/src/bin/usart_dma.rs +++ b/examples/stm32f4/src/bin/usart_dma.rs | |||
| @@ -9,7 +9,6 @@ use embassy::executor::Spawner; | |||
| 9 | use embassy_stm32::dma::NoDma; | 9 | use embassy_stm32::dma::NoDma; |
| 10 | use embassy_stm32::usart::{Config, Uart}; | 10 | use embassy_stm32::usart::{Config, Uart}; |
| 11 | use embassy_stm32::Peripherals; | 11 | use embassy_stm32::Peripherals; |
| 12 | use embassy_traits::uart::Write as _; | ||
| 13 | use example_common::*; | 12 | use example_common::*; |
| 14 | use heapless::String; | 13 | use heapless::String; |
| 15 | 14 | ||
