libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::Mpr121< Transport > Class Template Reference

Device support for MPR121 12x Capacitive Touch Sensor. More...

Detailed Description

template<typename Transport>
class daisy::Mpr121< Transport >

Device support for MPR121 12x Capacitive Touch Sensor.

Author
beserge
Date
December 2021

#include <mpr121.h>

Classes

struct  Config
 

Public Types

enum  Result { OK = 0 , ERR }
 
enum  RegMap {
  MPR121_TOUCHSTATUS_L = 0x00 , MPR121_TOUCHSTATUS_H = 0x01 , MPR121_FILTDATA_0L = 0x04 , MPR121_FILTDATA_0H = 0x05 ,
  MPR121_BASELINE_0 = 0x1E , MPR121_MHDR = 0x2B , MPR121_NHDR = 0x2C , MPR121_NCLR = 0x2D ,
  MPR121_FDLR = 0x2E , MPR121_MHDF = 0x2F , MPR121_NHDF = 0x30 , MPR121_NCLF = 0x31 ,
  MPR121_FDLF = 0x32 , MPR121_NHDT = 0x33 , MPR121_NCLT = 0x34 , MPR121_FDLT = 0x35 ,
  MPR121_TOUCHTH_0 = 0x41 , MPR121_RELEASETH_0 = 0x42 , MPR121_DEBOUNCE = 0x5B , MPR121_CONFIG1 = 0x5C ,
  MPR121_CONFIG2 = 0x5D , MPR121_CHARGECURR_0 = 0x5F , MPR121_CHARGETIME_1 = 0x6C , MPR121_ECR = 0x5E ,
  MPR121_AUTOCONFIG0 = 0x7B , MPR121_AUTOCONFIG1 = 0x7C , MPR121_UPLIMIT = 0x7D , MPR121_LOWLIMIT = 0x7E ,
  MPR121_TARGETLIMIT = 0x7F , MPR121_GPIODIR = 0x76 , MPR121_GPIOEN = 0x77 , MPR121_GPIOSET = 0x78 ,
  MPR121_GPIOCLR = 0x79 , MPR121_GPIOTOGGLE = 0x7A , MPR121_SOFTRESET = 0x80
}
 

Public Member Functions

 Mpr121 ()
 
 ~Mpr121 ()
 
Result Init (Config config)
 
void SetThresholds (uint8_t touch, uint8_t release)
 
uint16_t FilteredData (uint8_t t)
 
uint16_t BaselineData (uint8_t t)
 
uint16_t Touched ()
 
uint8_t ReadRegister8 (uint8_t reg)
 
uint16_t ReadRegister16 (uint8_t reg)
 
void WriteRegister (uint8_t reg, uint8_t value)
 

Member Enumeration Documentation

◆ RegMap

Device register map

Enumerator
MPR121_TOUCHSTATUS_L 
MPR121_TOUCHSTATUS_H 
MPR121_FILTDATA_0L 
MPR121_FILTDATA_0H 
MPR121_BASELINE_0 
MPR121_MHDR 
MPR121_NHDR 
MPR121_NCLR 
MPR121_FDLR 
MPR121_MHDF 
MPR121_NHDF 
MPR121_NCLF 
MPR121_FDLF 
MPR121_NHDT 
MPR121_NCLT 
MPR121_FDLT 
MPR121_TOUCHTH_0 
MPR121_RELEASETH_0 
MPR121_DEBOUNCE 
MPR121_CONFIG1 
MPR121_CONFIG2 
MPR121_CHARGECURR_0 
MPR121_CHARGETIME_1 
MPR121_ECR 
MPR121_AUTOCONFIG0 
MPR121_AUTOCONFIG1 
MPR121_UPLIMIT 
MPR121_LOWLIMIT 
MPR121_TARGETLIMIT 
MPR121_GPIODIR 
MPR121_GPIOEN 
MPR121_GPIOSET 
MPR121_GPIOCLR 
MPR121_GPIOTOGGLE 
MPR121_SOFTRESET 

◆ Result

Enumerator
OK 
ERR 

Constructor & Destructor Documentation

◆ Mpr121()

template<typename Transport >
daisy::Mpr121< Transport >::Mpr121 ( )
inline

◆ ~Mpr121()

template<typename Transport >
daisy::Mpr121< Transport >::~Mpr121 ( )
inline

Member Function Documentation

◆ BaselineData()

template<typename Transport >
uint16_t daisy::Mpr121< Transport >::BaselineData ( uint8_t  t)
inline

Read the baseline value for the channel. The 3rd level filtered result is internally 10bit but only high 8 bits are readable from registers 0x1E~0x2A as the baseline value output for each channel.

Parameters
tthe channel to read.
Returns
the baseline data that was read

◆ FilteredData()

template<typename Transport >
uint16_t daisy::Mpr121< Transport >::FilteredData ( uint8_t  t)
inline

Read the filtered data from channel t. The ADC raw data outputs run through 3 levels of digital filtering to filter out the high frequency and low frequency noise encountered. For detailed information on this filtering see page 6 of the device datasheet.

Parameters
tthe channel to read
Returns
the filtered reading as a 10 bit unsigned value

◆ Init()

template<typename Transport >
Result daisy::Mpr121< Transport >::Init ( Config  config)
inline

Initialize the MPR121 device

Parameters
configConfiguration settings

◆ ReadRegister16()

template<typename Transport >
uint16_t daisy::Mpr121< Transport >::ReadRegister16 ( uint8_t  reg)
inline

Read the contents of a 16 bit device register.

Parameters
regthe register address to read from
Returns
the 16 bit value that was read.

◆ ReadRegister8()

template<typename Transport >
uint8_t daisy::Mpr121< Transport >::ReadRegister8 ( uint8_t  reg)
inline

Read the contents of an 8 bit device register.

Parameters
regthe register address to read from
Returns
the 8 bit value that was read.

◆ SetThresholds()

template<typename Transport >
void daisy::Mpr121< Transport >::SetThresholds ( uint8_t  touch,
uint8_t  release 
)
inline

Set the touch and release thresholds for all 13 channels on the device to the passed values.

Parameters
touchThe touch threshold value from 0 to 255.
releaseThe release threshold from 0 to 255.

◆ Touched()

template<typename Transport >
uint16_t daisy::Mpr121< Transport >::Touched ( )
inline

Read the touch status of all 13 channels as bit values in a 12 bit integer.

Returns
a 12 bit integer with each bit corresponding to the touch status of a sensor. For example, if bit 0 is set then channel 0 of the device is currently deemed to be touched.

◆ WriteRegister()

template<typename Transport >
void daisy::Mpr121< Transport >::WriteRegister ( uint8_t  reg,
uint8_t  value 
)
inline

Writes 8-bits to the specified destination register

Parameters
regthe register address to write to
valuethe value to write

The documentation for this class was generated from the following file: