Final Game. Have fun!!! :-)

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

Committer:
bricecroxton
Date:
Wed Mar 16 19:13:19 2016 +0000
Revision:
0:71e79407f6d5
Tap Tap Revenge Mbed

Who changed what in which revision?

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