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