summaryrefslogtreecommitdiff
path: root/embassy-stm32
diff options
context:
space:
mode:
authorchemicstry <chemicstry@gmail.com>2022-08-09 22:13:35 +0300
committerchemicstry <chemicstry@gmail.com>2022-08-09 22:13:35 +0300
commit6498324b58dd287d252482aaf377ad7e0b8c778b (patch)
treeae3e335e6007eecba9cb716db6067550d10f786a /embassy-stm32
parentb7b4c84067e0e85fa641a540458438297176f2e4 (diff)
downloadembassy-6498324b58dd287d252482aaf377ad7e0b8c778b.zip
Implement I2C pullup configuration
Diffstat (limited to 'embassy-stm32')
-rw-r--r--embassy-stm32/src/gpio.rs8
-rw-r--r--embassy-stm32/src/i2c/v1.rs23
-rw-r--r--embassy-stm32/src/i2c/v2.rs23
3 files changed, 46 insertions, 8 deletions
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index 3c4cdb88..d794e398 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -213,7 +213,7 @@ impl<'d, T: Pin> Drop for Flex<'d, T> {
}
/// Pull setting for an input.
-#[derive(Debug, Eq, PartialEq)]
+#[derive(Debug, Eq, PartialEq, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Pull {
None,
@@ -235,7 +235,7 @@ impl From<Pull> for vals::Pupdr {
}
/// Speed settings
-#[derive(Debug)]
+#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Speed {
Low,
@@ -303,7 +303,7 @@ impl<'d, T: Pin> Input<'d, T> {
}
/// Digital input or output level.
-#[derive(Debug, Eq, PartialEq)]
+#[derive(Debug, Eq, PartialEq, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Level {
Low,
@@ -470,7 +470,7 @@ pub(crate) mod sealed {
use super::*;
/// Alternate function type settings
- #[derive(Debug)]
+ #[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum AFType {
Input,
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs
index 613815a9..5b3eb2f8 100644
--- a/embassy-stm32/src/i2c/v1.rs
+++ b/embassy-stm32/src/i2c/v1.rs
@@ -4,11 +4,24 @@ use embassy_embedded_hal::SetConfig;
use embassy_hal_common::into_ref;
use crate::gpio::sealed::AFType;
+use crate::gpio::Pull;
use crate::i2c::{Error, Instance, SclPin, SdaPin};
use crate::pac::i2c;
use crate::time::Hertz;
use crate::Peripheral;
+#[non_exhaustive]
+#[derive(Copy, Clone)]
+pub struct Config {
+ pullup_enable: bool,
+}
+
+impl Default for Config {
+ fn default() -> Self {
+ Self { pullup_enable: true }
+ }
+}
+
pub struct State {}
impl State {
@@ -27,15 +40,21 @@ impl<'d, T: Instance> I2c<'d, T> {
scl: impl Peripheral<P = impl SclPin<T>> + 'd,
sda: impl Peripheral<P = impl SdaPin<T>> + 'd,
freq: Hertz,
+ config: Config,
) -> Self {
into_ref!(scl, sda);
T::enable();
T::reset();
+ let pull = match config.pullup_enable {
+ true => Pull::Up,
+ false => Pull::None,
+ };
+
unsafe {
- scl.set_as_af(scl.af_num(), AFType::OutputOpenDrain);
- sda.set_as_af(sda.af_num(), AFType::OutputOpenDrain);
+ scl.set_as_af_pull(scl.af_num(), AFType::OutputOpenDrain, pull);
+ sda.set_as_af_pull(sda.af_num(), AFType::OutputOpenDrain, pull);
}
unsafe {
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs
index f8067e8b..7c1033e0 100644
--- a/embassy-stm32/src/i2c/v2.rs
+++ b/embassy-stm32/src/i2c/v2.rs
@@ -10,12 +10,25 @@ use futures::future::poll_fn;
use crate::dma::NoDma;
use crate::gpio::sealed::AFType;
+use crate::gpio::Pull;
use crate::i2c::{Error, Instance, SclPin, SdaPin};
use crate::interrupt::InterruptExt;
use crate::pac::i2c;
use crate::time::Hertz;
use crate::Peripheral;
+#[non_exhaustive]
+#[derive(Copy, Clone)]
+pub struct Config {
+ pullup_enable: bool,
+}
+
+impl Default for Config {
+ fn default() -> Self {
+ Self { pullup_enable: true }
+ }
+}
+
pub struct State {
waker: AtomicWaker,
chunks_transferred: AtomicUsize,
@@ -46,15 +59,21 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
tx_dma: impl Peripheral<P = TXDMA> + 'd,
rx_dma: impl Peripheral<P = RXDMA> + 'd,
freq: Hertz,
+ config: Config,
) -> Self {
into_ref!(peri, irq, scl, sda, tx_dma, rx_dma);
T::enable();
T::reset();
+ let pull = match config.pullup_enable {
+ true => Pull::Up,
+ false => Pull::None,
+ };
+
unsafe {
- scl.set_as_af(scl.af_num(), AFType::OutputOpenDrain);
- sda.set_as_af(sda.af_num(), AFType::OutputOpenDrain);
+ scl.set_as_af_pull(scl.af_num(), AFType::OutputOpenDrain, pull);
+ sda.set_as_af_pull(sda.af_num(), AFType::OutputOpenDrain, pull);
}
unsafe {