Skip to main content

ch57x_pac/
lib.rs

1#![doc = include_str!("../README.md")]
2#![doc = "\n\n---\n\nGenerated Register API\n"]
3#![doc = "Peripheral access API for WCH CH57x microcontrollers (generated with svd2rust).\n\nYou can find an overview of the generated API [here].\n\n[here]: https://docs.rs/svd2rust/latest/svd2rust/#peripheral-api"]
4#![allow(non_camel_case_types)]
5#![allow(non_snake_case)]
6#![no_std]
7#![cfg_attr(docsrs, feature(doc_cfg))]
8#[doc = r"Number available in the NVIC for configuring priority"]
9pub const NVIC_PRIO_BITS: u8 = 2;
10#[allow(unused_imports)]
11use generic::*;
12#[doc = r"Common register and bit access and modify traits"]
13pub mod generic;
14#[cfg(feature = "rt")]
15extern "C" {
16    fn TMR0();
17    fn GPIO_A();
18    fn GPIO_B();
19    fn SPI0();
20    fn BLEL();
21    fn BLEB();
22    fn USB();
23    fn TMR2();
24    fn UART0();
25    fn UART1();
26    fn RTC();
27    fn ADC();
28    fn TMR3();
29    fn UART2();
30    fn UART3();
31    fn WDOG_BAT();
32}
33#[doc(hidden)]
34#[repr(C)]
35pub union Vector {
36    _handler: unsafe extern "C" fn(),
37    _reserved: u32,
38}
39#[cfg(feature = "rt")]
40#[doc(hidden)]
41#[link_section = ".vector_table.interrupts"]
42#[no_mangle]
43pub static __INTERRUPTS: [Vector; 22] = [
44    Vector { _reserved: 0 },
45    Vector { _reserved: 0 },
46    Vector { _handler: TMR0 },
47    Vector { _handler: GPIO_A },
48    Vector { _handler: GPIO_B },
49    Vector { _handler: SPI0 },
50    Vector { _handler: BLEL },
51    Vector { _handler: BLEB },
52    Vector { _handler: USB },
53    Vector { _handler: TMR2 },
54    Vector { _handler: UART0 },
55    Vector { _handler: UART1 },
56    Vector { _reserved: 0 },
57    Vector { _reserved: 0 },
58    Vector { _handler: RTC },
59    Vector { _handler: ADC },
60    Vector { _handler: TMR3 },
61    Vector { _handler: UART2 },
62    Vector { _handler: UART3 },
63    Vector { _reserved: 0 },
64    Vector { _reserved: 0 },
65    Vector { _handler: WDOG_BAT },
66];
67#[doc = r"Enumeration of all the interrupts."]
68#[derive(Copy, Clone, Debug, PartialEq, Eq)]
69#[repr(u16)]
70pub enum Interrupt {
71    #[doc = "2 - TMR0_IRQHandler"]
72    TMR0 = 2,
73    #[doc = "3 - GPIO_IRQHandler"]
74    GPIO_A = 3,
75    #[doc = "4 - GPIO_IRQHandler"]
76    GPIO_B = 4,
77    #[doc = "5 - SPI0_IRQHandler"]
78    SPI0 = 5,
79    #[doc = "6 - LLE_IRQHandler"]
80    BLEL = 6,
81    #[doc = "7 - BB_IRQHandler"]
82    BLEB = 7,
83    #[doc = "8 - USB_IRQHandler"]
84    USB = 8,
85    #[doc = "9 - TMR2_IRQHandler"]
86    TMR2 = 9,
87    #[doc = "10 - UART0_IRQHandler"]
88    UART0 = 10,
89    #[doc = "11 - UART1_IRQHandler"]
90    UART1 = 11,
91    #[doc = "14 - RTC_IRQHandler"]
92    RTC = 14,
93    #[doc = "15 - ADC_IRQHandler"]
94    ADC = 15,
95    #[doc = "16 - TMR3_IRQHandler"]
96    TMR3 = 16,
97    #[doc = "17 - UART1_IRQHandler"]
98    UART2 = 17,
99    #[doc = "18 - UART3_IRQHandler"]
100    UART3 = 18,
101    #[doc = "21 - WDT_IRQHandler"]
102    WDOG_BAT = 21,
103}
104#[doc = "System Control Register"]
105pub type Sys = crate::Periph<sys::RegisterBlock, 0x4000_1000>;
106impl core::fmt::Debug for Sys {
107    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
108        f.debug_struct("Sys").finish()
109    }
110}
111#[doc = "System Control Register"]
112pub mod sys;
113#[doc = "Timer0 register"]
114pub type Tmr0 = crate::Periph<tmr0::RegisterBlock, 0x4000_2000>;
115impl core::fmt::Debug for Tmr0 {
116    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
117        f.debug_struct("Tmr0").finish()
118    }
119}
120#[doc = "Timer0 register"]
121pub mod tmr0;
122#[doc = "Timer1 register"]
123pub type Tmr1 = crate::Periph<tmr1::RegisterBlock, 0x4000_2400>;
124impl core::fmt::Debug for Tmr1 {
125    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
126        f.debug_struct("Tmr1").finish()
127    }
128}
129#[doc = "Timer1 register"]
130pub mod tmr1;
131#[doc = "Timer2 register"]
132pub type Tmr2 = crate::Periph<tmr2::RegisterBlock, 0x4000_2800>;
133impl core::fmt::Debug for Tmr2 {
134    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
135        f.debug_struct("Tmr2").finish()
136    }
137}
138#[doc = "Timer2 register"]
139pub mod tmr2;
140#[doc = "Timer3 register"]
141pub type Tmr3 = crate::Periph<tmr3::RegisterBlock, 0x4000_2c00>;
142impl core::fmt::Debug for Tmr3 {
143    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
144        f.debug_struct("Tmr3").finish()
145    }
146}
147#[doc = "Timer3 register"]
148pub mod tmr3;
149#[doc = "UART0 register"]
150pub type Uart0 = crate::Periph<uart0::RegisterBlock, 0x4000_3000>;
151impl core::fmt::Debug for Uart0 {
152    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
153        f.debug_struct("Uart0").finish()
154    }
155}
156#[doc = "UART0 register"]
157pub mod uart0;
158#[doc = "UART1 register"]
159pub type Uart1 = crate::Periph<uart1::RegisterBlock, 0x4000_3400>;
160impl core::fmt::Debug for Uart1 {
161    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
162        f.debug_struct("Uart1").finish()
163    }
164}
165#[doc = "UART1 register"]
166pub mod uart1;
167#[doc = "UART2 register"]
168pub type Uart2 = crate::Periph<uart2::RegisterBlock, 0x4000_3800>;
169impl core::fmt::Debug for Uart2 {
170    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
171        f.debug_struct("Uart2").finish()
172    }
173}
174#[doc = "UART2 register"]
175pub mod uart2;
176#[doc = "UART3 register"]
177pub type Uart3 = crate::Periph<uart3::RegisterBlock, 0x4000_3c00>;
178impl core::fmt::Debug for Uart3 {
179    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
180        f.debug_struct("Uart3").finish()
181    }
182}
183#[doc = "UART3 register"]
184pub mod uart3;
185#[doc = "SPI0 register"]
186pub type Spi0 = crate::Periph<spi0::RegisterBlock, 0x4000_4000>;
187impl core::fmt::Debug for Spi0 {
188    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
189        f.debug_struct("Spi0").finish()
190    }
191}
192#[doc = "SPI0 register"]
193pub mod spi0;
194#[doc = "PWMx register"]
195pub type Pwmx = crate::Periph<pwmx::RegisterBlock, 0x4000_5000>;
196impl core::fmt::Debug for Pwmx {
197    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
198        f.debug_struct("Pwmx").finish()
199    }
200}
201#[doc = "PWMx register"]
202pub mod pwmx;
203#[doc = "USB register"]
204pub type Usb = crate::Periph<usb::RegisterBlock, 0x4000_8000>;
205impl core::fmt::Debug for Usb {
206    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
207        f.debug_struct("Usb").finish()
208    }
209}
210#[doc = "USB register"]
211pub mod usb;
212#[doc = "Program Fast Interrupt Controller"]
213pub type Pfic = crate::Periph<pfic::RegisterBlock, 0xe000_e000>;
214impl core::fmt::Debug for Pfic {
215    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
216        f.debug_struct("Pfic").finish()
217    }
218}
219#[doc = "Program Fast Interrupt Controller"]
220pub mod pfic;
221#[doc = "Systick register"]
222pub type Systick = crate::Periph<systick::RegisterBlock, 0xe000_f000>;
223impl core::fmt::Debug for Systick {
224    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
225        f.debug_struct("Systick").finish()
226    }
227}
228#[doc = "Systick register"]
229pub mod systick;
230#[no_mangle]
231static mut DEVICE_PERIPHERALS: bool = false;
232#[doc = r" All the peripherals."]
233#[allow(non_snake_case)]
234pub struct Peripherals {
235    #[doc = "SYS"]
236    pub sys: Sys,
237    #[doc = "TMR0"]
238    pub tmr0: Tmr0,
239    #[doc = "TMR1"]
240    pub tmr1: Tmr1,
241    #[doc = "TMR2"]
242    pub tmr2: Tmr2,
243    #[doc = "TMR3"]
244    pub tmr3: Tmr3,
245    #[doc = "UART0"]
246    pub uart0: Uart0,
247    #[doc = "UART1"]
248    pub uart1: Uart1,
249    #[doc = "UART2"]
250    pub uart2: Uart2,
251    #[doc = "UART3"]
252    pub uart3: Uart3,
253    #[doc = "SPI0"]
254    pub spi0: Spi0,
255    #[doc = "PWMx"]
256    pub pwmx: Pwmx,
257    #[doc = "USB"]
258    pub usb: Usb,
259    #[doc = "PFIC"]
260    pub pfic: Pfic,
261    #[doc = "Systick"]
262    pub systick: Systick,
263}
264impl Peripherals {
265    #[doc = r" Returns all the peripherals *once*."]
266    #[cfg(feature = "critical-section")]
267    #[inline]
268    pub fn take() -> Option<Self> {
269        critical_section::with(|_| {
270            if unsafe { DEVICE_PERIPHERALS } {
271                return None;
272            }
273            Some(unsafe { Peripherals::steal() })
274        })
275    }
276    #[doc = r" Unchecked version of `Peripherals::take`."]
277    #[doc = r""]
278    #[doc = r" # Safety"]
279    #[doc = r""]
280    #[doc = r" Each of the returned peripherals must be used at most once."]
281    #[inline]
282    pub unsafe fn steal() -> Self {
283        DEVICE_PERIPHERALS = true;
284        Peripherals {
285            sys: Sys::steal(),
286            tmr0: Tmr0::steal(),
287            tmr1: Tmr1::steal(),
288            tmr2: Tmr2::steal(),
289            tmr3: Tmr3::steal(),
290            uart0: Uart0::steal(),
291            uart1: Uart1::steal(),
292            uart2: Uart2::steal(),
293            uart3: Uart3::steal(),
294            spi0: Spi0::steal(),
295            pwmx: Pwmx::steal(),
296            usb: Usb::steal(),
297            pfic: Pfic::steal(),
298            systick: Systick::steal(),
299        }
300    }
301}