Tetris game for mbed.

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

Fork of HelloWorld by Simon Ford

Committer:
greiner218
Date:
Mon Nov 07 07:18:59 2016 +0000
Revision:
3:803d3e67513f
Parent:
2:36cda8980746
Added .wav file

Who changed what in which revision?

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