Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
imu_aspirin.c
Go to the documentation of this file.
1 #include "subsystems/imu.h"
2 #include "peripherals/hmc5843.h"
3 
4 #include "mcu_periph/i2c.h"
5 
7 
8 /* initialize peripherals */
9 static void configure_gyro(void);
10 static void configure_accel(void);
11 //static void configure_mag(void);
12 
13 #ifndef ASPIRIN_ACCEL_RATE
14 #define ASPIRIN_ACCEL_RATE ADXL345_RATE_800
15 #endif
16 
17 // FIXME: there should be no arch dependent code here!
18 static void send_i2c_msg_with_retry(struct i2c_transaction* t) {
19  uint8_t max_retry = 8;
20  uint8_t nb_retry = 0;
21  do {
22  i2c_submit(&i2c2, t);
23  while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY));
24  while (t->status == I2CTransPending || t->status == I2CTransRunning);
25  if (t->status == I2CTransFailed)
26  nb_retry++;
27  }
28  while (t->status != I2CTransSuccess && nb_retry < max_retry);
29 }
30 
31 void imu_impl_init(void) {
32 
37 
44 
46  hmc5843_init();
47 
48 }
49 
50 
51 void imu_periodic(void) {
58  } else {
65  }
66  }
67 
68 }
69 
70 
71 /* sends a serie of I2C commands to configure the ITG3200 gyro */
72 static void configure_gyro(void) {
73  struct i2c_transaction t;
74  t.type = I2CTransTx;
76  /* set gyro range to 2000deg/s and low pass at 256Hz */
77  t.buf[0] = ITG3200_REG_DLPF_FS;
78  t.buf[1] = (0x03<<3);
79  t.len_w = 2;
81  /* set sample rate to 533Hz */
83  t.buf[1] = 0x0E;
85  /* switch to gyroX clock */
86  t.buf[0] = ITG3200_REG_PWR_MGM;
87  t.buf[1] = 0x01;
89  /* enable interrupt on data ready, idle high, latch until read any register */
90  t.buf[0] = ITG3200_REG_INT_CFG;
91  t.buf[1] = (0x01 | (0x1<<4) | (0x1<<5) | 0x01<<7);
93 
94 }
95 
96 
97 
98 static void configure_accel(void) {
99 
100  /* set data rate to 800Hz and bandwidth to 400Hz (unless set otherwise) */
102  /* switch to measurememnt mode */
104  /* enable data ready interrupt */
106  /* Enable full res with +-16g range and interrupt active low */
108  /* clear spi rx reg to make DMA happy */
110  /* reads data once to bring interrupt line up */
112 
113 }
#define ASPIRIN_ACCEL_TIMEOUT
Definition: imu_aspirin.h:150
#define ITG3200_REG_INT_CFG
Definition: itg3200.h:12
struct ImuAspirin imu_aspirin
Definition: imu_aspirin.c:6
#define ITG3200_REG_SMPLRT_DIV
Definition: itg3200.h:10
void imu_aspirin_arch_init(void)
#define ADXL345_REG_DATA_FORMAT
Definition: adxl345.h:12
#define ITG3200_ADDR
Definition: itg3200.h:5
void imu_impl_init(void)
Definition: imu_aspirin.c:31
void adxl345_start_reading_data(void)
void imu_periodic(void)
Definition: imu_aspirin.c:51
#define ADXL345_REG_POWER_CTL
Definition: adxl345.h:10
uint8_t slave_addr
Definition: i2c.h:43
#define FALSE
Definition: imu_chimu.h:141
struct i2c_transaction i2c_trans_gyro
Definition: imu_aspirin.h:136
void adxl345_clear_rx_buf(void)
bool_t i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
Definition: i2c_arch.c:321
void hmc5843_init(void)
Definition: hmc5843.c:16
#define ASPIRIN_ACCEL_RATE
Definition: imu_aspirin.c:14
static void configure_accel(void)
Definition: imu_aspirin.c:98
uint8_t mag_available
Definition: imu_aspirin.h:143
#define ADXL345_REG_BW_RATE
Definition: adxl345.h:9
enum I2CTransactionStatus status
Definition: i2c.h:47
Inertial Measurement Unit interface.
#define ADXL345_INT_INVERT
Definition: adxl345.h:32
#define ADXL345_FULL_RES
Definition: adxl345.h:33
#define TRUE
Definition: imu_chimu.h:144
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:46
uint8_t len_w
Definition: i2c.h:45
uint16_t len_r
Definition: i2c.h:44
unsigned char uint8_t
Definition: types.h:14
static void send_i2c_msg_with_retry(struct i2c_transaction *t)
Definition: imu_aspirin.c:18
#define ADXL345_RANGE_16G
Definition: adxl345.h:35
volatile uint8_t accel_available
Definition: imu_aspirin.h:138
#define ITG3200_REG_GYRO_XOUT_H
Definition: itg3200.h:16
enum AspirinStatus status
Definition: imu_aspirin.h:135
void imu_aspirin_arch_int_enable(void)
uint32_t time_since_last_accel_reading
Definition: imu_aspirin.h:142
enum I2CTransactionType type
Definition: i2c.h:42
void hmc5843_periodic(void)
Definition: hmc5843.c:103
#define ADXL345_REG_INT_ENABLE
Definition: adxl345.h:11
static void configure_gyro(void)
Definition: imu_aspirin.c:72
#define ITG3200_REG_DLPF_FS
Definition: itg3200.h:11
uint8_t gyro_available_blaaa
Definition: imu_aspirin.h:145
void adxl345_write_to_reg(uint8_t addr, uint8_t val)
Definition: i2c.h:9
uint32_t time_since_last_reading
Definition: imu_aspirin.h:141
#define ITG3200_REG_PWR_MGM
Definition: itg3200.h:22