Project

Dependencies:   4DGL-uLCD-SE MAX31855 mbed-rtos mbed

Fork of Coffee_Roaster by Eric Patterson

Committer:
ericspatterson
Date:
Thu Nov 20 04:01:51 2014 +0000
Revision:
7:8a0223a951c1
Parent:
3:0f0e79eff4a7
a bit slow, but the controls work now...

Who changed what in which revision?

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