Poker code for Secondary Mbed

Dependencies:   NokiaLCD mbed

Committer:
wjenkins7
Date:
Wed Dec 11 07:07:19 2013 +0000
Revision:
0:1324145f6904
Mbed Poker Secondary

Who changed what in which revision?

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