|  | 
| 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,87 @@ impl Delay { | 
| 75 | 75 |     } | 
| 76 | 76 | } | 
| 77 | 77 | 
 | 
| 78 |  | -impl DelayMs<u32> for Delay { | 
|  | 78 | +#[cfg(feature = "eh0")] | 
|  | 79 | +impl eh0::blocking::delay::DelayMs<u32> for Delay { | 
| 79 | 80 |     #[inline] | 
| 80 | 81 |     fn delay_ms(&mut self, ms: u32) { | 
| 81 | 82 |         Delay::delay_ms(self, ms); | 
| 82 | 83 |     } | 
| 83 | 84 | } | 
| 84 | 85 | 
 | 
| 85 | 86 | // This is a workaround to allow `delay_ms(42)` construction without specifying a type. | 
| 86 |  | -impl DelayMs<i32> for Delay { | 
|  | 87 | +#[cfg(feature = "eh0")] | 
|  | 88 | +impl eh0::blocking::delay::DelayMs<i32> for Delay { | 
| 87 | 89 |     #[inline(always)] | 
| 88 | 90 |     fn delay_ms(&mut self, ms: i32) { | 
| 89 | 91 |         assert!(ms >= 0); | 
| 90 | 92 |         Delay::delay_ms(self, ms as u32); | 
| 91 | 93 |     } | 
| 92 | 94 | } | 
| 93 | 95 | 
 | 
| 94 |  | -impl DelayMs<u16> for Delay { | 
|  | 96 | +#[cfg(feature = "eh0")] | 
|  | 97 | +impl eh0::blocking::delay::DelayMs<u16> for Delay { | 
| 95 | 98 |     #[inline(always)] | 
| 96 | 99 |     fn delay_ms(&mut self, ms: u16) { | 
| 97 | 100 |         Delay::delay_ms(self, u32::from(ms)); | 
| 98 | 101 |     } | 
| 99 | 102 | } | 
| 100 | 103 | 
 | 
| 101 |  | -impl DelayMs<u8> for Delay { | 
|  | 104 | +#[cfg(feature = "eh0")] | 
|  | 105 | +impl eh0::blocking::delay::DelayMs<u8> for Delay { | 
| 102 | 106 |     #[inline(always)] | 
| 103 | 107 |     fn delay_ms(&mut self, ms: u8) { | 
| 104 | 108 |         Delay::delay_ms(self, u32::from(ms)); | 
| 105 | 109 |     } | 
| 106 | 110 | } | 
| 107 | 111 | 
 | 
| 108 |  | -impl DelayUs<u32> for Delay { | 
|  | 112 | +#[cfg(feature = "eh0")] | 
|  | 113 | +impl eh0::blocking::delay::DelayUs<u32> for Delay { | 
| 109 | 114 |     #[inline] | 
| 110 | 115 |     fn delay_us(&mut self, us: u32) { | 
| 111 | 116 |         Delay::delay_us(self, us); | 
| 112 | 117 |     } | 
| 113 | 118 | } | 
| 114 | 119 | 
 | 
| 115 | 120 | // This is a workaround to allow `delay_us(42)` construction without specifying a type. | 
| 116 |  | -impl DelayUs<i32> for Delay { | 
|  | 121 | +#[cfg(feature = "eh0")] | 
|  | 122 | +impl eh0::blocking::delay::DelayUs<i32> for Delay { | 
| 117 | 123 |     #[inline(always)] | 
| 118 | 124 |     fn delay_us(&mut self, us: i32) { | 
| 119 | 125 |         assert!(us >= 0); | 
| 120 | 126 |         Delay::delay_us(self, us as u32); | 
| 121 | 127 |     } | 
| 122 | 128 | } | 
| 123 | 129 | 
 | 
| 124 |  | -impl DelayUs<u16> for Delay { | 
|  | 130 | +#[cfg(feature = "eh0")] | 
|  | 131 | +impl eh0::blocking::delay::DelayUs<u16> for Delay { | 
| 125 | 132 |     #[inline(always)] | 
| 126 | 133 |     fn delay_us(&mut self, us: u16) { | 
| 127 | 134 |         Delay::delay_us(self, u32::from(us)) | 
| 128 | 135 |     } | 
| 129 | 136 | } | 
| 130 | 137 | 
 | 
| 131 |  | -impl DelayUs<u8> for Delay { | 
|  | 138 | +#[cfg(feature = "eh0")] | 
|  | 139 | +impl eh0::blocking::delay::DelayUs<u8> for Delay { | 
| 132 | 140 |     #[inline(always)] | 
| 133 | 141 |     fn delay_us(&mut self, us: u8) { | 
| 134 | 142 |         Delay::delay_us(self, u32::from(us)) | 
| 135 | 143 |     } | 
| 136 | 144 | } | 
|  | 145 | + | 
|  | 146 | +impl DelayNs for Delay { | 
|  | 147 | +    #[inline] | 
|  | 148 | +    fn delay_ns(&mut self, ns: u32) { | 
|  | 149 | +        Delay::delay_us(self, ns.saturating_add(999) / 1000) | 
|  | 150 | +    } | 
|  | 151 | + | 
|  | 152 | +    #[inline] | 
|  | 153 | +    fn delay_us(&mut self, us: u32) { | 
|  | 154 | +        Delay::delay_us(self, us) | 
|  | 155 | +    } | 
|  | 156 | + | 
|  | 157 | +    #[inline] | 
|  | 158 | +    fn delay_ms(&mut self, ms: u32) { | 
|  | 159 | +        Delay::delay_ms(self, ms) | 
|  | 160 | +    } | 
|  | 161 | +} | 
0 commit comments