some more const improvements

This commit is contained in:
Robin Müller 2025-04-07 14:36:17 +02:00
parent 7d6f69d808
commit e8e7ea9b1c
Signed by: muellerr
GPG Key ID: A649FB78196E3849

View File

@ -38,6 +38,21 @@ pub enum Bank {
Uart2 = 2,
}
impl Bank {
/// Retrieve the peripheral register block.
///
/// # Safety
///
/// Circumvents the HAL safety guarantees.
pub const unsafe fn reg_block(&self) -> &'static uart_base::RegisterBlock {
match self {
Bank::Uart0 => unsafe { &(*pac::Uart0::ptr()) },
Bank::Uart1 => unsafe { &(*pac::Uart1::ptr()) },
Bank::Uart2 => unsafe { &(*pac::Uart2::ptr()) },
}
}
}
//==================================================================================================
// Type-Level support
//==================================================================================================
@ -421,21 +436,6 @@ impl Instance for Uart2 {
}
}
impl Bank {
/// Retrieve the peripheral register block.
///
/// # Safety
///
/// Circumvents the HAL safety guarantees.
pub unsafe fn reg_block(&self) -> &'static uart_base::RegisterBlock {
match self {
Bank::Uart0 => unsafe { pac::Uart0::reg_block() },
Bank::Uart1 => unsafe { pac::Uart1::reg_block() },
Bank::Uart2 => unsafe { pac::Uart2::reg_block() },
}
}
}
//==================================================================================================
// UART implementation
//==================================================================================================