aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/tsc
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/tsc
parent9edf5b7f049f95742b60b041e4443967d8a6b708 (diff)
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-stm32/src/tsc')
-rw-r--r--embassy-stm32/src/tsc/mod.rs5
-rw-r--r--embassy-stm32/src/tsc/pin_groups.rs14
-rw-r--r--embassy-stm32/src/tsc/tsc.rs22
3 files changed, 13 insertions, 28 deletions
diff --git a/embassy-stm32/src/tsc/mod.rs b/embassy-stm32/src/tsc/mod.rs
index 0d5c27465..9359d83e9 100644
--- a/embassy-stm32/src/tsc/mod.rs
+++ b/embassy-stm32/src/tsc/mod.rs
@@ -98,6 +98,7 @@ use core::marker::PhantomData;
98 98
99pub use acquisition_banks::*; 99pub use acquisition_banks::*;
100pub use config::*; 100pub use config::*;
101use embassy_hal_internal::PeripheralType;
101use embassy_sync::waitqueue::AtomicWaker; 102use embassy_sync::waitqueue::AtomicWaker;
102pub use errors::*; 103pub use errors::*;
103pub use io_pin::*; 104pub use io_pin::*;
@@ -106,7 +107,7 @@ pub use tsc::*;
106pub use types::*; 107pub use types::*;
107 108
108use crate::rcc::RccPeripheral; 109use crate::rcc::RccPeripheral;
109use crate::{interrupt, peripherals, Peripheral}; 110use crate::{interrupt, peripherals};
110 111
111#[cfg(tsc_v1)] 112#[cfg(tsc_v1)]
112const TSC_NUM_GROUPS: usize = 6; 113const TSC_NUM_GROUPS: usize = 6;
@@ -142,7 +143,7 @@ pub(crate) trait SealedInstance {
142 143
143/// TSC instance trait 144/// TSC instance trait
144#[allow(private_bounds)] 145#[allow(private_bounds)]
145pub trait Instance: Peripheral<P = Self> + SealedInstance + RccPeripheral { 146pub trait Instance: SealedInstance + PeripheralType + RccPeripheral {
146 /// Interrupt for this TSC instance 147 /// Interrupt for this TSC instance
147 type Interrupt: interrupt::typelevel::Interrupt; 148 type Interrupt: interrupt::typelevel::Interrupt;
148} 149}
diff --git a/embassy-stm32/src/tsc/pin_groups.rs b/embassy-stm32/src/tsc/pin_groups.rs
index 1f3aafa35..6f914a94e 100644
--- a/embassy-stm32/src/tsc/pin_groups.rs
+++ b/embassy-stm32/src/tsc/pin_groups.rs
@@ -1,13 +1,11 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2use core::ops::BitOr; 2use core::ops::BitOr;
3 3
4use embassy_hal_internal::{into_ref, PeripheralRef};
5
6use super::errors::GroupError; 4use super::errors::GroupError;
7use super::io_pin::*; 5use super::io_pin::*;
8use super::Instance; 6use super::Instance;
9use crate::gpio::{AfType, AnyPin, OutputType, Speed}; 7use crate::gpio::{AfType, AnyPin, OutputType, Speed};
10use crate::Peripheral; 8use crate::Peri;
11 9
12/// Pin type definition to control IO parameters 10/// Pin type definition to control IO parameters
13#[derive(PartialEq, Clone, Copy)] 11#[derive(PartialEq, Clone, Copy)]
@@ -23,7 +21,7 @@ pub enum PinType {
23/// Pin struct that maintains usage 21/// Pin struct that maintains usage
24#[allow(missing_docs)] 22#[allow(missing_docs)]
25pub struct Pin<'d, T, Group> { 23pub struct Pin<'d, T, Group> {
26 _pin: PeripheralRef<'d, AnyPin>, 24 _pin: Peri<'d, AnyPin>,
27 role: PinType, 25 role: PinType,
28 tsc_io_pin: IOPin, 26 tsc_io_pin: IOPin,
29 phantom: PhantomData<(T, Group)>, 27 phantom: PhantomData<(T, Group)>,
@@ -426,17 +424,13 @@ macro_rules! trait_to_io_pin {
426macro_rules! impl_set_io { 424macro_rules! impl_set_io {
427 ($method:ident, $group:ident, $trait:ident, $index:expr) => { 425 ($method:ident, $group:ident, $trait:ident, $index:expr) => {
428 #[doc = concat!("Create a new pin1 for ", stringify!($group), " TSC group instance.")] 426 #[doc = concat!("Create a new pin1 for ", stringify!($group), " TSC group instance.")]
429 pub fn $method<Role: pin_roles::Role>( 427 pub fn $method<Role: pin_roles::Role>(&mut self, pin: Peri<'d, impl $trait<T>>) -> IOPinWithRole<$group, Role> {
430 &mut self,
431 pin: impl Peripheral<P = impl $trait<T>> + 'd,
432 ) -> IOPinWithRole<$group, Role> {
433 into_ref!(pin);
434 critical_section::with(|_| { 428 critical_section::with(|_| {
435 pin.set_low(); 429 pin.set_low();
436 pin.set_as_af(pin.af_num(), AfType::output(Role::output_type(), Speed::VeryHigh)); 430 pin.set_as_af(pin.af_num(), AfType::output(Role::output_type(), Speed::VeryHigh));
437 let tsc_io_pin = trait_to_io_pin!($trait); 431 let tsc_io_pin = trait_to_io_pin!($trait);
438 let new_pin = Pin { 432 let new_pin = Pin {
439 _pin: pin.map_into(), 433 _pin: pin.into(),
440 role: Role::pin_type(), 434 role: Role::pin_type(),
441 tsc_io_pin, 435 tsc_io_pin,
442 phantom: PhantomData, 436 phantom: PhantomData,
diff --git a/embassy-stm32/src/tsc/tsc.rs b/embassy-stm32/src/tsc/tsc.rs
index 17d2da82f..e92479c26 100644
--- a/embassy-stm32/src/tsc/tsc.rs
+++ b/embassy-stm32/src/tsc/tsc.rs
@@ -3,7 +3,7 @@ use core::marker::PhantomData;
3use core::ops::BitOr; 3use core::ops::BitOr;
4use core::task::Poll; 4use core::task::Poll;
5 5
6use embassy_hal_internal::{into_ref, PeripheralRef}; 6use embassy_hal_internal::Peri;
7 7
8use super::acquisition_banks::*; 8use super::acquisition_banks::*;
9use super::config::*; 9use super::config::*;
@@ -14,7 +14,7 @@ use super::types::*;
14use super::{Instance, InterruptHandler, TSC_NUM_GROUPS}; 14use super::{Instance, InterruptHandler, TSC_NUM_GROUPS};
15use crate::interrupt::typelevel::Interrupt; 15use crate::interrupt::typelevel::Interrupt;
16use crate::mode::{Async, Blocking, Mode as PeriMode}; 16use crate::mode::{Async, Blocking, Mode as PeriMode};
17use crate::{interrupt, rcc, Peripheral}; 17use crate::{interrupt, rcc};
18 18
19/// Internal structure holding masks for different types of TSC IOs. 19/// Internal structure holding masks for different types of TSC IOs.
20/// 20///
@@ -31,7 +31,7 @@ struct IOMasks {
31 31
32/// TSC driver 32/// TSC driver
33pub struct Tsc<'d, T: Instance, K: PeriMode> { 33pub struct Tsc<'d, T: Instance, K: PeriMode> {
34 _peri: PeripheralRef<'d, T>, 34 _peri: Peri<'d, T>,
35 _pin_groups: PinGroups<'d, T>, 35 _pin_groups: PinGroups<'d, T>,
36 state: State, 36 state: State,
37 config: Config, 37 config: Config,
@@ -218,13 +218,7 @@ impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> {
218 groups 218 groups
219 } 219 }
220 220
221 fn new_inner( 221 fn new_inner(peri: Peri<'d, T>, pin_groups: PinGroups<'d, T>, config: Config) -> Result<Self, GroupError> {
222 peri: impl Peripheral<P = T> + 'd,
223 pin_groups: PinGroups<'d, T>,
224 config: Config,
225 ) -> Result<Self, GroupError> {
226 into_ref!(peri);
227
228 pin_groups.check()?; 222 pin_groups.check()?;
229 223
230 let masks = IOMasks { 224 let masks = IOMasks {
@@ -410,7 +404,7 @@ impl<'d, T: Instance, K: PeriMode> Drop for Tsc<'d, T, K> {
410impl<'d, T: Instance> Tsc<'d, T, Async> { 404impl<'d, T: Instance> Tsc<'d, T, Async> {
411 /// Create a Tsc instance that can be awaited for completion 405 /// Create a Tsc instance that can be awaited for completion
412 pub fn new_async( 406 pub fn new_async(
413 peri: impl Peripheral<P = T> + 'd, 407 peri: Peri<'d, T>,
414 pin_groups: PinGroups<'d, T>, 408 pin_groups: PinGroups<'d, T>,
415 config: Config, 409 config: Config,
416 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 410 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
@@ -441,11 +435,7 @@ impl<'d, T: Instance> Tsc<'d, T, Async> {
441 435
442impl<'d, T: Instance> Tsc<'d, T, Blocking> { 436impl<'d, T: Instance> Tsc<'d, T, Blocking> {
443 /// Create a Tsc instance that must be polled for completion 437 /// Create a Tsc instance that must be polled for completion
444 pub fn new_blocking( 438 pub fn new_blocking(peri: Peri<'d, T>, pin_groups: PinGroups<'d, T>, config: Config) -> Result<Self, GroupError> {
445 peri: impl Peripheral<P = T> + 'd,
446 pin_groups: PinGroups<'d, T>,
447 config: Config,
448 ) -> Result<Self, GroupError> {
449 Self::new_inner(peri, pin_groups, config) 439 Self::new_inner(peri, pin_groups, config)
450 } 440 }
451 441