aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/wdt.rs
diff options
context:
space:
mode:
authorMatthew Tran <[email protected]>2025-04-21 10:43:02 -0500
committerMatthew Tran <[email protected]>2025-04-21 10:43:02 -0500
commitc00e3f94f0ecccfc8afce3fb9bd19b05d3f8889b (patch)
treed2be71b0310c75d1cad737277cc66b1747d567ef /embassy-nrf/src/wdt.rs
parentf535acfca09b916554fa63550f9e12f18cbca25d (diff)
nrf: make wdt INDEX private
Diffstat (limited to 'embassy-nrf/src/wdt.rs')
-rw-r--r--embassy-nrf/src/wdt.rs16
1 files changed, 7 insertions, 9 deletions
diff --git a/embassy-nrf/src/wdt.rs b/embassy-nrf/src/wdt.rs
index baaf1c801..308071726 100644
--- a/embassy-nrf/src/wdt.rs
+++ b/embassy-nrf/src/wdt.rs
@@ -120,7 +120,7 @@ impl<T: Instance> Watchdog<T> {
120 120
121 let mut handles = [const { WatchdogHandle { index: 0 } }; N]; 121 let mut handles = [const { WatchdogHandle { index: 0 } }; N];
122 for i in 0..N { 122 for i in 0..N {
123 handles[i] = unsafe { WatchdogHandle::steal(T::INDEX, i as u8) }; 123 handles[i] = unsafe { WatchdogHandle::steal::<T>(i as u8) };
124 handles[i].pet(); 124 handles[i].pet();
125 } 125 }
126 126
@@ -202,18 +202,18 @@ impl WatchdogHandle {
202 /// Steal a watchdog handle by index. 202 /// Steal a watchdog handle by index.
203 /// 203 ///
204 /// # Safety 204 /// # Safety
205 /// Watchdog must be initialized, `instance_index` must be the index 205 /// Watchdog must be initialized and `index` must be between `0` and `N-1`
206 /// [`Instance::INDEX`], and `index` must be between `0` and `N-1` where `N` 206 /// where `N` is the handle count when initializing.
207 /// is the handle count when initializing. 207 pub unsafe fn steal<T: Instance>(index: u8) -> Self {
208 pub unsafe fn steal(instance_index: u8, index: u8) -> Self {
209 Self { 208 Self {
210 index: instance_index * 8 + index, 209 index: T::INDEX * 8 + index,
211 } 210 }
212 } 211 }
213} 212}
214 213
215pub(crate) trait SealedInstance { 214pub(crate) trait SealedInstance {
216 const REGS: pac::wdt::Wdt; 215 const REGS: pac::wdt::Wdt;
216 const INDEX: u8;
217} 217}
218 218
219/// WDT instance. 219/// WDT instance.
@@ -221,18 +221,16 @@ pub(crate) trait SealedInstance {
221pub trait Instance: SealedInstance + PeripheralType + 'static + Send { 221pub trait Instance: SealedInstance + PeripheralType + 'static + Send {
222 /// Interrupt for this peripheral. 222 /// Interrupt for this peripheral.
223 type Interrupt: interrupt::typelevel::Interrupt; 223 type Interrupt: interrupt::typelevel::Interrupt;
224 /// Index of the watchdog instance.
225 const INDEX: u8;
226} 224}
227 225
228macro_rules! impl_wdt { 226macro_rules! impl_wdt {
229 ($type:ident, $pac_type:ident, $irq:ident, $index:literal) => { 227 ($type:ident, $pac_type:ident, $irq:ident, $index:literal) => {
230 impl crate::wdt::SealedInstance for peripherals::$type { 228 impl crate::wdt::SealedInstance for peripherals::$type {
231 const REGS: pac::wdt::Wdt = pac::$pac_type; 229 const REGS: pac::wdt::Wdt = pac::$pac_type;
230 const INDEX: u8 = $index;
232 } 231 }
233 impl crate::wdt::Instance for peripherals::$type { 232 impl crate::wdt::Instance for peripherals::$type {
234 type Interrupt = crate::interrupt::typelevel::$irq; 233 type Interrupt = crate::interrupt::typelevel::$irq;
235 const INDEX: u8 = $index;
236 } 234 }
237 }; 235 };
238} 236}