ece 4180 project 2019

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

Committer:
rhuang77
Date:
Sat Apr 20 21:47:57 2019 +0000
Revision:
3:221fb009c1ac
Parent:
0:567492543056
finalizing details

Who changed what in which revision?

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