Switch to safe Peripherals API
This commit is contained in:
parent
5637649487
commit
b73cb2fa1c
26
src/bsp.rs
26
src/bsp.rs
|
@ -6,24 +6,22 @@ pub use f3::hal::stm32f30x::{adc1, gpioa, gpioc, rcc};
|
|||
use f3::hal::stm32f30x::{self, ADC1, GPIOA, GPIOD, GPIOE, RCC};
|
||||
|
||||
pub struct Peripherals {
|
||||
pub gpioa: &'static gpioa::RegisterBlock,
|
||||
pub gpiod: &'static gpioc::RegisterBlock,
|
||||
pub gpioe: &'static gpioc::RegisterBlock,
|
||||
pub rcc: &'static rcc::RegisterBlock,
|
||||
pub adc1: &'static adc1::RegisterBlock,
|
||||
pub gpioa: GPIOA,
|
||||
pub gpiod: GPIOD,
|
||||
pub gpioe: GPIOE,
|
||||
pub rcc: RCC,
|
||||
pub adc1: ADC1,
|
||||
}
|
||||
|
||||
pub fn init() -> Peripherals {
|
||||
// restrict access to the other peripherals
|
||||
(stm32f30x::Peripherals::take().unwrap());
|
||||
let per = stm32f30x::Peripherals::take().unwrap();
|
||||
|
||||
unsafe {
|
||||
Peripherals {
|
||||
gpioa: &*GPIOA::ptr(),
|
||||
gpiod: &*GPIOD::ptr(),
|
||||
gpioe: &*GPIOE::ptr(),
|
||||
rcc: &*RCC::ptr(),
|
||||
adc1: &*ADC1::ptr(),
|
||||
}
|
||||
Peripherals {
|
||||
gpioa: per.GPIOA,
|
||||
gpiod: per.GPIOD,
|
||||
gpioe: per.GPIOE,
|
||||
rcc: per.RCC,
|
||||
adc1: per.ADC1,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue