A work in progress on an updated library

Dependents:   FRDM_N3110LCD test

Fork of MMA8451Q by Emilio Monti

Committer:
SomeRandomBloke
Date:
Wed Mar 27 22:00:57 2013 +0000
Revision:
6:e8bacad228f6
Parent:
5:d813fe6c0c70
updates

Who changed what in which revision?

UserRevisionLine numberNew 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"
SomeRandomBloke 5:d813fe6c0c70 30 *
samux 1:d2630136d51e 31 * #define MMA8451_I2C_ADDRESS (0x1d<<1)
SomeRandomBloke 5:d813fe6c0c70 32 *
chris 4:c4d879a39775 33 * int main(void) {
SomeRandomBloke 5:d813fe6c0c70 34 *
chris 3:db7126dbd63f 35 * MMA8451Q acc(P_E25, P_E24, MMA8451_I2C_ADDRESS);
chris 3:db7126dbd63f 36 * PwmOut rled(LED_RED);
chris 3:db7126dbd63f 37 * PwmOut gled(LED_GREEN);
chris 3:db7126dbd63f 38 * PwmOut bled(LED_BLUE);
SomeRandomBloke 5:d813fe6c0c70 39 *
SomeRandomBloke 5:d813fe6c0c70 40 * while (true) {
chris 3:db7126dbd63f 41 * rled = 1.0 - abs(acc.getAccX());
chris 3:db7126dbd63f 42 * gled = 1.0 - abs(acc.getAccY());
chris 3:db7126dbd63f 43 * bled = 1.0 - abs(acc.getAccZ());
chris 3:db7126dbd63f 44 * wait(0.1);
chris 3:db7126dbd63f 45 * }
samux 1:d2630136d51e 46 * }
samux 2:a077541cbadc 47 * @endcode
samux 1:d2630136d51e 48 */
emilmont 0:6149091f755d 49 class MMA8451Q
emilmont 0:6149091f755d 50 {
emilmont 0:6149091f755d 51 public:
SomeRandomBloke 5:d813fe6c0c70 52 /**
SomeRandomBloke 5:d813fe6c0c70 53 * MMA8451Q constructor
SomeRandomBloke 5:d813fe6c0c70 54 *
SomeRandomBloke 5:d813fe6c0c70 55 * @param sda SDA pin
SomeRandomBloke 5:d813fe6c0c70 56 * @param sdl SCL pin
SomeRandomBloke 5:d813fe6c0c70 57 * @param addr addr of the I2C peripheral
SomeRandomBloke 5:d813fe6c0c70 58 */
SomeRandomBloke 5:d813fe6c0c70 59 MMA8451Q(PinName sda, PinName scl, int addr, bool highres, uint8_t scale);
emilmont 0:6149091f755d 60
SomeRandomBloke 5:d813fe6c0c70 61 /**
SomeRandomBloke 5:d813fe6c0c70 62 * MMA8451Q destructor
SomeRandomBloke 5:d813fe6c0c70 63 */
SomeRandomBloke 5:d813fe6c0c70 64 ~MMA8451Q();
emilmont 0:6149091f755d 65
SomeRandomBloke 5:d813fe6c0c70 66 /**
SomeRandomBloke 5:d813fe6c0c70 67 * Get the value of the WHO_AM_I register
SomeRandomBloke 5:d813fe6c0c70 68 *
SomeRandomBloke 5:d813fe6c0c70 69 * @returns WHO_AM_I value
SomeRandomBloke 5:d813fe6c0c70 70 */
SomeRandomBloke 5:d813fe6c0c70 71 uint8_t getWhoAmI();
emilmont 0:6149091f755d 72
SomeRandomBloke 5:d813fe6c0c70 73 /**
SomeRandomBloke 5:d813fe6c0c70 74 * Get X axis acceleration
SomeRandomBloke 5:d813fe6c0c70 75 *
SomeRandomBloke 5:d813fe6c0c70 76 * @returns X axis acceleration
SomeRandomBloke 5:d813fe6c0c70 77 */
SomeRandomBloke 5:d813fe6c0c70 78 float getAccX();
emilmont 0:6149091f755d 79
SomeRandomBloke 5:d813fe6c0c70 80 /**
SomeRandomBloke 5:d813fe6c0c70 81 * Get Y axis acceleration
SomeRandomBloke 5:d813fe6c0c70 82 *
SomeRandomBloke 5:d813fe6c0c70 83 * @returns Y axis acceleration
SomeRandomBloke 5:d813fe6c0c70 84 */
SomeRandomBloke 5:d813fe6c0c70 85 float getAccY();
emilmont 0:6149091f755d 86
SomeRandomBloke 5:d813fe6c0c70 87 /**
SomeRandomBloke 5:d813fe6c0c70 88 * Get Z axis acceleration
SomeRandomBloke 5:d813fe6c0c70 89 *
SomeRandomBloke 5:d813fe6c0c70 90 * @returns Z axis acceleration
SomeRandomBloke 5:d813fe6c0c70 91 */
SomeRandomBloke 5:d813fe6c0c70 92 float getAccZ();
emilmont 0:6149091f755d 93
SomeRandomBloke 5:d813fe6c0c70 94 /**
SomeRandomBloke 5:d813fe6c0c70 95 * Get XYZ axis acceleration
SomeRandomBloke 5:d813fe6c0c70 96 *
SomeRandomBloke 5:d813fe6c0c70 97 * @param res array where acceleration data will be stored
SomeRandomBloke 5:d813fe6c0c70 98 */
SomeRandomBloke 5:d813fe6c0c70 99 void getAccAllAxis(float * res);
emilmont 0:6149091f755d 100
emilmont 0:6149091f755d 101 private:
SomeRandomBloke 5:d813fe6c0c70 102 I2C m_i2c;
SomeRandomBloke 5:d813fe6c0c70 103 int m_addr;
SomeRandomBloke 5:d813fe6c0c70 104 void readRegs(int addr, uint8_t * data, int len);
SomeRandomBloke 5:d813fe6c0c70 105 void writeRegs(uint8_t * data, int len);
SomeRandomBloke 5:d813fe6c0c70 106 int16_t getAccAxis(uint8_t addr);
SomeRandomBloke 5:d813fe6c0c70 107 float getAccAxisF(uint8_t addr);
SomeRandomBloke 5:d813fe6c0c70 108 uint8_t _scale;
SomeRandomBloke 5:d813fe6c0c70 109 float _step_factor;
SomeRandomBloke 5:d813fe6c0c70 110 bool _highres;
emilmont 0:6149091f755d 111
emilmont 0:6149091f755d 112 };
emilmont 0:6149091f755d 113
emilmont 0:6149091f755d 114 #endif