Very simple library for the FXOS8700 combined magnetometer and accelerometer

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FXOS8700.h Source File

FXOS8700.h

00001 /* Copyright (c) 2017 JHD
00002  */
00003 
00004 #ifndef FXOS8700_H
00005 #define FXOS8700_H
00006 
00007 #include "mbed.h"
00008 #include "stdint.h"
00009 
00010 struct FXOS8700_data
00011 {
00012     int16_t x;
00013     int16_t y;
00014     int16_t z;
00015     int16_t mx;
00016     int16_t my;
00017     int16_t mz;
00018 
00019 };
00020 
00021 //  FXOS8700 registers
00022 #define FXOS8700CQ_STATUS 0x00
00023 #define FXOS8700CQ_WHOAMI 0x0D
00024 #define FXOS8700CQ_XYZ_DATA_CFG 0x0E
00025 #define FXOS8700CQ_CTRL_REG1 0x2A
00026 #define FXOS8700CQ_M_CTRL_REG1 0x5B
00027 #define FXOS8700CQ_M_CTRL_REG2 0x5C
00028 #define FXOS8700CQ_WHOAMI_VAL 0xC7
00029 
00030 //!Library for the FXOS8700 magnetometer.
00031 
00032 class FXOS8700
00033 {
00034 public:
00035   //!Creates an instance of the class.
00036   /*!
00037   Connect module at I2C address addr using I2C port pins sda and scl.
00038   */
00039   FXOS8700(PinName sda, PinName scl, int chip_address);
00040   
00041   /*!
00042   Destroys instance.
00043   */ 
00044   ~FXOS8700 ();
00045   
00046   //!Reads the current registers.
00047   int i2c_address;
00048   FXOS8700_data read();  
00049   bool i2c_error;
00050   
00051 private:
00052   
00053   I2C i2c;
00054   FXOS8700_data readdata;
00055 
00056 };
00057 
00058 #endif