Skip to content

Commit e898e89

Browse files
bugadaniDominaezzzjessebraham
authored
Remove AnyInputOnlyPin (#2071)
* Remove AnyInputOnlyPin * Add section to migration guide * Remove unnecessary enum Co-authored-by: Dominic Fischer <[email protected]> --------- Co-authored-by: Dominic Fischer <[email protected]> Co-authored-by: Jesse Braham <[email protected]>
1 parent 39109a4 commit e898e89

File tree

4 files changed

+21
-115
lines changed

4 files changed

+21
-115
lines changed

esp-hal/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2626
- Removed the `async`, `embedded-hal-02`, `embedded-hal`, `embedded-io`, `embedded-io-async`, and `ufmt` features (#2070)
2727
- Removed the `GpioN` type aliasses. Use `GpioPin<N>` instead. (#2073)
2828
- Removed `Peripherals::take`. Use `esp_hal::init` to obtain `Peripherals` (#1999)
29+
- Removed `AnyInputOnlyPin` in favour of `AnyPin`. (#2071)
2930

3031
## [0.20.1] - 2024-08-30
3132

esp-hal/MIGRATING-0.20.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ Instead of manually grabbing peripherals and setting up clocks, you should now c
3838

3939
## GPIO changes
4040

41-
The `GpioN` type aliasses are no longer available. You can use `GpioPin<N>` instead.
41+
- The `GpioN` type aliasses are no longer available. You can use `GpioPin<N>` instead.
42+
- The `AnyInputOnlyPin` has been removed. Replace any use with `AnyPin`.
43+
- The `NoPinType` has been removed. You can use `DummyPin` in its place.

esp-hal/src/gpio/any_pin.rs

Lines changed: 15 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,25 @@
11
use super::*;
22

3-
#[derive(Clone, Copy)]
4-
enum Inverted {
5-
NonInverted,
6-
Inverted,
7-
}
8-
9-
impl Inverted {
10-
fn is_inverted(&self) -> bool {
11-
match self {
12-
Inverted::NonInverted => false,
13-
Inverted::Inverted => true,
14-
}
15-
}
16-
}
17-
18-
/// Generic pin wrapper for pins which can be Output or Input.
3+
/// A type-erased GPIO pin, with additional configuration options.
4+
///
5+
/// Note that accessing unsupported pin functions (e.g. trying to use an
6+
/// input-only pin as output) will panic.
197
pub struct AnyPin<'d> {
208
pin: ErasedPin,
21-
inverted: Inverted,
9+
is_inverted: bool,
2210
_phantom: PhantomData<&'d ()>,
2311
}
2412

2513
impl<'d> AnyPin<'d> {
2614
/// Create wrapper for the given pin.
2715
#[inline]
28-
pub fn new<P: OutputPin + InputPin + CreateErasedPin>(
29-
pin: impl crate::peripheral::Peripheral<P = P> + 'd,
30-
) -> Self {
16+
pub fn new<P: CreateErasedPin>(pin: impl crate::peripheral::Peripheral<P = P> + 'd) -> Self {
3117
crate::into_ref!(pin);
3218
let pin = pin.erased_pin(private::Internal);
3319

3420
Self {
3521
pin,
36-
inverted: Inverted::NonInverted,
22+
is_inverted: false,
3723
_phantom: PhantomData,
3824
}
3925
}
@@ -49,7 +35,7 @@ impl<'d> AnyPin<'d> {
4935

5036
Self {
5137
pin,
52-
inverted: Inverted::Inverted,
38+
is_inverted: true,
5339
_phantom: PhantomData,
5440
}
5541
}
@@ -61,7 +47,7 @@ impl<'d> crate::peripheral::Peripheral for AnyPin<'d> {
6147
unsafe fn clone_unchecked(&mut self) -> Self::P {
6248
Self {
6349
pin: unsafe { self.pin.clone_unchecked() },
64-
inverted: self.inverted,
50+
is_inverted: self.is_inverted,
6551
_phantom: PhantomData,
6652
}
6753
}
@@ -114,10 +100,10 @@ impl<'d> OutputPin for AnyPin<'d> {
114100
fn connect_peripheral_to_output(&mut self, signal: OutputSignal, _internal: private::Internal) {
115101
self.pin.connect_peripheral_to_output_with_options(
116102
signal,
117-
self.inverted.is_inverted(),
103+
self.is_inverted,
118104
false,
119105
false,
120-
self.inverted.is_inverted(),
106+
self.is_inverted,
121107
private::Internal,
122108
);
123109
}
@@ -131,7 +117,7 @@ impl<'d> OutputPin for AnyPin<'d> {
131117
force_via_gpio_mux: bool,
132118
_internal: private::Internal,
133119
) {
134-
if self.inverted.is_inverted() {
120+
if self.is_inverted {
135121
self.pin.connect_peripheral_to_output_with_options(
136122
signal,
137123
true,
@@ -168,8 +154,8 @@ impl<'d> InputPin for AnyPin<'d> {
168154
fn connect_input_to_peripheral(&mut self, signal: InputSignal, _internal: private::Internal) {
169155
self.pin.connect_input_to_peripheral_with_options(
170156
signal,
171-
self.inverted.is_inverted(),
172-
self.inverted.is_inverted(),
157+
self.is_inverted,
158+
self.is_inverted,
173159
private::Internal,
174160
);
175161
}
@@ -181,7 +167,7 @@ impl<'d> InputPin for AnyPin<'d> {
181167
force_via_gpio_mux: bool,
182168
_internal: private::Internal,
183169
) {
184-
if self.inverted.is_inverted() {
170+
if self.is_inverted {
185171
self.pin.connect_input_to_peripheral_with_options(
186172
signal,
187173
true,
@@ -198,85 +184,3 @@ impl<'d> InputPin for AnyPin<'d> {
198184
}
199185
}
200186
}
201-
202-
/// Generic pin wrapper for pins which can only be Input.
203-
pub struct AnyInputOnlyPin<'d> {
204-
pin: ErasedPin,
205-
inverted: Inverted,
206-
_phantom: PhantomData<&'d ()>,
207-
}
208-
209-
impl<'d> AnyInputOnlyPin<'d> {
210-
/// Create wrapper for the given pin.
211-
#[inline]
212-
pub fn new<P: InputPin + CreateErasedPin>(
213-
pin: impl crate::peripheral::Peripheral<P = P> + 'd,
214-
) -> Self {
215-
crate::into_ref!(pin);
216-
let pin = pin.erased_pin(private::Internal);
217-
218-
Self {
219-
pin,
220-
inverted: Inverted::NonInverted,
221-
_phantom: PhantomData,
222-
}
223-
}
224-
}
225-
226-
impl<'d> crate::peripheral::Peripheral for AnyInputOnlyPin<'d> {
227-
type P = Self;
228-
229-
unsafe fn clone_unchecked(&mut self) -> Self::P {
230-
Self {
231-
pin: unsafe { self.pin.clone_unchecked() },
232-
inverted: self.inverted,
233-
_phantom: PhantomData,
234-
}
235-
}
236-
}
237-
238-
impl<'d> private::Sealed for AnyInputOnlyPin<'d> {}
239-
240-
impl<'d> Pin for AnyInputOnlyPin<'d> {
241-
delegate::delegate! {
242-
to self.pin {
243-
fn number(&self, _internal: private::Internal) -> u8;
244-
fn sleep_mode(&mut self, on: bool, _internal: private::Internal);
245-
fn set_alternate_function(&mut self, alternate: AlternateFunction, _internal: private::Internal);
246-
fn is_listening(&self, _internal: private::Internal) -> bool;
247-
fn listen_with_options(
248-
&mut self,
249-
event: Event,
250-
int_enable: bool,
251-
nmi_enable: bool,
252-
wake_up_from_light_sleep: bool,
253-
_internal: private::Internal,
254-
);
255-
fn unlisten(&mut self, _internal: private::Internal);
256-
fn is_interrupt_set(&self, _internal: private::Internal) -> bool;
257-
fn clear_interrupt(&mut self, _internal: private::Internal);
258-
fn wakeup_enable(&mut self, enable: bool, event: WakeEvent, _internal: private::Internal);
259-
}
260-
}
261-
}
262-
263-
impl<'d> InputPin for AnyInputOnlyPin<'d> {
264-
delegate::delegate! {
265-
to self.pin {
266-
fn init_input(&self, pull_down: bool, pull_up: bool, _internal: private::Internal);
267-
fn set_to_input(&mut self, _internal: private::Internal);
268-
fn enable_input(&mut self, on: bool, _internal: private::Internal);
269-
fn enable_input_in_sleep_mode(&mut self, on: bool, _internal: private::Internal);
270-
fn is_input_high(&self, _internal: private::Internal) -> bool;
271-
fn connect_input_to_peripheral(&mut self, signal: InputSignal, _internal: private::Internal);
272-
fn connect_input_to_peripheral_with_options(
273-
&mut self,
274-
signal: InputSignal,
275-
invert: bool,
276-
force_via_gpio_mux: bool,
277-
_internal: private::Internal,
278-
);
279-
fn disconnect_input_from_peripheral(&mut self, signal: InputSignal, _internal: private::Internal);
280-
}
281-
}
282-
}

esp-hal/src/gpio/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
//! - [Input] pins can be used as digital inputs.
2626
//! - [Output] and [OutputOpenDrain] pins can be used as digital outputs.
2727
//! - [Flex] pin is a pin that can be used as an input and output pin.
28-
//! - [AnyPin] and [AnyInputOnlyPin] are type-erased GPIO pins with support for
29-
//! inverted signalling.
28+
//! - [AnyPin] is a type-erased GPIO pin with support for inverted signalling.
3029
//! - [DummyPin] is a useful for cases where peripheral driver requires a pin,
3130
//! but real pin cannot be used.
3231
//!
@@ -77,7 +76,7 @@ pub(crate) use crate::{touch_common, touch_into};
7776
mod any_pin;
7877
mod dummy_pin;
7978

80-
pub use any_pin::{AnyInputOnlyPin, AnyPin};
79+
pub use any_pin::AnyPin;
8180
pub use dummy_pin::DummyPin;
8281

8382
#[cfg(soc_etm)]

0 commit comments

Comments
 (0)