Switch to safe Peripherals API

This commit is contained in:
2019-09-28 12:42:27 -07:00
parent 5637649487
commit b73cb2fa1c

View File

@@ -6,24 +6,22 @@ pub use f3::hal::stm32f30x::{adc1, gpioa, gpioc, rcc};
use f3::hal::stm32f30x::{self, ADC1, GPIOA, GPIOD, GPIOE, RCC}; use f3::hal::stm32f30x::{self, ADC1, GPIOA, GPIOD, GPIOE, RCC};
pub struct Peripherals { pub struct Peripherals {
pub gpioa: &'static gpioa::RegisterBlock, pub gpioa: GPIOA,
pub gpiod: &'static gpioc::RegisterBlock, pub gpiod: GPIOD,
pub gpioe: &'static gpioc::RegisterBlock, pub gpioe: GPIOE,
pub rcc: &'static rcc::RegisterBlock, pub rcc: RCC,
pub adc1: &'static adc1::RegisterBlock, pub adc1: ADC1,
} }
pub fn init() -> Peripherals { pub fn init() -> Peripherals {
// restrict access to the other peripherals // restrict access to the other peripherals
(stm32f30x::Peripherals::take().unwrap()); let per = stm32f30x::Peripherals::take().unwrap();
unsafe { Peripherals {
Peripherals { gpioa: per.GPIOA,
gpioa: &*GPIOA::ptr(), gpiod: per.GPIOD,
gpiod: &*GPIOD::ptr(), gpioe: per.GPIOE,
gpioe: &*GPIOE::ptr(), rcc: per.RCC,
rcc: &*RCC::ptr(), adc1: per.ADC1,
adc1: &*ADC1::ptr(),
}
} }
} }