Skip to content

Commit 97024cc

Browse files
committed
RealI2sClock
1 parent 00ab3cc commit 97024cc

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

src/rcc/f4/mod.rs

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,9 @@ impl CFGR {
869869
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
870870
i2s_clk: plls.i2s.i2s_clk.map(Hertz::from_raw),
871871
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
872-
i2s_apb1_clk: plls.i2s.i2s_apb1_clk.map(Hertz::from_raw),
872+
i2s_apb1_clk: plls.i2s.apb1.i2s_clk.map(Hertz::from_raw),
873873
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
874-
i2s_apb2_clk: plls.i2s.i2s_apb2_clk.map(Hertz::from_raw),
874+
i2s_apb2_clk: plls.i2s.apb2.i2s_clk.map(Hertz::from_raw),
875875

876876
#[cfg(feature = "sai")]
877877
#[cfg(not(feature = "sai2"))]
@@ -929,51 +929,53 @@ struct I2sClocks {
929929
}
930930

931931
impl I2sClocks {
932-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
933932
fn real(&self, pll_i2s_clk: Option<u32>, i2s_ckin: Option<u32>) -> RealI2sClocks {
934-
RealI2sClocks {
935-
i2s_apb1_ext: self.i2s_apb1_ext,
936-
i2s_apb2_ext: self.i2s_apb2_ext,
937-
i2s_apb1_clk: if self.i2s_apb1_ext {
938-
i2s_ckin
939-
} else {
940-
pll_i2s_clk
933+
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
934+
let clk = RealI2sClocks {
935+
apb1: RealI2sClock {
936+
i2s_ext: self.i2s_apb1_ext,
937+
i2s_clk: if self.i2s_apb1_ext {
938+
i2s_ckin
939+
} else {
940+
pll_i2s_clk
941+
},
941942
},
942-
i2s_apb2_clk: if self.i2s_apb2_ext {
943-
i2s_ckin
944-
} else {
945-
pll_i2s_clk
943+
apb2: RealI2sClock {
944+
i2s_ext: self.i2s_apb2_ext,
945+
i2s_clk: if self.i2s_apb2_ext {
946+
i2s_ckin
947+
} else {
948+
pll_i2s_clk
949+
},
946950
},
947-
}
948-
}
949-
950-
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
951-
fn real(&self, pll_i2s_clk: Option<u32>, i2s_ckin: Option<u32>) -> RealI2sClocks {
952-
RealI2sClocks {
951+
};
952+
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
953+
let clk = RealI2sClocks {
953954
i2s_ext: self.i2s_ext,
954955
i2s_clk: if self.i2s_ext { i2s_ckin } else { pll_i2s_clk },
955-
}
956+
};
957+
clk
956958
}
957959
}
958960

959-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
960961
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
961962
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
962-
struct RealI2sClocks {
963-
i2s_apb1_ext: bool,
964-
i2s_apb2_ext: bool,
965-
i2s_apb1_clk: Option<u32>,
966-
i2s_apb2_clk: Option<u32>,
963+
struct RealI2sClock {
964+
i2s_ext: bool,
965+
i2s_clk: Option<u32>,
967966
}
968967

969-
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
968+
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
970969
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
971970
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
972971
struct RealI2sClocks {
973-
i2s_ext: bool,
974-
i2s_clk: Option<u32>,
972+
apb1: RealI2sClock,
973+
apb2: RealI2sClock,
975974
}
976975

976+
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
977+
use RealI2sClock as RealI2sClocks;
978+
977979
impl RealI2sClocks {
978980
fn config_clocksel(&self) {
979981
let rcc = unsafe { &*RCC::ptr() };
@@ -1001,12 +1003,12 @@ impl RealI2sClocks {
10011003
});
10021004
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
10031005
rcc.dckcfgr().modify(|_, w| {
1004-
if self.i2s_apb1_ext {
1006+
if self.apb1.i2s_ext {
10051007
w.i2s1src().i2s_ckin()
10061008
} else {
10071009
w.i2s1src().plli2sr()
10081010
};
1009-
if self.i2s_apb2_ext {
1011+
if self.apb2.i2s_ext {
10101012
w.i2s2src().i2s_ckin()
10111013
} else {
10121014
w.i2s2src().plli2sr()

0 commit comments

Comments
 (0)