Switch to safe Peripherals API
This commit is contained in:
24
src/bsp.rs
24
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};
|
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: &*GPIOA::ptr(),
|
gpioa: per.GPIOA,
|
||||||
gpiod: &*GPIOD::ptr(),
|
gpiod: per.GPIOD,
|
||||||
gpioe: &*GPIOE::ptr(),
|
gpioe: per.GPIOE,
|
||||||
rcc: &*RCC::ptr(),
|
rcc: per.RCC,
|
||||||
adc1: &*ADC1::ptr(),
|
adc1: per.ADC1,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user