Complete

Dependencies:   mbed

Committer:
mikeb
Date:
Sat Jan 30 03:22:41 2016 +0000
Revision:
3:ecfa4fa0b5a7
Complete;

Who changed what in which revision?

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