Lab that has to do with basic IO on mbed.

Dependencies:   DebounceIn mbed PinDetect

Committer:
Jesse Baker
Date:
Sun Jan 24 16:45:15 2016 -0500
Revision:
53:1c8235c49b70
Parent:
46:7775a1ff6915
JB is about to test expansion

Who changed what in which revision?

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