Remove the frequency argument for i2c, move to using RccPeripheral.
This commit is contained in:
parent
e7a4a72977
commit
9f5d35d891
4 changed files with 9 additions and 6 deletions
|
@ -17,8 +17,9 @@ pub enum Error {
|
||||||
|
|
||||||
pub(crate) mod sealed {
|
pub(crate) mod sealed {
|
||||||
use crate::gpio::Pin;
|
use crate::gpio::Pin;
|
||||||
|
use crate::rcc::RccPeripheral;
|
||||||
|
|
||||||
pub trait Instance {
|
pub trait Instance: RccPeripheral {
|
||||||
fn regs() -> &'static crate::pac::i2c::I2c;
|
fn regs() -> &'static crate::pac::i2c::I2c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,13 +22,14 @@ impl<'d, T: Instance> I2c<'d, T> {
|
||||||
_peri: impl Unborrow<Target = T> + 'd,
|
_peri: impl Unborrow<Target = T> + 'd,
|
||||||
scl: impl Unborrow<Target = impl SclPin<T>>,
|
scl: impl Unborrow<Target = impl SclPin<T>>,
|
||||||
sda: impl Unborrow<Target = impl SdaPin<T>>,
|
sda: impl Unborrow<Target = impl SdaPin<T>>,
|
||||||
freq: F,
|
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
F: Into<Hertz>,
|
F: Into<Hertz>,
|
||||||
{
|
{
|
||||||
unborrow!(scl, sda);
|
unborrow!(scl, sda);
|
||||||
|
|
||||||
|
T::enable();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
Self::configure_pin(scl.block(), scl.pin() as _, scl.af_num());
|
Self::configure_pin(scl.block(), scl.pin() as _, scl.af_num());
|
||||||
Self::configure_pin(sda.block(), sda.pin() as _, sda.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 {
|
unsafe {
|
||||||
T::regs().cr2().modify(|reg| {
|
T::regs().cr2().modify(|reg| {
|
||||||
|
|
|
@ -22,13 +22,14 @@ impl<'d, T: Instance> I2c<'d, T> {
|
||||||
_peri: impl Unborrow<Target = T> + 'd,
|
_peri: impl Unborrow<Target = T> + 'd,
|
||||||
scl: impl Unborrow<Target = impl SclPin<T>>,
|
scl: impl Unborrow<Target = impl SclPin<T>>,
|
||||||
sda: impl Unborrow<Target = impl SdaPin<T>>,
|
sda: impl Unborrow<Target = impl SdaPin<T>>,
|
||||||
freq: F,
|
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
F: Into<Hertz>,
|
F: Into<Hertz>,
|
||||||
{
|
{
|
||||||
unborrow!(scl, sda);
|
unborrow!(scl, sda);
|
||||||
|
|
||||||
|
T::enable();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
Self::configure_pin(scl.block(), scl.pin() as _, scl.af_num());
|
Self::configure_pin(scl.block(), scl.pin() as _, scl.af_num());
|
||||||
Self::configure_pin(sda.block(), sda.pin() as _, sda.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 {
|
unsafe {
|
||||||
T::regs().timingr().write(|reg| {
|
T::regs().timingr().write(|reg| {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 0877c27cb1332237e65d74700b7bfb768996ca66
|
Subproject commit d7caa63b0091f38af6657ec86b868bfa2e8a7b56
|
Loading…
Reference in a new issue