This is the vcdMaker demo project. See http://vcdmaker.org for details. vcdMaker is supposed to help engineers to debug their applications and systems. It transforms text log files into the VCD format which can be easily displayed as a waveform.

Dependencies:   mbed vcdLogger vcdSignal

Committer:
ketjow
Date:
Fri Feb 12 21:38:04 2016 +0000
Revision:
0:9a59cffaafad
vcdMaker demo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ketjow 0:9a59cffaafad 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
ketjow 0:9a59cffaafad 2 *
ketjow 0:9a59cffaafad 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ketjow 0:9a59cffaafad 4 * and associated documentation files (the "Software"), to deal in the Software without
ketjow 0:9a59cffaafad 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
ketjow 0:9a59cffaafad 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
ketjow 0:9a59cffaafad 7 * Software is furnished to do so, subject to the following conditions:
ketjow 0:9a59cffaafad 8 *
ketjow 0:9a59cffaafad 9 * The above copyright notice and this permission notice shall be included in all copies or
ketjow 0:9a59cffaafad 10 * substantial portions of the Software.
ketjow 0:9a59cffaafad 11 *
ketjow 0:9a59cffaafad 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ketjow 0:9a59cffaafad 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ketjow 0:9a59cffaafad 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ketjow 0:9a59cffaafad 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ketjow 0:9a59cffaafad 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ketjow 0:9a59cffaafad 17 */
ketjow 0:9a59cffaafad 18
ketjow 0:9a59cffaafad 19 #ifndef MMA8451Q_H
ketjow 0:9a59cffaafad 20 #define MMA8451Q_H
ketjow 0:9a59cffaafad 21
ketjow 0:9a59cffaafad 22 #include "mbed.h"
ketjow 0:9a59cffaafad 23
ketjow 0:9a59cffaafad 24 /**
ketjow 0:9a59cffaafad 25 * MMA8451Q accelerometer example
ketjow 0:9a59cffaafad 26 *
ketjow 0:9a59cffaafad 27 * @code
ketjow 0:9a59cffaafad 28 * #include "mbed.h"
ketjow 0:9a59cffaafad 29 * #include "MMA8451Q.h"
ketjow 0:9a59cffaafad 30 *
ketjow 0:9a59cffaafad 31 * #define MMA8451_I2C_ADDRESS (0x1d<<1)
ketjow 0:9a59cffaafad 32 *
ketjow 0:9a59cffaafad 33 * int main(void) {
ketjow 0:9a59cffaafad 34 *
ketjow 0:9a59cffaafad 35 * MMA8451Q acc(P_E25, P_E24, MMA8451_I2C_ADDRESS);
ketjow 0:9a59cffaafad 36 * PwmOut rled(LED_RED);
ketjow 0:9a59cffaafad 37 * PwmOut gled(LED_GREEN);
ketjow 0:9a59cffaafad 38 * PwmOut bled(LED_BLUE);
ketjow 0:9a59cffaafad 39 *
ketjow 0:9a59cffaafad 40 * while (true) {
ketjow 0:9a59cffaafad 41 * rled = 1.0 - abs(acc.getAccX());
ketjow 0:9a59cffaafad 42 * gled = 1.0 - abs(acc.getAccY());
ketjow 0:9a59cffaafad 43 * bled = 1.0 - abs(acc.getAccZ());
ketjow 0:9a59cffaafad 44 * wait(0.1);
ketjow 0:9a59cffaafad 45 * }
ketjow 0:9a59cffaafad 46 * }
ketjow 0:9a59cffaafad 47 * @endcode
ketjow 0:9a59cffaafad 48 */
ketjow 0:9a59cffaafad 49 class MMA8451Q
ketjow 0:9a59cffaafad 50 {
ketjow 0:9a59cffaafad 51 public:
ketjow 0:9a59cffaafad 52 /**
ketjow 0:9a59cffaafad 53 * MMA8451Q constructor
ketjow 0:9a59cffaafad 54 *
ketjow 0:9a59cffaafad 55 * @param sda SDA pin
ketjow 0:9a59cffaafad 56 * @param sdl SCL pin
ketjow 0:9a59cffaafad 57 * @param addr addr of the I2C peripheral
ketjow 0:9a59cffaafad 58 */
ketjow 0:9a59cffaafad 59 MMA8451Q(PinName sda, PinName scl, int addr);
ketjow 0:9a59cffaafad 60
ketjow 0:9a59cffaafad 61 /**
ketjow 0:9a59cffaafad 62 * MMA8451Q destructor
ketjow 0:9a59cffaafad 63 */
ketjow 0:9a59cffaafad 64 ~MMA8451Q();
ketjow 0:9a59cffaafad 65
ketjow 0:9a59cffaafad 66 /**
ketjow 0:9a59cffaafad 67 * Get the value of the WHO_AM_I register
ketjow 0:9a59cffaafad 68 *
ketjow 0:9a59cffaafad 69 * @returns WHO_AM_I value
ketjow 0:9a59cffaafad 70 */
ketjow 0:9a59cffaafad 71 uint8_t getWhoAmI();
ketjow 0:9a59cffaafad 72
ketjow 0:9a59cffaafad 73 /**
ketjow 0:9a59cffaafad 74 * Get X axis acceleration
ketjow 0:9a59cffaafad 75 *
ketjow 0:9a59cffaafad 76 * @returns X axis acceleration
ketjow 0:9a59cffaafad 77 */
ketjow 0:9a59cffaafad 78 float getAccX();
ketjow 0:9a59cffaafad 79
ketjow 0:9a59cffaafad 80 /**
ketjow 0:9a59cffaafad 81 * Get Y axis acceleration
ketjow 0:9a59cffaafad 82 *
ketjow 0:9a59cffaafad 83 * @returns Y axis acceleration
ketjow 0:9a59cffaafad 84 */
ketjow 0:9a59cffaafad 85 float getAccY();
ketjow 0:9a59cffaafad 86
ketjow 0:9a59cffaafad 87 /**
ketjow 0:9a59cffaafad 88 * Get Z axis acceleration
ketjow 0:9a59cffaafad 89 *
ketjow 0:9a59cffaafad 90 * @returns Z axis acceleration
ketjow 0:9a59cffaafad 91 */
ketjow 0:9a59cffaafad 92 float getAccZ();
ketjow 0:9a59cffaafad 93
ketjow 0:9a59cffaafad 94 /**
ketjow 0:9a59cffaafad 95 * Get XYZ axis acceleration
ketjow 0:9a59cffaafad 96 *
ketjow 0:9a59cffaafad 97 * @param res array where acceleration data will be stored
ketjow 0:9a59cffaafad 98 */
ketjow 0:9a59cffaafad 99 void getAccAllAxis(float * res);
ketjow 0:9a59cffaafad 100
ketjow 0:9a59cffaafad 101 /** JK
ketjow 0:9a59cffaafad 102 * Setup Double Tap detection
ketjow 0:9a59cffaafad 103
ketjow 0:9a59cffaafad 104
ketjow 0:9a59cffaafad 105 Example:
ketjow 0:9a59cffaafad 106
ketjow 0:9a59cffaafad 107 #include "mbed.h"
ketjow 0:9a59cffaafad 108 #include "MMA8451Q.h"
ketjow 0:9a59cffaafad 109
ketjow 0:9a59cffaafad 110 #define MMA8451_I2C_ADDRESS (0x1d<<1)
ketjow 0:9a59cffaafad 111 #define ON 0
ketjow 0:9a59cffaafad 112 #define OFF !ON
ketjow 0:9a59cffaafad 113
ketjow 0:9a59cffaafad 114 //Setup the interrupts for the MMA8451Q
ketjow 0:9a59cffaafad 115 InterruptIn accInt1(PTA14);
ketjow 0:9a59cffaafad 116 InterruptIn accInt2(PTA15);//not used in this prog but this is the other int from the accelorometer
ketjow 0:9a59cffaafad 117
ketjow 0:9a59cffaafad 118 uint8_t togstat=0;//Led status
ketjow 0:9a59cffaafad 119 DigitalOut bled(LED_BLUE);
ketjow 0:9a59cffaafad 120
ketjow 0:9a59cffaafad 121
ketjow 0:9a59cffaafad 122 void tapTrue(void){//ISR
ketjow 0:9a59cffaafad 123 if(togstat == 0){
ketjow 0:9a59cffaafad 124 togstat = 1;
ketjow 0:9a59cffaafad 125 bled=ON;
ketjow 0:9a59cffaafad 126 } else {
ketjow 0:9a59cffaafad 127 togstat = 0;
ketjow 0:9a59cffaafad 128 bled=OFF;
ketjow 0:9a59cffaafad 129 }
ketjow 0:9a59cffaafad 130
ketjow 0:9a59cffaafad 131 }
ketjow 0:9a59cffaafad 132
ketjow 0:9a59cffaafad 133
ketjow 0:9a59cffaafad 134 int main(void) {
ketjow 0:9a59cffaafad 135
ketjow 0:9a59cffaafad 136 MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);//accelorometer instance
ketjow 0:9a59cffaafad 137
ketjow 0:9a59cffaafad 138 acc.setDoubleTap();//Setup the MMA8451Q to look for a double Tap
ketjow 0:9a59cffaafad 139 accInt1.rise(&tapTrue);//call tapTrue when an interrupt is generated on PTA14
ketjow 0:9a59cffaafad 140
ketjow 0:9a59cffaafad 141 while (true) {
ketjow 0:9a59cffaafad 142 //Interrupt driven so nothing in main loop
ketjow 0:9a59cffaafad 143 }
ketjow 0:9a59cffaafad 144 }
ketjow 0:9a59cffaafad 145
ketjow 0:9a59cffaafad 146
ketjow 0:9a59cffaafad 147 */
ketjow 0:9a59cffaafad 148 void setDoubleTap(void);
ketjow 0:9a59cffaafad 149
ketjow 0:9a59cffaafad 150 private:
ketjow 0:9a59cffaafad 151 I2C m_i2c;
ketjow 0:9a59cffaafad 152 int m_addr;
ketjow 0:9a59cffaafad 153 void readRegs(int addr, uint8_t * data, int len);
ketjow 0:9a59cffaafad 154 void writeRegs(uint8_t * data, int len);
ketjow 0:9a59cffaafad 155 int16_t getAccAxis(uint8_t addr);
ketjow 0:9a59cffaafad 156
ketjow 0:9a59cffaafad 157 };
ketjow 0:9a59cffaafad 158
ketjow 0:9a59cffaafad 159 #endif