#![allow(non_camel_case_types, non_snake_case)]
use core::marker::PhantomData;
use core::ops::Deref;
use core::sync::atomic::{AtomicBool, Ordering};
pub use bcm2711_lpa::systmr;
pub use bcm2711_lpa::uart0;
pub use bcm2711_lpa::vcmailbox;
pub use bcm2711_lpa::emmc;
pub const SOC_BASE: usize = 0x10_0000_0000;
pub const RP1_BASE: usize = 0x1f_0000_0000;
pub struct SYSTMR {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for SYSTMR {}
impl SYSTMR {
pub const PTR: *const systmr::RegisterBlock = (SOC_BASE + 0x7c00_3000) as *const _;
#[inline(always)]
pub const fn ptr() -> *const systmr::RegisterBlock {
Self::PTR
}
pub unsafe fn steal() -> Self {
Self {
_marker: PhantomData,
}
}
}
impl Deref for SYSTMR {
type Target = systmr::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for SYSTMR {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("SYSTMR").finish()
}
}
pub struct VCMAILBOX {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for VCMAILBOX {}
impl VCMAILBOX {
pub const PTR: *const vcmailbox::RegisterBlock = (SOC_BASE + 0x7c01_3880) as *const _;
#[inline(always)]
pub const fn ptr() -> *const vcmailbox::RegisterBlock {
Self::PTR
}
pub unsafe fn steal() -> Self {
Self {
_marker: PhantomData,
}
}
}
impl Deref for VCMAILBOX {
type Target = vcmailbox::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for VCMAILBOX {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("VCMAILBOX").finish()
}
}
pub struct SDIO1 {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for SDIO1 {}
impl SDIO1 {
pub const PTR: *const emmc::RegisterBlock = (SOC_BASE + 0x00ff_f000) as *const _;
pub const CFG: usize = SOC_BASE + 0x00ff_f400;
#[inline(always)]
pub const fn ptr() -> *const emmc::RegisterBlock {
Self::PTR
}
pub unsafe fn steal() -> Self {
Self {
_marker: PhantomData,
}
}
}
impl Deref for SDIO1 {
type Target = emmc::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for SDIO1 {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("SDIO1").finish()
}
}
pub struct BSC1 {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for BSC1 {}
impl BSC1 {
pub const ADDR: usize = RP1_BASE + 0x0007_4000;
pub unsafe fn steal() -> Self {
Self {
_marker: PhantomData,
}
}
}
impl core::fmt::Debug for BSC1 {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("BSC1").finish()
}
}
pub struct BSC0 {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for BSC0 {}
impl BSC0 {
pub const ADDR: usize = RP1_BASE + 0x0007_0000;
pub unsafe fn steal() -> Self {
Self {
_marker: PhantomData,
}
}
}
impl core::fmt::Debug for BSC0 {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("BSC0").finish()
}
}
pub struct UART0 {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for UART0 {}
impl UART0 {
pub const PTR: *const uart0::RegisterBlock = (RP1_BASE + 0x0003_0000) as *const _;
#[inline(always)]
pub const fn ptr() -> *const uart0::RegisterBlock {
Self::PTR
}
pub unsafe fn steal() -> Self {
Self {
_marker: PhantomData,
}
}
}
impl Deref for UART0 {
type Target = uart0::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for UART0 {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("UART0").finish()
}
}
pub struct GPIO {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for GPIO {}
impl GPIO {
pub const IO_BANK0: usize = RP1_BASE + 0x000d_0000;
pub const SYS_RIO0: usize = RP1_BASE + 0x000e_0000;
pub const PADS_BANK0: usize = RP1_BASE + 0x000f_0000;
pub unsafe fn steal() -> Self {
Self {
_marker: PhantomData,
}
}
}
impl core::fmt::Debug for GPIO {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("GPIO").finish()
}
}
pub struct GIO_AON {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for GIO_AON {}
impl GIO_AON {
pub const PTR: *const u32 = (SOC_BASE + 0x7d51_7c00) as *const _;
#[inline(always)]
pub const fn ptr() -> *const u32 {
Self::PTR
}
pub unsafe fn steal() -> Self {
Self {
_marker: PhantomData,
}
}
}
impl core::fmt::Debug for GIO_AON {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("GIO_AON").finish()
}
}
static TAKEN: AtomicBool = AtomicBool::new(false);
pub struct Peripherals {
pub VCMAILBOX: VCMAILBOX,
pub SYSTMR: SYSTMR,
pub SDIO1: SDIO1,
pub UART0: UART0,
pub BSC0: BSC0,
pub BSC1: BSC1,
pub GPIO: GPIO,
pub GIO_AON: GIO_AON,
}
impl Peripherals {
pub fn take() -> Option<Self> {
critical_section::with(|_| {
if TAKEN.load(Ordering::Relaxed) {
return None;
}
Some(unsafe { Self::steal() })
})
}
pub unsafe fn steal() -> Self {
TAKEN.store(true, Ordering::Relaxed);
Self {
VCMAILBOX: unsafe { VCMAILBOX::steal() },
SYSTMR: unsafe { SYSTMR::steal() },
SDIO1: unsafe { SDIO1::steal() },
UART0: unsafe { UART0::steal() },
BSC0: unsafe { BSC0::steal() },
BSC1: unsafe { BSC1::steal() },
GPIO: unsafe { GPIO::steal() },
GIO_AON: unsafe { GIO_AON::steal() },
}
}
}