diff options
| author | Daniel Berlin <[email protected]> | 2023-09-30 12:14:20 -0400 |
|---|---|---|
| committer | Daniel Berlin <[email protected]> | 2023-09-30 12:14:20 -0400 |
| commit | 74eb51981091e2e8fab4f8d251353f7b8c2f7584 (patch) | |
| tree | 126d1c7f90c36db46d5dd8c463cc65ed815b0fc7 | |
| parent | 61dc36b1f28d38b55d2fe65f4de3fba7e8036b99 (diff) | |
Move trait impls out of macros
| -rw-r--r-- | embassy-stm32/src/timer/mod.rs | 489 |
1 files changed, 143 insertions, 346 deletions
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index 4402e1cf3..04919659b 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs | |||
| @@ -22,27 +22,67 @@ pub(crate) mod sealed { | |||
| 22 | 22 | ||
| 23 | fn regs() -> crate::pac::timer::TimBasic; | 23 | fn regs() -> crate::pac::timer::TimBasic; |
| 24 | 24 | ||
| 25 | fn start(&mut self); | 25 | fn start(&mut self) { |
| 26 | Self::regs().cr1().modify(|r| r.set_cen(true)); | ||
| 27 | } | ||
| 26 | 28 | ||
| 27 | fn stop(&mut self); | 29 | fn stop(&mut self) { |
| 30 | Self::regs().cr1().modify(|r| r.set_cen(false)); | ||
| 31 | } | ||
| 28 | 32 | ||
| 29 | fn reset(&mut self); | 33 | fn reset(&mut self) { |
| 34 | Self::regs().cnt().write(|r| r.set_cnt(0)); | ||
| 35 | } | ||
| 30 | 36 | ||
| 31 | fn set_frequency(&mut self, frequency: Hertz); | 37 | fn set_frequency(&mut self, frequency: Hertz) { |
| 38 | let f = frequency.0; | ||
| 39 | let timer_f = Self::frequency().0; | ||
| 40 | assert!(f > 0); | ||
| 41 | let pclk_ticks_per_timer_period = timer_f / f; | ||
| 42 | let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 16)).try_into()); | ||
| 43 | let arr: u16 = unwrap!((pclk_ticks_per_timer_period / (u32::from(psc) + 1)).try_into()); | ||
| 44 | |||
| 45 | let regs = Self::regs(); | ||
| 46 | regs.psc().write(|r| r.set_psc(psc)); | ||
| 47 | regs.arr().write(|r| r.set_arr(arr)); | ||
| 48 | |||
| 49 | regs.cr1().modify(|r| r.set_urs(vals::Urs::COUNTERONLY)); | ||
| 50 | regs.egr().write(|r| r.set_ug(true)); | ||
| 51 | regs.cr1().modify(|r| r.set_urs(vals::Urs::ANYEVENT)); | ||
| 52 | } | ||
| 32 | 53 | ||
| 33 | fn clear_update_interrupt(&mut self) -> bool; | 54 | fn clear_update_interrupt(&mut self) -> bool { |
| 55 | let regs = Self::regs(); | ||
| 56 | let sr = regs.sr().read(); | ||
| 57 | if sr.uif() { | ||
| 58 | regs.sr().modify(|r| { | ||
| 59 | r.set_uif(false); | ||
| 60 | }); | ||
| 61 | true | ||
| 62 | } else { | ||
| 63 | false | ||
| 64 | } | ||
| 65 | } | ||
| 34 | 66 | ||
| 35 | fn enable_update_interrupt(&mut self, enable: bool); | 67 | fn enable_update_interrupt(&mut self, enable: bool) { |
| 68 | Self::regs().dier().write(|r| r.set_uie(enable)); | ||
| 69 | } | ||
| 36 | 70 | ||
| 37 | fn set_autoreload_preload(&mut self, enable: vals::Arpe); | 71 | fn set_autoreload_preload(&mut self, enable: vals::Arpe) { |
| 72 | Self::regs().cr1().modify(|r| r.set_arpe(enable)); | ||
| 73 | } | ||
| 38 | } | 74 | } |
| 39 | 75 | ||
| 40 | pub trait GeneralPurpose16bitInstance: Basic16bitInstance { | 76 | pub trait GeneralPurpose16bitInstance: Basic16bitInstance { |
| 41 | fn regs_gp16() -> crate::pac::timer::TimGp16; | 77 | fn regs_gp16() -> crate::pac::timer::TimGp16; |
| 42 | 78 | ||
| 43 | fn set_count_direction(&mut self, direction: vals::Dir); | 79 | fn set_count_direction(&mut self, direction: vals::Dir) { |
| 80 | Self::regs_gp16().cr1().modify(|r| r.set_dir(direction)); | ||
| 81 | } | ||
| 44 | 82 | ||
| 45 | fn set_clock_division(&mut self, ckd: vals::Ckd); | 83 | fn set_clock_division(&mut self, ckd: vals::Ckd) { |
| 84 | Self::regs_gp16().cr1().modify(|r| r.set_ckd(ckd)); | ||
| 85 | } | ||
| 46 | } | 86 | } |
| 47 | 87 | ||
| 48 | pub trait GeneralPurpose32bitInstance: GeneralPurpose16bitInstance { | 88 | pub trait GeneralPurpose32bitInstance: GeneralPurpose16bitInstance { |
| @@ -56,50 +96,115 @@ pub(crate) mod sealed { | |||
| 56 | } | 96 | } |
| 57 | 97 | ||
| 58 | pub trait CaptureCompare16bitInstance: GeneralPurpose16bitInstance { | 98 | pub trait CaptureCompare16bitInstance: GeneralPurpose16bitInstance { |
| 59 | fn set_input_capture_filter(&mut self, channel: Channel, icf: vals::Icf); | 99 | fn set_input_capture_filter(&mut self, channel: Channel, icf: vals::Icf) { |
| 60 | 100 | let raw_channel = channel.raw(); | |
| 61 | fn clear_input_interrupt(&mut self, channel: Channel); | 101 | Self::regs_gp16() |
| 62 | 102 | .ccmr_input(raw_channel / 2) | |
| 63 | fn enable_input_interrupt(&mut self, channel: Channel, enable: bool); | 103 | .modify(|r| r.set_icf(raw_channel % 2, icf)); |
| 64 | 104 | } | |
| 65 | fn set_input_capture_prescaler(&mut self, channel: Channel, val: u8); | ||
| 66 | 105 | ||
| 67 | fn set_input_ti_selection(&mut self, channel: Channel, tisel: InputTISelection); | 106 | fn clear_input_interrupt(&mut self, channel: Channel) { |
| 107 | Self::regs_gp16().sr().modify(|r| r.set_ccif(channel.raw(), false)); | ||
| 108 | } | ||
| 68 | 109 | ||
| 69 | fn set_input_capture_mode(&mut self, channel: Channel, mode: InputCaptureMode); | 110 | fn enable_input_interrupt(&mut self, channel: Channel, enable: bool) { |
| 111 | Self::regs_gp16().dier().modify(|r| r.set_ccie(channel.raw(), enable)); | ||
| 112 | } | ||
| 113 | fn set_input_capture_prescaler(&mut self, channel: Channel, factor: u8) { | ||
| 114 | let raw_channel = channel.raw(); | ||
| 115 | Self::regs_gp16() | ||
| 116 | .ccmr_input(raw_channel / 2) | ||
| 117 | .modify(|r| r.set_icpsc(raw_channel % 2, factor)); | ||
| 118 | } | ||
| 70 | 119 | ||
| 71 | /// Global output enable. Does not do anything on non-advanced timers. | 120 | fn set_input_ti_selection(&mut self, channel: Channel, tisel: InputTISelection) { |
| 72 | fn enable_outputs(&mut self, enable: bool); | 121 | let raw_channel = channel.raw(); |
| 122 | Self::regs_gp16() | ||
| 123 | .ccmr_input(raw_channel / 2) | ||
| 124 | .modify(|r| r.set_ccs(raw_channel % 2, tisel.into())); | ||
| 125 | } | ||
| 126 | fn set_input_capture_mode(&mut self, channel: Channel, mode: InputCaptureMode) { | ||
| 127 | Self::regs_gp16().ccer().modify(|r| match mode { | ||
| 128 | InputCaptureMode::Rising => { | ||
| 129 | r.set_ccnp(channel.raw(), false); | ||
| 130 | r.set_ccp(channel.raw(), false); | ||
| 131 | } | ||
| 132 | InputCaptureMode::Falling => { | ||
| 133 | r.set_ccnp(channel.raw(), false); | ||
| 134 | r.set_ccp(channel.raw(), true); | ||
| 135 | } | ||
| 136 | InputCaptureMode::BothEdges => { | ||
| 137 | r.set_ccnp(channel.raw(), true); | ||
| 138 | r.set_ccp(channel.raw(), true); | ||
| 139 | } | ||
| 140 | }); | ||
| 141 | } | ||
| 142 | fn enable_outputs(&mut self, _enable: bool) {} | ||
| 73 | 143 | ||
| 74 | fn set_output_compare_mode(&mut self, channel: Channel, mode: OutputCompareMode); | 144 | fn set_output_compare_mode(&mut self, channel: Channel, mode: OutputCompareMode) { |
| 145 | let r = Self::regs_gp16(); | ||
| 146 | let raw_channel: usize = channel.raw(); | ||
| 147 | r.ccmr_output(raw_channel / 2) | ||
| 148 | .modify(|w| w.set_ocm(raw_channel % 2, mode.into())); | ||
| 149 | } | ||
| 75 | 150 | ||
| 76 | fn set_output_polarity(&mut self, channel: Channel, polarity: OutputPolarity); | 151 | fn set_output_polarity(&mut self, channel: Channel, polarity: OutputPolarity) { |
| 152 | Self::regs_gp16() | ||
| 153 | .ccer() | ||
| 154 | .modify(|w| w.set_ccp(channel.raw(), polarity.into())); | ||
| 155 | } | ||
| 77 | 156 | ||
| 78 | fn enable_channel(&mut self, channel: Channel, enable: bool); | 157 | fn enable_channel(&mut self, channel: Channel, enable: bool) { |
| 158 | Self::regs_gp16().ccer().modify(|w| w.set_cce(channel.raw(), enable)); | ||
| 159 | } | ||
| 79 | 160 | ||
| 80 | fn set_compare_value(&mut self, channel: Channel, value: u16); | 161 | fn set_compare_value(&mut self, channel: Channel, value: u16) { |
| 162 | Self::regs_gp16().ccr(channel.raw()).modify(|w| w.set_ccr(value)); | ||
| 163 | } | ||
| 81 | 164 | ||
| 82 | fn get_capture_value(&mut self, channel: Channel) -> u16; | 165 | fn get_capture_value(&mut self, channel: Channel) -> u16 { |
| 166 | Self::regs_gp16().ccr(channel.raw()).read().ccr() | ||
| 167 | } | ||
| 83 | 168 | ||
| 84 | fn get_max_compare_value(&self) -> u16; | 169 | fn get_max_compare_value(&self) -> u16 { |
| 170 | Self::regs_gp16().arr().read().arr() | ||
| 171 | } | ||
| 85 | } | 172 | } |
| 86 | 173 | ||
| 87 | pub trait ComplementaryCaptureCompare16bitInstance: CaptureCompare16bitInstance { | 174 | pub trait ComplementaryCaptureCompare16bitInstance: CaptureCompare16bitInstance + AdvancedControlInstance { |
| 88 | fn set_complementary_output_polarity(&mut self, channel: Channel, polarity: OutputPolarity); | 175 | fn set_complementary_output_polarity(&mut self, channel: Channel, polarity: OutputPolarity) { |
| 176 | Self::regs_advanced() | ||
| 177 | .ccer() | ||
| 178 | .modify(|w| w.set_ccnp(channel.raw(), polarity.into())); | ||
| 179 | } | ||
| 89 | 180 | ||
| 90 | fn set_dead_time_clock_division(&mut self, value: vals::Ckd); | 181 | fn set_dead_time_clock_division(&mut self, value: vals::Ckd) { |
| 182 | Self::regs_advanced().cr1().modify(|w| w.set_ckd(value)); | ||
| 183 | } | ||
| 91 | 184 | ||
| 92 | fn set_dead_time_value(&mut self, value: u8); | 185 | fn set_dead_time_value(&mut self, value: u8) { |
| 186 | Self::regs_advanced().bdtr().modify(|w| w.set_dtg(value)); | ||
| 187 | } | ||
| 93 | 188 | ||
| 94 | fn enable_complementary_channel(&mut self, channel: Channel, enable: bool); | 189 | fn enable_complementary_channel(&mut self, channel: Channel, enable: bool) { |
| 190 | Self::regs_advanced() | ||
| 191 | .ccer() | ||
| 192 | .modify(|w| w.set_ccne(channel.raw(), enable)); | ||
| 193 | } | ||
| 95 | } | 194 | } |
| 96 | 195 | ||
| 97 | pub trait CaptureCompare32bitInstance: GeneralPurpose32bitInstance + CaptureCompare16bitInstance { | 196 | pub trait CaptureCompare32bitInstance: GeneralPurpose32bitInstance + CaptureCompare16bitInstance { |
| 98 | fn set_compare_value(&mut self, channel: Channel, value: u32); | 197 | fn set_compare_value(&mut self, channel: Channel, value: u32) { |
| 198 | Self::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(value)); | ||
| 199 | } | ||
| 99 | 200 | ||
| 100 | fn get_capture_value(&mut self, channel: Channel) -> u32; | 201 | fn get_capture_value(&mut self, channel: Channel) -> u32 { |
| 202 | Self::regs_gp32().ccr(channel.raw()).read().ccr() | ||
| 203 | } | ||
| 101 | 204 | ||
| 102 | fn get_max_compare_value(&self) -> u32; | 205 | fn get_max_compare_value(&self) -> u32 { |
| 206 | Self::regs_gp32().arr().read().arr() as u32 | ||
| 207 | } | ||
| 103 | } | 208 | } |
| 104 | } | 209 | } |
| 105 | 210 | ||
| @@ -236,57 +341,6 @@ macro_rules! impl_basic_16bit_timer { | |||
| 236 | fn regs() -> crate::pac::timer::TimBasic { | 341 | fn regs() -> crate::pac::timer::TimBasic { |
| 237 | unsafe { crate::pac::timer::TimBasic::from_ptr(crate::pac::$inst.as_ptr()) } | 342 | unsafe { crate::pac::timer::TimBasic::from_ptr(crate::pac::$inst.as_ptr()) } |
| 238 | } | 343 | } |
| 239 | |||
| 240 | fn start(&mut self) { | ||
| 241 | Self::regs().cr1().modify(|r| r.set_cen(true)); | ||
| 242 | } | ||
| 243 | |||
| 244 | fn stop(&mut self) { | ||
| 245 | Self::regs().cr1().modify(|r| r.set_cen(false)); | ||
| 246 | } | ||
| 247 | |||
| 248 | fn reset(&mut self) { | ||
| 249 | Self::regs().cnt().write(|r| r.set_cnt(0)); | ||
| 250 | } | ||
| 251 | |||
| 252 | fn set_frequency(&mut self, frequency: Hertz) { | ||
| 253 | use core::convert::TryInto; | ||
| 254 | let f = frequency.0; | ||
| 255 | let timer_f = Self::frequency().0; | ||
| 256 | assert!(f > 0); | ||
| 257 | let pclk_ticks_per_timer_period = timer_f / f; | ||
| 258 | let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 16)).try_into()); | ||
| 259 | let arr: u16 = unwrap!((pclk_ticks_per_timer_period / (u32::from(psc) + 1)).try_into()); | ||
| 260 | |||
| 261 | let regs = Self::regs(); | ||
| 262 | regs.psc().write(|r| r.set_psc(psc)); | ||
| 263 | regs.arr().write(|r| r.set_arr(arr)); | ||
| 264 | |||
| 265 | regs.cr1().modify(|r| r.set_urs(vals::Urs::COUNTERONLY)); | ||
| 266 | regs.egr().write(|r| r.set_ug(true)); | ||
| 267 | regs.cr1().modify(|r| r.set_urs(vals::Urs::ANYEVENT)); | ||
| 268 | } | ||
| 269 | |||
| 270 | fn clear_update_interrupt(&mut self) -> bool { | ||
| 271 | let regs = Self::regs(); | ||
| 272 | let sr = regs.sr().read(); | ||
| 273 | if sr.uif() { | ||
| 274 | regs.sr().modify(|r| { | ||
| 275 | r.set_uif(false); | ||
| 276 | }); | ||
| 277 | true | ||
| 278 | } else { | ||
| 279 | false | ||
| 280 | } | ||
| 281 | } | ||
| 282 | |||
| 283 | fn enable_update_interrupt(&mut self, enable: bool) { | ||
| 284 | Self::regs().dier().write(|r| r.set_uie(enable)); | ||
| 285 | } | ||
| 286 | |||
| 287 | fn set_autoreload_preload(&mut self, enable: vals::Arpe) { | ||
| 288 | Self::regs().cr1().modify(|r| r.set_arpe(enable)); | ||
| 289 | } | ||
| 290 | } | 344 | } |
| 291 | }; | 345 | }; |
| 292 | } | 346 | } |
| @@ -323,99 +377,7 @@ macro_rules! impl_32bit_timer { | |||
| 323 | #[allow(unused)] | 377 | #[allow(unused)] |
| 324 | macro_rules! impl_compare_capable_16bit { | 378 | macro_rules! impl_compare_capable_16bit { |
| 325 | ($inst:ident) => { | 379 | ($inst:ident) => { |
| 326 | impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst { | 380 | impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst {} |
| 327 | fn set_input_capture_filter(&mut self, channel: Channel, icf: vals::Icf) { | ||
| 328 | use sealed::GeneralPurpose16bitInstance; | ||
| 329 | let raw_channel = channel.raw(); | ||
| 330 | Self::regs_gp16() | ||
| 331 | .ccmr_input(raw_channel / 2) | ||
| 332 | .modify(|r| r.set_icf(raw_channel % 2, icf)); | ||
| 333 | } | ||
| 334 | |||
| 335 | fn clear_input_interrupt(&mut self, channel: Channel) { | ||
| 336 | use sealed::GeneralPurpose16bitInstance; | ||
| 337 | Self::regs_gp16() | ||
| 338 | .sr() | ||
| 339 | .modify(|r| r.set_ccif(channel.raw(), false)); | ||
| 340 | } | ||
| 341 | |||
| 342 | fn enable_input_interrupt(&mut self, channel: Channel, enable: bool) { | ||
| 343 | use sealed::GeneralPurpose16bitInstance; | ||
| 344 | Self::regs_gp16() | ||
| 345 | .dier() | ||
| 346 | .modify(|r| r.set_ccie(channel.raw(), enable)); | ||
| 347 | } | ||
| 348 | fn set_input_capture_prescaler(&mut self, channel: Channel, factor: u8) { | ||
| 349 | use sealed::GeneralPurpose16bitInstance; | ||
| 350 | let raw_channel = channel.raw(); | ||
| 351 | Self::regs_gp16() | ||
| 352 | .ccmr_input(raw_channel / 2) | ||
| 353 | .modify(|r| r.set_icpsc(raw_channel % 2, factor)); | ||
| 354 | } | ||
| 355 | |||
| 356 | fn set_input_ti_selection(&mut self, channel: Channel, tisel: InputTISelection) { | ||
| 357 | use sealed::GeneralPurpose16bitInstance; | ||
| 358 | let raw_channel = channel.raw(); | ||
| 359 | Self::regs_gp16() | ||
| 360 | .ccmr_input(raw_channel / 2) | ||
| 361 | .modify(|r| r.set_ccs(raw_channel % 2, tisel.into())); | ||
| 362 | } | ||
| 363 | fn set_input_capture_mode(&mut self, channel: Channel, mode: InputCaptureMode) { | ||
| 364 | use sealed::GeneralPurpose16bitInstance; | ||
| 365 | Self::regs_gp16().ccer().modify(|r| match mode { | ||
| 366 | InputCaptureMode::Rising => { | ||
| 367 | r.set_ccnp(channel.raw(), false); | ||
| 368 | r.set_ccp(channel.raw(), false); | ||
| 369 | } | ||
| 370 | InputCaptureMode::Falling => { | ||
| 371 | r.set_ccnp(channel.raw(), false); | ||
| 372 | r.set_ccp(channel.raw(), true); | ||
| 373 | } | ||
| 374 | InputCaptureMode::BothEdges => { | ||
| 375 | r.set_ccnp(channel.raw(), true); | ||
| 376 | r.set_ccp(channel.raw(), true); | ||
| 377 | } | ||
| 378 | }); | ||
| 379 | } | ||
| 380 | fn enable_outputs(&mut self, _enable: bool) {} | ||
| 381 | |||
| 382 | fn set_output_compare_mode(&mut self, channel: Channel, mode: OutputCompareMode) { | ||
| 383 | use sealed::GeneralPurpose16bitInstance; | ||
| 384 | let r = Self::regs_gp16(); | ||
| 385 | let raw_channel: usize = channel.raw(); | ||
| 386 | r.ccmr_output(raw_channel / 2) | ||
| 387 | .modify(|w| w.set_ocm(raw_channel % 2, mode.into())); | ||
| 388 | } | ||
| 389 | |||
| 390 | fn set_output_polarity(&mut self, channel: Channel, polarity: OutputPolarity) { | ||
| 391 | use sealed::GeneralPurpose16bitInstance; | ||
| 392 | Self::regs_gp16() | ||
| 393 | .ccer() | ||
| 394 | .modify(|w| w.set_ccp(channel.raw(), polarity.into())); | ||
| 395 | } | ||
| 396 | |||
| 397 | fn enable_channel(&mut self, channel: Channel, enable: bool) { | ||
| 398 | use sealed::GeneralPurpose16bitInstance; | ||
| 399 | Self::regs_gp16() | ||
| 400 | .ccer() | ||
| 401 | .modify(|w| w.set_cce(channel.raw(), enable)); | ||
| 402 | } | ||
| 403 | |||
| 404 | fn set_compare_value(&mut self, channel: Channel, value: u16) { | ||
| 405 | use sealed::GeneralPurpose16bitInstance; | ||
| 406 | Self::regs_gp16().ccr(channel.raw()).modify(|w| w.set_ccr(value)); | ||
| 407 | } | ||
| 408 | |||
| 409 | fn get_capture_value(&mut self, channel: Channel) -> u16 { | ||
| 410 | use sealed::GeneralPurpose16bitInstance; | ||
| 411 | Self::regs_gp16().ccr(channel.raw()).read().ccr() | ||
| 412 | } | ||
| 413 | |||
| 414 | fn get_max_compare_value(&self) -> u16 { | ||
| 415 | use sealed::GeneralPurpose16bitInstance; | ||
| 416 | Self::regs_gp16().arr().read().arr() | ||
| 417 | } | ||
| 418 | } | ||
| 419 | }; | 381 | }; |
| 420 | } | 382 | } |
| 421 | 383 | ||
| @@ -435,14 +397,6 @@ foreach_interrupt! { | |||
| 435 | fn regs_gp16() -> crate::pac::timer::TimGp16 { | 397 | fn regs_gp16() -> crate::pac::timer::TimGp16 { |
| 436 | crate::pac::$inst | 398 | crate::pac::$inst |
| 437 | } | 399 | } |
| 438 | |||
| 439 | fn set_count_direction(&mut self, direction: vals::Dir) { | ||
| 440 | Self::regs_gp16().cr1().modify(|r| r.set_dir(direction)); | ||
| 441 | } | ||
| 442 | |||
| 443 | fn set_clock_division(&mut self, ckd: vals::Ckd) { | ||
| 444 | Self::regs_gp16().cr1().modify(|r| r.set_ckd(ckd)); | ||
| 445 | } | ||
| 446 | } | 400 | } |
| 447 | }; | 401 | }; |
| 448 | 402 | ||
| @@ -455,36 +409,12 @@ foreach_interrupt! { | |||
| 455 | impl CaptureCompare32bitInstance for crate::peripherals::$inst {} | 409 | impl CaptureCompare32bitInstance for crate::peripherals::$inst {} |
| 456 | impl GeneralPurpose16bitInstance for crate::peripherals::$inst {} | 410 | impl GeneralPurpose16bitInstance for crate::peripherals::$inst {} |
| 457 | impl GeneralPurpose32bitInstance for crate::peripherals::$inst {} | 411 | impl GeneralPurpose32bitInstance for crate::peripherals::$inst {} |
| 458 | 412 | impl sealed::CaptureCompare32bitInstance for crate::peripherals::$inst {} | |
| 459 | impl sealed::CaptureCompare32bitInstance for crate::peripherals::$inst { | ||
| 460 | fn set_compare_value(&mut self, channel: Channel, value: u32) { | ||
| 461 | use crate::timer::sealed::GeneralPurpose32bitInstance; | ||
| 462 | Self::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(value)); | ||
| 463 | } | ||
| 464 | |||
| 465 | fn get_capture_value(&mut self, channel: Channel) -> u32 { | ||
| 466 | use crate::timer::sealed::GeneralPurpose32bitInstance; | ||
| 467 | Self::regs_gp32().ccr(channel.raw()).read().ccr() | ||
| 468 | } | ||
| 469 | |||
| 470 | fn get_max_compare_value(&self) -> u32 { | ||
| 471 | use crate::timer::sealed::GeneralPurpose32bitInstance; | ||
| 472 | Self::regs_gp32().arr().read().arr() as u32 | ||
| 473 | } | ||
| 474 | } | ||
| 475 | 413 | ||
| 476 | impl sealed::GeneralPurpose16bitInstance for crate::peripherals::$inst { | 414 | impl sealed::GeneralPurpose16bitInstance for crate::peripherals::$inst { |
| 477 | fn regs_gp16() -> crate::pac::timer::TimGp16 { | 415 | fn regs_gp16() -> crate::pac::timer::TimGp16 { |
| 478 | unsafe { crate::pac::timer::TimGp16::from_ptr(crate::pac::$inst.as_ptr()) } | 416 | unsafe { crate::pac::timer::TimGp16::from_ptr(crate::pac::$inst.as_ptr()) } |
| 479 | } | 417 | } |
| 480 | |||
| 481 | fn set_count_direction(&mut self, direction: vals::Dir) { | ||
| 482 | Self::regs_gp16().cr1().modify(|r| r.set_dir(direction)); | ||
| 483 | } | ||
| 484 | |||
| 485 | fn set_clock_division(&mut self, ckd: vals::Ckd) { | ||
| 486 | Self::regs_gp16().cr1().modify(|r| r.set_ckd(ckd)); | ||
| 487 | } | ||
| 488 | } | 418 | } |
| 489 | }; | 419 | }; |
| 490 | 420 | ||
| @@ -496,19 +426,12 @@ foreach_interrupt! { | |||
| 496 | impl CaptureCompare16bitInstance for crate::peripherals::$inst {} | 426 | impl CaptureCompare16bitInstance for crate::peripherals::$inst {} |
| 497 | impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {} | 427 | impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {} |
| 498 | impl AdvancedControlInstance for crate::peripherals::$inst {} | 428 | impl AdvancedControlInstance for crate::peripherals::$inst {} |
| 499 | 429 | impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst {} | |
| 430 | impl sealed::ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {} | ||
| 500 | impl sealed::GeneralPurpose16bitInstance for crate::peripherals::$inst { | 431 | impl sealed::GeneralPurpose16bitInstance for crate::peripherals::$inst { |
| 501 | fn regs_gp16() -> crate::pac::timer::TimGp16 { | 432 | fn regs_gp16() -> crate::pac::timer::TimGp16 { |
| 502 | unsafe { crate::pac::timer::TimGp16::from_ptr(crate::pac::$inst.as_ptr()) } | 433 | unsafe { crate::pac::timer::TimGp16::from_ptr(crate::pac::$inst.as_ptr()) } |
| 503 | } | 434 | } |
| 504 | |||
| 505 | fn set_count_direction(&mut self, direction: vals::Dir) { | ||
| 506 | Self::regs_gp16().cr1().modify(|r| r.set_dir(direction)); | ||
| 507 | } | ||
| 508 | |||
| 509 | fn set_clock_division(&mut self, ckd: vals::Ckd) { | ||
| 510 | Self::regs_gp16().cr1().modify(|r| r.set_ckd(ckd)); | ||
| 511 | } | ||
| 512 | } | 435 | } |
| 513 | 436 | ||
| 514 | impl sealed::AdvancedControlInstance for crate::peripherals::$inst { | 437 | impl sealed::AdvancedControlInstance for crate::peripherals::$inst { |
| @@ -517,133 +440,7 @@ foreach_interrupt! { | |||
| 517 | } | 440 | } |
| 518 | } | 441 | } |
| 519 | 442 | ||
| 520 | impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst { | ||
| 521 | fn set_input_capture_filter(&mut self, channel: Channel, icf: vals::Icf) { | ||
| 522 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 523 | let raw_channel = channel.raw(); | ||
| 524 | Self::regs_advanced() | ||
| 525 | .ccmr_input(raw_channel / 2) | ||
| 526 | .modify(|r| r.set_icf(raw_channel % 2, icf)); | ||
| 527 | } | ||
| 528 | |||
| 529 | fn clear_input_interrupt(&mut self, channel: Channel) { | ||
| 530 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 531 | Self::regs_advanced() | ||
| 532 | .sr() | ||
| 533 | .modify(|r| r.set_ccif(channel.raw(), false)); | ||
| 534 | } | ||
| 535 | fn enable_input_interrupt(&mut self, channel: Channel, enable: bool) { | ||
| 536 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 537 | Self::regs_advanced() | ||
| 538 | .dier() | ||
| 539 | .modify(|r| r.set_ccie(channel.raw(), enable)); | ||
| 540 | } | ||
| 541 | fn set_input_capture_prescaler(&mut self, channel: Channel, factor: u8) { | ||
| 542 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 543 | let raw_channel = channel.raw(); | ||
| 544 | Self::regs_advanced() | ||
| 545 | .ccmr_input(raw_channel / 2) | ||
| 546 | .modify(|r| r.set_icpsc(raw_channel % 2, factor)); | ||
| 547 | } | ||
| 548 | fn set_input_ti_selection(&mut self, channel: Channel, tisel: InputTISelection) { | ||
| 549 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 550 | let raw_channel = channel.raw(); | ||
| 551 | Self::regs_advanced() | ||
| 552 | .ccmr_input(raw_channel / 2) | ||
| 553 | .modify(|r| r.set_ccs(raw_channel % 2, tisel.into())); | ||
| 554 | } | ||
| 555 | fn set_input_capture_mode(&mut self, channel: Channel, mode: InputCaptureMode) { | ||
| 556 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 557 | Self::regs_advanced().ccer().modify(|r| match mode { | ||
| 558 | InputCaptureMode::Rising => { | ||
| 559 | r.set_ccnp(channel.raw(), false); | ||
| 560 | r.set_ccp(channel.raw(), false); | ||
| 561 | } | ||
| 562 | InputCaptureMode::Falling => { | ||
| 563 | r.set_ccnp(channel.raw(), false); | ||
| 564 | r.set_ccp(channel.raw(), true); | ||
| 565 | } | ||
| 566 | InputCaptureMode::BothEdges => { | ||
| 567 | r.set_ccnp(channel.raw(), true); | ||
| 568 | r.set_ccp(channel.raw(), true); | ||
| 569 | } | ||
| 570 | }); | ||
| 571 | } | ||
| 572 | fn enable_outputs(&mut self, enable: bool) { | ||
| 573 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 574 | let r = Self::regs_advanced(); | ||
| 575 | r.bdtr().modify(|w| w.set_moe(enable)); | ||
| 576 | } | ||
| 577 | |||
| 578 | fn set_output_compare_mode( | ||
| 579 | &mut self, | ||
| 580 | channel: Channel, | ||
| 581 | mode: OutputCompareMode, | ||
| 582 | ) { | ||
| 583 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 584 | let r = Self::regs_advanced(); | ||
| 585 | let raw_channel: usize = channel.raw(); | ||
| 586 | r.ccmr_output(raw_channel / 2) | ||
| 587 | .modify(|w| w.set_ocm(raw_channel % 2, mode.into())); | ||
| 588 | } | ||
| 589 | |||
| 590 | fn set_output_polarity(&mut self, channel: Channel, polarity: OutputPolarity) { | ||
| 591 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 592 | Self::regs_advanced() | ||
| 593 | .ccer() | ||
| 594 | .modify(|w| w.set_ccp(channel.raw(), polarity.into())); | ||
| 595 | } | ||
| 596 | |||
| 597 | fn enable_channel(&mut self, channel: Channel, enable: bool) { | ||
| 598 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 599 | Self::regs_advanced() | ||
| 600 | .ccer() | ||
| 601 | .modify(|w| w.set_cce(channel.raw(), enable)); | ||
| 602 | } | ||
| 603 | |||
| 604 | fn get_capture_value(&mut self, channel: Channel) -> u16 { | ||
| 605 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 606 | Self::regs_advanced().ccr(channel.raw()).read().ccr() | ||
| 607 | } | ||
| 608 | |||
| 609 | fn set_compare_value(&mut self, channel: Channel, value: u16) { | ||
| 610 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 611 | Self::regs_advanced() | ||
| 612 | .ccr(channel.raw()) | ||
| 613 | .modify(|w| w.set_ccr(value)); | ||
| 614 | } | ||
| 615 | |||
| 616 | fn get_max_compare_value(&self) -> u16 { | ||
| 617 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 618 | Self::regs_advanced().arr().read().arr() | ||
| 619 | } | ||
| 620 | } | ||
| 621 | |||
| 622 | impl sealed::ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst { | ||
| 623 | fn set_complementary_output_polarity(&mut self, channel: Channel, polarity: OutputPolarity) { | ||
| 624 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 625 | Self::regs_advanced() | ||
| 626 | .ccer() | ||
| 627 | .modify(|w| w.set_ccnp(channel.raw(), polarity.into())); | ||
| 628 | } | ||
| 629 | |||
| 630 | fn set_dead_time_clock_division(&mut self, value: vals::Ckd) { | ||
| 631 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 632 | Self::regs_advanced().cr1().modify(|w| w.set_ckd(value)); | ||
| 633 | } | ||
| 634 | |||
| 635 | fn set_dead_time_value(&mut self, value: u8) { | ||
| 636 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 637 | Self::regs_advanced().bdtr().modify(|w| w.set_dtg(value)); | ||
| 638 | } | ||
| 639 | 443 | ||
| 640 | fn enable_complementary_channel(&mut self, channel: Channel, enable: bool) { | ||
| 641 | use crate::timer::sealed::AdvancedControlInstance; | ||
| 642 | Self::regs_advanced() | ||
| 643 | .ccer() | ||
| 644 | .modify(|w| w.set_ccne(channel.raw(), enable)); | ||
| 645 | } | ||
| 646 | } | ||
| 647 | 444 | ||
| 648 | 445 | ||
| 649 | }; | 446 | }; |
