File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -42,3 +42,6 @@ pub mod prelude;
42
42
43
43
#[ cfg( feature = "device-selected" ) ]
44
44
pub mod pwr;
45
+
46
+ #[ cfg( feature = "device-selected" ) ]
47
+ pub mod time;
Original file line number Diff line number Diff line change
1
+ //! Time units
2
+
3
+ pub use fugit:: {
4
+ HertzU32 as Hertz , KilohertzU32 as KiloHertz , MegahertzU32 as MegaHertz ,
5
+ MicrosDurationU32 as MicroSeconds , MillisDurationU32 as MilliSeconds ,
6
+ NanosDurationU32 as NanoSeconds ,
7
+ } ;
8
+
9
+ //use core::time::Duration;
10
+ use cortex_m:: peripheral:: DWT ;
11
+
12
+ /// Bits per second
13
+ pub type Bps = Hertz ;
14
+
15
+ /// Extension trait that adds convenience methods to the `u32` type
16
+ pub trait U32Ext {
17
+ /// Wrap in `Bps`
18
+ fn bps ( self ) -> Bps ;
19
+ }
20
+
21
+ impl U32Ext for u32 {
22
+ fn bps ( self ) -> Bps {
23
+ Bps :: from_raw ( self )
24
+ }
25
+ }
26
+
27
+ /// A measurement of a monotonically nondecreasing clock
28
+ #[ derive( Clone , Copy ) ]
29
+ pub struct Instant {
30
+ now : u32 ,
31
+ }
32
+
33
+ impl Instant {
34
+ /// Ticks elapsed since the `Instant` was created
35
+ pub fn elapsed ( & self ) -> u32 {
36
+ DWT :: cycle_count ( ) . wrapping_sub ( self . now )
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments