Skip to main content

ch32_hal/
peripheral.rs

1use critical_section::CriticalSection;
2
3pub(crate) trait SealedRccPeripheral {
4    fn frequency() -> crate::time::Hertz;
5    fn enable_and_reset_with_cs(cs: CriticalSection);
6    fn disable_with_cs(cs: CriticalSection);
7
8    fn enable_and_reset() {
9        critical_section::with(|cs| Self::enable_and_reset_with_cs(cs))
10    }
11    fn disable() {
12        critical_section::with(|cs| Self::disable_with_cs(cs))
13    }
14}
15
16pub(crate) trait SealedRemapPeripheral {
17    fn set_remap(remap: u8);
18}
19
20#[allow(private_bounds)]
21pub trait RccPeripheral: SealedRccPeripheral + 'static {}
22#[allow(private_bounds)]
23pub trait RemapPeripheral: SealedRemapPeripheral + 'static {}
24
25/// Supertrait used by drivers that write `AFIO.PCFR*`.
26///
27/// Remap chips require [`RemapPeripheral`]. CH32H4 selects the function with
28/// a per-pin AF number, so the bound is empty there.
29#[cfg(not(afio_h4))]
30pub(crate) trait RemapBound: RemapPeripheral {}
31#[cfg(not(afio_h4))]
32impl<T: RemapPeripheral> RemapBound for T {}
33
34#[cfg(afio_h4)]
35pub(crate) trait RemapBound {}
36#[cfg(afio_h4)]
37impl<T: ?Sized> RemapBound for T {}