Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
ami601.h
Go to the documentation of this file.
1 #ifndef AMI601_H
2 #define AMI601_H
3 
4 #include "std.h"
5 #include "mcu_periph/i2c.h"
6 
7 extern void ami601_init(void);
8 
9 extern void ami601_read(void);
10 extern void ami601_periodic(void);
11 extern void ami601_scale_measures(void);
12 
13 #define AMI601_NB_CHAN 6
15 extern uint8_t ami601_foo1;
16 extern uint8_t ami601_foo2;
17 extern uint8_t ami601_foo3;
18 
19 #define AMI601_IDLE 0
20 #define AMI601_SENDING_REQ 1
21 #define AMI601_WAITING_MEASURE 2
22 #define AMI601_READING_MEASURE 3
23 #define AMI601_DATA_AVAILABLE 4
24 extern volatile uint8_t ami601_status;
25 extern struct i2c_transaction ami601_i2c_trans;
26 extern volatile uint32_t ami601_nb_err;
27 
28 #define AMI601_SLAVE_ADDR 0x60
29 #define AMI601_IT TIR_MR1I
30 #define AMI601_ISR() {}
31 
32 #ifdef SITL
33 #define AMI601Event(_handler) { \
34  if (ami601_status == AMI601_DATA_AVAILABLE) \
35  _handler(); \
36  }
37 #else
38 #define AMI601Event(_handler) { \
39  switch (ami601_status) { \
40  case AMI601_SENDING_REQ : \
41  if ( ami601_i2c_trans.status == I2CTransSuccess ) { \
42  ami601_status = AMI601_WAITING_MEASURE; \
43  } \
44  break; \
45  case AMI601_WAITING_MEASURE : \
46  ami601_status = AMI601_READING_MEASURE; \
47  ami601_i2c_trans.type = I2CTransRx; \
48  ami601_i2c_trans.len_r = 15; \
49  i2c_submit(&i2c1, &ami601_i2c_trans); \
50  break; \
51  case AMI601_READING_MEASURE : \
52  if ( ami601_i2c_trans.status == I2CTransSuccess ) { \
53  ami601_foo1 = ami601_i2c_trans.buf[0]; /* AA ? */ \
54  ami601_foo2 = ami601_i2c_trans.buf[1]; /* 55 ? */ \
55  ami601_foo3 = ami601_i2c_trans.buf[2]; /* ERR ? */ \
56  uint8_t i; \
57  for (i=0; i< AMI601_NB_CHAN; i++) { \
58  ami601_values[i] = ami601_i2c_trans.buf[3 + 2 * i]; \
59  ami601_values[i] += ami601_i2c_trans.buf[3 + 2 * i + 1] * 256; \
60  } \
61  ami601_status = AMI601_DATA_AVAILABLE; \
62  _handler(); \
63  } \
64  break; \
65  default: \
66  break; \
67  } \
68  }
69 #endif
70 
71 
72 
73 #endif /* AMI601_H */
void ami601_periodic(void)
void ami601_init(void)
Definition: ami601.c:12
struct i2c_transaction ami601_i2c_trans
Definition: ami601.c:9
uint8_t ami601_foo2
Definition: ami601.c:4
volatile uint8_t ami601_status
Definition: ami601.c:8
void ami601_read(void)
Definition: ami601.c:26
uint8_t ami601_foo1
Definition: ami601.c:3
volatile uint32_t ami601_nb_err
Definition: ami601.c:10
uint16_t ami601_values[AMI601_NB_CHAN]
Definition: ami601.c:6
void ami601_scale_measures(void)
#define AMI601_NB_CHAN
Definition: ami601.h:13
uint8_t ami601_foo3
Definition: ami601.c:5
I2C transaction structure.
Definition: i2c.h:93
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98