A Stock Exchange Game using IO devices, the 128x128 uLCD, and other components

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

Fork of WavePlayer_HelloWorld by jim hamblen

Committer:
RohanIyengar
Date:
Thu Nov 03 19:35:44 2016 +0000
Revision:
2:3585cd51c765
Created project

Who changed what in which revision?

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