1
1
//! Delays
2
2
3
3
use cast:: u32;
4
+ use core:: convert:: Infallible ;
5
+
4
6
use cortex_m:: peripheral:: syst:: SystClkSource ;
5
7
use cortex_m:: peripheral:: SYST ;
6
8
@@ -28,25 +30,33 @@ impl Delay {
28
30
}
29
31
30
32
impl DelayMs < u32 > for Delay {
31
- fn delay_ms ( & mut self , ms : u32 ) {
32
- self . delay_us ( ms * 1_000 ) ;
33
+ type Error = Infallible ;
34
+
35
+ fn try_delay_ms ( & mut self , ms : u32 ) -> Result < ( ) , Self :: Error > {
36
+ self . try_delay_us ( ms * 1_000 )
33
37
}
34
38
}
35
39
36
40
impl DelayMs < u16 > for Delay {
37
- fn delay_ms ( & mut self , ms : u16 ) {
38
- self . delay_ms ( u32 ( ms) ) ;
41
+ type Error = Infallible ;
42
+
43
+ fn try_delay_ms ( & mut self , ms : u16 ) -> Result < ( ) , Self :: Error > {
44
+ self . try_delay_ms ( u32 ( ms) )
39
45
}
40
46
}
41
47
42
48
impl DelayMs < u8 > for Delay {
43
- fn delay_ms ( & mut self , ms : u8 ) {
44
- self . delay_ms ( u32 ( ms) ) ;
49
+ type Error = Infallible ;
50
+
51
+ fn try_delay_ms ( & mut self , ms : u8 ) -> Result < ( ) , Self :: Error > {
52
+ self . try_delay_ms ( u32 ( ms) )
45
53
}
46
54
}
47
55
48
56
impl DelayUs < u32 > for Delay {
49
- fn delay_us ( & mut self , us : u32 ) {
57
+ type Error = Infallible ;
58
+
59
+ fn try_delay_us ( & mut self , us : u32 ) -> Result < ( ) , Self :: Error > {
50
60
// The SysTick Reload Value register supports values between 1 and 0x00FFFFFF.
51
61
const MAX_RVR : u32 = 0x00FF_FFFF ;
52
62
@@ -70,17 +80,23 @@ impl DelayUs<u32> for Delay {
70
80
71
81
self . syst . disable_counter ( ) ;
72
82
}
83
+
84
+ Ok ( ( ) )
73
85
}
74
86
}
75
87
76
88
impl DelayUs < u16 > for Delay {
77
- fn delay_us ( & mut self , us : u16 ) {
78
- self . delay_us ( u32 ( us) )
89
+ type Error = Infallible ;
90
+
91
+ fn try_delay_us ( & mut self , us : u16 ) -> Result < ( ) , Self :: Error > {
92
+ self . try_delay_us ( u32 ( us) )
79
93
}
80
94
}
81
95
82
96
impl DelayUs < u8 > for Delay {
83
- fn delay_us ( & mut self , us : u8 ) {
84
- self . delay_us ( u32 ( us) )
97
+ type Error = Infallible ;
98
+
99
+ fn try_delay_us ( & mut self , us : u8 ) -> Result < ( ) , Self :: Error > {
100
+ self . try_delay_us ( u32 ( us) )
85
101
}
86
102
}
0 commit comments