111

Dependencies:   4DGL-uLCD-SE AD5206 mbed-rtos mbed

Fork of 4180_proj by ECE4180proj

Committer:
hanjiex
Date:
Mon Dec 07 18:41:29 2015 +0000
Revision:
13:4cec0e446def
Parent:
12:b6265952fb06
111

Who changed what in which revision?

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