nrf: make wdt INDEX private
This commit is contained in:
parent
f535acfca0
commit
c00e3f94f0
@ -120,7 +120,7 @@ impl<T: Instance> Watchdog<T> {
|
|||||||
|
|
||||||
let mut handles = [const { WatchdogHandle { index: 0 } }; N];
|
let mut handles = [const { WatchdogHandle { index: 0 } }; N];
|
||||||
for i in 0..N {
|
for i in 0..N {
|
||||||
handles[i] = unsafe { WatchdogHandle::steal(T::INDEX, i as u8) };
|
handles[i] = unsafe { WatchdogHandle::steal::<T>(i as u8) };
|
||||||
handles[i].pet();
|
handles[i].pet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,18 +202,18 @@ impl WatchdogHandle {
|
|||||||
/// Steal a watchdog handle by index.
|
/// Steal a watchdog handle by index.
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// Watchdog must be initialized, `instance_index` must be the index
|
/// Watchdog must be initialized and `index` must be between `0` and `N-1`
|
||||||
/// [`Instance::INDEX`], and `index` must be between `0` and `N-1` where `N`
|
/// where `N` is the handle count when initializing.
|
||||||
/// is the handle count when initializing.
|
pub unsafe fn steal<T: Instance>(index: u8) -> Self {
|
||||||
pub unsafe fn steal(instance_index: u8, index: u8) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
index: instance_index * 8 + index,
|
index: T::INDEX * 8 + index,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait SealedInstance {
|
pub(crate) trait SealedInstance {
|
||||||
const REGS: pac::wdt::Wdt;
|
const REGS: pac::wdt::Wdt;
|
||||||
|
const INDEX: u8;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// WDT instance.
|
/// WDT instance.
|
||||||
@ -221,18 +221,16 @@ pub(crate) trait SealedInstance {
|
|||||||
pub trait Instance: SealedInstance + PeripheralType + 'static + Send {
|
pub trait Instance: SealedInstance + PeripheralType + 'static + Send {
|
||||||
/// Interrupt for this peripheral.
|
/// Interrupt for this peripheral.
|
||||||
type Interrupt: interrupt::typelevel::Interrupt;
|
type Interrupt: interrupt::typelevel::Interrupt;
|
||||||
/// Index of the watchdog instance.
|
|
||||||
const INDEX: u8;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_wdt {
|
macro_rules! impl_wdt {
|
||||||
($type:ident, $pac_type:ident, $irq:ident, $index:literal) => {
|
($type:ident, $pac_type:ident, $irq:ident, $index:literal) => {
|
||||||
impl crate::wdt::SealedInstance for peripherals::$type {
|
impl crate::wdt::SealedInstance for peripherals::$type {
|
||||||
const REGS: pac::wdt::Wdt = pac::$pac_type;
|
const REGS: pac::wdt::Wdt = pac::$pac_type;
|
||||||
|
const INDEX: u8 = $index;
|
||||||
}
|
}
|
||||||
impl crate::wdt::Instance for peripherals::$type {
|
impl crate::wdt::Instance for peripherals::$type {
|
||||||
type Interrupt = crate::interrupt::typelevel::$irq;
|
type Interrupt = crate::interrupt::typelevel::$irq;
|
||||||
const INDEX: u8 = $index;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user