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.c
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2011 Gautier Hattenberger
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 
27 #include "peripherals/mpl3115.h"
28 #include "std.h"
29 
30 #define MPL_CONF_UNINIT 0
31 #define MPL_CONF_PT_DATA 1
32 #define MPL_CONF_CTRL1 2
33 #define MPL_CONF_DONE 3
34 
35 
36 // Data ready flag
37 volatile bool_t mpl3115_data_available;
38 // Data
42 // I2C transaction for reading and configuring
44 // I2C transaction for conversion request
46 // Init flag
49 
50 void mpl3115_init(void)
51 {
56 
57  mpl3115_pressure = 0;
59  mpl3115_alt = 0.;
60 }
61 
62 // Configuration function called once before normal use
63 static void mpl3115_send_config(void)
64 {
65  switch (mpl3115_init_status) {
66  case MPL_CONF_PT_DATA:
71  break;
72  case MPL_CONF_CTRL1:
77  break;
78  case MPL_CONF_DONE:
81  break;
82  default:
83  break;
84  }
85 }
86 
87 // Configure
89 {
94  }
95  }
96 }
97 
98 // Normal reading
99 void mpl3115_read(void)
100 {
101  // ask for a reading and then prepare next conversion
109  }
110  }
111 }
112 
113 void mpl3115_event(void)
114 {
115  if (mpl3115_initialized) {
118  }
119  else if (mpl3115_trans.status == I2CTransSuccess) {
120  // Successfull reading and new pressure data available
121  if (mpl3115_trans.buf[0] & (1<<2)) {
122 #if MPL3115_RAW_OUTPUT
123  // New data available
127 #else // Not in raw mode
128 #if MPL3115_ALT_MODE
130  mpl3115_alt = (float)(tmp>>4)/(1<<4);
131  tmp = ((int16_t)mpl3115_trans.buf[4]<<8)|mpl3115_trans.buf[5];
132  mpl3115_temperature = (tmp>>4);
134 #else // Pressure mode
136  mpl3115_pressure = (tmp>>4);
137  tmp = ((int16_t)mpl3115_trans.buf[4]<<8)|mpl3115_trans.buf[5];
138  mpl3115_temperature = (tmp>>4);
140 #endif // end alt mode
141 #endif // end raw mode
142  }
144  }
145  }
146  else if (!mpl3115_initialized && mpl3115_init_status != MPL_CONF_UNINIT) { // Configuring
150  }
154  mpl3115_send_config(); // Retry config (TODO max retry)
155  }
156  }
159  }
160 }
161 
unsigned short uint16_t
Definition: types.h:16
void mpl3115_init(void)
Definition: mpl3115.c:50
void mpl3115_configure(void)
Definition: mpl3115.c:88
#define MPL3115_CTRL_REG1
Definition: mpl3115.h:73
volatile bool_t mpl3115_data_available
Definition: mpl3115.c:37
float mpl3115_alt
Definition: mpl3115.c:41
#define MPL3115_PT_DATA_CFG
Definition: mpl3115.h:61
#define MPL3115_REG_STATUS
Definition: mpl3115.h:43
#define MPL_CONF_PT_DATA
Definition: mpl3115.c:31
bool_t i2c_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r)
Definition: i2c.c:105
bool_t mpl3115_initialized
Definition: mpl3115.c:47
#define FALSE
Definition: imu_chimu.h:141
struct i2c_transaction mpl3115_req_trans
Definition: mpl3115.c:45
#define MPL3115_REG_PT_DATA_CFG
Definition: mpl3115.h:50
#define MPL_CONF_UNINIT
Definition: mpl3115.c:30
#define MPL_CONF_DONE
Definition: mpl3115.c:33
#define MPL3115_I2C_ADDR
Definition: mpl3115.h:35
void mpl3115_read(void)
Definition: mpl3115.c:99
bool_t i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Definition: i2c.c:85
unsigned long uint32_t
Definition: types.h:18
signed short int16_t
Definition: types.h:17
uint8_t mpl3115_init_status
Definition: mpl3115.c:48
Driver for the baro MPL3115A2 from Freescale (i2c)
enum I2CTransactionStatus status
Definition: i2c.h:83
struct i2c_transaction mpl3115_trans
Definition: mpl3115.c:43
#define TRUE
Definition: imu_chimu.h:144
#define MPL3115_I2C_DEV
Definition: mpl3115.h:39
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:82
unsigned char uint8_t
Definition: types.h:14
int16_t mpl3115_temperature
Definition: mpl3115.c:40
void mpl3115_event(void)
Definition: mpl3115.c:113
#define MPL_CONF_CTRL1
Definition: mpl3115.c:32
static void mpl3115_send_config(void)
Definition: mpl3115.c:63
uint32_t mpl3115_pressure
Definition: mpl3115.c:39
#define MPL3115_REG_CTRL_REG1
Definition: mpl3115.h:51
#define MPL3115_OST_BIT
Definition: mpl3115.h:57