Skip to content

Commit 6b26f84

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 4ebb5c1 commit 6b26f84

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
@@ -858,6 +858,16 @@ macro_rules! adc_hal {
858858
panic!("Cannot read linear calibration value when the ADC is disabled");
859859
}
860860
}
861+
862+
/// Returns a reference to the inner peripheral
863+
pub fn inner(&self) -> &$ADC {
864+
&self.rb
865+
}
866+
867+
/// Returns a mutable reference to the inner peripheral
868+
pub fn inner_mut(&mut self) -> &mut $ADC {
869+
&mut self.rb
870+
}
861871
}
862872

863873
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
@@ -346,6 +346,11 @@ macro_rules! i2c {
346346
&self.i2c
347347
}
348348

349+
/// Returns a mutable reference to the inner peripheral
350+
pub fn inner_mut(&mut self) -> &mut $I2CX {
351+
&mut self.i2c
352+
}
353+
349354
/// Enable or disable the DMA mode for reception
350355
pub fn rx_dma(&mut self, enable: bool) {
351356
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
@@ -294,6 +294,16 @@ impl Pwr {
294294
});
295295
while d3cr!(self.rb).read().vosrdy().bit_is_clear() {}
296296
}
297+
298+
/// Returns a reference to the inner peripheral
299+
pub fn inner(&self) -> &PWR {
300+
&self.rb
301+
}
302+
303+
/// Returns a mutable reference to the inner peripheral
304+
pub fn inner_mut(&mut self) -> &mut PWR {
305+
&mut self.rb
306+
}
297307
}
298308

299309
/// Builder methods

src/rng.rs

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

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

src/rtc.rs

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

src/sdmmc.rs

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

398408
macro_rules! sdmmc {

src/serial.rs

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

715715
self.usart
716716
}
717+
718+
/// Returns a reference to the inner peripheral
719+
pub fn inner(&self) -> &$USARTX {
720+
&self.usart
721+
}
722+
723+
/// Returns a mutable reference to the inner peripheral
724+
pub fn inner_mut(&mut self) -> &mut $USARTX {
725+
&mut self.usart
726+
}
717727
}
718728

719729
impl SerialExt<$USARTX> for $USARTX {

0 commit comments

Comments
 (0)