A Card Matching Game using uLCD and Touchpad

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

Committer:
mtaylor33
Date:
Wed Oct 22 00:12:42 2014 +0000
Revision:
0:d77e1909cdc7
Card Match Game

Who changed what in which revision?

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