MPL3115A2 driver

Dependents:   lmic_NAmote_GPS_tjm lmic_NAmote_GPS_tjm Senet NAMote scpi_sx127x ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mpl3115a2.h Source File

mpl3115a2.h

00001 #include "mbed.h"
00002 
00003 /*
00004  * MPL3115A2 Registers
00005  */ 
00006 #define STATUS_REG            0x00 // STATUS Register
00007 
00008 #define OUT_P_MSB_REG         0x01 // Bits 12-19 of 20-bit real-time Pressure sample 
00009 #define OUT_P_CSB_REG         0x02 // Bits 4-11 of 20-bit real-time Pressure sample 
00010 #define OUT_P_LSB_REG         0x03 // Bits 0-3 of 20-bit real-time Pressure sample 
00011 #define OUT_T_MSB_REG         0x04 // Bits 4-11 of 12-bit real-time Temperature sample 
00012 #define OUT_T_LSB_REG         0x05 // Bits 0-3 of 12-bit real-time Temperature sample 
00013 
00014 #define DR_STATUS             0x06 // Data Ready status information 
00015 
00016 #define OUT_P_DELTA_MSB_REG   0x07 // Bits 12-19 of 20-bit Pressure change data 
00017 #define OUT_P_DELTA_CSB_REG   0x08 // Bits 4-11 of 20-bit Pressure change data 
00018 #define OUT_P_DELTA_LSB_REG   0x09 // Bits 0-3 of 20-bit Pressure change data 
00019 #define OUT_T_DELTA_MSB_REG   0x0A // Bits 4-11 of 12-bit Temperature change data 
00020 #define OUT_T_DELTA_LSB_REG   0x0B // Bits 0-3 of 12-bit Temperature change data 
00021 
00022 #define MPL3115_ID            0x0C // Fixed Device ID Number = 0xC4 
00023 
00024 #define F_STATUS_REG          0x0D // FIFO Status 
00025 #define F_DATA_REG            0x0E // FIFO 8-bit data access 
00026 #define F_SETUP_REG           0x0F // FIFO setup 
00027 #define TIME_DLY_REG          0x10 // Time since FIFO overflow 
00028 
00029 #define SYSMOD_REG            0x11 // Current system mode 
00030 #define INT_SOURCE_REG        0x12 // Interrupt status 
00031 #define PT_DATA_CFG_REG       0x13 // Data event flag configuration 
00032 
00033 #define BAR_IN_MSB_REG        0x14 // Barometric input for Altitude calculation bits 8-15 
00034 #define BAR_IN_LSB_REG        0x15 // Barometric input for Altitude calculation bits 0-7 
00035 
00036 #define P_TGT_MSB_REG         0x16 // Pressure/Altitude target value bits 8-15 
00037 #define P_TGT_LSB_REG         0x17 // Pressure/Altitude target value bits 0-7 
00038 #define T_TGT_REG             0x18 // Temperature target value 
00039 
00040 #define P_WND_MSB_REG         0x19 // Pressure/Altitude window value bits 8-15 
00041 #define P_WND_LSB_REG         0x1A // Pressure/Altitude window value bits 0-7 
00042 #define T_WND_REG             0x1B // Temperature window value 
00043 
00044 #define P_MIN_MSB_REG         0x1C // Minimum Pressure/Altitude bits 12-19 
00045 #define P_MIN_CSB_REG         0x1D // Minimum Pressure/Altitude bits 4-11 
00046 #define P_MIN_LSB_REG         0x1E // Minimum Pressure/Altitude bits 0-3 
00047 #define T_MIN_MSB_REG         0x1F // Minimum Temperature bits 8-15 
00048 #define T_MIN_LSB_REG         0x20 // Minimum Temperature bits 0-7 
00049 
00050 #define P_MAX_MSB_REG         0x21 // Maximum Pressure/Altitude bits 12-19 
00051 #define P_MAX_CSB_REG         0x22 // Maximum Pressure/Altitude bits 4-11 
00052 #define P_MAX_LSB_REG         0x23 // Maximum Pressure/Altitude bits 0-3 
00053 #define T_MAX_MSB_REG         0x24 // Maximum Pressure/Altitude bits 8-15 
00054 #define T_MAX_LSB_REG         0x25 // Maximum Pressure/Altitude bits 0-7 
00055 
00056 #define CTRL_REG1             0x26 // CTRL_REG1 System Control 1 Register 
00057 #define CTRL_REG2             0x27 // CTRL_REG2 System Control 2 Register 
00058 #define CTRL_REG3             0x28 // CTRL_REG3 Interrupt Configuration Register 
00059 #define CTRL_REG4             0x29 // CTRL_REG4 Interrupt Enable Register 
00060 #define CTRL_REG5             0x2A // CTRL_REG5 Interrupt Output Pin Assignment Register 
00061 
00062 #define OFF_P_REG             0x2B // Pressure data offset 
00063 #define OFF_T_REG             0x2C // Temperature data offset 
00064 #define OFF_H_REG             0x2D // Altitude data offset
00065 
00066 
00067 typedef union { 
00068     struct {    // at 0x26
00069         uint8_t SBYB : 1;    // 0   0==standby, 1=active
00070         uint8_t OST  : 1;    // 1     initiate measurement now
00071         uint8_t RST  : 1;    // 2    software reset
00072         uint8_t OS   : 3;    // 3,4,5     oversampling ratio
00073         uint8_t RAW  : 1;    // 6          raw output mode
00074         uint8_t ALT  : 1;    // 7      0=barometer 1=altitude
00075     } bits;
00076     uint8_t octet;
00077 } mpl_ctrl_reg1_t;
00078 
00079 typedef union { 
00080     struct {    // at 0x
00081         uint8_t SRC_TCHG    : 1;    // 0
00082         uint8_t SRC_PCHG    : 1;    // 1
00083         uint8_t SRC_TTH     : 1;    // 2
00084         uint8_t SRC_PTH     : 1;    // 3
00085         uint8_t SRC_TW      : 1;    // 4
00086         uint8_t SRC_PW      : 1;    // 5
00087         uint8_t SRC_FIFO    : 1;    // 6
00088         uint8_t SRC_DRDY    : 1;    // 7
00089     } bits;
00090     uint8_t octet;
00091 } mpl_int_source_t;
00092 
00093 class MPL3115A2 {
00094     public:
00095         MPL3115A2(I2C& r, DigitalIn& int_pin);
00096         ~MPL3115A2();
00097         void write(uint8_t reg_addr, uint8_t reg_value);
00098         void init(void);
00099         uint8_t read(uint8_t a);
00100         void SetModeActive(void);
00101         bool GetModeActive(void);
00102         void SetModeStandby(void);
00103         float ReadAltitude( void ); // returns meters above sea level
00104         float ReadBarometer(void);  // returns pascals
00105         float ReadTemperature( void );  // returns celcius
00106         void SetModeAltimeter(void);
00107         void SetModeBarometer(void);
00108         void ToggleOneShot( void );
00109         void setOSR(uint8_t);
00110         uint8_t getOSR(void);
00111         float Altitude;
00112         float Temperature;
00113         void service(void);
00114         
00115         mpl_ctrl_reg1_t ctrl_reg1;
00116 
00117     private:
00118         I2C& m_i2c;
00119         DigitalIn& m_int_pin;
00120         uint8_t ctrl_reg4;
00121 };
00122 
00123