]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/tests/peripherals/MMA7660/MMA7660.h
1 /* Copyright (c) <year> <copyright holders>, MIT License
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 restriction,
5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
7 * furnished to do so, subject to the following conditions:
9 * The above copyright notice and this permission notice shall be included in all copies or
10 * substantial portions of the Software.
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.
25 #define MMA7660_ADDRESS 0x98
26 #define MMA7660_SENSITIVITY 21.33
28 #define MMA7660_XOUT_R 0x00
29 #define MMA7660_YOUT_R 0x01
30 #define MMA7660_ZOUT_R 0x02
31 #define MMA7660_TILT_R 0x03
32 #define MMA7660_INT_R 0x06
33 #define MMA7660_MODE_R 0x07
34 #define MMA7660_SR_R 0x08
37 /** An interface for the MMA7660 triple axis accelerometer
40 * //Uses the measured z-acceleration to drive leds 2 and 3 of the mbed
43 * #include "MMA7660.h"
45 * MMA7660 MMA(p28, p27);
47 * DigitalOut connectionLed(LED1);
48 * PwmOut Zaxis_p(LED2);
49 * PwmOut Zaxis_n(LED3);
52 * if (MMA.testConnection())
67 * The 6 different orientations and unknown
70 * Right & Left = Y-axis
71 * Back & Front = Z-axis
74 enum Orientation
{Up
, Down
,
81 * Creates a new MMA7660 object
83 * @param sda - I2C data pin
84 * @param scl - I2C clock pin
85 * @param active - true (default) to enable the device, false to keep it standby
87 MMA7660(PinName sda
, PinName scl
, bool active
= true);
90 * Tests if communication is possible with the MMA7660
92 * Because the MMA7660 lacks a WHO_AM_I register, this function can only check
93 * if there is an I2C device that responds to the MMA7660 address
95 * @param return - true for successfull connection, false for no connection
97 bool testConnection( void );
100 * Sets the active state of the MMA7660
102 * Note: This is unrelated to awake/sleep mode
104 * @param state - true for active, false for standby
106 void setActive( bool state
);
109 * Reads acceleration data from the sensor
111 * When the parameter is a pointer to an integer array it will be the raw data.
112 * When it is a pointer to a float array it will be the acceleration in g's
114 * @param data - pointer to array with length 3 where the acceleration data will be stored, X-Y-Z
116 void readData( int *data
);
117 void readData( float *data
);
122 * @param return - X-acceleration in g's
129 * @param return - Y-acceleration in g's
136 * @param return - Z-acceleration in g's
141 * Sets the active samplerate
143 * The entered samplerate will be rounded to nearest supported samplerate.
144 * Supported samplerates are: 120 - 64 - 32 - 16 - 8 - 4 - 2 - 1 samples/second.
146 * @param samplerate - the samplerate that will be set
148 void setSampleRate(int samplerate
);
151 * Returns if it is on its front, back, or unknown side
153 * This is read from MMA7760s registers, page 12 of datasheet
155 * @param return - Front, Back or Unknown orientation
157 Orientation
getSide( void );
160 * Returns if it is on it left, right, down or up side
162 * This is read from MMA7760s registers, page 12 of datasheet
164 * @param return - Left, Right, Down, Up or Unknown orientation
166 Orientation
getOrientation ( void );
172 * Writes data to the device
174 * @param adress - register address to write to
175 * @param data - data to write
177 void write( char address
, char data
);
180 * Read data from the device
182 * @param adress - register address to write to
183 * @return - data from the register specified by RA
185 char read( char adress
);
188 * Read multiple regigsters from the device, more efficient than using multiple normal reads.
190 * @param adress - register address to write to
191 * @param length - number of bytes to read
192 * @param data - pointer where the data needs to be written to
194 void read( char adress
, char *data
, int length
);
199 float getSingle(int number
);