|
1 | 1 | //! A delay driver based on SysTick.
|
2 | 2 |
|
3 | 3 | use crate::peripheral::{syst::SystClkSource, SYST};
|
4 |
| -use embedded_hal::blocking::delay::{DelayMs, DelayUs}; |
| 4 | +use eh1::delay::DelayNs; |
5 | 5 |
|
6 | 6 | /// System timer (SysTick) as a delay provider.
|
7 | 7 | pub struct Delay {
|
@@ -75,62 +75,83 @@ impl Delay {
|
75 | 75 | }
|
76 | 76 | }
|
77 | 77 |
|
78 |
| -impl DelayMs<u32> for Delay { |
| 78 | +impl eh0::blocking::delay::DelayMs<u32> for Delay { |
79 | 79 | #[inline]
|
80 | 80 | fn delay_ms(&mut self, ms: u32) {
|
81 | 81 | Delay::delay_ms(self, ms);
|
82 | 82 | }
|
83 | 83 | }
|
84 | 84 |
|
85 | 85 | // This is a workaround to allow `delay_ms(42)` construction without specifying a type.
|
86 |
| -impl DelayMs<i32> for Delay { |
| 86 | +impl eh0::blocking::delay::DelayMs<i32> for Delay { |
87 | 87 | #[inline(always)]
|
88 | 88 | fn delay_ms(&mut self, ms: i32) {
|
89 | 89 | assert!(ms >= 0);
|
90 | 90 | Delay::delay_ms(self, ms as u32);
|
91 | 91 | }
|
92 | 92 | }
|
93 | 93 |
|
94 |
| -impl DelayMs<u16> for Delay { |
| 94 | +impl eh0::blocking::delay::DelayMs<u16> for Delay { |
95 | 95 | #[inline(always)]
|
96 | 96 | fn delay_ms(&mut self, ms: u16) {
|
97 | 97 | Delay::delay_ms(self, u32::from(ms));
|
98 | 98 | }
|
99 | 99 | }
|
100 | 100 |
|
101 |
| -impl DelayMs<u8> for Delay { |
| 101 | +impl eh0::blocking::delay::DelayMs<u8> for Delay { |
102 | 102 | #[inline(always)]
|
103 | 103 | fn delay_ms(&mut self, ms: u8) {
|
104 | 104 | Delay::delay_ms(self, u32::from(ms));
|
105 | 105 | }
|
106 | 106 | }
|
107 | 107 |
|
108 |
| -impl DelayUs<u32> for Delay { |
| 108 | +impl eh0::blocking::delay::DelayUs<u32> for Delay { |
109 | 109 | #[inline]
|
110 | 110 | fn delay_us(&mut self, us: u32) {
|
111 | 111 | Delay::delay_us(self, us);
|
112 | 112 | }
|
113 | 113 | }
|
114 | 114 |
|
115 | 115 | // This is a workaround to allow `delay_us(42)` construction without specifying a type.
|
116 |
| -impl DelayUs<i32> for Delay { |
| 116 | +impl eh0::blocking::delay::DelayUs<i32> for Delay { |
117 | 117 | #[inline(always)]
|
118 | 118 | fn delay_us(&mut self, us: i32) {
|
119 | 119 | assert!(us >= 0);
|
120 | 120 | Delay::delay_us(self, us as u32);
|
121 | 121 | }
|
122 | 122 | }
|
123 | 123 |
|
124 |
| -impl DelayUs<u16> for Delay { |
| 124 | +impl eh0::blocking::delay::DelayUs<u16> for Delay { |
125 | 125 | #[inline(always)]
|
126 | 126 | fn delay_us(&mut self, us: u16) {
|
127 | 127 | Delay::delay_us(self, u32::from(us))
|
128 | 128 | }
|
129 | 129 | }
|
130 | 130 |
|
131 |
| -impl DelayUs<u8> for Delay { |
| 131 | +impl eh0::blocking::delay::DelayUs<u8> for Delay { |
132 | 132 | #[inline(always)]
|
133 | 133 | fn delay_us(&mut self, us: u8) {
|
134 | 134 | Delay::delay_us(self, u32::from(us))
|
135 | 135 | }
|
136 | 136 | }
|
| 137 | + |
| 138 | +impl DelayNs for Delay { |
| 139 | + #[inline] |
| 140 | + fn delay_ns(&mut self, ns: u32) { |
| 141 | + // from the rp2040-hal: |
| 142 | + let us = ns / 1000 + if ns % 1000 == 0 { 0 } else { 1 }; |
| 143 | + // With rustc 1.73, this can be replaced by: |
| 144 | + // let us = ns.div_ceil(1000); |
| 145 | + Delay::delay_us(self, us) |
| 146 | + } |
| 147 | + |
| 148 | + #[inline] |
| 149 | + fn delay_us(&mut self, us: u32) { |
| 150 | + Delay::delay_us(self, us) |
| 151 | + } |
| 152 | + |
| 153 | + #[inline] |
| 154 | + fn delay_ms(&mut self, ms: u32) { |
| 155 | + Delay::delay_ms(self, ms) |
| 156 | + } |
| 157 | +} |
0 commit comments