ECE 4180 Final

Dependencies:   mbed wave_player mbed-rtos C12832_lcd 4DGL-uLCD-SE LCD_fonts SDFileSystem

Committer:
yqin70
Date:
Sun Dec 08 02:18:30 2019 +0000
Revision:
21:cbcbb3480cad
Parent:
16:13b65f6139be
somewhat done(pushbutton added, has an issue where if you spam the touchpad, it'll increase your score even if there is no bubble).

Who changed what in which revision?

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