Skip to content

Commit 05173f9

Browse files
committed
Add inner and inner_mut functions to peripherals where it's easy to do so
Where the registers are owned by a single struct and not shared amongst many channels, etc.
1 parent 80f8676 commit 05173f9

File tree

12 files changed

+117
-0
lines changed

12 files changed

+117
-0
lines changed

src/adc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,16 @@ macro_rules! adc_hal {
841841
panic!("Cannot read linear calibration value when the ADC is disabled");
842842
}
843843
}
844+
845+
/// Returns a reference to the inner peripheral
846+
pub fn inner(&self) -> &$ADC {
847+
&self.rb
848+
}
849+
850+
/// Returns a mutable reference to the inner peripheral
851+
pub fn inner_mut(&mut self) -> &mut $ADC {
852+
&mut self.rb
853+
}
844854
}
845855

846856
impl<WORD, PIN> OneShot<$ADC, WORD, PIN> for Adc<$ADC, Enabled>

src/crc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ impl Crc {
133133
pub fn get_idr(&self) -> u32 {
134134
self.reg.idr.read().idr().bits()
135135
}
136+
137+
/// Returns a reference to the inner peripheral
138+
pub fn inner(&self) -> &CRC {
139+
&self.reg
140+
}
141+
142+
/// Returns a mutable reference to the inner peripheral
143+
pub fn inner_mut(&mut self) -> &mut CRC {
144+
&mut self.reg
145+
}
136146
}
137147

138148
#[macro_use]

src/fmc.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ impl FmcExt for stm32::FMC {
138138
}
139139
}
140140

141+
impl FMC {
142+
/// Returns a reference to the inner peripheral
143+
pub fn inner(&self) -> &stm32::FMC {
144+
&self.fmc
145+
}
146+
147+
/// Returns a mutable reference to the inner peripheral
148+
pub fn inner_mut(&mut self) -> &mut stm32::FMC {
149+
&mut self.fmc
150+
}
151+
}
152+
141153
unsafe impl FmcPeripheral for FMC {
142154
const REGISTERS: *const () = stm32::FMC::ptr() as *const ();
143155

src/i2c.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ macro_rules! i2c {
344344
&self.i2c
345345
}
346346

347+
/// Returns a mutable reference to the inner peripheral
348+
pub fn inner_mut(&mut self) -> &mut $I2CX {
349+
&mut self.i2c
350+
}
351+
347352
/// Enable or disable the DMA mode for reception
348353
pub fn rx_dma(&mut self, enable: bool) {
349354
self.i2c.cr1.modify(|_,w| w.rxdmaen().bit(enable));

src/ltdc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ impl Ltdc {
9999
// unsafe: clear write-one interrupt flag
100100
unsafe { (*LTDC::ptr()).icr.write(|w| w.crrif().set_bit()) };
101101
}
102+
103+
/// Returns a reference to the inner peripheral
104+
pub fn inner(&self) -> &LTDC {
105+
&self.ltdc
106+
}
107+
108+
/// Returns a mutable reference to the inner peripheral
109+
pub fn inner_mut(&mut self) -> &mut LTDC {
110+
&mut self.ltdc
111+
}
102112
}
103113

104114
impl DisplayController for Ltdc {

src/pwr.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,16 @@ impl Pwr {
292292
});
293293
while d3cr!(self.rb).read().vosrdy().bit_is_clear() {}
294294
}
295+
296+
/// Returns a reference to the inner peripheral
297+
pub fn inner(&self) -> &PWR {
298+
&self.rb
299+
}
300+
301+
/// Returns a mutable reference to the inner peripheral
302+
pub fn inner_mut(&mut self) -> &mut PWR {
303+
&mut self.rb
304+
}
295305
}
296306

297307
/// Builder methods

src/rng.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ impl Rng {
9595
pub fn release(self) -> RNG {
9696
self.rb
9797
}
98+
99+
/// Returns a reference to the inner peripheral
100+
pub fn inner(&self) -> &RNG {
101+
&self.rb
102+
}
103+
104+
/// Returns a mutable reference to the inner peripheral
105+
pub fn inner_mut(&mut self) -> &mut RNG {
106+
&mut self.rb
107+
}
98108
}
99109

100110
impl core::iter::Iterator for Rng {

src/rtc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,4 +783,14 @@ impl Rtc {
783783
// We're allowed to change this once after the LSE fails
784784
self.prec.kernel_clk_mux(backup::RtcClkSel::LSI);
785785
}
786+
787+
/// Returns a reference to the inner peripheral
788+
pub fn inner(&self) -> &RTC {
789+
&self.reg
790+
}
791+
792+
/// Returns a mutable reference to the inner peripheral
793+
pub fn inner_mut(&mut self) -> &mut RTC {
794+
&mut self.reg
795+
}
786796
}

src/sdmmc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,16 @@ impl<S> Sdmmc<S> {
391391
_ => Err(Error::BadClock),
392392
}
393393
}
394+
395+
/// Returns a reference to the inner peripheral
396+
pub fn inner(&self) -> &S {
397+
&self.sdmmc
398+
}
399+
400+
/// Returns a mutable reference to the inner peripheral
401+
pub fn inner_mut(&mut self) -> &mut S {
402+
&mut self.sdmmc
403+
}
394404
}
395405

396406
macro_rules! sdmmc {

src/serial.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,16 @@ macro_rules! usart {
711711

712712
self.usart
713713
}
714+
715+
/// Returns a reference to the inner peripheral
716+
pub fn inner(&self) -> &$USARTX {
717+
&self.usart
718+
}
719+
720+
/// Returns a mutable reference to the inner peripheral
721+
pub fn inner_mut(&mut self) -> &mut $USARTX {
722+
&mut self.usart
723+
}
714724
}
715725

716726
impl SerialExt<$USARTX> for $USARTX {

0 commit comments

Comments
 (0)