|
16 | 16 |
|
17 | 17 | ``` |
18 | 18 | // (Other imports omitted) |
19 | | - use stm32f3xx-hal::pwm::tim3; |
| 19 | + use stm32f3xx-hal::{pwm::tim3, time::rate::*}; |
20 | 20 |
|
21 | 21 | let dp = stm32f303::Peripherals::take().unwrap(); |
22 | 22 |
|
|
25 | 25 | let clocks = rcc.cfgr.freeze(&mut flash.acr); |
26 | 26 |
|
27 | 27 | // Set the resolution of our duty cycle to 9000 and our period to |
28 | | - // 50hz. |
| 28 | + // 50Hz. |
29 | 29 | let mut (c1_no_pins, _, _, c4_no_pins) = |
30 | | - tim3(device.TIM3, 9000, 50.hz(), clocks); |
| 30 | + tim3(device.TIM3, 9000, 50.Hz(), clocks); |
31 | 31 | ``` |
32 | 32 |
|
33 | 33 | In this case, we're only going to use channel 1 and channel 4. |
|
65 | 65 | ch4.enable(); |
66 | 66 | ``` |
67 | 67 |
|
68 | | - All three pins will output a 50hz period. PA6 and PB4 will share a |
| 68 | + All three pins will output a 50Hz period. PA6 and PB4 will share a |
69 | 69 | duty cycle, but the duty cycle for PB1 can be controlled |
70 | 70 | independently. |
71 | 71 |
|
|
84 | 84 |
|
85 | 85 | ``` |
86 | 86 | // (Other imports omitted) |
87 | | - use stm32f3xx-hal::pwm::tim16; |
| 87 | + use stm32f3xx-hal::{pwm::tim16, time::rate::*}; |
88 | 88 |
|
89 | 89 | let dp = stm32f303::Peripherals::take().unwrap(); |
90 | 90 |
|
|
93 | 93 | let clocks = rcc.cfgr.freeze(&mut flash.acr); |
94 | 94 |
|
95 | 95 | // Set the resolution of our duty cycle to 9000 and our period to |
96 | | - // 50hz. |
97 | | - let mut c1_no_pins = tim16(device.TIM3, 9000, 50.hz(), clocks); |
| 96 | + // 50Hz. |
| 97 | + let mut c1_no_pins = tim16(device.TIM3, 9000, 50.Hz(), clocks); |
98 | 98 | ``` |
99 | 99 |
|
100 | 100 | ## Complementary timers |
|
109 | 109 |
|
110 | 110 | ``` |
111 | 111 | // (Other imports omitted) |
112 | | - use stm32f3xx-hal::pwm::tim1; |
| 112 | + use stm32f3xx-hal::{pwm::tim1, time::rate::*}; |
113 | 113 |
|
114 | 114 | let dp = stm32f303::Peripherals::take().unwrap(); |
115 | 115 |
|
|
118 | 118 | let clocks = rcc.cfgr.freeze(&mut flash.acr); |
119 | 119 |
|
120 | 120 | // Set the resolution of our duty cycle to 9000 and our period to |
121 | | - // 50hz. |
122 | | - let mut (ch1_no_pins, _, _, _) = tim1(device.TIM3, 9000, 50.hz(), clocks); |
| 121 | + // 50Hz. |
| 122 | + let mut (ch1_no_pins, _, _, _) = tim1(device.TIM3, 9000, 50.Hz(), clocks); |
123 | 123 |
|
124 | 124 | let mut gpioa = dp.GPIOB.split(&mut rcc.ahb); |
125 | 125 | let pa7 = gpioa.pa7.into_af6(&mut gpioa.moder, &mut gpioa.afrl); |
@@ -160,7 +160,7 @@ use crate::{ |
160 | 160 | hal::PwmPin, |
161 | 161 | pac::{RCC, TIM15, TIM16, TIM17, TIM2}, |
162 | 162 | rcc::Clocks, |
163 | | - time::rate::Hertz, |
| 163 | + time::rate::*, |
164 | 164 | }; |
165 | 165 | use core::marker::PhantomData; |
166 | 166 |
|
@@ -282,7 +282,7 @@ macro_rules! pwm_timer_private { |
282 | 282 | // It might make sense to move into the clocks as a crate-only property. |
283 | 283 | // TODO: ppre1 is used in timer.rs (never ppre2), should this be dynamic? |
284 | 284 | let clock_freq = clocks.$pclkz().0 * if clocks.ppre1() == 1 { 1 } else { 2 }; |
285 | | - let prescale_factor = clock_freq / res as u32 / freq.0; |
| 285 | + let prescale_factor = clock_freq / res as u32 / *freq.integer(); |
286 | 286 | // NOTE(write): uses all bits of this register. |
287 | 287 | tim.psc.write(|w| w.psc().bits(prescale_factor as u16 - 1)); |
288 | 288 |
|
|
0 commit comments