diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-06-12 22:15:44 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-06-12 22:22:31 +0200 |
| commit | a8703b75988e1e700af701116464025679d2feb8 (patch) | |
| tree | f4ec5de70ec05e793a774049e010935ac45853ed /examples/stm32f3/src/bin | |
| parent | 6199bdea710cde33e5d5381b6d6abfc8af46df19 (diff) | |
Run rustfmt.
Diffstat (limited to 'examples/stm32f3/src/bin')
| -rw-r--r-- | examples/stm32f3/src/bin/blinky.rs | 4 | ||||
| -rw-r--r-- | examples/stm32f3/src/bin/button.rs | 3 | ||||
| -rw-r--r-- | examples/stm32f3/src/bin/button_events.rs | 25 | ||||
| -rw-r--r-- | examples/stm32f3/src/bin/button_exti.rs | 3 | ||||
| -rw-r--r-- | examples/stm32f3/src/bin/flash.rs | 4 | ||||
| -rw-r--r-- | examples/stm32f3/src/bin/hello.rs | 7 | ||||
| -rw-r--r-- | examples/stm32f3/src/bin/multiprio.rs | 6 | ||||
| -rw-r--r-- | examples/stm32f3/src/bin/spi_dma.rs | 8 | ||||
| -rw-r--r-- | examples/stm32f3/src/bin/usart_dma.rs | 4 | ||||
| -rw-r--r-- | examples/stm32f3/src/bin/usb_serial.rs | 20 |
10 files changed, 27 insertions, 57 deletions
diff --git a/examples/stm32f3/src/bin/blinky.rs b/examples/stm32f3/src/bin/blinky.rs index 4b181a784..4d0b33f61 100644 --- a/examples/stm32f3/src/bin/blinky.rs +++ b/examples/stm32f3/src/bin/blinky.rs | |||
| @@ -7,9 +7,7 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_stm32::gpio::{Level, Output, Speed}; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 9 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f3/src/bin/button.rs b/examples/stm32f3/src/bin/button.rs index 207381bdd..b55bf3901 100644 --- a/examples/stm32f3/src/bin/button.rs +++ b/examples/stm32f3/src/bin/button.rs | |||
| @@ -4,9 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | use cortex_m_rt::entry; | 5 | use cortex_m_rt::entry; |
| 6 | use defmt::*; | 6 | use defmt::*; |
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 7 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 9 | use panic_probe as _; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 9 | ||
| 11 | #[entry] | 10 | #[entry] |
| 12 | fn main() -> ! { | 11 | fn main() -> ! { |
diff --git a/examples/stm32f3/src/bin/button_events.rs b/examples/stm32f3/src/bin/button_events.rs index 593701799..45862ddc6 100644 --- a/examples/stm32f3/src/bin/button_events.rs +++ b/examples/stm32f3/src/bin/button_events.rs | |||
| @@ -19,9 +19,7 @@ use embassy_stm32::exti::ExtiInput; | |||
| 19 | use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed}; | 19 | use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed}; |
| 20 | use embassy_stm32::peripherals::PA0; | 20 | use embassy_stm32::peripherals::PA0; |
| 21 | use embassy_stm32::Peripherals; | 21 | use embassy_stm32::Peripherals; |
| 22 | 22 | use {defmt_rtt as _, panic_probe as _}; | |
| 23 | use defmt_rtt as _; // global logger | ||
| 24 | use panic_probe as _; | ||
| 25 | 23 | ||
| 26 | struct Leds<'a> { | 24 | struct Leds<'a> { |
| 27 | leds: [Output<'a, AnyPin>; 8], | 25 | leds: [Output<'a, AnyPin>; 8], |
| @@ -57,8 +55,7 @@ impl<'a> Leds<'a> { | |||
| 57 | self.process_event(new_message).await; | 55 | self.process_event(new_message).await; |
| 58 | } else { | 56 | } else { |
| 59 | self.leds[self.current_led].set_low(); | 57 | self.leds[self.current_led].set_low(); |
| 60 | if let Ok(new_message) = with_timeout(Duration::from_millis(200), CHANNEL.recv()).await | 58 | if let Ok(new_message) = with_timeout(Duration::from_millis(200), CHANNEL.recv()).await { |
| 61 | { | ||
| 62 | self.process_event(new_message).await; | 59 | self.process_event(new_message).await; |
| 63 | } | 60 | } |
| 64 | } | 61 | } |
| @@ -137,22 +134,16 @@ async fn button_waiter(mut button: ExtiInput<'static, PA0>) { | |||
| 137 | 134 | ||
| 138 | button.wait_for_rising_edge().await; | 135 | button.wait_for_rising_edge().await; |
| 139 | loop { | 136 | loop { |
| 140 | if with_timeout( | 137 | if with_timeout(Duration::from_millis(HOLD_DELAY), button.wait_for_falling_edge()) |
| 141 | Duration::from_millis(HOLD_DELAY), | 138 | .await |
| 142 | button.wait_for_falling_edge(), | 139 | .is_err() |
| 143 | ) | ||
| 144 | .await | ||
| 145 | .is_err() | ||
| 146 | { | 140 | { |
| 147 | info!("Hold"); | 141 | info!("Hold"); |
| 148 | CHANNEL.send(ButtonEvent::Hold).await; | 142 | CHANNEL.send(ButtonEvent::Hold).await; |
| 149 | button.wait_for_falling_edge().await; | 143 | button.wait_for_falling_edge().await; |
| 150 | } else if with_timeout( | 144 | } else if with_timeout(Duration::from_millis(DOUBLE_CLICK_DELAY), button.wait_for_rising_edge()) |
| 151 | Duration::from_millis(DOUBLE_CLICK_DELAY), | 145 | .await |
| 152 | button.wait_for_rising_edge(), | 146 | .is_err() |
| 153 | ) | ||
| 154 | .await | ||
| 155 | .is_err() | ||
| 156 | { | 147 | { |
| 157 | info!("Single click"); | 148 | info!("Single click"); |
| 158 | CHANNEL.send(ButtonEvent::SingleClick).await; | 149 | CHANNEL.send(ButtonEvent::SingleClick).await; |
diff --git a/examples/stm32f3/src/bin/button_exti.rs b/examples/stm32f3/src/bin/button_exti.rs index 68d166367..add6712b4 100644 --- a/examples/stm32f3/src/bin/button_exti.rs +++ b/examples/stm32f3/src/bin/button_exti.rs | |||
| @@ -3,12 +3,11 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use defmt_rtt as _; // global logger | ||
| 7 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 8 | use embassy_stm32::exti::ExtiInput; | 7 | use embassy_stm32::exti::ExtiInput; |
| 9 | use embassy_stm32::gpio::{Input, Pull}; | 8 | use embassy_stm32::gpio::{Input, Pull}; |
| 10 | use embassy_stm32::Peripherals; | 9 | use embassy_stm32::Peripherals; |
| 11 | use panic_probe as _; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 11 | ||
| 13 | #[embassy::main] | 12 | #[embassy::main] |
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f3/src/bin/flash.rs b/examples/stm32f3/src/bin/flash.rs index 3890f0514..ce16f6de7 100644 --- a/examples/stm32f3/src/bin/flash.rs +++ b/examples/stm32f3/src/bin/flash.rs | |||
| @@ -7,9 +7,7 @@ use embassy::executor::Spawner; | |||
| 7 | use embassy_stm32::flash::Flash; | 7 | use embassy_stm32::flash::Flash; |
| 8 | use embassy_stm32::Peripherals; | 8 | use embassy_stm32::Peripherals; |
| 9 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; | 9 | use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; |
| 10 | 10 | use {defmt_rtt as _, panic_probe as _}; | |
| 11 | use defmt_rtt as _; // global logger | ||
| 12 | use panic_probe as _; | ||
| 13 | 11 | ||
| 14 | #[embassy::main] | 12 | #[embassy::main] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 13 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f3/src/bin/hello.rs b/examples/stm32f3/src/bin/hello.rs index a79d6838c..3b89f1c72 100644 --- a/examples/stm32f3/src/bin/hello.rs +++ b/examples/stm32f3/src/bin/hello.rs | |||
| @@ -6,11 +6,8 @@ use defmt::info; | |||
| 6 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 7 | use embassy::time::{Duration, Timer}; | 7 | use embassy::time::{Duration, Timer}; |
| 8 | use embassy_stm32::time::Hertz; | 8 | use embassy_stm32::time::Hertz; |
| 9 | use embassy_stm32::Config; | 9 | use embassy_stm32::{Config, Peripherals}; |
| 10 | use embassy_stm32::Peripherals; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | |||
| 12 | use defmt_rtt as _; // global logger | ||
| 13 | use panic_probe as _; | ||
| 14 | 11 | ||
| 15 | fn config() -> Config { | 12 | fn config() -> Config { |
| 16 | let mut config = Config::default(); | 13 | let mut config = Config::default(); |
diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs index 684295609..4f2cf9a6f 100644 --- a/examples/stm32f3/src/bin/multiprio.rs +++ b/examples/stm32f3/src/bin/multiprio.rs | |||
| @@ -57,16 +57,14 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use defmt::*; | ||
| 61 | use defmt_rtt as _; // global logger | ||
| 62 | use panic_probe as _; | ||
| 63 | |||
| 64 | use cortex_m_rt::entry; | 60 | use cortex_m_rt::entry; |
| 61 | use defmt::*; | ||
| 65 | use embassy::time::{Duration, Instant, Timer}; | 62 | use embassy::time::{Duration, Instant, Timer}; |
| 66 | use embassy::util::Forever; | 63 | use embassy::util::Forever; |
| 67 | use embassy_stm32::executor::{Executor, InterruptExecutor}; | 64 | use embassy_stm32::executor::{Executor, InterruptExecutor}; |
| 68 | use embassy_stm32::interrupt; | 65 | use embassy_stm32::interrupt; |
| 69 | use embassy_stm32::interrupt::InterruptExt; | 66 | use embassy_stm32::interrupt::InterruptExt; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | ||
| 70 | 68 | ||
| 71 | #[embassy::task] | 69 | #[embassy::task] |
| 72 | async fn run_high() { | 70 | async fn run_high() { |
diff --git a/examples/stm32f3/src/bin/spi_dma.rs b/examples/stm32f3/src/bin/spi_dma.rs index 6d80c4087..ece1ae6fe 100644 --- a/examples/stm32f3/src/bin/spi_dma.rs +++ b/examples/stm32f3/src/bin/spi_dma.rs | |||
| @@ -4,14 +4,14 @@ | |||
| 4 | 4 | ||
| 5 | use core::fmt::Write; | 5 | use core::fmt::Write; |
| 6 | use core::str::from_utf8; | 6 | use core::str::from_utf8; |
| 7 | |||
| 7 | use defmt::*; | 8 | use defmt::*; |
| 8 | use defmt_rtt as _; // global logger | ||
| 9 | use embassy::executor::Spawner; | 9 | 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 heapless::String; | 13 | use heapless::String; |
| 14 | use panic_probe as _; | 14 | use {defmt_rtt as _, panic_probe as _}; |
| 15 | 15 | ||
| 16 | #[embassy::main] | 16 | #[embassy::main] |
| 17 | async fn main(_spawner: Spawner, p: Peripherals) { | 17 | async fn main(_spawner: Spawner, p: Peripherals) { |
| @@ -32,9 +32,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 32 | let mut write: String<128> = String::new(); | 32 | let mut write: String<128> = String::new(); |
| 33 | let mut read = [0; 128]; | 33 | let mut read = [0; 128]; |
| 34 | core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); | 34 | core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); |
| 35 | spi.transfer(&mut read[0..write.len()], write.as_bytes()) | 35 | spi.transfer(&mut read[0..write.len()], write.as_bytes()).await.ok(); |
| 36 | .await | ||
| 37 | .ok(); | ||
| 38 | info!("read via spi+dma: {}", from_utf8(&read).unwrap()); | 36 | info!("read via spi+dma: {}", from_utf8(&read).unwrap()); |
| 39 | } | 37 | } |
| 40 | } | 38 | } |
diff --git a/examples/stm32f3/src/bin/usart_dma.rs b/examples/stm32f3/src/bin/usart_dma.rs index 859749eb7..4660f812e 100644 --- a/examples/stm32f3/src/bin/usart_dma.rs +++ b/examples/stm32f3/src/bin/usart_dma.rs | |||
| @@ -3,14 +3,14 @@ | |||
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use core::fmt::Write; | 5 | use core::fmt::Write; |
| 6 | |||
| 6 | use defmt::*; | 7 | use defmt::*; |
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy::executor::Spawner; | 8 | 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 heapless::String; | 12 | use heapless::String; |
| 13 | use panic_probe as _; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 14 | ||
| 15 | #[embassy::main] | 15 | #[embassy::main] |
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | 16 | async fn main(_spawner: Spawner, p: Peripherals) { |
diff --git a/examples/stm32f3/src/bin/usb_serial.rs b/examples/stm32f3/src/bin/usb_serial.rs index fc33d0bc7..8a76d4546 100644 --- a/examples/stm32f3/src/bin/usb_serial.rs +++ b/examples/stm32f3/src/bin/usb_serial.rs | |||
| @@ -2,24 +2,18 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use defmt::panic; | 5 | use defmt::{panic, *}; |
| 6 | use defmt::*; | ||
| 7 | use defmt_rtt as _; // global logger | ||
| 8 | use embassy::executor::Spawner; | 6 | use embassy::executor::Spawner; |
| 9 | use embassy::time::Duration; | 7 | use embassy::time::{Duration, Timer}; |
| 10 | use embassy::time::Timer; | 8 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 11 | use embassy_stm32::gpio::Level; | ||
| 12 | use embassy_stm32::gpio::Output; | ||
| 13 | use embassy_stm32::gpio::Speed; | ||
| 14 | use embassy_stm32::interrupt; | ||
| 15 | use embassy_stm32::time::U32Ext; | 9 | use embassy_stm32::time::U32Ext; |
| 16 | use embassy_stm32::usb::{Driver, Instance}; | 10 | use embassy_stm32::usb::{Driver, Instance}; |
| 17 | use embassy_stm32::{Config, Peripherals}; | 11 | use embassy_stm32::{interrupt, Config, Peripherals}; |
| 18 | use embassy_usb::driver::EndpointError; | 12 | use embassy_usb::driver::EndpointError; |
| 19 | use embassy_usb::Builder; | 13 | use embassy_usb::Builder; |
| 20 | use embassy_usb_serial::{CdcAcmClass, State}; | 14 | use embassy_usb_serial::{CdcAcmClass, State}; |
| 21 | use futures::future::join; | 15 | use futures::future::join; |
| 22 | use panic_probe as _; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 23 | 17 | ||
| 24 | fn config() -> Config { | 18 | fn config() -> Config { |
| 25 | let mut config = Config::default(); | 19 | let mut config = Config::default(); |
| @@ -103,9 +97,7 @@ impl From<EndpointError> for Disconnected { | |||
| 103 | } | 97 | } |
| 104 | } | 98 | } |
| 105 | 99 | ||
| 106 | async fn echo<'d, T: Instance + 'd>( | 100 | async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> { |
| 107 | class: &mut CdcAcmClass<'d, Driver<'d, T>>, | ||
| 108 | ) -> Result<(), Disconnected> { | ||
| 109 | let mut buf = [0; 64]; | 101 | let mut buf = [0; 64]; |
| 110 | loop { | 102 | loop { |
| 111 | let n = class.read_packet(&mut buf).await?; | 103 | let n = class.read_packet(&mut buf).await?; |
