Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
mpl3115.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Gautier Hattenberger
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
27 #ifndef MPL3115_H
28 #define MPL3115_H
29 
30 #include "std.h"
31 #include "math/pprz_algebra_int.h"
32 #include "mcu_periph/i2c.h"
33 
34 /* Device address (8 bits) */
35 #define MPL3115_I2C_ADDR 0xC0
36 
37 /* Default I2C device */
38 #ifndef MPL3115_I2C_DEV
39 #define MPL3115_I2C_DEV i2c0
40 #endif
41 
42 /* Registers */
43 #define MPL3115_REG_STATUS 0x00
44 #define MPL3115_REG_OUT_P_MSB 0x01
45 #define MPL3115_REG_OUT_P_CSB 0x02
46 #define MPL3115_REG_OUT_P_LSB 0x03
47 #define MPL3115_REG_OUT_T_MSB 0x04
48 #define MPL3115_REG_OUT_T_LSB 0x05
49 #define MPL3115_REG_WHO_AM_I 0x0C
50 #define MPL3115_REG_PT_DATA_CFG 0x13
51 #define MPL3115_REG_CTRL_REG1 0x26
52 #define MPL3115_REG_CTRL_REG2 0x27
53 #define MPL3115_REG_CTRL_REG3 0x28
54 #define MPL3115_REG_CTRL_REG4 0x29
55 #define MPL3115_REG_CTRL_REG5 0x2A
56 
57 #define MPL3115_OST_BIT (1<<1) // One Shot control bit
58 
59 /* Default conf */
60 #ifndef MPL3115_PT_DATA_CFG
61 #define MPL3115_PT_DATA_CFG 0x2 // Enable data event flag for pressure
62 #endif
63 #ifndef MPL3115_OVERSAMPLING
64 #define MPL3115_OVERSAMPLING 0x5 // Oversample ratio (0x5: 130ms between data sample)
65 #endif
66 #ifndef MPL3115_RAW_OUTPUT
67 #define MPL3115_RAW_OUTPUT 0x0 // Raw output (disable alt mode if true)
68 #endif
69 #ifndef MPL3115_ALT_MODE
70 #define MPL3115_ALT_MODE 0x1 // 0: baro, 1: alti (disable by raw mode)
71 #endif
72 
73 #define MPL3115_CTRL_REG1 ((MPL3115_OVERSAMPLING<<3)|(MPL3115_RAW_OUTPUT<<6)|(MPL3115_ALT_MODE<<7))
74 
75 // Config done flag
76 extern bool_t mpl3115_initialized;
77 // Data ready flag
78 extern volatile bool_t mpl3115_data_available;
79 // Data
82 extern float mpl3115_alt;
83 // I2C transaction structure
84 //extern struct i2c_transaction mpl3115_trans;
85 
86 // Functions
87 extern void mpl3115_init(void);
88 extern void mpl3115_configure(void);
89 extern void mpl3115_read(void);
90 extern void mpl3115_event(void);
91 
92 // Macro for using MPL3115 in periodic function
93 #define Mpl3115Periodic() { \
94  if (mpl3115_initialized) mpl3115_read(); \
95  else mpl3115_configure(); \
96 }
97 
98 #endif // MPL3115_H
void mpl3115_read(void)
Definition: mpl3115.c:99
int16_t mpl3115_temperature
Definition: mpl3115.c:40
void mpl3115_event(void)
Definition: mpl3115.c:113
void mpl3115_init(void)
Definition: mpl3115.c:50
void mpl3115_configure(void)
Definition: mpl3115.c:88
uint32_t mpl3115_pressure
Definition: mpl3115.c:39
float mpl3115_alt
Definition: mpl3115.c:41
unsigned long uint32_t
Definition: types.h:18
signed short int16_t
Definition: types.h:17
volatile bool_t mpl3115_data_available
Definition: mpl3115.c:37
bool_t mpl3115_initialized
Definition: mpl3115.c:47
Paparazzi fixed point algebra.
Architecture independent I2C (Inter-Integrated Circuit Bus) API.