Martin Sturm / Mbed 2 deprecated Project

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mpr121.h Source File

mpr121.h

00001 /*
00002 Copyright (c) 2011 Anthony Buckton (abuckton [at] blackink [dot} net {dot} au)
00003 
00004  
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011  
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014  
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022 
00023    Parts written by Jim Lindblom of Sparkfun
00024    Ported to mbed by A.Buckton, Feb 2011
00025 */
00026 
00027 #ifndef MPR121_H
00028 #define MPR121_H
00029 
00030 //using namespace std;
00031 
00032 class Mpr121 
00033 {
00034 
00035 public:
00036     // i2c Addresses, bit-shifted
00037     enum Address { ADD_VSS = 0xb4,// 
00038                    //ADD_VSS = 0x5a,// <-wiring on Sparkfun board
00039                    ADD_VDD = 0xb6,// 
00040                    //ADD_VDD = 0x5b,
00041                    ADD_SCL = 0xb8,// 
00042                    //ADD_SDA = 0x5c,
00043                    ADD_SDA = 0xba //
00044                    //ADD_SCL = 0x5d
00045                  };
00046 
00047     // Real initialiser, takes the i2c address of the device.
00048     Mpr121(I2C *i2c, Address i2cAddress);
00049     
00050     bool getProximityMode();
00051     
00052     void setProximityMode(bool mode);
00053     
00054     int readTouchData();
00055                
00056     unsigned char read(int key);
00057     
00058     int write(int address, unsigned char value);
00059     int writeMany(int start, unsigned char* dataSet, int length);
00060 
00061     void setElectrodeThreshold(int electrodeId, unsigned char touchThreshold, unsigned char releaseThreshold);
00062         
00063 protected:
00064     // Configures the MPR with standard settings. This is permitted to be overwritten by sub-classes.
00065     void configureSettings();
00066     
00067 private:
00068     // The I2C bus instance.
00069     I2C *i2c;
00070 
00071     // i2c address of this mpr121
00072     Address address;
00073 };
00074 
00075 
00076 // MPR121 Register Defines
00077 #define    MHD_R        0x2B
00078 #define    NHD_R        0x2C
00079 #define    NCL_R        0x2D
00080 #define    FDL_R        0x2E
00081 #define    MHD_F        0x2F
00082 #define    NHD_F        0x30
00083 #define    NCL_F        0x31
00084 #define    FDL_F        0x32
00085 #define    NHDT         0x33
00086 #define    NCLT         0x34
00087 #define    FDLT         0x35
00088 // Proximity sensing controls
00089 #define    MHDPROXR     0x36
00090 #define    NHDPROXR     0x37
00091 #define    NCLPROXR     0x38
00092 #define    FDLPROXR     0x39
00093 #define    MHDPROXF     0x3A
00094 #define    NHDPROXF     0x3B
00095 #define    NCLPROXF     0x3C
00096 #define    FDLPROXF     0x3D
00097 #define    NHDPROXT     0x3E
00098 #define    NCLPROXT     0x3F
00099 #define    FDLPROXT     0x40
00100 // Electrode Touch/Release thresholds
00101 #define    ELE0_T       0x41
00102 #define    ELE0_R       0x42
00103 #define    ELE1_T       0x43
00104 #define    ELE1_R       0x44
00105 #define    ELE2_T       0x45
00106 #define    ELE2_R       0x46
00107 #define    ELE3_T       0x47
00108 #define    ELE3_R       0x48
00109 #define    ELE4_T       0x49
00110 #define    ELE4_R       0x4A
00111 #define    ELE5_T       0x4B
00112 #define    ELE5_R       0x4C
00113 #define    ELE6_T       0x4D
00114 #define    ELE6_R       0x4E
00115 #define    ELE7_T       0x4F
00116 #define    ELE7_R       0x50
00117 #define    ELE8_T       0x51
00118 #define    ELE8_R       0x52
00119 #define    ELE9_T       0x53
00120 #define    ELE9_R       0x54
00121 #define    ELE10_T      0x55
00122 #define    ELE10_R      0x56
00123 #define    ELE11_T      0x57
00124 #define    ELE11_R      0x58
00125 // Proximity Touch/Release thresholds
00126 #define    EPROXTTH     0x59
00127 #define    EPROXRTH     0x5A
00128 // Debounce configuration
00129 #define    DEB_CFG      0x5B
00130 // AFE- Analogue Front End configuration
00131 #define    AFE_CFG      0x5C 
00132 // Filter configuration
00133 #define    FIL_CFG      0x5D
00134 // Electrode configuration - transistions to "active mode"
00135 #define    ELE_CFG      0x5E
00136 
00137 #define GPIO_CTRL0      0x73
00138 #define GPIO_CTRL1      0x74
00139 #define GPIO_DATA       0x75
00140 #define    GPIO_DIR     0x76
00141 #define    GPIO_EN      0x77
00142 #define    GPIO_SET     0x78
00143 #define GPIO_CLEAR      0x79
00144 #define GPIO_TOGGLE     0x7A
00145 // Auto configration registers
00146 #define    AUTO_CFG_0   0x7B
00147 #define    AUTO_CFG_U   0x7D
00148 #define    AUTO_CFG_L   0x7E
00149 #define    AUTO_CFG_T   0x7F
00150 
00151 // Threshold defaults
00152 // Electrode touch threshold
00153 #define    E_THR_T      0x2F//0x0F   
00154 // Electrode release threshold 
00155 #define    E_THR_R      0x12//0x0A    
00156 // Prox touch threshold
00157 #define    PROX_THR_T   0x02
00158 // Prox release threshold
00159 #define    PROX_THR_R   0x02
00160 
00161 #endif