1use embassy_hal_internal::Peripheral;
2use crate::interrupt;
5use crate::rcc::SealedRccEnableReset;
6
7#[derive(Clone, Copy)]
9pub enum Channel {
10 Ch1,
12 Ch2,
14 Ch3,
16 Ch4,
18 Ch5,
20 Ch6,
22}
23
24impl Channel {
25 pub fn index(&self) -> usize {
27 match self {
28 Channel::Ch1 => 0,
29 Channel::Ch2 => 1,
30 Channel::Ch3 => 2,
31 Channel::Ch4 => 3,
32 Channel::Ch5 => 4,
33 Channel::Ch6 => 5,
34 }
35 }
36}
37
38#[derive(Clone, Copy, PartialEq, Eq, Debug)]
40#[cfg_attr(feature = "defmt", derive(defmt::Format))]
41pub enum TimerBits {
42 Bits16,
44 Bits32,
46}
47
48trait SealedInstance: SealedRccEnableReset + Peripheral<P = Self> {
63 }
66
67#[allow(private_bounds)]
69pub trait Instance: SealedInstance + 'static {
70 type Interrupt: interrupt::typelevel::Interrupt;
72
73 const BITS: TimerBits;
75
76 fn regs() -> *mut ();
80}
81
82pub trait AtimInstance: Instance + 'static {}
83pub trait GptimInstance: Instance + 'static {}
84pub trait BimInstance: Instance + 'static {}
85
86
87
88use crate::peripherals;
90
91impl SealedInstance for peripherals::ATIM1 {}
92impl Instance for peripherals::ATIM1 {
93 type Interrupt = interrupt::typelevel::ATIM1;
94 const BITS: TimerBits = TimerBits::Bits32;
95 fn regs() -> *mut () {
96 crate::pac::ATIM1.as_ptr()
97 }
98}
99impl AtimInstance for peripherals::ATIM1 {}
100
101impl SealedInstance for peripherals::GPTIM1 {}
102impl Instance for peripherals::GPTIM1 {
103 type Interrupt = interrupt::typelevel::GPTIM1;
104 const BITS: TimerBits = TimerBits::Bits32;
105 fn regs() -> *mut () {
106 crate::pac::GPTIM1.as_ptr()
107 }
108}
109impl GptimInstance for peripherals::GPTIM1 {}
110
111impl SealedInstance for peripherals::GPTIM2 {}
112impl Instance for peripherals::GPTIM2 {
113 type Interrupt = interrupt::typelevel::GPTIM2;
114 const BITS: TimerBits = TimerBits::Bits32;
115 fn regs() -> *mut () {
116 crate::pac::GPTIM2.as_ptr()
117 }
118}
119impl GptimInstance for peripherals::GPTIM2 {}
120
121impl SealedInstance for peripherals::BTIM1 {}
122impl Instance for peripherals::BTIM1 {
123 type Interrupt = interrupt::typelevel::BTIM1;
124 const BITS: TimerBits = TimerBits::Bits32;
125 fn regs() -> *mut () {
126 crate::pac::BTIM1.as_ptr()
127 }
128}
129impl BimInstance for peripherals::BTIM1 {}
130
131impl SealedInstance for peripherals::BTIM2 {}
132impl Instance for peripherals::BTIM2 {
133 type Interrupt = interrupt::typelevel::BTIM2;
134 const BITS: TimerBits = TimerBits::Bits32;
135 fn regs() -> *mut () {
136 crate::pac::BTIM2.as_ptr()
137 }
138}
139impl BimInstance for peripherals::BTIM2 {}