use rp2350_pac::RESETS;
pub trait Resettable {
const RESET_MASK: u32;
#[inline]
fn init() {
unsafe {
reset(Self::RESET_MASK);
unreset(Self::RESET_MASK);
}
}
#[inline]
fn reset() {
unsafe { reset(Self::RESET_MASK) }
}
#[inline]
fn unreset() {
unsafe { unreset(Self::RESET_MASK) }
}
}
#[inline]
pub unsafe fn reset(mask: u32) {
let resets = unsafe { RESETS::steal() };
resets.reset.set_bits(mask);
}
#[inline]
pub unsafe fn unreset(mask: u32) {
let resets = unsafe { RESETS::steal() };
resets.reset.clr_bits(mask);
crate::spin::spin_wait("peripheral to leave reset", || {
(resets.reset_done.read_bits() & mask) == mask
});
}
pub const RESET_TIMEOUT_SPINS: u32 = crate::spin::SPIN_TIMEOUT;
macro_rules! impl_resettable {
($($pac_type:ty => $bit:literal),+ $(,)?) => {
$(
impl Resettable for $pac_type {
const RESET_MASK: u32 = 1 << $bit;
}
)+
};
}
impl_resettable!(
rp2350_pac::ADC => 0,
rp2350_pac::BUSCTRL => 1,
rp2350_pac::DMA => 2,
rp2350_pac::HSTX_CTRL => 3,
rp2350_pac::I2C0 => 4,
rp2350_pac::I2C1 => 5,
rp2350_pac::IO_BANK0 => 6,
rp2350_pac::IO_QSPI => 7,
rp2350_pac::PADS_BANK0 => 9,
rp2350_pac::PADS_QSPI => 10,
rp2350_pac::PIO0 => 11,
rp2350_pac::PIO1 => 12,
rp2350_pac::PIO2 => 13,
rp2350_pac::PLL_SYS => 14,
rp2350_pac::PLL_USB => 15,
rp2350_pac::PWM => 16,
rp2350_pac::SHA256 => 17,
rp2350_pac::SPI0 => 18,
rp2350_pac::SPI1 => 19,
rp2350_pac::SYSCFG => 20,
rp2350_pac::SYSINFO => 21,
rp2350_pac::TBMAN => 22,
rp2350_pac::TIMER0 => 23,
rp2350_pac::TIMER1 => 24,
rp2350_pac::TRNG => 25,
rp2350_pac::UART0 => 26,
rp2350_pac::UART1 => 27,
rp2350_pac::USB => 28,
);