A compilation of some hardware sensors and their shared programming interfaces.
MMA8451Q.h@0:8d34cc2ff388, 2014-03-16 (annotated)
- Committer:
- mgottscho
- Date:
- Sun Mar 16 01:48:59 2014 +0000
- Revision:
- 0:8d34cc2ff388
A compilation of various hardware sensors and some shared programming interfaces.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mgottscho | 0:8d34cc2ff388 | 1 | /* MMA8451Q.h |
mgottscho | 0:8d34cc2ff388 | 2 | * Tested with mbed board: FRDM-KL46Z |
mgottscho | 0:8d34cc2ff388 | 3 | * Author: Mark Gottscho |
mgottscho | 0:8d34cc2ff388 | 4 | * mgottscho@ucla.edu |
mgottscho | 0:8d34cc2ff388 | 5 | */ |
mgottscho | 0:8d34cc2ff388 | 6 | |
mgottscho | 0:8d34cc2ff388 | 7 | #ifndef MMA8451Q_H |
mgottscho | 0:8d34cc2ff388 | 8 | #define MMA8451Q_H |
mgottscho | 0:8d34cc2ff388 | 9 | |
mgottscho | 0:8d34cc2ff388 | 10 | #include "mbed.h" |
mgottscho | 0:8d34cc2ff388 | 11 | #include "I2CSensor.h" |
mgottscho | 0:8d34cc2ff388 | 12 | #include "PeriodicSensor.h" |
mgottscho | 0:8d34cc2ff388 | 13 | #include "SleepableSensor.h" |
mgottscho | 0:8d34cc2ff388 | 14 | |
mgottscho | 0:8d34cc2ff388 | 15 | /** |
mgottscho | 0:8d34cc2ff388 | 16 | * This class allows for easy control of an MMA8451Q accelerometer IC. |
mgottscho | 0:8d34cc2ff388 | 17 | */ |
mgottscho | 0:8d34cc2ff388 | 18 | class MMA8451Q : public I2CSensor, public PeriodicSensor, public SleepableSensor { |
mgottscho | 0:8d34cc2ff388 | 19 | public: |
mgottscho | 0:8d34cc2ff388 | 20 | /** |
mgottscho | 0:8d34cc2ff388 | 21 | * Enumeration of allowed output data sampling rates. |
mgottscho | 0:8d34cc2ff388 | 22 | */ |
mgottscho | 0:8d34cc2ff388 | 23 | typedef enum { |
mgottscho | 0:8d34cc2ff388 | 24 | HZ800, |
mgottscho | 0:8d34cc2ff388 | 25 | HZ400, |
mgottscho | 0:8d34cc2ff388 | 26 | HZ200, |
mgottscho | 0:8d34cc2ff388 | 27 | HZ100, |
mgottscho | 0:8d34cc2ff388 | 28 | HZ50, |
mgottscho | 0:8d34cc2ff388 | 29 | HZ12_5, |
mgottscho | 0:8d34cc2ff388 | 30 | HZ6_25, |
mgottscho | 0:8d34cc2ff388 | 31 | HZ1_56 |
mgottscho | 0:8d34cc2ff388 | 32 | } smpl_rate_t; |
mgottscho | 0:8d34cc2ff388 | 33 | |
mgottscho | 0:8d34cc2ff388 | 34 | /** |
mgottscho | 0:8d34cc2ff388 | 35 | * Enumeration of allowed dynamic ranges (full scale) of the accelerometer data. |
mgottscho | 0:8d34cc2ff388 | 36 | * G2: +/- 2G (0.25 mg/level at 14b, 15.6 mg/level at 8b) |
mgottscho | 0:8d34cc2ff388 | 37 | * G4: +/- 4G (0.5 mg/level at 14b, 31.25 mg/level at 8b) |
mgottscho | 0:8d34cc2ff388 | 38 | * G8: +/- 8G (1.0 mg/level at 14b, 62.5 mg/level at 8b) |
mgottscho | 0:8d34cc2ff388 | 39 | */ |
mgottscho | 0:8d34cc2ff388 | 40 | typedef enum { |
mgottscho | 0:8d34cc2ff388 | 41 | G2, |
mgottscho | 0:8d34cc2ff388 | 42 | G4, |
mgottscho | 0:8d34cc2ff388 | 43 | G8 |
mgottscho | 0:8d34cc2ff388 | 44 | } scale_t; |
mgottscho | 0:8d34cc2ff388 | 45 | |
mgottscho | 0:8d34cc2ff388 | 46 | /** |
mgottscho | 0:8d34cc2ff388 | 47 | * @param sda the pin identifier for SDA I2C signal |
mgottscho | 0:8d34cc2ff388 | 48 | * @param scl the pin identifier for SCL I2C signal |
mgottscho | 0:8d34cc2ff388 | 49 | * @param i2c_addr the 8-bit I2C address for this device. Note that LSB is a don't care. |
mgottscho | 0:8d34cc2ff388 | 50 | */ |
mgottscho | 0:8d34cc2ff388 | 51 | MMA8451Q(PinName sda, PinName scl, int i2c_addr); |
mgottscho | 0:8d34cc2ff388 | 52 | |
mgottscho | 0:8d34cc2ff388 | 53 | /** |
mgottscho | 0:8d34cc2ff388 | 54 | */ |
mgottscho | 0:8d34cc2ff388 | 55 | ~MMA8451Q(); |
mgottscho | 0:8d34cc2ff388 | 56 | |
mgottscho | 0:8d34cc2ff388 | 57 | /** |
mgottscho | 0:8d34cc2ff388 | 58 | * Self-initialization to some nice preset. You must ensure the device is first deactivated using setActive(). |
mgottscho | 0:8d34cc2ff388 | 59 | */ |
mgottscho | 0:8d34cc2ff388 | 60 | void selfInit(); |
mgottscho | 0:8d34cc2ff388 | 61 | |
mgottscho | 0:8d34cc2ff388 | 62 | /** |
mgottscho | 0:8d34cc2ff388 | 63 | * Does a soft reset of the device. |
mgottscho | 0:8d34cc2ff388 | 64 | */ |
mgottscho | 0:8d34cc2ff388 | 65 | void reset(); |
mgottscho | 0:8d34cc2ff388 | 66 | |
mgottscho | 0:8d34cc2ff388 | 67 | //I2C specific methods |
mgottscho | 0:8d34cc2ff388 | 68 | |
mgottscho | 0:8d34cc2ff388 | 69 | /** |
mgottscho | 0:8d34cc2ff388 | 70 | * Implements the pure virtual method of the parent I2CSensor class. |
mgottscho | 0:8d34cc2ff388 | 71 | * @returns the 8-bit device identifier. |
mgottscho | 0:8d34cc2ff388 | 72 | */ |
mgottscho | 0:8d34cc2ff388 | 73 | uint8_t whoAmI(); |
mgottscho | 0:8d34cc2ff388 | 74 | |
mgottscho | 0:8d34cc2ff388 | 75 | //Device-specific methods |
mgottscho | 0:8d34cc2ff388 | 76 | |
mgottscho | 0:8d34cc2ff388 | 77 | /** |
mgottscho | 0:8d34cc2ff388 | 78 | * @returns true if the device is active |
mgottscho | 0:8d34cc2ff388 | 79 | */ |
mgottscho | 0:8d34cc2ff388 | 80 | bool isActive(); |
mgottscho | 0:8d34cc2ff388 | 81 | |
mgottscho | 0:8d34cc2ff388 | 82 | /** |
mgottscho | 0:8d34cc2ff388 | 83 | * @param activate if true, enables the device, else disables it |
mgottscho | 0:8d34cc2ff388 | 84 | */ |
mgottscho | 0:8d34cc2ff388 | 85 | void setActive(bool activate); |
mgottscho | 0:8d34cc2ff388 | 86 | |
mgottscho | 0:8d34cc2ff388 | 87 | /** |
mgottscho | 0:8d34cc2ff388 | 88 | * @returns the 8-bit system mode status |
mgottscho | 0:8d34cc2ff388 | 89 | */ |
mgottscho | 0:8d34cc2ff388 | 90 | uint8_t getSystemMode(); |
mgottscho | 0:8d34cc2ff388 | 91 | |
mgottscho | 0:8d34cc2ff388 | 92 | /** |
mgottscho | 0:8d34cc2ff388 | 93 | * @returns true if the device is generating 14b resolution data, otherwise 8b |
mgottscho | 0:8d34cc2ff388 | 94 | */ |
mgottscho | 0:8d34cc2ff388 | 95 | bool is14bDataEnabled(); |
mgottscho | 0:8d34cc2ff388 | 96 | |
mgottscho | 0:8d34cc2ff388 | 97 | /** |
mgottscho | 0:8d34cc2ff388 | 98 | * @param enable if true, sets 14b data, otherwise 8b data |
mgottscho | 0:8d34cc2ff388 | 99 | */ |
mgottscho | 0:8d34cc2ff388 | 100 | void set14bData(bool enable); |
mgottscho | 0:8d34cc2ff388 | 101 | |
mgottscho | 0:8d34cc2ff388 | 102 | /** |
mgottscho | 0:8d34cc2ff388 | 103 | * @returns an enumerated value corresponding to the current output data sample rate |
mgottscho | 0:8d34cc2ff388 | 104 | */ |
mgottscho | 0:8d34cc2ff388 | 105 | smpl_rate_t getOutputDataRate(); |
mgottscho | 0:8d34cc2ff388 | 106 | |
mgottscho | 0:8d34cc2ff388 | 107 | /** |
mgottscho | 0:8d34cc2ff388 | 108 | * @param the enumerated value corresponding to the output data sample rate to use |
mgottscho | 0:8d34cc2ff388 | 109 | */ |
mgottscho | 0:8d34cc2ff388 | 110 | void setOutputDataRate(smpl_rate_t rate); |
mgottscho | 0:8d34cc2ff388 | 111 | |
mgottscho | 0:8d34cc2ff388 | 112 | /** |
mgottscho | 0:8d34cc2ff388 | 113 | * @returns an enumerated value corresponding to the full scale (range) of the output data |
mgottscho | 0:8d34cc2ff388 | 114 | */ |
mgottscho | 0:8d34cc2ff388 | 115 | scale_t getScale(); |
mgottscho | 0:8d34cc2ff388 | 116 | |
mgottscho | 0:8d34cc2ff388 | 117 | /** |
mgottscho | 0:8d34cc2ff388 | 118 | * @param scale sets the sample scale via the enumerated value |
mgottscho | 0:8d34cc2ff388 | 119 | */ |
mgottscho | 0:8d34cc2ff388 | 120 | void setScale(scale_t scale); |
mgottscho | 0:8d34cc2ff388 | 121 | |
mgottscho | 0:8d34cc2ff388 | 122 | /** |
mgottscho | 0:8d34cc2ff388 | 123 | * Enables an interrupt output signal from the device whenever data (XYZ) is generated. |
mgottscho | 0:8d34cc2ff388 | 124 | * @param enable Enables/disables interrupt |
mgottscho | 0:8d34cc2ff388 | 125 | * @param pinSelect if false, INT2. if true, INT1 |
mgottscho | 0:8d34cc2ff388 | 126 | */ |
mgottscho | 0:8d34cc2ff388 | 127 | void enableDataReadyInterrupt(bool enable, bool pinSelect); |
mgottscho | 0:8d34cc2ff388 | 128 | |
mgottscho | 0:8d34cc2ff388 | 129 | |
mgottscho | 0:8d34cc2ff388 | 130 | //Device-specific data retrieval methods |
mgottscho | 0:8d34cc2ff388 | 131 | /** |
mgottscho | 0:8d34cc2ff388 | 132 | * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value. |
mgottscho | 0:8d34cc2ff388 | 133 | * The latter is preferred if this object is set up to sample using interrupts. |
mgottscho | 0:8d34cc2ff388 | 134 | * @returns a 14-bit value representing the latest data sample for the X dimension, centered at 0. |
mgottscho | 0:8d34cc2ff388 | 135 | */ |
mgottscho | 0:8d34cc2ff388 | 136 | int16_t getX(bool sampleNow); |
mgottscho | 0:8d34cc2ff388 | 137 | |
mgottscho | 0:8d34cc2ff388 | 138 | /** |
mgottscho | 0:8d34cc2ff388 | 139 | * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value. |
mgottscho | 0:8d34cc2ff388 | 140 | * The latter is preferred if this object is set up to sample using interrupts. |
mgottscho | 0:8d34cc2ff388 | 141 | * @returns a 14-bit value representing the latest data sample for the Y dimension, centered at 0. |
mgottscho | 0:8d34cc2ff388 | 142 | */ |
mgottscho | 0:8d34cc2ff388 | 143 | int16_t getY(bool sampleNow); |
mgottscho | 0:8d34cc2ff388 | 144 | |
mgottscho | 0:8d34cc2ff388 | 145 | /** |
mgottscho | 0:8d34cc2ff388 | 146 | * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value. |
mgottscho | 0:8d34cc2ff388 | 147 | * The latter is preferred if this object is set up to sample using interrupts. |
mgottscho | 0:8d34cc2ff388 | 148 | * @returns a 14-bit value representing the latest data sample for the Z dimension, centered at 0. |
mgottscho | 0:8d34cc2ff388 | 149 | */ |
mgottscho | 0:8d34cc2ff388 | 150 | int16_t getZ(bool sampleNow); |
mgottscho | 0:8d34cc2ff388 | 151 | |
mgottscho | 0:8d34cc2ff388 | 152 | /** |
mgottscho | 0:8d34cc2ff388 | 153 | * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value. |
mgottscho | 0:8d34cc2ff388 | 154 | * The latter is preferred if this object is set up to sample using interrupts. |
mgottscho | 0:8d34cc2ff388 | 155 | * Returns the latest X data reading as a float in Gs |
mgottscho | 0:8d34cc2ff388 | 156 | */ |
mgottscho | 0:8d34cc2ff388 | 157 | float getFloatX(bool sampleNow); |
mgottscho | 0:8d34cc2ff388 | 158 | |
mgottscho | 0:8d34cc2ff388 | 159 | /** |
mgottscho | 0:8d34cc2ff388 | 160 | * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value. |
mgottscho | 0:8d34cc2ff388 | 161 | * The latter is preferred if this object is set up to sample using interrupts. |
mgottscho | 0:8d34cc2ff388 | 162 | * Returns the latest Y data reading as a float in Gs |
mgottscho | 0:8d34cc2ff388 | 163 | */ |
mgottscho | 0:8d34cc2ff388 | 164 | float getFloatY(bool sampleNow); |
mgottscho | 0:8d34cc2ff388 | 165 | |
mgottscho | 0:8d34cc2ff388 | 166 | /** |
mgottscho | 0:8d34cc2ff388 | 167 | * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value. |
mgottscho | 0:8d34cc2ff388 | 168 | * The latter is preferred if this object is set up to sample using interrupts. |
mgottscho | 0:8d34cc2ff388 | 169 | * Returns the latest Z data reading as a float in Gs |
mgottscho | 0:8d34cc2ff388 | 170 | */ |
mgottscho | 0:8d34cc2ff388 | 171 | float getFloatZ(bool sampleNow); |
mgottscho | 0:8d34cc2ff388 | 172 | |
mgottscho | 0:8d34cc2ff388 | 173 | virtual void sleep(); |
mgottscho | 0:8d34cc2ff388 | 174 | |
mgottscho | 0:8d34cc2ff388 | 175 | virtual void wake(); |
mgottscho | 0:8d34cc2ff388 | 176 | |
mgottscho | 0:8d34cc2ff388 | 177 | private: |
mgottscho | 0:8d34cc2ff388 | 178 | /** |
mgottscho | 0:8d34cc2ff388 | 179 | * Interrupt service routine for fetching accelerometer data from the device. |
mgottscho | 0:8d34cc2ff388 | 180 | */ |
mgottscho | 0:8d34cc2ff388 | 181 | virtual void __sample_data_ISR(); |
mgottscho | 0:8d34cc2ff388 | 182 | |
mgottscho | 0:8d34cc2ff388 | 183 | ///////////////// CONSTANTS ///////////////////// |
mgottscho | 0:8d34cc2ff388 | 184 | |
mgottscho | 0:8d34cc2ff388 | 185 | //Device register addresses |
mgottscho | 0:8d34cc2ff388 | 186 | static const uint8_t STATUS = 0x00; |
mgottscho | 0:8d34cc2ff388 | 187 | static const uint8_t F_STATUS = 0x00; |
mgottscho | 0:8d34cc2ff388 | 188 | static const uint8_t OUT_X_MSB = 0x01; |
mgottscho | 0:8d34cc2ff388 | 189 | static const uint8_t OUT_X_LSB = 0x02; |
mgottscho | 0:8d34cc2ff388 | 190 | static const uint8_t OUT_Y_MSB = 0x03; |
mgottscho | 0:8d34cc2ff388 | 191 | static const uint8_t OUT_Y_LSB = 0x04; |
mgottscho | 0:8d34cc2ff388 | 192 | static const uint8_t OUT_Z_MSB = 0x05; |
mgottscho | 0:8d34cc2ff388 | 193 | static const uint8_t OUT_Z_LSB = 0x06; |
mgottscho | 0:8d34cc2ff388 | 194 | static const uint8_t F_SETUP = 0x09; |
mgottscho | 0:8d34cc2ff388 | 195 | static const uint8_t TRIG_CFG = 0x0A; |
mgottscho | 0:8d34cc2ff388 | 196 | static const uint8_t SYSMOD = 0x0B; |
mgottscho | 0:8d34cc2ff388 | 197 | static const uint8_t INT_SOURCE = 0x0C; |
mgottscho | 0:8d34cc2ff388 | 198 | static const uint8_t WHO_AM_I = 0x0D; |
mgottscho | 0:8d34cc2ff388 | 199 | static const uint8_t XYZ_DATA_CFG = 0x0E; |
mgottscho | 0:8d34cc2ff388 | 200 | static const uint8_t HP_FILTER_CUTOFF = 0x0F; |
mgottscho | 0:8d34cc2ff388 | 201 | static const uint8_t PL_STATUS = 0x10; |
mgottscho | 0:8d34cc2ff388 | 202 | static const uint8_t PL_CFG = 0x11; |
mgottscho | 0:8d34cc2ff388 | 203 | static const uint8_t PL_COUNT = 0x12; |
mgottscho | 0:8d34cc2ff388 | 204 | static const uint8_t PL_BF_ZCOMP = 0x13; |
mgottscho | 0:8d34cc2ff388 | 205 | static const uint8_t P_L_THS_REG = 0x14; |
mgottscho | 0:8d34cc2ff388 | 206 | static const uint8_t FF_MT_CFG = 0x15; |
mgottscho | 0:8d34cc2ff388 | 207 | static const uint8_t FF_MT_SRC = 0x16; |
mgottscho | 0:8d34cc2ff388 | 208 | static const uint8_t FF_MT_THS = 0x17; |
mgottscho | 0:8d34cc2ff388 | 209 | static const uint8_t FF_MT_COUNT = 0x18; |
mgottscho | 0:8d34cc2ff388 | 210 | static const uint8_t TRANSIENT_CFG = 0x1D; |
mgottscho | 0:8d34cc2ff388 | 211 | static const uint8_t TRANSIENT_SRC = 0x1E; |
mgottscho | 0:8d34cc2ff388 | 212 | static const uint8_t TRANSIENT_THS = 0x1F; |
mgottscho | 0:8d34cc2ff388 | 213 | static const uint8_t PULSE_CFG = 0x21; |
mgottscho | 0:8d34cc2ff388 | 214 | static const uint8_t PULSE_SRC = 0x22; |
mgottscho | 0:8d34cc2ff388 | 215 | static const uint8_t PULSE_THSX = 0x23; |
mgottscho | 0:8d34cc2ff388 | 216 | static const uint8_t PULSE_THSY = 0x24; |
mgottscho | 0:8d34cc2ff388 | 217 | static const uint8_t PULSE_THSZ = 0x25; |
mgottscho | 0:8d34cc2ff388 | 218 | static const uint8_t PULSE_TMLT = 0x26; |
mgottscho | 0:8d34cc2ff388 | 219 | static const uint8_t PULSE_LTCY = 0x27; |
mgottscho | 0:8d34cc2ff388 | 220 | static const uint8_t PULSE_WIND = 0x28; |
mgottscho | 0:8d34cc2ff388 | 221 | static const uint8_t ASLP_COUNT = 0x29; |
mgottscho | 0:8d34cc2ff388 | 222 | static const uint8_t CTRL_REG1 = 0x2A; |
mgottscho | 0:8d34cc2ff388 | 223 | static const uint8_t CTRL_REG2 = 0x2B; |
mgottscho | 0:8d34cc2ff388 | 224 | static const uint8_t CTRL_REG3 = 0x2C; |
mgottscho | 0:8d34cc2ff388 | 225 | static const uint8_t CTRL_REG4 = 0x2D; |
mgottscho | 0:8d34cc2ff388 | 226 | static const uint8_t CTRL_REG5 = 0x2E; |
mgottscho | 0:8d34cc2ff388 | 227 | static const uint8_t OFF_X = 0x2F; |
mgottscho | 0:8d34cc2ff388 | 228 | static const uint8_t OFF_Y = 0x30; |
mgottscho | 0:8d34cc2ff388 | 229 | static const uint8_t OFF_Z = 0x31; |
mgottscho | 0:8d34cc2ff388 | 230 | |
mgottscho | 0:8d34cc2ff388 | 231 | //Register masks |
mgottscho | 0:8d34cc2ff388 | 232 | static const uint8_t XYZ_DATA_CFG_HPF_OUT_MASK = 0x10; //b0001 0000 |
mgottscho | 0:8d34cc2ff388 | 233 | static const uint8_t XYZ_DATA_CFG_FS_MASK = 0x03; //b0000 0011 |
mgottscho | 0:8d34cc2ff388 | 234 | static const uint8_t CTRL_REG1_ASLP_RATE_MASK = 0xC0; //b1100 0000 |
mgottscho | 0:8d34cc2ff388 | 235 | static const uint8_t CTRL_REG1_DR_MASK = 0x38; //b0011 1000 |
mgottscho | 0:8d34cc2ff388 | 236 | static const uint8_t CTRL_REG1_LNOISE_MASK = 0x04; //b0000 0100 |
mgottscho | 0:8d34cc2ff388 | 237 | static const uint8_t CTRL_REG1_F_READ_MASK = 0x02; //b0000 0010 |
mgottscho | 0:8d34cc2ff388 | 238 | static const uint8_t CTRL_REG1_ACTIVE_MASK = 0x01; //b0000 0001 |
mgottscho | 0:8d34cc2ff388 | 239 | static const uint8_t CTRL_REG2_ST_MASK = 0x80; //b1000 0000 |
mgottscho | 0:8d34cc2ff388 | 240 | static const uint8_t CTRL_REG2_RST_MASK = 0x40; //b0100 0000 |
mgottscho | 0:8d34cc2ff388 | 241 | static const uint8_t CTRL_REG2_SMODS_MASK = 0x18; //b0001 1000 |
mgottscho | 0:8d34cc2ff388 | 242 | static const uint8_t CTRL_REG2_SLPE_MASK = 0x04; //b0000 0100 |
mgottscho | 0:8d34cc2ff388 | 243 | static const uint8_t CTRL_REG2_MODS_MASK = 0x03; //b0000 0011 |
mgottscho | 0:8d34cc2ff388 | 244 | static const uint8_t CTRL_REG3_FIFO_GATE_MASK = 0x80; //b1000 0000 |
mgottscho | 0:8d34cc2ff388 | 245 | static const uint8_t CTRL_REG3_WAKE_TRANS_MASK = 0x40; //b0100 0000 |
mgottscho | 0:8d34cc2ff388 | 246 | static const uint8_t CTRL_REG3_WAKE_LNDPRT_MASK = 0x20; //b0010 0000 |
mgottscho | 0:8d34cc2ff388 | 247 | static const uint8_t CTRL_REG3_WAKE_PULSE_MASK = 0x10; //b0001 0000 |
mgottscho | 0:8d34cc2ff388 | 248 | static const uint8_t CTRL_REG3_WAKE_FF_MT_MASK = 0x08; //b0000 1000 |
mgottscho | 0:8d34cc2ff388 | 249 | static const uint8_t CTRL_REG3_IPOL_MASK = 0x02; //b0000 0010 |
mgottscho | 0:8d34cc2ff388 | 250 | static const uint8_t CTRL_REG3_PP_OD_MASK = 0x01; //b0000 0001 |
mgottscho | 0:8d34cc2ff388 | 251 | static const uint8_t CTRL_REG4_INT_EN_ASLP_MASK = 0x80; //b1000 0000 |
mgottscho | 0:8d34cc2ff388 | 252 | static const uint8_t CTRL_REG4_INT_EN_FIFO_MASK = 0x40; //b0100 0000 |
mgottscho | 0:8d34cc2ff388 | 253 | static const uint8_t CTRL_REG4_INT_EN_TRANS_MASK = 0x20; //b0010 0000 |
mgottscho | 0:8d34cc2ff388 | 254 | static const uint8_t CTRL_REG4_INT_EN_LNDPR_MASK = 0x10; //b0001 0000 |
mgottscho | 0:8d34cc2ff388 | 255 | static const uint8_t CTRL_REG4_INT_EN_PULSE_MASK = 0x08; //b0000 1000 |
mgottscho | 0:8d34cc2ff388 | 256 | static const uint8_t CTRL_REG4_INT_EN_FF_MT_MASK = 0x04; //b0000 0100 |
mgottscho | 0:8d34cc2ff388 | 257 | static const uint8_t CTRL_REG4_INT_EN_DRDY_MASK = 0x01; //b0000 0001 |
mgottscho | 0:8d34cc2ff388 | 258 | static const uint8_t CTRL_REG5_INT_CFG_ASLP_MASK = 0x80; //b1000 0000 |
mgottscho | 0:8d34cc2ff388 | 259 | static const uint8_t CTRL_REG5_INT_CFG_FIFO_MASK = 0x40; //b0100 0000 |
mgottscho | 0:8d34cc2ff388 | 260 | static const uint8_t CTRL_REG5_INT_CFG_TRANS_MASK = 0x20; //b0010 0000 |
mgottscho | 0:8d34cc2ff388 | 261 | static const uint8_t CTRL_REG5_INT_CFG_LNDPRT_MASK = 0x10; //b0001 0000 |
mgottscho | 0:8d34cc2ff388 | 262 | static const uint8_t CTRL_REG5_INT_CFG_PULSE_MASK = 0x08; //b0000 1000 |
mgottscho | 0:8d34cc2ff388 | 263 | static const uint8_t CTRL_REG5_INT_CFG_FF_MT_MASK = 0x04; //b0000 0100 |
mgottscho | 0:8d34cc2ff388 | 264 | static const uint8_t CTRL_REG5_INT_CFG_DRDY_MASK = 0x01; //b0000 0001 |
mgottscho | 0:8d34cc2ff388 | 265 | |
mgottscho | 0:8d34cc2ff388 | 266 | //Mapping of sensor values |
mgottscho | 0:8d34cc2ff388 | 267 | static const float G2_DIV = 0.00024414; // in Gs/level, 1/4096 |
mgottscho | 0:8d34cc2ff388 | 268 | static const float G4_DIV = 0.00048828; // in Gs/level, 1/2048 |
mgottscho | 0:8d34cc2ff388 | 269 | static const float G8_DIV = 0.00097656; // in Gs/level, 1/1024 |
mgottscho | 0:8d34cc2ff388 | 270 | |
mgottscho | 0:8d34cc2ff388 | 271 | |
mgottscho | 0:8d34cc2ff388 | 272 | ////////////// VARIABLES ///////////////// |
mgottscho | 0:8d34cc2ff388 | 273 | |
mgottscho | 0:8d34cc2ff388 | 274 | //MMA8451Q state ("cached" from the values actually on the device) |
mgottscho | 0:8d34cc2ff388 | 275 | volatile int16_t __x; |
mgottscho | 0:8d34cc2ff388 | 276 | volatile int16_t __y; |
mgottscho | 0:8d34cc2ff388 | 277 | volatile int16_t __z; |
mgottscho | 0:8d34cc2ff388 | 278 | |
mgottscho | 0:8d34cc2ff388 | 279 | bool __active; |
mgottscho | 0:8d34cc2ff388 | 280 | bool __14b_data_enabled; |
mgottscho | 0:8d34cc2ff388 | 281 | smpl_rate_t __output_data_rate; |
mgottscho | 0:8d34cc2ff388 | 282 | scale_t __scale; |
mgottscho | 0:8d34cc2ff388 | 283 | float __div; //current sensor mapping |
mgottscho | 0:8d34cc2ff388 | 284 | }; |
mgottscho | 0:8d34cc2ff388 | 285 | |
mgottscho | 0:8d34cc2ff388 | 286 | #endif |