Skip to content

Commit b01219f

Browse files
committed
Rename ErasedPin to AnyPin
1 parent 3db88de commit b01219f

File tree

7 files changed

+49
-47
lines changed

7 files changed

+49
-47
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
- Implement `embedded_hal::i2c::I2c` for `I2cMasterDma` [#838]
1111
- Back to `stm32f4`
1212
- Implement `Ptr`, `Sealed`, `Steal` for generic `Periph` [#834]
13+
- Rename `ErasedPin` to `AnyPin` [#841]
1314
- Use `&mut RCC` for `PER::enable/reset`
1415
- Unmacro `Adc` [#832]
1516
- Use `write` instead of `modify` to clear flags [#829]
@@ -29,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2930
[#834]: https://github.com/stm32-rs/stm32f4xx-hal/pull/834
3031
[#838]: https://github.com/stm32-rs/stm32f4xx-hal/pull/838
3132
[#839]: https://github.com/stm32-rs/stm32f4xx-hal/pull/839
33+
[#841]: https://github.com/stm32-rs/stm32f4xx-hal/pull/841
3234

3335
## [v0.22.1] - 2024-11-03
3436

src/gpio.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, MODE> {
401401
///
402402
/// This is useful when you want to collect the pins into an array where you
403403
/// need all the elements to have the same type
404-
pub fn erase(self) -> ErasedPin<MODE> {
405-
ErasedPin::new(P as u8 - b'A', N)
404+
pub fn erase(self) -> AnyPin<MODE> {
405+
AnyPin::new(P as u8 - b'A', N)
406406
}
407407
}
408408

@@ -415,7 +415,7 @@ impl<const P: char, const N: u8, MODE> From<Pin<P, N, MODE>> for PartiallyErased
415415
}
416416
}
417417

418-
impl<const P: char, const N: u8, MODE> From<Pin<P, N, MODE>> for ErasedPin<MODE> {
418+
impl<const P: char, const N: u8, MODE> From<Pin<P, N, MODE>> for AnyPin<MODE> {
419419
/// Pin-to-erased pin conversion using the [`From`] trait.
420420
///
421421
/// Note that [`From`] is the reciprocal of [`Into`].

src/gpio/convert.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ macro_rules! change_mode {
166166
}
167167
use change_mode;
168168

169-
use super::ErasedPin;
170-
impl<MODE: PinMode> ErasedPin<MODE> {
169+
use super::AnyPin;
170+
impl<MODE: PinMode> AnyPin<MODE> {
171171
#[inline(always)]
172172
pub(super) fn mode<M: PinMode>(&mut self) {
173173
let n = self.pin_id();
@@ -176,9 +176,9 @@ impl<MODE: PinMode> ErasedPin<MODE> {
176176

177177
#[inline(always)]
178178
/// Converts pin into specified mode
179-
pub fn into_mode<M: PinMode>(mut self) -> ErasedPin<M> {
179+
pub fn into_mode<M: PinMode>(mut self) -> AnyPin<M> {
180180
self.mode::<M>();
181-
ErasedPin::from_pin_port(self.into_pin_port())
181+
AnyPin::from_pin_port(self.into_pin_port())
182182
}
183183
}
184184

src/gpio/erased.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use super::*;
22

3-
pub use ErasedPin as AnyPin;
3+
pub use AnyPin as ErasedPin;
44

55
/// Fully erased pin
66
///
77
/// `MODE` is one of the pin modes (see [Modes](crate::gpio#modes) section).
8-
pub struct ErasedPin<MODE> {
8+
pub struct AnyPin<MODE> {
99
// Bits 0-3: Pin, Bits 4-7: Port
1010
pin_port: u8,
1111
_mode: PhantomData<MODE>,
1212
}
1313

14-
impl<MODE> fmt::Debug for ErasedPin<MODE> {
14+
impl<MODE> fmt::Debug for AnyPin<MODE> {
1515
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1616
formatter.write_fmt(format_args!(
1717
"P({}{})<{}>",
@@ -23,7 +23,7 @@ impl<MODE> fmt::Debug for ErasedPin<MODE> {
2323
}
2424

2525
#[cfg(feature = "defmt")]
26-
impl<MODE> defmt::Format for ErasedPin<MODE> {
26+
impl<MODE> defmt::Format for AnyPin<MODE> {
2727
fn format(&self, f: defmt::Formatter) {
2828
defmt::write!(
2929
f,
@@ -35,7 +35,7 @@ impl<MODE> defmt::Format for ErasedPin<MODE> {
3535
}
3636
}
3737

38-
impl<MODE> PinExt for ErasedPin<MODE> {
38+
impl<MODE> PinExt for AnyPin<MODE> {
3939
type Mode = MODE;
4040

4141
#[inline(always)]
@@ -48,7 +48,7 @@ impl<MODE> PinExt for ErasedPin<MODE> {
4848
}
4949
}
5050

51-
impl<MODE> ErasedPin<MODE> {
51+
impl<MODE> AnyPin<MODE> {
5252
pub(crate) fn from_pin_port(pin_port: u8) -> Self {
5353
Self {
5454
pin_port,
@@ -93,23 +93,17 @@ impl<MODE> ErasedPin<MODE> {
9393
}
9494
}
9595

96-
impl<MODE> ErasedPin<Output<MODE>> {
96+
impl<MODE> AnyPin<Output<MODE>> {
9797
/// Drives the pin high
9898
#[inline(always)]
9999
pub fn set_high(&mut self) {
100-
// NOTE(unsafe) atomic write to a stateless register
101-
unsafe { self.block().bsrr().write(|w| w.bits(1 << self.pin_id())) };
100+
self.block().bsrr().write(|w| w.bs(self.pin_id()).set_bit());
102101
}
103102

104103
/// Drives the pin low
105104
#[inline(always)]
106105
pub fn set_low(&mut self) {
107-
// NOTE(unsafe) atomic write to a stateless register
108-
unsafe {
109-
self.block()
110-
.bsrr()
111-
.write(|w| w.bits(1 << (self.pin_id() + 16)))
112-
};
106+
self.block().bsrr().write(|w| w.br(self.pin_id()).set_bit());
113107
}
114108

115109
/// Is the pin in drive high or low mode?
@@ -140,7 +134,7 @@ impl<MODE> ErasedPin<Output<MODE>> {
140134
/// Is the pin in drive low mode?
141135
#[inline(always)]
142136
pub fn is_set_low(&self) -> bool {
143-
self.block().odr().read().bits() & (1 << self.pin_id()) == 0
137+
self.block().odr().read().odr(self.pin_id()).bit_is_clear()
144138
}
145139

146140
/// Toggle pin output
@@ -154,7 +148,7 @@ impl<MODE> ErasedPin<Output<MODE>> {
154148
}
155149
}
156150

157-
impl<MODE> ErasedPin<MODE>
151+
impl<MODE> AnyPin<MODE>
158152
where
159153
MODE: marker::Readable,
160154
{
@@ -167,6 +161,6 @@ where
167161
/// Is the input pin low?
168162
#[inline(always)]
169163
pub fn is_low(&self) -> bool {
170-
self.block().idr().read().bits() & (1 << self.pin_id()) == 0
164+
self.block().idr().read().idr(self.pin_id()).bit_is_clear()
171165
}
172166
}

src/gpio/hal_02.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::convert::Infallible;
22

33
use super::{
4-
dynamic::PinModeError, marker, DynamicPin, ErasedPin, Input, OpenDrain, Output,
4+
dynamic::PinModeError, marker, AnyPin, DynamicPin, Input, OpenDrain, Output,
55
PartiallyErasedPin, Pin, PinMode, PinState,
66
};
77

@@ -107,7 +107,7 @@ where
107107

108108
// Implementations for `ErasedPin`
109109

110-
impl<MODE> OutputPin for ErasedPin<Output<MODE>> {
110+
impl<MODE> OutputPin for AnyPin<Output<MODE>> {
111111
type Error = core::convert::Infallible;
112112

113113
#[inline(always)]
@@ -123,7 +123,7 @@ impl<MODE> OutputPin for ErasedPin<Output<MODE>> {
123123
}
124124
}
125125

126-
impl<MODE> StatefulOutputPin for ErasedPin<Output<MODE>> {
126+
impl<MODE> StatefulOutputPin for AnyPin<Output<MODE>> {
127127
#[inline(always)]
128128
fn is_set_high(&self) -> Result<bool, Self::Error> {
129129
Ok(self.is_set_high())
@@ -135,7 +135,7 @@ impl<MODE> StatefulOutputPin for ErasedPin<Output<MODE>> {
135135
}
136136
}
137137

138-
impl<MODE> ToggleableOutputPin for ErasedPin<Output<MODE>> {
138+
impl<MODE> ToggleableOutputPin for AnyPin<Output<MODE>> {
139139
type Error = Infallible;
140140

141141
#[inline(always)]
@@ -145,7 +145,7 @@ impl<MODE> ToggleableOutputPin for ErasedPin<Output<MODE>> {
145145
}
146146
}
147147

148-
impl<MODE> InputPin for ErasedPin<MODE>
148+
impl<MODE> InputPin for AnyPin<MODE>
149149
where
150150
MODE: marker::Readable,
151151
{

src/gpio/hal_1.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use core::convert::Infallible;
22

3-
use super::{
4-
dynamic::PinModeError, marker, DynamicPin, ErasedPin, Output, PartiallyErasedPin, Pin,
5-
};
3+
use super::{dynamic::PinModeError, marker, AnyPin, DynamicPin, Output, PartiallyErasedPin, Pin};
64

75
use embedded_hal::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin};
86

@@ -53,11 +51,11 @@ where
5351
}
5452

5553
// Implementations for `ErasedPin`
56-
impl<MODE> ErrorType for ErasedPin<MODE> {
54+
impl<MODE> ErrorType for AnyPin<MODE> {
5755
type Error = core::convert::Infallible;
5856
}
5957

60-
impl<MODE> OutputPin for ErasedPin<Output<MODE>> {
58+
impl<MODE> OutputPin for AnyPin<Output<MODE>> {
6159
#[inline(always)]
6260
fn set_high(&mut self) -> Result<(), Self::Error> {
6361
self.set_high();
@@ -71,7 +69,7 @@ impl<MODE> OutputPin for ErasedPin<Output<MODE>> {
7169
}
7270
}
7371

74-
impl<MODE> StatefulOutputPin for ErasedPin<Output<MODE>> {
72+
impl<MODE> StatefulOutputPin for AnyPin<Output<MODE>> {
7573
#[inline(always)]
7674
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
7775
Ok(Self::is_set_high(self))
@@ -83,7 +81,7 @@ impl<MODE> StatefulOutputPin for ErasedPin<Output<MODE>> {
8381
}
8482
}
8583

86-
impl<MODE> InputPin for ErasedPin<MODE>
84+
impl<MODE> InputPin for AnyPin<MODE>
8785
where
8886
MODE: marker::Readable,
8987
{

src/gpio/partially_erased.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ impl<const P: char, MODE> PartiallyErasedPin<P, Output<MODE>> {
6868
#[inline(always)]
6969
pub fn set_high(&mut self) {
7070
// NOTE(unsafe) atomic write to a stateless register
71-
unsafe {
72-
(*gpiox::<P>()).bsrr().write(|w| w.bits(1 << self.i));
73-
}
71+
unsafe { &*gpiox::<P>() }
72+
.bsrr()
73+
.write(|w| w.bs(self.i).set_bit());
7474
}
7575

7676
/// Drives the pin low
7777
#[inline(always)]
7878
pub fn set_low(&mut self) {
7979
// NOTE(unsafe) atomic write to a stateless register
80-
unsafe {
81-
(*gpiox::<P>()).bsrr().write(|w| w.bits(1 << (self.i + 16)));
82-
}
80+
unsafe { &*gpiox::<P>() }
81+
.bsrr()
82+
.write(|w| w.br(self.i).set_bit());
8383
}
8484

8585
/// Is the pin in drive high or low mode?
@@ -111,7 +111,11 @@ impl<const P: char, MODE> PartiallyErasedPin<P, Output<MODE>> {
111111
#[inline(always)]
112112
pub fn is_set_low(&self) -> bool {
113113
// NOTE(unsafe) atomic read with no side effects
114-
unsafe { (*gpiox::<P>()).odr().read().bits() & (1 << self.i) == 0 }
114+
unsafe { &*gpiox::<P>() }
115+
.odr()
116+
.read()
117+
.odr(self.i)
118+
.bit_is_clear()
115119
}
116120

117121
/// Toggle pin output
@@ -139,15 +143,19 @@ where
139143
#[inline(always)]
140144
pub fn is_low(&self) -> bool {
141145
// NOTE(unsafe) atomic read with no side effects
142-
unsafe { (*gpiox::<P>()).idr().read().bits() & (1 << self.i) == 0 }
146+
unsafe { &*gpiox::<P>() }
147+
.idr()
148+
.read()
149+
.idr(self.i)
150+
.bit_is_clear()
143151
}
144152
}
145153

146-
impl<const P: char, MODE> From<PartiallyErasedPin<P, MODE>> for ErasedPin<MODE> {
154+
impl<const P: char, MODE> From<PartiallyErasedPin<P, MODE>> for AnyPin<MODE> {
147155
/// Partially erased pin-to-erased pin conversion using the [`From`] trait.
148156
///
149157
/// Note that [`From`] is the reciprocal of [`Into`].
150158
fn from(p: PartiallyErasedPin<P, MODE>) -> Self {
151-
ErasedPin::new(P as u8 - b'A', p.i)
159+
AnyPin::new(P as u8 - b'A', p.i)
152160
}
153161
}

0 commit comments

Comments
 (0)