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
/// before the pin is put into output mode.
///
#[inline]
#[inline]
pub fn new(pin: impl Unborrow<Target = T> + 'd) -> Self {
unborrow!(pin);
// Pin will be in disconnected state.
@ -32,9 +32,9 @@ impl<'d, T: Pin> Flex<'d, T> {
phantom: PhantomData,
}
}
/// Put the pin into input mode.
#[inline]
#[inline]
pub fn set_as_input(&mut self, pull: Pull) {
critical_section::with(|_| unsafe {
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.
#[inline]
pub fn set_as_output(&mut self, speed: Speed) {
critical_section::with(|_| unsafe {
let r = self.pin.block();
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.
///
/// 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
/// at a specific level, call `set_high`/`set_low` on the pin first.
#[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 {
let r = self.pin.block();
let n = self.pin.pin() as usize;
@ -164,7 +163,7 @@ impl<'d, T: Pin> Flex<'d, T> {
pub fn set_low(&mut self) {
self.pin.set_low();
}
/// Toggle pin output
#[inline]
pub fn toggle(&mut self) {
@ -262,7 +261,7 @@ impl From<Speed> for vals::Ospeedr {
/// GPIO input driver.
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> {
@ -340,10 +339,9 @@ impl<'d, T: Pin> Output<'d, T> {
}
}
/// GPIO output open-drain driver.
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> {
@ -925,10 +923,9 @@ mod eh1 {
Ok(self.is_set_low())
}
}
}
#[cfg(feature = "unstable-pac")]
pub mod low_level {
pub use super::sealed::*;
}
}

View file

@ -6,7 +6,7 @@
mod example_common;
use defmt::assert;
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 example_common::*;
@ -104,21 +104,21 @@ async fn main(_spawner: Spawner, p: Peripherals) {
// FLEX
// Test initial output
{
//Flex pin configured as input
let mut b = Flex::new(&mut b);
//Flex pin configured as input
let mut b = Flex::new(&mut b);
b.set_as_input(Pull::None);
{
//Flex pin configured as output
let mut a = Flex::new(&mut a); //Flex pin configured as output
//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_as_output(Speed::Low);
delay();
assert!(b.is_low());
}
{
//Flex pin configured as output
let mut a = Flex::new(&mut a);
//Flex pin configured as output
let mut a = Flex::new(&mut a);
a.set_high();
a.set_as_output(Speed::Low);
@ -129,12 +129,12 @@ async fn main(_spawner: Spawner, p: Peripherals) {
// Test input no pull
{
let mut b = Flex::new(&mut b);
b.set_as_input(Pull::None); // no pull, the status is undefined
let mut b = Flex::new(&mut b);
b.set_as_input(Pull::None); // no pull, the status is undefined
let mut a = Flex::new(&mut a);
a.set_low();
a.set_as_output(Speed::Low);
a.set_as_output(Speed::Low);
delay();
assert!(b.is_low());
@ -143,11 +143,10 @@ async fn main(_spawner: Spawner, p: Peripherals) {
assert!(b.is_high());
}
// Test input pulldown
{
let mut b = Flex::new(&mut b);
b.set_as_input(Pull::Down);
b.set_as_input(Pull::Down);
delay();
assert!(b.is_low());
@ -164,7 +163,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
// Test input pullup
{
let mut b = Flex::new(&mut b);
b.set_as_input(Pull::Up);
b.set_as_input(Pull::Up);
delay();
assert!(b.is_high());
@ -185,7 +184,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
let mut a = Flex::new(&mut a);
a.set_low();
a.set_as_input_output(Speed::Low, Pull::None);
a.set_as_input_output(Speed::Low, Pull::None);
delay();
assert!(b.is_low());
a.set_high(); // High-Z output