File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -20,14 +20,17 @@ macro_rules! stopwatches {
20
20
rcc. rb. $apbenr. modify( |_, w| w. $timXen( ) . set_bit( ) ) ;
21
21
rcc. rb. $apbrstr. modify( |_, w| w. $timXrst( ) . set_bit( ) ) ;
22
22
rcc. rb. $apbrstr. modify( |_, w| w. $timXrst( ) . clear_bit( ) ) ;
23
- tim. cr1. modify( |_, w| w. urs( ) . set_bit( ) ) ;
24
23
tim. cr1. modify( |_, w| w. cen( ) . set_bit( ) ) ;
25
24
Stopwatch {
26
25
tim,
27
26
clk: rcc. clocks. apb_tim_clk,
28
27
}
29
28
}
30
29
30
+ /// Overrides the counter clock input frequency
31
+ ///
32
+ /// Useful if the APB Timer Clock changes after the `Stopwatch` is created or
33
+ /// to deliberately speed up or slow down the `Stopwatch` from actual measured time.
31
34
pub fn set_clock<T >( & mut self , clk: T )
32
35
where
33
36
T : Into <Hertz >,
@@ -37,6 +40,14 @@ macro_rules! stopwatches {
37
40
self . clk = clk;
38
41
}
39
42
43
+ /// Set the prescaler which divides the input clock frequency before the counter
44
+ ///
45
+ /// The counter frequency is equal to the input clock divided by the prescaler + 1.
46
+ pub fn set_prescaler( & mut self , prescaler: u16 ) {
47
+ self . tim. psc. write( |w| unsafe { w. psc( ) . bits( prescaler) } ) ;
48
+ self . tim. egr. write( |w| w. ug( ) . set_bit( ) ) ;
49
+ }
50
+
40
51
pub fn reset( & mut self ) {
41
52
self . tim. cnt. reset( ) ;
42
53
}
You can’t perform that action at this time.
0 commit comments