First Release

This commit is contained in:
nopnop2002
2021-12-28 09:45:06 +09:00
parent 6ee08637eb
commit e4f4473602
9 changed files with 2001 additions and 1 deletions

6
CMakeLists.txt Normal file
View File

@@ -0,0 +1,6 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(mpr121)

View File

@@ -1,2 +1,68 @@
# esp-idf-mpr121 # esp-idf-mpr121
MPR121 Capacitive Touch Driver for esp-idf MPR121 Capacitive Touch Driver for esp-idf.
I ported from [here](https://github.com/BareConductive/mpr121).
# Hardware requirements
MPR121 Capacitive Touch switch.
![mpr121-1](https://user-images.githubusercontent.com/6020549/147515909-cd50a16a-5c60-4bd0-bc32-c288f5d8ee88.JPG)
# Software requirements
esp-idf v4.4 or later.
This is because this version supports ESP32-C3.
# Installation for ESP32
```Shell
git clone https://github.com/nopnop2002/esp-idf-mpr121
cd esp-idf-mpr121
idf.py set-target esp32
idf.py menuconfig
idf.py flash
```
# Installation for ESP32-S2
```Shell
git clone https://github.com/nopnop2002/esp-idf-mpr121
cd esp-idf-mpr121
idf.py set-target esp32s2
idf.py menuconfig
idf.py flash
```
# Installation for ESP32-C3
```Shell
git clone https://github.com/nopnop2002/esp-idf-mpr121
cd esp-idf-mpr121
idf.py set-target esp32c3
idf.py menuconfig
idf.py flash
```
# Configuration
![config-top](https://user-images.githubusercontent.com/6020549/147515950-b6e2cf2f-5a82-4114-a565-df7a78085c8d.jpg)
![config-mpr121](https://user-images.githubusercontent.com/6020549/147515956-ef978fca-07ae-4dc6-b8c1-121fe17e23ef.jpg)
# Wirering
|MPR121||ESP32|ESP32-S2|ESP32-C3|
|:-:|:-:|:-:|:-:|:-:|
|SCL|--|GPIO4|GPIO16|GPIO6|
|SDA|--|GPIO5|GPIO17|GPIO7|
|IRQ|--|GPIO15|GPIO18|GPIO8|
|GND|--|GND|GND|GND|
|VCC|--|3.3V|3.3V|3.3V|
__You can change it to any pin using menuconfig.__
# Screen Shot
![mpr121-2](https://user-images.githubusercontent.com/6020549/147515969-54901561-66f5-4077-b6f8-7dbd7fe49f2c.jpg)

2
main/CMakeLists.txt Normal file
View File

@@ -0,0 +1,2 @@
idf_component_register(SRCS "main.c" "mpr121.c"
INCLUDE_DIRS ".")

36
main/Kconfig.projbuild Normal file
View File

@@ -0,0 +1,36 @@
menu "MPR121 Configuration"
config SCL_GPIO
int "SCL GPIO number"
range 0 48
default 6 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32H2
default 16 if IDF_TARGET_ESP32S2
default 46 if IDF_TARGET_ESP32S3
default 4
help
GPIO number (IOxx) to SCL.
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to blink.
config SDA_GPIO
int "SDA GPIO number"
range 0 48
default 7 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32H2
default 17 if IDF_TARGET_ESP32S2
default 47 if IDF_TARGET_ESP32S3
default 5
help
GPIO number (IOxx) to SDA.
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to blink.
config IRQ_GPIO
int "IRQ GPIO number"
range 0 48
default 8 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32H2
default 18 if IDF_TARGET_ESP32S2
default 48 if IDF_TARGET_ESP32S3
default 15
help
GPIO number (IOxx) to IRQ.
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to blink.
endmenu

3
main/component.mk Normal file
View File

@@ -0,0 +1,3 @@
#
# Main Makefile. This is basically the same as a component makefile.
#

88
main/main.c Normal file
View File

@@ -0,0 +1,88 @@
/* MPR121 Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "mpr121.h"
#define MPR121_ADDR 0x5A
static const char *TAG = "MAIN";
void app_main(void)
{
ESP_LOGI(TAG, "CONFIG_SCL_GPIO=%d", CONFIG_SCL_GPIO);
ESP_LOGI(TAG, "CONFIG_SDA_GPIO=%d", CONFIG_SDA_GPIO);
ESP_LOGI(TAG, "CONFIG_IRQ_GPIO=%d", CONFIG_IRQ_GPIO);
MPR121_t dev;
uint16_t touchThreshold = 40;
uint16_t releaseThreshold = 20;
//uint16_t interruptPin = 4;
bool ret = MPR121_begin(&dev, MPR121_ADDR, touchThreshold, releaseThreshold, CONFIG_IRQ_GPIO, CONFIG_SDA_GPIO, CONFIG_SCL_GPIO);
ESP_LOGI(TAG, "MPR121_begin=%d", ret);
if (ret == false) {
switch (MPR121_getError(&dev)) {
case NO_ERROR:
ESP_LOGE(TAG, "no error");
break;
case ADDRESS_UNKNOWN:
ESP_LOGE(TAG, "incorrect address");
break;
case READBACK_FAIL:
ESP_LOGE(TAG, "readback failure");
break;
case OVERCURRENT_FLAG:
ESP_LOGE(TAG, "overcurrent on REXT pin");
break;
case OUT_OF_RANGE:
ESP_LOGE(TAG, "electrode out of range");
break;
case NOT_INITED:
ESP_LOGE(TAG, "not initialised");
break;
default:
ESP_LOGE(TAG, "unknown error");
break;
}
while(1) {
vTaskDelay(1);
}
}
#if 0
MPR121_setTouchThresholdAll(&dev, 40); // this is the touch threshold - setting it low makes it more like a proximity trigger, default value is 40 for touch
MPR121_setReleaseThresholdAll(&dev, 20); // this is the release threshold - must ALWAYS be smaller than the touch threshold, default value is 20 for touch
#endif
MPR121_setFFI(&dev, FFI_10); // AFE Configuration 1
MPR121_setSFI(&dev, SFI_10); // AFE Configuration 2
MPR121_setGlobalCDT(&dev, CDT_4US); // reasonable for larger capacitances
MPR121_autoSetElectrodesDefault(&dev, true); // autoset all electrode settings
while(1) {
MPR121_updateAll(&dev);
for (int i = 0; i < 12; i++) {
if (MPR121_isNewTouch(&dev, i)) {
ESP_LOGI(TAG, "electrode %d was just touched", i);
} else if (MPR121_isNewRelease(&dev, i)) {
ESP_LOGI(TAG, "electrode %d was just released", i);
}
}
vTaskDelay(10);
}
}

1152
main/mpr121.c Normal file

File diff suppressed because it is too large Load Diff

433
main/mpr121.h Normal file
View File

@@ -0,0 +1,433 @@
/*******************************************************************************
Bare Conductive MPR121 library
------------------------------
MPR121.h - MPR121 class header file
Based on code by Jim Lindblom and plenty of inspiration from the Freescale
Semiconductor datasheets and application notes.
Bare Conductive code written by Stefan Dzisiewski-Smith, Peter Krige
and Szymon Kaliski.
This work is licensed under a MIT license https://opensource.org/licenses/MIT
Copyright (c) 2016, Bare Conductive
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*******************************************************************************/
#ifndef MPR121_H
#define MPR121_H
#include "mpr121_defs.h"
// idea behind this is to create a settings structure that we can use to store
// all the setup variables for a particular setup - comes pre-instantiated with
// defaults and can be easily tweaked - we pass by reference (as a pointer) to
// save RAM
typedef struct
{
// touch and release thresholds
uint8_t _TTHRESH;
uint8_t _RTHRESH;
uint8_t _INTERRUPT;
// general electrode touch sense baseline filters
// rising filter
uint8_t _MHDR;
uint8_t _NHDR;
uint8_t _NCLR;
uint8_t _FDLR;
// falling filter
uint8_t _MHDF;
uint8_t _NHDF;
uint8_t _NCLF;
uint8_t _FDLF;
// touched filter
uint8_t _NHDT;
uint8_t _NCLT;
uint8_t _FDLT;
// proximity electrode touch sense baseline filters
// rising filter
uint8_t _MHDPROXR;
uint8_t _NHDPROXR;
uint8_t _NCLPROXR;
uint8_t _FDLPROXR;
// falling filter
uint8_t _MHDPROXF;
uint8_t _NHDPROXF;
uint8_t _NCLPROXF;
uint8_t _FDLPROXF;
// touched filter
uint8_t _NHDPROXT;
uint8_t _NCLPROXT;
uint8_t _FDLPROXT;
// debounce settings
uint8_t _DTR;
// configuration registers
uint8_t _AFE1;
uint8_t _AFE2;
uint8_t _ECR;
// auto-configuration registers
uint8_t _ACCR0;
uint8_t _ACCR1;
uint8_t _USL;
uint8_t _LSL;
uint8_t _TL;
} MPR121_settings_type;
typedef struct {
uint8_t address;
MPR121_settings_type defaultSettings;
uint8_t ECR_backup; // so we can re-enable the correct number of electrodes
// when recovering from stop mode
uint8_t error;
bool running;
uint8_t interruptPin;
int16_t filteredData[13];
int16_t baselineData[13];
uint16_t touchData;
uint16_t lastTouchData;
bool autoTouchStatusFlag; // we use this to catch touch / release events that happen
// during other update calls
} MPR121_t;
// GPIO pin function constants
enum mpr121_pinf_type
{
// INPUT and OUTPUT (and others) are already defined by Arduino, use its definitions if they exist
#ifndef INPUT
INPUT, // digital input
#endif
#ifndef INPUT_PULLUP
INPUT_PULLUP, // digital input with pullup
#endif
#ifndef INPUT_PULLDOWN
INPUT_PULLDOWN, // digital input with pulldown
#endif
#ifndef OUTPUT
OUTPUT, // digital output (push-pull)
#endif
#ifndef OUTPUT_HIGHSIDE
OUTPUT_HIGHSIDE, // digital output, open collector (high side)
#endif
#ifndef OUTPUT_LOWSIDE
OUTPUT_LOWSIDE // digital output, open collector (low side)
#endif
};
// "13th electrode" proximity modes
// N.B. this does not relate to normal proximity detection
// see http://cache.freescale.com/files/sensors/doc/app_note/AN3893.pdf
enum mpr121_proxmode_type
{
PROX_DISABLED, // proximity mode disabled
PROX_0_1, // proximity mode for ELE0..ELE1
PROX_0_3, // proximity mode for ELE0..ELE3
PROX_0_11 // proximity mode for ELE0..ELE11
};
// baseline calibration lock modes
enum mpr121_cal_lock_type
{
CAL_LOCK_ENABLED, // baseline tracking enabled, no value change on run
CAL_LOCK_DISABLED, // baseline tracking disabled
CAL_LOCK_ENABLED_5_BIT_COPY, // baseline tracking enabled, load 5 MSB of filtered data on entering run mode
CAL_LOCK_ENABLED_10_BIT_COPY // baseline tracking enabled, load 10 MSB of filtered data on entering run mode
};
// error codes
enum mpr121_error_type
{
NO_ERROR, // no error
RETURN_TO_SENDER, // not implemented
ADDRESS_UNKNOWN, // no MPR121 found at specified I2C address
READBACK_FAIL, // readback from MPR121 was not as expected
OVERCURRENT_FLAG, // overcurrent on REXT pin
OUT_OF_RANGE, // autoconfiguration fail, often a result of shorted pins
NOT_INITED // device has not been initialised
};
// sample intervals
enum mpr121_sample_interval_type
{
SAMPLE_INTERVAL_1MS = 0x00,
SAMPLE_INTERVAL_2MS = 0x01,
SAMPLE_INTERVAL_4MS = 0x02,
SAMPLE_INTERVAL_8MS = 0x03,
SAMPLE_INTERVAL_16MS = 0x04,
SAMPLE_INTERVAL_32MS = 0x05,
SAMPLE_INTERVAL_64MS = 0x06,
SAMPLE_INTERVAL_128MS = 0x07
};
// charge / discharge times (CDT)
enum mpr121_CDT_type
{
CDT_500NS = 0x01,
CDT_1US = 0x02,
CDT_2US = 0x03,
CDT_4US = 0x04,
CDT_8US = 0x05,
CDT_16US = 0x06,
CDT_32US = 0x07
};
// first filter iterations (FFI)
enum mpr121_FFI_type
{
FFI_6 = 0x00,
FFI_10 = 0x01,
FFI_18 = 0x02,
FFI_34 = 0x03
};
// second filter iterations (SFI)
enum mpr121_SFI_type
{
SFI_4 = 0x00,
SFI_6 = 0x01,
SFI_10 = 0x02,
SFI_18 = 0x03
};
// -------------------- BASIC FUNCTIONS --------------------
void MPR121_type(MPR121_t * dev);
// begin() must be called before using any other function
// address is optional, default is 0x5C
bool MPR121_begin(MPR121_t * dev, int16_t address, int16_t touchThreshold, int16_t releaseThreshold, int16_t interruptPin, int16_t sda, int16_t scl);
// read touch and release threshold saved to EEPROM using
// saveTouchThreshold and releaseTouchThreshold
void MPR121_restoreSavedThresholds(MPR121_t * dev);
// reset saved thresholds to 255, which will force the MPR121
// to load default thresholds
void MPR121_clearSavedThresholds(MPR121_t * dev);
// I2C speed control functions - goFast() sets the SCL clock
// to 400kHz - goSlow() sets the SCL clock to 100kHz. Defaults
// to 100kHz and affects all devices on the I2C bus. Included
// for speed freaks only.
void MPR121_goSlow(MPR121_t * dev);
void MPR121_goFast(MPR121_t * dev);
// getError() returns an mpr121_error_type indicating the current
// error on the MPR121 - clearError() clears this
uint8_t MPR121_getError(MPR121_t * dev);
void MPR121_clearError(MPR121_t * dev);
// returns status of the MPR121 INT pin as read via digitalRead() on the
// Arduino board - this tells us if there has been a change in touch status
// on any active electrode since we last read any data
bool MPR121_touchStatusChanged(MPR121_t * dev);
// updates the data from the MPR121 into our internal buffer
// updateTouchData() does this only for touch on / off status
// updateBaseLineData() does this for background baseline
// updateFilteredData() does this for continuous proximity data
// updateAll() does all three
// the appropriate function from these must be called before data
// from getTouchData(), getFilteredData() etc. can be considered
// valid
void MPR121_updateTouchData(MPR121_t * dev);
bool MPR121_updateBaselineData(MPR121_t * dev);
bool MPR121_updateFilteredData(MPR121_t * dev);
void MPR121_updateAll(MPR121_t * dev);
// returns a boolean indicating the touch status of a given electrode
bool MPR121_getTouchData(MPR121_t * dev, uint8_t electrode);
// returns the number of touches currently detected
uint8_t MPR121_getNumTouches(MPR121_t * dev);
bool MPR121_getLastTouchData(MPR121_t * dev, uint8_t electrode);
// returns continous proximity or baseline data for a given electrode
int MPR121_getFilteredData(MPR121_t * dev, uint8_t electrode);
int MPR121_getBaselineData(MPR121_t * dev, uint8_t electrode);
// returns boolean indicating whether a new touch or release has been
// detected since the last time updateTouchData() was called
bool MPR121_isNewTouch(MPR121_t * dev, uint8_t electrode);
bool MPR121_isNewRelease(MPR121_t * dev, uint8_t electrode);
// sets touch and release thresholds either for all electrodes, or
// for a specfic electrode - higher values = less sensitive and
// release threshold must ALWAYS be lower than touch threshold
void MPR121_setTouchThresholdAll(MPR121_t * dev, uint8_t val);
void MPR121_setTouchThreshold(MPR121_t * dev, uint8_t electrode, uint8_t val);
void MPR121_saveTouchThreshold(MPR121_t * dev, uint8_t electrode, uint8_t val);
void MPR121_setReleaseThresholdAll(MPR121_t * dev, uint8_t val);
void MPR121_setReleaseThreshold(MPR121_t * dev, uint8_t electrode, uint8_t val);
void MPR121_saveReleaseThreshold(MPR121_t * dev, uint8_t electrode, uint8_t val);
// returns the current touch or release threshold for a specified electrode
uint8_t MPR121_getTouchThreshold(MPR121_t * dev, uint8_t electrode);
uint8_t MPR121_getReleaseThreshold(MPR121_t * dev, uint8_t electrode);
// ------------------ ADVANCED FUNCTIONS ------------------
void MPR121_settingsType(MPR121_settings_type *defaultSettings);
// applies a complete array of settings from an
// MPR121_settings_type variable passed as a pointer
// useful if you want to do a bulk setup of the device
//void MPR121_applySettings(MPR121_t * dev, MPR121_settings_type *settings);
void MPR121_applySettings(MPR121_t * dev);
// setRegister() and getRegister() manipulate registers on
// the MPR121 directly, whilst correctly stopping and
// restarting the MPR121 if necessary
void MPR121_setRegister(MPR121_t * dev, uint8_t reg, uint8_t value);
uint8_t MPR121_getRegister(MPR121_t * dev, uint8_t reg);
// stop() and run() take the MPR121 in and out of stop mode
// which reduces current consumption to 3uA
void MPR121_run(MPR121_t * dev);
void MPR121_stop(MPR121_t * dev);
// resets the MPR121
bool MPR121_reset(MPR121_t * dev);
// tells us if we are in run mode, and if we have inited the
// MPR121
bool MPR121_isRunning(MPR121_t * dev);
bool MPR121_isInited(MPR121_t * dev);
// sets the pin that the MPR121 INT output is connected to on the
// Arduino board - does not have to be a hardware interrupt pin
// if it is, however, an interrupt service routine will automatically
// set an internal flag when a touch event occurs - thus minimising
// lost events if you are also reading other data types (filtered data,
// baseline data)
void MPR121_setInterruptPin(MPR121_t * dev, uint8_t pin);
// set number of electrodes to use to generate virtual "13th"
// proximity electrode
// see http://cache.freescale.com/files/sensors/doc/app_note/AN3893.pdf
//
// N.B. - this is not related to general proximity detection or
// reading back continuous proximity data
void MPR121_setProxMode(MPR121_t * dev, uint8_t mode);
// set calibration lock mode for baseline tracking
// this can be useful to disable baseline tracking, set it to
// current values (with 5 or 10 most significant bits copied across from
// current filtered values to baseline the next time run mode is entered)
// or leave it enabled with its current values in place (and no copy-across
// when run mode is re-entered)
void MPR121_setCalibrationLock(MPR121_t * dev, uint8_t lock);
// set global or per-electrode charge / discharge current in microamps
// current_uA is valid 0..63 (for global value, 0 means use electrode-specific setting)
// electrode is valid 0..12 (includes virtual proximity electrode)
void MPR121_setGlobalCDC(MPR121_t * dev, uint8_t CDC);
void MPR121_setElectrodeCDC(MPR121_t * dev, uint8_t electrode, uint8_t CDC);
// runs hardware routine for automatic electrode calibration for all electrodes
// this is implemented in the MPR121 hardware itself
// fixedChargeTime flag keeps CDT constant (useful for carbon-based inks with high lead-in resistance)
bool MPR121_autoSetElectrodes(MPR121_t * dev, uint16_t VCC_mV, bool fixedChargeTime);
bool MPR121_autoSetElectrodesDefault(MPR121_t * dev, bool fixedChargeTime);
// software routine to keep CDT constant and adjust CDC to fit
bool MPR121_autoSetElectrodeCDC(MPR121_t * dev, uint8_t electrode, uint16_t VCC_mV);
bool MPR121_autoSetElectrodeCDCDefault(MPR121_t * dev, uint8_t electrode);
bool MPR121_autoSetElectrodeCDCAll(MPR121_t * dev); // runs autocal for all electrodes
// set global or per-electrode charge / discharge time
// CDT follows a 0.5(2^(n-1))uS rule, so an enum type is provided for clarity
void MPR121_setGlobalCDT(MPR121_t * dev, uint8_t CDT);
void MPR121_setElectrodeCDT(MPR121_t * dev, uint8_t electrode, uint8_t CDT);
// Set / get the number of enabled electrodes, from 0 (which implicitly enters
// stop mode) up to 12. This allows for a reduction in power consumption
// when using fewer electrodes and faster update rates. Implementation is
// similar to setNumDigPins below, butwith a different intent.
void MPR121_setNumEnabledElectrodes(MPR121_t * dev, uint8_t numElectrodes);
uint8_t MPR121_getNumEnabledElectrodes(MPR121_t * dev);
// Enables GPIO mode for up to 8 of the MPR121 electrodes
// starts with electrode 11 - i.e. setNumDigPins(1) sets just
// electrode 11 as GPIO, setNumDigPins(2) sets electrodes 11
// & 10 as GPIO, and so on. Electrodes 0 to 3 cannot be used
// as GPIO
//
// N.B. electrodes are 3.3V and WILL be damaged if driven by
// a greater voltage
void MPR121_setNumDigPins(MPR121_t * dev, uint8_t numPins);
// Sets pin mode for an electrode already set as GPIO by
// setNumDigPins() - see section "GPIO pin function constants"
// for details
#if 0
void MPR121_pinMode(MPR121_t * dev, uint8_t electrode, mpr121_pinf_type mode);
#endif
void MPR121_pinMode(MPR121_t * dev, uint8_t electrode, int mode);
// Similar to digitalWrite in Arduino for GPIO electrode
void MPR121_digitalWrite(MPR121_t * dev, uint8_t electrode, uint8_t val);
// Toggles electrode set as GPIO output
void MPR121_digitalToggle(MPR121_t * dev, uint8_t electrode);
// Reads electrode set as GPIO input
bool MPR121_digitalRead(MPR121_t * dev, uint8_t electrode);
// Writes PWM value to electrode set as GPIO output - very limited
// (4 bit, although input to function is 0..255 to match Arduino,
// internally reduced to 4 bit) and broken on ELE9 and ELE10
// see https://community.freescale.com/thread/305474
void MPR121_analogWrite(MPR121_t * dev, uint8_t electrode, uint8_t val);
// Sets the sample period of the MPR121 - the time between capacitive
// readings. Higher values consume less power, but are less responsive.
void MPR121_setSamplePeriod(MPR121_t * dev, uint8_t period);
void MPR121_setFFI(MPR121_t * dev, uint8_t FFI);
void MPR121_setSFI(MPR121_t * dev, uint8_t SFI);
//extern MPR121_type MPR121;
#endif // MPR121_H

214
main/mpr121_defs.h Normal file
View File

@@ -0,0 +1,214 @@
/*******************************************************************************
Bare Conductive MPR121 library
------------------------------
MPR121_defs.h - MPR121 register definitions
Based on code by Jim Lindblom and plenty of inspiration from the Freescale
Semiconductor datasheets and application notes.
Bare Conductive code written by Stefan Dzisiewski-Smith and Peter Krige.
This work is licensed under a MIT license https://opensource.org/licenses/MIT
Copyright (c) 2016, Bare Conductive
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*******************************************************************************/
#ifndef MPR121_DEFS_H
#define MPR121_DEFS_H
// MPR121 Register Defines
// touch and OOR statuses
static uint8_t const MPR121_TS1 = 0x00;
static uint8_t const MPR121_TS2 = 0x01;
static uint8_t const MPR121_OORS1 = 0x02;
static uint8_t const MPR121_OORS2 = 0x03;
// filtered data
static uint8_t const MPR121_E0FDL = 0x04;
static uint8_t const MPR121_E0FDH = 0x05;
static uint8_t const MPR121_E1FDL = 0x06;
static uint8_t const MPR121_E1FDH = 0x07;
static uint8_t const MPR121_E2FDL = 0x08;
static uint8_t const MPR121_E2FDH = 0x09;
static uint8_t const MPR121_E3FDL = 0x0A;
static uint8_t const MPR121_E3FDH = 0x0B;
static uint8_t const MPR121_E4FDL = 0x0C;
static uint8_t const MPR121_E4FDH = 0x0D;
static uint8_t const MPR121_E5FDL = 0x0E;
static uint8_t const MPR121_E5FDH = 0x0F;
static uint8_t const MPR121_E6FDL = 0x10;
static uint8_t const MPR121_E6FDH = 0x11;
static uint8_t const MPR121_E7FDL = 0x12;
static uint8_t const MPR121_E7FDH = 0x13;
static uint8_t const MPR121_E8FDL = 0x14;
static uint8_t const MPR121_E8FDH = 0x15;
static uint8_t const MPR121_E9FDL = 0x16;
static uint8_t const MPR121_E9FDH = 0x17;
static uint8_t const MPR121_E10FDL = 0x18;
static uint8_t const MPR121_E10FDH = 0x19;
static uint8_t const MPR121_E11FDL = 0x1A;
static uint8_t const MPR121_E11FDH = 0x1B;
static uint8_t const MPR121_E12FDL = 0x1C;
static uint8_t const MPR121_E12FDH = 0x1D;
// baseline values
static uint8_t const MPR121_E0BV = 0x1E;
static uint8_t const MPR121_E1BV = 0x1F;
static uint8_t const MPR121_E2BV = 0x20;
static uint8_t const MPR121_E3BV = 0x21;
static uint8_t const MPR121_E4BV = 0x22;
static uint8_t const MPR121_E5BV = 0x23;
static uint8_t const MPR121_E6BV = 0x24;
static uint8_t const MPR121_E7BV = 0x25;
static uint8_t const MPR121_E8BV = 0x26;
static uint8_t const MPR121_E9BV = 0x27;
static uint8_t const MPR121_E10BV = 0x28;
static uint8_t const MPR121_E11BV = 0x29;
static uint8_t const MPR121_E12BV = 0x2A;
// general electrode touch sense baseline filters
// rising filter
static uint8_t const MPR121_MHDR = 0x2B;
static uint8_t const MPR121_NHDR = 0x2C;
static uint8_t const MPR121_NCLR = 0x2D;
static uint8_t const MPR121_FDLR = 0x2E;
// falling filter
static uint8_t const MPR121_MHDF = 0x2F;
static uint8_t const MPR121_NHDF = 0x30;
static uint8_t const MPR121_NCLF = 0x31;
static uint8_t const MPR121_FDLF = 0x32;
// touched filter
static uint8_t const MPR121_NHDT = 0x33;
static uint8_t const MPR121_NCLT = 0x34;
static uint8_t const MPR121_FDLT = 0x35;
// proximity electrode touch sense baseline filters
// rising filter
static uint8_t const MPR121_MHDPROXR = 0x36;
static uint8_t const MPR121_NHDPROXR = 0x37;
static uint8_t const MPR121_NCLPROXR = 0x38;
static uint8_t const MPR121_FDLPROXR = 0x39;
// falling filter
static uint8_t const MPR121_MHDPROXF = 0x3A;
static uint8_t const MPR121_NHDPROXF = 0x3B;
static uint8_t const MPR121_NCLPROXF = 0x3C;
static uint8_t const MPR121_FDLPROXF = 0x3D;
// touched filter
static uint8_t const MPR121_NHDPROXT = 0x3E;
static uint8_t const MPR121_NCLPROXT = 0x3F;
static uint8_t const MPR121_FDLPROXT = 0x40;
// electrode touch and release thresholds
static uint8_t const MPR121_E0TTH = 0x41;
static uint8_t const MPR121_E0RTH = 0x42;
static uint8_t const MPR121_E1TTH = 0x43;
static uint8_t const MPR121_E1RTH = 0x44;
static uint8_t const MPR121_E2TTH = 0x45;
static uint8_t const MPR121_E2RTH = 0x46;
static uint8_t const MPR121_E3TTH = 0x47;
static uint8_t const MPR121_E3RTH = 0x48;
static uint8_t const MPR121_E4TTH = 0x49;
static uint8_t const MPR121_E4RTH = 0x4A;
static uint8_t const MPR121_E5TTH = 0x4B;
static uint8_t const MPR121_E5RTH = 0x4C;
static uint8_t const MPR121_E6TTH = 0x4D;
static uint8_t const MPR121_E6RTH = 0x4E;
static uint8_t const MPR121_E7TTH = 0x4F;
static uint8_t const MPR121_E7RTH = 0x50;
static uint8_t const MPR121_E8TTH = 0x51;
static uint8_t const MPR121_E8RTH = 0x52;
static uint8_t const MPR121_E9TTH = 0x53;
static uint8_t const MPR121_E9RTH = 0x54;
static uint8_t const MPR121_E10TTH = 0x55;
static uint8_t const MPR121_E10RTH = 0x56;
static uint8_t const MPR121_E11TTH = 0x57;
static uint8_t const MPR121_E11RTH = 0x58;
static uint8_t const MPR121_E12TTH = 0x59;
static uint8_t const MPR121_E12RTH = 0x5A;
// debounce settings
static uint8_t const MPR121_DTR = 0x5B;
// configuration registers
static uint8_t const MPR121_AFE1 = 0x5C;
static uint8_t const MPR121_AFE2 = 0x5D;
static uint8_t const MPR121_ECR = 0x5E;
// electrode currents
static uint8_t const MPR121_CDC0 = 0x5F;
static uint8_t const MPR121_CDC1 = 0x60;
static uint8_t const MPR121_CDC2 = 0x61;
static uint8_t const MPR121_CDC3 = 0x62;
static uint8_t const MPR121_CDC4 = 0x63;
static uint8_t const MPR121_CDC5 = 0x64;
static uint8_t const MPR121_CDC6 = 0x65;
static uint8_t const MPR121_CDC7 = 0x66;
static uint8_t const MPR121_CDC8 = 0x67;
static uint8_t const MPR121_CDC9 = 0x68;
static uint8_t const MPR121_CDC10 = 0x69;
static uint8_t const MPR121_CDC11 = 0x6A;
static uint8_t const MPR121_CDCPROX = 0x6B;
// electrode charge times
static uint8_t const MPR121_CDT01 = 0x6C;
static uint8_t const MPR121_CDT23 = 0x6D;
static uint8_t const MPR121_CDT45 = 0x6E;
static uint8_t const MPR121_CDT67 = 0x6F;
static uint8_t const MPR121_CDT89 = 0x70;
static uint8_t const MPR121_CDT1011 = 0x71;
static uint8_t const MPR121_CDTPROX = 0x72;
// GPIO
static uint8_t const MPR121_CTL0 = 0x73;
static uint8_t const MPR121_CTL1 = 0x74;
static uint8_t const MPR121_DAT = 0x75;
static uint8_t const MPR121_DIR = 0x76;
static uint8_t const MPR121_EN = 0x77;
static uint8_t const MPR121_SET = 0x78;
static uint8_t const MPR121_CLR = 0x79;
static uint8_t const MPR121_TOG = 0x7A;
// auto-config
static uint8_t const MPR121_ACCR0 = 0x7B;
static uint8_t const MPR121_ACCR1 = 0x7C;
static uint8_t const MPR121_USL = 0x7D;
static uint8_t const MPR121_LSL = 0x7E;
static uint8_t const MPR121_TL = 0x7F;
// soft reset
static uint8_t const MPR121_SRST = 0x80;
// PWM
static uint8_t const MPR121_PWM0 = 0x81;
static uint8_t const MPR121_PWM1 = 0x82;
static uint8_t const MPR121_PWM2 = 0x83;
static uint8_t const MPR121_PWM3 = 0x84;
#endif // MPR121_DEFS_H