4180 Design project

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player

Committer:
asims35
Date:
Tue Dec 08 16:30:32 2015 +0000
Revision:
0:be32bcd5f29d
Design project for ECE4180

Who changed what in which revision?

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