IoAbstraction
Public Member Functions | Protected Member Functions | List of all members
MPR121IoAbstraction Class Reference

#include <IoAbstractionWire.h>

Inheritance diagram for MPR121IoAbstraction:
Standard16BitDevice BasicIoAbstraction

Public Member Functions

 MPR121IoAbstraction (uint8_t addr, pinid_t intPin=IO_PIN_NOT_DEFINED, WireType wirePtr=nullptr)
 
void begin (int maxTouchPin, MPR121ConfigType configType, uint8_t configReg1=0x10, uint8_t configReg2=0x20)
 
void pinDirection (pinid_t pin, uint8_t mode) override
 
void attachInterrupt (pinid_t pin, RawIntHandler intHandler, uint8_t mode) override
 
bool runLoop () override
 
void electrodeSettingsForPin (pinid_t pin, uint8_t touchThreshold, uint8_t releaseThreshold, uint8_t current=0, uint8_t chargeTime=0)
 
uint16_t getOutOfRangeRegister ()
 
void configureDebounce (uint8_t debounceTouch, uint8_t debounceRelease)
 
uint16_t read2ndFilteredData (uint8_t pin)
 
void setPinLedCurrent (pinid_t pin, uint8_t pwr)
 
void softwareReset ()
 
void initDevice () override
 
void writeReg8 (uint8_t reg, uint8_t data)
 
void writeReg16 (uint8_t reg, uint16_t data)
 
uint8_t readReg8 (uint8_t reg)
 
uint16_t readReg16 (uint8_t reg)
 
- Public Member Functions inherited from Standard16BitDevice
void writeValue (pinid_t pin, uint8_t value) override
 
uint8_t readValue (pinid_t pin) override
 
void writePort (pinid_t pin, uint8_t port) override
 
uint8_t readPort (pinid_t pin) override
 
void clearChangeFlags ()
 
void setReadPort (int port)
 
bool isReadPortSet (int port) const
 
bool isWritePortSet (int port) const
 
bool isInitNeeded () const
 
void markInitialised ()
 
- Public Member Functions inherited from BasicIoAbstraction
uint8_t digitalRead (pinid_t p)
 
void digitalWrite (pinid_t p, uint8_t v)
 
uint8_t digitalReadS (pinid_t p)
 
void digitalWriteS (pinid_t p, uint8_t v)
 
void writePortS (pinid_t p, uint8_t v)
 
uint8_t readPortS (pinid_t p)
 
void pinMode (pinid_t pin, uint8_t mode)
 
bool sync ()
 

Protected Member Functions

void enableTouchSupportOnPin (pinid_t pin)
 

Additional Inherited Members

- Protected Attributes inherited from Standard16BitDevice
uint16_t lastRead
 
uint16_t toWrite
 
uint8_t flags
 

Detailed Description

The MPR121IoAbstraction class provide a wide range of the capabilities of the MPR121 chip using the regular abstraction method such that they can be used with switches, LCDs, encoders, keyboards etc, similar to how you use device pins. For the additional functionality that is not directly provided, you can access the chips registers and set these particular extended functions up directly.

To use in touch mode you need to setup the registers before calling pinMode to set directions up. There are some helper functions to do some of the legwork, but given the shear number of possible configurations many of the touch registers need to be set up manually.

Constructor & Destructor Documentation

◆ MPR121IoAbstraction()

MPR121IoAbstraction::MPR121IoAbstraction ( uint8_t  addr,
pinid_t  intPin = IO_PIN_NOT_DEFINED,
WireType  wirePtr = nullptr 
)
explicit

create an instance of the abstraction that communicates with the device and extends Arduino like functions for the pins on the device. This constructor takes the I2C address, and optionally an interrupt pin and wire implementation. Any interrupt pin provided will be set up on your behalf automatically.

Parameters
addrthe address on the I2C bus of the device
intPinoptionally a pin on the board that the devices interrupt pin is connected to
wirePtroptionally an alternative wire implementation, EG Wire1, or other non standard I2C device.

Member Function Documentation

◆ begin()

void MPR121IoAbstraction::begin ( int  maxTouchPin,
MPR121ConfigType  configType,
uint8_t  configReg1 = 0x10,
uint8_t  configReg2 = 0x20 
)

Call this to start the device, it will initialise the touch sensor up to maxTouchPin, and set basic configuration options, this should be largely compatible with the Adafruit library, and therefore should work with the shield without too many issues. Note that if you configure more than 4 touch pins you cannot use GPIO at the same time.

Parameters
maxTouchPinthe maximum touch pin zero based
configTypeeither MPR121_MANUAL_CONFIG, MPR121_AUTO_CONFIG
configReg1optionally the first config register (default 0x10)
configReg2optionally the second config register (default 0x20)

◆ pinDirection()

void MPR121IoAbstraction::pinDirection ( pinid_t  pin,
uint8_t  mode 
)
overridevirtual

Sets the pin direction similar to pinMode, pin direction on this device supports INPUT, OUTPUT and LED_CURRENT_OUTPUT which enables the onboard LED controller, and then you use the setPinLedCurrent to control instead of digital write.

Parameters
pinthe pin to set direction for on this device
modefor this device, INPUT, OUTPUT or AW9523_LED_OUTPUT

Reimplemented from BasicIoAbstraction.

◆ attachInterrupt()

void MPR121IoAbstraction::attachInterrupt ( pinid_t  pin,
RawIntHandler  intHandler,
uint8_t  mode 
)
overridevirtual

Attaches an interrupt to the device and links it to the arduino pin. On this device nearly all interrupt modes are supported, including CHANGE, RISING, FALLING and are selective.

Reimplemented from BasicIoAbstraction.

◆ runLoop()

bool MPR121IoAbstraction::runLoop ( )
overridevirtual

updates settings on the board after changes

Reimplemented from BasicIoAbstraction.

◆ electrodeSettingsForPin()

void MPR121IoAbstraction::electrodeSettingsForPin ( pinid_t  pin,
uint8_t  touchThreshold,
uint8_t  releaseThreshold,
uint8_t  current = 0,
uint8_t  chargeTime = 0 
)

Set the electrode settings for a pin, should only ever be called once the pin is set as input, it will turn the pin into a touch pin. These take values in line with the datasheet, which should be consulted for the correct value ranges. This should be called before setting pin direction to input. It is assumed the device is in stop mode by calling softwareReset and before the begin call.

Parameters
pinthe pin to configure for
currentthe current to be used
chargeTimethe charge time to be used
touchThresholdthe touch threshold as per value determined from testing
releaseThresholdthe release threshold has per value determined from test.

◆ getOutOfRangeRegister()

uint16_t MPR121IoAbstraction::getOutOfRangeRegister ( )
Returns
the current status of the Out Of Range register on the device. See the datasheet for more details.

◆ configureDebounce()

void MPR121IoAbstraction::configureDebounce ( uint8_t  debounceTouch,
uint8_t  debounceRelease 
)

Debounce configuration takes value for both touch and release and is in conformance with the datasheet. Each is a value between 0 and 7. It is assumed the device is in stop mode by calling softwareReset and before the begin call.

Parameters
debounceTouch
debounceRelease

◆ read2ndFilteredData()

uint16_t MPR121IoAbstraction::read2ndFilteredData ( uint8_t  pin)

Read the electrode filtered data, which is after the 2nd filter from the datasheet. This reads Electrode Data Registers 0x04-0x1D. See datasheet for more detail.

Parameters
pinthe pin number
Returns
the value from the registers

◆ setPinLedCurrent()

void MPR121IoAbstraction::setPinLedCurrent ( pinid_t  pin,
uint8_t  pwr 
)

Enable or disable the LED controller mode of the pin, the power parameter is a value between 0 and 255 that represents the dimming level for that pin.

Parameters
pinthe pin to control
pwrthe current to provide, based on the global control setting, default 0..37mA.

◆ softwareReset()

void MPR121IoAbstraction::softwareReset ( )

Perform a software reset of the device. Make sure you've called sync at least once before calling.


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