This is a MIDI synthesizer with touchpads used for playing the notes. mbed will capture the touchpad press and release events and sends the appropriate MIDI commands to the PC. By using the C# windows forms application created by us, one can compose songs as though they were composed on a piano. We support all types of standard MIDI piano types.

Dependencies:   mbed

Committer:
thejasvi3
Date:
Thu Oct 13 06:17:30 2011 +0000
Revision:
0:e33f18af0471

        

Who changed what in which revision?

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