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