Glimit
Fork of MMA8451Q8 by
MMA8451Q.h@2:a077541cbadc, 2012-10-11 (annotated)
- Committer:
- samux
- Date:
- Thu Oct 11 14:28:23 2012 +0000
- Revision:
- 2:a077541cbadc
- Parent:
- 1:d2630136d51e
- Child:
- 3:db7126dbd63f
fixed doxygen program example
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 1:d2630136d51e | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
samux | 1:d2630136d51e | 2 | * |
samux | 1:d2630136d51e | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
samux | 1:d2630136d51e | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
samux | 1:d2630136d51e | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
samux | 1:d2630136d51e | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
samux | 1:d2630136d51e | 7 | * Software is furnished to do so, subject to the following conditions: |
samux | 1:d2630136d51e | 8 | * |
samux | 1:d2630136d51e | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
samux | 1:d2630136d51e | 10 | * substantial portions of the Software. |
samux | 1:d2630136d51e | 11 | * |
samux | 1:d2630136d51e | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
samux | 1:d2630136d51e | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
samux | 1:d2630136d51e | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
samux | 1:d2630136d51e | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
samux | 1:d2630136d51e | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
samux | 1:d2630136d51e | 17 | */ |
samux | 1:d2630136d51e | 18 | |
emilmont | 0:6149091f755d | 19 | #ifndef MMA8451Q_H |
emilmont | 0:6149091f755d | 20 | #define MMA8451Q_H |
emilmont | 0:6149091f755d | 21 | |
emilmont | 0:6149091f755d | 22 | #include "mbed.h" |
emilmont | 0:6149091f755d | 23 | |
samux | 1:d2630136d51e | 24 | /** |
samux | 1:d2630136d51e | 25 | * MMA8451Q accelerometer example |
samux | 2:a077541cbadc | 26 | * |
samux | 2:a077541cbadc | 27 | * @code |
samux | 1:d2630136d51e | 28 | * #include "mbed.h" |
samux | 1:d2630136d51e | 29 | * #include "MMA8451Q.h" |
samux | 1:d2630136d51e | 30 | * |
samux | 1:d2630136d51e | 31 | * #define MMA8451_I2C_ADDRESS (0x1d<<1) |
samux | 1:d2630136d51e | 32 | * |
samux | 1:d2630136d51e | 33 | * int main(void) { |
samux | 1:d2630136d51e | 34 | * DigitalOut led(LED_GREEN); |
samux | 1:d2630136d51e | 35 | * MMA8451Q acc(P_E25, P_E24, MMA8451_I2C_ADDRESS); |
samux | 1:d2630136d51e | 36 | * printf("WHO AM I: 0x%2X\r\n", acc.getWhoAmI()); |
samux | 1:d2630136d51e | 37 | * |
samux | 1:d2630136d51e | 38 | * while (true) { |
samux | 1:d2630136d51e | 39 | * printf("-----------\r\n"); |
samux | 1:d2630136d51e | 40 | * printf("acc_x: %d\r\n", acc.getAccX()); |
samux | 1:d2630136d51e | 41 | * printf("acc_y: %d\r\n", acc.getAccY()); |
samux | 1:d2630136d51e | 42 | * printf("acc_z: %d\r\n", acc.getAccZ()); |
samux | 1:d2630136d51e | 43 | * |
samux | 1:d2630136d51e | 44 | * wait(1); |
samux | 1:d2630136d51e | 45 | * led = !led; |
samux | 1:d2630136d51e | 46 | * } |
samux | 1:d2630136d51e | 47 | * } |
samux | 2:a077541cbadc | 48 | * @endcode |
samux | 1:d2630136d51e | 49 | */ |
emilmont | 0:6149091f755d | 50 | class MMA8451Q |
emilmont | 0:6149091f755d | 51 | { |
emilmont | 0:6149091f755d | 52 | public: |
samux | 1:d2630136d51e | 53 | /** |
samux | 1:d2630136d51e | 54 | * MMA8451Q constructor |
samux | 1:d2630136d51e | 55 | * |
samux | 1:d2630136d51e | 56 | * @param sda SDA pin |
samux | 1:d2630136d51e | 57 | * @param sdl SCL pin |
samux | 1:d2630136d51e | 58 | * @param addr addr of the I2C peripheral |
emilmont | 0:6149091f755d | 59 | */ |
emilmont | 0:6149091f755d | 60 | MMA8451Q(PinName sda, PinName scl, int addr); |
emilmont | 0:6149091f755d | 61 | |
samux | 1:d2630136d51e | 62 | /** |
samux | 1:d2630136d51e | 63 | * MMA8451Q destructor |
emilmont | 0:6149091f755d | 64 | */ |
emilmont | 0:6149091f755d | 65 | ~MMA8451Q(); |
emilmont | 0:6149091f755d | 66 | |
samux | 1:d2630136d51e | 67 | /** |
emilmont | 0:6149091f755d | 68 | * Get the value of the WHO_AM_I register |
emilmont | 0:6149091f755d | 69 | * |
samux | 1:d2630136d51e | 70 | * @returns WHO_AM_I value |
emilmont | 0:6149091f755d | 71 | */ |
emilmont | 0:6149091f755d | 72 | uint8_t getWhoAmI(); |
emilmont | 0:6149091f755d | 73 | |
samux | 1:d2630136d51e | 74 | /** |
emilmont | 0:6149091f755d | 75 | * Get X axis acceleration |
emilmont | 0:6149091f755d | 76 | * |
samux | 1:d2630136d51e | 77 | * @returns X axis acceleration |
emilmont | 0:6149091f755d | 78 | */ |
emilmont | 0:6149091f755d | 79 | int16_t getAccX(); |
emilmont | 0:6149091f755d | 80 | |
samux | 1:d2630136d51e | 81 | /** |
emilmont | 0:6149091f755d | 82 | * Get Y axis acceleration |
emilmont | 0:6149091f755d | 83 | * |
samux | 1:d2630136d51e | 84 | * @returns Y axis acceleration |
emilmont | 0:6149091f755d | 85 | */ |
emilmont | 0:6149091f755d | 86 | int16_t getAccY(); |
emilmont | 0:6149091f755d | 87 | |
samux | 1:d2630136d51e | 88 | /** |
emilmont | 0:6149091f755d | 89 | * Get Z axis acceleration |
emilmont | 0:6149091f755d | 90 | * |
samux | 1:d2630136d51e | 91 | * @returns Z axis acceleration |
emilmont | 0:6149091f755d | 92 | */ |
emilmont | 0:6149091f755d | 93 | int16_t getAccZ(); |
emilmont | 0:6149091f755d | 94 | |
samux | 1:d2630136d51e | 95 | /** |
emilmont | 0:6149091f755d | 96 | * Get XYZ axis acceleration |
emilmont | 0:6149091f755d | 97 | * |
samux | 1:d2630136d51e | 98 | * @param res array where acceleration data will be stored |
emilmont | 0:6149091f755d | 99 | */ |
samux | 1:d2630136d51e | 100 | void getAccAllAxis(int16_t * res); |
emilmont | 0:6149091f755d | 101 | |
emilmont | 0:6149091f755d | 102 | private: |
samux | 1:d2630136d51e | 103 | I2C m_i2c; |
emilmont | 0:6149091f755d | 104 | int m_addr; |
samux | 1:d2630136d51e | 105 | void readRegs(int addr, uint8_t * data, int len); |
samux | 1:d2630136d51e | 106 | void writeRegs(uint8_t * data, int len); |
emilmont | 0:6149091f755d | 107 | int16_t getAccAxis(uint8_t addr); |
emilmont | 0:6149091f755d | 108 | |
emilmont | 0:6149091f755d | 109 | }; |
emilmont | 0:6149091f755d | 110 | |
emilmont | 0:6149091f755d | 111 | #endif |