MMA8451Q8g
Fork of MMA8451Q8b by
MMA8451Q8g.h@9:3229b6691c89, 2015-02-09 (annotated)
- Committer:
- scohennm
- Date:
- Mon Feb 09 20:05:35 2015 +0000
- Revision:
- 9:3229b6691c89
- Child:
- 12:12b18fdb72f7
Update for generic tap program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
scohennm | 9:3229b6691c89 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
scohennm | 9:3229b6691c89 | 2 | * |
scohennm | 9:3229b6691c89 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
scohennm | 9:3229b6691c89 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
scohennm | 9:3229b6691c89 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
scohennm | 9:3229b6691c89 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
scohennm | 9:3229b6691c89 | 7 | * Software is furnished to do so, subject to the following conditions: |
scohennm | 9:3229b6691c89 | 8 | * |
scohennm | 9:3229b6691c89 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
scohennm | 9:3229b6691c89 | 10 | * substantial portions of the Software. |
scohennm | 9:3229b6691c89 | 11 | * |
scohennm | 9:3229b6691c89 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
scohennm | 9:3229b6691c89 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
scohennm | 9:3229b6691c89 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
scohennm | 9:3229b6691c89 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
scohennm | 9:3229b6691c89 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
scohennm | 9:3229b6691c89 | 17 | */ |
scohennm | 9:3229b6691c89 | 18 | |
scohennm | 9:3229b6691c89 | 19 | #ifndef MMA8451Q_H |
scohennm | 9:3229b6691c89 | 20 | #define MMA8451Q_H |
scohennm | 9:3229b6691c89 | 21 | |
scohennm | 9:3229b6691c89 | 22 | #include "mbed.h" |
scohennm | 9:3229b6691c89 | 23 | |
scohennm | 9:3229b6691c89 | 24 | /** |
scohennm | 9:3229b6691c89 | 25 | * MMA8451Q accelerometer example |
scohennm | 9:3229b6691c89 | 26 | * |
scohennm | 9:3229b6691c89 | 27 | * @code |
scohennm | 9:3229b6691c89 | 28 | * #include "mbed.h" |
scohennm | 9:3229b6691c89 | 29 | * #include "MMA8451Q.h" |
scohennm | 9:3229b6691c89 | 30 | * |
scohennm | 9:3229b6691c89 | 31 | * #define MMA8451_I2C_ADDRESS (0x1d<<1) |
scohennm | 9:3229b6691c89 | 32 | * |
scohennm | 9:3229b6691c89 | 33 | * int main(void) { |
scohennm | 9:3229b6691c89 | 34 | * |
scohennm | 9:3229b6691c89 | 35 | * MMA8451Q acc(P_E25, P_E24, MMA8451_I2C_ADDRESS); |
scohennm | 9:3229b6691c89 | 36 | * PwmOut rled(LED_RED); |
scohennm | 9:3229b6691c89 | 37 | * PwmOut gled(LED_GREEN); |
scohennm | 9:3229b6691c89 | 38 | * PwmOut bled(LED_BLUE); |
scohennm | 9:3229b6691c89 | 39 | * |
scohennm | 9:3229b6691c89 | 40 | * while (true) { |
scohennm | 9:3229b6691c89 | 41 | * rled = 1.0 - abs(acc.getAccX()); |
scohennm | 9:3229b6691c89 | 42 | * gled = 1.0 - abs(acc.getAccY()); |
scohennm | 9:3229b6691c89 | 43 | * bled = 1.0 - abs(acc.getAccZ()); |
scohennm | 9:3229b6691c89 | 44 | * wait(0.1); |
scohennm | 9:3229b6691c89 | 45 | * } |
scohennm | 9:3229b6691c89 | 46 | * } |
scohennm | 9:3229b6691c89 | 47 | * @endcode |
scohennm | 9:3229b6691c89 | 48 | */ |
scohennm | 9:3229b6691c89 | 49 | class MMA8451Q |
scohennm | 9:3229b6691c89 | 50 | { |
scohennm | 9:3229b6691c89 | 51 | public: |
scohennm | 9:3229b6691c89 | 52 | /** |
scohennm | 9:3229b6691c89 | 53 | * MMA8451Q constructor |
scohennm | 9:3229b6691c89 | 54 | * |
scohennm | 9:3229b6691c89 | 55 | * @param sda SDA pin |
scohennm | 9:3229b6691c89 | 56 | * @param sdl SCL pin |
scohennm | 9:3229b6691c89 | 57 | * @param addr addr of the I2C peripheral |
scohennm | 9:3229b6691c89 | 58 | */ |
scohennm | 9:3229b6691c89 | 59 | MMA8451Q(PinName sda, PinName scl, int addr); |
scohennm | 9:3229b6691c89 | 60 | |
scohennm | 9:3229b6691c89 | 61 | /** |
scohennm | 9:3229b6691c89 | 62 | * MMA8451Q destructor |
scohennm | 9:3229b6691c89 | 63 | */ |
scohennm | 9:3229b6691c89 | 64 | ~MMA8451Q(); |
scohennm | 9:3229b6691c89 | 65 | |
scohennm | 9:3229b6691c89 | 66 | /** |
scohennm | 9:3229b6691c89 | 67 | * Get the value of the WHO_AM_I register |
scohennm | 9:3229b6691c89 | 68 | * |
scohennm | 9:3229b6691c89 | 69 | * @returns WHO_AM_I value |
scohennm | 9:3229b6691c89 | 70 | */ |
scohennm | 9:3229b6691c89 | 71 | uint8_t getWhoAmI(); |
scohennm | 9:3229b6691c89 | 72 | |
scohennm | 9:3229b6691c89 | 73 | /** |
scohennm | 9:3229b6691c89 | 74 | * Get X axis acceleration |
scohennm | 9:3229b6691c89 | 75 | * |
scohennm | 9:3229b6691c89 | 76 | * @returns X axis acceleration |
scohennm | 9:3229b6691c89 | 77 | */ |
scohennm | 9:3229b6691c89 | 78 | float getAccX(); |
scohennm | 9:3229b6691c89 | 79 | |
scohennm | 9:3229b6691c89 | 80 | uint16_t igetAccX(); |
scohennm | 9:3229b6691c89 | 81 | |
scohennm | 9:3229b6691c89 | 82 | /** |
scohennm | 9:3229b6691c89 | 83 | * Get Y axis acceleration |
scohennm | 9:3229b6691c89 | 84 | * |
scohennm | 9:3229b6691c89 | 85 | * @returns Y axis acceleration |
scohennm | 9:3229b6691c89 | 86 | */ |
scohennm | 9:3229b6691c89 | 87 | float getAccY(); |
scohennm | 9:3229b6691c89 | 88 | |
scohennm | 9:3229b6691c89 | 89 | /** |
scohennm | 9:3229b6691c89 | 90 | * Get Z axis acceleration |
scohennm | 9:3229b6691c89 | 91 | * |
scohennm | 9:3229b6691c89 | 92 | * @returns Z axis acceleration |
scohennm | 9:3229b6691c89 | 93 | */ |
scohennm | 9:3229b6691c89 | 94 | float getAccZ(); |
scohennm | 9:3229b6691c89 | 95 | |
scohennm | 9:3229b6691c89 | 96 | /** |
scohennm | 9:3229b6691c89 | 97 | * Get XYZ axis acceleration |
scohennm | 9:3229b6691c89 | 98 | * |
scohennm | 9:3229b6691c89 | 99 | * @param res array where acceleration data will be stored |
scohennm | 9:3229b6691c89 | 100 | */ |
scohennm | 9:3229b6691c89 | 101 | void getAccAllAxis(float * res); |
scohennm | 9:3229b6691c89 | 102 | |
scohennm | 9:3229b6691c89 | 103 | int16_t getAccAxis(uint8_t addr); |
scohennm | 9:3229b6691c89 | 104 | |
scohennm | 9:3229b6691c89 | 105 | I2C m_i2c; |
scohennm | 9:3229b6691c89 | 106 | int m_addr; |
scohennm | 9:3229b6691c89 | 107 | int gChosen; |
scohennm | 9:3229b6691c89 | 108 | |
scohennm | 9:3229b6691c89 | 109 | /** |
scohennm | 9:3229b6691c89 | 110 | Allow user to set max g's |
scohennm | 9:3229b6691c89 | 111 | **/ |
scohennm | 9:3229b6691c89 | 112 | void setGLimit(int gSelect); |
scohennm | 9:3229b6691c89 | 113 | // added in .cpp file for tap configuration |
scohennm | 9:3229b6691c89 | 114 | /** |
scohennm | 9:3229b6691c89 | 115 | Set pulse config register |
scohennm | 9:3229b6691c89 | 116 | **/ |
scohennm | 9:3229b6691c89 | 117 | void setPulseConfiguration(uint8_t latch,uint8_t axisSet); |
scohennm | 9:3229b6691c89 | 118 | /** |
scohennm | 9:3229b6691c89 | 119 | Generic register set mode for those needing to be |
scohennm | 9:3229b6691c89 | 120 | put in standby to update |
scohennm | 9:3229b6691c89 | 121 | **/ |
scohennm | 9:3229b6691c89 | 122 | void setRegisterInStandby(uint8_t regAddress,uint8_t regData); |
scohennm | 9:3229b6691c89 | 123 | |
scohennm | 9:3229b6691c89 | 124 | void readRegs(int addr, uint8_t * data, int len); |
scohennm | 9:3229b6691c89 | 125 | void writeRegs(uint8_t * data, int len); |
scohennm | 9:3229b6691c89 | 126 | |
scohennm | 9:3229b6691c89 | 127 | private: |
scohennm | 9:3229b6691c89 | 128 | |
scohennm | 9:3229b6691c89 | 129 | |
scohennm | 9:3229b6691c89 | 130 | }; |
scohennm | 9:3229b6691c89 | 131 | |
scohennm | 9:3229b6691c89 | 132 | #endif |