@@ -30,17 +30,13 @@ pub struct Periodic;
30
30
///
31
31
/// CC[0] is used for the current/most-recent delay period and CC[1] is used
32
32
/// to grab the current value of the counter at a given instant.
33
- pub struct BaseTimer < T , U > ( T , PhantomData < U > ) ;
33
+ pub struct Timer < T , U = OneShot > ( T , PhantomData < U > ) ;
34
34
35
- pub type Timer < T > = BaseTimer < T , OneShot > ;
36
- pub type PeriodicTimer < T > = BaseTimer < T , Periodic > ;
37
- pub type OneShotTimer < T > = BaseTimer < T , OneShot > ;
38
-
39
- impl < T > OneShotTimer < T >
40
- where
35
+ impl < T > Timer < T , OneShot >
36
+ where
41
37
T : Instance ,
42
38
{
43
- pub fn new ( timer : T ) -> OneShotTimer < T > {
39
+ pub fn one_shot ( timer : T ) -> Timer < T , OneShot > {
44
40
timer
45
41
. shorts
46
42
. write ( |w| w. compare0_clear ( ) . enabled ( ) . compare0_stop ( ) . enabled ( ) ) ;
@@ -49,23 +45,20 @@ where
49
45
) ;
50
46
timer. bitmode . write ( |w| w. bitmode ( ) . _32bit ( ) ) ;
51
47
52
- BaseTimer :: < T , OneShot > ( timer, PhantomData )
48
+ Timer :: < T , OneShot > ( timer, PhantomData )
53
49
}
54
50
55
- pub fn into_periodic ( self ) -> PeriodicTimer < T > {
56
- self . 0
57
- . shorts
58
- . write ( |w| w. compare0_clear ( ) . enabled ( ) . compare0_stop ( ) . disabled ( ) ) ;
59
-
60
- BaseTimer :: < T , Periodic > ( self . free ( ) , PhantomData )
51
+ pub fn new ( timer : T ) -> Timer < T , OneShot > {
52
+ Timer :: < T , OneShot > :: one_shot ( timer)
61
53
}
54
+
62
55
}
63
56
64
- impl < T > PeriodicTimer < T >
57
+ impl < T > Timer < T , Periodic >
65
58
where
66
59
T : Instance ,
67
60
{
68
- pub fn new ( timer : T ) -> PeriodicTimer < T > {
61
+ pub fn periodic ( timer : T ) -> Timer < T , Periodic > {
69
62
timer
70
63
. shorts
71
64
. write ( |w| w. compare0_clear ( ) . enabled ( ) . compare0_stop ( ) . disabled ( ) ) ;
@@ -74,24 +67,33 @@ where
74
67
) ;
75
68
timer. bitmode . write ( |w| w. bitmode ( ) . _32bit ( ) ) ;
76
69
77
- BaseTimer :: < T , Periodic > ( timer, PhantomData )
70
+ Timer :: < T , Periodic > ( timer, PhantomData )
78
71
}
79
72
80
- pub fn into_oneshot ( self ) -> OneShotTimer < T > {
81
- self . 0
82
- . shorts
83
- . write ( |w| w. compare0_clear ( ) . enabled ( ) . compare0_stop ( ) . enabled ( ) ) ;
84
-
85
- BaseTimer :: < T , OneShot > ( self . free ( ) , PhantomData )
86
- }
87
73
}
88
74
89
- impl < T , U > BaseTimer < T , U >
75
+ impl < T , U > Timer < T , U >
90
76
where
91
77
T : Instance ,
92
78
{
93
79
pub const TICKS_PER_SECOND : u32 = 1_000_000 ;
94
80
81
+ pub fn into_periodic ( self ) -> Timer < T , Periodic > {
82
+ self . 0
83
+ . shorts
84
+ . write ( |w| w. compare0_clear ( ) . enabled ( ) . compare0_stop ( ) . disabled ( ) ) ;
85
+
86
+ Timer :: < T , Periodic > ( self . free ( ) , PhantomData )
87
+ }
88
+
89
+ pub fn into_oneshot ( self ) -> Timer < T , OneShot > {
90
+ self . 0
91
+ . shorts
92
+ . write ( |w| w. compare0_clear ( ) . enabled ( ) . compare0_stop ( ) . enabled ( ) ) ;
93
+
94
+ Timer :: < T , OneShot > ( self . free ( ) , PhantomData )
95
+ }
96
+
95
97
/// Return the raw interface to the underlying timer peripheral
96
98
pub fn free ( self ) -> T {
97
99
self . 0
@@ -150,7 +152,7 @@ where
150
152
}
151
153
}
152
154
153
- impl < T , U > timer:: CountDown for BaseTimer < T , U >
155
+ impl < T , U > timer:: CountDown for Timer < T , U >
154
156
where
155
157
T : Instance ,
156
158
{
@@ -211,7 +213,7 @@ where
211
213
}
212
214
}
213
215
214
- impl < T , U > timer:: Cancel for BaseTimer < T , U >
216
+ impl < T , U > timer:: Cancel for Timer < T , U >
215
217
where
216
218
T : Instance ,
217
219
{
@@ -225,7 +227,7 @@ where
225
227
}
226
228
}
227
229
228
- impl < T > timer:: Periodic for PeriodicTimer < T >
230
+ impl < T > timer:: Periodic for Timer < T , Periodic >
229
231
where
230
232
T : Instance ,
231
233
{ }
0 commit comments