diff options
| author | melvdl <[email protected]> | 2025-06-27 01:08:28 +0200 |
|---|---|---|
| committer | melvdl <[email protected]> | 2025-06-27 01:08:28 +0200 |
| commit | 6f88c2c73caa63a6e534130f4a064cb95d3e9d7d (patch) | |
| tree | fdddad93e4f48f32ff15a3b8ad6cd0ae12095fd4 /embassy-stm32/src/timer/mod.rs | |
| parent | cbd24bf2eece65a787fc085c255e9b2932ea73e3 (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.rs | 48 |
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)] |
| 22 | pub enum TimerChannel { | 22 | pub 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 | ||
| 33 | impl TimerChannel { | 33 | impl 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)] |
| 56 | pub trait Channel: SealedChannel { | 56 | pub trait TimerChannel: SealedTimerChannel { |
| 57 | /// The runtime channel. | 57 | /// The runtime channel. |
| 58 | const CHANNEL: TimerChannel; | 58 | const CHANNEL: Channel; |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | trait SealedChannel {} | 61 | trait SealedTimerChannel {} |
| 62 | 62 | ||
| 63 | impl Channel for Ch1 { | 63 | impl TimerChannel for Ch1 { |
| 64 | const CHANNEL: TimerChannel = TimerChannel::Ch1; | 64 | const CHANNEL: Channel = Channel::Ch1; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | impl Channel for Ch2 { | 67 | impl TimerChannel for Ch2 { |
| 68 | const CHANNEL: TimerChannel = TimerChannel::Ch2; | 68 | const CHANNEL: Channel = Channel::Ch2; |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | impl Channel for Ch3 { | 71 | impl TimerChannel for Ch3 { |
| 72 | const CHANNEL: TimerChannel = TimerChannel::Ch3; | 72 | const CHANNEL: Channel = Channel::Ch3; |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | impl Channel for Ch4 { | 75 | impl TimerChannel for Ch4 { |
| 76 | const CHANNEL: TimerChannel = TimerChannel::Ch4; | 76 | const CHANNEL: Channel = Channel::Ch4; |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | impl SealedChannel for Ch1 {} | 79 | impl SealedTimerChannel for Ch1 {} |
| 80 | impl SealedChannel for Ch2 {} | 80 | impl SealedTimerChannel for Ch2 {} |
| 81 | impl SealedChannel for Ch3 {} | 81 | impl SealedTimerChannel for Ch3 {} |
| 82 | impl SealedChannel for Ch4 {} | 82 | impl 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. |
| 224 | pub trait AdvancedInstance4Channel: AdvancedInstance2Channel + GeneralInstance4Channel {} | 224 | pub trait AdvancedInstance4Channel: AdvancedInstance2Channel + GeneralInstance4Channel {} |
| 225 | 225 | ||
| 226 | pin_trait!(TimerPin, GeneralInstance4Channel, Channel); | 226 | pin_trait!(TimerPin, GeneralInstance4Channel, TimerChannel); |
| 227 | pin_trait!(ExternalTriggerPin, GeneralInstance4Channel); | 227 | pin_trait!(ExternalTriggerPin, GeneralInstance4Channel); |
| 228 | 228 | ||
| 229 | pin_trait!(TimerComplementaryPin, AdvancedInstance4Channel, Channel); | 229 | pin_trait!(TimerComplementaryPin, AdvancedInstance4Channel, TimerChannel); |
| 230 | 230 | ||
| 231 | pin_trait!(BreakInputPin, AdvancedInstance4Channel, BreakInput); | 231 | pin_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 |
| 237 | dma_trait!(UpDma, BasicInstance); | 237 | dma_trait!(UpDma, BasicInstance); |
| 238 | 238 | ||
| 239 | dma_trait!(Dma, GeneralInstance4Channel, Channel); | 239 | dma_trait!(Dma, GeneralInstance4Channel, TimerChannel); |
| 240 | 240 | ||
| 241 | #[allow(unused)] | 241 | #[allow(unused)] |
| 242 | macro_rules! impl_core_timer { | 242 | macro_rules! impl_core_timer { |
