Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
mpu60x0.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Felix Ruess <felix.ruess@gmail.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
29 #include "peripherals/mpu60x0.h"
30 
31 const float MPU60X0_GYRO_SENS[4] = {
36 };
37 
38 const struct Int32Rates MPU60X0_GYRO_SENS_FRAC[4][2] = {
47 };
48 
49 const float MPU60X0_ACCEL_SENS[4] = {
54 };
55 
56 const struct Int32Vect3 MPU60X0_ACCEL_SENS_FRAC[4][2] = {
65 };
66 
68 {
69  c->type = MPU60X0;
76  c->drdy_int_enable = false;
77 
78  /* Number of bytes to read starting with MPU60X0_REG_INT_STATUS
79  * By default read only gyro and accel data -> 15 bytes.
80  * Increase to include slave data.
81  */
82  c->nb_bytes = 15;
83  c->nb_slaves = 0;
84  c->nb_slave_init = 0;
85 
86  c->i2c_bypass = false;
87 }
88 
89 void mpu60x0_send_config(Mpu60x0ConfigSet mpu_set, void *mpu, struct Mpu60x0Config *config)
90 {
91  switch (config->init_status) {
92  case MPU60X0_CONF_RESET:
93  /* device reset, set register values to defaults */
94  mpu_set(mpu, MPU60X0_REG_PWR_MGMT_1, (1 << 6));
95  config->init_status++;
96  break;
98  /* trigger FIFO, I2C_MST and SIG_COND resets */
99  mpu_set(mpu, MPU60X0_REG_USER_CTRL, ((1 << MPU60X0_FIFO_RESET) |
100  (1 << MPU60X0_I2C_MST_RESET) |
101  (1 << MPU60X0_SIG_COND_RESET)));
102  config->init_status++;
103  break;
104  case MPU60X0_CONF_PWR:
105  /* switch to gyroX clock by default */
106  mpu_set(mpu, MPU60X0_REG_PWR_MGMT_1, ((config->clk_sel) | (0 << 6)));
107  config->init_status++;
108  break;
109  case MPU60X0_CONF_SD:
110  /* configure sample rate divider */
111  mpu_set(mpu, MPU60X0_REG_SMPLRT_DIV, config->smplrt_div);
112  config->init_status++;
113  break;
114  case MPU60X0_CONF_DLPF:
115  /* configure digital low pass filter */
116  mpu_set(mpu, MPU60X0_REG_CONFIG, config->dlpf_cfg);
117  config->init_status++;
118  break;
119  case MPU60X0_CONF_GYRO:
120  /* configure gyro range */
121  mpu_set(mpu, MPU60X0_REG_GYRO_CONFIG, (config->gyro_range << 3));
122  config->init_status++;
123  break;
124  case MPU60X0_CONF_ACCEL:
125  /* configure accelerometer range */
126  mpu_set(mpu, MPU60X0_REG_ACCEL_CONFIG, (config->accel_range << 3));
127  config->init_status++;
128  break;
129  case MPU60X0_CONF_ACCEL2:
130  /* configure accelerometer DLPF (for ICM devices) */
131  if (config->type != MPU60X0) {
132  mpu_set(mpu, MPU60X0_REG_ACCEL_CONFIG2, config->dlpf_cfg_acc);
133  }
134  config->init_status++;
135  break;
137  /* if any, set MPU for I2C slaves and configure them*/
138  if (config->nb_slaves > 0) {
139  /* returns TRUE when all slaves are configured */
140  if (mpu60x0_configure_i2c_slaves(mpu_set, mpu)) {
141  config->init_status++;
142  }
143  } else {
144  config->init_status++;
145  }
146  break;
148  /* configure data ready interrupt */
149  mpu_set(mpu, MPU60X0_REG_INT_ENABLE, (config->drdy_int_enable << 0));
150  config->init_status++;
151  break;
152  case MPU60X0_CONF_UNDOC1:
153  /* configure undocumented register (for ICM devices) to remove 2.7m/s^2 y-acc bias */
154  if (config->type != MPU60X0) {
155  mpu_set(mpu, MPU60X0_REG_UNDOC1, 0xC9);
156  }
157  config->init_status++;
158  break;
159  case MPU60X0_CONF_DONE:
160  config->initialized = true;
161  break;
162  default:
163  break;
164  }
165 }
angular rates
const struct Int32Rates MPU60X0_GYRO_SENS_FRAC[4][2]
Definition: mpu60x0.c:38
const struct Int32Vect3 MPU60X0_ACCEL_SENS_FRAC[4][2]
Definition: mpu60x0.c:56
void mpu60x0_set_default_config(struct Mpu60x0Config *c)
Definition: mpu60x0.c:67
void mpu60x0_send_config(Mpu60x0ConfigSet mpu_set, void *mpu, struct Mpu60x0Config *config)
Configuration sequence called once before normal use.
Definition: mpu60x0.c:89
const float MPU60X0_ACCEL_SENS[4]
Definition: mpu60x0.c:49
const float MPU60X0_GYRO_SENS[4]
Definition: mpu60x0.c:31
MPU-60X0 driver common interface (I2C and SPI).
#define MPU60X0_DEFAULT_AFS_SEL
Default accel full scale range +- 16g.
Definition: mpu60x0.h:41
#define MPU60X0_ACCEL_SENS_8G_DEN
Definition: mpu60x0.h:92
#define MPU60X0_ACCEL_SENS_8G_NUM
Definition: mpu60x0.h:91
#define MPU60X0_GYRO_SENS_2000
Definition: mpu60x0.h:70
#define MPU60X0_DEFAULT_FS_SEL
Default gyro full scale range +- 2000°/s.
Definition: mpu60x0.h:39
#define MPU60X0_DEFAULT_SMPLRT_DIV
Default sample rate divider.
Definition: mpu60x0.h:37
#define MPU60X0_DEFAULT_DLPF_CFG_ACC
Default internal sampling for accelerometer ICM devices only (1kHz, 99Hz LP Bandwidth)
Definition: mpu60x0.h:45
#define MPU60X0_ACCEL_SENS_16G
Definition: mpu60x0.h:93
#define MPU60X0_ACCEL_SENS_16G_NUM
Definition: mpu60x0.h:94
#define MPU60X0_ACCEL_SENS_4G_NUM
Definition: mpu60x0.h:88
#define MPU60X0_GYRO_SENS_1000_NUM
Definition: mpu60x0.h:68
uint8_t nb_bytes
number of bytes to read starting with MPU60X0_REG_INT_STATUS
Definition: mpu60x0.h:147
@ MPU60X0
Definition: mpu60x0.h:105
uint8_t smplrt_div
Sample rate divider.
Definition: mpu60x0.h:140
uint8_t nb_slaves
number of used I2C slaves
Definition: mpu60x0.h:156
#define MPU60X0_ACCEL_SENS_4G_DEN
Definition: mpu60x0.h:89
#define MPU60X0_GYRO_SENS_2000_DEN
Definition: mpu60x0.h:72
uint8_t nb_slave_init
number of already configured/initialized slaves
Definition: mpu60x0.h:157
#define MPU60X0_GYRO_SENS_250
default gyro sensitivy from the datasheet sens = 1/ [LSB/(deg/s)] * pi/180 * 2^INT32_RATE_FRAC ex: MP...
Definition: mpu60x0.h:61
#define MPU60X0_GYRO_SENS_500_DEN
Definition: mpu60x0.h:66
enum Mpu60x0DLPF dlpf_cfg
Digital Low Pass Filter.
Definition: mpu60x0.h:141
enum Mpu60x0Type type
The type of sensor (MPU60x0, ICM20608, ...)
Definition: mpu60x0.h:139
#define MPU60X0_DEFAULT_CLK_SEL
Default clock: PLL with X gyro reference.
Definition: mpu60x0.h:49
#define MPU60X0_GYRO_SENS_250_NUM
Definition: mpu60x0.h:62
#define MPU60X0_GYRO_SENS_500
Definition: mpu60x0.h:64
#define MPU60X0_ACCEL_SENS_8G
Definition: mpu60x0.h:90
#define MPU60X0_ACCEL_SENS_16G_DEN
Definition: mpu60x0.h:95
#define MPU60X0_ACCEL_SENS_2G
default accel sensitivy from the datasheet sens = 9.81 [m/s^2] / [LSB/g] * 2^INT32_ACCEL_FRAC ex: MPU...
Definition: mpu60x0.h:84
#define MPU60X0_GYRO_SENS_1000
Definition: mpu60x0.h:67
bool i2c_bypass
Bypass MPU I2C.
Definition: mpu60x0.h:154
#define MPU60X0_GYRO_SENS_2000_NUM
Definition: mpu60x0.h:71
bool drdy_int_enable
Enable Data Ready Interrupt.
Definition: mpu60x0.h:145
@ MPU60X0_CONF_I2C_SLAVES
Definition: mpu60x0.h:122
@ MPU60X0_CONF_DONE
Definition: mpu60x0.h:125
@ MPU60X0_CONF_ACCEL
Definition: mpu60x0.h:120
@ MPU60X0_CONF_PWR
Definition: mpu60x0.h:116
@ MPU60X0_CONF_GYRO
Definition: mpu60x0.h:119
@ MPU60X0_CONF_INT_ENABLE
Definition: mpu60x0.h:123
@ MPU60X0_CONF_USER_RESET
Definition: mpu60x0.h:115
@ MPU60X0_CONF_RESET
Definition: mpu60x0.h:114
@ MPU60X0_CONF_ACCEL2
Definition: mpu60x0.h:121
@ MPU60X0_CONF_UNDOC1
Definition: mpu60x0.h:124
@ MPU60X0_CONF_SD
Definition: mpu60x0.h:117
@ MPU60X0_CONF_DLPF
Definition: mpu60x0.h:118
#define MPU60X0_DEFAULT_DLPF_CFG
Default internal sampling (1kHz, 98Hz LP Bandwidth)
Definition: mpu60x0.h:43
#define MPU60X0_GYRO_SENS_1000_DEN
Definition: mpu60x0.h:69
#define MPU60X0_GYRO_SENS_250_DEN
Definition: mpu60x0.h:63
#define MPU60X0_ACCEL_SENS_2G_DEN
Definition: mpu60x0.h:86
enum Mpu60x0AccelRanges accel_range
g Range
Definition: mpu60x0.h:144
#define MPU60X0_ACCEL_SENS_2G_NUM
Definition: mpu60x0.h:85
uint8_t clk_sel
Clock select.
Definition: mpu60x0.h:146
#define MPU60X0_ACCEL_SENS_4G
Definition: mpu60x0.h:87
enum Mpu60x0ACCDLPF dlpf_cfg_acc
Digital Low Pass Filter for acceleremoter (ICM devices only)
Definition: mpu60x0.h:142
void(* Mpu60x0ConfigSet)(void *mpu, uint8_t _reg, uint8_t _val)
Configuration function prototype.
Definition: mpu60x0.h:129
bool mpu60x0_configure_i2c_slaves(Mpu60x0ConfigSet mpu_set, void *mpu)
Configure I2C slaves of the MPU.
Definition: mpu60x0_i2c.c:135
#define MPU60X0_GYRO_SENS_500_NUM
Definition: mpu60x0.h:65
enum Mpu60x0GyroRanges gyro_range
deg/s Range
Definition: mpu60x0.h:143
#define MPU60X0_REG_USER_CTRL
Definition: mpu60x0_regs.h:39
#define MPU60X0_FIFO_RESET
Definition: mpu60x0_regs.h:132
#define MPU60X0_REG_GYRO_CONFIG
Definition: mpu60x0_regs.h:52
#define MPU60X0_REG_CONFIG
Definition: mpu60x0_regs.h:51
#define MPU60X0_REG_ACCEL_CONFIG2
Definition: mpu60x0_regs.h:54
#define MPU60X0_REG_PWR_MGMT_1
Definition: mpu60x0_regs.h:40
#define MPU60X0_SIG_COND_RESET
Definition: mpu60x0_regs.h:130
#define MPU60X0_REG_ACCEL_CONFIG
Definition: mpu60x0_regs.h:53
#define MPU60X0_REG_UNDOC1
Definition: mpu60x0_regs.h:55
#define MPU60X0_REG_INT_ENABLE
Definition: mpu60x0_regs.h:90
#define MPU60X0_REG_SMPLRT_DIV
Definition: mpu60x0_regs.h:50
#define MPU60X0_I2C_MST_RESET
Definition: mpu60x0_regs.h:131
static const struct usb_config_descriptor config
Definition: usb_ser_hw.c:200