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
baro_board.c
Go to the documentation of this file.
1 
3 
4 struct Baro baro;
7 
8 static inline void baro_board_write_to_register(uint8_t baro_addr, uint8_t reg_addr, uint8_t val_msb, uint8_t val_lsb);
9 static inline void baro_board_read_from_register(uint8_t baro_addr, uint8_t reg_addr);
10 static inline void baro_board_set_current_register(uint8_t baro_addr, uint8_t reg_addr);
11 static inline void baro_board_read_from_current_register(uint8_t baro_addr);
12 
13 // absolute
14 #define BARO_ABS_ADDR 0x90
15 // differential
16 #define BARO_DIFF_ADDR 0x92
17 
18 void baro_init(void) {
20  baro.absolute = 0;
21  baro.differential = 0;
23 }
24 
25 
26 void baro_periodic(void) {
27  // check i2c_done
28  if (!i2c_idle(&i2c2)) return;
29 
30  switch (baro_board.status) {
31  case LBS_UNINITIALIZED:
34  break;
35  case LBS_RESETED:
38  break;
42  break;
46  break;
50  // baro_board.status = LBS_UNINITIALIZED;
51  break;
54  case LBS_READ_DIFF:
57  break;
58  case LBS_READ_ABS:
61  break;
62  default:
63  break;
64  }
65 
66 }
67 
68 
70 #ifndef BARO_LOW_GAIN
71 INFO("Using High LisaL Baro Gain: Do not use below 1000hPa")
73 #else
74 INFO("Using Low LisaL Baro Gain, capable of measuring below 1000hPa or more")
75  //config register should be 0x84 in low countries, or 0x86 in normal countries
77 #endif
78 }
79 
82 }
83 
86  baro_trans.slave_addr = 0x00;
87  baro_trans.len_w = 1;
88  baro_trans.buf[0] = 0x06;
89  i2c_submit(&i2c2,&baro_trans);
90 }
91 
92 static inline void baro_board_write_to_register(uint8_t baro_addr, uint8_t reg_addr, uint8_t val_msb, uint8_t val_lsb) {
94  baro_trans.slave_addr = baro_addr;
95  baro_trans.len_w = 3;
96  baro_trans.buf[0] = reg_addr;
97  baro_trans.buf[1] = val_msb;
98  baro_trans.buf[2] = val_lsb;
99  i2c_submit(&i2c2,&baro_trans);
100 }
101 
102 static inline void baro_board_read_from_register(uint8_t baro_addr, uint8_t reg_addr) {
104  baro_trans.slave_addr = baro_addr;
105  baro_trans.len_w = 1;
106  baro_trans.len_r = 2;
107  baro_trans.buf[0] = reg_addr;
108  i2c_submit(&i2c2,&baro_trans);
109  // i2c2.buf[0] = reg_addr;
110  // i2c2_transceive(baro_addr, 1, 2, &baro_board.i2c_done);
111 }
112 
113 static inline void baro_board_set_current_register(uint8_t baro_addr, uint8_t reg_addr) {
115  baro_trans.slave_addr = baro_addr;
116  baro_trans.len_w = 1;
117  baro_trans.buf[0] = reg_addr;
118  i2c_submit(&i2c2,&baro_trans);
119  // i2c2.buf[0] = reg_addr;
120  // i2c2_transmit(baro_addr, 1, &baro_board.i2c_done);
121 }
122 
123 static inline void baro_board_read_from_current_register(uint8_t baro_addr) {
125  baro_trans.slave_addr = baro_addr;
126  baro_trans.len_r = 2;
127  i2c_submit(&i2c2,&baro_trans);
128  // i2c2_receive(baro_addr, 2, &baro_board.i2c_done);
129 }
struct BaroBoard baro_board
Definition: baro_board.c:35
static void baro_board_read_from_current_register(uint8_t baro_addr)
Definition: baro_board.c:123
void baro_board_send_config_diff(void)
Definition: baro_board.c:80
bool_t i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
Definition: i2c_arch.c:333
#define BARO_ABS_ADDR
Definition: baro_board.c:14
Common barometric sensor implementation.
Definition: baro.h:40
#define BARO_DIFF_ADDR
Definition: baro_board.c:16
static void baro_board_write_to_register(uint8_t baro_addr, uint8_t reg_addr, uint8_t val_msb, uint8_t val_lsb)
Definition: baro_board.c:92
void baro_init(void)
Definition: baro_board.c:42
uint8_t slave_addr
Definition: i2c.h:79
void baro_periodic(void)
Definition: baro_board.c:50
int32_t absolute
Definition: baro.h:41
int32_t differential
Definition: baro.h:42
static void baro_board_read_from_register(uint8_t baro_addr, uint8_t reg_addr)
Definition: baro_board.c:102
void baro_board_send_config_abs(void)
Definition: baro_board.c:69
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:82
uint8_t len_w
Definition: i2c.h:81
uint16_t len_r
Definition: i2c.h:80
struct Baro baro
Definition: baro_board.c:36
unsigned char uint8_t
Definition: types.h:14
struct i2c_transaction baro_trans
Definition: baro_board.c:6
enum BaroStatus status
Definition: baro.h:43
Definition: i2c.h:45
enum I2CTransactionType type
Definition: i2c.h:78
static void baro_board_set_current_register(uint8_t baro_addr, uint8_t reg_addr)
Definition: baro_board.c:113
enum LisaBaroStatus status
Definition: baro_board.h:28
void baro_board_send_reset(void)
Definition: baro_board.c:84
Definition: i2c.h:46
bool_t i2c_idle(struct i2c_periph *p)
Definition: i2c_arch.c:329