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