enhancing Multitech's library for some accelerometer
Fork of MMA845x by
MMA845x.h@7:90ce70da8673, 2018-07-02 (annotated)
- Committer:
- amateusz
- Date:
- Mon Jul 02 22:09:19 2018 +0000
- Revision:
- 7:90ce70da8673
- Parent:
- 1:41af2b3eefb5
- Child:
- 8:0eb2995f0ecb
Mentioning that setCommonParameters actually also turns activeMode on implicitly
Who changed what in which revision?
User | Revision | Line number | New 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 | 7:90ce70da8673 | 133 | WAKE, 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 */ |
falingtrea | 1:41af2b3eefb5 | 175 | LN_ON = 0x02 /* 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 | /** |
falingtrea | 1:41af2b3eefb5 | 222 | * @enum REGISTER |
sam_grove | 0:9d1e3a344e4f | 223 | * @brief The device register map |
sam_grove | 0:9d1e3a344e4f | 224 | */ |
amateusz | 7:90ce70da8673 | 225 | enum REGISTER { |
falingtrea | 1:41af2b3eefb5 | 226 | STATUS = 0x00, |
sam_grove | 0:9d1e3a344e4f | 227 | OUT_X_MSB, OUT_X_LSB, OUT_Y_MSB, OUT_Y_LSB, OUT_Z_MSB, OUT_Z_LSB, |
amateusz | 7:90ce70da8673 | 228 | |
falingtrea | 1:41af2b3eefb5 | 229 | F_SETUP = 0x09, TRIG_CFG, // only available on the MMA8451 variant |
amateusz | 7:90ce70da8673 | 230 | |
falingtrea | 1:41af2b3eefb5 | 231 | SYSMOD = 0x0B, |
sam_grove | 0:9d1e3a344e4f | 232 | INT_SOURCE, WHO_AM_I, XYZ_DATA_CFG, HP_FILTER_CUTOFF, PL_STATUS, |
sam_grove | 0:9d1e3a344e4f | 233 | PL_CFG, PL_COUNT, PL_BF_ZCOMP, P_L_THS_REG, FF_MT_CFG, FF_MT_SRC, |
sam_grove | 0:9d1e3a344e4f | 234 | FF_MT_THS, FF_MT_COUNT, |
amateusz | 7:90ce70da8673 | 235 | |
falingtrea | 1:41af2b3eefb5 | 236 | TRANSIENT_CFG = 0x1D, |
sam_grove | 0:9d1e3a344e4f | 237 | TRANSIENT_SRC, TRANSIENT_THS, TRANSIENT_COUNT, PULSE_CFG, PULSE_SRC, |
sam_grove | 0:9d1e3a344e4f | 238 | PULSE_THSX, PULSE_THSY, PULSE_THSZ, PULSE_TMLT, PULSE_LTCY, PULSE_WIND, |
sam_grove | 0:9d1e3a344e4f | 239 | ASLP_COUNT, CTRL_REG1, CTRL_REG2, CTRL_REG3, CTRL_REG4, CTRL_REG5, |
sam_grove | 0:9d1e3a344e4f | 240 | OFF_X, OFF_Y, OFF_Z |
sam_grove | 0:9d1e3a344e4f | 241 | }; |
amateusz | 7:90ce70da8673 | 242 | |
sam_grove | 0:9d1e3a344e4f | 243 | /** Create the MMA845x object |
sam_grove | 0:9d1e3a344e4f | 244 | * @param i2c - A defined I2C object |
falingtrea | 1:41af2b3eefb5 | 245 | * @param int1 - A defined InterruptIn object pointer. Default NULL for polling mode |
falingtrea | 1:41af2b3eefb5 | 246 | * @param int2 - A defined InterruptIn object pointer. Default NULL for polling mode |
falingtrea | 1:41af2b3eefb5 | 247 | * @param i2c_addr - state of pin SA0 |
falingtrea | 1:41af2b3eefb5 | 248 | * TODO - need to add interrupt support |
amateusz | 7:90ce70da8673 | 249 | */ |
falingtrea | 1:41af2b3eefb5 | 250 | MMA845x(I2C &i2c, SA0 const i2c_addr = SA0_VSS, InterruptIn* int1 = NULL, InterruptIn* int2 = NULL); |
amateusz | 7:90ce70da8673 | 251 | |
sam_grove | 0:9d1e3a344e4f | 252 | /** Get the X data |
falingtrea | 1:41af2b3eefb5 | 253 | * @return The last valid X-axis reading from the accelerometer |
sam_grove | 0:9d1e3a344e4f | 254 | */ |
falingtrea | 1:41af2b3eefb5 | 255 | int16_t getX(void); |
amateusz | 7:90ce70da8673 | 256 | |
sam_grove | 0:9d1e3a344e4f | 257 | /** Get the Y data |
falingtrea | 1:41af2b3eefb5 | 258 | * @return The last valid Y-axis reading from the accelerometer |
sam_grove | 0:9d1e3a344e4f | 259 | */ |
falingtrea | 1:41af2b3eefb5 | 260 | int16_t getY(void); |
amateusz | 7:90ce70da8673 | 261 | |
sam_grove | 0:9d1e3a344e4f | 262 | /** Get the Z data |
falingtrea | 1:41af2b3eefb5 | 263 | * @return The last Z-axis valid reading from the accelerometer |
sam_grove | 0:9d1e3a344e4f | 264 | */ |
falingtrea | 1:41af2b3eefb5 | 265 | int16_t getZ(void); |
amateusz | 7:90ce70da8673 | 266 | |
falingtrea | 1:41af2b3eefb5 | 267 | /** Get the XYZ data structure |
falingtrea | 1:41af2b3eefb5 | 268 | * @return The last valid X, Y, and Z-axis readings from the accelerometer |
falingtrea | 1:41af2b3eefb5 | 269 | */ |
falingtrea | 1:41af2b3eefb5 | 270 | MMA845x_DATA getXYZ(void); |
amateusz | 7:90ce70da8673 | 271 | |
sam_grove | 0:9d1e3a344e4f | 272 | /** Get the XYZ data structure |
falingtrea | 1:41af2b3eefb5 | 273 | * @return accelerometer ID code. Test versus the WHO_AM_I_VAL enum |
falingtrea | 1:41af2b3eefb5 | 274 | */ |
falingtrea | 1:41af2b3eefb5 | 275 | char getWhoAmI(void) const; |
falingtrea | 1:41af2b3eefb5 | 276 | |
falingtrea | 1:41af2b3eefb5 | 277 | /** Setup the MMA845x for standard accelerometer read mode |
falingtrea | 1:41af2b3eefb5 | 278 | * @range - set the measurement range using RANGE enum |
falingtrea | 1:41af2b3eefb5 | 279 | * @resolution - set the ADC resolution using the RESOLUTION enum |
falingtrea | 1:41af2b3eefb5 | 280 | * @lo_noise - Set the Low-Noise mode using the LOW_NOISE enum |
falingtrea | 1:41af2b3eefb5 | 281 | * @data_rate - set the aquisition rate using the DATA_RATE enum |
falingtrea | 1:41af2b3eefb5 | 282 | * @os_mode - Set the Over sample mode suing the OVERSAMPLE_MODE enum |
falingtrea | 1:41af2b3eefb5 | 283 | * @hpf_mode - Set the Hi pass filter mode using the HPF_MOSE enum |
falingtrea | 1:41af2b3eefb5 | 284 | * @return status of command |
falingtrea | 1:41af2b3eefb5 | 285 | * |
falingtrea | 1:41af2b3eefb5 | 286 | * This sets the resolution, range, data rate, oversample |
falingtrea | 1:41af2b3eefb5 | 287 | * mode, hi and lo pass filter. |
amateusz | 7:90ce70da8673 | 288 | * Also sets the device to active mode, so no further configuration will take an effect. |
amateusz | 7:90ce70da8673 | 289 | * To perform any configuration, switch to standby. |
falingtrea | 1:41af2b3eefb5 | 290 | */ |
falingtrea | 1:41af2b3eefb5 | 291 | uint8_t setCommonParameters(RANGE range, RESOLUTION resolution, LOW_NOISE lo_noise, |
amateusz | 7:90ce70da8673 | 292 | DATA_RATE data_rate, OVERSAMPLE_MODE os_mode, HPF_MODE hpf_mode ) const; |
falingtrea | 1:41af2b3eefb5 | 293 | |
falingtrea | 1:41af2b3eefb5 | 294 | /** Ebnable Motion detect mode and interrupt handler |
falingtrea | 1:41af2b3eefb5 | 295 | * @return status of command |
falingtrea | 1:41af2b3eefb5 | 296 | * TODO - need to implement function |
sam_grove | 0:9d1e3a344e4f | 297 | */ |
falingtrea | 1:41af2b3eefb5 | 298 | uint8_t enableMotionDetect(void) const; |
falingtrea | 1:41af2b3eefb5 | 299 | |
falingtrea | 1:41af2b3eefb5 | 300 | /** Enable Pulse Detect mode and interrupt handler |
falingtrea | 1:41af2b3eefb5 | 301 | * @return status of command |
falingtrea | 1:41af2b3eefb5 | 302 | * TODO - need to implement function |
falingtrea | 1:41af2b3eefb5 | 303 | */ |
falingtrea | 1:41af2b3eefb5 | 304 | uint8_t enablePulseDetect(void) const; |
falingtrea | 1:41af2b3eefb5 | 305 | |
falingtrea | 1:41af2b3eefb5 | 306 | /** Enable Orientation mode and interrupt handler |
falingtrea | 1:41af2b3eefb5 | 307 | * @return status of command |
falingtrea | 1:41af2b3eefb5 | 308 | * TODO - need to implement function |
sam_grove | 0:9d1e3a344e4f | 309 | */ |
falingtrea | 1:41af2b3eefb5 | 310 | uint8_t enableOrientationDetect(void) const; |
falingtrea | 1:41af2b3eefb5 | 311 | |
falingtrea | 1:41af2b3eefb5 | 312 | /** Enable Transient detect mode and interrupt handler |
falingtrea | 1:41af2b3eefb5 | 313 | * @return status of command |
falingtrea | 1:41af2b3eefb5 | 314 | * TODO - need to implement function |
falingtrea | 1:41af2b3eefb5 | 315 | */ |
falingtrea | 1:41af2b3eefb5 | 316 | uint8_t enableTransientDetect(void) const; |
falingtrea | 1:41af2b3eefb5 | 317 | |
falingtrea | 1:41af2b3eefb5 | 318 | /** Enable Autosleep function and interrupt handler |
falingtrea | 1:41af2b3eefb5 | 319 | * @return status of command |
falingtrea | 1:41af2b3eefb5 | 320 | * TODO - need to implement function |
falingtrea | 1:41af2b3eefb5 | 321 | */ |
falingtrea | 1:41af2b3eefb5 | 322 | uint8_t enableAutoSleep(void) const; |
falingtrea | 1:41af2b3eefb5 | 323 | |
falingtrea | 1:41af2b3eefb5 | 324 | /** Enbale FIFO function and interrupt handler |
falingtrea | 1:41af2b3eefb5 | 325 | * @return status of command |
falingtrea | 1:41af2b3eefb5 | 326 | * TODO - need to implement function |
falingtrea | 1:41af2b3eefb5 | 327 | */ |
falingtrea | 1:41af2b3eefb5 | 328 | uint8_t enableFIFO(void) const; |
amateusz | 7:90ce70da8673 | 329 | |
falingtrea | 1:41af2b3eefb5 | 330 | /** Put the MMA845x in the Standby mode |
falingtrea | 1:41af2b3eefb5 | 331 | * @return status of command |
sam_grove | 0:9d1e3a344e4f | 332 | */ |
falingtrea | 1:41af2b3eefb5 | 333 | uint8_t standbyMode(void) const; |
amateusz | 7:90ce70da8673 | 334 | |
falingtrea | 1:41af2b3eefb5 | 335 | /** Put the MMA845x in the active mode |
falingtrea | 1:41af2b3eefb5 | 336 | * @return status of command |
falingtrea | 1:41af2b3eefb5 | 337 | */ |
falingtrea | 1:41af2b3eefb5 | 338 | uint8_t activeMode(void) const; |
amateusz | 7:90ce70da8673 | 339 | |
falingtrea | 1:41af2b3eefb5 | 340 | /** Check the MMA845x status register |
falingtrea | 1:41af2b3eefb5 | 341 | * @return status byte |
falingtrea | 1:41af2b3eefb5 | 342 | */ |
falingtrea | 1:41af2b3eefb5 | 343 | uint8_t getStatus(void) const; |
falingtrea | 1:41af2b3eefb5 | 344 | |
amateusz | 7:90ce70da8673 | 345 | |
sam_grove | 0:9d1e3a344e4f | 346 | private: |
amateusz | 7:90ce70da8673 | 347 | |
sam_grove | 0:9d1e3a344e4f | 348 | I2C *_i2c; |
sam_grove | 0:9d1e3a344e4f | 349 | InterruptIn *_int1; |
sam_grove | 0:9d1e3a344e4f | 350 | InterruptIn *_int2; |
sam_grove | 0:9d1e3a344e4f | 351 | uint8_t _i2c_addr; |
falingtrea | 1:41af2b3eefb5 | 352 | char _who_am_i; |
sam_grove | 0:9d1e3a344e4f | 353 | MMA845x_DATA _data; |
falingtrea | 1:41af2b3eefb5 | 354 | bool _polling_mode; |
amateusz | 7:90ce70da8673 | 355 | |
falingtrea | 1:41af2b3eefb5 | 356 | uint8_t init(void); |
amateusz | 7:90ce70da8673 | 357 | |
falingtrea | 1:41af2b3eefb5 | 358 | /** Write to a register (exposed for debugging reasons) |
falingtrea | 1:41af2b3eefb5 | 359 | * Note: most writes are only valid in stop mode |
falingtrea | 1:41af2b3eefb5 | 360 | * @param reg - The register to be written |
falingtrea | 1:41af2b3eefb5 | 361 | * @param data - The data to be written |
falingtrea | 1:41af2b3eefb5 | 362 | */ |
falingtrea | 1:41af2b3eefb5 | 363 | uint8_t writeRegister(uint8_t const reg, uint8_t const data) const; |
amateusz | 7:90ce70da8673 | 364 | |
falingtrea | 1:41af2b3eefb5 | 365 | /** Read from a register (exposed for debugging reasons) |
falingtrea | 1:41af2b3eefb5 | 366 | * @param reg - The register to read from |
falingtrea | 1:41af2b3eefb5 | 367 | * @return The register contents |
falingtrea | 1:41af2b3eefb5 | 368 | */ |
falingtrea | 1:41af2b3eefb5 | 369 | uint8_t readRegister(uint8_t const reg, uint8_t count, char* data) const; |
amateusz | 7:90ce70da8673 | 370 | |
falingtrea | 1:41af2b3eefb5 | 371 | |
sam_grove | 0:9d1e3a344e4f | 372 | }; |
sam_grove | 0:9d1e3a344e4f | 373 | |
sam_grove | 0:9d1e3a344e4f | 374 | #endif |