Ye Qiu / Mbed 2 deprecated Tic_Tac_Toe_with_Touchpad

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

Fork of app-board-RTOS-Threads by jim hamblen

Committer:
ethan_wireless
Date:
Tue Oct 20 17:24:08 2015 +0000
Revision:
5:36b6ce2faf88
NA

Who changed what in which revision?

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