From b73cb2fa1c7a2e3ebaceecd4da7a4b0e7d94a045 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 28 Sep 2019 12:42:27 -0700 Subject: [PATCH] Switch to safe Peripherals API --- src/bsp.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/bsp.rs b/src/bsp.rs index 46b7f23..bd7b68d 100644 --- a/src/bsp.rs +++ b/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, } }