Skip to content

daisy::Mpr121

Module: External

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

#include <mpr121.h>

Public Classes

Name
struct Config

Public Types

Name
enum Result
enum RegMap

Public Functions

Name
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)

Detailed Description

template <typename Transport >
class daisy::Mpr121;

Device support for MPR121 12x Capacitive Touch Sensor.

Author: beserge

Date: December 2021

Public Types Documentation

enum Result

Enumerator Value Description
OK 0
ERR

enum RegMap

Enumerator Value Description
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

Device register map

Public Functions Documentation

function Mpr121

inline Mpr121()

function ~Mpr121

inline ~Mpr121()

function Init

inline Result Init(
    Config config
)

Parameters:

  • config Configuration settings

Initialize the MPR121 device


function SetThresholds

inline void SetThresholds(
    uint8_t touch,
    uint8_t release
)

Parameters:

  • touch The touch threshold value from 0 to 255.
  • release The release threshold from 0 to 255.

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


function FilteredData

inline uint16_t FilteredData(
    uint8_t t
)

Parameters:

  • t the channel to read

Return: the filtered reading as a 10 bit unsigned value

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.


function BaselineData

inline uint16_t BaselineData(
    uint8_t t
)

Parameters:

  • t the channel to read.

Return: the baseline data that was read

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.


function Touched

inline uint16_t Touched()

Return: 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.

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


function ReadRegister8

inline uint8_t ReadRegister8(
    uint8_t reg
)

Parameters:

  • reg the register address to read from

Return: the 8 bit value that was read.

Read the contents of an 8 bit device register.


function ReadRegister16

inline uint16_t ReadRegister16(
    uint8_t reg
)

Parameters:

  • reg the register address to read from

Return: the 16 bit value that was read.

Read the contents of a 16 bit device register.


function WriteRegister

inline void WriteRegister(
    uint8_t reg,
    uint8_t value
)

Parameters:

  • reg the register address to write to
  • value the value to write

Writes 8-bits to the specified destination register

---

Updated on 2024-01-03 at 19:41:01 +0000