Device driver for the Freescale MMA845x family of accelerometers.

Fork of MMA845x by Sam Grove

Committer:
1994timmeh
Date:
Wed Jan 11 04:12:05 2017 +0000
Revision:
2:555f8ba0c959
Parent:
1:37ddb4739f02
sdfasdf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:9d1e3a344e4f 1 /**
sam_grove 0:9d1e3a344e4f 2 * @file MMA845x.h
sam_grove 0:9d1e3a344e4f 3 * @brief Device driver - MMA845x 3-axis accelerometer IC
1994timmeh 2:555f8ba0c959 4 * @author Tim Barr
sam_grove 0:9d1e3a344e4f 5 * @version 1.0
sam_grove 0:9d1e3a344e4f 6 * @see http://cache.freescale.com/files/sensors/doc/data_sheet/MMA8451Q.pdf
sam_grove 0:9d1e3a344e4f 7 * @see http://cache.freescale.com/files/sensors/doc/data_sheet/MMA8452Q.pdf
sam_grove 0:9d1e3a344e4f 8 * @see http://cache.freescale.com/files/sensors/doc/data_sheet/MMA8453Q.pdf
sam_grove 0:9d1e3a344e4f 9 *
1994timmeh 2:555f8ba0c959 10 * Copyright (c) 2015
sam_grove 0:9d1e3a344e4f 11 *
sam_grove 0:9d1e3a344e4f 12 * Licensed under the Apache License, Version 2.0 (the "License");
sam_grove 0:9d1e3a344e4f 13 * you may not use this file except in compliance with the License.
sam_grove 0:9d1e3a344e4f 14 * You may obtain a copy of the License at
sam_grove 0:9d1e3a344e4f 15 *
sam_grove 0:9d1e3a344e4f 16 * http://www.apache.org/licenses/LICENSE-2.0
sam_grove 0:9d1e3a344e4f 17 *
sam_grove 0:9d1e3a344e4f 18 * Unless required by applicable law or agreed to in writing, software
sam_grove 0:9d1e3a344e4f 19 * distributed under the License is distributed on an "AS IS" BASIS,
sam_grove 0:9d1e3a344e4f 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sam_grove 0:9d1e3a344e4f 21 * See the License for the specific language governing permissions and
sam_grove 0:9d1e3a344e4f 22 * limitations under the License.
1994timmeh 2:555f8ba0c959 23 * Forked from
sam_grove 0:9d1e3a344e4f 24 */
sam_grove 0:9d1e3a344e4f 25
sam_grove 0:9d1e3a344e4f 26 #ifndef MMA845X_H
sam_grove 0:9d1e3a344e4f 27 #define MMA845X_H
sam_grove 0:9d1e3a344e4f 28
sam_grove 0:9d1e3a344e4f 29 #include "mbed.h"
sam_grove 0:9d1e3a344e4f 30
sam_grove 0:9d1e3a344e4f 31 /** Using the Sparkfun SEN-10955
sam_grove 0:9d1e3a344e4f 32 *
sam_grove 0:9d1e3a344e4f 33 * Example:
sam_grove 0:9d1e3a344e4f 34 * @code
sam_grove 0:9d1e3a344e4f 35 * #include "mbed.h"
sam_grove 0:9d1e3a344e4f 36 * #include "MMA845x.h"
sam_grove 0:9d1e3a344e4f 37 *
sam_grove 0:9d1e3a344e4f 38
sam_grove 0:9d1e3a344e4f 39 *
sam_grove 0:9d1e3a344e4f 40 * int main()
sam_grove 0:9d1e3a344e4f 41 * {
sam_grove 0:9d1e3a344e4f 42
sam_grove 0:9d1e3a344e4f 43 * }
sam_grove 0:9d1e3a344e4f 44 * @endcode
sam_grove 0:9d1e3a344e4f 45 */
sam_grove 0:9d1e3a344e4f 46
sam_grove 0:9d1e3a344e4f 47
sam_grove 0:9d1e3a344e4f 48 /**
sam_grove 0:9d1e3a344e4f 49 * @class MMA845x_DATA
sam_grove 0:9d1e3a344e4f 50 * @brief API abstraction for the MMA845x 3-axis accelerometer IC data
sam_grove 0:9d1e3a344e4f 51 */
sam_grove 0:9d1e3a344e4f 52 class MMA845x_DATA
sam_grove 0:9d1e3a344e4f 53 {
sam_grove 0:9d1e3a344e4f 54 public:
sam_grove 0:9d1e3a344e4f 55
1994timmeh 2:555f8ba0c959 56 volatile int16_t _x; /*!< volatile data variable */
1994timmeh 2:555f8ba0c959 57 volatile int16_t _y; /*!< volatile data variable */
1994timmeh 2:555f8ba0c959 58 volatile int16_t _z; /*!< volatile data variable */
sam_grove 0:9d1e3a344e4f 59
sam_grove 0:9d1e3a344e4f 60 /** Create the MMA845x_DATA object initialized to the parameter (or 0 if none)
sam_grove 0:9d1e3a344e4f 61 * @param x - the init value of _x
sam_grove 0:9d1e3a344e4f 62 * @param y - the init value of _y
sam_grove 0:9d1e3a344e4f 63 * @param x - the init value of _z
sam_grove 0:9d1e3a344e4f 64 */
1994timmeh 2:555f8ba0c959 65 MMA845x_DATA(int16_t x = 0, int16_t y = 0, int16_t z = 0) : _x(x), _y(y), _z(z) {}
sam_grove 0:9d1e3a344e4f 66
sam_grove 0:9d1e3a344e4f 67 /** Overloaded '=' operator to allow shorthand coding, assigning objects to one another
sam_grove 0:9d1e3a344e4f 68 * @param rhs - an object of the same type to assign ourself the same values of
sam_grove 0:9d1e3a344e4f 69 * @return this
sam_grove 0:9d1e3a344e4f 70 */
sam_grove 0:9d1e3a344e4f 71 MMA845x_DATA &operator= (MMA845x_DATA const &rhs)
sam_grove 0:9d1e3a344e4f 72 {
sam_grove 0:9d1e3a344e4f 73 _x = rhs._x;
sam_grove 0:9d1e3a344e4f 74 _y = rhs._y;
sam_grove 0:9d1e3a344e4f 75 _z = rhs._z;
sam_grove 0:9d1e3a344e4f 76
sam_grove 0:9d1e3a344e4f 77 return *this;
sam_grove 0:9d1e3a344e4f 78 }
sam_grove 0:9d1e3a344e4f 79
sam_grove 0:9d1e3a344e4f 80 /** Overloaded '=' operator to allow shorthand coding, assigning objects to one another
sam_grove 0:9d1e3a344e4f 81 * @param val - Assign each data member (_x, _y, _z) this value
sam_grove 0:9d1e3a344e4f 82 * @return this
sam_grove 0:9d1e3a344e4f 83 */
1994timmeh 2:555f8ba0c959 84 MMA845x_DATA &operator= (int16_t const val)
sam_grove 0:9d1e3a344e4f 85 {
sam_grove 0:9d1e3a344e4f 86 _x = _y = _z = val;
sam_grove 0:9d1e3a344e4f 87
sam_grove 0:9d1e3a344e4f 88 return *this;
sam_grove 0:9d1e3a344e4f 89 }
sam_grove 0:9d1e3a344e4f 90
sam_grove 0:9d1e3a344e4f 91 /** Overloaded '==' operator to allow shorthand coding, test objects to one another
sam_grove 0:9d1e3a344e4f 92 * @param rhs - the object to compare against
sam_grove 0:9d1e3a344e4f 93 * @return 1 if the data members are the same and 0 otherwise
sam_grove 0:9d1e3a344e4f 94 */
sam_grove 0:9d1e3a344e4f 95 bool operator== (MMA845x_DATA const &rhs) const
sam_grove 0:9d1e3a344e4f 96 {
sam_grove 0:9d1e3a344e4f 97 return ((_x == rhs._x)&&(_y == rhs._y)&&(_z == rhs._z)) ? 1 : 0;
sam_grove 0:9d1e3a344e4f 98 }
sam_grove 0:9d1e3a344e4f 99 };
sam_grove 0:9d1e3a344e4f 100
sam_grove 0:9d1e3a344e4f 101 /**
sam_grove 0:9d1e3a344e4f 102 * @class MMA845x
sam_grove 0:9d1e3a344e4f 103 * @brief API abstraction for the MMA845x 3-axis accelerometer IC
1994timmeh 2:555f8ba0c959 104 * initial version will be polling only. Interrupt service and rtos support will
1994timmeh 2:555f8ba0c959 105 * be added at a later point
sam_grove 0:9d1e3a344e4f 106 */
sam_grove 0:9d1e3a344e4f 107 class MMA845x
sam_grove 0:9d1e3a344e4f 108 {
sam_grove 0:9d1e3a344e4f 109 public:
sam_grove 0:9d1e3a344e4f 110
sam_grove 0:9d1e3a344e4f 111 /**
1994timmeh 2:555f8ba0c959 112 * @enum SA0
sam_grove 0:9d1e3a344e4f 113 * @brief Possible terminations for the ADDR pin
sam_grove 0:9d1e3a344e4f 114 */
1994timmeh 2:555f8ba0c959 115 enum SA0
1994timmeh 2:555f8ba0c959 116 {
sam_grove 0:9d1e3a344e4f 117 SA0_VSS = 0, /*!< SA0 connected to VSS */
sam_grove 0:9d1e3a344e4f 118 SA0_VDD /*!< SA0 connected to VDD */
sam_grove 0:9d1e3a344e4f 119 };
sam_grove 0:9d1e3a344e4f 120
sam_grove 0:9d1e3a344e4f 121 /**
1994timmeh 2:555f8ba0c959 122 * @enum WHO_AM_I_VAL
sam_grove 0:9d1e3a344e4f 123 * @brief Device ID's that this class is compatible with
sam_grove 0:9d1e3a344e4f 124 */
1994timmeh 2:555f8ba0c959 125 enum WHO_AM_I_VAL
1994timmeh 2:555f8ba0c959 126 {
sam_grove 0:9d1e3a344e4f 127 MMA8451 = 0x1a, /*!< MMA8451 WHO_AM_I register content */
sam_grove 0:9d1e3a344e4f 128 MMA8452 = 0x2a, /*!< MMA8452 WHO_AM_I register content */
sam_grove 0:9d1e3a344e4f 129 MMA8453 = 0x3a, /*!< MMA8453 WHO_AM_I register content */
sam_grove 0:9d1e3a344e4f 130 };
1994timmeh 2:555f8ba0c959 131
1994timmeh 2:555f8ba0c959 132 /**
1994timmeh 2:555f8ba0c959 133 * @enum SYS_MODE
1994timmeh 2:555f8ba0c959 134 * @brief operating mode of MMA845x
1994timmeh 2:555f8ba0c959 135 */
1994timmeh 2:555f8ba0c959 136 enum SYS_MODE
1994timmeh 2:555f8ba0c959 137 {
1994timmeh 2:555f8ba0c959 138 STANDBY = 0,
1994timmeh 2:555f8ba0c959 139 WAKE, SLEEP
1994timmeh 2:555f8ba0c959 140 };
1994timmeh 2:555f8ba0c959 141
1994timmeh 2:555f8ba0c959 142 /**
1994timmeh 2:555f8ba0c959 143 * @enum STATUS
1994timmeh 2:555f8ba0c959 144 * @brief flags for data overwrite and data ready
1994timmeh 2:555f8ba0c959 145 */
1994timmeh 2:555f8ba0c959 146 enum STATUS
1994timmeh 2:555f8ba0c959 147 {
1994timmeh 2:555f8ba0c959 148 XDR = 0x01,
1994timmeh 2:555f8ba0c959 149 YDR = 0x02,
1994timmeh 2:555f8ba0c959 150 ZDR = 0x04,
1994timmeh 2:555f8ba0c959 151 XYZDR = 0x08,
1994timmeh 2:555f8ba0c959 152 XOW = 0x10,
1994timmeh 2:555f8ba0c959 153 YOW = 0x20,
1994timmeh 2:555f8ba0c959 154 ZOW = 0x40,
1994timmeh 2:555f8ba0c959 155 XYZOW = 0x80
1994timmeh 2:555f8ba0c959 156 };
1994timmeh 2:555f8ba0c959 157
1994timmeh 2:555f8ba0c959 158 /**
1994timmeh 2:555f8ba0c959 159 * @enum RANGE
1994timmeh 2:555f8ba0c959 160 * @brief values for measurement range positive and negative
1994timmeh 2:555f8ba0c959 161 */
1994timmeh 2:555f8ba0c959 162 enum RANGE
1994timmeh 2:555f8ba0c959 163 {
1994timmeh 2:555f8ba0c959 164 RANGE_2g = 0,
1994timmeh 2:555f8ba0c959 165 RANGE_4g, RANGE_8g
1994timmeh 2:555f8ba0c959 166 };
sam_grove 0:9d1e3a344e4f 167
sam_grove 0:9d1e3a344e4f 168 /**
1994timmeh 2:555f8ba0c959 169 * @enum RESOLUTION
1994timmeh 2:555f8ba0c959 170 * @brief selections for resolution of data, 8 bit or maximum
1994timmeh 2:555f8ba0c959 171 */
1994timmeh 2:555f8ba0c959 172 enum RESOLUTION
1994timmeh 2:555f8ba0c959 173 {
1994timmeh 2:555f8ba0c959 174 RES_MAX = 0, /* Read back full resolution - normal mode*/
1994timmeh 2:555f8ba0c959 175 RES_8BIT = 2 /* Read back 8 bit values only - fast mode*/
1994timmeh 2:555f8ba0c959 176 };
1994timmeh 2:555f8ba0c959 177
1994timmeh 2:555f8ba0c959 178 /**
1994timmeh 2:555f8ba0c959 179 * @enum LOW_NOISE
1994timmeh 2:555f8ba0c959 180 * @brief Low Noise mode Note: 4g max reading when on
1994timmeh 2:555f8ba0c959 181 */
1994timmeh 2:555f8ba0c959 182 enum LOW_NOISE
1994timmeh 2:555f8ba0c959 183 {
1994timmeh 2:555f8ba0c959 184 LN_OFF = 0x00, /* Low Noise mode off */
1994timmeh 2:555f8ba0c959 185 LN_ON = 0x02 /* Low Noise mode on, 4g max readings */
1994timmeh 2:555f8ba0c959 186 };
1994timmeh 2:555f8ba0c959 187
1994timmeh 2:555f8ba0c959 188 /**
1994timmeh 2:555f8ba0c959 189 * @enum HPF_MODE
1994timmeh 2:555f8ba0c959 190 * @brief High Pass Filter mode
1994timmeh 2:555f8ba0c959 191 */
1994timmeh 2:555f8ba0c959 192 enum HPF_MODE
1994timmeh 2:555f8ba0c959 193 {
1994timmeh 2:555f8ba0c959 194 HPF_OFF = 0x00, /* High Pass Filter mode off */
1994timmeh 2:555f8ba0c959 195 HPF_ON = 0x10 /* High Pass Filter mode on */
1994timmeh 2:555f8ba0c959 196 };
1994timmeh 2:555f8ba0c959 197
1994timmeh 2:555f8ba0c959 198 /**
1994timmeh 2:555f8ba0c959 199 * @enum DATA_RATE
1994timmeh 2:555f8ba0c959 200 * @brief values for normal output data rate in Hz
1994timmeh 2:555f8ba0c959 201 */
1994timmeh 2:555f8ba0c959 202 enum DATA_RATE
1994timmeh 2:555f8ba0c959 203 {
1994timmeh 2:555f8ba0c959 204 DR_800 = 0x00,
1994timmeh 2:555f8ba0c959 205 DR_400 = 0x08,
1994timmeh 2:555f8ba0c959 206 DR_200 = 0x10,
1994timmeh 2:555f8ba0c959 207 DR_100 = 0x18,
1994timmeh 2:555f8ba0c959 208 DR_50 = 0x20,
1994timmeh 2:555f8ba0c959 209 DR_12_5 = 0x28,
1994timmeh 2:555f8ba0c959 210 DR_6_25 = 0x30,
1994timmeh 2:555f8ba0c959 211 DR_1_56 = 0x38
1994timmeh 2:555f8ba0c959 212 };
1994timmeh 2:555f8ba0c959 213 /**
1994timmeh 2:555f8ba0c959 214 * @enum ASLP_DATA_RATE
1994timmeh 2:555f8ba0c959 215 * @brief values for auto_sleep mode data rate in HZ
1994timmeh 2:555f8ba0c959 216 */
1994timmeh 2:555f8ba0c959 217 enum ASLP_DATA_RATE
1994timmeh 2:555f8ba0c959 218 {
1994timmeh 2:555f8ba0c959 219 ASLPDR_50 = 0x00,
1994timmeh 2:555f8ba0c959 220 ALSPDR_12_5 = 0x40,
1994timmeh 2:555f8ba0c959 221 ASLPDR_6_25 = 0x80,
1994timmeh 2:555f8ba0c959 222 ASLPDR_1_56 = 0xB0
1994timmeh 2:555f8ba0c959 223 };
1994timmeh 2:555f8ba0c959 224
1994timmeh 2:555f8ba0c959 225 /**
1994timmeh 2:555f8ba0c959 226 * @enum OVERSAMPLE_MODE
1994timmeh 2:555f8ba0c959 227 * @brief sets the oversample mode, Normal, Low power and noise, High resolution, or low power
1994timmeh 2:555f8ba0c959 228 */
1994timmeh 2:555f8ba0c959 229 enum OVERSAMPLE_MODE
1994timmeh 2:555f8ba0c959 230 {
1994timmeh 2:555f8ba0c959 231 OS_NORMAL = 0,
1994timmeh 2:555f8ba0c959 232 OS_LO_PN, OS_HI_RES, OS_LO_POW
1994timmeh 2:555f8ba0c959 233 };
1994timmeh 2:555f8ba0c959 234
1994timmeh 2:555f8ba0c959 235 /**
1994timmeh 2:555f8ba0c959 236 * @enum REGISTER
sam_grove 0:9d1e3a344e4f 237 * @brief The device register map
sam_grove 0:9d1e3a344e4f 238 */
1994timmeh 2:555f8ba0c959 239 enum REGISTER
1994timmeh 2:555f8ba0c959 240 {
1994timmeh 2:555f8ba0c959 241 STATUS = 0x00,
sam_grove 0:9d1e3a344e4f 242 OUT_X_MSB, OUT_X_LSB, OUT_Y_MSB, OUT_Y_LSB, OUT_Z_MSB, OUT_Z_LSB,
sam_grove 0:9d1e3a344e4f 243
1994timmeh 2:555f8ba0c959 244 F_SETUP = 0x09, TRIG_CFG, // only available on the MMA8451 variant
sam_grove 0:9d1e3a344e4f 245
1994timmeh 2:555f8ba0c959 246 SYSMOD = 0x0B,
sam_grove 0:9d1e3a344e4f 247 INT_SOURCE, WHO_AM_I, XYZ_DATA_CFG, HP_FILTER_CUTOFF, PL_STATUS,
sam_grove 0:9d1e3a344e4f 248 PL_CFG, PL_COUNT, PL_BF_ZCOMP, P_L_THS_REG, FF_MT_CFG, FF_MT_SRC,
sam_grove 0:9d1e3a344e4f 249 FF_MT_THS, FF_MT_COUNT,
sam_grove 0:9d1e3a344e4f 250
1994timmeh 2:555f8ba0c959 251 TRANSIENT_CFG = 0x1D,
sam_grove 0:9d1e3a344e4f 252 TRANSIENT_SRC, TRANSIENT_THS, TRANSIENT_COUNT, PULSE_CFG, PULSE_SRC,
sam_grove 0:9d1e3a344e4f 253 PULSE_THSX, PULSE_THSY, PULSE_THSZ, PULSE_TMLT, PULSE_LTCY, PULSE_WIND,
sam_grove 0:9d1e3a344e4f 254 ASLP_COUNT, CTRL_REG1, CTRL_REG2, CTRL_REG3, CTRL_REG4, CTRL_REG5,
sam_grove 0:9d1e3a344e4f 255 OFF_X, OFF_Y, OFF_Z
sam_grove 0:9d1e3a344e4f 256 };
sam_grove 0:9d1e3a344e4f 257
sam_grove 0:9d1e3a344e4f 258 /** Create the MMA845x object
sam_grove 0:9d1e3a344e4f 259 * @param i2c - A defined I2C object
1994timmeh 2:555f8ba0c959 260 * @param int1 - A defined InterruptIn object pointer. Default NULL for polling mode
1994timmeh 2:555f8ba0c959 261 * @param int2 - A defined InterruptIn object pointer. Default NULL for polling mode
1994timmeh 2:555f8ba0c959 262 * @param i2c_addr - state of pin SA0
1994timmeh 2:555f8ba0c959 263 * TODO - need to add interrupt support
sam_grove 0:9d1e3a344e4f 264 */
1994timmeh 2:555f8ba0c959 265 MMA845x(I2C &i2c, SA0 const i2c_addr = SA0_VSS, InterruptIn* int1 = NULL, InterruptIn* int2 = NULL);
sam_grove 0:9d1e3a344e4f 266
sam_grove 0:9d1e3a344e4f 267 /** Get the X data
1994timmeh 2:555f8ba0c959 268 * @return The last valid X-axis reading from the accelerometer
sam_grove 0:9d1e3a344e4f 269 */
1994timmeh 2:555f8ba0c959 270 int16_t getX(void);
sam_grove 0:9d1e3a344e4f 271
sam_grove 0:9d1e3a344e4f 272 /** Get the Y data
1994timmeh 2:555f8ba0c959 273 * @return The last valid Y-axis reading from the accelerometer
sam_grove 0:9d1e3a344e4f 274 */
1994timmeh 2:555f8ba0c959 275 int16_t getY(void);
sam_grove 0:9d1e3a344e4f 276
sam_grove 0:9d1e3a344e4f 277 /** Get the Z data
1994timmeh 2:555f8ba0c959 278 * @return The last Z-axis valid reading from the accelerometer
sam_grove 0:9d1e3a344e4f 279 */
1994timmeh 2:555f8ba0c959 280 int16_t getZ(void);
1994timmeh 2:555f8ba0c959 281
1994timmeh 2:555f8ba0c959 282 /** Get the XYZ data structure
1994timmeh 2:555f8ba0c959 283 * @return The last valid X, Y, and Z-axis readings from the accelerometer
1994timmeh 2:555f8ba0c959 284 */
1994timmeh 2:555f8ba0c959 285 MMA845x_DATA getXYZ(void);
sam_grove 0:9d1e3a344e4f 286
sam_grove 0:9d1e3a344e4f 287 /** Get the XYZ data structure
1994timmeh 2:555f8ba0c959 288 * @return accelerometer ID code. Test versus the WHO_AM_I_VAL enum
1994timmeh 2:555f8ba0c959 289 */
1994timmeh 2:555f8ba0c959 290 char getWhoAmI(void) const;
1994timmeh 2:555f8ba0c959 291
1994timmeh 2:555f8ba0c959 292 /** Setup the MMA845x for standard accelerometer read mode
1994timmeh 2:555f8ba0c959 293 * @range - set the measurement range using RANGE enum
1994timmeh 2:555f8ba0c959 294 * @resolution - set the ADC resolution using the RESOLUTION enum
1994timmeh 2:555f8ba0c959 295 * @lo_noise - Set the Low-Noise mode using the LOW_NOISE enum
1994timmeh 2:555f8ba0c959 296 * @data_rate - set the aquisition rate using the DATA_RATE enum
1994timmeh 2:555f8ba0c959 297 * @os_mode - Set the Over sample mode suing the OVERSAMPLE_MODE enum
1994timmeh 2:555f8ba0c959 298 * @hpf_mode - Set the Hi pass filter mode using the HPF_MOSE enum
1994timmeh 2:555f8ba0c959 299 * @return status of command
1994timmeh 2:555f8ba0c959 300 *
1994timmeh 2:555f8ba0c959 301 * This sets the resolution, range, data rate, oversample
1994timmeh 2:555f8ba0c959 302 * mode, hi and lo pass filter.
1994timmeh 2:555f8ba0c959 303 */
1994timmeh 2:555f8ba0c959 304 uint8_t setCommonParameters(RANGE range, RESOLUTION resolution, LOW_NOISE lo_noise,
1994timmeh 2:555f8ba0c959 305 DATA_RATE data_rate, OVERSAMPLE_MODE os_mode, HPF_MODE hpf_mode ) const;
1994timmeh 2:555f8ba0c959 306
1994timmeh 2:555f8ba0c959 307 /** Ebnable Motion detect mode and interrupt handler
1994timmeh 2:555f8ba0c959 308 * @return status of command
1994timmeh 2:555f8ba0c959 309 * TODO - need to implement function
sam_grove 0:9d1e3a344e4f 310 */
1994timmeh 2:555f8ba0c959 311 uint8_t enableMotionDetect(void) const;
1994timmeh 2:555f8ba0c959 312
1994timmeh 2:555f8ba0c959 313 /** Enable Pulse Detect mode and interrupt handler
1994timmeh 2:555f8ba0c959 314 * @return status of command
1994timmeh 2:555f8ba0c959 315 * TODO - need to implement function
1994timmeh 2:555f8ba0c959 316 */
1994timmeh 2:555f8ba0c959 317 uint8_t enablePulseDetect(void) const;
1994timmeh 2:555f8ba0c959 318
1994timmeh 2:555f8ba0c959 319 /** Enable Orientation mode and interrupt handler
1994timmeh 2:555f8ba0c959 320 * @return status of command
1994timmeh 2:555f8ba0c959 321 * TODO - need to implement function
sam_grove 0:9d1e3a344e4f 322 */
1994timmeh 2:555f8ba0c959 323 uint8_t enableOrientationDetect(void) const;
1994timmeh 2:555f8ba0c959 324
1994timmeh 2:555f8ba0c959 325 /** Enable Transient detect mode and interrupt handler
1994timmeh 2:555f8ba0c959 326 * @return status of command
1994timmeh 2:555f8ba0c959 327 * TODO - need to implement function
1994timmeh 2:555f8ba0c959 328 */
1994timmeh 2:555f8ba0c959 329 uint8_t enableTransientDetect(void) const;
1994timmeh 2:555f8ba0c959 330
1994timmeh 2:555f8ba0c959 331 /** Enable Autosleep function and interrupt handler
1994timmeh 2:555f8ba0c959 332 * @return status of command
1994timmeh 2:555f8ba0c959 333 * TODO - need to implement function
1994timmeh 2:555f8ba0c959 334 */
1994timmeh 2:555f8ba0c959 335 uint8_t enableAutoSleep(void) const;
1994timmeh 2:555f8ba0c959 336
1994timmeh 2:555f8ba0c959 337 /** Enbale FIFO function and interrupt handler
1994timmeh 2:555f8ba0c959 338 * @return status of command
1994timmeh 2:555f8ba0c959 339 * TODO - need to implement function
1994timmeh 2:555f8ba0c959 340 */
1994timmeh 2:555f8ba0c959 341 uint8_t enableFIFO(void) const;
sam_grove 0:9d1e3a344e4f 342
1994timmeh 2:555f8ba0c959 343 /** Put the MMA845x in the Standby mode
1994timmeh 2:555f8ba0c959 344 * @return status of command
sam_grove 0:9d1e3a344e4f 345 */
1994timmeh 2:555f8ba0c959 346 uint8_t standbyMode(void) const;
1994timmeh 2:555f8ba0c959 347
1994timmeh 2:555f8ba0c959 348 /** Put the MMA845x in the active mode
1994timmeh 2:555f8ba0c959 349 * @return status of command
1994timmeh 2:555f8ba0c959 350 */
1994timmeh 2:555f8ba0c959 351 uint8_t activeMode(void) const;
sam_grove 0:9d1e3a344e4f 352
1994timmeh 2:555f8ba0c959 353 /** Check the MMA845x status register
1994timmeh 2:555f8ba0c959 354 * @return status byte
1994timmeh 2:555f8ba0c959 355 */
1994timmeh 2:555f8ba0c959 356 uint8_t getStatus(void) const;
1994timmeh 2:555f8ba0c959 357
sam_grove 0:9d1e3a344e4f 358
sam_grove 0:9d1e3a344e4f 359 private:
sam_grove 0:9d1e3a344e4f 360
sam_grove 0:9d1e3a344e4f 361 I2C *_i2c;
sam_grove 0:9d1e3a344e4f 362 InterruptIn *_int1;
sam_grove 0:9d1e3a344e4f 363 InterruptIn *_int2;
sam_grove 0:9d1e3a344e4f 364 uint8_t _i2c_addr;
1994timmeh 2:555f8ba0c959 365 char _who_am_i;
sam_grove 0:9d1e3a344e4f 366 MMA845x_DATA _data;
1994timmeh 2:555f8ba0c959 367 bool _polling_mode;
1994timmeh 2:555f8ba0c959 368
1994timmeh 2:555f8ba0c959 369 uint8_t init(void);
sam_grove 0:9d1e3a344e4f 370
1994timmeh 2:555f8ba0c959 371 /** Write to a register (exposed for debugging reasons)
1994timmeh 2:555f8ba0c959 372 * Note: most writes are only valid in stop mode
1994timmeh 2:555f8ba0c959 373 * @param reg - The register to be written
1994timmeh 2:555f8ba0c959 374 * @param data - The data to be written
1994timmeh 2:555f8ba0c959 375 */
1994timmeh 2:555f8ba0c959 376 uint8_t writeRegister(uint8_t const reg, uint8_t const data) const;
1994timmeh 2:555f8ba0c959 377
1994timmeh 2:555f8ba0c959 378 /** Read from a register (exposed for debugging reasons)
1994timmeh 2:555f8ba0c959 379 * @param reg - The register to read from
1994timmeh 2:555f8ba0c959 380 * @return The register contents
1994timmeh 2:555f8ba0c959 381 */
1994timmeh 2:555f8ba0c959 382 uint8_t readRegister(uint8_t const reg, uint8_t count, char* data) const;
1994timmeh 2:555f8ba0c959 383
1994timmeh 2:555f8ba0c959 384
sam_grove 0:9d1e3a344e4f 385 };
sam_grove 0:9d1e3a344e4f 386
sam_grove 0:9d1e3a344e4f 387 #endif