WCH_CH57x_PAC/src/lib.rs
Yilin Sun 4efd89758a
Initial commit.
Signed-off-by: Yilin Sun <imi415@imi.moe>
2023-01-27 20:39:58 +08:00

730 lines
19 KiB
Rust

#![doc = "Peripheral access API for CH579SFR microcontrollers (generated using svd2rust v0.28.0 ( ))\n\nYou can find an overview of the generated API [here].\n\nAPI features to be included in the [next]
svd2rust release can be generated by cloning the svd2rust [repository], checking out the above commit, and running `cargo doc --open`.\n\n[here]: https://docs.rs/svd2rust/0.28.0/svd2rust/#peripheral-api\n[next]: https://github.com/rust-embedded/svd2rust/blob/master/CHANGELOG.md#unreleased\n[repository]: https://github.com/rust-embedded/svd2rust"]
#![deny(dead_code)]
#![deny(improper_ctypes)]
#![deny(missing_docs)]
#![deny(no_mangle_generic_items)]
#![deny(non_shorthand_field_patterns)]
#![deny(overflowing_literals)]
#![deny(path_statements)]
#![deny(patterns_in_fns_without_body)]
#![deny(private_in_public)]
#![deny(unconditional_recursion)]
#![deny(unused_allocation)]
#![deny(unused_comparisons)]
#![deny(unused_parens)]
#![deny(while_true)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![no_std]
use core::marker::PhantomData;
use core::ops::Deref;
#[doc = r"Number available in the NVIC for configuring priority"]
pub const NVIC_PRIO_BITS: u8 = 2;
#[cfg(feature = "rt")]
pub use self::Interrupt as interrupt;
pub use cortex_m::peripheral::Peripherals as CorePeripherals;
pub use cortex_m::peripheral::{CBP, CPUID, DCB, DWT, FPB, ITM, MPU, NVIC, SCB, SYST, TPIU};
#[cfg(feature = "rt")]
pub use cortex_m_rt::interrupt;
#[allow(unused_imports)]
use generic::*;
#[doc = r"Common register and bit access and modify traits"]
pub mod generic;
#[cfg(feature = "rt")]
extern "C" {
fn TMR0();
fn GPIO();
fn SLAVE();
fn SPI0();
fn BB();
fn LLE();
fn USB();
fn ETH();
fn TMR1();
fn TMR2();
fn UART0();
fn UART1();
fn RTC();
fn ADC();
fn SPI1();
fn LED();
fn TMR3();
fn UART2();
fn UART3();
fn WDOG_BAT();
}
#[doc(hidden)]
pub union Vector {
_handler: unsafe extern "C" fn(),
_reserved: u32,
}
#[cfg(feature = "rt")]
#[doc(hidden)]
#[link_section = ".vector_table.interrupts"]
#[no_mangle]
pub static __INTERRUPTS: [Vector; 20] = [
Vector { _handler: TMR0 },
Vector { _handler: GPIO },
Vector { _handler: SLAVE },
Vector { _handler: SPI0 },
Vector { _handler: BB },
Vector { _handler: LLE },
Vector { _handler: USB },
Vector { _handler: ETH },
Vector { _handler: TMR1 },
Vector { _handler: TMR2 },
Vector { _handler: UART0 },
Vector { _handler: UART1 },
Vector { _handler: RTC },
Vector { _handler: ADC },
Vector { _handler: SPI1 },
Vector { _handler: LED },
Vector { _handler: TMR3 },
Vector { _handler: UART2 },
Vector { _handler: UART3 },
Vector { _handler: WDOG_BAT },
];
#[doc = r"Enumeration of all the interrupts."]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u16)]
pub enum Interrupt {
#[doc = "0 - TMR0_IRQHandler"]
TMR0 = 0,
#[doc = "1 - GPIO_IRQHandler"]
GPIO = 1,
#[doc = "2 - SLAVE_IRQHandler"]
SLAVE = 2,
#[doc = "3 - SPI0_IRQHandler"]
SPI0 = 3,
#[doc = "4 - BB_IRQHandler"]
BB = 4,
#[doc = "5 - LLE_IRQHandler"]
LLE = 5,
#[doc = "6 - USB_IRQHandler"]
USB = 6,
#[doc = "7 - ETH_IRQHandler"]
ETH = 7,
#[doc = "8 - TMR1_IRQHandler"]
TMR1 = 8,
#[doc = "9 - TMR2_IRQHandler"]
TMR2 = 9,
#[doc = "10 - UART0_IRQHandler"]
UART0 = 10,
#[doc = "11 - UART1_IRQHandler"]
UART1 = 11,
#[doc = "12 - RTC_IRQHandler"]
RTC = 12,
#[doc = "13 - ADC_IRQHandler"]
ADC = 13,
#[doc = "14 - SPI1_IRQHandler"]
SPI1 = 14,
#[doc = "15 - LED_IRQHandler"]
LED = 15,
#[doc = "16 - TMR3_IRQHandler"]
TMR3 = 16,
#[doc = "17 - UART1_IRQHandler"]
UART2 = 17,
#[doc = "18 - UART3_IRQHandler"]
UART3 = 18,
#[doc = "19 - WDT_IRQHandler"]
WDOG_BAT = 19,
}
unsafe impl cortex_m::interrupt::InterruptNumber for Interrupt {
#[inline(always)]
fn number(self) -> u16 {
self as u16
}
}
#[doc = "System Control Register"]
pub struct SYS {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for SYS {}
impl SYS {
#[doc = r"Pointer to the register block"]
pub const PTR: *const sys::RegisterBlock = 0x4000_1000 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const sys::RegisterBlock {
Self::PTR
}
}
impl Deref for SYS {
type Target = sys::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for SYS {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("SYS").finish()
}
}
#[doc = "System Control Register"]
pub mod sys;
#[doc = "Flash ROM control register"]
pub struct FLASH {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for FLASH {}
impl FLASH {
#[doc = r"Pointer to the register block"]
pub const PTR: *const flash::RegisterBlock = 0x4000_1800 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const flash::RegisterBlock {
Self::PTR
}
}
impl Deref for FLASH {
type Target = flash::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for FLASH {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("FLASH").finish()
}
}
#[doc = "Flash ROM control register"]
pub mod flash;
#[doc = "Timer0 register"]
pub struct TMR0 {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for TMR0 {}
impl TMR0 {
#[doc = r"Pointer to the register block"]
pub const PTR: *const tmr0::RegisterBlock = 0x4000_2000 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const tmr0::RegisterBlock {
Self::PTR
}
}
impl Deref for TMR0 {
type Target = tmr0::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for TMR0 {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("TMR0").finish()
}
}
#[doc = "Timer0 register"]
pub mod tmr0;
#[doc = "Timer1 register"]
pub struct TMR1 {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for TMR1 {}
impl TMR1 {
#[doc = r"Pointer to the register block"]
pub const PTR: *const tmr1::RegisterBlock = 0x4000_2400 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const tmr1::RegisterBlock {
Self::PTR
}
}
impl Deref for TMR1 {
type Target = tmr1::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for TMR1 {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("TMR1").finish()
}
}
#[doc = "Timer1 register"]
pub mod tmr1;
#[doc = "Timer2 register"]
pub struct TMR2 {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for TMR2 {}
impl TMR2 {
#[doc = r"Pointer to the register block"]
pub const PTR: *const tmr2::RegisterBlock = 0x4000_2800 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const tmr2::RegisterBlock {
Self::PTR
}
}
impl Deref for TMR2 {
type Target = tmr2::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for TMR2 {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("TMR2").finish()
}
}
#[doc = "Timer2 register"]
pub mod tmr2;
#[doc = "Timer3 register"]
pub struct TMR3 {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for TMR3 {}
impl TMR3 {
#[doc = r"Pointer to the register block"]
pub const PTR: *const tmr3::RegisterBlock = 0x4000_2c00 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const tmr3::RegisterBlock {
Self::PTR
}
}
impl Deref for TMR3 {
type Target = tmr3::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for TMR3 {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("TMR3").finish()
}
}
#[doc = "Timer3 register"]
pub mod tmr3;
#[doc = "UART0 register"]
pub struct UART0 {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for UART0 {}
impl UART0 {
#[doc = r"Pointer to the register block"]
pub const PTR: *const uart0::RegisterBlock = 0x4000_3000 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const uart0::RegisterBlock {
Self::PTR
}
}
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()
}
}
#[doc = "UART0 register"]
pub mod uart0;
#[doc = "UART1 register"]
pub struct UART1 {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for UART1 {}
impl UART1 {
#[doc = r"Pointer to the register block"]
pub const PTR: *const uart1::RegisterBlock = 0x4000_3400 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const uart1::RegisterBlock {
Self::PTR
}
}
impl Deref for UART1 {
type Target = uart1::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for UART1 {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("UART1").finish()
}
}
#[doc = "UART1 register"]
pub mod uart1;
#[doc = "UART2 register"]
pub struct UART2 {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for UART2 {}
impl UART2 {
#[doc = r"Pointer to the register block"]
pub const PTR: *const uart2::RegisterBlock = 0x4000_3800 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const uart2::RegisterBlock {
Self::PTR
}
}
impl Deref for UART2 {
type Target = uart2::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for UART2 {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("UART2").finish()
}
}
#[doc = "UART2 register"]
pub mod uart2;
#[doc = "UART3 register"]
pub struct UART3 {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for UART3 {}
impl UART3 {
#[doc = r"Pointer to the register block"]
pub const PTR: *const uart3::RegisterBlock = 0x4000_3c00 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const uart3::RegisterBlock {
Self::PTR
}
}
impl Deref for UART3 {
type Target = uart3::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for UART3 {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("UART3").finish()
}
}
#[doc = "UART3 register"]
pub mod uart3;
#[doc = "SPI0 register"]
pub struct SPI0 {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for SPI0 {}
impl SPI0 {
#[doc = r"Pointer to the register block"]
pub const PTR: *const spi0::RegisterBlock = 0x4000_4000 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const spi0::RegisterBlock {
Self::PTR
}
}
impl Deref for SPI0 {
type Target = spi0::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for SPI0 {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("SPI0").finish()
}
}
#[doc = "SPI0 register"]
pub mod spi0;
#[doc = "SPI1 register"]
pub struct SPI1 {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for SPI1 {}
impl SPI1 {
#[doc = r"Pointer to the register block"]
pub const PTR: *const spi1::RegisterBlock = 0x4000_4400 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const spi1::RegisterBlock {
Self::PTR
}
}
impl Deref for SPI1 {
type Target = spi1::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for SPI1 {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("SPI1").finish()
}
}
#[doc = "SPI1 register"]
pub mod spi1;
#[doc = "PWMx register"]
pub struct PWMX {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for PWMX {}
impl PWMX {
#[doc = r"Pointer to the register block"]
pub const PTR: *const pwmx::RegisterBlock = 0x4000_5000 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const pwmx::RegisterBlock {
Self::PTR
}
}
impl Deref for PWMX {
type Target = pwmx::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for PWMX {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("PWMX").finish()
}
}
#[doc = "PWMx register"]
pub mod pwmx;
#[doc = "LCD register"]
pub struct LCD {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for LCD {}
impl LCD {
#[doc = r"Pointer to the register block"]
pub const PTR: *const lcd::RegisterBlock = 0x4000_6000 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const lcd::RegisterBlock {
Self::PTR
}
}
impl Deref for LCD {
type Target = lcd::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for LCD {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("LCD").finish()
}
}
#[doc = "LCD register"]
pub mod lcd;
#[doc = "LED register"]
pub struct LED {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for LED {}
impl LED {
#[doc = r"Pointer to the register block"]
pub const PTR: *const led::RegisterBlock = 0x4000_6400 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const led::RegisterBlock {
Self::PTR
}
}
impl Deref for LED {
type Target = led::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for LED {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("LED").finish()
}
}
#[doc = "LED register"]
pub mod led;
#[doc = "USB register"]
pub struct USB {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for USB {}
impl USB {
#[doc = r"Pointer to the register block"]
pub const PTR: *const usb::RegisterBlock = 0x4000_8000 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const usb::RegisterBlock {
Self::PTR
}
}
impl Deref for USB {
type Target = usb::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for USB {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("USB").finish()
}
}
#[doc = "USB register"]
pub mod usb;
#[doc = "ETH register"]
pub struct ETH {
_marker: PhantomData<*const ()>,
}
unsafe impl Send for ETH {}
impl ETH {
#[doc = r"Pointer to the register block"]
pub const PTR: *const eth::RegisterBlock = 0x4000_9000 as *const _;
#[doc = r"Return the pointer to the register block"]
#[inline(always)]
pub const fn ptr() -> *const eth::RegisterBlock {
Self::PTR
}
}
impl Deref for ETH {
type Target = eth::RegisterBlock;
#[inline(always)]
fn deref(&self) -> &Self::Target {
unsafe { &*Self::PTR }
}
}
impl core::fmt::Debug for ETH {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("ETH").finish()
}
}
#[doc = "ETH register"]
pub mod eth;
#[no_mangle]
static mut DEVICE_PERIPHERALS: bool = false;
#[doc = r" All the peripherals."]
#[allow(non_snake_case)]
pub struct Peripherals {
#[doc = "SYS"]
pub SYS: SYS,
#[doc = "FLASH"]
pub FLASH: FLASH,
#[doc = "TMR0"]
pub TMR0: TMR0,
#[doc = "TMR1"]
pub TMR1: TMR1,
#[doc = "TMR2"]
pub TMR2: TMR2,
#[doc = "TMR3"]
pub TMR3: TMR3,
#[doc = "UART0"]
pub UART0: UART0,
#[doc = "UART1"]
pub UART1: UART1,
#[doc = "UART2"]
pub UART2: UART2,
#[doc = "UART3"]
pub UART3: UART3,
#[doc = "SPI0"]
pub SPI0: SPI0,
#[doc = "SPI1"]
pub SPI1: SPI1,
#[doc = "PWMX"]
pub PWMX: PWMX,
#[doc = "LCD"]
pub LCD: LCD,
#[doc = "LED"]
pub LED: LED,
#[doc = "USB"]
pub USB: USB,
#[doc = "ETH"]
pub ETH: ETH,
}
impl Peripherals {
#[doc = r" Returns all the peripherals *once*."]
#[cfg(feature = "critical-section")]
#[inline]
pub fn take() -> Option<Self> {
critical_section::with(|_| {
if unsafe { DEVICE_PERIPHERALS } {
return None;
}
Some(unsafe { Peripherals::steal() })
})
}
#[doc = r" Unchecked version of `Peripherals::take`."]
#[doc = r""]
#[doc = r" # Safety"]
#[doc = r""]
#[doc = r" Each of the returned peripherals must be used at most once."]
#[inline]
pub unsafe fn steal() -> Self {
DEVICE_PERIPHERALS = true;
Peripherals {
SYS: SYS {
_marker: PhantomData,
},
FLASH: FLASH {
_marker: PhantomData,
},
TMR0: TMR0 {
_marker: PhantomData,
},
TMR1: TMR1 {
_marker: PhantomData,
},
TMR2: TMR2 {
_marker: PhantomData,
},
TMR3: TMR3 {
_marker: PhantomData,
},
UART0: UART0 {
_marker: PhantomData,
},
UART1: UART1 {
_marker: PhantomData,
},
UART2: UART2 {
_marker: PhantomData,
},
UART3: UART3 {
_marker: PhantomData,
},
SPI0: SPI0 {
_marker: PhantomData,
},
SPI1: SPI1 {
_marker: PhantomData,
},
PWMX: PWMX {
_marker: PhantomData,
},
LCD: LCD {
_marker: PhantomData,
},
LED: LED {
_marker: PhantomData,
},
USB: USB {
_marker: PhantomData,
},
ETH: ETH {
_marker: PhantomData,
},
}
}
}