aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchemicstry <[email protected]>2022-08-10 12:36:15 +0300
committerchemicstry <[email protected]>2022-08-10 12:36:15 +0300
commit936473b68adb3a526846ff30233936dc3c52de25 (patch)
tree5a99772e9d0931a349f39e0b0ce59cc7cb5a8f17
parent6498324b58dd287d252482aaf377ad7e0b8c778b (diff)
Make sda/scl pullups separate as in nRF HAL
-rw-r--r--embassy-stm32/src/i2c/v1.rs31
-rw-r--r--embassy-stm32/src/i2c/v2.rs31
2 files changed, 44 insertions, 18 deletions
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs
index 5b3eb2f81..9dc75789a 100644
--- a/embassy-stm32/src/i2c/v1.rs
+++ b/embassy-stm32/src/i2c/v1.rs
@@ -13,12 +13,16 @@ use crate::Peripheral;
13#[non_exhaustive] 13#[non_exhaustive]
14#[derive(Copy, Clone)] 14#[derive(Copy, Clone)]
15pub struct Config { 15pub struct Config {
16 pullup_enable: bool, 16 pub sda_pullup: bool,
17 pub scl_pullup: bool,
17} 18}
18 19
19impl Default for Config { 20impl Default for Config {
20 fn default() -> Self { 21 fn default() -> Self {
21 Self { pullup_enable: true } 22 Self {
23 sda_pullup: false,
24 scl_pullup: false,
25 }
22 } 26 }
23} 27}
24 28
@@ -47,14 +51,23 @@ impl<'d, T: Instance> I2c<'d, T> {
47 T::enable(); 51 T::enable();
48 T::reset(); 52 T::reset();
49 53
50 let pull = match config.pullup_enable {
51 true => Pull::Up,
52 false => Pull::None,
53 };
54
55 unsafe { 54 unsafe {
56 scl.set_as_af_pull(scl.af_num(), AFType::OutputOpenDrain, pull); 55 scl.set_as_af_pull(
57 sda.set_as_af_pull(sda.af_num(), AFType::OutputOpenDrain, pull); 56 scl.af_num(),
57 AFType::OutputOpenDrain,
58 match config.scl_pullup {
59 true => Pull::Up,
60 false => Pull::None,
61 },
62 );
63 sda.set_as_af_pull(
64 sda.af_num(),
65 AFType::OutputOpenDrain,
66 match config.sda_pullup {
67 true => Pull::Up,
68 false => Pull::None,
69 },
70 );
58 } 71 }
59 72
60 unsafe { 73 unsafe {
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs
index 7c1033e0b..b4303d3d4 100644
--- a/embassy-stm32/src/i2c/v2.rs
+++ b/embassy-stm32/src/i2c/v2.rs
@@ -20,12 +20,16 @@ use crate::Peripheral;
20#[non_exhaustive] 20#[non_exhaustive]
21#[derive(Copy, Clone)] 21#[derive(Copy, Clone)]
22pub struct Config { 22pub struct Config {
23 pullup_enable: bool, 23 pub sda_pullup: bool,
24 pub scl_pullup: bool,
24} 25}
25 26
26impl Default for Config { 27impl Default for Config {
27 fn default() -> Self { 28 fn default() -> Self {
28 Self { pullup_enable: true } 29 Self {
30 sda_pullup: false,
31 scl_pullup: false,
32 }
29 } 33 }
30} 34}
31 35
@@ -66,14 +70,23 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
66 T::enable(); 70 T::enable();
67 T::reset(); 71 T::reset();
68 72
69 let pull = match config.pullup_enable {
70 true => Pull::Up,
71 false => Pull::None,
72 };
73
74 unsafe { 73 unsafe {
75 scl.set_as_af_pull(scl.af_num(), AFType::OutputOpenDrain, pull); 74 scl.set_as_af_pull(
76 sda.set_as_af_pull(sda.af_num(), AFType::OutputOpenDrain, pull); 75 scl.af_num(),
76 AFType::OutputOpenDrain,
77 match config.scl_pullup {
78 true => Pull::Up,
79 false => Pull::None,
80 },
81 );
82 sda.set_as_af_pull(
83 sda.af_num(),
84 AFType::OutputOpenDrain,
85 match config.sda_pullup {
86 true => Pull::Up,
87 false => Pull::None,
88 },
89 );
77 } 90 }
78 91
79 unsafe { 92 unsafe {