From 936473b68adb3a526846ff30233936dc3c52de25 Mon Sep 17 00:00:00 2001 From: chemicstry Date: Wed, 10 Aug 2022 12:36:15 +0300 Subject: [PATCH] Make sda/scl pullups separate as in nRF HAL --- embassy-stm32/src/i2c/v1.rs | 31 ++++++++++++++++++++++--------- embassy-stm32/src/i2c/v2.rs | 31 ++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index 5b3eb2f8..9dc75789 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs @@ -13,12 +13,16 @@ use crate::Peripheral; #[non_exhaustive] #[derive(Copy, Clone)] pub struct Config { - pullup_enable: bool, + pub sda_pullup: bool, + pub scl_pullup: bool, } impl Default for Config { 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::reset(); - let pull = match config.pullup_enable { - true => Pull::Up, - false => Pull::None, - }; - unsafe { - scl.set_as_af_pull(scl.af_num(), AFType::OutputOpenDrain, pull); - sda.set_as_af_pull(sda.af_num(), AFType::OutputOpenDrain, pull); + scl.set_as_af_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 { diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index 7c1033e0..b4303d3d 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs @@ -20,12 +20,16 @@ use crate::Peripheral; #[non_exhaustive] #[derive(Copy, Clone)] pub struct Config { - pullup_enable: bool, + pub sda_pullup: bool, + pub scl_pullup: bool, } impl Default for Config { 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::reset(); - let pull = match config.pullup_enable { - true => Pull::Up, - false => Pull::None, - }; - unsafe { - scl.set_as_af_pull(scl.af_num(), AFType::OutputOpenDrain, pull); - sda.set_as_af_pull(sda.af_num(), AFType::OutputOpenDrain, pull); + scl.set_as_af_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 {