Skip to content

Commit ae12718

Browse files
authored
Merge pull request #299 from burrbull/rcc_enable
rcc enable/reset
2 parents c5697aa + b1e88e9 commit ae12718

File tree

15 files changed

+348
-256
lines changed

15 files changed

+348
-256
lines changed

src/adc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{
1919
adc1_2::ccr::CKMODE_A,
2020
ADC1, ADC1_2, ADC2,
2121
},
22-
rcc::{Clocks, AHB},
22+
rcc::{Clocks, Enable, AHB},
2323
};
2424

2525
#[cfg(any(
@@ -555,10 +555,10 @@ macro_rules! adc12_hal {
555555
/// the clock can be enabled with the given settings
556556
/// or the clock was already enabled with the same settings
557557
fn enable_clock(&self, ahb: &mut AHB, adc_common: &mut ADC1_2) -> bool {
558-
if ahb.enr().read().adc12en().is_enabled() {
558+
if ADC1_2::is_enabled() {
559559
return (adc_common.ccr.read().ckmode().variant() == self.clock_mode.into());
560560
}
561-
ahb.enr().modify(|_, w| w.adc12en().enabled());
561+
ADC1_2::enable(ahb);
562562
adc_common.ccr.modify(|_, w| w
563563
.ckmode().variant(self.clock_mode.into())
564564
);
@@ -585,10 +585,10 @@ macro_rules! adc34_hal {
585585
/// the clock can be enabled with the given settings
586586
/// or the clock was already enabled with the same settings
587587
fn enable_clock(&self, ahb: &mut AHB, adc_common: &mut ADC3_4) -> bool {
588-
if ahb.enr().read().adc34en().is_enabled() {
588+
if ADC3_4::is_enabled() {
589589
return (adc_common.ccr.read().ckmode().variant() == self.clock_mode.into());
590590
}
591-
ahb.enr().modify(|_, w| w.adc34en().enabled());
591+
ADC3_4::enable(ahb);
592592
adc_common.ccr.modify(|_, w| w
593593
.ckmode().variant(self.clock_mode.into())
594594
);

src/can.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::gpio::{gpioa, gpiob};
1515
use crate::gpio::{PushPull, AF9};
1616
use crate::pac;
1717

18-
use crate::rcc::APB1;
18+
use crate::rcc::{Enable, Reset, APB1};
1919

2020
pub use bxcan;
2121
use bxcan::RegisterBlock;
@@ -62,9 +62,8 @@ where
6262
/// before the peripheral can be enabled.
6363
/// See the CAN example, for a more thorough example of the full setup process.
6464
pub fn new(can: pac::CAN, tx: Tx, rx: Rx, apb1: &mut APB1) -> bxcan::Can<Self> {
65-
apb1.enr().modify(|_, w| w.canen().enabled());
66-
apb1.rstr().modify(|_, w| w.canrst().set_bit());
67-
apb1.rstr().modify(|_, w| w.canrst().clear_bit());
65+
pac::CAN::enable(apb1);
66+
pac::CAN::reset(apb1);
6867

6968
bxcan::Can::builder(Can { can, tx, rx }).enable()
7069
}

src/dma.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,13 @@ macro_rules! dma {
446446
pub mod $dmax {
447447
use super::*;
448448
use crate::pac::$DMAx;
449+
use crate::rcc::Enable;
449450

450451
impl DmaExt for $DMAx {
451452
type Channels = Channels;
452453

453454
fn split(self, ahb: &mut AHB) -> Channels {
454-
ahb.enr().modify(|_, w| w.$dmaxen().set_bit());
455+
<$DMAx>::enable(ahb);
455456

456457
let mut channels = Channels {
457458
$( $chi: $Ci { _0: () }, )+

src/gpio.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,6 @@ macro_rules! gpio {
784784
Gpio: $Gpiox:ty,
785785
port_index: $port_index:literal,
786786
gpio_mapped: $gpioy:ident,
787-
iopen: $iopxen:ident,
788-
ioprst: $iopxrst:ident,
789787
partially_erased_pin: $PXx:ident,
790788
pins: [$(
791789
$i:literal => (
@@ -842,7 +840,7 @@ macro_rules! gpio {
842840

843841
use crate::{
844842
pac::{$gpioy, $GPIOX},
845-
rcc::AHB,
843+
rcc::{AHB, Enable, Reset},
846844
};
847845

848846
use super::{Afr, $Gpiox, GpioExt, Moder, Ospeedr, Otyper, Pupdr, U};
@@ -884,9 +882,8 @@ macro_rules! gpio {
884882
type Parts = Parts;
885883

886884
fn split(self, ahb: &mut AHB) -> Parts {
887-
ahb.enr().modify(|_, w| w.$iopxen().set_bit());
888-
ahb.rstr().modify(|_, w| w.$iopxrst().set_bit());
889-
ahb.rstr().modify(|_, w| w.$iopxrst().clear_bit());
885+
<$GPIOX>::enable(ahb);
886+
<$GPIOX>::reset(ahb);
890887

891888
Parts {
892889
afrh: AFRH(()),
@@ -1003,8 +1000,6 @@ macro_rules! gpio {
10031000
Gpio: [<Gpio $x>],
10041001
port_index: $port_index,
10051002
gpio_mapped: $gpioy,
1006-
iopen: [<iop $x en>],
1007-
ioprst: [<iop $x rst>],
10081003
partially_erased_pin: [<P $X x>],
10091004
pins: [$(
10101005
$i => (

src/i2c.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
gpio::{gpioa, gpiob, OpenDrain, AF4},
1313
hal::blocking::i2c::{Read, Write, WriteRead},
1414
pac::{i2c1::RegisterBlock, rcc::cfgr3::I2C1SW_A, I2C1, RCC},
15-
rcc::{Clocks, APB1},
15+
rcc::{self, Clocks},
1616
time::rate::*,
1717
};
1818

@@ -111,15 +111,22 @@ macro_rules! busy_wait {
111111

112112
impl<I2C, SCL, SDA> I2c<I2C, (SCL, SDA)> {
113113
/// Configures the I2C peripheral to work in master mode
114-
pub fn new(i2c: I2C, pins: (SCL, SDA), freq: Hertz, clocks: Clocks, apb1: &mut APB1) -> Self
114+
pub fn new(
115+
i2c: I2C,
116+
pins: (SCL, SDA),
117+
freq: Hertz,
118+
clocks: Clocks,
119+
bus: &mut <I2C as rcc::RccBus>::Bus,
120+
) -> Self
115121
where
116122
I2C: Instance,
117123
SCL: SclPin<I2C>,
118124
SDA: SdaPin<I2C>,
119125
{
120126
crate::assert!(freq.integer() <= 1_000_000);
121127

122-
I2C::enable_clock(apb1);
128+
I2C::enable(bus);
129+
I2C::reset(bus);
123130

124131
// TODO review compliance with the timing requirements of I2C
125132
// t_I2CCLK = 1 / PCLK1
@@ -441,24 +448,17 @@ where
441448
}
442449

443450
/// I2C instance
444-
pub trait Instance: Deref<Target = RegisterBlock> + crate::private::Sealed {
445-
#[doc(hidden)]
446-
fn enable_clock(apb1: &mut APB1);
451+
pub trait Instance:
452+
Deref<Target = RegisterBlock> + crate::private::Sealed + rcc::Enable + rcc::Reset
453+
{
447454
#[doc(hidden)]
448455
fn clock(clocks: &Clocks) -> Hertz;
449456
}
450457

451458
macro_rules! i2c {
452-
($($I2CX:ident: ($i2cXen:ident, $i2cXrst:ident, $i2cXsw:ident),)+) => {
459+
($($I2CX:ident: ($i2cXsw:ident),)+) => {
453460
$(
454-
impl crate::private::Sealed for $I2CX {}
455461
impl Instance for $I2CX {
456-
fn enable_clock(apb1: &mut APB1) {
457-
apb1.enr().modify(|_, w| w.$i2cXen().enabled());
458-
apb1.rstr().modify(|_, w| w.$i2cXrst().reset());
459-
apb1.rstr().modify(|_, w| w.$i2cXrst().clear_bit());
460-
}
461-
462462
fn clock(clocks: &Clocks) -> Hertz {
463463
// NOTE(unsafe) atomic read with no side effects
464464
match unsafe { (*RCC::ptr()).cfgr3.read().$i2cXsw().variant() } {
@@ -473,7 +473,7 @@ macro_rules! i2c {
473473
([ $($X:literal),+ ]) => {
474474
paste::paste! {
475475
i2c!(
476-
$([<I2C $X>]: ([<i2c $X en>], [<i2c $X rst>], [<i2c $X sw>]),)+
476+
$([<I2C $X>]: ([<i2c $X sw>]),)+
477477
);
478478
}
479479
};

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ mod private {
142142
pub(crate) use modify_at;
143143
}
144144

145-
pub(crate) use private::modify_at;
145+
pub(crate) use private::{modify_at, Sealed};
146146

147147
/// Peripheral access
148148
#[cfg(feature = "svd-f301")]

0 commit comments

Comments
 (0)