rustfmt on previously edited files

This commit is contained in:
amugniere@gmail.com 2022-07-10 21:08:12 +02:00
parent 53388d4576
commit e4a36e1d98
2 changed files with 22 additions and 26 deletions

View File

@ -23,7 +23,7 @@ impl<'d, T: Pin> Flex<'d, T> {
/// The pin remains disconnected. The initial output level is unspecified, but can be changed /// The pin remains disconnected. The initial output level is unspecified, but can be changed
/// before the pin is put into output mode. /// before the pin is put into output mode.
/// ///
#[inline] #[inline]
pub fn new(pin: impl Unborrow<Target = T> + 'd) -> Self { pub fn new(pin: impl Unborrow<Target = T> + 'd) -> Self {
unborrow!(pin); unborrow!(pin);
// Pin will be in disconnected state. // Pin will be in disconnected state.
@ -32,9 +32,9 @@ impl<'d, T: Pin> Flex<'d, T> {
phantom: PhantomData, phantom: PhantomData,
} }
} }
/// Put the pin into input mode. /// Put the pin into input mode.
#[inline] #[inline]
pub fn set_as_input(&mut self, pull: Pull) { pub fn set_as_input(&mut self, pull: Pull) {
critical_section::with(|_| unsafe { critical_section::with(|_| unsafe {
let r = self.pin.block(); let r = self.pin.block();
@ -74,7 +74,6 @@ impl<'d, T: Pin> Flex<'d, T> {
/// at a specific level, call `set_high`/`set_low` on the pin first. /// at a specific level, call `set_high`/`set_low` on the pin first.
#[inline] #[inline]
pub fn set_as_output(&mut self, speed: Speed) { pub fn set_as_output(&mut self, speed: Speed) {
critical_section::with(|_| unsafe { critical_section::with(|_| unsafe {
let r = self.pin.block(); let r = self.pin.block();
let n = self.pin.pin() as usize; let n = self.pin.pin() as usize;
@ -95,7 +94,7 @@ impl<'d, T: Pin> Flex<'d, T> {
} }
}); });
} }
/// Put the pin into input + output mode. /// Put the pin into input + output mode.
/// ///
/// This is commonly used for "open drain" mode. /// This is commonly used for "open drain" mode.
@ -106,7 +105,7 @@ impl<'d, T: Pin> Flex<'d, T> {
/// The pin level will be whatever was set before (or low by default). If you want it to begin /// The pin level will be whatever was set before (or low by default). If you want it to begin
/// at a specific level, call `set_high`/`set_low` on the pin first. /// at a specific level, call `set_high`/`set_low` on the pin first.
#[inline] #[inline]
pub fn set_as_input_output(&mut self,speed: Speed, pull : Pull) { pub fn set_as_input_output(&mut self, speed: Speed, pull: Pull) {
critical_section::with(|_| unsafe { critical_section::with(|_| unsafe {
let r = self.pin.block(); let r = self.pin.block();
let n = self.pin.pin() as usize; let n = self.pin.pin() as usize;
@ -164,7 +163,7 @@ impl<'d, T: Pin> Flex<'d, T> {
pub fn set_low(&mut self) { pub fn set_low(&mut self) {
self.pin.set_low(); self.pin.set_low();
} }
/// Toggle pin output /// Toggle pin output
#[inline] #[inline]
pub fn toggle(&mut self) { pub fn toggle(&mut self) {
@ -262,7 +261,7 @@ impl From<Speed> for vals::Ospeedr {
/// GPIO input driver. /// GPIO input driver.
pub struct Input<'d, T: Pin> { pub struct Input<'d, T: Pin> {
pub(crate) pin: Flex<'d, T> pub(crate) pin: Flex<'d, T>,
} }
impl<'d, T: Pin> Input<'d, T> { impl<'d, T: Pin> Input<'d, T> {
@ -340,10 +339,9 @@ impl<'d, T: Pin> Output<'d, T> {
} }
} }
/// GPIO output open-drain driver. /// GPIO output open-drain driver.
pub struct OutputOpenDrain<'d, T: Pin> { pub struct OutputOpenDrain<'d, T: Pin> {
pub(crate) pin: Flex<'d, T> pub(crate) pin: Flex<'d, T>,
} }
impl<'d, T: Pin> OutputOpenDrain<'d, T> { impl<'d, T: Pin> OutputOpenDrain<'d, T> {
@ -925,10 +923,9 @@ mod eh1 {
Ok(self.is_set_low()) Ok(self.is_set_low())
} }
} }
} }
#[cfg(feature = "unstable-pac")] #[cfg(feature = "unstable-pac")]
pub mod low_level { pub mod low_level {
pub use super::sealed::*; pub use super::sealed::*;
} }

View File

@ -6,7 +6,7 @@
mod example_common; mod example_common;
use defmt::assert; use defmt::assert;
use embassy::executor::Spawner; use embassy::executor::Spawner;
use embassy_stm32::gpio::{Input, Level, Output, OutputOpenDrain, Flex, Pull, Speed}; use embassy_stm32::gpio::{Flex, Input, Level, Output, OutputOpenDrain, Pull, Speed};
use embassy_stm32::Peripherals; use embassy_stm32::Peripherals;
use example_common::*; use example_common::*;
@ -104,21 +104,21 @@ async fn main(_spawner: Spawner, p: Peripherals) {
// FLEX // FLEX
// Test initial output // Test initial output
{ {
//Flex pin configured as input //Flex pin configured as input
let mut b = Flex::new(&mut b); let mut b = Flex::new(&mut b);
b.set_as_input(Pull::None); b.set_as_input(Pull::None);
{ {
//Flex pin configured as output //Flex pin configured as output
let mut a = Flex::new(&mut a); //Flex pin configured as output let mut a = Flex::new(&mut a); //Flex pin configured as output
a.set_low(); // Pin state must be set before configuring the pin, thus we avoid unknown state a.set_low(); // Pin state must be set before configuring the pin, thus we avoid unknown state
a.set_as_output(Speed::Low); a.set_as_output(Speed::Low);
delay(); delay();
assert!(b.is_low()); assert!(b.is_low());
} }
{ {
//Flex pin configured as output //Flex pin configured as output
let mut a = Flex::new(&mut a); let mut a = Flex::new(&mut a);
a.set_high(); a.set_high();
a.set_as_output(Speed::Low); a.set_as_output(Speed::Low);
@ -129,12 +129,12 @@ async fn main(_spawner: Spawner, p: Peripherals) {
// Test input no pull // Test input no pull
{ {
let mut b = Flex::new(&mut b); let mut b = Flex::new(&mut b);
b.set_as_input(Pull::None); // no pull, the status is undefined b.set_as_input(Pull::None); // no pull, the status is undefined
let mut a = Flex::new(&mut a); let mut a = Flex::new(&mut a);
a.set_low(); a.set_low();
a.set_as_output(Speed::Low); a.set_as_output(Speed::Low);
delay(); delay();
assert!(b.is_low()); assert!(b.is_low());
@ -143,11 +143,10 @@ async fn main(_spawner: Spawner, p: Peripherals) {
assert!(b.is_high()); assert!(b.is_high());
} }
// Test input pulldown // Test input pulldown
{ {
let mut b = Flex::new(&mut b); let mut b = Flex::new(&mut b);
b.set_as_input(Pull::Down); b.set_as_input(Pull::Down);
delay(); delay();
assert!(b.is_low()); assert!(b.is_low());
@ -164,7 +163,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
// Test input pullup // Test input pullup
{ {
let mut b = Flex::new(&mut b); let mut b = Flex::new(&mut b);
b.set_as_input(Pull::Up); b.set_as_input(Pull::Up);
delay(); delay();
assert!(b.is_high()); assert!(b.is_high());
@ -185,7 +184,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
let mut a = Flex::new(&mut a); let mut a = Flex::new(&mut a);
a.set_low(); a.set_low();
a.set_as_input_output(Speed::Low, Pull::None); a.set_as_input_output(Speed::Low, Pull::None);
delay(); delay();
assert!(b.is_low()); assert!(b.is_low());
a.set_high(); // High-Z output a.set_high(); // High-Z output