CodeShare

Dependencies:   mbed

Committer:
jeremycai3721
Date:
Sun Sep 25 20:20:04 2016 +0000
Revision:
0:42cceb842d76
CodeShare

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jeremycai3721 0:42cceb842d76 1 /*
jeremycai3721 0:42cceb842d76 2 Copyright (c) 2011 Anthony Buckton (abuckton [at] blackink [dot} net {dot} au)
jeremycai3721 0:42cceb842d76 3
jeremycai3721 0:42cceb842d76 4
jeremycai3721 0:42cceb842d76 5 Permission is hereby granted, free of charge, to any person obtaining a copy
jeremycai3721 0:42cceb842d76 6 of this software and associated documentation files (the "Software"), to deal
jeremycai3721 0:42cceb842d76 7 in the Software without restriction, including without limitation the rights
jeremycai3721 0:42cceb842d76 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jeremycai3721 0:42cceb842d76 9 copies of the Software, and to permit persons to whom the Software is
jeremycai3721 0:42cceb842d76 10 furnished to do so, subject to the following conditions:
jeremycai3721 0:42cceb842d76 11
jeremycai3721 0:42cceb842d76 12 The above copyright notice and this permission notice shall be included in
jeremycai3721 0:42cceb842d76 13 all copies or substantial portions of the Software.
jeremycai3721 0:42cceb842d76 14
jeremycai3721 0:42cceb842d76 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jeremycai3721 0:42cceb842d76 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jeremycai3721 0:42cceb842d76 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jeremycai3721 0:42cceb842d76 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jeremycai3721 0:42cceb842d76 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jeremycai3721 0:42cceb842d76 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jeremycai3721 0:42cceb842d76 21 THE SOFTWARE.
jeremycai3721 0:42cceb842d76 22
jeremycai3721 0:42cceb842d76 23 Parts written by Jim Lindblom of Sparkfun
jeremycai3721 0:42cceb842d76 24 Ported to mbed by A.Buckton, Feb 2011
jeremycai3721 0:42cceb842d76 25 */
jeremycai3721 0:42cceb842d76 26
jeremycai3721 0:42cceb842d76 27 #ifndef MPR121_H
jeremycai3721 0:42cceb842d76 28 #define MPR121_H
jeremycai3721 0:42cceb842d76 29
jeremycai3721 0:42cceb842d76 30 //using namespace std;
jeremycai3721 0:42cceb842d76 31
jeremycai3721 0:42cceb842d76 32 class Mpr121
jeremycai3721 0:42cceb842d76 33 {
jeremycai3721 0:42cceb842d76 34
jeremycai3721 0:42cceb842d76 35 public:
jeremycai3721 0:42cceb842d76 36 // i2c Addresses, bit-shifted
jeremycai3721 0:42cceb842d76 37 enum Address { ADD_VSS = 0xb4,// ADD->VSS = 0x5a <-wiring on Sparkfun board
jeremycai3721 0:42cceb842d76 38 ADD_VDD = 0xb6,// ADD->VDD = 0x5b
jeremycai3721 0:42cceb842d76 39 ADD_SCL = 0xb8,// ADD->SDA = 0x5c
jeremycai3721 0:42cceb842d76 40 ADD_SDA = 0xba // ADD->SCL = 0x5d
jeremycai3721 0:42cceb842d76 41 };
jeremycai3721 0:42cceb842d76 42
jeremycai3721 0:42cceb842d76 43 // Real initialiser, takes the i2c address of the device.
jeremycai3721 0:42cceb842d76 44 Mpr121(I2C *i2c, Address i2cAddress);
jeremycai3721 0:42cceb842d76 45
jeremycai3721 0:42cceb842d76 46 bool getProximityMode();
jeremycai3721 0:42cceb842d76 47
jeremycai3721 0:42cceb842d76 48 void setProximityMode(bool mode);
jeremycai3721 0:42cceb842d76 49
jeremycai3721 0:42cceb842d76 50 int readTouchData();
jeremycai3721 0:42cceb842d76 51
jeremycai3721 0:42cceb842d76 52 unsigned char read(int key);
jeremycai3721 0:42cceb842d76 53
jeremycai3721 0:42cceb842d76 54 int write(int address, unsigned char value);
jeremycai3721 0:42cceb842d76 55 int writeMany(int start, unsigned char* dataSet, int length);
jeremycai3721 0:42cceb842d76 56
jeremycai3721 0:42cceb842d76 57 void setElectrodeThreshold(int electrodeId, unsigned char touchThreshold, unsigned char releaseThreshold);
jeremycai3721 0:42cceb842d76 58
jeremycai3721 0:42cceb842d76 59 protected:
jeremycai3721 0:42cceb842d76 60 // Configures the MPR with standard settings. This is permitted to be overwritten by sub-classes.
jeremycai3721 0:42cceb842d76 61 void configureSettings();
jeremycai3721 0:42cceb842d76 62
jeremycai3721 0:42cceb842d76 63 private:
jeremycai3721 0:42cceb842d76 64 // The I2C bus instance.
jeremycai3721 0:42cceb842d76 65 I2C *i2c;
jeremycai3721 0:42cceb842d76 66
jeremycai3721 0:42cceb842d76 67 // i2c address of this mpr121
jeremycai3721 0:42cceb842d76 68 Address address;
jeremycai3721 0:42cceb842d76 69 };
jeremycai3721 0:42cceb842d76 70
jeremycai3721 0:42cceb842d76 71
jeremycai3721 0:42cceb842d76 72 // MPR121 Register Defines
jeremycai3721 0:42cceb842d76 73 #define MHD_R 0x2B
jeremycai3721 0:42cceb842d76 74 #define NHD_R 0x2C
jeremycai3721 0:42cceb842d76 75 #define NCL_R 0x2D
jeremycai3721 0:42cceb842d76 76 #define FDL_R 0x2E
jeremycai3721 0:42cceb842d76 77 #define MHD_F 0x2F
jeremycai3721 0:42cceb842d76 78 #define NHD_F 0x30
jeremycai3721 0:42cceb842d76 79 #define NCL_F 0x31
jeremycai3721 0:42cceb842d76 80 #define FDL_F 0x32
jeremycai3721 0:42cceb842d76 81 #define NHDT 0x33
jeremycai3721 0:42cceb842d76 82 #define NCLT 0x34
jeremycai3721 0:42cceb842d76 83 #define FDLT 0x35
jeremycai3721 0:42cceb842d76 84 // Proximity sensing controls
jeremycai3721 0:42cceb842d76 85 #define MHDPROXR 0x36
jeremycai3721 0:42cceb842d76 86 #define NHDPROXR 0x37
jeremycai3721 0:42cceb842d76 87 #define NCLPROXR 0x38
jeremycai3721 0:42cceb842d76 88 #define FDLPROXR 0x39
jeremycai3721 0:42cceb842d76 89 #define MHDPROXF 0x3A
jeremycai3721 0:42cceb842d76 90 #define NHDPROXF 0x3B
jeremycai3721 0:42cceb842d76 91 #define NCLPROXF 0x3C
jeremycai3721 0:42cceb842d76 92 #define FDLPROXF 0x3D
jeremycai3721 0:42cceb842d76 93 #define NHDPROXT 0x3E
jeremycai3721 0:42cceb842d76 94 #define NCLPROXT 0x3F
jeremycai3721 0:42cceb842d76 95 #define FDLPROXT 0x40
jeremycai3721 0:42cceb842d76 96 // Electrode Touch/Release thresholds
jeremycai3721 0:42cceb842d76 97 #define ELE0_T 0x41
jeremycai3721 0:42cceb842d76 98 #define ELE0_R 0x42
jeremycai3721 0:42cceb842d76 99 #define ELE1_T 0x43
jeremycai3721 0:42cceb842d76 100 #define ELE1_R 0x44
jeremycai3721 0:42cceb842d76 101 #define ELE2_T 0x45
jeremycai3721 0:42cceb842d76 102 #define ELE2_R 0x46
jeremycai3721 0:42cceb842d76 103 #define ELE3_T 0x47
jeremycai3721 0:42cceb842d76 104 #define ELE3_R 0x48
jeremycai3721 0:42cceb842d76 105 #define ELE4_T 0x49
jeremycai3721 0:42cceb842d76 106 #define ELE4_R 0x4A
jeremycai3721 0:42cceb842d76 107 #define ELE5_T 0x4B
jeremycai3721 0:42cceb842d76 108 #define ELE5_R 0x4C
jeremycai3721 0:42cceb842d76 109 #define ELE6_T 0x4D
jeremycai3721 0:42cceb842d76 110 #define ELE6_R 0x4E
jeremycai3721 0:42cceb842d76 111 #define ELE7_T 0x4F
jeremycai3721 0:42cceb842d76 112 #define ELE7_R 0x50
jeremycai3721 0:42cceb842d76 113 #define ELE8_T 0x51
jeremycai3721 0:42cceb842d76 114 #define ELE8_R 0x52
jeremycai3721 0:42cceb842d76 115 #define ELE9_T 0x53
jeremycai3721 0:42cceb842d76 116 #define ELE9_R 0x54
jeremycai3721 0:42cceb842d76 117 #define ELE10_T 0x55
jeremycai3721 0:42cceb842d76 118 #define ELE10_R 0x56
jeremycai3721 0:42cceb842d76 119 #define ELE11_T 0x57
jeremycai3721 0:42cceb842d76 120 #define ELE11_R 0x58
jeremycai3721 0:42cceb842d76 121 // Proximity Touch/Release thresholds
jeremycai3721 0:42cceb842d76 122 #define EPROXTTH 0x59
jeremycai3721 0:42cceb842d76 123 #define EPROXRTH 0x5A
jeremycai3721 0:42cceb842d76 124 // Debounce configuration
jeremycai3721 0:42cceb842d76 125 #define DEB_CFG 0x5B
jeremycai3721 0:42cceb842d76 126 // AFE- Analogue Front End configuration
jeremycai3721 0:42cceb842d76 127 #define AFE_CFG 0x5C
jeremycai3721 0:42cceb842d76 128 // Filter configuration
jeremycai3721 0:42cceb842d76 129 #define FIL_CFG 0x5D
jeremycai3721 0:42cceb842d76 130 // Electrode configuration - transistions to "active mode"
jeremycai3721 0:42cceb842d76 131 #define ELE_CFG 0x5E
jeremycai3721 0:42cceb842d76 132
jeremycai3721 0:42cceb842d76 133 #define GPIO_CTRL0 0x73
jeremycai3721 0:42cceb842d76 134 #define GPIO_CTRL1 0x74
jeremycai3721 0:42cceb842d76 135 #define GPIO_DATA 0x75
jeremycai3721 0:42cceb842d76 136 #define GPIO_DIR 0x76
jeremycai3721 0:42cceb842d76 137 #define GPIO_EN 0x77
jeremycai3721 0:42cceb842d76 138 #define GPIO_SET 0x78
jeremycai3721 0:42cceb842d76 139 #define GPIO_CLEAR 0x79
jeremycai3721 0:42cceb842d76 140 #define GPIO_TOGGLE 0x7A
jeremycai3721 0:42cceb842d76 141 // Auto configration registers
jeremycai3721 0:42cceb842d76 142 #define AUTO_CFG_0 0x7B
jeremycai3721 0:42cceb842d76 143 #define AUTO_CFG_U 0x7D
jeremycai3721 0:42cceb842d76 144 #define AUTO_CFG_L 0x7E
jeremycai3721 0:42cceb842d76 145 #define AUTO_CFG_T 0x7F
jeremycai3721 0:42cceb842d76 146
jeremycai3721 0:42cceb842d76 147 // Threshold defaults
jeremycai3721 0:42cceb842d76 148 // Electrode touch threshold
jeremycai3721 0:42cceb842d76 149 #define E_THR_T 0x0F
jeremycai3721 0:42cceb842d76 150 // Electrode release threshold
jeremycai3721 0:42cceb842d76 151 #define E_THR_R 0x0A
jeremycai3721 0:42cceb842d76 152 // Prox touch threshold
jeremycai3721 0:42cceb842d76 153 #define PROX_THR_T 0x02
jeremycai3721 0:42cceb842d76 154 // Prox release threshold
jeremycai3721 0:42cceb842d76 155 #define PROX_THR_R 0x02
jeremycai3721 0:42cceb842d76 156
jeremycai3721 0:42cceb842d76 157 #endif