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
This commit is contained in:
Karl Palsson
2017-10-26 21:54:30 +00:00
committed by Karl Palsson
parent 965d28ecbe
commit ed90df85f0
2 changed files with 13 additions and 19 deletions

View File

@@ -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 */