MP3 Player with touch panel interface and LCD display.

Dependencies:   TextLCD mbed SDFileSystem

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,// ADD->VSS = 0x5a <-wiring on Sparkfun board
00038                    ADD_VDD = 0xb6,// ADD->VDD = 0x5b
00039                    ADD_SCL = 0xb8,// ADD->SDA = 0x5c
00040                    ADD_SDA = 0xba // ADD->SCL = 0x5d
00041                  };
00042 
00043     // Real initialiser, takes the i2c address of the device.
00044     Mpr121(I2C *i2c, Address i2cAddress);
00045     
00046     bool getProximityMode();
00047     
00048     void setProximityMode(bool mode);
00049     
00050     int readTouchData();
00051                
00052     unsigned char read(int key);
00053     
00054     int write(int address, unsigned char value);
00055     int writeMany(int start, unsigned char* dataSet, int length);
00056 
00057     void setElectrodeThreshold(int electrodeId, unsigned char touchThreshold, unsigned char releaseThreshold);
00058         
00059 protected:
00060     // Configures the MPR with standard settings. This is permitted to be overwritten by sub-classes.
00061     void configureSettings();
00062     
00063 private:
00064     // The I2C bus instance.
00065     I2C *i2c;
00066 
00067     // i2c address of this mpr121
00068     Address address;
00069 };
00070 
00071 
00072 // MPR121 Register Defines
00073 #define    MHD_R        0x2B
00074 #define    NHD_R        0x2C
00075 #define    NCL_R        0x2D
00076 #define    FDL_R        0x2E
00077 #define    MHD_F        0x2F
00078 #define    NHD_F        0x30
00079 #define    NCL_F        0x31
00080 #define    FDL_F        0x32
00081 #define    NHDT         0x33
00082 #define    NCLT         0x34
00083 #define    FDLT         0x35
00084 // Proximity sensing controls
00085 #define    MHDPROXR     0x36
00086 #define    NHDPROXR     0x37
00087 #define    NCLPROXR     0x38
00088 #define    FDLPROXR     0x39
00089 #define    MHDPROXF     0x3A
00090 #define    NHDPROXF     0x3B
00091 #define    NCLPROXF     0x3C
00092 #define    FDLPROXF     0x3D
00093 #define    NHDPROXT     0x3E
00094 #define    NCLPROXT     0x3F
00095 #define    FDLPROXT     0x40
00096 // Electrode Touch/Release thresholds
00097 #define    ELE0_T       0x41
00098 #define    ELE0_R       0x42
00099 #define    ELE1_T       0x43
00100 #define    ELE1_R       0x44
00101 #define    ELE2_T       0x45
00102 #define    ELE2_R       0x46
00103 #define    ELE3_T       0x47
00104 #define    ELE3_R       0x48
00105 #define    ELE4_T       0x49
00106 #define    ELE4_R       0x4A
00107 #define    ELE5_T       0x4B
00108 #define    ELE5_R       0x4C
00109 #define    ELE6_T       0x4D
00110 #define    ELE6_R       0x4E
00111 #define    ELE7_T       0x4F
00112 #define    ELE7_R       0x50
00113 #define    ELE8_T       0x51
00114 #define    ELE8_R       0x52
00115 #define    ELE9_T       0x53
00116 #define    ELE9_R       0x54
00117 #define    ELE10_T      0x55
00118 #define    ELE10_R      0x56
00119 #define    ELE11_T      0x57
00120 #define    ELE11_R      0x58
00121 // Proximity Touch/Release thresholds
00122 #define    EPROXTTH     0x59
00123 #define    EPROXRTH     0x5A
00124 // Debounce configuration
00125 #define    DEB_CFG      0x5B
00126 // AFE- Analogue Front End configuration
00127 #define    AFE_CFG      0x5C 
00128 // Filter configuration
00129 #define    FIL_CFG      0x5D
00130 // Electrode configuration - transistions to "active mode"
00131 #define    ELE_CFG      0x5E
00132 
00133 #define GPIO_CTRL0      0x73
00134 #define GPIO_CTRL1      0x74
00135 #define GPIO_DATA       0x75
00136 #define    GPIO_DIR     0x76
00137 #define    GPIO_EN      0x77
00138 #define    GPIO_SET     0x78
00139 #define GPIO_CLEAR      0x79
00140 #define GPIO_TOGGLE     0x7A
00141 // Auto configration registers
00142 #define    AUTO_CFG_0   0x7B
00143 #define    AUTO_CFG_U   0x7D
00144 #define    AUTO_CFG_L   0x7E
00145 #define    AUTO_CFG_T   0x7F
00146 
00147 // Threshold defaults
00148 // Electrode touch threshold
00149 #define    E_THR_T      0x0F   
00150 // Electrode release threshold 
00151 #define    E_THR_R      0x0A    
00152 // Prox touch threshold
00153 #define    PROX_THR_T   0x02
00154 // Prox release threshold
00155 #define    PROX_THR_R   0x02
00156 
00157 #endif