1 /*!
2  * \file      mpl3115.h
3  *
4  * \brief     MPL3115 Temperature, pressure and altitude sensor driver implementation
5  *
6  * \copyright Revised BSD License, see section \ref LICENSE.
7  *
8  * \code
9  *                ______                              _
10  *               / _____)             _              | |
11  *              ( (____  _____ ____ _| |_ _____  ____| |__
12  *               \____ \| ___ |    (_   _) ___ |/ ___)  _ \
13  *               _____) ) ____| | | || |_| ____( (___| | | |
14  *              (______/|_____)_|_|_| \__)_____)\____)_| |_|
15  *              (C)2013-2017 Semtech
16  *
17  * \endcode
18  *
19  * \author    Miguel Luis ( Semtech )
20  *
21  * \author    Gregory Cristian ( Semtech )
22  */
23 #ifndef __MPL3115_H__
24 #define __MPL3115_H__
25 
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30 
31 #include <stdint.h>
32 #include "utilities.h"
33 
34 /*
35  * MPL3115A2 I2C address
36  */
37 #define MPL3115A_I2C_ADDRESS                          0x60
38 
39 /*
40  * MPL3115A2 Registers
41  */
42 #define STATUS_REG            0x00 // STATUS Register
43 
44 #define OUT_P_MSB_REG         0x01 // Bits 12-19 of 20-bit real-time Pressure sample
45 #define OUT_P_CSB_REG         0x02 // Bits 4-11 of 20-bit real-time Pressure sample
46 #define OUT_P_LSB_REG         0x03 // Bits 0-3 of 20-bit real-time Pressure sample
47 #define OUT_T_MSB_REG         0x04 // Bits 4-11 of 12-bit real-time Temperature sample
48 #define OUT_T_LSB_REG         0x05 // Bits 0-3 of 12-bit real-time Temperature sample
49 
50 #define DR_STATUS             0x06 // Data Ready status information
51 
52 #define OUT_P_DELTA_MSB_REG   0x07 // Bits 12-19 of 20-bit Pressure change data
53 #define OUT_P_DELTA_CSB_REG   0x08 // Bits 4-11 of 20-bit Pressure change data
54 #define OUT_P_DELTA_LSB_REG   0x09 // Bits 0-3 of 20-bit Pressure change data
55 #define OUT_T_DELTA_MSB_REG   0x0A // Bits 4-11 of 12-bit Temperature change data
56 #define OUT_T_DELTA_LSB_REG   0x0B // Bits 0-3 of 12-bit Temperature change data
57 
58 #define MPL3115_ID            0x0C // Fixed Device ID Number = 0xC4
59 
60 #define F_STATUS_REG          0x0D // FIFO Status
61 #define F_DATA_REG            0x0E // FIFO 8-bit data access
62 #define F_SETUP_REG           0x0F // FIFO setup
63 #define TIME_DLY_REG          0x10 // Time since FIFO overflow
64 
65 #define SYSMOD_REG            0x11 // Current system mode
66 #define INT_SOURCE_REG        0x12 // Interrupt status
67 #define PT_DATA_CFG_REG       0x13 // Data event flag configuration
68 
69 #define BAR_IN_MSB_REG        0x14 // Barometric input for Altitude calculation bits 8-15
70 #define BAR_IN_LSB_REG        0x15 // Barometric input for Altitude calculation bits 0-7
71 
72 #define P_TGT_MSB_REG         0x16 // Pressure/Altitude target value bits 8-15
73 #define P_TGT_LSB_REG         0x17 // Pressure/Altitude target value bits 0-7
74 #define T_TGT_REG             0x18 // Temperature target value
75 
76 #define P_WND_MSB_REG         0x19 // Pressure/Altitude window value bits 8-15
77 #define P_WND_LSB_REG         0x1A // Pressure/Altitude window value bits 0-7
78 #define T_WND_REG             0x1B // Temperature window value
79 
80 #define P_MIN_MSB_REG         0x1C // Minimum Pressure/Altitude bits 12-19
81 #define P_MIN_CSB_REG         0x1D // Minimum Pressure/Altitude bits 4-11
82 #define P_MIN_LSB_REG         0x1E // Minimum Pressure/Altitude bits 0-3
83 #define T_MIN_MSB_REG         0x1F // Minimum Temperature bits 8-15
84 #define T_MIN_LSB_REG         0x20 // Minimum Temperature bits 0-7
85 
86 #define P_MAX_MSB_REG         0x21 // Maximum Pressure/Altitude bits 12-19
87 #define P_MAX_CSB_REG         0x22 // Maximum Pressure/Altitude bits 4-11
88 #define P_MAX_LSB_REG         0x23 // Maximum Pressure/Altitude bits 0-3
89 #define T_MAX_MSB_REG         0x24 // Maximum Pressure/Altitude bits 8-15
90 #define T_MAX_LSB_REG         0x25 // Maximum Pressure/Altitude bits 0-7
91 
92 #define CTRL_REG1             0x26 // CTRL_REG1 System Control 1 Register
93 #define CTRL_REG2             0x27 // CTRL_REG2 System Control 2 Register
94 #define CTRL_REG3             0x28 // CTRL_REG3 Interrupt Configuration Register
95 #define CTRL_REG4             0x29 // CTRL_REG4 Interrupt Enable Register
96 #define CTRL_REG5             0x2A // CTRL_REG5 Interrupt Output Pin Assignment Register
97 
98 #define OFF_P_REG             0x2B // Pressure data offset
99 #define OFF_T_REG             0x2C // Temperature data offset
100 #define OFF_H_REG             0x2D // Altitude data offset
101 
102 
103 /*
104  * MPL3115A2 Bit Field
105  */
106 #define PTDR                  0x08
107 #define PDR                   0x04
108 #define TDR                   0x02
109 #define ALT                   0x80
110 #define RAW                   0x40
111 #define OS2                   0x20
112 #define OS1                   0x10
113 #define OS0                   0x08
114 #define RST                   0x04
115 #define OST                   0x02
116 #define SBYB                  0x01
117 #define OS_1                  0x00
118 #define OS_2                  OS0
119 #define OS_4                  OS1
120 #define OS_8                  OS1 | OS0
121 #define OS_16                 OS2
122 #define OS_32                 OS2 | OS0
123 #define OS_64                 OS2 | OS1
124 #define OS_128                OS2 | OS1 | OS0
125 #define DREM                  0x04
126 #define PDEFE                 0x02
127 #define TDEFE                 0x01
128 
129 /*!
130  * \brief Initializes the device
131  *
132  * \retval status [LMN_STATUS_OK, LMN_STATUS_ERROR]
133  */
134 LmnStatus_t MPL3115Init( void );
135 
136 /*!
137  * \brief Resets the device
138  *
139  * \retval status [LMN_STATUS_OK, LMN_STATUS_ERROR]
140  */
141 LmnStatus_t MPL3115Reset( void );
142 
143 /*!
144  * \brief Reads the altitude from the MPL3115
145  *
146  * \retval altitude Measured altitude
147  */
148 float MPL3115ReadAltitude( void );
149 
150 /*!
151  * \brief Reads the Pressure from the MPL3115
152  *
153  * \retval pressure Measured pressure
154  */
155 float MPL3115ReadPressure( void );
156 
157 /*!
158  * \brief Reads the Temperature from the MPL3115
159  *
160  * \retval temperature Measured temperature
161  */
162 float MPL3115ReadTemperature( void );
163 
164 #ifdef __cplusplus
165 }
166 #endif
167 
168 #endif // __MPL3115_H__
169