Struct mpr121_hal::Mpr121Busless
source · Expand description
Implementations
sourceimpl<I2C: Write + WriteRead> Mpr121Busless<I2C>
impl<I2C: Write + WriteRead> Mpr121Busless<I2C>
pub const DEFAULT_TOUCH_THRESHOLD: u8 = 12u8
pub const DEFAULT_RELEASE_THRESOLD: u8 = 6u8
sourcepub fn new(
i2c: &mut I2C,
addr: Mpr121Address,
use_auto_config: bool
) -> Result<Self, Mpr121Error>
pub fn new(
i2c: &mut I2C,
addr: Mpr121Address,
use_auto_config: 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: &mut I2C) -> Result<Self, Mpr121Error>
pub fn new_default(i2c: &mut I2C) -> Result<Self, Mpr121Error>
sourcepub fn set_thresholds(&self, i2c: &mut I2C, touch: u8, release: u8)
pub fn set_thresholds(&self, i2c: &mut I2C, 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(&self, i2c: &mut I2C, debounce_count: u8)
pub fn set_debounce(&self, i2c: &mut I2C, 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(&self, i2c: &mut I2C, channel: u8) -> Result<u16, Mpr121Error>
pub fn get_filtered(&self, i2c: &mut I2C, 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(&self, i2c: &mut I2C, channel: u8) -> Result<u8, Mpr121Error>
pub fn get_baseline(&self, i2c: &mut I2C, 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(&self, i2c: &mut I2C) -> Result<u16, Mpr121Error>
pub fn get_touched(&self, i2c: &mut I2C) -> 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(&self, i2c: &mut I2C, channel: u8) -> bool
pub fn get_sensor_touch(&self, i2c: &mut I2C, channel: u8) -> bool
Returns the touch state of the given sensor.
Returns false if channel>11, or reading failed.