an mbed tile music game using a capacitive touchpad and uLCD

Dependencies:   SDFileSystem mbed wave_player

Committer:
clu67
Date:
Mon Mar 14 00:26:24 2016 +0000
Revision:
0:a1c374b9a4fe
Initial Release

Who changed what in which revision?

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