Skip to content

Commit 817252b

Browse files
committed
Add SYSCFG wrapper, based on f4xx-hal
1 parent b1a3451 commit 817252b

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ cfg_if::cfg_if! {
191191
pub mod rtc;
192192
pub mod serial;
193193
pub mod spi;
194+
pub mod syscfg;
194195
pub mod timer;
195196
}
196197
}

src/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub use crate::flash::FlashExt as _stm32f3xx_hal_flash_FlashExt;
66
pub use crate::gpio::GpioExt as _stm32f3xx_hal_gpio_GpioExt;
77
pub use crate::hal::prelude::*;
88
pub use crate::rcc::RccExt as _stm32f3xx_hal_rcc_RccExt;
9+
pub use crate::syscfg::SysCfgExt as _stm32f3xx_hal_syscfg_SysCfgExt;
910
pub use crate::time::duration::Extensions as _stm32f3xx_hal_time_time_Extensions;
1011
pub use crate::time::rate::Extensions as _stm32f3xx_hal_time_rate_Extensions;
1112
#[cfg(feature = "unproven")]

src/syscfg.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//! System configuration controller
2+
3+
use core::ops::Deref;
4+
5+
use crate::{pac::SYSCFG, rcc::APB2};
6+
7+
/// Extension trait that constrains the `SYSCFG` peripheral
8+
pub trait SysCfgExt {
9+
/// Constrains the `SYSCFG` peripheral so it plays nicely with the other abstractions
10+
fn constrain(self, apb2: &mut APB2) -> SysCfg;
11+
}
12+
13+
impl SysCfgExt for SYSCFG {
14+
fn constrain(self, apb2: &mut APB2) -> SysCfg {
15+
apb2.enr().modify(|_, w| w.syscfgen().enabled());
16+
17+
SysCfg(self)
18+
}
19+
}
20+
21+
/// Constrained SYSCFG peripheral
22+
///
23+
/// An instance of this struct is acquired by calling the
24+
/// [`constrain`](SysCfgExt::constrain) function on the
25+
/// [`SYSCFG`](crate::pac::SYSCFG) struct.
26+
///
27+
/// ```
28+
/// let dp = pac::Peripherals::take().unwrap();
29+
/// let syscfg = dp.SYSCFG.constrain();
30+
/// ```
31+
pub struct SysCfg(SYSCFG);
32+
33+
impl Deref for SysCfg {
34+
type Target = SYSCFG;
35+
36+
#[inline(always)]
37+
fn deref(&self) -> &Self::Target {
38+
&self.0
39+
}
40+
}

0 commit comments

Comments
 (0)