minor changes to support mobile life IoT project
Fork of FXOS8700CQ by
Revision 3:2ce85aa45d7d, committed 2014-05-28
- Comitter:
- trm
- Date:
- Wed May 28 18:38:09 2014 +0000
- Parent:
- 2:4c2f8a3549a9
- Child:
- 4:e2fe752b881e
- Commit message:
- Updates to documentation and comments.
Changed in this revision
FXOS8700CQ.cpp | Show annotated file Show diff for this revision Revisions of this file |
FXOS8700CQ.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/FXOS8700CQ.cpp Wed May 28 17:08:33 2014 +0000 +++ b/FXOS8700CQ.cpp Wed May 28 18:38:09 2014 +0000 @@ -8,18 +8,16 @@ { // Initialization of the FXOS8700CQ dev_i2c.frequency(I2C_400K); // Use maximum I2C frequency - uint8_t data[6] = {0, 0, 0, 0, 0, 0}; // target device write address, single byte to write at address + uint8_t data[6] = {0, 0, 0, 0, 0, 0}; // to write over I2C: device register, up to 5 bytes data // TODO: verify WHOAMI? - // TODO: un-magic-number register configuration - // Place peripheral in standby for configuration, resetting CTRL_REG1 data[0] = FXOS8700CQ_CTRL_REG1; data[1] = 0x00; // this will unset CTRL_REG1:active write_regs(data, 2); - // Now that the device is in standby, configure registers + // Now that the device is in standby, configure registers at will // Setup for write-though for CTRL_REG series // Keep data[0] as FXOS8700CQ_CTRL_REG1 @@ -33,15 +31,15 @@ FXOS8700CQ_CTRL_REG2_MODS2(1); // 0b01 gives low noise, low power oversampling mode // No configuration changes from default 0x00 in CTRL_REG3 - // Interrupts will be active low + // Interrupts will be active low, their outputs in push-pull mode data[3] = 0x00; // FXOS8700CQ_CTRL_REG4; data[4] = - FXOS8700CQ_CTRL_REG4_INT_EN_DRDY; + FXOS8700CQ_CTRL_REG4_INT_EN_DRDY; // Enable the Data-Ready interrupt // No configuration changes from default 0x00 in CTRL_REG5 - // Data ready interrupt will appear on INT2 + // Data-Ready interrupt will appear on INT2 data[5] = 0x00; // Write to the 5 CTRL_REG registers @@ -153,6 +151,7 @@ read_regs(FXOS8700CQ_XYZ_DATA_CFG, &data, 1); data &= FXOS8700CQ_XYZ_DATA_CFG_FS2(3); // mask with 0b11 + // Choose output value based on masked data switch(data) { case FXOS8700CQ_XYZ_DATA_CFG_FS2(0): return 2; @@ -167,6 +166,8 @@ // Private methods +// Excepting the call to dev_i2c.frequency() in the constructor, +// the use of the mbed I2C class is restricted to these methods void FXOS8700CQ::read_regs(int reg_addr, uint8_t* data, int len) { char t[1] = {reg_addr};
--- a/FXOS8700CQ.h Wed May 28 17:08:33 2014 +0000 +++ b/FXOS8700CQ.h Wed May 28 18:38:09 2014 +0000 @@ -116,7 +116,7 @@ * A driver on top of mbed-I2C to operate the FXOS8700CQ accelerometer/magnetometer * on the FRDM-K64F. * -* Warning: incomplete code! +* Code has been completed, but likely not optimized and potentially buggy. */ class FXOS8700CQ { @@ -137,9 +137,18 @@ void enable(void); void disable(void); + + /** + * @return the contents of device register FXOS8700CQ_WHOAMI 0x0D, + * should be FXOS8700CQ_WHOAMI_VAL 0xC7 + */ uint8_t get_whoami(void); + + /** + * @return the contents of device register FXOS8700CQ_STATUS 0x00 + */ uint8_t status(void); - + /** * Data retrieval from the FXOS8700CQ * @@ -148,10 +157,10 @@ * @return 0 on success, non-zero on failure */ uint8_t get_data(SRAWDATA *accel_data, SRAWDATA *magn_data); - + /** * Retrieve the full-range scale value of the accelerometer - * + * * @return 2, 4, or 8, depending on part configuration; 0 on error */ uint8_t get_accel_scale(void); @@ -161,7 +170,7 @@ private: I2C dev_i2c; // instance of the mbed I2C class uint8_t dev_addr; // Device I2C address, in (7-bit << 1) form - bool enabled; + bool enabled; // keep track of enable bit of device // I2C helper methods void read_regs(int reg_addr, uint8_t* data, int len);