File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -22,12 +22,17 @@ use crate::target::{TIMER3, TIMER4};
22
22
///
23
23
/// Right now, this is a very basic interface. The timer will always be
24
24
/// hardcoded to a frequency of 1 MHz and 32 bits accuracy.
25
+ ///
26
+ /// CC[0] is used for the current/most-recent delay period and CC[1] is used
27
+ /// to grab the current value of the counter at a given instant.
25
28
pub struct Timer < T > ( T ) ;
26
29
27
30
impl < T > Timer < T >
28
31
where
29
32
T : Instance ,
30
33
{
34
+ pub const TICKS_PER_SECOND : u32 = 1_000_000 ;
35
+
31
36
pub fn new ( timer : T ) -> Self {
32
37
timer
33
38
. shorts
45
50
self . 0
46
51
}
47
52
53
+ /// Return the current value of the counter, by capturing to CC[1].
54
+ pub fn read ( & self ) -> u32 {
55
+ self . 0 . tasks_capture [ 1 ] . write ( |w| w. tasks_capture ( ) . trigger ( ) ) ;
56
+ self . 0 . cc [ 1 ] . read ( ) . bits ( )
57
+ }
58
+
48
59
/// Enables the interrupt for this timer
49
60
///
50
61
/// Enables an interrupt that is fired when the timer reaches the value that
You can’t perform that action at this time.
0 commit comments