aboutsummaryrefslogtreecommitdiff
path: root/embassy-mspm0
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-03-26 16:01:37 +0100
committerDario Nieuwenhuis <[email protected]>2025-03-27 15:18:06 +0100
commitd41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch)
tree678b6fc732216e529dc38e6f65b72a309917ac32 /embassy-mspm0
parent9edf5b7f049f95742b60b041e4443967d8a6b708 (diff)
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-mspm0')
-rw-r--r--embassy-mspm0/src/gpio.rs38
-rw-r--r--embassy-mspm0/src/lib.rs2
2 files changed, 17 insertions, 23 deletions
diff --git a/embassy-mspm0/src/gpio.rs b/embassy-mspm0/src/gpio.rs
index 1048d980e..2edadbc5a 100644
--- a/embassy-mspm0/src/gpio.rs
+++ b/embassy-mspm0/src/gpio.rs
@@ -5,7 +5,7 @@ use core::future::Future;
5use core::pin::Pin as FuturePin; 5use core::pin::Pin as FuturePin;
6use core::task::{Context, Poll}; 6use core::task::{Context, Poll};
7 7
8use embassy_hal_internal::{impl_peripheral, into_ref, Peripheral, PeripheralRef}; 8use embassy_hal_internal::{impl_peripheral, Peri, PeripheralType};
9use embassy_sync::waitqueue::AtomicWaker; 9use embassy_sync::waitqueue::AtomicWaker;
10 10
11use crate::pac::gpio::vals::*; 11use crate::pac::gpio::vals::*;
@@ -74,7 +74,7 @@ pub enum Port {
74/// set while not in output mode, so the pin's level will be 'remembered' when it is not in output 74/// set while not in output mode, so the pin's level will be 'remembered' when it is not in output
75/// mode. 75/// mode.
76pub struct Flex<'d> { 76pub struct Flex<'d> {
77 pin: PeripheralRef<'d, AnyPin>, 77 pin: Peri<'d, AnyPin>,
78} 78}
79 79
80impl<'d> Flex<'d> { 80impl<'d> Flex<'d> {
@@ -83,11 +83,9 @@ impl<'d> Flex<'d> {
83 /// The pin remains disconnected. The initial output level is unspecified, but can be changed 83 /// The pin remains disconnected. The initial output level is unspecified, but can be changed
84 /// before the pin is put into output mode. 84 /// before the pin is put into output mode.
85 #[inline] 85 #[inline]
86 pub fn new(pin: impl Peripheral<P = impl Pin> + 'd) -> Self { 86 pub fn new(pin: Peri<'d, impl Pin>) -> Self {
87 into_ref!(pin);
88
89 // Pin will be in disconnected state. 87 // Pin will be in disconnected state.
90 Self { pin: pin.map_into() } 88 Self { pin: pin.into() }
91 } 89 }
92 90
93 /// Set the pin's pull. 91 /// Set the pin's pull.
@@ -345,7 +343,7 @@ pub struct Input<'d> {
345impl<'d> Input<'d> { 343impl<'d> Input<'d> {
346 /// Create GPIO input driver for a [Pin] with the provided [Pull] configuration. 344 /// Create GPIO input driver for a [Pin] with the provided [Pull] configuration.
347 #[inline] 345 #[inline]
348 pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, pull: Pull) -> Self { 346 pub fn new(pin: Peri<'d, impl Pin>, pull: Pull) -> Self {
349 let mut pin = Flex::new(pin); 347 let mut pin = Flex::new(pin);
350 pin.set_as_input(); 348 pin.set_as_input();
351 pin.set_pull(pull); 349 pin.set_pull(pull);
@@ -421,7 +419,7 @@ pub struct Output<'d> {
421impl<'d> Output<'d> { 419impl<'d> Output<'d> {
422 /// Create GPIO output driver for a [Pin] with the provided [Level] configuration. 420 /// Create GPIO output driver for a [Pin] with the provided [Level] configuration.
423 #[inline] 421 #[inline]
424 pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, initial_output: Level) -> Self { 422 pub fn new(pin: Peri<'d, impl Pin>, initial_output: Level) -> Self {
425 let mut pin = Flex::new(pin); 423 let mut pin = Flex::new(pin);
426 pin.set_as_output(); 424 pin.set_as_output();
427 pin.set_level(initial_output); 425 pin.set_level(initial_output);
@@ -491,7 +489,7 @@ pub struct OutputOpenDrain<'d> {
491impl<'d> OutputOpenDrain<'d> { 489impl<'d> OutputOpenDrain<'d> {
492 /// Create a new GPIO open drain output driver for a [Pin] with the provided [Level]. 490 /// Create a new GPIO open drain output driver for a [Pin] with the provided [Level].
493 #[inline] 491 #[inline]
494 pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, initial_output: Level) -> Self { 492 pub fn new(pin: Peri<'d, impl Pin>, initial_output: Level) -> Self {
495 let mut pin = Flex::new(pin); 493 let mut pin = Flex::new(pin);
496 pin.set_level(initial_output); 494 pin.set_level(initial_output);
497 pin.set_as_input_output(); 495 pin.set_as_input_output();
@@ -599,7 +597,7 @@ impl<'d> OutputOpenDrain<'d> {
599 597
600/// Type-erased GPIO pin 598/// Type-erased GPIO pin
601pub struct AnyPin { 599pub struct AnyPin {
602 pin_port: u8, 600 pub(crate) pin_port: u8,
603} 601}
604 602
605impl AnyPin { 603impl AnyPin {
@@ -608,8 +606,8 @@ impl AnyPin {
608 /// # Safety 606 /// # Safety
609 /// - `pin_port` should not in use by another driver. 607 /// - `pin_port` should not in use by another driver.
610 #[inline] 608 #[inline]
611 pub unsafe fn steal(pin_port: u8) -> Self { 609 pub unsafe fn steal(pin_port: u8) -> Peri<'static, Self> {
612 Self { pin_port } 610 Peri::new_unchecked(Self { pin_port })
613 } 611 }
614} 612}
615 613
@@ -625,13 +623,7 @@ impl SealedPin for AnyPin {
625 623
626/// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. 624/// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin].
627#[allow(private_bounds)] 625#[allow(private_bounds)]
628pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static { 626pub trait Pin: PeripheralType + Into<AnyPin> + SealedPin + Sized + 'static {
629 fn degrade(self) -> AnyPin {
630 AnyPin {
631 pin_port: self.pin_port(),
632 }
633 }
634
635 /// The index of this pin in PINCM (pin control management) registers. 627 /// The index of this pin in PINCM (pin control management) registers.
636 #[inline] 628 #[inline]
637 fn pin_cm(&self) -> u8 { 629 fn pin_cm(&self) -> u8 {
@@ -866,7 +858,9 @@ macro_rules! impl_pin {
866 858
867 impl From<crate::peripherals::$name> for crate::gpio::AnyPin { 859 impl From<crate::peripherals::$name> for crate::gpio::AnyPin {
868 fn from(val: crate::peripherals::$name) -> Self { 860 fn from(val: crate::peripherals::$name) -> Self {
869 crate::gpio::Pin::degrade(val) 861 Self {
862 pin_port: crate::gpio::SealedPin::pin_port(&val),
863 }
870 } 864 }
871 } 865 }
872 }; 866 };
@@ -928,11 +922,11 @@ pub(crate) trait SealedPin {
928 922
929#[must_use = "futures do nothing unless you `.await` or poll them"] 923#[must_use = "futures do nothing unless you `.await` or poll them"]
930struct InputFuture<'d> { 924struct InputFuture<'d> {
931 pin: PeripheralRef<'d, AnyPin>, 925 pin: Peri<'d, AnyPin>,
932} 926}
933 927
934impl<'d> InputFuture<'d> { 928impl<'d> InputFuture<'d> {
935 fn new(pin: PeripheralRef<'d, AnyPin>, polarity: Polarity) -> Self { 929 fn new(pin: Peri<'d, AnyPin>, polarity: Polarity) -> Self {
936 let block = pin.block(); 930 let block = pin.block();
937 931
938 // Before clearing any previous edge events, we must disable events. 932 // Before clearing any previous edge events, we must disable events.
diff --git a/embassy-mspm0/src/lib.rs b/embassy-mspm0/src/lib.rs
index 1df85a520..99b7ed4a1 100644
--- a/embassy-mspm0/src/lib.rs
+++ b/embassy-mspm0/src/lib.rs
@@ -50,7 +50,7 @@ pub(crate) mod _generated {
50// Reexports 50// Reexports
51pub(crate) use _generated::gpio_pincm; 51pub(crate) use _generated::gpio_pincm;
52pub use _generated::{peripherals, Peripherals}; 52pub use _generated::{peripherals, Peripherals};
53pub use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; 53pub use embassy_hal_internal::Peri;
54#[cfg(feature = "unstable-pac")] 54#[cfg(feature = "unstable-pac")]
55pub use mspm0_metapac as pac; 55pub use mspm0_metapac as pac;
56#[cfg(not(feature = "unstable-pac"))] 56#[cfg(not(feature = "unstable-pac"))]