Laser

Dependencies:   USBMIDI mbed

Fork of USBMIDI_HelloWorld by Simon Ford

Committer:
ywang627
Date:
Tue Dec 09 00:03:45 2014 +0000
Revision:
2:21f0ae3bef8a
Parent:
1:2b551cb862fe
Code for Laser Harp Implementation with MBed.

Who changed what in which revision?

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