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