Struct Mpr121

Source
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>

Source

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.

Source

pub fn new_default(i2c: I2C) -> Result<Self, Mpr121Error>

Initializes the driver assuming the sensors address is the default one (0x5a). If this fails, consider searching for the driver. Or following the documentation on setting a driver address, and use new to specify the address.

Have a look at new for further documentation.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

pub fn free(self) -> I2C

Consumes self and releases the i2c bus that is used.

Auto Trait Implementations§

§

impl<I2C> Freeze for Mpr121<I2C>
where I2C: Freeze,

§

impl<I2C> RefUnwindSafe for Mpr121<I2C>
where I2C: RefUnwindSafe,

§

impl<I2C> Send for Mpr121<I2C>
where I2C: Send,

§

impl<I2C> Sync for Mpr121<I2C>
where I2C: Sync,

§

impl<I2C> Unpin for Mpr121<I2C>
where I2C: Unpin,

§

impl<I2C> UnwindSafe for Mpr121<I2C>
where I2C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.