#include <IoAbstractionWire.h>
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 |
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.
|
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.
addr | the address on the I2C bus of the device |
intPin | optionally a pin on the board that the devices interrupt pin is connected to |
wirePtr | optionally an alternative wire implementation, EG Wire1, or other non standard I2C device. |
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.
maxTouchPin | the maximum touch pin zero based |
configType | either MPR121_MANUAL_CONFIG, MPR121_AUTO_CONFIG |
configReg1 | optionally the first config register (default 0x10) |
configReg2 | optionally the second config register (default 0x20) |
|
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.
pin | the pin to set direction for on this device |
mode | for this device, INPUT, OUTPUT or AW9523_LED_OUTPUT |
Reimplemented from BasicIoAbstraction.
|
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.
|
overridevirtual |
updates settings on the board after changes
Reimplemented from BasicIoAbstraction.
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.
pin | the pin to configure for |
current | the current to be used |
chargeTime | the charge time to be used |
touchThreshold | the touch threshold as per value determined from testing |
releaseThreshold | the release threshold has per value determined from test. |
uint16_t MPR121IoAbstraction::getOutOfRangeRegister | ( | ) |
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.
debounceTouch | |
debounceRelease |
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.
pin | the pin number |
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.
pin | the pin to control |
pwr | the current to provide, based on the global control setting, default 0..37mA. |
void MPR121IoAbstraction::softwareReset | ( | ) |
Perform a software reset of the device. Make sure you've called sync at least once before calling.