Make sda/scl pullups separate as in nRF HAL

This commit is contained in:
chemicstry 2022-08-10 12:36:15 +03:00
parent 6498324b58
commit 936473b68a
2 changed files with 44 additions and 18 deletions

View File

@ -13,12 +13,16 @@ use crate::Peripheral;
#[non_exhaustive] #[non_exhaustive]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct Config { pub struct Config {
pullup_enable: bool, pub sda_pullup: bool,
pub scl_pullup: bool,
} }
impl Default for Config { impl Default for Config {
fn default() -> Self { fn default() -> Self {
Self { pullup_enable: true } Self {
sda_pullup: false,
scl_pullup: false,
}
} }
} }
@ -47,14 +51,23 @@ impl<'d, T: Instance> I2c<'d, T> {
T::enable(); T::enable();
T::reset(); T::reset();
let pull = match config.pullup_enable {
true => Pull::Up,
false => Pull::None,
};
unsafe { unsafe {
scl.set_as_af_pull(scl.af_num(), AFType::OutputOpenDrain, pull); scl.set_as_af_pull(
sda.set_as_af_pull(sda.af_num(), AFType::OutputOpenDrain, pull); scl.af_num(),
AFType::OutputOpenDrain,
match config.scl_pullup {
true => Pull::Up,
false => Pull::None,
},
);
sda.set_as_af_pull(
sda.af_num(),
AFType::OutputOpenDrain,
match config.sda_pullup {
true => Pull::Up,
false => Pull::None,
},
);
} }
unsafe { unsafe {

View File

@ -20,12 +20,16 @@ use crate::Peripheral;
#[non_exhaustive] #[non_exhaustive]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct Config { pub struct Config {
pullup_enable: bool, pub sda_pullup: bool,
pub scl_pullup: bool,
} }
impl Default for Config { impl Default for Config {
fn default() -> Self { fn default() -> Self {
Self { pullup_enable: true } Self {
sda_pullup: false,
scl_pullup: false,
}
} }
} }
@ -66,14 +70,23 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
T::enable(); T::enable();
T::reset(); T::reset();
let pull = match config.pullup_enable {
true => Pull::Up,
false => Pull::None,
};
unsafe { unsafe {
scl.set_as_af_pull(scl.af_num(), AFType::OutputOpenDrain, pull); scl.set_as_af_pull(
sda.set_as_af_pull(sda.af_num(), AFType::OutputOpenDrain, pull); scl.af_num(),
AFType::OutputOpenDrain,
match config.scl_pullup {
true => Pull::Up,
false => Pull::None,
},
);
sda.set_as_af_pull(
sda.af_num(),
AFType::OutputOpenDrain,
match config.sda_pullup {
true => Pull::Up,
false => Pull::None,
},
);
} }
unsafe { unsafe {