Bop-It Game

Dependencies:   TextLCD mbed ADXL345 VS1053b

Committer:
jdumond3
Date:
Wed Oct 19 18:04:48 2011 +0000
Revision:
0:d16ac399135a

        

Who changed what in which revision?

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