Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
baro_board.c
Go to the documentation of this file.
1 
3 #include <stm32/gpio.h>
4 
5 struct Baro baro;
9 
10 #define BMP085_SAMPLE_PERIOD_MS (3 + (2 << BMP085_OSS) * 3)
11 #define BMP085_SAMPLE_PERIOD (BMP075_SAMPLE_PERIOD_MS >> 1)
12 
13 // FIXME: BARO DRDY connected to PB0 for lisa/m
14 
15 static inline void bmp085_write_reg(uint8_t addr, uint8_t value)
16 {
19  baro_trans.len_w = 2;
20  baro_trans.buf[0] = addr;
21  baro_trans.buf[1] = value;
22  i2c_submit(&i2c2, &baro_trans);
24 }
25 
26 static inline void bmp085_read_reg16(uint8_t addr)
27 {
30  baro_trans.len_w = 1;
31  baro_trans.len_r = 2;
32  baro_trans.buf[0] = addr;
33  i2c_submit(&i2c2, &baro_trans);
34 }
35 
37 {
38  bmp085_read_reg16(addr);
39 
41 
42  return ((baro_trans.buf[0] << 8) | baro_trans.buf[1]);
43 }
44 
45 static inline void bmp085_read_reg24(uint8_t addr)
46 {
49  baro_trans.len_w = 1;
50  baro_trans.len_r = 3;
51  baro_trans.buf[0] = addr;
52  i2c_submit(&i2c2, &baro_trans);
53 }
54 
56 {
68 }
69 
70 void baro_init(void) {
72  baro.absolute = 0;
73  baro.differential = 0;
76 
77  /* STM32 specific (maybe this is a LISA/M specific driver anyway?) */
78  GPIO_InitTypeDef GPIO_InitStructure;
79  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
80  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
81  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
82  GPIO_Init(GPIOB, &GPIO_InitStructure);
83 }
84 
85 static inline int baro_eoc(void)
86 {
87  return GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0);
88 }
89 
90 static inline void bmp085_request_pressure(void)
91 {
92  bmp085_write_reg(0xF4, 0x34 + (BMP085_OSS << 6));
93 }
94 
95 static inline void bmp085_request_temp(void)
96 {
97  bmp085_write_reg(0xF4, 0x2E);
98 }
99 
100 static inline void bmp085_read_pressure(void)
101 {
102  bmp085_read_reg24(0xF6);
103 }
104 
105 static inline void bmp085_read_temp(void)
106 {
107  bmp085_read_reg16(0xF6);
108 }
109 
110 void baro_periodic(void) {
111  // check that nothing is in progress
112  if (baro_trans.status == I2CTransPending) return;
113  if (baro_trans.status == I2CTransRunning) return;
114  if (!i2c_idle(&i2c2)) return;
115 
116  switch (baro_board.status) {
117  case LBS_UNINITIALIZED:
121  break;
122  case LBS_REQUEST:
125  break;
126  case LBS_READ:
127  if (baro_eoc()) {
130  }
131  break;
132  case LBS_REQUEST_TEMP:
135  break;
136  case LBS_READ_TEMP:
137  if (baro_eoc()) {
140  }
141  break;
142  default:
143  break;
144  }
145 
146 }
147 
149  // This is a NOP at the moment
150 }
#define BMP085_OSS
Definition: baro_board.h:16
struct BaroBoard baro_board
Definition: baro_board.c:35
static int baro_eoc(void)
Definition: baro_board.c:85
static void bmp085_read_pressure(void)
Definition: baro_board.c:100
Definition: baro.h:41
void baro_periodic(void)
Definition: baro_board.c:56
bool_t i2c_idle(struct i2c_periph *p)
Definition: i2c_arch.c:317
static void bmp085_read_temp(void)
Definition: baro_board.c:105
uint8_t slave_addr
Definition: i2c.h:43
int32_t absolute
Definition: baro.h:42
static void bmp085_baro_read_calibration(void)
Definition: baro_board.c:55
bool_t i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
Definition: i2c_arch.c:321
struct Baro baro
Definition: baro_board.c:34
int32_t differential
Definition: baro.h:43
signed short int16_t
Definition: types.h:17
enum I2CTransactionStatus status
Definition: i2c.h:47
struct bmp085_baro_calibration calibration
Definition: baro_board.c:8
void baro_init(void)
Definition: baro_board.c:38
static void bmp085_write_reg(uint8_t addr, uint8_t value)
Definition: baro_board.c:15
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:46
uint8_t len_w
Definition: i2c.h:45
static void bmp085_request_pressure(void)
Definition: baro_board.c:90
uint16_t len_r
Definition: i2c.h:44
unsigned char uint8_t
Definition: types.h:14
static void bmp085_read_reg24(uint8_t addr)
Definition: baro_board.c:45
struct i2c_transaction baro_trans
Definition: baro_board.c:6
enum BaroStatus status
Definition: baro.h:44
enum I2CTransactionType type
Definition: i2c.h:42
static int16_t bmp085_read_reg16_blocking(uint8_t addr)
Definition: baro_board.c:36
enum LisaBaroStatus status
Definition: baro_board.h:28
void baro_board_send_reset(void)
Definition: baro_board.c:84
static void bmp085_read_reg16(uint8_t addr)
Definition: baro_board.c:26
Definition: i2c.h:9
#define BMP085_ADDR
Definition: baro_board.h:14
static void bmp085_request_temp(void)
Definition: baro_board.c:95