enhancing Multitech's library for some accelerometer

Fork of MMA845x by Multi-Hackers

Committer:
amateusz
Date:
Thu Jul 05 15:05:20 2018 +0000
Revision:
18:2316ca98e599
Parent:
17:ff9a9933d123
FIX setting LowPower mode <- wrong bitmask was setting Fast mode instead, SIC

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
falingtrea 1:41af2b3eefb5 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 *
falingtrea 1:41af2b3eefb5 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.
amateusz 7:90ce70da8673 23 * Forked from
sam_grove 0:9d1e3a344e4f 24 */
amateusz 7:90ce70da8673 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
amateusz 7:90ce70da8673 39 *
amateusz 7:90ce70da8673 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
amateusz 7:90ce70da8673 51 */
sam_grove 0:9d1e3a344e4f 52 class MMA845x_DATA
amateusz 7:90ce70da8673 53 {
sam_grove 0:9d1e3a344e4f 54 public:
amateusz 7:90ce70da8673 55
falingtrea 1:41af2b3eefb5 56 volatile int16_t _x; /*!< volatile data variable */
falingtrea 1:41af2b3eefb5 57 volatile int16_t _y; /*!< volatile data variable */
falingtrea 1:41af2b3eefb5 58 volatile int16_t _z; /*!< volatile data variable */
amateusz 7:90ce70da8673 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 */
falingtrea 1:41af2b3eefb5 65 MMA845x_DATA(int16_t x = 0, int16_t y = 0, int16_t z = 0) : _x(x), _y(y), _z(z) {}
amateusz 7:90ce70da8673 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 */
amateusz 7:90ce70da8673 71 MMA845x_DATA &operator= (MMA845x_DATA const &rhs) {
sam_grove 0:9d1e3a344e4f 72 _x = rhs._x;
sam_grove 0:9d1e3a344e4f 73 _y = rhs._y;
sam_grove 0:9d1e3a344e4f 74 _z = rhs._z;
amateusz 7:90ce70da8673 75
sam_grove 0:9d1e3a344e4f 76 return *this;
sam_grove 0:9d1e3a344e4f 77 }
amateusz 7:90ce70da8673 78
sam_grove 0:9d1e3a344e4f 79 /** Overloaded '=' operator to allow shorthand coding, assigning objects to one another
sam_grove 0:9d1e3a344e4f 80 * @param val - Assign each data member (_x, _y, _z) this value
sam_grove 0:9d1e3a344e4f 81 * @return this
sam_grove 0:9d1e3a344e4f 82 */
amateusz 7:90ce70da8673 83 MMA845x_DATA &operator= (int16_t const val) {
sam_grove 0:9d1e3a344e4f 84 _x = _y = _z = val;
amateusz 7:90ce70da8673 85
sam_grove 0:9d1e3a344e4f 86 return *this;
sam_grove 0:9d1e3a344e4f 87 }
amateusz 7:90ce70da8673 88
sam_grove 0:9d1e3a344e4f 89 /** Overloaded '==' operator to allow shorthand coding, test objects to one another
sam_grove 0:9d1e3a344e4f 90 * @param rhs - the object to compare against
sam_grove 0:9d1e3a344e4f 91 * @return 1 if the data members are the same and 0 otherwise
sam_grove 0:9d1e3a344e4f 92 */
amateusz 7:90ce70da8673 93 bool operator== (MMA845x_DATA const &rhs) const {
sam_grove 0:9d1e3a344e4f 94 return ((_x == rhs._x)&&(_y == rhs._y)&&(_z == rhs._z)) ? 1 : 0;
sam_grove 0:9d1e3a344e4f 95 }
sam_grove 0:9d1e3a344e4f 96 };
sam_grove 0:9d1e3a344e4f 97
sam_grove 0:9d1e3a344e4f 98 /**
sam_grove 0:9d1e3a344e4f 99 * @class MMA845x
sam_grove 0:9d1e3a344e4f 100 * @brief API abstraction for the MMA845x 3-axis accelerometer IC
falingtrea 1:41af2b3eefb5 101 * initial version will be polling only. Interrupt service and rtos support will
falingtrea 1:41af2b3eefb5 102 * be added at a later point
amateusz 7:90ce70da8673 103 */
sam_grove 0:9d1e3a344e4f 104 class MMA845x
amateusz 7:90ce70da8673 105 {
sam_grove 0:9d1e3a344e4f 106 public:
amateusz 7:90ce70da8673 107
sam_grove 0:9d1e3a344e4f 108 /**
falingtrea 1:41af2b3eefb5 109 * @enum SA0
sam_grove 0:9d1e3a344e4f 110 * @brief Possible terminations for the ADDR pin
amateusz 7:90ce70da8673 111 */
amateusz 7:90ce70da8673 112 enum SA0 {
sam_grove 0:9d1e3a344e4f 113 SA0_VSS = 0, /*!< SA0 connected to VSS */
sam_grove 0:9d1e3a344e4f 114 SA0_VDD /*!< SA0 connected to VDD */
sam_grove 0:9d1e3a344e4f 115 };
amateusz 7:90ce70da8673 116
sam_grove 0:9d1e3a344e4f 117 /**
falingtrea 1:41af2b3eefb5 118 * @enum WHO_AM_I_VAL
sam_grove 0:9d1e3a344e4f 119 * @brief Device ID's that this class is compatible with
amateusz 7:90ce70da8673 120 */
amateusz 7:90ce70da8673 121 enum WHO_AM_I_VAL {
amateusz 7:90ce70da8673 122 MMA8451 = 0x1A, /*!< MMA8451 WHO_AM_I register content */
amateusz 7:90ce70da8673 123 MMA8452 = 0x2A, /*!< MMA8452 WHO_AM_I register content */
amateusz 7:90ce70da8673 124 MMA8453 = 0x3A, /*!< MMA8453 WHO_AM_I register content */
sam_grove 0:9d1e3a344e4f 125 };
falingtrea 1:41af2b3eefb5 126
falingtrea 1:41af2b3eefb5 127 /**
falingtrea 1:41af2b3eefb5 128 * @enum SYS_MODE
falingtrea 1:41af2b3eefb5 129 * @brief operating mode of MMA845x
falingtrea 1:41af2b3eefb5 130 */
amateusz 7:90ce70da8673 131 enum SYS_MODE {
amateusz 7:90ce70da8673 132 STANDBY = 0,
amateusz 8:0eb2995f0ecb 133 AWAKE, SLEEP
amateusz 7:90ce70da8673 134 };
falingtrea 1:41af2b3eefb5 135
falingtrea 1:41af2b3eefb5 136 /**
falingtrea 1:41af2b3eefb5 137 * @enum STATUS
falingtrea 1:41af2b3eefb5 138 * @brief flags for data overwrite and data ready
falingtrea 1:41af2b3eefb5 139 */
amateusz 7:90ce70da8673 140 enum STATUS {
amateusz 7:90ce70da8673 141 XDR = 0x01,
amateusz 7:90ce70da8673 142 YDR = 0x02,
amateusz 7:90ce70da8673 143 ZDR = 0x04,
amateusz 7:90ce70da8673 144 XYZDR = 0x08,
amateusz 7:90ce70da8673 145 XOW = 0x10,
amateusz 7:90ce70da8673 146 YOW = 0x20,
amateusz 7:90ce70da8673 147 ZOW = 0x40,
amateusz 7:90ce70da8673 148 XYZOW = 0x80
amateusz 7:90ce70da8673 149 };
falingtrea 1:41af2b3eefb5 150
amateusz 7:90ce70da8673 151 /**
amateusz 7:90ce70da8673 152 * @enum RANGE
amateusz 7:90ce70da8673 153 * @brief values for measurement range positive and negative
amateusz 7:90ce70da8673 154 */
amateusz 7:90ce70da8673 155 enum RANGE {
amateusz 7:90ce70da8673 156 RANGE_2g = 0,
amateusz 7:90ce70da8673 157 RANGE_4g, RANGE_8g
amateusz 7:90ce70da8673 158 };
amateusz 7:90ce70da8673 159
sam_grove 0:9d1e3a344e4f 160 /**
falingtrea 1:41af2b3eefb5 161 * @enum RESOLUTION
falingtrea 1:41af2b3eefb5 162 * @brief selections for resolution of data, 8 bit or maximum
falingtrea 1:41af2b3eefb5 163 */
amateusz 7:90ce70da8673 164 enum RESOLUTION {
amateusz 7:90ce70da8673 165 RES_MAX = 0, /* Read back full resolution - normal mode*/
amateusz 7:90ce70da8673 166 RES_8BIT = 2 /* Read back 8 bit values only - fast mode*/
amateusz 7:90ce70da8673 167 };
falingtrea 1:41af2b3eefb5 168
falingtrea 1:41af2b3eefb5 169 /**
falingtrea 1:41af2b3eefb5 170 * @enum LOW_NOISE
falingtrea 1:41af2b3eefb5 171 * @brief Low Noise mode Note: 4g max reading when on
falingtrea 1:41af2b3eefb5 172 */
amateusz 7:90ce70da8673 173 enum LOW_NOISE {
falingtrea 1:41af2b3eefb5 174 LN_OFF = 0x00, /* Low Noise mode off */
amateusz 18:2316ca98e599 175 LN_ON = 0x04 /* Low Noise mode on, 4g max readings */
falingtrea 1:41af2b3eefb5 176 };
falingtrea 1:41af2b3eefb5 177
falingtrea 1:41af2b3eefb5 178 /**
falingtrea 1:41af2b3eefb5 179 * @enum HPF_MODE
falingtrea 1:41af2b3eefb5 180 * @brief High Pass Filter mode
falingtrea 1:41af2b3eefb5 181 */
amateusz 7:90ce70da8673 182 enum HPF_MODE {
falingtrea 1:41af2b3eefb5 183 HPF_OFF = 0x00, /* High Pass Filter mode off */
falingtrea 1:41af2b3eefb5 184 HPF_ON = 0x10 /* High Pass Filter mode on */
falingtrea 1:41af2b3eefb5 185 };
falingtrea 1:41af2b3eefb5 186
amateusz 7:90ce70da8673 187 /**
amateusz 7:90ce70da8673 188 * @enum DATA_RATE
amateusz 7:90ce70da8673 189 * @brief values for normal output data rate in Hz
amateusz 7:90ce70da8673 190 */
amateusz 7:90ce70da8673 191 enum DATA_RATE {
amateusz 7:90ce70da8673 192 DR_800 = 0x00,
amateusz 7:90ce70da8673 193 DR_400 = 0x08,
amateusz 7:90ce70da8673 194 DR_200 = 0x10,
amateusz 7:90ce70da8673 195 DR_100 = 0x18,
amateusz 7:90ce70da8673 196 DR_50 = 0x20,
amateusz 7:90ce70da8673 197 DR_12_5 = 0x28,
amateusz 7:90ce70da8673 198 DR_6_25 = 0x30,
amateusz 7:90ce70da8673 199 DR_1_56 = 0x38
amateusz 7:90ce70da8673 200 };
falingtrea 1:41af2b3eefb5 201 /**
falingtrea 1:41af2b3eefb5 202 * @enum ASLP_DATA_RATE
falingtrea 1:41af2b3eefb5 203 * @brief values for auto_sleep mode data rate in HZ
falingtrea 1:41af2b3eefb5 204 */
amateusz 7:90ce70da8673 205 enum ASLP_DATA_RATE {
amateusz 7:90ce70da8673 206 ASLPDR_50 = 0x00,
amateusz 7:90ce70da8673 207 ALSPDR_12_5 = 0x40,
amateusz 7:90ce70da8673 208 ASLPDR_6_25 = 0x80,
amateusz 7:90ce70da8673 209 ASLPDR_1_56 = 0xB0
amateusz 7:90ce70da8673 210 };
falingtrea 1:41af2b3eefb5 211
falingtrea 1:41af2b3eefb5 212 /**
falingtrea 1:41af2b3eefb5 213 * @enum OVERSAMPLE_MODE
falingtrea 1:41af2b3eefb5 214 * @brief sets the oversample mode, Normal, Low power and noise, High resolution, or low power
falingtrea 1:41af2b3eefb5 215 */
amateusz 7:90ce70da8673 216 enum OVERSAMPLE_MODE {
amateusz 7:90ce70da8673 217 OS_NORMAL = 0,
amateusz 7:90ce70da8673 218 OS_LO_PN, OS_HI_RES, OS_LO_POW
amateusz 7:90ce70da8673 219 };
falingtrea 1:41af2b3eefb5 220
falingtrea 1:41af2b3eefb5 221 /**
amateusz 11:8dc4f77b2f53 222 * @enum INTERRUPT_CFG_AND_ENABLE
amateusz 12:92294b5ca1c1 223 * @brief used to {configure, enable, detect source of} interrupts for corresponding functions
amateusz 12:92294b5ca1c1 224 * (INT_FIFO used only in MMA8451)
amateusz 11:8dc4f77b2f53 225 */
amateusz 12:92294b5ca1c1 226 enum INTERRUPT_CFG_EN_SOURCE {
amateusz 17:ff9a9933d123 227 INT_DRDY = 0x01,
amateusz 11:8dc4f77b2f53 228 // 0x20 missing,
amateusz 11:8dc4f77b2f53 229 INT_FF_MT = 0x04,
amateusz 11:8dc4f77b2f53 230 INT_PULSE = 0x08,
amateusz 11:8dc4f77b2f53 231 INT_LNDPRT = 0x10,
amateusz 11:8dc4f77b2f53 232 INT_TRANS = 0x20,
amateusz 11:8dc4f77b2f53 233 INT_FIFO = 0x40,
amateusz 11:8dc4f77b2f53 234 INT_ASLP = 0x80
amateusz 12:92294b5ca1c1 235 };
amateusz 11:8dc4f77b2f53 236 /**
amateusz 11:8dc4f77b2f53 237 * @enum INTERRUPT_PIN
amateusz 11:8dc4f77b2f53 238 * @brief chooses interrupt pin used to signal interrupt condition
amateusz 11:8dc4f77b2f53 239 */
amateusz 11:8dc4f77b2f53 240 enum INTERRUPT_PIN {
amateusz 11:8dc4f77b2f53 241 INT1 = 1,
amateusz 12:92294b5ca1c1 242 INT2 = 0,
amateusz 12:92294b5ca1c1 243 INT_NONE = 2
amateusz 12:92294b5ca1c1 244 };
amateusz 11:8dc4f77b2f53 245
amateusz 11:8dc4f77b2f53 246 /**
falingtrea 1:41af2b3eefb5 247 * @enum REGISTER
sam_grove 0:9d1e3a344e4f 248 * @brief The device register map
sam_grove 0:9d1e3a344e4f 249 */
amateusz 7:90ce70da8673 250 enum REGISTER {
falingtrea 1:41af2b3eefb5 251 STATUS = 0x00,
sam_grove 0:9d1e3a344e4f 252 OUT_X_MSB, OUT_X_LSB, OUT_Y_MSB, OUT_Y_LSB, OUT_Z_MSB, OUT_Z_LSB,
amateusz 7:90ce70da8673 253
falingtrea 1:41af2b3eefb5 254 F_SETUP = 0x09, TRIG_CFG, // only available on the MMA8451 variant
amateusz 7:90ce70da8673 255
falingtrea 1:41af2b3eefb5 256 SYSMOD = 0x0B,
sam_grove 0:9d1e3a344e4f 257 INT_SOURCE, WHO_AM_I, XYZ_DATA_CFG, HP_FILTER_CUTOFF, PL_STATUS,
sam_grove 0:9d1e3a344e4f 258 PL_CFG, PL_COUNT, PL_BF_ZCOMP, P_L_THS_REG, FF_MT_CFG, FF_MT_SRC,
sam_grove 0:9d1e3a344e4f 259 FF_MT_THS, FF_MT_COUNT,
amateusz 7:90ce70da8673 260
falingtrea 1:41af2b3eefb5 261 TRANSIENT_CFG = 0x1D,
sam_grove 0:9d1e3a344e4f 262 TRANSIENT_SRC, TRANSIENT_THS, TRANSIENT_COUNT, PULSE_CFG, PULSE_SRC,
sam_grove 0:9d1e3a344e4f 263 PULSE_THSX, PULSE_THSY, PULSE_THSZ, PULSE_TMLT, PULSE_LTCY, PULSE_WIND,
sam_grove 0:9d1e3a344e4f 264 ASLP_COUNT, CTRL_REG1, CTRL_REG2, CTRL_REG3, CTRL_REG4, CTRL_REG5,
sam_grove 0:9d1e3a344e4f 265 OFF_X, OFF_Y, OFF_Z
sam_grove 0:9d1e3a344e4f 266 };
amateusz 7:90ce70da8673 267
sam_grove 0:9d1e3a344e4f 268 /** Create the MMA845x object
sam_grove 0:9d1e3a344e4f 269 * @param i2c - A defined I2C object
falingtrea 1:41af2b3eefb5 270 * @param int1 - A defined InterruptIn object pointer. Default NULL for polling mode
falingtrea 1:41af2b3eefb5 271 * @param int2 - A defined InterruptIn object pointer. Default NULL for polling mode
falingtrea 1:41af2b3eefb5 272 * @param i2c_addr - state of pin SA0
falingtrea 1:41af2b3eefb5 273 * TODO - need to add interrupt support
amateusz 7:90ce70da8673 274 */
falingtrea 1:41af2b3eefb5 275 MMA845x(I2C &i2c, SA0 const i2c_addr = SA0_VSS, InterruptIn* int1 = NULL, InterruptIn* int2 = NULL);
amateusz 7:90ce70da8673 276
sam_grove 0:9d1e3a344e4f 277 /** Get the X data
falingtrea 1:41af2b3eefb5 278 * @return The last valid X-axis reading from the accelerometer
sam_grove 0:9d1e3a344e4f 279 */
falingtrea 1:41af2b3eefb5 280 int16_t getX(void);
amateusz 7:90ce70da8673 281
sam_grove 0:9d1e3a344e4f 282 /** Get the Y data
falingtrea 1:41af2b3eefb5 283 * @return The last valid Y-axis reading from the accelerometer
sam_grove 0:9d1e3a344e4f 284 */
falingtrea 1:41af2b3eefb5 285 int16_t getY(void);
amateusz 7:90ce70da8673 286
sam_grove 0:9d1e3a344e4f 287 /** Get the Z data
falingtrea 1:41af2b3eefb5 288 * @return The last Z-axis valid reading from the accelerometer
sam_grove 0:9d1e3a344e4f 289 */
falingtrea 1:41af2b3eefb5 290 int16_t getZ(void);
amateusz 7:90ce70da8673 291
falingtrea 1:41af2b3eefb5 292 /** Get the XYZ data structure
falingtrea 1:41af2b3eefb5 293 * @return The last valid X, Y, and Z-axis readings from the accelerometer
falingtrea 1:41af2b3eefb5 294 */
falingtrea 1:41af2b3eefb5 295 MMA845x_DATA getXYZ(void);
amateusz 7:90ce70da8673 296
sam_grove 0:9d1e3a344e4f 297 /** Get the XYZ data structure
falingtrea 1:41af2b3eefb5 298 * @return accelerometer ID code. Test versus the WHO_AM_I_VAL enum
falingtrea 1:41af2b3eefb5 299 */
falingtrea 1:41af2b3eefb5 300 char getWhoAmI(void) const;
falingtrea 1:41af2b3eefb5 301
falingtrea 1:41af2b3eefb5 302 /** Setup the MMA845x for standard accelerometer read mode
falingtrea 1:41af2b3eefb5 303 * @range - set the measurement range using RANGE enum
falingtrea 1:41af2b3eefb5 304 * @resolution - set the ADC resolution using the RESOLUTION enum
falingtrea 1:41af2b3eefb5 305 * @lo_noise - Set the Low-Noise mode using the LOW_NOISE enum
falingtrea 1:41af2b3eefb5 306 * @data_rate - set the aquisition rate using the DATA_RATE enum
falingtrea 1:41af2b3eefb5 307 * @os_mode - Set the Over sample mode suing the OVERSAMPLE_MODE enum
falingtrea 1:41af2b3eefb5 308 * @hpf_mode - Set the Hi pass filter mode using the HPF_MOSE enum
falingtrea 1:41af2b3eefb5 309 * @return status of command
falingtrea 1:41af2b3eefb5 310 *
falingtrea 1:41af2b3eefb5 311 * This sets the resolution, range, data rate, oversample
falingtrea 1:41af2b3eefb5 312 * mode, hi and lo pass filter.
amateusz 7:90ce70da8673 313 * Also sets the device to active mode, so no further configuration will take an effect.
amateusz 7:90ce70da8673 314 * To perform any configuration, switch to standby.
falingtrea 1:41af2b3eefb5 315 */
falingtrea 1:41af2b3eefb5 316 uint8_t setCommonParameters(RANGE range, RESOLUTION resolution, LOW_NOISE lo_noise,
amateusz 7:90ce70da8673 317 DATA_RATE data_rate, OVERSAMPLE_MODE os_mode, HPF_MODE hpf_mode ) const;
falingtrea 1:41af2b3eefb5 318
falingtrea 1:41af2b3eefb5 319 /** Ebnable Motion detect mode and interrupt handler
falingtrea 1:41af2b3eefb5 320 * @return status of command
falingtrea 1:41af2b3eefb5 321 * TODO - need to implement function
sam_grove 0:9d1e3a344e4f 322 */
falingtrea 1:41af2b3eefb5 323 uint8_t enableMotionDetect(void) const;
falingtrea 1:41af2b3eefb5 324
falingtrea 1:41af2b3eefb5 325 /** Enable Pulse Detect mode and interrupt handler
amateusz 14:683234dfe179 326 * @char x_threshold - tap/double tap detection threshold for x axis. resolution of 0.063 g/LSB, min value 1, max value 127, use 0 to disable
amateusz 14:683234dfe179 327 * @char y_threshold - tap/double tap detection threshold for y axis. resolution of 0.063 g/LSB, min value 1, max value 127, use 0 to disable
amateusz 14:683234dfe179 328 * @char z_threshold - tap/double tap detection threshold for z axis. resolution of 0.063 g/LSB, min value 1, max value 127, use 0 to disable
amateusz 14:683234dfe179 329 * @char window - pulse must fit within window (raise and fall below threshold) in order "to be considered a valid pulse."
amateusz 14:683234dfe179 330 * @char latency - period, that starts after a pulse has been detected, during all pulses are ignored. Kind of debouncing
amateusz 14:683234dfe179 331 * @pin - an interrupt has to be attached to some pin, even if this pin is NC
falingtrea 1:41af2b3eefb5 332 * @return status of command
amateusz 15:8544130b5def 333 * TODO - implement conversion from some arbitrary units to ms for window and latency, double tap, way of fetching pulse events
falingtrea 1:41af2b3eefb5 334 */
amateusz 14:683234dfe179 335 uint8_t enablePulseDetect(char x_threshold, char y_threshold, char z_threshold, char window, char latency, INTERRUPT_PIN pin) const;
falingtrea 1:41af2b3eefb5 336
falingtrea 1:41af2b3eefb5 337 /** Enable Orientation mode and interrupt handler
amateusz 12:92294b5ca1c1 338 * @debounce_steps - how long a state has to last to trigger orientation change. step varies from 1.25 to 160 ms.
amateusz 14:683234dfe179 339 * @pin - an interrupt has to be attached to some pin, even if this pin is NC
falingtrea 1:41af2b3eefb5 340 * @return status of command
amateusz 15:8544130b5def 341 * TODO - add trip angles change (only when MMA8451), way of fetching orientation events
sam_grove 0:9d1e3a344e4f 342 */
amateusz 12:92294b5ca1c1 343 uint8_t enableOrientationDetect(uint8_t debounce_steps, INTERRUPT_PIN pin = INT_NONE) const;
falingtrea 1:41af2b3eefb5 344
falingtrea 1:41af2b3eefb5 345 /** Enable Transient detect mode and interrupt handler
falingtrea 1:41af2b3eefb5 346 * @return status of command
falingtrea 1:41af2b3eefb5 347 * TODO - need to implement function
falingtrea 1:41af2b3eefb5 348 */
falingtrea 1:41af2b3eefb5 349 uint8_t enableTransientDetect(void) const;
falingtrea 1:41af2b3eefb5 350
falingtrea 1:41af2b3eefb5 351 /** Enable Autosleep function and interrupt handler
falingtrea 1:41af2b3eefb5 352 * @return status of command
falingtrea 1:41af2b3eefb5 353 * TODO - need to implement function
falingtrea 1:41af2b3eefb5 354 */
falingtrea 1:41af2b3eefb5 355 uint8_t enableAutoSleep(void) const;
falingtrea 1:41af2b3eefb5 356
falingtrea 1:41af2b3eefb5 357 /** Enbale FIFO function and interrupt handler
falingtrea 1:41af2b3eefb5 358 * @return status of command
falingtrea 1:41af2b3eefb5 359 * TODO - need to implement function
falingtrea 1:41af2b3eefb5 360 */
falingtrea 1:41af2b3eefb5 361 uint8_t enableFIFO(void) const;
amateusz 7:90ce70da8673 362
falingtrea 1:41af2b3eefb5 363 /** Put the MMA845x in the Standby mode
falingtrea 1:41af2b3eefb5 364 * @return status of command
sam_grove 0:9d1e3a344e4f 365 */
falingtrea 1:41af2b3eefb5 366 uint8_t standbyMode(void) const;
amateusz 7:90ce70da8673 367
falingtrea 1:41af2b3eefb5 368 /** Put the MMA845x in the active mode
falingtrea 1:41af2b3eefb5 369 * @return status of command
falingtrea 1:41af2b3eefb5 370 */
falingtrea 1:41af2b3eefb5 371 uint8_t activeMode(void) const;
amateusz 7:90ce70da8673 372
falingtrea 1:41af2b3eefb5 373 /** Check the MMA845x status register
falingtrea 1:41af2b3eefb5 374 * @return status byte
falingtrea 1:41af2b3eefb5 375 */
falingtrea 1:41af2b3eefb5 376 uint8_t getStatus(void) const;
falingtrea 1:41af2b3eefb5 377
amateusz 13:77a8994b3bb2 378 /** Write to a register (exposed for debugging reasons)
amateusz 13:77a8994b3bb2 379 * Note: most writes are only valid in stop mode
amateusz 13:77a8994b3bb2 380 * @param reg - The register to be written
amateusz 13:77a8994b3bb2 381 * @param data - The data to be written
amateusz 13:77a8994b3bb2 382 */
amateusz 13:77a8994b3bb2 383 uint8_t writeRegister(uint8_t const reg, uint8_t const data) const;
amateusz 7:90ce70da8673 384
amateusz 13:77a8994b3bb2 385 /** Read from a register (exposed for debugging reasons)
amateusz 13:77a8994b3bb2 386 * @param reg - The register to read from
amateusz 13:77a8994b3bb2 387 * @return The register contents
amateusz 13:77a8994b3bb2 388 */
amateusz 13:77a8994b3bb2 389 uint8_t readRegister(uint8_t const reg, uint8_t count, char* data) const;
amateusz 17:ff9a9933d123 390
amateusz 17:ff9a9933d123 391 /** Enable disable interrupt triggering for a given function.
amateusz 17:ff9a9933d123 392 * @function - a internal funcion capable to trigger an interrupt
amateusz 17:ff9a9933d123 393 * @pin - which phy pin assign to interrupt condition. If no pin is specified, interrupt is disabled
amateusz 17:ff9a9933d123 394 * @return
amateusz 17:ff9a9933d123 395 */
amateusz 17:ff9a9933d123 396 uint8_t configInterrupt(INTERRUPT_CFG_EN_SOURCE function, INTERRUPT_PIN pin) const;
amateusz 17:ff9a9933d123 397
sam_grove 0:9d1e3a344e4f 398 private:
amateusz 7:90ce70da8673 399
sam_grove 0:9d1e3a344e4f 400 I2C *_i2c;
sam_grove 0:9d1e3a344e4f 401 InterruptIn *_int1;
sam_grove 0:9d1e3a344e4f 402 InterruptIn *_int2;
sam_grove 0:9d1e3a344e4f 403 uint8_t _i2c_addr;
falingtrea 1:41af2b3eefb5 404 char _who_am_i;
sam_grove 0:9d1e3a344e4f 405 MMA845x_DATA _data;
falingtrea 1:41af2b3eefb5 406 bool _polling_mode;
amateusz 7:90ce70da8673 407
falingtrea 1:41af2b3eefb5 408 uint8_t init(void);
amateusz 7:90ce70da8673 409
sam_grove 0:9d1e3a344e4f 410 };
sam_grove 0:9d1e3a344e4f 411
sam_grove 0:9d1e3a344e4f 412 #endif