Skip to content

Commit 1dbe8e8

Browse files
Implement Deref and DerefMut for Rcc
Cordoning off access to RCC registers makes implementing certain software and drivers (e.g. a bootloader for STMF0 cores need SYSCFG) unnecessarily difficult. A completely encapsulated RCC renders peripheral enable registers inaccessible and some drivers (e.g stm32_usbd) opt for using unsafe raw pointer accesses completely eliminating the safety and the structure provided by the HAL. This commit copies an escape hatch from stm32f4xx-hal crate by implementing Deref and DerefMut for Rcc structure. The stm32f4xx-hal implementation can be seen at the link below: https://github.com/stm32-rs/stm32f4xx-hal/blob/0ba01f4fb3f19b0eea40d8ea2403e2e9d4e41609/src/rcc/mod.rs#L56-L67
1 parent 8eda864 commit 1dbe8e8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/rcc.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::pac::RCC;
22
use crate::time::Hertz;
3+
use core::ops::{Deref, DerefMut};
34

45
/// Extension trait that sets up the `RCC` peripheral
56
pub trait RccExt {
@@ -45,6 +46,21 @@ pub struct Rcc {
4546
pub(crate) regs: RCC,
4647
}
4748

49+
impl Deref for Rcc {
50+
type Target = RCC;
51+
52+
fn deref(&self) -> &Self::Target {
53+
&self.regs
54+
}
55+
}
56+
57+
impl DerefMut for Rcc {
58+
59+
fn deref_mut(&mut self) -> &mut Self::Target {
60+
&mut self.regs
61+
}
62+
}
63+
4864
pub enum HSEBypassMode {
4965
/// Not bypassed: for crystals
5066
NotBypassed,

0 commit comments

Comments
 (0)