diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index c108a0a8..d2da8c31 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs @@ -17,8 +17,9 @@ pub enum Error { pub(crate) mod sealed { use crate::gpio::Pin; + use crate::rcc::RccPeripheral; - pub trait Instance { + pub trait Instance: RccPeripheral { fn regs() -> &'static crate::pac::i2c::I2c; } diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index 91bc37db..62435e8a 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs @@ -22,13 +22,14 @@ impl<'d, T: Instance> I2c<'d, T> { _peri: impl Unborrow + 'd, scl: impl Unborrow>, sda: impl Unborrow>, - freq: F, ) -> Self where F: Into, { unborrow!(scl, sda); + T::enable(); + unsafe { Self::configure_pin(scl.block(), scl.pin() as _, scl.af_num()); Self::configure_pin(sda.block(), sda.pin() as _, sda.af_num()); @@ -41,7 +42,7 @@ impl<'d, T: Instance> I2c<'d, T> { }); } - let timings = Timings::new(pclk, freq.into()); + let timings = Timings::new(pclk, T::frequency().into()); unsafe { T::regs().cr2().modify(|reg| { diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index 03ad29f1..7747857b 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs @@ -22,13 +22,14 @@ impl<'d, T: Instance> I2c<'d, T> { _peri: impl Unborrow + 'd, scl: impl Unborrow>, sda: impl Unborrow>, - freq: F, ) -> Self where F: Into, { unborrow!(scl, sda); + T::enable(); + unsafe { Self::configure_pin(scl.block(), scl.pin() as _, scl.af_num()); Self::configure_pin(sda.block(), sda.pin() as _, sda.af_num()); @@ -41,7 +42,7 @@ impl<'d, T: Instance> I2c<'d, T> { }); } - let timings = Timings::new(pclk, freq.into()); + let timings = Timings::new(pclk, T::frequency().into()); unsafe { T::regs().timingr().write(|reg| { diff --git a/stm32-data b/stm32-data index 0877c27c..d7caa63b 160000 --- a/stm32-data +++ b/stm32-data @@ -1 +1 @@ -Subproject commit 0877c27cb1332237e65d74700b7bfb768996ca66 +Subproject commit d7caa63b0091f38af6657ec86b868bfa2e8a7b56