aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichel <[email protected]>2024-10-10 15:14:53 +0200
committermichel <[email protected]>2024-11-29 17:58:35 +0100
commit31da5155e840d97e432cf2fa06c6fa4c2a19bf9a (patch)
tree50b2745e97e0305fb06afcfdf3a649529a2d0d3a
parenta5b34a7980edaba5d8de05c68a48972dd9239f75 (diff)
Refactor TSC module: Remove redundant 'Tsc' prefixes for improved naming consistency
-rw-r--r--embassy-stm32/src/tsc/acquisition_banks.rs108
-rw-r--r--embassy-stm32/src/tsc/io_pin.rs200
-rw-r--r--embassy-stm32/src/tsc/mod.rs4
-rw-r--r--embassy-stm32/src/tsc/pin_groups.rs136
-rw-r--r--embassy-stm32/src/tsc/tsc.rs58
-rw-r--r--embassy-stm32/src/tsc/tsc_io_pin.rs200
-rw-r--r--examples/stm32f3/src/bin/tsc_blocking.rs6
-rw-r--r--examples/stm32l0/src/bin/tsc_async.rs4
-rw-r--r--examples/stm32l0/src/bin/tsc_blocking.rs6
-rw-r--r--examples/stm32l0/src/bin/tsc_multipin.rs10
-rw-r--r--examples/stm32l4/src/bin/tsc_async.rs4
-rw-r--r--examples/stm32l4/src/bin/tsc_blocking.rs6
-rw-r--r--examples/stm32l4/src/bin/tsc_multipin.rs12
-rw-r--r--examples/stm32u5/src/bin/tsc.rs10
14 files changed, 379 insertions, 385 deletions
diff --git a/embassy-stm32/src/tsc/acquisition_banks.rs b/embassy-stm32/src/tsc/acquisition_banks.rs
index 21a5c3f87..6791ef6c1 100644
--- a/embassy-stm32/src/tsc/acquisition_banks.rs
+++ b/embassy-stm32/src/tsc/acquisition_banks.rs
@@ -1,69 +1,69 @@
1use super::io_pin::*;
1#[cfg(any(tsc_v2, tsc_v3))] 2#[cfg(any(tsc_v2, tsc_v3))]
2use super::pin_groups::G7; 3use super::pin_groups::G7;
3#[cfg(tsc_v3)] 4#[cfg(tsc_v3)]
4use super::pin_groups::G8; 5use super::pin_groups::G8;
5use super::pin_groups::{tsc_pin_roles, G1, G2, G3, G4, G5, G6}; 6use super::pin_groups::{pin_roles, G1, G2, G3, G4, G5, G6};
6use super::tsc_io_pin::*;
7use super::types::{Group, GroupStatus}; 7use super::types::{Group, GroupStatus};
8use super::TSC_NUM_GROUPS; 8use super::TSC_NUM_GROUPS;
9 9
10/// Represents a collection of TSC (Touch Sensing Controller) pins for an acquisition bank. 10/// Represents a collection of TSC (Touch Sensing Controller) pins for an acquisition bank.
11/// 11///
12/// This struct holds optional `TscIOPin` values for each TSC group, allowing for flexible 12/// This struct holds optional `tsc::IOPin` values for each TSC group, allowing for flexible
13/// configuration of TSC acquisition banks. Each field corresponds to a specific TSC group 13/// configuration of TSC acquisition banks. Each field corresponds to a specific TSC group
14/// and can be set to `Some(TscIOPin)` if that group is to be included in the acquisition, 14/// and can be set to `Some(tsc::IOPin)` if that group is to be included in the acquisition,
15/// or `None` if it should be excluded. 15/// or `None` if it should be excluded.
16#[allow(missing_docs)] 16#[allow(missing_docs)]
17#[derive(Default)] 17#[derive(Default)]
18pub struct TscAcquisitionBankPins { 18pub struct AcquisitionBankPins {
19 pub g1_pin: Option<TscIOPinWithRole<G1, tsc_pin_roles::Channel>>, 19 pub g1_pin: Option<IOPinWithRole<G1, pin_roles::Channel>>,
20 pub g2_pin: Option<TscIOPinWithRole<G2, tsc_pin_roles::Channel>>, 20 pub g2_pin: Option<IOPinWithRole<G2, pin_roles::Channel>>,
21 pub g3_pin: Option<TscIOPinWithRole<G3, tsc_pin_roles::Channel>>, 21 pub g3_pin: Option<IOPinWithRole<G3, pin_roles::Channel>>,
22 pub g4_pin: Option<TscIOPinWithRole<G4, tsc_pin_roles::Channel>>, 22 pub g4_pin: Option<IOPinWithRole<G4, pin_roles::Channel>>,
23 pub g5_pin: Option<TscIOPinWithRole<G5, tsc_pin_roles::Channel>>, 23 pub g5_pin: Option<IOPinWithRole<G5, pin_roles::Channel>>,
24 pub g6_pin: Option<TscIOPinWithRole<G6, tsc_pin_roles::Channel>>, 24 pub g6_pin: Option<IOPinWithRole<G6, pin_roles::Channel>>,
25 #[cfg(any(tsc_v2, tsc_v3))] 25 #[cfg(any(tsc_v2, tsc_v3))]
26 pub g7_pin: Option<TscIOPinWithRole<G7, tsc_pin_roles::Channel>>, 26 pub g7_pin: Option<IOPinWithRole<G7, pin_roles::Channel>>,
27 #[cfg(tsc_v3)] 27 #[cfg(tsc_v3)]
28 pub g8_pin: Option<TscIOPinWithRole<G8, tsc_pin_roles::Channel>>, 28 pub g8_pin: Option<IOPinWithRole<G8, pin_roles::Channel>>,
29} 29}
30 30
31impl TscAcquisitionBankPins { 31impl AcquisitionBankPins {
32 /// Returns an iterator over the pins in this acquisition bank. 32 /// Returns an iterator over the pins in this acquisition bank.
33 /// 33 ///
34 /// This method allows for easy traversal of all configured pins in the bank. 34 /// This method allows for easy traversal of all configured pins in the bank.
35 pub fn iter(&self) -> TscAcquisitionBankPinsIterator { 35 pub fn iter(&self) -> AcquisitionBankPinsIterator {
36 TscAcquisitionBankPinsIterator(TscAcquisitionBankIterator::new(self)) 36 AcquisitionBankPinsIterator(AcquisitionBankIterator::new(self))
37 } 37 }
38} 38}
39 39
40/// Iterator for TSC acquisition banks. 40/// Iterator for TSC acquisition banks.
41/// 41///
42/// This iterator allows traversing through the pins of a `TscAcquisitionBankPins` struct, 42/// This iterator allows traversing through the pins of a `AcquisitionBankPins` struct,
43/// yielding each configured pin in order of the TSC groups. 43/// yielding each configured pin in order of the TSC groups.
44pub struct TscAcquisitionBankIterator<'a> { 44pub struct AcquisitionBankIterator<'a> {
45 pins: &'a TscAcquisitionBankPins, 45 pins: &'a AcquisitionBankPins,
46 current_group: u8, 46 current_group: u8,
47} 47}
48 48
49impl<'a> TscAcquisitionBankIterator<'a> { 49impl<'a> AcquisitionBankIterator<'a> {
50 fn new(pins: &'a TscAcquisitionBankPins) -> Self { 50 fn new(pins: &'a AcquisitionBankPins) -> Self {
51 Self { pins, current_group: 0 } 51 Self { pins, current_group: 0 }
52 } 52 }
53 53
54 fn next_pin(&mut self) -> Option<TscIOPin> { 54 fn next_pin(&mut self) -> Option<IOPin> {
55 while self.current_group < TSC_NUM_GROUPS as u8 { 55 while self.current_group < TSC_NUM_GROUPS as u8 {
56 let pin = match self.current_group { 56 let pin = match self.current_group {
57 0 => self.pins.g1_pin.map(TscIOPinWithRole::get_pin), 57 0 => self.pins.g1_pin.map(IOPinWithRole::get_pin),
58 1 => self.pins.g2_pin.map(TscIOPinWithRole::get_pin), 58 1 => self.pins.g2_pin.map(IOPinWithRole::get_pin),
59 2 => self.pins.g3_pin.map(TscIOPinWithRole::get_pin), 59 2 => self.pins.g3_pin.map(IOPinWithRole::get_pin),
60 3 => self.pins.g4_pin.map(TscIOPinWithRole::get_pin), 60 3 => self.pins.g4_pin.map(IOPinWithRole::get_pin),
61 4 => self.pins.g5_pin.map(TscIOPinWithRole::get_pin), 61 4 => self.pins.g5_pin.map(IOPinWithRole::get_pin),
62 5 => self.pins.g6_pin.map(TscIOPinWithRole::get_pin), 62 5 => self.pins.g6_pin.map(IOPinWithRole::get_pin),
63 #[cfg(any(tsc_v2, tsc_v3))] 63 #[cfg(any(tsc_v2, tsc_v3))]
64 6 => self.pins.g7_pin.map(TscIOPinWithRole::get_pin), 64 6 => self.pins.g7_pin.map(IOPinWithRole::get_pin),
65 #[cfg(tsc_v3)] 65 #[cfg(tsc_v3)]
66 7 => self.pins.g8_pin.map(TscIOPinWithRole::get_pin), 66 7 => self.pins.g8_pin.map(IOPinWithRole::get_pin),
67 _ => None, 67 _ => None,
68 }; 68 };
69 self.current_group += 1; 69 self.current_group += 1;
@@ -77,21 +77,21 @@ impl<'a> TscAcquisitionBankIterator<'a> {
77 77
78/// Iterator for TSC acquisition bank pins. 78/// Iterator for TSC acquisition bank pins.
79/// 79///
80/// This iterator yields `TscIOPin` values for each configured pin in the acquisition bank. 80/// This iterator yields `tsc::IOPin` values for each configured pin in the acquisition bank.
81pub struct TscAcquisitionBankPinsIterator<'a>(TscAcquisitionBankIterator<'a>); 81pub struct AcquisitionBankPinsIterator<'a>(AcquisitionBankIterator<'a>);
82 82
83impl<'a> Iterator for TscAcquisitionBankPinsIterator<'a> { 83impl<'a> Iterator for AcquisitionBankPinsIterator<'a> {
84 type Item = TscIOPin; 84 type Item = IOPin;
85 85
86 fn next(&mut self) -> Option<Self::Item> { 86 fn next(&mut self) -> Option<Self::Item> {
87 self.0.next_pin() 87 self.0.next_pin()
88 } 88 }
89} 89}
90 90
91impl TscAcquisitionBankPins { 91impl AcquisitionBankPins {
92 /// Returns an iterator over the available pins in the bank 92 /// Returns an iterator over the available pins in the bank
93 pub fn pins_iterator(&self) -> TscAcquisitionBankPinsIterator { 93 pub fn pins_iterator(&self) -> AcquisitionBankPinsIterator {
94 TscAcquisitionBankPinsIterator(TscAcquisitionBankIterator::new(self)) 94 AcquisitionBankPinsIterator(AcquisitionBankIterator::new(self))
95 } 95 }
96} 96}
97 97
@@ -100,14 +100,14 @@ impl TscAcquisitionBankPins {
100/// This struct contains a set of pins to be used in a TSC acquisition with a pre-computed and 100/// This struct contains a set of pins to be used in a TSC acquisition with a pre-computed and
101/// verified mask for efficiently setting up the TSC peripheral before performing an acquisition. 101/// verified mask for efficiently setting up the TSC peripheral before performing an acquisition.
102/// It ensures that only one channel pin per TSC group is included, adhering to hardware limitations. 102/// It ensures that only one channel pin per TSC group is included, adhering to hardware limitations.
103pub struct TscAcquisitionBank { 103pub struct AcquisitionBank {
104 pub(super) pins: TscAcquisitionBankPins, 104 pub(super) pins: AcquisitionBankPins,
105 pub(super) mask: u32, 105 pub(super) mask: u32,
106} 106}
107 107
108impl TscAcquisitionBank { 108impl AcquisitionBank {
109 /// Returns an iterator over the available pins in the bank. 109 /// Returns an iterator over the available pins in the bank.
110 pub fn pins_iterator(&self) -> TscAcquisitionBankPinsIterator { 110 pub fn pins_iterator(&self) -> AcquisitionBankPinsIterator {
111 self.pins.pins_iterator() 111 self.pins.pins_iterator()
112 } 112 }
113 113
@@ -122,8 +122,8 @@ impl TscAcquisitionBank {
122 /// * `group` - The TSC group to retrieve the pin for. 122 /// * `group` - The TSC group to retrieve the pin for.
123 /// 123 ///
124 /// # Returns 124 /// # Returns
125 /// An `Option<TscIOPin>` containing the pin if it exists for the given group, or `None` if not. 125 /// An `Option<tsc::IOPin>` containing the pin if it exists for the given group, or `None` if not.
126 pub fn get_pin(&self, group: Group) -> Option<TscIOPin> { 126 pub fn get_pin(&self, group: Group) -> Option<IOPin> {
127 match group { 127 match group {
128 Group::One => self.pins.g1_pin.map(|p| p.pin), 128 Group::One => self.pins.g1_pin.map(|p| p.pin),
129 Group::Two => self.pins.g2_pin.map(|p| p.pin), 129 Group::Two => self.pins.g2_pin.map(|p| p.pin),
@@ -141,11 +141,11 @@ impl TscAcquisitionBank {
141 141
142/// Represents the status of all TSC groups in an acquisition bank 142/// Represents the status of all TSC groups in an acquisition bank
143#[derive(Default)] 143#[derive(Default)]
144pub struct TscAcquisitionBankStatus { 144pub struct AcquisitionBankStatus {
145 pub(super) groups: [Option<GroupStatus>; TSC_NUM_GROUPS], 145 pub(super) groups: [Option<GroupStatus>; TSC_NUM_GROUPS],
146} 146}
147 147
148impl TscAcquisitionBankStatus { 148impl AcquisitionBankStatus {
149 /// Check if all groups in the bank are complete 149 /// Check if all groups in the bank are complete
150 pub fn all_complete(&self) -> bool { 150 pub fn all_complete(&self) -> bool {
151 self.groups 151 self.groups
@@ -174,36 +174,36 @@ impl TscAcquisitionBankStatus {
174 174
175/// Represents the result of a Touch Sensing Controller (TSC) acquisition for a specific pin. 175/// Represents the result of a Touch Sensing Controller (TSC) acquisition for a specific pin.
176/// 176///
177/// This struct contains a reference to the `TscIOPin` from which a value was read, 177/// This struct contains a reference to the `tsc::IOPin` from which a value was read,
178/// along with the actual sensor reading for that pin. It provides a convenient way 178/// along with the actual sensor reading for that pin. It provides a convenient way
179/// to associate TSC readings with their corresponding pins after an acquisition. 179/// to associate TSC readings with their corresponding pins after an acquisition.
180#[cfg_attr(feature = "defmt", derive(defmt::Format))] 180#[cfg_attr(feature = "defmt", derive(defmt::Format))]
181#[derive(Clone, Copy, Debug)] 181#[derive(Clone, Copy, Debug)]
182pub struct TscChannelReading { 182pub struct ChannelReading {
183 /// The sensor reading value obtained from the TSC acquisition. 183 /// The sensor reading value obtained from the TSC acquisition.
184 /// Lower values typically indicate a detected touch, while higher values indicate no touch. 184 /// Lower values typically indicate a detected touch, while higher values indicate no touch.
185 pub sensor_value: u16, 185 pub sensor_value: u16,
186 186
187 /// The `TscIOPin` associated with this reading. 187 /// The `tsc::IOPin` associated with this reading.
188 /// This allows for easy identification of which pin the reading corresponds to. 188 /// This allows for easy identification of which pin the reading corresponds to.
189 pub tsc_pin: TscIOPin, 189 pub tsc_pin: IOPin,
190} 190}
191 191
192/// Represents the readings from all TSC groups 192/// Represents the readings from all TSC groups
193#[derive(Default)] 193#[derive(Default)]
194pub struct TscAcquisitionBankReadings { 194pub struct AcquisitionBankReadings {
195 pub(super) groups: [Option<TscChannelReading>; TSC_NUM_GROUPS], 195 pub(super) groups: [Option<ChannelReading>; TSC_NUM_GROUPS],
196} 196}
197 197
198impl TscAcquisitionBankReadings { 198impl AcquisitionBankReadings {
199 /// Get the reading for a specific group, if the group is present in the bank 199 /// Get the reading for a specific group, if the group is present in the bank
200 pub fn get_group_reading(&self, group: Group) -> Option<TscChannelReading> { 200 pub fn get_group_reading(&self, group: Group) -> Option<ChannelReading> {
201 let index: usize = group.into(); 201 let index: usize = group.into();
202 self.groups[index] 202 self.groups[index]
203 } 203 }
204 204
205 /// Iterator for readings for groups present in the bank 205 /// Iterator for readings for groups present in the bank
206 pub fn iter(&self) -> impl Iterator<Item = TscChannelReading> + '_ { 206 pub fn iter(&self) -> impl Iterator<Item = ChannelReading> + '_ {
207 self.groups.iter().filter_map(|&x| x) 207 self.groups.iter().filter_map(|&x| x)
208 } 208 }
209} 209}
diff --git a/embassy-stm32/src/tsc/io_pin.rs b/embassy-stm32/src/tsc/io_pin.rs
new file mode 100644
index 000000000..ad2010ed7
--- /dev/null
+++ b/embassy-stm32/src/tsc/io_pin.rs
@@ -0,0 +1,200 @@
1use core::marker::PhantomData;
2use core::ops::{BitAnd, BitOr, BitOrAssign};
3
4use super::pin_roles;
5use super::types::Group;
6
7/// Pin defines
8#[allow(missing_docs)]
9#[cfg_attr(feature = "defmt", derive(defmt::Format))]
10#[derive(PartialEq, Clone, Copy, Debug)]
11pub enum IOPin {
12 Group1Io1,
13 Group1Io2,
14 Group1Io3,
15 Group1Io4,
16 Group2Io1,
17 Group2Io2,
18 Group2Io3,
19 Group2Io4,
20 Group3Io1,
21 Group3Io2,
22 Group3Io3,
23 Group3Io4,
24 Group4Io1,
25 Group4Io2,
26 Group4Io3,
27 Group4Io4,
28 Group5Io1,
29 Group5Io2,
30 Group5Io3,
31 Group5Io4,
32 Group6Io1,
33 Group6Io2,
34 Group6Io3,
35 Group6Io4,
36 #[cfg(any(tsc_v2, tsc_v3))]
37 Group7Io1,
38 #[cfg(any(tsc_v2, tsc_v3))]
39 Group7Io2,
40 #[cfg(any(tsc_v2, tsc_v3))]
41 Group7Io3,
42 #[cfg(any(tsc_v2, tsc_v3))]
43 Group7Io4,
44 #[cfg(tsc_v3)]
45 Group8Io1,
46 #[cfg(tsc_v3)]
47 Group8Io2,
48 #[cfg(tsc_v3)]
49 Group8Io3,
50 #[cfg(tsc_v3)]
51 Group8Io4,
52}
53
54/// Represents a TSC I/O pin with associated group and role information.
55///
56/// This type combines an `tsc::IOPin` with phantom type parameters to statically
57/// encode the pin's group and role. This allows for type-safe operations
58/// on TSC pins within their specific contexts.
59///
60/// - `Group`: A type parameter representing the TSC group (e.g., `G1`, `G2`).
61/// - `Role`: A type parameter representing the pin's role (e.g., `Channel`, `Sample`).
62#[derive(Clone, Copy, Debug)]
63pub struct IOPinWithRole<Group, Role: pin_roles::Role> {
64 /// The underlying TSC I/O pin.
65 pub pin: IOPin,
66 pub(super) phantom: PhantomData<(Group, Role)>,
67}
68
69impl<G, R: pin_roles::Role> IOPinWithRole<G, R> {
70 pub(super) fn get_pin(wrapped_pin: IOPinWithRole<G, R>) -> IOPin {
71 wrapped_pin.pin
72 }
73}
74
75impl IOPin {
76 /// Maps this IOPin to the Group it belongs to.
77 ///
78 /// This method provides a convenient way to determine which Group
79 /// a specific TSC I/O pin is associated with.
80 pub const fn group(&self) -> Group {
81 match self {
82 IOPin::Group1Io1 | IOPin::Group1Io2 | IOPin::Group1Io3 | IOPin::Group1Io4 => Group::One,
83 IOPin::Group2Io1 | IOPin::Group2Io2 | IOPin::Group2Io3 | IOPin::Group2Io4 => Group::Two,
84 IOPin::Group3Io1 | IOPin::Group3Io2 | IOPin::Group3Io3 | IOPin::Group3Io4 => Group::Three,
85 IOPin::Group4Io1 | IOPin::Group4Io2 | IOPin::Group4Io3 | IOPin::Group4Io4 => Group::Four,
86 IOPin::Group5Io1 | IOPin::Group5Io2 | IOPin::Group5Io3 | IOPin::Group5Io4 => Group::Five,
87 IOPin::Group6Io1 | IOPin::Group6Io2 | IOPin::Group6Io3 | IOPin::Group6Io4 => Group::Six,
88 #[cfg(any(tsc_v2, tsc_v3))]
89 IOPin::Group7Io1 | IOPin::Group7Io2 | IOPin::Group7Io3 | IOPin::Group7Io4 => Group::Seven,
90 #[cfg(tsc_v3)]
91 IOPin::Group8Io1 | IOPin::Group8Io2 | IOPin::Group8Io3 | IOPin::Group8Io4 => Group::Eight,
92 }
93 }
94
95 /// Returns the `Group` associated with the given `IOPin`.
96 pub fn get_group(pin: IOPin) -> Group {
97 pin.group()
98 }
99}
100
101impl BitOr<IOPin> for u32 {
102 type Output = u32;
103 fn bitor(self, rhs: IOPin) -> Self::Output {
104 let rhs: u32 = rhs.into();
105 self | rhs
106 }
107}
108
109impl BitOr<u32> for IOPin {
110 type Output = u32;
111 fn bitor(self, rhs: u32) -> Self::Output {
112 let val: u32 = self.into();
113 val | rhs
114 }
115}
116
117impl BitOr for IOPin {
118 type Output = u32;
119 fn bitor(self, rhs: Self) -> Self::Output {
120 let val: u32 = self.into();
121 let rhs: u32 = rhs.into();
122 val | rhs
123 }
124}
125
126impl BitOrAssign<IOPin> for u32 {
127 fn bitor_assign(&mut self, rhs: IOPin) {
128 let rhs: u32 = rhs.into();
129 *self |= rhs;
130 }
131}
132
133impl BitAnd<IOPin> for u32 {
134 type Output = u32;
135 fn bitand(self, rhs: IOPin) -> Self::Output {
136 let rhs: u32 = rhs.into();
137 self & rhs
138 }
139}
140
141impl BitAnd<u32> for IOPin {
142 type Output = u32;
143 fn bitand(self, rhs: u32) -> Self::Output {
144 let val: u32 = self.into();
145 val & rhs
146 }
147}
148
149impl IOPin {
150 const fn to_u32(self) -> u32 {
151 match self {
152 IOPin::Group1Io1 => 0x00000001,
153 IOPin::Group1Io2 => 0x00000002,
154 IOPin::Group1Io3 => 0x00000004,
155 IOPin::Group1Io4 => 0x00000008,
156 IOPin::Group2Io1 => 0x00000010,
157 IOPin::Group2Io2 => 0x00000020,
158 IOPin::Group2Io3 => 0x00000040,
159 IOPin::Group2Io4 => 0x00000080,
160 IOPin::Group3Io1 => 0x00000100,
161 IOPin::Group3Io2 => 0x00000200,
162 IOPin::Group3Io3 => 0x00000400,
163 IOPin::Group3Io4 => 0x00000800,
164 IOPin::Group4Io1 => 0x00001000,
165 IOPin::Group4Io2 => 0x00002000,
166 IOPin::Group4Io3 => 0x00004000,
167 IOPin::Group4Io4 => 0x00008000,
168 IOPin::Group5Io1 => 0x00010000,
169 IOPin::Group5Io2 => 0x00020000,
170 IOPin::Group5Io3 => 0x00040000,
171 IOPin::Group5Io4 => 0x00080000,
172 IOPin::Group6Io1 => 0x00100000,
173 IOPin::Group6Io2 => 0x00200000,
174 IOPin::Group6Io3 => 0x00400000,
175 IOPin::Group6Io4 => 0x00800000,
176 #[cfg(any(tsc_v2, tsc_v3))]
177 IOPin::Group7Io1 => 0x01000000,
178 #[cfg(any(tsc_v2, tsc_v3))]
179 IOPin::Group7Io2 => 0x02000000,
180 #[cfg(any(tsc_v2, tsc_v3))]
181 IOPin::Group7Io3 => 0x04000000,
182 #[cfg(any(tsc_v2, tsc_v3))]
183 IOPin::Group7Io4 => 0x08000000,
184 #[cfg(tsc_v3)]
185 IOPin::Group8Io1 => 0x10000000,
186 #[cfg(tsc_v3)]
187 IOPin::Group8Io2 => 0x20000000,
188 #[cfg(tsc_v3)]
189 IOPin::Group8Io3 => 0x40000000,
190 #[cfg(tsc_v3)]
191 IOPin::Group8Io4 => 0x80000000,
192 }
193 }
194}
195
196impl Into<u32> for IOPin {
197 fn into(self) -> u32 {
198 self.to_u32()
199 }
200}
diff --git a/embassy-stm32/src/tsc/mod.rs b/embassy-stm32/src/tsc/mod.rs
index 2df3847bc..0d5c27465 100644
--- a/embassy-stm32/src/tsc/mod.rs
+++ b/embassy-stm32/src/tsc/mod.rs
@@ -80,7 +80,7 @@ pub mod config;
80pub mod pin_groups; 80pub mod pin_groups;
81 81
82/// Definitions and implementations for individual TSC I/O pins. 82/// Definitions and implementations for individual TSC I/O pins.
83pub mod tsc_io_pin; 83pub mod io_pin;
84 84
85/// Structures and implementations for TSC acquisition banks. 85/// Structures and implementations for TSC acquisition banks.
86pub mod acquisition_banks; 86pub mod acquisition_banks;
@@ -100,9 +100,9 @@ pub use acquisition_banks::*;
100pub use config::*; 100pub use config::*;
101use embassy_sync::waitqueue::AtomicWaker; 101use embassy_sync::waitqueue::AtomicWaker;
102pub use errors::*; 102pub use errors::*;
103pub use io_pin::*;
103pub use pin_groups::*; 104pub use pin_groups::*;
104pub use tsc::*; 105pub use tsc::*;
105pub use tsc_io_pin::*;
106pub use types::*; 106pub use types::*;
107 107
108use crate::rcc::RccPeripheral; 108use crate::rcc::RccPeripheral;
diff --git a/embassy-stm32/src/tsc/pin_groups.rs b/embassy-stm32/src/tsc/pin_groups.rs
index b15890d6f..1f3aafa35 100644
--- a/embassy-stm32/src/tsc/pin_groups.rs
+++ b/embassy-stm32/src/tsc/pin_groups.rs
@@ -4,7 +4,7 @@ use core::ops::BitOr;
4use embassy_hal_internal::{into_ref, PeripheralRef}; 4use embassy_hal_internal::{into_ref, PeripheralRef};
5 5
6use super::errors::GroupError; 6use super::errors::GroupError;
7use super::tsc_io_pin::*; 7use super::io_pin::*;
8use super::Instance; 8use super::Instance;
9use crate::gpio::{AfType, AnyPin, OutputType, Speed}; 9use crate::gpio::{AfType, AnyPin, OutputType, Speed};
10use crate::Peripheral; 10use crate::Peripheral;
@@ -22,14 +22,14 @@ pub enum PinType {
22 22
23/// Pin struct that maintains usage 23/// Pin struct that maintains usage
24#[allow(missing_docs)] 24#[allow(missing_docs)]
25pub struct TscPin<'d, T, Group> { 25pub struct Pin<'d, T, Group> {
26 _pin: PeripheralRef<'d, AnyPin>, 26 _pin: PeripheralRef<'d, AnyPin>,
27 role: PinType, 27 role: PinType,
28 tsc_io_pin: TscIOPin, 28 tsc_io_pin: IOPin,
29 phantom: PhantomData<(T, Group)>, 29 phantom: PhantomData<(T, Group)>,
30} 30}
31 31
32impl<'d, T, Group> TscPin<'d, T, Group> { 32impl<'d, T, Group> Pin<'d, T, Group> {
33 /// Returns the role of this TSC pin. 33 /// Returns the role of this TSC pin.
34 /// 34 ///
35 /// The role indicates whether this pin is configured as a channel, 35 /// The role indicates whether this pin is configured as a channel,
@@ -47,8 +47,8 @@ impl<'d, T, Group> TscPin<'d, T, Group> {
47 /// which includes information about the pin's group and position within that group. 47 /// which includes information about the pin's group and position within that group.
48 /// 48 ///
49 /// # Returns 49 /// # Returns
50 /// The `TscIOPin` representing this pin's TSC-specific configuration. 50 /// The `IOPin` representing this pin's TSC-specific configuration.
51 pub fn tsc_io_pin(&self) -> TscIOPin { 51 pub fn tsc_io_pin(&self) -> IOPin {
52 self.tsc_io_pin 52 self.tsc_io_pin
53 } 53 }
54} 54}
@@ -71,10 +71,10 @@ impl<'d, T, Group> TscPin<'d, T, Group> {
71/// - No more than one shield pin is allowed across all groups. 71/// - No more than one shield pin is allowed across all groups.
72#[allow(missing_docs)] 72#[allow(missing_docs)]
73pub struct PinGroup<'d, T, Group> { 73pub struct PinGroup<'d, T, Group> {
74 pin1: Option<TscPin<'d, T, Group>>, 74 pin1: Option<Pin<'d, T, Group>>,
75 pin2: Option<TscPin<'d, T, Group>>, 75 pin2: Option<Pin<'d, T, Group>>,
76 pin3: Option<TscPin<'d, T, Group>>, 76 pin3: Option<Pin<'d, T, Group>>,
77 pin4: Option<TscPin<'d, T, Group>>, 77 pin4: Option<Pin<'d, T, Group>>,
78} 78}
79 79
80impl<'d, T, G> Default for PinGroup<'d, T, G> { 80impl<'d, T, G> Default for PinGroup<'d, T, G> {
@@ -92,7 +92,7 @@ impl<'d, T, G> Default for PinGroup<'d, T, G> {
92/// 92///
93/// This module contains marker types and traits that represent different roles 93/// This module contains marker types and traits that represent different roles
94/// a TSC pin can have, such as channel, sample, or shield. 94/// a TSC pin can have, such as channel, sample, or shield.
95pub mod tsc_pin_roles { 95pub mod pin_roles {
96 use super::{OutputType, PinType}; 96 use super::{OutputType, PinType};
97 97
98 /// Marker type for a TSC channel pin. 98 /// Marker type for a TSC channel pin.
@@ -162,10 +162,10 @@ pub struct PinGroupWithRoles<
162 'd, 162 'd,
163 T: Instance, 163 T: Instance,
164 G, 164 G,
165 R1 = tsc_pin_roles::Channel, 165 R1 = pin_roles::Channel,
166 R2 = tsc_pin_roles::Channel, 166 R2 = pin_roles::Channel,
167 R3 = tsc_pin_roles::Channel, 167 R3 = pin_roles::Channel,
168 R4 = tsc_pin_roles::Channel, 168 R4 = pin_roles::Channel,
169> { 169> {
170 /// The underlying pin group without role information. 170 /// The underlying pin group without role information.
171 pub pin_group: PinGroup<'d, T, G>, 171 pub pin_group: PinGroup<'d, T, G>,
@@ -230,38 +230,38 @@ impl<'d, T: Instance, G> PinGroup<'d, T, G> {
230 } 230 }
231 231
232 /// Returns a reference to the first pin in the group, if configured. 232 /// Returns a reference to the first pin in the group, if configured.
233 pub fn pin1(&self) -> Option<&TscPin<'d, T, G>> { 233 pub fn pin1(&self) -> Option<&Pin<'d, T, G>> {
234 self.pin1.as_ref() 234 self.pin1.as_ref()
235 } 235 }
236 236
237 /// Returns a reference to the second pin in the group, if configured. 237 /// Returns a reference to the second pin in the group, if configured.
238 pub fn pin2(&self) -> Option<&TscPin<'d, T, G>> { 238 pub fn pin2(&self) -> Option<&Pin<'d, T, G>> {
239 self.pin2.as_ref() 239 self.pin2.as_ref()
240 } 240 }
241 241
242 /// Returns a reference to the third pin in the group, if configured. 242 /// Returns a reference to the third pin in the group, if configured.
243 pub fn pin3(&self) -> Option<&TscPin<'d, T, G>> { 243 pub fn pin3(&self) -> Option<&Pin<'d, T, G>> {
244 self.pin3.as_ref() 244 self.pin3.as_ref()
245 } 245 }
246 246
247 /// Returns a reference to the fourth pin in the group, if configured. 247 /// Returns a reference to the fourth pin in the group, if configured.
248 pub fn pin4(&self) -> Option<&TscPin<'d, T, G>> { 248 pub fn pin4(&self) -> Option<&Pin<'d, T, G>> {
249 self.pin4.as_ref() 249 self.pin4.as_ref()
250 } 250 }
251 251
252 fn sample_pins(&self) -> impl Iterator<Item = TscIOPin> + '_ { 252 fn sample_pins(&self) -> impl Iterator<Item = IOPin> + '_ {
253 self.pins_filtered(PinType::Sample) 253 self.pins_filtered(PinType::Sample)
254 } 254 }
255 255
256 fn shield_pins(&self) -> impl Iterator<Item = TscIOPin> + '_ { 256 fn shield_pins(&self) -> impl Iterator<Item = IOPin> + '_ {
257 self.pins_filtered(PinType::Shield) 257 self.pins_filtered(PinType::Shield)
258 } 258 }
259 259
260 fn channel_pins(&self) -> impl Iterator<Item = TscIOPin> + '_ { 260 fn channel_pins(&self) -> impl Iterator<Item = IOPin> + '_ {
261 self.pins_filtered(PinType::Channel) 261 self.pins_filtered(PinType::Channel)
262 } 262 }
263 263
264 fn pins_filtered(&self, pin_type: PinType) -> impl Iterator<Item = TscIOPin> + '_ { 264 fn pins_filtered(&self, pin_type: PinType) -> impl Iterator<Item = IOPin> + '_ {
265 self.pins().into_iter().filter_map(move |pin| { 265 self.pins().into_iter().filter_map(move |pin| {
266 pin.as_ref() 266 pin.as_ref()
267 .and_then(|p| if p.role == pin_type { Some(p.tsc_io_pin) } else { None }) 267 .and_then(|p| if p.role == pin_type { Some(p.tsc_io_pin) } else { None })
@@ -280,11 +280,11 @@ impl<'d, T: Instance, G> PinGroup<'d, T, G> {
280 self.sample_pins().fold(0, u32::bitor) 280 self.sample_pins().fold(0, u32::bitor)
281 } 281 }
282 282
283 fn pins(&self) -> [&Option<TscPin<'d, T, G>>; 4] { 283 fn pins(&self) -> [&Option<Pin<'d, T, G>>; 4] {
284 [&self.pin1, &self.pin2, &self.pin3, &self.pin4] 284 [&self.pin1, &self.pin2, &self.pin3, &self.pin4]
285 } 285 }
286 286
287 fn pins_mut(&mut self) -> [&mut Option<TscPin<'d, T, G>>; 4] { 287 fn pins_mut(&mut self) -> [&mut Option<Pin<'d, T, G>>; 4] {
288 [&mut self.pin1, &mut self.pin2, &mut self.pin3, &mut self.pin4] 288 [&mut self.pin1, &mut self.pin2, &mut self.pin3, &mut self.pin4]
289 } 289 }
290} 290}
@@ -317,132 +317,132 @@ macro_rules! TSC_V3_GUARD {
317 }}; 317 }};
318} 318}
319 319
320macro_rules! trait_to_tsc_io_pin { 320macro_rules! trait_to_io_pin {
321 (G1IO1Pin) => { 321 (G1IO1Pin) => {
322 TscIOPin::Group1Io1 322 IOPin::Group1Io1
323 }; 323 };
324 (G1IO2Pin) => { 324 (G1IO2Pin) => {
325 TscIOPin::Group1Io2 325 IOPin::Group1Io2
326 }; 326 };
327 (G1IO3Pin) => { 327 (G1IO3Pin) => {
328 TscIOPin::Group1Io3 328 IOPin::Group1Io3
329 }; 329 };
330 (G1IO4Pin) => { 330 (G1IO4Pin) => {
331 TscIOPin::Group1Io4 331 IOPin::Group1Io4
332 }; 332 };
333 333
334 (G2IO1Pin) => { 334 (G2IO1Pin) => {
335 TscIOPin::Group2Io1 335 IOPin::Group2Io1
336 }; 336 };
337 (G2IO2Pin) => { 337 (G2IO2Pin) => {
338 TscIOPin::Group2Io2 338 IOPin::Group2Io2
339 }; 339 };
340 (G2IO3Pin) => { 340 (G2IO3Pin) => {
341 TscIOPin::Group2Io3 341 IOPin::Group2Io3
342 }; 342 };
343 (G2IO4Pin) => { 343 (G2IO4Pin) => {
344 TscIOPin::Group2Io4 344 IOPin::Group2Io4
345 }; 345 };
346 346
347 (G3IO1Pin) => { 347 (G3IO1Pin) => {
348 TscIOPin::Group3Io1 348 IOPin::Group3Io1
349 }; 349 };
350 (G3IO2Pin) => { 350 (G3IO2Pin) => {
351 TscIOPin::Group3Io2 351 IOPin::Group3Io2
352 }; 352 };
353 (G3IO3Pin) => { 353 (G3IO3Pin) => {
354 TscIOPin::Group3Io3 354 IOPin::Group3Io3
355 }; 355 };
356 (G3IO4Pin) => { 356 (G3IO4Pin) => {
357 TscIOPin::Group3Io4 357 IOPin::Group3Io4
358 }; 358 };
359 359
360 (G4IO1Pin) => { 360 (G4IO1Pin) => {
361 TscIOPin::Group4Io1 361 IOPin::Group4Io1
362 }; 362 };
363 (G4IO2Pin) => { 363 (G4IO2Pin) => {
364 TscIOPin::Group4Io2 364 IOPin::Group4Io2
365 }; 365 };
366 (G4IO3Pin) => { 366 (G4IO3Pin) => {
367 TscIOPin::Group4Io3 367 IOPin::Group4Io3
368 }; 368 };
369 (G4IO4Pin) => { 369 (G4IO4Pin) => {
370 TscIOPin::Group4Io4 370 IOPin::Group4Io4
371 }; 371 };
372 372
373 (G5IO1Pin) => { 373 (G5IO1Pin) => {
374 TscIOPin::Group5Io1 374 IOPin::Group5Io1
375 }; 375 };
376 (G5IO2Pin) => { 376 (G5IO2Pin) => {
377 TscIOPin::Group5Io2 377 IOPin::Group5Io2
378 }; 378 };
379 (G5IO3Pin) => { 379 (G5IO3Pin) => {
380 TscIOPin::Group5Io3 380 IOPin::Group5Io3
381 }; 381 };
382 (G5IO4Pin) => { 382 (G5IO4Pin) => {
383 TscIOPin::Group5Io4 383 IOPin::Group5Io4
384 }; 384 };
385 385
386 (G6IO1Pin) => { 386 (G6IO1Pin) => {
387 TscIOPin::Group6Io1 387 IOPin::Group6Io1
388 }; 388 };
389 (G6IO2Pin) => { 389 (G6IO2Pin) => {
390 TscIOPin::Group6Io2 390 IOPin::Group6Io2
391 }; 391 };
392 (G6IO3Pin) => { 392 (G6IO3Pin) => {
393 TscIOPin::Group6Io3 393 IOPin::Group6Io3
394 }; 394 };
395 (G6IO4Pin) => { 395 (G6IO4Pin) => {
396 TscIOPin::Group6Io4 396 IOPin::Group6Io4
397 }; 397 };
398 398
399 (G7IO1Pin) => { 399 (G7IO1Pin) => {
400 TSC_V2_V3_GUARD!(TscIOPin::Group7Io1) 400 TSC_V2_V3_GUARD!(IOPin::Group7Io1)
401 }; 401 };
402 (G7IO2Pin) => { 402 (G7IO2Pin) => {
403 TSC_V2_V3_GUARD!(TscIOPin::Group7Io2) 403 TSC_V2_V3_GUARD!(IOPin::Group7Io2)
404 }; 404 };
405 (G7IO3Pin) => { 405 (G7IO3Pin) => {
406 TSC_V2_V3_GUARD!(TscIOPin::Group7Io3) 406 TSC_V2_V3_GUARD!(IOPin::Group7Io3)
407 }; 407 };
408 (G7IO4Pin) => { 408 (G7IO4Pin) => {
409 TSC_V2_V3_GUARD!(TscIOPin::Group7Io4) 409 TSC_V2_V3_GUARD!(IOPin::Group7Io4)
410 }; 410 };
411 411
412 (G8IO1Pin) => { 412 (G8IO1Pin) => {
413 TSC_V3_GUARD!(TscIOPin::Group8Io1) 413 TSC_V3_GUARD!(IOPin::Group8Io1)
414 }; 414 };
415 (G8IO2Pin) => { 415 (G8IO2Pin) => {
416 TSC_V3_GUARD!(TscIOPin::Group8Io2) 416 TSC_V3_GUARD!(IOPin::Group8Io2)
417 }; 417 };
418 (G8IO3Pin) => { 418 (G8IO3Pin) => {
419 TSC_V3_GUARD!(TscIOPin::Group8Io3) 419 TSC_V3_GUARD!(IOPin::Group8Io3)
420 }; 420 };
421 (G8IO4Pin) => { 421 (G8IO4Pin) => {
422 TSC_V3_GUARD!(TscIOPin::Group8Io4) 422 TSC_V3_GUARD!(IOPin::Group8Io4)
423 }; 423 };
424} 424}
425 425
426macro_rules! impl_set_io { 426macro_rules! impl_set_io {
427 ($method:ident, $group:ident, $trait:ident, $index:expr) => { 427 ($method:ident, $group:ident, $trait:ident, $index:expr) => {
428 #[doc = concat!("Create a new pin1 for ", stringify!($group), " TSC group instance.")] 428 #[doc = concat!("Create a new pin1 for ", stringify!($group), " TSC group instance.")]
429 pub fn $method<Role: tsc_pin_roles::Role>( 429 pub fn $method<Role: pin_roles::Role>(
430 &mut self, 430 &mut self,
431 pin: impl Peripheral<P = impl $trait<T>> + 'd, 431 pin: impl Peripheral<P = impl $trait<T>> + 'd,
432 ) -> TscIOPinWithRole<$group, Role> { 432 ) -> IOPinWithRole<$group, Role> {
433 into_ref!(pin); 433 into_ref!(pin);
434 critical_section::with(|_| { 434 critical_section::with(|_| {
435 pin.set_low(); 435 pin.set_low();
436 pin.set_as_af(pin.af_num(), AfType::output(Role::output_type(), Speed::VeryHigh)); 436 pin.set_as_af(pin.af_num(), AfType::output(Role::output_type(), Speed::VeryHigh));
437 let tsc_io_pin = trait_to_tsc_io_pin!($trait); 437 let tsc_io_pin = trait_to_io_pin!($trait);
438 let new_pin = TscPin { 438 let new_pin = Pin {
439 _pin: pin.map_into(), 439 _pin: pin.map_into(),
440 role: Role::pin_type(), 440 role: Role::pin_type(),
441 tsc_io_pin, 441 tsc_io_pin,
442 phantom: PhantomData, 442 phantom: PhantomData,
443 }; 443 };
444 *self.pin_group.pins_mut()[$index] = Some(new_pin); 444 *self.pin_group.pins_mut()[$index] = Some(new_pin);
445 TscIOPinWithRole { 445 IOPinWithRole {
446 pin: tsc_io_pin, 446 pin: tsc_io_pin,
447 phantom: PhantomData, 447 phantom: PhantomData,
448 } 448 }
@@ -453,14 +453,8 @@ macro_rules! impl_set_io {
453 453
454macro_rules! group_impl { 454macro_rules! group_impl {
455 ($group:ident, $trait1:ident, $trait2:ident, $trait3:ident, $trait4:ident) => { 455 ($group:ident, $trait1:ident, $trait2:ident, $trait3:ident, $trait4:ident) => {
456 impl< 456 impl<'d, T: Instance, R1: pin_roles::Role, R2: pin_roles::Role, R3: pin_roles::Role, R4: pin_roles::Role>
457 'd, 457 PinGroupWithRoles<'d, T, $group, R1, R2, R3, R4>
458 T: Instance,
459 R1: tsc_pin_roles::Role,
460 R2: tsc_pin_roles::Role,
461 R3: tsc_pin_roles::Role,
462 R4: tsc_pin_roles::Role,
463 > PinGroupWithRoles<'d, T, $group, R1, R2, R3, R4>
464 { 458 {
465 impl_set_io!(set_io1, $group, $trait1, 0); 459 impl_set_io!(set_io1, $group, $trait1, 0);
466 impl_set_io!(set_io2, $group, $trait2, 1); 460 impl_set_io!(set_io2, $group, $trait2, 1);
diff --git a/embassy-stm32/src/tsc/tsc.rs b/embassy-stm32/src/tsc/tsc.rs
index 58f9d9d2e..17d2da82f 100644
--- a/embassy-stm32/src/tsc/tsc.rs
+++ b/embassy-stm32/src/tsc/tsc.rs
@@ -8,8 +8,8 @@ use embassy_hal_internal::{into_ref, PeripheralRef};
8use super::acquisition_banks::*; 8use super::acquisition_banks::*;
9use super::config::*; 9use super::config::*;
10use super::errors::*; 10use super::errors::*;
11use super::io_pin::*;
11use super::pin_groups::*; 12use super::pin_groups::*;
12use super::tsc_io_pin::*;
13use super::types::*; 13use 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;
@@ -20,7 +20,7 @@ use crate::{interrupt, rcc, Peripheral};
20/// 20///
21/// These masks are used during the initial configuration of the TSC peripheral 21/// These masks are used during the initial configuration of the TSC peripheral
22/// and for validating pin types during operations like creating acquisition banks. 22/// and for validating pin types during operations like creating acquisition banks.
23struct TscIOMasks { 23struct IOMasks {
24 /// Mask representing all configured channel IOs 24 /// Mask representing all configured channel IOs
25 channel_ios: u32, 25 channel_ios: u32,
26 /// Mask representing all configured shield IOs 26 /// Mask representing all configured shield IOs
@@ -35,19 +35,19 @@ pub struct Tsc<'d, T: Instance, K: PeriMode> {
35 _pin_groups: PinGroups<'d, T>, 35 _pin_groups: PinGroups<'d, T>,
36 state: State, 36 state: State,
37 config: Config, 37 config: Config,
38 masks: TscIOMasks, 38 masks: IOMasks,
39 _kind: PhantomData<K>, 39 _kind: PhantomData<K>,
40} 40}
41 41
42impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> { 42impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> {
43 // Helper method to check if a pin is a channel pin 43 // Helper method to check if a pin is a channel pin
44 fn is_channel_pin(&self, pin: TscIOPin) -> bool { 44 fn is_channel_pin(&self, pin: IOPin) -> bool {
45 (self.masks.channel_ios & pin) != 0 45 (self.masks.channel_ios & pin) != 0
46 } 46 }
47 47
48 /// Get the status of all groups involved in a TscAcquisitionBank 48 /// Get the status of all groups involved in a AcquisitionBank
49 pub fn get_acquisition_bank_status(&self, bank: &TscAcquisitionBank) -> TscAcquisitionBankStatus { 49 pub fn get_acquisition_bank_status(&self, bank: &AcquisitionBank) -> AcquisitionBankStatus {
50 let mut bank_status = TscAcquisitionBankStatus::default(); 50 let mut bank_status = AcquisitionBankStatus::default();
51 for pin in bank.pins_iterator() { 51 for pin in bank.pins_iterator() {
52 let group = pin.group(); 52 let group = pin.group();
53 let group_status = self.group_get_status(group); 53 let group_status = self.group_get_status(group);
@@ -57,13 +57,13 @@ impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> {
57 bank_status 57 bank_status
58 } 58 }
59 59
60 /// Get the values for all channels involved in a TscAcquisitionBank 60 /// Get the values for all channels involved in a AcquisitionBank
61 pub fn get_acquisition_bank_values(&self, bank: &TscAcquisitionBank) -> TscAcquisitionBankReadings { 61 pub fn get_acquisition_bank_values(&self, bank: &AcquisitionBank) -> AcquisitionBankReadings {
62 let mut bank_readings = TscAcquisitionBankReadings::default(); 62 let mut bank_readings = AcquisitionBankReadings::default();
63 for pin in bank.pins_iterator() { 63 for pin in bank.pins_iterator() {
64 let group = pin.group(); 64 let group = pin.group();
65 let value = self.group_get_value(group); 65 let value = self.group_get_value(group);
66 let reading = TscChannelReading { 66 let reading = ChannelReading {
67 sensor_value: value, 67 sensor_value: value,
68 tsc_pin: pin, 68 tsc_pin: pin,
69 }; 69 };
@@ -75,7 +75,7 @@ impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> {
75 75
76 /// Creates a new TSC acquisition bank from the provided pin configuration. 76 /// Creates a new TSC acquisition bank from the provided pin configuration.
77 /// 77 ///
78 /// This method creates a `TscAcquisitionBank` that can be used for efficient, 78 /// This method creates a `AcquisitionBank` that can be used for efficient,
79 /// repeated TSC acquisitions. It automatically generates the appropriate mask 79 /// repeated TSC acquisitions. It automatically generates the appropriate mask
80 /// for the provided pins. 80 /// for the provided pins.
81 /// 81 ///
@@ -87,16 +87,16 @@ impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> {
87 /// * `acquisition_bank_pins` - The pin configuration for the acquisition bank. 87 /// * `acquisition_bank_pins` - The pin configuration for the acquisition bank.
88 /// 88 ///
89 /// # Returns 89 /// # Returns
90 /// A new `TscAcquisitionBank` instance. 90 /// A new `AcquisitionBank` instance.
91 /// 91 ///
92 /// # Example 92 /// # Example
93 /// 93 ///
94 /// ``` 94 /// ```
95 /// let tsc = // ... initialize TSC 95 /// let tsc = // ... initialize TSC
96 /// let tsc_sensor1: TscIOPinWithRole<G1, tsc_pin_roles::Channel> = ...; 96 /// let tsc_sensor1: tsc::IOPinWithRole<G1, tsc_pin_roles::Channel> = ...;
97 /// let tsc_sensor2: TscIOPinWithRole<G2, tsc_pin_roles::Channel> = ...; 97 /// let tsc_sensor2: tsc::IOPinWithRole<G2, tsc_pin_roles::Channel> = ...;
98 /// 98 ///
99 /// let bank = tsc.create_acquisition_bank(TscAcquisitionBankPins { 99 /// let bank = tsc.create_acquisition_bank(AcquisitionBankPins {
100 /// g1_pin: Some(tsc_sensor1), 100 /// g1_pin: Some(tsc_sensor1),
101 /// g2_pin: Some(tsc_sensor2), 101 /// g2_pin: Some(tsc_sensor2),
102 /// ..Default::default() 102 /// ..Default::default()
@@ -107,10 +107,10 @@ impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> {
107 /// tsc.start(); 107 /// tsc.start();
108 /// // ... perform acquisition ... 108 /// // ... perform acquisition ...
109 /// ``` 109 /// ```
110 pub fn create_acquisition_bank(&self, acquisition_bank_pins: TscAcquisitionBankPins) -> TscAcquisitionBank { 110 pub fn create_acquisition_bank(&self, acquisition_bank_pins: AcquisitionBankPins) -> AcquisitionBank {
111 let bank_mask = acquisition_bank_pins.iter().fold(0u32, BitOr::bitor); 111 let bank_mask = acquisition_bank_pins.iter().fold(0u32, BitOr::bitor);
112 112
113 TscAcquisitionBank { 113 AcquisitionBank {
114 pins: acquisition_bank_pins, 114 pins: acquisition_bank_pins,
115 mask: bank_mask, 115 mask: bank_mask,
116 } 116 }
@@ -118,7 +118,7 @@ impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> {
118 118
119 fn make_channels_mask<Itt>(&self, channels: Itt) -> Result<u32, AcquisitionBankError> 119 fn make_channels_mask<Itt>(&self, channels: Itt) -> Result<u32, AcquisitionBankError>
120 where 120 where
121 Itt: IntoIterator<Item = TscIOPin>, 121 Itt: IntoIterator<Item = IOPin>,
122 { 122 {
123 let mut group_mask = 0u32; 123 let mut group_mask = 0u32;
124 let mut channel_mask = 0u32; 124 let mut channel_mask = 0u32;
@@ -144,7 +144,7 @@ impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> {
144 /// Sets the active channels for the next TSC acquisition. 144 /// Sets the active channels for the next TSC acquisition.
145 /// 145 ///
146 /// This is a low-level method that directly sets the channel mask. For most use cases, 146 /// This is a low-level method that directly sets the channel mask. For most use cases,
147 /// consider using `set_active_channels_bank` with a `TscAcquisitionBank` instead, which 147 /// consider using `set_active_channels_bank` with a `AcquisitionBank` instead, which
148 /// provides a higher-level interface and additional safety checks. 148 /// provides a higher-level interface and additional safety checks.
149 /// 149 ///
150 /// This method configures which sensor channels will be read during the next 150 /// This method configures which sensor channels will be read during the next
@@ -167,9 +167,9 @@ impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> {
167 T::regs().ioccr().write(|w| w.0 = mask | self.masks.shield_ios); 167 T::regs().ioccr().write(|w| w.0 = mask | self.masks.shield_ios);
168 } 168 }
169 169
170 /// Convenience method for setting active channels directly from a slice of TscIOPin. 170 /// Convenience method for setting active channels directly from a slice of tsc::IOPin.
171 /// This method performs safety checks but is less efficient for repeated use. 171 /// This method performs safety checks but is less efficient for repeated use.
172 pub fn set_active_channels(&mut self, channels: &[TscIOPin]) -> Result<(), AcquisitionBankError> { 172 pub fn set_active_channels(&mut self, channels: &[IOPin]) -> Result<(), AcquisitionBankError> {
173 let mask = self.make_channels_mask(channels.iter().cloned())?; 173 let mask = self.make_channels_mask(channels.iter().cloned())?;
174 self.set_active_channels_mask(mask); 174 self.set_active_channels_mask(mask);
175 Ok(()) 175 Ok(())
@@ -178,21 +178,21 @@ impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> {
178 /// Sets the active channels for the next TSC acquisition using a pre-configured acquisition bank. 178 /// Sets the active channels for the next TSC acquisition using a pre-configured acquisition bank.
179 /// 179 ///
180 /// This method efficiently configures the TSC peripheral to read the channels specified 180 /// This method efficiently configures the TSC peripheral to read the channels specified
181 /// in the provided `TscAcquisitionBank`. It's the recommended way to set up 181 /// in the provided `AcquisitionBank`. It's the recommended way to set up
182 /// channel configurations for acquisition, especially when using the same set of channels repeatedly. 182 /// channel configurations for acquisition, especially when using the same set of channels repeatedly.
183 /// 183 ///
184 /// # Arguments 184 /// # Arguments
185 /// 185 ///
186 /// * `bank` - A reference to a `TscAcquisitionBank` containing the pre-configured 186 /// * `bank` - A reference to a `AcquisitionBank` containing the pre-configured
187 /// TSC channel mask. 187 /// TSC channel mask.
188 /// 188 ///
189 /// # Example 189 /// # Example
190 /// 190 ///
191 /// ``` 191 /// ```
192 /// let tsc_sensor1: TscIOPinWithRole<G1, Channel> = ...; 192 /// let tsc_sensor1: tsc::IOPinWithRole<G1, Channel> = ...;
193 /// let tsc_sensor2: TscIOPinWithRole<G5, Channel> = ...; 193 /// let tsc_sensor2: tsc::IOPinWithRole<G5, Channel> = ...;
194 /// let mut touch_controller: Tsc<'_, TSC, Async> = ...; 194 /// let mut touch_controller: Tsc<'_, TSC, Async> = ...;
195 /// let bank = touch_controller.create_acquisition_bank(TscAcquisitionBankPins { 195 /// let bank = touch_controller.create_acquisition_bank(AcquisitionBankPins {
196 /// g1_pin: Some(tsc_sensor1), 196 /// g1_pin: Some(tsc_sensor1),
197 /// g2_pin: Some(tsc_sensor2), 197 /// g2_pin: Some(tsc_sensor2),
198 /// ..Default::default() 198 /// ..Default::default()
@@ -204,7 +204,7 @@ impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> {
204 /// ``` 204 /// ```
205 /// 205 ///
206 /// This method should be called before starting a new acquisition with the `start()` method. 206 /// This method should be called before starting a new acquisition with the `start()` method.
207 pub fn set_active_channels_bank(&mut self, bank: &TscAcquisitionBank) { 207 pub fn set_active_channels_bank(&mut self, bank: &AcquisitionBank) {
208 self.set_active_channels_mask(bank.mask) 208 self.set_active_channels_mask(bank.mask)
209 } 209 }
210 210
@@ -227,7 +227,7 @@ impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> {
227 227
228 pin_groups.check()?; 228 pin_groups.check()?;
229 229
230 let masks = TscIOMasks { 230 let masks = IOMasks {
231 channel_ios: pin_groups.make_channel_ios_mask(), 231 channel_ios: pin_groups.make_channel_ios_mask(),
232 shield_ios: pin_groups.make_shield_ios_mask(), 232 shield_ios: pin_groups.make_shield_ios_mask(),
233 sampling_ios: pin_groups.make_sample_ios_mask(), 233 sampling_ios: pin_groups.make_sample_ios_mask(),
diff --git a/embassy-stm32/src/tsc/tsc_io_pin.rs b/embassy-stm32/src/tsc/tsc_io_pin.rs
deleted file mode 100644
index 38b27d0b3..000000000
--- a/embassy-stm32/src/tsc/tsc_io_pin.rs
+++ /dev/null
@@ -1,200 +0,0 @@
1use core::marker::PhantomData;
2use core::ops::{BitAnd, BitOr, BitOrAssign};
3
4use super::tsc_pin_roles;
5use super::types::Group;
6
7/// Pin defines
8#[allow(missing_docs)]
9#[cfg_attr(feature = "defmt", derive(defmt::Format))]
10#[derive(PartialEq, Clone, Copy, Debug)]
11pub enum TscIOPin {
12 Group1Io1,
13 Group1Io2,
14 Group1Io3,
15 Group1Io4,
16 Group2Io1,
17 Group2Io2,
18 Group2Io3,
19 Group2Io4,
20 Group3Io1,
21 Group3Io2,
22 Group3Io3,
23 Group3Io4,
24 Group4Io1,
25 Group4Io2,
26 Group4Io3,
27 Group4Io4,
28 Group5Io1,
29 Group5Io2,
30 Group5Io3,
31 Group5Io4,
32 Group6Io1,
33 Group6Io2,
34 Group6Io3,
35 Group6Io4,
36 #[cfg(any(tsc_v2, tsc_v3))]
37 Group7Io1,
38 #[cfg(any(tsc_v2, tsc_v3))]
39 Group7Io2,
40 #[cfg(any(tsc_v2, tsc_v3))]
41 Group7Io3,
42 #[cfg(any(tsc_v2, tsc_v3))]
43 Group7Io4,
44 #[cfg(tsc_v3)]
45 Group8Io1,
46 #[cfg(tsc_v3)]
47 Group8Io2,
48 #[cfg(tsc_v3)]
49 Group8Io3,
50 #[cfg(tsc_v3)]
51 Group8Io4,
52}
53
54/// Represents a TSC I/O pin with associated group and role information.
55///
56/// This type combines a `TscIOPin` with phantom type parameters to statically
57/// encode the pin's group and role. This allows for type-safe operations
58/// on TSC pins within their specific contexts.
59///
60/// - `Group`: A type parameter representing the TSC group (e.g., `G1`, `G2`).
61/// - `Role`: A type parameter representing the pin's role (e.g., `Channel`, `Sample`).
62#[derive(Clone, Copy, Debug)]
63pub struct TscIOPinWithRole<Group, Role: tsc_pin_roles::Role> {
64 /// The underlying TSC I/O pin.
65 pub pin: TscIOPin,
66 pub(super) phantom: PhantomData<(Group, Role)>,
67}
68
69impl<G, R: tsc_pin_roles::Role> TscIOPinWithRole<G, R> {
70 pub(super) fn get_pin(wrapped_pin: TscIOPinWithRole<G, R>) -> TscIOPin {
71 wrapped_pin.pin
72 }
73}
74
75impl TscIOPin {
76 /// Maps this TscIOPin to the Group it belongs to.
77 ///
78 /// This method provides a convenient way to determine which Group
79 /// a specific TSC I/O pin is associated with.
80 pub const fn group(&self) -> Group {
81 match self {
82 TscIOPin::Group1Io1 | TscIOPin::Group1Io2 | TscIOPin::Group1Io3 | TscIOPin::Group1Io4 => Group::One,
83 TscIOPin::Group2Io1 | TscIOPin::Group2Io2 | TscIOPin::Group2Io3 | TscIOPin::Group2Io4 => Group::Two,
84 TscIOPin::Group3Io1 | TscIOPin::Group3Io2 | TscIOPin::Group3Io3 | TscIOPin::Group3Io4 => Group::Three,
85 TscIOPin::Group4Io1 | TscIOPin::Group4Io2 | TscIOPin::Group4Io3 | TscIOPin::Group4Io4 => Group::Four,
86 TscIOPin::Group5Io1 | TscIOPin::Group5Io2 | TscIOPin::Group5Io3 | TscIOPin::Group5Io4 => Group::Five,
87 TscIOPin::Group6Io1 | TscIOPin::Group6Io2 | TscIOPin::Group6Io3 | TscIOPin::Group6Io4 => Group::Six,
88 #[cfg(any(tsc_v2, tsc_v3))]
89 TscIOPin::Group7Io1 | TscIOPin::Group7Io2 | TscIOPin::Group7Io3 | TscIOPin::Group7Io4 => Group::Seven,
90 #[cfg(tsc_v3)]
91 TscIOPin::Group8Io1 | TscIOPin::Group8Io2 | TscIOPin::Group8Io3 | TscIOPin::Group8Io4 => Group::Eight,
92 }
93 }
94
95 /// Returns the `Group` associated with the given `TscIOPin`.
96 pub fn get_group(pin: TscIOPin) -> Group {
97 pin.group()
98 }
99}
100
101impl BitOr<TscIOPin> for u32 {
102 type Output = u32;
103 fn bitor(self, rhs: TscIOPin) -> Self::Output {
104 let rhs: u32 = rhs.into();
105 self | rhs
106 }
107}
108
109impl BitOr<u32> for TscIOPin {
110 type Output = u32;
111 fn bitor(self, rhs: u32) -> Self::Output {
112 let val: u32 = self.into();
113 val | rhs
114 }
115}
116
117impl BitOr for TscIOPin {
118 type Output = u32;
119 fn bitor(self, rhs: Self) -> Self::Output {
120 let val: u32 = self.into();
121 let rhs: u32 = rhs.into();
122 val | rhs
123 }
124}
125
126impl BitOrAssign<TscIOPin> for u32 {
127 fn bitor_assign(&mut self, rhs: TscIOPin) {
128 let rhs: u32 = rhs.into();
129 *self |= rhs;
130 }
131}
132
133impl BitAnd<TscIOPin> for u32 {
134 type Output = u32;
135 fn bitand(self, rhs: TscIOPin) -> Self::Output {
136 let rhs: u32 = rhs.into();
137 self & rhs
138 }
139}
140
141impl BitAnd<u32> for TscIOPin {
142 type Output = u32;
143 fn bitand(self, rhs: u32) -> Self::Output {
144 let val: u32 = self.into();
145 val & rhs
146 }
147}
148
149impl TscIOPin {
150 const fn to_u32(self) -> u32 {
151 match self {
152 TscIOPin::Group1Io1 => 0x00000001,
153 TscIOPin::Group1Io2 => 0x00000002,
154 TscIOPin::Group1Io3 => 0x00000004,
155 TscIOPin::Group1Io4 => 0x00000008,
156 TscIOPin::Group2Io1 => 0x00000010,
157 TscIOPin::Group2Io2 => 0x00000020,
158 TscIOPin::Group2Io3 => 0x00000040,
159 TscIOPin::Group2Io4 => 0x00000080,
160 TscIOPin::Group3Io1 => 0x00000100,
161 TscIOPin::Group3Io2 => 0x00000200,
162 TscIOPin::Group3Io3 => 0x00000400,
163 TscIOPin::Group3Io4 => 0x00000800,
164 TscIOPin::Group4Io1 => 0x00001000,
165 TscIOPin::Group4Io2 => 0x00002000,
166 TscIOPin::Group4Io3 => 0x00004000,
167 TscIOPin::Group4Io4 => 0x00008000,
168 TscIOPin::Group5Io1 => 0x00010000,
169 TscIOPin::Group5Io2 => 0x00020000,
170 TscIOPin::Group5Io3 => 0x00040000,
171 TscIOPin::Group5Io4 => 0x00080000,
172 TscIOPin::Group6Io1 => 0x00100000,
173 TscIOPin::Group6Io2 => 0x00200000,
174 TscIOPin::Group6Io3 => 0x00400000,
175 TscIOPin::Group6Io4 => 0x00800000,
176 #[cfg(any(tsc_v2, tsc_v3))]
177 TscIOPin::Group7Io1 => 0x01000000,
178 #[cfg(any(tsc_v2, tsc_v3))]
179 TscIOPin::Group7Io2 => 0x02000000,
180 #[cfg(any(tsc_v2, tsc_v3))]
181 TscIOPin::Group7Io3 => 0x04000000,
182 #[cfg(any(tsc_v2, tsc_v3))]
183 TscIOPin::Group7Io4 => 0x08000000,
184 #[cfg(tsc_v3)]
185 TscIOPin::Group8Io1 => 0x10000000,
186 #[cfg(tsc_v3)]
187 TscIOPin::Group8Io2 => 0x20000000,
188 #[cfg(tsc_v3)]
189 TscIOPin::Group8Io3 => 0x40000000,
190 #[cfg(tsc_v3)]
191 TscIOPin::Group8Io4 => 0x80000000,
192 }
193 }
194}
195
196impl Into<u32> for TscIOPin {
197 fn into(self) -> u32 {
198 self.to_u32()
199 }
200}
diff --git a/examples/stm32f3/src/bin/tsc_blocking.rs b/examples/stm32f3/src/bin/tsc_blocking.rs
index fa7f718e6..2c33838e5 100644
--- a/examples/stm32f3/src/bin/tsc_blocking.rs
+++ b/examples/stm32f3/src/bin/tsc_blocking.rs
@@ -64,9 +64,9 @@ async fn main(_spawner: embassy_executor::Spawner) {
64 64
65 let mut g: PinGroupWithRoles<peripherals::TSC, G4> = PinGroupWithRoles::default(); 65 let mut g: PinGroupWithRoles<peripherals::TSC, G4> = PinGroupWithRoles::default();
66 // D68 on the STM32F303ZE nucleo-board 66 // D68 on the STM32F303ZE nucleo-board
67 g.set_io2::<tsc_pin_roles::Sample>(context.PA10); 67 g.set_io2::<tsc::pin_roles::Sample>(context.PA10);
68 // D69 on the STM32F303ZE nucleo-board 68 // D69 on the STM32F303ZE nucleo-board
69 let tsc_sensor = g.set_io1::<tsc_pin_roles::Channel>(context.PA9); 69 let tsc_sensor = g.set_io1::<tsc::pin_roles::Channel>(context.PA9);
70 70
71 let pin_groups: PinGroups<peripherals::TSC> = PinGroups { 71 let pin_groups: PinGroups<peripherals::TSC> = PinGroups {
72 g4: Some(g.pin_group), 72 g4: Some(g.pin_group),
@@ -119,7 +119,7 @@ const MAX_GROUP_STATUS_READ_ATTEMPTS: usize = 10;
119// attempt to read group status and delay when still ongoing 119// attempt to read group status and delay when still ongoing
120async fn read_touch_value( 120async fn read_touch_value(
121 touch_controller: &mut tsc::Tsc<'_, peripherals::TSC, mode::Blocking>, 121 touch_controller: &mut tsc::Tsc<'_, peripherals::TSC, mode::Blocking>,
122 sensor_pin: TscIOPin, 122 sensor_pin: tsc::IOPin,
123) -> Option<u16> { 123) -> Option<u16> {
124 for _ in 0..MAX_GROUP_STATUS_READ_ATTEMPTS { 124 for _ in 0..MAX_GROUP_STATUS_READ_ATTEMPTS {
125 match touch_controller.group_get_status(sensor_pin.group()) { 125 match touch_controller.group_get_status(sensor_pin.group()) {
diff --git a/examples/stm32l0/src/bin/tsc_async.rs b/examples/stm32l0/src/bin/tsc_async.rs
index cebe9712f..dae351c2e 100644
--- a/examples/stm32l0/src/bin/tsc_async.rs
+++ b/examples/stm32l0/src/bin/tsc_async.rs
@@ -58,8 +58,8 @@ async fn main(_spawner: embassy_executor::Spawner) {
58 let context = embassy_stm32::init(device_config); 58 let context = embassy_stm32::init(device_config);
59 59
60 let mut pin_group: PinGroupWithRoles<peripherals::TSC, G1> = PinGroupWithRoles::default(); 60 let mut pin_group: PinGroupWithRoles<peripherals::TSC, G1> = PinGroupWithRoles::default();
61 pin_group.set_io1::<tsc_pin_roles::Sample>(context.PA0); 61 pin_group.set_io1::<tsc::pin_roles::Sample>(context.PA0);
62 let sensor = pin_group.set_io2::<tsc_pin_roles::Channel>(context.PA1); 62 let sensor = pin_group.set_io2::<tsc::pin_roles::Channel>(context.PA1);
63 63
64 let tsc_conf = Config { 64 let tsc_conf = Config {
65 ct_pulse_high_length: ChargeTransferPulseCycle::_4, 65 ct_pulse_high_length: ChargeTransferPulseCycle::_4,
diff --git a/examples/stm32l0/src/bin/tsc_blocking.rs b/examples/stm32l0/src/bin/tsc_blocking.rs
index 65203925c..e1f24639b 100644
--- a/examples/stm32l0/src/bin/tsc_blocking.rs
+++ b/examples/stm32l0/src/bin/tsc_blocking.rs
@@ -69,8 +69,8 @@ async fn main(_spawner: embassy_executor::Spawner) {
69 }; 69 };
70 70
71 let mut g1: PinGroupWithRoles<peripherals::TSC, G1> = PinGroupWithRoles::default(); 71 let mut g1: PinGroupWithRoles<peripherals::TSC, G1> = PinGroupWithRoles::default();
72 g1.set_io1::<tsc_pin_roles::Sample>(context.PA0); 72 g1.set_io1::<tsc::pin_roles::Sample>(context.PA0);
73 let tsc_sensor = g1.set_io2::<tsc_pin_roles::Channel>(context.PA1); 73 let tsc_sensor = g1.set_io2::<tsc::pin_roles::Channel>(context.PA1);
74 74
75 let pin_groups: PinGroups<peripherals::TSC> = PinGroups { 75 let pin_groups: PinGroups<peripherals::TSC> = PinGroups {
76 g1: Some(g1.pin_group), 76 g1: Some(g1.pin_group),
@@ -123,7 +123,7 @@ const MAX_GROUP_STATUS_READ_ATTEMPTS: usize = 10;
123// attempt to read group status and delay when still ongoing 123// attempt to read group status and delay when still ongoing
124async fn read_touch_value( 124async fn read_touch_value(
125 touch_controller: &mut tsc::Tsc<'_, peripherals::TSC, mode::Blocking>, 125 touch_controller: &mut tsc::Tsc<'_, peripherals::TSC, mode::Blocking>,
126 sensor_pin: TscIOPin, 126 sensor_pin: tsc::IOPin,
127) -> Option<u16> { 127) -> Option<u16> {
128 for _ in 0..MAX_GROUP_STATUS_READ_ATTEMPTS { 128 for _ in 0..MAX_GROUP_STATUS_READ_ATTEMPTS {
129 match touch_controller.group_get_status(sensor_pin.group()) { 129 match touch_controller.group_get_status(sensor_pin.group()) {
diff --git a/examples/stm32l0/src/bin/tsc_multipin.rs b/examples/stm32l0/src/bin/tsc_multipin.rs
index 85feb50b0..bf75a5657 100644
--- a/examples/stm32l0/src/bin/tsc_multipin.rs
+++ b/examples/stm32l0/src/bin/tsc_multipin.rs
@@ -78,7 +78,7 @@ const SENSOR_THRESHOLD: u16 = 35;
78 78
79async fn acquire_sensors( 79async fn acquire_sensors(
80 touch_controller: &mut Tsc<'static, peripherals::TSC, mode::Async>, 80 touch_controller: &mut Tsc<'static, peripherals::TSC, mode::Async>,
81 tsc_acquisition_bank: &TscAcquisitionBank, 81 tsc_acquisition_bank: &AcquisitionBank,
82) { 82) {
83 touch_controller.set_active_channels_mask(tsc_acquisition_bank.mask()); 83 touch_controller.set_active_channels_mask(tsc_acquisition_bank.mask());
84 touch_controller.start(); 84 touch_controller.start();
@@ -95,11 +95,11 @@ async fn main(_spawner: embassy_executor::Spawner) {
95 95
96 // ---------- initial configuration of TSC ---------- 96 // ---------- initial configuration of TSC ----------
97 let mut pin_group1: PinGroupWithRoles<peripherals::TSC, G1> = PinGroupWithRoles::default(); 97 let mut pin_group1: PinGroupWithRoles<peripherals::TSC, G1> = PinGroupWithRoles::default();
98 pin_group1.set_io1::<tsc_pin_roles::Sample>(context.PA0); 98 pin_group1.set_io1::<tsc::pin_roles::Sample>(context.PA0);
99 let tsc_sensor0 = pin_group1.set_io2(context.PA1); 99 let tsc_sensor0 = pin_group1.set_io2(context.PA1);
100 100
101 let mut pin_group5: PinGroupWithRoles<peripherals::TSC, G5> = PinGroupWithRoles::default(); 101 let mut pin_group5: PinGroupWithRoles<peripherals::TSC, G5> = PinGroupWithRoles::default();
102 pin_group5.set_io1::<tsc_pin_roles::Sample>(context.PB3); 102 pin_group5.set_io1::<tsc::pin_roles::Sample>(context.PB3);
103 let tsc_sensor1 = pin_group5.set_io2(context.PB4); 103 let tsc_sensor1 = pin_group5.set_io2(context.PB4);
104 let tsc_sensor2 = pin_group5.set_io3(context.PB6); 104 let tsc_sensor2 = pin_group5.set_io3(context.PB6);
105 105
@@ -128,14 +128,14 @@ async fn main(_spawner: embassy_executor::Spawner) {
128 // ---------- setting up acquisition banks ---------- 128 // ---------- setting up acquisition banks ----------
129 // sensor0 and sensor1 in this example belong to different TSC-groups, 129 // sensor0 and sensor1 in this example belong to different TSC-groups,
130 // therefore we can acquire and read them both in one go. 130 // therefore we can acquire and read them both in one go.
131 let bank1 = touch_controller.create_acquisition_bank(TscAcquisitionBankPins { 131 let bank1 = touch_controller.create_acquisition_bank(AcquisitionBankPins {
132 g1_pin: Some(tsc_sensor0), 132 g1_pin: Some(tsc_sensor0),
133 g5_pin: Some(tsc_sensor1), 133 g5_pin: Some(tsc_sensor1),
134 ..Default::default() 134 ..Default::default()
135 }); 135 });
136 // `sensor1` and `sensor2` belongs to the same TSC-group, therefore we must make sure to 136 // `sensor1` and `sensor2` belongs to the same TSC-group, therefore we must make sure to
137 // acquire them one at the time. Therefore, we organize them into different acquisition banks. 137 // acquire them one at the time. Therefore, we organize them into different acquisition banks.
138 let bank2 = touch_controller.create_acquisition_bank(TscAcquisitionBankPins { 138 let bank2 = touch_controller.create_acquisition_bank(AcquisitionBankPins {
139 g5_pin: Some(tsc_sensor2), 139 g5_pin: Some(tsc_sensor2),
140 ..Default::default() 140 ..Default::default()
141 }); 141 });
diff --git a/examples/stm32l4/src/bin/tsc_async.rs b/examples/stm32l4/src/bin/tsc_async.rs
index ada2c468f..b9a059e2e 100644
--- a/examples/stm32l4/src/bin/tsc_async.rs
+++ b/examples/stm32l4/src/bin/tsc_async.rs
@@ -50,9 +50,9 @@ async fn main(_spawner: embassy_executor::Spawner) {
50 50
51 let mut pin_group: PinGroupWithRoles<peripherals::TSC, G2> = PinGroupWithRoles::default(); 51 let mut pin_group: PinGroupWithRoles<peripherals::TSC, G2> = PinGroupWithRoles::default();
52 // D25 52 // D25
53 pin_group.set_io1::<tsc_pin_roles::Sample>(context.PB4); 53 pin_group.set_io1::<tsc::pin_roles::Sample>(context.PB4);
54 // D21 54 // D21
55 let tsc_sensor = pin_group.set_io2::<tsc_pin_roles::Channel>(context.PB5); 55 let tsc_sensor = pin_group.set_io2::<tsc::pin_roles::Channel>(context.PB5);
56 56
57 let pin_groups: PinGroups<peripherals::TSC> = PinGroups { 57 let pin_groups: PinGroups<peripherals::TSC> = PinGroups {
58 g2: Some(pin_group.pin_group), 58 g2: Some(pin_group.pin_group),
diff --git a/examples/stm32l4/src/bin/tsc_blocking.rs b/examples/stm32l4/src/bin/tsc_blocking.rs
index 76aba55ba..12084f8e2 100644
--- a/examples/stm32l4/src/bin/tsc_blocking.rs
+++ b/examples/stm32l4/src/bin/tsc_blocking.rs
@@ -74,9 +74,9 @@ async fn main(_spawner: embassy_executor::Spawner) {
74 74
75 let mut g2: PinGroupWithRoles<peripherals::TSC, G2> = PinGroupWithRoles::default(); 75 let mut g2: PinGroupWithRoles<peripherals::TSC, G2> = PinGroupWithRoles::default();
76 // D25 76 // D25
77 g2.set_io1::<tsc_pin_roles::Sample>(context.PB4); 77 g2.set_io1::<tsc::pin_roles::Sample>(context.PB4);
78 // D21 78 // D21
79 let tsc_sensor = g2.set_io2::<tsc_pin_roles::Channel>(context.PB5); 79 let tsc_sensor = g2.set_io2::<tsc::pin_roles::Channel>(context.PB5);
80 80
81 let pin_groups: PinGroups<peripherals::TSC> = PinGroups { 81 let pin_groups: PinGroups<peripherals::TSC> = PinGroups {
82 g2: Some(g2.pin_group), 82 g2: Some(g2.pin_group),
@@ -128,7 +128,7 @@ const MAX_GROUP_STATUS_READ_ATTEMPTS: usize = 10;
128// attempt to read group status and delay when still ongoing 128// attempt to read group status and delay when still ongoing
129async fn read_touch_value( 129async fn read_touch_value(
130 touch_controller: &mut tsc::Tsc<'_, peripherals::TSC, mode::Blocking>, 130 touch_controller: &mut tsc::Tsc<'_, peripherals::TSC, mode::Blocking>,
131 sensor_pin: TscIOPin, 131 sensor_pin: tsc::IOPin,
132) -> Option<u16> { 132) -> Option<u16> {
133 for _ in 0..MAX_GROUP_STATUS_READ_ATTEMPTS { 133 for _ in 0..MAX_GROUP_STATUS_READ_ATTEMPTS {
134 match touch_controller.group_get_status(sensor_pin.group()) { 134 match touch_controller.group_get_status(sensor_pin.group()) {
diff --git a/examples/stm32l4/src/bin/tsc_multipin.rs b/examples/stm32l4/src/bin/tsc_multipin.rs
index f26a6f4eb..2fadbe16a 100644
--- a/examples/stm32l4/src/bin/tsc_multipin.rs
+++ b/examples/stm32l4/src/bin/tsc_multipin.rs
@@ -74,7 +74,7 @@ const SENSOR_THRESHOLD: u16 = 20;
74 74
75async fn acquire_sensors( 75async fn acquire_sensors(
76 touch_controller: &mut Tsc<'static, peripherals::TSC, mode::Async>, 76 touch_controller: &mut Tsc<'static, peripherals::TSC, mode::Async>,
77 tsc_acquisition_bank: &TscAcquisitionBank, 77 tsc_acquisition_bank: &AcquisitionBank,
78) { 78) {
79 touch_controller.set_active_channels_mask(tsc_acquisition_bank.mask()); 79 touch_controller.set_active_channels_mask(tsc_acquisition_bank.mask());
80 touch_controller.start(); 80 touch_controller.start();
@@ -91,11 +91,11 @@ async fn main(_spawner: embassy_executor::Spawner) {
91 91
92 // ---------- initial configuration of TSC ---------- 92 // ---------- initial configuration of TSC ----------
93 let mut g1: PinGroupWithRoles<peripherals::TSC, G1> = PinGroupWithRoles::default(); 93 let mut g1: PinGroupWithRoles<peripherals::TSC, G1> = PinGroupWithRoles::default();
94 g1.set_io1::<tsc_pin_roles::Sample>(context.PB12); 94 g1.set_io1::<tsc::pin_roles::Sample>(context.PB12);
95 let sensor0 = g1.set_io2::<tsc_pin_roles::Channel>(context.PB13); 95 let sensor0 = g1.set_io2::<tsc::pin_roles::Channel>(context.PB13);
96 96
97 let mut g2: PinGroupWithRoles<peripherals::TSC, G2> = PinGroupWithRoles::default(); 97 let mut g2: PinGroupWithRoles<peripherals::TSC, G2> = PinGroupWithRoles::default();
98 g2.set_io1::<tsc_pin_roles::Sample>(context.PB4); 98 g2.set_io1::<tsc::pin_roles::Sample>(context.PB4);
99 let sensor1 = g2.set_io2(context.PB5); 99 let sensor1 = g2.set_io2(context.PB5);
100 let sensor2 = g2.set_io3(context.PB6); 100 let sensor2 = g2.set_io3(context.PB6);
101 101
@@ -124,14 +124,14 @@ async fn main(_spawner: embassy_executor::Spawner) {
124 // ---------- setting up acquisition banks ---------- 124 // ---------- setting up acquisition banks ----------
125 // sensor0 and sensor1 belong to different TSC-groups, therefore we can acquire and 125 // sensor0 and sensor1 belong to different TSC-groups, therefore we can acquire and
126 // read them both in one go. 126 // read them both in one go.
127 let bank1 = touch_controller.create_acquisition_bank(TscAcquisitionBankPins { 127 let bank1 = touch_controller.create_acquisition_bank(AcquisitionBankPins {
128 g1_pin: Some(sensor0), 128 g1_pin: Some(sensor0),
129 g2_pin: Some(sensor1), 129 g2_pin: Some(sensor1),
130 ..Default::default() 130 ..Default::default()
131 }); 131 });
132 // `sensor1` and `sensor2` belongs to the same TSC-group, therefore we must make sure to 132 // `sensor1` and `sensor2` belongs to the same TSC-group, therefore we must make sure to
133 // acquire them one at the time. We do this by organizing them into different acquisition banks. 133 // acquire them one at the time. We do this by organizing them into different acquisition banks.
134 let bank2 = touch_controller.create_acquisition_bank(TscAcquisitionBankPins { 134 let bank2 = touch_controller.create_acquisition_bank(AcquisitionBankPins {
135 g2_pin: Some(sensor2), 135 g2_pin: Some(sensor2),
136 ..Default::default() 136 ..Default::default()
137 }); 137 });
diff --git a/examples/stm32u5/src/bin/tsc.rs b/examples/stm32u5/src/bin/tsc.rs
index 800486665..a85acc4c7 100644
--- a/examples/stm32u5/src/bin/tsc.rs
+++ b/examples/stm32u5/src/bin/tsc.rs
@@ -36,15 +36,15 @@ async fn main(_spawner: embassy_executor::Spawner) {
36 }; 36 };
37 37
38 let mut g1: PinGroupWithRoles<peripherals::TSC, G1> = PinGroupWithRoles::default(); 38 let mut g1: PinGroupWithRoles<peripherals::TSC, G1> = PinGroupWithRoles::default();
39 g1.set_io2::<tsc_pin_roles::Sample>(context.PB13); 39 g1.set_io2::<tsc::pin_roles::Sample>(context.PB13);
40 g1.set_io3::<tsc_pin_roles::Shield>(context.PB14); 40 g1.set_io3::<tsc::pin_roles::Shield>(context.PB14);
41 41
42 let mut g2: PinGroupWithRoles<peripherals::TSC, G2> = PinGroupWithRoles::default(); 42 let mut g2: PinGroupWithRoles<peripherals::TSC, G2> = PinGroupWithRoles::default();
43 g2.set_io1::<tsc_pin_roles::Sample>(context.PB4); 43 g2.set_io1::<tsc::pin_roles::Sample>(context.PB4);
44 let sensor0 = g2.set_io2(context.PB5); 44 let sensor0 = g2.set_io2(context.PB5);
45 45
46 let mut g7: PinGroupWithRoles<peripherals::TSC, G7> = PinGroupWithRoles::default(); 46 let mut g7: PinGroupWithRoles<peripherals::TSC, G7> = PinGroupWithRoles::default();
47 g7.set_io2::<tsc_pin_roles::Sample>(context.PE3); 47 g7.set_io2::<tsc::pin_roles::Sample>(context.PE3);
48 let sensor1 = g7.set_io3(context.PE4); 48 let sensor1 = g7.set_io3(context.PE4);
49 49
50 let pin_groups: PinGroups<peripherals::TSC> = PinGroups { 50 let pin_groups: PinGroups<peripherals::TSC> = PinGroups {
@@ -56,7 +56,7 @@ async fn main(_spawner: embassy_executor::Spawner) {
56 56
57 let mut touch_controller = tsc::Tsc::new_async(context.TSC, pin_groups, config, Irqs).unwrap(); 57 let mut touch_controller = tsc::Tsc::new_async(context.TSC, pin_groups, config, Irqs).unwrap();
58 58
59 let acquisition_bank = touch_controller.create_acquisition_bank(TscAcquisitionBankPins { 59 let acquisition_bank = touch_controller.create_acquisition_bank(AcquisitionBankPins {
60 g2_pin: Some(sensor0), 60 g2_pin: Some(sensor0),
61 g7_pin: Some(sensor1), 61 g7_pin: Some(sensor1),
62 ..Default::default() 62 ..Default::default()