I think there was a bug with debug mode
Dependents: Generic_Platformer
MMA8452.h@10:ca9ba7ad4e94, 2014-03-04 (annotated)
- Committer:
- ashleymills
- Date:
- Tue Mar 04 11:14:34 2014 +0000
- Revision:
- 10:ca9ba7ad4e94
- Parent:
- 9:dfb0f6a7a455
- Child:
- 11:dfd1e0afcb7b
Some minor changes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 10:ca9ba7ad4e94 | 1 | // Author: Nicholas Herriot, Ashley Mills |
nherriot | 0:bcf2aa85d7f9 | 2 | /* Copyright (c) 2013 Vodafone, MIT License |
nherriot | 0:bcf2aa85d7f9 | 3 | * |
nherriot | 0:bcf2aa85d7f9 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
nherriot | 0:bcf2aa85d7f9 | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
nherriot | 0:bcf2aa85d7f9 | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
nherriot | 0:bcf2aa85d7f9 | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
nherriot | 0:bcf2aa85d7f9 | 8 | * furnished to do so, subject to the following conditions: |
nherriot | 0:bcf2aa85d7f9 | 9 | * |
nherriot | 0:bcf2aa85d7f9 | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
nherriot | 0:bcf2aa85d7f9 | 11 | * substantial portions of the Software. |
nherriot | 0:bcf2aa85d7f9 | 12 | * |
nherriot | 0:bcf2aa85d7f9 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
nherriot | 0:bcf2aa85d7f9 | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
nherriot | 0:bcf2aa85d7f9 | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
nherriot | 0:bcf2aa85d7f9 | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
nherriot | 0:bcf2aa85d7f9 | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
nherriot | 0:bcf2aa85d7f9 | 18 | */ |
nherriot | 0:bcf2aa85d7f9 | 19 | |
nherriot | 0:bcf2aa85d7f9 | 20 | // the SparkFun breakout board defaults to 1, set to 0 if SA0 jumper on the bottom of the board is set |
nherriot | 0:bcf2aa85d7f9 | 21 | // see the Table 10. I2C Device Address Sequence in Freescale MMA8452Q pdf |
nherriot | 0:bcf2aa85d7f9 | 22 | |
nherriot | 0:bcf2aa85d7f9 | 23 | //#define SA0 1 |
nherriot | 0:bcf2aa85d7f9 | 24 | //#if SA0 |
nherriot | 0:bcf2aa85d7f9 | 25 | //#define MMA8452_ADDRESS 0x3A // SA0 is high, 0x1C if low - it should be 0x1D, but we shift now to save shifting in the code |
nherriot | 0:bcf2aa85d7f9 | 26 | //#else |
nherriot | 0:bcf2aa85d7f9 | 27 | //#define MMA8452_ADDRESS 0x1C |
nherriot | 0:bcf2aa85d7f9 | 28 | //#endif |
nherriot | 0:bcf2aa85d7f9 | 29 | |
nherriot | 0:bcf2aa85d7f9 | 30 | //#ifndef MBED_MMA8452 |
nherriot | 0:bcf2aa85d7f9 | 31 | |
nherriot | 0:bcf2aa85d7f9 | 32 | //#define MBED_MMA8452 |
nherriot | 0:bcf2aa85d7f9 | 33 | |
nherriot | 0:bcf2aa85d7f9 | 34 | #include "mbed.h" |
nherriot | 0:bcf2aa85d7f9 | 35 | |
nherriot | 0:bcf2aa85d7f9 | 36 | /** Accelerometer MMA8452 class |
nherriot | 0:bcf2aa85d7f9 | 37 | * |
nherriot | 0:bcf2aa85d7f9 | 38 | * Example: |
nherriot | 0:bcf2aa85d7f9 | 39 | * @code |
nherriot | 0:bcf2aa85d7f9 | 40 | * |
nherriot | 0:bcf2aa85d7f9 | 41 | * #include "mbed.h" |
nherriot | 0:bcf2aa85d7f9 | 42 | * #include "MMA8452.h" |
nherriot | 0:bcf2aa85d7f9 | 43 | * |
nherriot | 0:bcf2aa85d7f9 | 44 | * |
nherriot | 0:bcf2aa85d7f9 | 45 | * Accelerometer_MMA8452 Acc(p28, p27); |
nherriot | 0:bcf2aa85d7f9 | 46 | * serial pc(USBTX, USBRX); |
nherriot | 0:bcf2aa85d7f9 | 47 | * |
nherriot | 0:bcf2aa85d7f9 | 48 | * int main() |
nherriot | 0:bcf2aa85d7f9 | 49 | * { |
nherriot | 0:bcf2aa85d7f9 | 50 | * Acc.init(); |
nherriot | 0:bcf2aa85d7f9 | 51 | * while(1) |
nherriot | 0:bcf2aa85d7f9 | 52 | * { |
nherriot | 0:bcf2aa85d7f9 | 53 | * int x=0, y=0, z=0; |
nherriot | 0:bcf2aa85d7f9 | 54 | * Acc.read_Tilt(&x, &y, &z); |
nherriot | 0:bcf2aa85d7f9 | 55 | * pc.printf("Tilt x: %2.2f degree \n", x); // Print the tilt orientation of the X axis |
nherriot | 0:bcf2aa85d7f9 | 56 | * pc.printf("Tilt y: %2.2f degree \n", y); // Print the tilt orientation of the Y axis |
nherriot | 0:bcf2aa85d7f9 | 57 | * pc.printf("Tilt z: %2.2f degree \n", z); // Print the tilt orientation of the Z axis |
nherriot | 0:bcf2aa85d7f9 | 58 | * wait(1); |
nherriot | 0:bcf2aa85d7f9 | 59 | * } |
nherriot | 0:bcf2aa85d7f9 | 60 | * } |
nherriot | 0:bcf2aa85d7f9 | 61 | * @endcode |
nherriot | 0:bcf2aa85d7f9 | 62 | */ |
nherriot | 0:bcf2aa85d7f9 | 63 | |
nherriot | 0:bcf2aa85d7f9 | 64 | // More info on MCU Master address can be found on section 5.10.1 of http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MMA8452Q |
nherriot | 0:bcf2aa85d7f9 | 65 | #define SA0 1 |
nherriot | 0:bcf2aa85d7f9 | 66 | #if SA0 |
nherriot | 0:bcf2aa85d7f9 | 67 | #define MMA8452_ADDRESS 0x1D // SA0 is high, 0x1C if low - |
nherriot | 0:bcf2aa85d7f9 | 68 | #else |
nherriot | 0:bcf2aa85d7f9 | 69 | #define MMA8452_ADDRESS 0x1C |
nherriot | 0:bcf2aa85d7f9 | 70 | #endif |
nherriot | 0:bcf2aa85d7f9 | 71 | |
nherriot | 0:bcf2aa85d7f9 | 72 | // Register descriptions found in section 6 of pdf |
nherriot | 0:bcf2aa85d7f9 | 73 | #define STATUS 0x00 // Type 'read' : Real time status, should return 0x00 |
nherriot | 0:bcf2aa85d7f9 | 74 | #define OUT_X_MSB 0x01 // Type 'read' : x axis - 8 most significatn bit of a 12 bit sample |
nherriot | 0:bcf2aa85d7f9 | 75 | #define OUT_X_LSB 0x02 // Type 'read' : x axis - 4 least significatn bit of a 12 bit sample |
nherriot | 0:bcf2aa85d7f9 | 76 | #define OUT_Y_MSB 0x03 // Type 'read' : y axis - 8 most significatn bit of a 12 bit sample |
nherriot | 0:bcf2aa85d7f9 | 77 | #define OUT_Y_LSB 0x04 // Type 'read' : y axis - 4 least significatn bit of a 12 bit sample |
nherriot | 0:bcf2aa85d7f9 | 78 | #define OUT_Z_MSB 0x05 // Type 'read' : z axis - 8 most significatn bit of a 12 bit sample |
nherriot | 0:bcf2aa85d7f9 | 79 | #define OUT_Z_LSB 0x06 // Type 'read' : z axis - 4 least significatn bit of a 12 bit sample |
nherriot | 0:bcf2aa85d7f9 | 80 | |
nherriot | 0:bcf2aa85d7f9 | 81 | #define SYSMOD 0x0B // Type 'read' : This tells you if device is active, sleep or standy 0x00=STANDBY 0x01=WAKE 0x02=SLEEP |
nherriot | 0:bcf2aa85d7f9 | 82 | #define WHO_AM_I 0x0D // Type 'read' : This should return the device id of 0x2A |
nherriot | 0:bcf2aa85d7f9 | 83 | |
nherriot | 0:bcf2aa85d7f9 | 84 | #define PL_STATUS 0x10 // Type 'read' : This shows portrait landscape mode orientation |
nherriot | 0:bcf2aa85d7f9 | 85 | #define PL_CFG 0x11 // Type 'read/write' : This allows portrait landscape configuration |
nherriot | 0:bcf2aa85d7f9 | 86 | #define PL_COUNT 0x12 // Type 'read' : This is the portraint landscape debounce counter |
nherriot | 0:bcf2aa85d7f9 | 87 | #define PL_BF_ZCOMP 0x13 // Type 'read' : |
nherriot | 0:bcf2aa85d7f9 | 88 | #define PL_THS_REG 0x14 // Type 'read' : |
nherriot | 0:bcf2aa85d7f9 | 89 | |
nherriot | 0:bcf2aa85d7f9 | 90 | #define FF_MT_CFG 0X15 // Type 'read/write' : Freefaul motion functional block configuration |
nherriot | 0:bcf2aa85d7f9 | 91 | #define FF_MT_SRC 0X16 // Type 'read' : Freefaul motion event source register |
nherriot | 1:ef026bf28798 | 92 | #define FF_MT_THS 0X17 // Type 'read' : Freefaul motion threshold register |
nherriot | 0:bcf2aa85d7f9 | 93 | #define FF_COUNT 0X18 // Type 'read' : Freefaul motion debouce counter |
nherriot | 0:bcf2aa85d7f9 | 94 | |
nherriot | 3:ffb0b1650ca2 | 95 | #define ASLP_COUNT 0x29 // Type 'read/write' : Counter settings for auto sleep |
nherriot | 0:bcf2aa85d7f9 | 96 | #define CTRL_REG_1 0x2A // Type 'read/write' : |
nherriot | 0:bcf2aa85d7f9 | 97 | #define CTRL_REG_2 0x2B // Type 'read/write' : |
nherriot | 0:bcf2aa85d7f9 | 98 | #define CTRL_REG_3 0x2C // Type 'read/write' : |
nherriot | 0:bcf2aa85d7f9 | 99 | #define CTRL_REG_4 0x2D // Type 'read/write' : |
nherriot | 0:bcf2aa85d7f9 | 100 | #define CTRL_REG_5 0x2E // Type 'read/write' : |
nherriot | 0:bcf2aa85d7f9 | 101 | |
nherriot | 3:ffb0b1650ca2 | 102 | // Defined in table 13 of the Freescale PDF |
nherriot | 3:ffb0b1650ca2 | 103 | #define STANDBY 0x00 // State value returned after a SYSMOD request, it can be in state STANDBY, WAKE or SLEEP |
nherriot | 3:ffb0b1650ca2 | 104 | #define WAKE 0x01 // State value returned after a SYSMOD request, it can be in state STANDBY, WAKE or SLEEP |
nherriot | 3:ffb0b1650ca2 | 105 | #define SLEEP 0x02 // State value returned after a SYSMOD request, it can be in state STANDBY, WAKE or SLEEP |
nherriot | 3:ffb0b1650ca2 | 106 | #define ACTIVE 0x01 // Stage value returned and set in Control Register 1, it can be STANDBY=00, or ACTIVE=01 |
nherriot | 3:ffb0b1650ca2 | 107 | |
nherriot | 0:bcf2aa85d7f9 | 108 | |
nherriot | 0:bcf2aa85d7f9 | 109 | |
nherriot | 0:bcf2aa85d7f9 | 110 | #define TILT_STATUS 0x03 // Tilt Status (Read only) |
nherriot | 0:bcf2aa85d7f9 | 111 | #define SRST_STATUS 0x04 // Sample Rate Status Register (Read only) |
nherriot | 0:bcf2aa85d7f9 | 112 | #define SPCNT_STATUS 0x05 // Sleep Count Register (Read/Write) |
nherriot | 0:bcf2aa85d7f9 | 113 | #define INTSU_STATUS 0x06 // Interrupt Setup Register |
nherriot | 0:bcf2aa85d7f9 | 114 | #define MODE_STATUS 0x07 // Mode Register (Read/Write) |
nherriot | 0:bcf2aa85d7f9 | 115 | #define SR_STATUS 0x08 // Auto-Wake and Active Mode Portrait/Landscape Samples per Seconds Register (Read/Write) |
nherriot | 0:bcf2aa85d7f9 | 116 | #define PDET_STATUS 0x09 // Tap/Pulse Detection Register (Read/Write) |
nherriot | 0:bcf2aa85d7f9 | 117 | #define PD_STATUS 0xA // Tap/Pulse Debounce Count Register (Read/Write) |
nherriot | 0:bcf2aa85d7f9 | 118 | |
ashleymills | 10:ca9ba7ad4e94 | 119 | class MMA8452 |
nherriot | 0:bcf2aa85d7f9 | 120 | { |
nherriot | 0:bcf2aa85d7f9 | 121 | public: |
ashleymills | 10:ca9ba7ad4e94 | 122 | |
ashleymills | 10:ca9ba7ad4e94 | 123 | enum OperationalMode { |
ashleymills | 10:ca9ba7ad4e94 | 124 | MODE_STANDBY, |
ashleymills | 10:ca9ba7ad4e94 | 125 | MODE_ACTIVE_2G, |
ashleymills | 10:ca9ba7ad4e94 | 126 | MODE_ACTIVE_4G, |
ashleymills | 10:ca9ba7ad4e94 | 127 | MODE_ACTIVE_8G |
ashleymills | 10:ca9ba7ad4e94 | 128 | }; |
nherriot | 0:bcf2aa85d7f9 | 129 | |
ashleymills | 10:ca9ba7ad4e94 | 130 | enum BitDepth { |
ashleymills | 10:ca9ba7ad4e94 | 131 | BIT_DEPTH_8, |
ashleymills | 10:ca9ba7ad4e94 | 132 | BIT_DEPTH_12 |
ashleymills | 10:ca9ba7ad4e94 | 133 | }; |
nherriot | 0:bcf2aa85d7f9 | 134 | |
nherriot | 0:bcf2aa85d7f9 | 135 | /** Create an accelerometer object connected to the specified I2C object |
nherriot | 0:bcf2aa85d7f9 | 136 | * |
nherriot | 0:bcf2aa85d7f9 | 137 | * @param sda I2C data port |
nherriot | 0:bcf2aa85d7f9 | 138 | * @param scl I2C8452 clock port |
nherriot | 0:bcf2aa85d7f9 | 139 | * |
nherriot | 0:bcf2aa85d7f9 | 140 | */ |
ashleymills | 10:ca9ba7ad4e94 | 141 | MMA8452(PinName sda, PinName scl, int frequency); |
nherriot | 1:ef026bf28798 | 142 | //Accelerometer_MMA8452(PinName sda, PinName scl); |
nherriot | 0:bcf2aa85d7f9 | 143 | |
nherriot | 0:bcf2aa85d7f9 | 144 | /** Destroys an MMA8452 object |
nherriot | 0:bcf2aa85d7f9 | 145 | * |
nherriot | 0:bcf2aa85d7f9 | 146 | */ |
ashleymills | 10:ca9ba7ad4e94 | 147 | ~MMA8452(); |
ashleymills | 6:f6bde04bf8be | 148 | |
nherriot | 3:ffb0b1650ca2 | 149 | /** Get system mode of the MMA8452 (not required) |
nherriot | 3:ffb0b1650ca2 | 150 | * returns 0 for success in reading the system mode of the chip |
nherriot | 3:ffb0b1650ca2 | 151 | * returns 1 for failure in reading the system mode of the chip |
nherriot | 3:ffb0b1650ca2 | 152 | * -currently no retries or waiting is done, this method tries 1 time then exits. |
nherriot | 3:ffb0b1650ca2 | 153 | * |
nherriot | 3:ffb0b1650ca2 | 154 | * This method is used to find out the system mode of the chip ACTIVE = 0x00 or STANDBY = 0x01 |
nherriot | 3:ffb0b1650ca2 | 155 | */ |
ashleymills | 10:ca9ba7ad4e94 | 156 | int getSystemMode(int *dst); |
nherriot | 3:ffb0b1650ca2 | 157 | |
nherriot | 3:ffb0b1650ca2 | 158 | /** Get status of the MMA8452 (not required) |
nherriot | 3:ffb0b1650ca2 | 159 | * returns 0 for success in reading the status of the chip |
nherriot | 3:ffb0b1650ca2 | 160 | * returns 1 for failure in reading the status of the chip |
nherriot | 3:ffb0b1650ca2 | 161 | * -currrently no retries or waiting is done, this method tries 1 time then exits. |
nherriot | 3:ffb0b1650ca2 | 162 | * |
nherriot | 3:ffb0b1650ca2 | 163 | * This method is used to find out the real time status of the device it shows if |
nherriot | 3:ffb0b1650ca2 | 164 | * x,y and z values have been overwritten before they have been read since a change happened. |
nherriot | 3:ffb0b1650ca2 | 165 | * |
nherriot | 3:ffb0b1650ca2 | 166 | */ |
ashleymills | 10:ca9ba7ad4e94 | 167 | int getStatus(int *dst); |
nherriot | 3:ffb0b1650ca2 | 168 | |
nherriot | 3:ffb0b1650ca2 | 169 | |
nherriot | 0:bcf2aa85d7f9 | 170 | /** Activate the MMA8452 (required) |
nherriot | 1:ef026bf28798 | 171 | * returns 0 for success in activating the chip |
nherriot | 1:ef026bf28798 | 172 | * returns 1 for failure in activating the chip |
nherriot | 1:ef026bf28798 | 173 | * -currrently no retries or waiting is done, this method tries 1 time the exits. |
nherriot | 3:ffb0b1650ca2 | 174 | * |
nherriot | 3:ffb0b1650ca2 | 175 | * This will set the device 'active' even if it's already active. It's just a way to force that state. |
nherriot | 1:ef026bf28798 | 176 | */ |
nherriot | 0:bcf2aa85d7f9 | 177 | int activate(); |
nherriot | 3:ffb0b1650ca2 | 178 | |
nherriot | 3:ffb0b1650ca2 | 179 | |
nherriot | 3:ffb0b1650ca2 | 180 | /** Standby the MMA8452 (not required) |
nherriot | 3:ffb0b1650ca2 | 181 | * returns 0 for success in activating the chip |
nherriot | 3:ffb0b1650ca2 | 182 | * returns 1 for failure in activating the chip |
nherriot | 3:ffb0b1650ca2 | 183 | * -currrently no retries or waiting is done, this method tries 1 time the exits. |
nherriot | 3:ffb0b1650ca2 | 184 | * |
nherriot | 3:ffb0b1650ca2 | 185 | * This will set the device 'standby' even if it's already in standby. It's just a way to force that state. |
nherriot | 3:ffb0b1650ca2 | 186 | */ |
nherriot | 3:ffb0b1650ca2 | 187 | int standby(); |
nherriot | 3:ffb0b1650ca2 | 188 | |
nherriot | 3:ffb0b1650ca2 | 189 | |
nherriot | 5:b3d0abd97e55 | 190 | /** get_CTRL_Reg1 the MMA8452 (not required) |
nherriot | 5:b3d0abd97e55 | 191 | * returns 0 for success in activating the chip |
nherriot | 5:b3d0abd97e55 | 192 | * returns 1 for failure in activating the chip |
nherriot | 5:b3d0abd97e55 | 193 | * -currrently no retries or waiting is done, this method tries 1 time the exits. |
nherriot | 5:b3d0abd97e55 | 194 | * |
nherriot | 5:b3d0abd97e55 | 195 | * This will return the state of the control register 1. This holds and sets values for auto wake, sleep mode |
nherriot | 5:b3d0abd97e55 | 196 | * output data rate, fast read mode and active/standby. More info on 6.7 of pdf for MMA8452 Freescale doc. |
nherriot | 5:b3d0abd97e55 | 197 | */ |
ashleymills | 9:dfb0f6a7a455 | 198 | int get_CTRL_Reg1(int* dst); |
nherriot | 5:b3d0abd97e55 | 199 | |
nherriot | 0:bcf2aa85d7f9 | 200 | |
nherriot | 0:bcf2aa85d7f9 | 201 | /** Initialization of device MMA8452 (required) |
nherriot | 0:bcf2aa85d7f9 | 202 | */ |
nherriot | 0:bcf2aa85d7f9 | 203 | void init(); |
nherriot | 0:bcf2aa85d7f9 | 204 | |
nherriot | 1:ef026bf28798 | 205 | /** Read the device ID from the accelerometer |
nherriot | 1:ef026bf28798 | 206 | * |
nherriot | 1:ef026bf28798 | 207 | * @param *deviceID Value of device - is should be 0x2A |
nherriot | 1:ef026bf28798 | 208 | * return 0 for success or |
nherriot | 1:ef026bf28798 | 209 | * return 1 for failure. |
nherriot | 1:ef026bf28798 | 210 | */ |
ashleymills | 10:ca9ba7ad4e94 | 211 | int getDeviceID(int *dst); |
nherriot | 0:bcf2aa85d7f9 | 212 | |
nherriot | 3:ffb0b1650ca2 | 213 | int read_y(); |
nherriot | 3:ffb0b1650ca2 | 214 | |
nherriot | 3:ffb0b1650ca2 | 215 | int read_z(); |
nherriot | 3:ffb0b1650ca2 | 216 | |
nherriot | 0:bcf2aa85d7f9 | 217 | /** Read the x register of the MMA8452 |
nherriot | 0:bcf2aa85d7f9 | 218 | * |
nherriot | 0:bcf2aa85d7f9 | 219 | * @returns The value of x acceleration |
nherriot | 0:bcf2aa85d7f9 | 220 | */ |
ashleymills | 10:ca9ba7ad4e94 | 221 | int readRawX(char *xaxis); |
nherriot | 3:ffb0b1650ca2 | 222 | //int read_x(int& xaxisLSB); |
nherriot | 0:bcf2aa85d7f9 | 223 | /** Read the y register of the MMA8452 |
nherriot | 0:bcf2aa85d7f9 | 224 | * |
nherriot | 0:bcf2aa85d7f9 | 225 | * @returns The value of y acceleration |
nherriot | 0:bcf2aa85d7f9 | 226 | */ |
ashleymills | 10:ca9ba7ad4e94 | 227 | int readRawY(char *yaxis); |
nherriot | 0:bcf2aa85d7f9 | 228 | |
nherriot | 0:bcf2aa85d7f9 | 229 | /** Read the z register of the MMA8452 |
nherriot | 0:bcf2aa85d7f9 | 230 | * |
nherriot | 0:bcf2aa85d7f9 | 231 | * @returns The value of z acceleration |
nherriot | 0:bcf2aa85d7f9 | 232 | */ |
ashleymills | 10:ca9ba7ad4e94 | 233 | int readRawZ(char * zaxis); |
nherriot | 1:ef026bf28798 | 234 | |
nherriot | 1:ef026bf28798 | 235 | /** Read the x,y and z registers of the MMA8452 |
nherriot | 1:ef026bf28798 | 236 | * |
nherriot | 1:ef026bf28798 | 237 | * takes a 2 byte char buffer to store the value |
nherriot | 1:ef026bf28798 | 238 | * for each axis. |
nherriot | 1:ef026bf28798 | 239 | * returns 0 for success, and 1 for failure |
nherriot | 1:ef026bf28798 | 240 | * |
nherriot | 1:ef026bf28798 | 241 | */ |
ashleymills | 10:ca9ba7ad4e94 | 242 | int readRawXYZ(char *x, char *y, char *z); |
nherriot | 0:bcf2aa85d7f9 | 243 | |
nherriot | 0:bcf2aa85d7f9 | 244 | /** Read from specified MMA8452 register |
nherriot | 0:bcf2aa85d7f9 | 245 | * |
nherriot | 0:bcf2aa85d7f9 | 246 | * @param addr The internal registeraddress of the MMA8452 |
nherriot | 0:bcf2aa85d7f9 | 247 | * @returns The value of the register |
nherriot | 0:bcf2aa85d7f9 | 248 | */ |
ashleymills | 10:ca9ba7ad4e94 | 249 | int readRegister(char addr, int *dst); |
nherriot | 0:bcf2aa85d7f9 | 250 | |
nherriot | 0:bcf2aa85d7f9 | 251 | /** Write to specified MMA8452 register |
nherriot | 0:bcf2aa85d7f9 | 252 | * |
nherriot | 0:bcf2aa85d7f9 | 253 | * @param addr The internal registeraddress of the MMA8452 |
nherriot | 0:bcf2aa85d7f9 | 254 | * @param data New value of the register |
nherriot | 0:bcf2aa85d7f9 | 255 | */ |
ashleymills | 10:ca9ba7ad4e94 | 256 | void writeRegister(char addr, char data); |
nherriot | 0:bcf2aa85d7f9 | 257 | |
ashleymills | 10:ca9ba7ad4e94 | 258 | int setOperationalMode(OperationalMode m); |
ashleymills | 10:ca9ba7ad4e94 | 259 | int setBitDepth(BitDepth b); |
nherriot | 0:bcf2aa85d7f9 | 260 | |
nherriot | 0:bcf2aa85d7f9 | 261 | private: |
ashleymills | 10:ca9ba7ad4e94 | 262 | int readRaw(char src, char *dst, int len); |
ashleymills | 8:89272163f395 | 263 | |
ashleymills | 8:89272163f395 | 264 | |
nherriot | 0:bcf2aa85d7f9 | 265 | I2C m_i2c; |
nherriot | 1:ef026bf28798 | 266 | int m_frequency; |
ashleymills | 6:f6bde04bf8be | 267 | int _readAddress; |
ashleymills | 6:f6bde04bf8be | 268 | int _writeAddress; |
nherriot | 0:bcf2aa85d7f9 | 269 | |
nherriot | 0:bcf2aa85d7f9 | 270 | }; |
nherriot | 0:bcf2aa85d7f9 | 271 | |
nherriot | 0:bcf2aa85d7f9 | 272 | //#endif |