Vins version of FXOS8700CQ library for use in mbed online compiler
Fork of FXOS8700CQ by
Diff: FXOS8700CQ.cpp
- Revision:
- 5:7bdb0d5e5287
- Parent:
- 3:2ce85aa45d7d
diff -r e2fe752b881e -r 7bdb0d5e5287 FXOS8700CQ.cpp --- a/FXOS8700CQ.cpp Tue Jun 03 19:02:19 2014 +0000 +++ b/FXOS8700CQ.cpp Sun Jan 10 17:45:05 2016 +0000 @@ -30,20 +30,26 @@ FXOS8700CQ_CTRL_REG2_SMODS2(3) | // 0b11 gives low power sleep oversampling mode FXOS8700CQ_CTRL_REG2_MODS2(1); // 0b01 gives low noise, low power oversampling mode +//MPL - don't configure interrupts here. +/* // No configuration changes from default 0x00 in CTRL_REG3 // Interrupts will be active low, their outputs in push-pull mode data[3] = 0x00; + // FXOS8700CQ_CTRL_REG4; - data[4] = + data[4] = 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[5] = 0x00; - // Write to the 5 CTRL_REG registers - write_regs(data, 6); + // Write to the 4 CTRL_REG registers + + write_regs(data, 6); +*/ + write_regs(data, 3); // FXOS8700CQ_XYZ_DATA_CFG data[0] = FXOS8700CQ_XYZ_DATA_CFG; @@ -69,6 +75,7 @@ // Write to the 3 M_CTRL_REG registers write_regs(data, 4); + // Peripheral is configured, but disabled enabled = false; } @@ -88,6 +95,73 @@ enabled = true; } +//MPL +uint8_t FXOS8700CQ::config_int( void) +{ + + /*don't enable interrupts in constructor. Do that here. */ + + /* todo: pass in a structure and have this function enable the interrupts you want, set the pin you want them to come out on, and set whether active high or low */ + + uint8_t data[2]; + + //external interrupt signal is active low & push-pull by default (bit value 0). + data[0] = FXOS8700CQ_CTRL_REG3; + data[1] = 0x08; //enable freefall/motion detection interrupt to wake sensor from sleep mode + write_regs(data, 2); + + data[0] = FXOS8700CQ_CTRL_REG4; + data[1] = 0x04; //enable freefall/motion detection interrupt + write_regs(data, 2); + + //by default it comes out on INT2 + //INT2 connected to PTD1 on FRDM-KL26Z + data[0] = FXOS8700CQ_CTRL_REG5; + data[1] = 0x00; //interrupts come out on INT2 + write_regs(data, 2); + + //todo: what is the correct return value for okay? + return 99; +} + +//MPL +void FXOS8700CQ::clear_int( void) +{ + /* todo: pass in a structure and have this function clear the interrupts you want */ + + //this is only for the freefall / motion detection + + uint8_t data[2]; + + read_regs(FXOS8700CQ_INT_SOURCE, &data[1], 1); // need to clear this because we had selected to latch the interrupt + //printf("INT_SOURCE = %x\n",data[1]); + + read_regs(FXOS8700CQ_A_FFMT_SRC, &data[1], 1); //clear the motion interrupt because we enabled it + //printf("A_FFMT_SRC = %x\n",data[1]); + +} + +//MPL +uint8_t FXOS8700CQ::config_feature( void) +{ + //dont enable specific features (tap detection, motion detection, etc) in constructor - do that here +//todo: should this be in a separate function that allows users to select what capabilities to enable? + +//MPL - enable motion detection + + uint8_t data[2]; + + data[0] = FXOS8700CQ_A_FFMT_CFG; + data[1] = 0x78; //(don't latch event in register.) bit6: 1 motion flag. bits5,4,3: 1 enable detection in all 3 accel axis + write_regs(data, 2); + + data[0] = FXOS8700CQ_A_FFMT_THS; + data[1] = 0x07; //will this work?? //do I need to enable the debounce filter? + write_regs(data, 2); + + return 0; // not implemented return yet + +} void FXOS8700CQ::disable(void) { uint8_t data[2];