4180Lab1Part5

Dependencies:   mbed

Committer:
CRaslawski
Date:
Mon Feb 27 22:32:33 2017 +0000
Revision:
0:5bfc0a45db24
initial commit

Who changed what in which revision?

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