Multi-game multiplayer arcade gaming system meant for the blue O when playing Super Tic-Tac-Toe.

Dependencies:   4DGL-uLCD-SE PinDetect SDFileSystem mbed wave_player

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