IoT for mbed1

Dependencies:   4DGL-uLCD-SE IoTsecuritySys PinDetect mbed-rtos mbed

Fork of IoT by Tal Landes

Committer:
jsmith352
Date:
Tue Nov 24 20:15:53 2015 +0000
Revision:
0:04dcbfb4388c
Touch pad door lock with two phase authentication

Who changed what in which revision?

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