aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer/mod.rs
diff options
context:
space:
mode:
authormelvdl <[email protected]>2025-06-27 01:08:28 +0200
committermelvdl <[email protected]>2025-06-27 01:08:28 +0200
commit6f88c2c73caa63a6e534130f4a064cb95d3e9d7d (patch)
treefdddad93e4f48f32ff15a3b8ad6cd0ae12095fd4 /embassy-stm32/src/timer/mod.rs
parentcbd24bf2eece65a787fc085c255e9b2932ea73e3 (diff)
stm32: rename timer channel trait; replace impls via macro with impls generic over timer channels
Diffstat (limited to 'embassy-stm32/src/timer/mod.rs')
-rw-r--r--embassy-stm32/src/timer/mod.rs48
1 files changed, 24 insertions, 24 deletions
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs
index 362d95e25..7062f5f4c 100644
--- a/embassy-stm32/src/timer/mod.rs
+++ b/embassy-stm32/src/timer/mod.rs
@@ -19,7 +19,7 @@ use crate::rcc::RccPeripheral;
19 19
20/// Timer channel. 20/// Timer channel.
21#[derive(Clone, Copy)] 21#[derive(Clone, Copy)]
22pub enum TimerChannel { 22pub enum Channel {
23 /// Channel 1. 23 /// Channel 1.
24 Ch1, 24 Ch1,
25 /// Channel 2. 25 /// Channel 2.
@@ -30,14 +30,14 @@ pub enum TimerChannel {
30 Ch4, 30 Ch4,
31} 31}
32 32
33impl TimerChannel { 33impl Channel {
34 /// Get the channel index (0..3) 34 /// Get the channel index (0..3)
35 pub fn index(&self) -> usize { 35 pub fn index(&self) -> usize {
36 match self { 36 match self {
37 TimerChannel::Ch1 => 0, 37 Channel::Ch1 => 0,
38 TimerChannel::Ch2 => 1, 38 Channel::Ch2 => 1,
39 TimerChannel::Ch3 => 2, 39 Channel::Ch3 => 2,
40 TimerChannel::Ch4 => 3, 40 Channel::Ch4 => 3,
41 } 41 }
42 } 42 }
43} 43}
@@ -53,33 +53,33 @@ pub enum Ch4 {}
53 53
54/// Timer channel trait. 54/// Timer channel trait.
55#[allow(private_bounds)] 55#[allow(private_bounds)]
56pub trait Channel: SealedChannel { 56pub trait TimerChannel: SealedTimerChannel {
57 /// The runtime channel. 57 /// The runtime channel.
58 const CHANNEL: TimerChannel; 58 const CHANNEL: Channel;
59} 59}
60 60
61trait SealedChannel {} 61trait SealedTimerChannel {}
62 62
63impl Channel for Ch1 { 63impl TimerChannel for Ch1 {
64 const CHANNEL: TimerChannel = TimerChannel::Ch1; 64 const CHANNEL: Channel = Channel::Ch1;
65} 65}
66 66
67impl Channel for Ch2 { 67impl TimerChannel for Ch2 {
68 const CHANNEL: TimerChannel = TimerChannel::Ch2; 68 const CHANNEL: Channel = Channel::Ch2;
69} 69}
70 70
71impl Channel for Ch3 { 71impl TimerChannel for Ch3 {
72 const CHANNEL: TimerChannel = TimerChannel::Ch3; 72 const CHANNEL: Channel = Channel::Ch3;
73} 73}
74 74
75impl Channel for Ch4 { 75impl TimerChannel for Ch4 {
76 const CHANNEL: TimerChannel = TimerChannel::Ch4; 76 const CHANNEL: Channel = Channel::Ch4;
77} 77}
78 78
79impl SealedChannel for Ch1 {} 79impl SealedTimerChannel for Ch1 {}
80impl SealedChannel for Ch2 {} 80impl SealedTimerChannel for Ch2 {}
81impl SealedChannel for Ch3 {} 81impl SealedTimerChannel for Ch3 {}
82impl SealedChannel for Ch4 {} 82impl SealedTimerChannel for Ch4 {}
83 83
84/// Timer break input. 84/// Timer break input.
85#[derive(Clone, Copy)] 85#[derive(Clone, Copy)]
@@ -223,10 +223,10 @@ pub trait AdvancedInstance2Channel: BasicInstance + GeneralInstance2Channel + Ad
223/// Advanced 16-bit timer with 4 channels instance. 223/// Advanced 16-bit timer with 4 channels instance.
224pub trait AdvancedInstance4Channel: AdvancedInstance2Channel + GeneralInstance4Channel {} 224pub trait AdvancedInstance4Channel: AdvancedInstance2Channel + GeneralInstance4Channel {}
225 225
226pin_trait!(TimerPin, GeneralInstance4Channel, Channel); 226pin_trait!(TimerPin, GeneralInstance4Channel, TimerChannel);
227pin_trait!(ExternalTriggerPin, GeneralInstance4Channel); 227pin_trait!(ExternalTriggerPin, GeneralInstance4Channel);
228 228
229pin_trait!(TimerComplementaryPin, AdvancedInstance4Channel, Channel); 229pin_trait!(TimerComplementaryPin, AdvancedInstance4Channel, TimerChannel);
230 230
231pin_trait!(BreakInputPin, AdvancedInstance4Channel, BreakInput); 231pin_trait!(BreakInputPin, AdvancedInstance4Channel, BreakInput);
232 232
@@ -236,7 +236,7 @@ pin_trait!(BreakInputComparator2Pin, AdvancedInstance4Channel, BreakInput);
236// Update Event trigger DMA for every timer 236// Update Event trigger DMA for every timer
237dma_trait!(UpDma, BasicInstance); 237dma_trait!(UpDma, BasicInstance);
238 238
239dma_trait!(Dma, GeneralInstance4Channel, Channel); 239dma_trait!(Dma, GeneralInstance4Channel, TimerChannel);
240 240
241#[allow(unused)] 241#[allow(unused)]
242macro_rules! impl_core_timer { 242macro_rules! impl_core_timer {