pub struct Mpr121<I2C: I2c> { /* private fields */ }
Expand description
I2C connected Mpr121. Use either new_default or new to create a new instance.
If you want to collect the I²C bus upon drop, use free, which deconstructs Self
.
Implementations§
Source§impl<I2C: I2c> Mpr121<I2C>
impl<I2C: I2c> Mpr121<I2C>
Sourcepub fn new(
i2c: I2C,
addr: Mpr121Address,
use_auto_config: bool,
check_reset_flags: bool,
) -> Result<Self, Mpr121Error>
pub fn new( i2c: I2C, addr: Mpr121Address, use_auto_config: bool, check_reset_flags: bool, ) -> Result<Self, Mpr121Error>
Creates the driver for the given I²C ports. Assumes that the I²C port is configured as master.
If use_auto_config
is set, the controller will use its auto configuration routine to setup
charging parameters whenever it is transitioned from STOP to START mode.
Note that we use the same default values as the Adafruit implementation, except for threshold values. Use set_thresholds to define those.
Sourcepub fn new_default(i2c: I2C) -> Result<Self, Mpr121Error>
pub fn new_default(i2c: I2C) -> Result<Self, Mpr121Error>
Sourcepub fn set_thresholds(&mut self, touch: u8, release: u8)
pub fn set_thresholds(&mut self, touch: u8, release: u8)
Set the touch and release threshold for all channels. Usually the touch threshold is a little bigger than the release threshold. This creates some debounce characteristics. The correct thresholds depend on the application.
Have a look at note AN3892 of the mpr121 guidelines.
Sourcepub fn set_debounce(&mut self, debounce_count: u8)
pub fn set_debounce(&mut self, debounce_count: u8)
Sets the count for both touch and release. See 5.7 of the data sheet.
value must be 0..8, is clamped if it exceeds.
Sourcepub fn get_filtered(&mut self, channel: u8) -> Result<u16, Mpr121Error>
pub fn get_filtered(&mut self, channel: u8) -> Result<u16, Mpr121Error>
Reads the filtered data form channel t. Noise gets filtered out by the chip. See 5.3 in the data sheet.
Note that the resulting value is only 10bit wide.
Note that 0 is returned, if channel > 12
.
Sourcepub fn get_baseline(&mut self, channel: u8) -> Result<u8, Mpr121Error>
pub fn get_baseline(&mut self, channel: u8) -> Result<u8, Mpr121Error>
Reads the baseline data for the channel. Note that this has only a resolution of 8bit.
Note that 0 is returned, if channel > 12
, or reading failed
Sourcepub fn get_touched(&mut self) -> Result<u16, Mpr121Error>
pub fn get_touched(&mut self) -> Result<u16, Mpr121Error>
Reads the touched state of all channels. Returns a u16 where each bit 0..12 indicates whether the pin is touched or not. Use bit shifting / masking to generate a mask, or, if only one sensor’s value is needed, use get_touch_state.
Returns 0 if reading failed.
Sourcepub fn get_sensor_touch(&mut self, channel: u8) -> bool
pub fn get_sensor_touch(&mut self, channel: u8) -> bool
Returns the touch state of the given sensor.
Returns false if channel>11
, or reading failed.