Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/thirdpin/libopencm3.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKarl Palsson <karlp@tweak.net.au>2017-10-27 00:54:30 +0300
committerKarl Palsson <karlp@etactica.com>2018-01-08 14:16:24 +0300
commited90df85f089d260fc598cb200b5d36678045ec0 (patch)
treed82f4723485615cd8f0a5f8c15b6bf64f0c9c638 /lib
parent965d28ecbec5df5b77f7a93222e0eb8d79c4c79c (diff)
stm32:i2c-v2: Clarify digital filter setting
Drop redundant field definitions, fix truncation of argument bug and add documentation. Fixes: https://github.com/libopencm3/libopencm3/issues/831
Diffstat (limited to 'lib')
-rw-r--r--lib/stm32/common/i2c_common_v2.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/stm32/common/i2c_common_v2.c b/lib/stm32/common/i2c_common_v2.c
index 2116064f..04ae7623 100644
--- a/lib/stm32/common/i2c_common_v2.c
+++ b/lib/stm32/common/i2c_common_v2.c
@@ -188,9 +188,18 @@ void i2c_disable_analog_filter(uint32_t i2c)
I2C_CR1(i2c) |= I2C_CR1_ANFOFF;
}
+/**
+ * Set the I2C digital filter.
+ * These bits are used to configure the digital noise filter on SDA and
+ * SCL input. The digital filter will filter spikes with a length of up
+ * to dnf_setting * I2CCLK clocks
+ * @param i2c peripheral of interest
+ * @param dnf_setting 0 to disable, else 1..15 i2c clocks
+ */
void i2c_set_digital_filter(uint32_t i2c, uint8_t dnf_setting)
{
- I2C_CR1(i2c) = (I2C_CR1(i2c) & ~I2C_CR1_DNF_MASK) | dnf_setting;
+ I2C_CR1(i2c) = (I2C_CR1(i2c) & ~(I2C_CR1_DNF_MASK << I2C_CR1_DNF_SHIFT)) |
+ (dnf_setting << I2C_CR1_DNF_SHIFT);
}
/* t_presc= (presc+1)*t_i2cclk */