aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author[email protected] <[email protected]>2022-07-10 21:08:12 +0200
committer[email protected] <[email protected]>2022-07-10 21:08:12 +0200
commite4a36e1d98ac62482285dfb2b22f2683c3840572 (patch)
treee55b8fefcb5910bc02dd063fd74e00fbb0ccaf49
parent53388d4576617e621b5e63fd8599311a7f6066c3 (diff)
rustfmt on previously edited files
-rw-r--r--embassy-stm32/src/gpio.rs21
-rw-r--r--tests/stm32/src/bin/gpio.rs27
2 files changed, 22 insertions, 26 deletions
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index c3ae96f35..fd0bdb7b7 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -23,7 +23,7 @@ impl<'d, T: Pin> Flex<'d, T> {
23 /// The pin remains disconnected. The initial output level is unspecified, but can be changed 23 /// The pin remains disconnected. The initial output level is unspecified, but can be changed
24 /// before the pin is put into output mode. 24 /// before the pin is put into output mode.
25 /// 25 ///
26 #[inline] 26 #[inline]
27 pub fn new(pin: impl Unborrow<Target = T> + 'd) -> Self { 27 pub fn new(pin: impl Unborrow<Target = T> + 'd) -> Self {
28 unborrow!(pin); 28 unborrow!(pin);
29 // Pin will be in disconnected state. 29 // Pin will be in disconnected state.
@@ -32,9 +32,9 @@ impl<'d, T: Pin> Flex<'d, T> {
32 phantom: PhantomData, 32 phantom: PhantomData,
33 } 33 }
34 } 34 }
35 35
36 /// Put the pin into input mode. 36 /// Put the pin into input mode.
37 #[inline] 37 #[inline]
38 pub fn set_as_input(&mut self, pull: Pull) { 38 pub fn set_as_input(&mut self, pull: Pull) {
39 critical_section::with(|_| unsafe { 39 critical_section::with(|_| unsafe {
40 let r = self.pin.block(); 40 let r = self.pin.block();
@@ -74,7 +74,6 @@ impl<'d, T: Pin> Flex<'d, T> {
74 /// at a specific level, call `set_high`/`set_low` on the pin first. 74 /// at a specific level, call `set_high`/`set_low` on the pin first.
75 #[inline] 75 #[inline]
76 pub fn set_as_output(&mut self, speed: Speed) { 76 pub fn set_as_output(&mut self, speed: Speed) {
77
78 critical_section::with(|_| unsafe { 77 critical_section::with(|_| unsafe {
79 let r = self.pin.block(); 78 let r = self.pin.block();
80 let n = self.pin.pin() as usize; 79 let n = self.pin.pin() as usize;
@@ -95,7 +94,7 @@ impl<'d, T: Pin> Flex<'d, T> {
95 } 94 }
96 }); 95 });
97 } 96 }
98 97
99 /// Put the pin into input + output mode. 98 /// Put the pin into input + output mode.
100 /// 99 ///
101 /// This is commonly used for "open drain" mode. 100 /// This is commonly used for "open drain" mode.
@@ -106,7 +105,7 @@ impl<'d, T: Pin> Flex<'d, T> {
106 /// The pin level will be whatever was set before (or low by default). If you want it to begin 105 /// The pin level will be whatever was set before (or low by default). If you want it to begin
107 /// at a specific level, call `set_high`/`set_low` on the pin first. 106 /// at a specific level, call `set_high`/`set_low` on the pin first.
108 #[inline] 107 #[inline]
109 pub fn set_as_input_output(&mut self,speed: Speed, pull : Pull) { 108 pub fn set_as_input_output(&mut self, speed: Speed, pull: Pull) {
110 critical_section::with(|_| unsafe { 109 critical_section::with(|_| unsafe {
111 let r = self.pin.block(); 110 let r = self.pin.block();
112 let n = self.pin.pin() as usize; 111 let n = self.pin.pin() as usize;
@@ -164,7 +163,7 @@ impl<'d, T: Pin> Flex<'d, T> {
164 pub fn set_low(&mut self) { 163 pub fn set_low(&mut self) {
165 self.pin.set_low(); 164 self.pin.set_low();
166 } 165 }
167 166
168 /// Toggle pin output 167 /// Toggle pin output
169 #[inline] 168 #[inline]
170 pub fn toggle(&mut self) { 169 pub fn toggle(&mut self) {
@@ -262,7 +261,7 @@ impl From<Speed> for vals::Ospeedr {
262 261
263/// GPIO input driver. 262/// GPIO input driver.
264pub struct Input<'d, T: Pin> { 263pub struct Input<'d, T: Pin> {
265 pub(crate) pin: Flex<'d, T> 264 pub(crate) pin: Flex<'d, T>,
266} 265}
267 266
268impl<'d, T: Pin> Input<'d, T> { 267impl<'d, T: Pin> Input<'d, T> {
@@ -340,10 +339,9 @@ impl<'d, T: Pin> Output<'d, T> {
340 } 339 }
341} 340}
342 341
343
344/// GPIO output open-drain driver. 342/// GPIO output open-drain driver.
345pub struct OutputOpenDrain<'d, T: Pin> { 343pub struct OutputOpenDrain<'d, T: Pin> {
346 pub(crate) pin: Flex<'d, T> 344 pub(crate) pin: Flex<'d, T>,
347} 345}
348 346
349impl<'d, T: Pin> OutputOpenDrain<'d, T> { 347impl<'d, T: Pin> OutputOpenDrain<'d, T> {
@@ -925,10 +923,9 @@ mod eh1 {
925 Ok(self.is_set_low()) 923 Ok(self.is_set_low())
926 } 924 }
927 } 925 }
928
929} 926}
930 927
931#[cfg(feature = "unstable-pac")] 928#[cfg(feature = "unstable-pac")]
932pub mod low_level { 929pub mod low_level {
933 pub use super::sealed::*; 930 pub use super::sealed::*;
934} \ No newline at end of file 931}
diff --git a/tests/stm32/src/bin/gpio.rs b/tests/stm32/src/bin/gpio.rs
index a26daab4e..37cfe7cf4 100644
--- a/tests/stm32/src/bin/gpio.rs
+++ b/tests/stm32/src/bin/gpio.rs
@@ -6,7 +6,7 @@
6mod example_common; 6mod example_common;
7use defmt::assert; 7use defmt::assert;
8use embassy::executor::Spawner; 8use embassy::executor::Spawner;
9use embassy_stm32::gpio::{Input, Level, Output, OutputOpenDrain, Flex, Pull, Speed}; 9use embassy_stm32::gpio::{Flex, Input, Level, Output, OutputOpenDrain, Pull, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use example_common::*; 11use example_common::*;
12 12
@@ -104,21 +104,21 @@ async fn main(_spawner: Spawner, p: Peripherals) {
104 // FLEX 104 // FLEX
105 // Test initial output 105 // Test initial output
106 { 106 {
107 //Flex pin configured as input 107 //Flex pin configured as input
108 let mut b = Flex::new(&mut b); 108 let mut b = Flex::new(&mut b);
109 b.set_as_input(Pull::None); 109 b.set_as_input(Pull::None);
110 110
111 { 111 {
112 //Flex pin configured as output 112 //Flex pin configured as output
113 let mut a = Flex::new(&mut a); //Flex pin configured as output 113 let mut a = Flex::new(&mut a); //Flex pin configured as output
114 a.set_low(); // Pin state must be set before configuring the pin, thus we avoid unknown state 114 a.set_low(); // Pin state must be set before configuring the pin, thus we avoid unknown state
115 a.set_as_output(Speed::Low); 115 a.set_as_output(Speed::Low);
116 delay(); 116 delay();
117 assert!(b.is_low()); 117 assert!(b.is_low());
118 } 118 }
119 { 119 {
120 //Flex pin configured as output 120 //Flex pin configured as output
121 let mut a = Flex::new(&mut a); 121 let mut a = Flex::new(&mut a);
122 a.set_high(); 122 a.set_high();
123 a.set_as_output(Speed::Low); 123 a.set_as_output(Speed::Low);
124 124
@@ -129,12 +129,12 @@ async fn main(_spawner: Spawner, p: Peripherals) {
129 129
130 // Test input no pull 130 // Test input no pull
131 { 131 {
132 let mut b = Flex::new(&mut b); 132 let mut b = Flex::new(&mut b);
133 b.set_as_input(Pull::None); // no pull, the status is undefined 133 b.set_as_input(Pull::None); // no pull, the status is undefined
134 134
135 let mut a = Flex::new(&mut a); 135 let mut a = Flex::new(&mut a);
136 a.set_low(); 136 a.set_low();
137 a.set_as_output(Speed::Low); 137 a.set_as_output(Speed::Low);
138 138
139 delay(); 139 delay();
140 assert!(b.is_low()); 140 assert!(b.is_low());
@@ -143,11 +143,10 @@ async fn main(_spawner: Spawner, p: Peripherals) {
143 assert!(b.is_high()); 143 assert!(b.is_high());
144 } 144 }
145 145
146
147 // Test input pulldown 146 // Test input pulldown
148 { 147 {
149 let mut b = Flex::new(&mut b); 148 let mut b = Flex::new(&mut b);
150 b.set_as_input(Pull::Down); 149 b.set_as_input(Pull::Down);
151 delay(); 150 delay();
152 assert!(b.is_low()); 151 assert!(b.is_low());
153 152
@@ -164,7 +163,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
164 // Test input pullup 163 // Test input pullup
165 { 164 {
166 let mut b = Flex::new(&mut b); 165 let mut b = Flex::new(&mut b);
167 b.set_as_input(Pull::Up); 166 b.set_as_input(Pull::Up);
168 delay(); 167 delay();
169 assert!(b.is_high()); 168 assert!(b.is_high());
170 169
@@ -185,7 +184,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
185 184
186 let mut a = Flex::new(&mut a); 185 let mut a = Flex::new(&mut a);
187 a.set_low(); 186 a.set_low();
188 a.set_as_input_output(Speed::Low, Pull::None); 187 a.set_as_input_output(Speed::Low, Pull::None);
189 delay(); 188 delay();
190 assert!(b.is_low()); 189 assert!(b.is_low());
191 a.set_high(); // High-Z output 190 a.set_high(); // High-Z output