aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/exti.rs
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-stm32/src/exti.rs
parent9edf5b7f049f95742b60b041e4443967d8a6b708 (diff)
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-stm32/src/exti.rs')
-rw-r--r--embassy-stm32/src/exti.rs35
1 files changed, 13 insertions, 22 deletions
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs
index 9604c5149..9fce78f95 100644
--- a/embassy-stm32/src/exti.rs
+++ b/embassy-stm32/src/exti.rs
@@ -5,13 +5,13 @@ use core::marker::PhantomData;
5use core::pin::Pin; 5use core::pin::Pin;
6use core::task::{Context, Poll}; 6use core::task::{Context, Poll};
7 7
8use embassy_hal_internal::{impl_peripheral, into_ref}; 8use embassy_hal_internal::{impl_peripheral, PeripheralType};
9use embassy_sync::waitqueue::AtomicWaker; 9use embassy_sync::waitqueue::AtomicWaker;
10 10
11use crate::gpio::{AnyPin, Input, Level, Pin as GpioPin, Pull}; 11use crate::gpio::{AnyPin, Input, Level, Pin as GpioPin, Pull};
12use crate::pac::exti::regs::Lines; 12use crate::pac::exti::regs::Lines;
13use crate::pac::EXTI; 13use crate::pac::EXTI;
14use crate::{interrupt, pac, peripherals, Peripheral}; 14use crate::{interrupt, pac, peripherals, Peri};
15 15
16const EXTI_COUNT: usize = 16; 16const EXTI_COUNT: usize = 16;
17static EXTI_WAKERS: [AtomicWaker; EXTI_COUNT] = [const { AtomicWaker::new() }; EXTI_COUNT]; 17static EXTI_WAKERS: [AtomicWaker; EXTI_COUNT] = [const { AtomicWaker::new() }; EXTI_COUNT];
@@ -105,13 +105,7 @@ impl<'d> Unpin for ExtiInput<'d> {}
105 105
106impl<'d> ExtiInput<'d> { 106impl<'d> ExtiInput<'d> {
107 /// Create an EXTI input. 107 /// Create an EXTI input.
108 pub fn new<T: GpioPin>( 108 pub fn new<T: GpioPin>(pin: Peri<'d, T>, ch: Peri<'d, T::ExtiChannel>, pull: Pull) -> Self {
109 pin: impl Peripheral<P = T> + 'd,
110 ch: impl Peripheral<P = T::ExtiChannel> + 'd,
111 pull: Pull,
112 ) -> Self {
113 into_ref!(pin, ch);
114
115 // Needed if using AnyPin+AnyChannel. 109 // Needed if using AnyPin+AnyChannel.
116 assert_eq!(pin.pin(), ch.number()); 110 assert_eq!(pin.pin(), ch.number());
117 111
@@ -338,23 +332,12 @@ trait SealedChannel {}
338 332
339/// EXTI channel trait. 333/// EXTI channel trait.
340#[allow(private_bounds)] 334#[allow(private_bounds)]
341pub trait Channel: SealedChannel + Sized { 335pub trait Channel: PeripheralType + SealedChannel + Sized {
342 /// Get the EXTI channel number. 336 /// Get the EXTI channel number.
343 fn number(&self) -> u8; 337 fn number(&self) -> u8;
344
345 /// Type-erase (degrade) this channel into an `AnyChannel`.
346 ///
347 /// This converts EXTI channel singletons (`EXTI0`, `EXTI1`, ...), which
348 /// are all different types, into the same type. It is useful for
349 /// creating arrays of channels, or avoiding generics.
350 fn degrade(self) -> AnyChannel {
351 AnyChannel {
352 number: self.number() as u8,
353 }
354 }
355} 338}
356 339
357/// Type-erased (degraded) EXTI channel. 340/// Type-erased EXTI channel.
358/// 341///
359/// This represents ownership over any EXTI channel, known at runtime. 342/// This represents ownership over any EXTI channel, known at runtime.
360pub struct AnyChannel { 343pub struct AnyChannel {
@@ -377,6 +360,14 @@ macro_rules! impl_exti {
377 $number 360 $number
378 } 361 }
379 } 362 }
363
364 impl From<peripherals::$type> for AnyChannel {
365 fn from(val: peripherals::$type) -> Self {
366 Self {
367 number: val.number() as u8,
368 }
369 }
370 }
380 }; 371 };
381} 372}
382 373