Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
mpu9250.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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
30 #include "peripherals/mpu9250.h"
31 
32 const float MPU9250_GYRO_SENS[4] = {
37 };
38 
39 const struct Int32Rates MPU9250_GYRO_SENS_FRAC[4][2] = {
48 };
49 
50 const float MPU9250_ACCEL_SENS[4] = {
55 };
56 
57 const struct Int32Vect3 MPU9250_ACCEL_SENS_FRAC[4][2] = {
66 };
67 
69 {
76  c->drdy_int_enable = false;
77 
78  /* Number of bytes to read starting with MPU9250_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 mpu9250_send_config(Mpu9250ConfigSet mpu_set, void *mpu, struct Mpu9250Config *config)
90 {
91  switch (config->init_status) {
92  case MPU9250_CONF_RESET:
93  /* device reset, set register values to defaults */
94  mpu_set(mpu, MPU9250_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, MPU9250_REG_USER_CTRL, ((1 << MPU9250_FIFO_RESET) |
100  (1 << MPU9250_I2C_MST_RESET) |
101  (1 << MPU9250_SIG_COND_RESET)));
102  config->init_status++;
103  break;
104  case MPU9250_CONF_PWR:
105  /* switch to gyroX clock by default */
106  mpu_set(mpu, MPU9250_REG_PWR_MGMT_1, ((config->clk_sel) | (0 << 6)));
107  config->init_status++;
108  break;
109  case MPU9250_CONF_SD:
110  /* configure sample rate divider */
111  mpu_set(mpu, MPU9250_REG_SMPLRT_DIV, config->smplrt_div);
112  config->init_status++;
113  break;
115  /* configure digital low pass filter for gyroscope */
116  mpu_set(mpu, MPU9250_REG_CONFIG, config->dlpf_gyro_cfg);
117  config->init_status++;
118  break;
120  /* configure digital low pass filter fir accelerometer */
121  mpu_set(mpu, MPU9250_REG_ACCEL_CONFIG_2, config->dlpf_accel_cfg);
122  config->init_status++;
123  break;
124  case MPU9250_CONF_GYRO:
125  /* configure gyro range */
126  mpu_set(mpu, MPU9250_REG_GYRO_CONFIG, (config->gyro_range << 3));
127  config->init_status++;
128  break;
129  case MPU9250_CONF_ACCEL:
130  /* configure accelerometer range */
131  mpu_set(mpu, MPU9250_REG_ACCEL_CONFIG, (config->accel_range << 3));
132  config->init_status++;
133  break;
135  /* if any, set MPU for I2C slaves and configure them*/
136  if (config->nb_slaves > 0) {
137  /* returns TRUE when all slaves are configured */
138  if (mpu9250_configure_i2c_slaves(mpu_set, mpu)) {
139  config->init_status++;
140  }
141  } else {
142  config->init_status++;
143  }
144  break;
146  /* configure data ready interrupt */
147  mpu_set(mpu, MPU9250_REG_INT_ENABLE, (config->drdy_int_enable << 0));
148  config->init_status++;
149  break;
150  case MPU9250_CONF_DONE:
151  config->initialized = true;
152  break;
153  default:
154  break;
155  }
156 }
angular rates
const struct Int32Vect3 MPU9250_ACCEL_SENS_FRAC[4][2]
Definition: mpu9250.c:57
void mpu9250_send_config(Mpu9250ConfigSet mpu_set, void *mpu, struct Mpu9250Config *config)
Configuration sequence called once before normal use.
Definition: mpu9250.c:89
const float MPU9250_GYRO_SENS[4]
Definition: mpu9250.c:32
const struct Int32Rates MPU9250_GYRO_SENS_FRAC[4][2]
Definition: mpu9250.c:39
const float MPU9250_ACCEL_SENS[4]
Definition: mpu9250.c:50
void mpu9250_set_default_config(struct Mpu9250Config *c)
Definition: mpu9250.c:68
MPU-60X0 driver common interface (I2C and SPI).
#define MPU9250_ACCEL_SENS_2G
default accel sensitivy from the datasheet sens = 9.81 [m/s^2] / [LSB/g] * 2^INT32_ACCEL_FRAC ex: MPU...
Definition: mpu9250.h:84
#define MPU9250_DEFAULT_SMPLRT_DIV
Default sample rate divider.
Definition: mpu9250.h:37
#define MPU9250_GYRO_SENS_500
Definition: mpu9250.h:64
enum Mpu9250DLPFGyro dlpf_gyro_cfg
Digital Low Pass Filter for gyroscope.
Definition: mpu9250.h:130
#define MPU9250_GYRO_SENS_2000
Definition: mpu9250.h:70
uint8_t clk_sel
Clock select.
Definition: mpu9250.h:134
#define MPU9250_ACCEL_SENS_16G
Definition: mpu9250.h:93
#define MPU9250_GYRO_SENS_1000_NUM
Definition: mpu9250.h:68
#define MPU9250_DEFAULT_AFS_SEL
Default accel full scale range +- 16g.
Definition: mpu9250.h:41
#define MPU9250_GYRO_SENS_2000_NUM
Definition: mpu9250.h:71
#define MPU9250_GYRO_SENS_2000_DEN
Definition: mpu9250.h:72
#define MPU9250_GYRO_SENS_500_NUM
Definition: mpu9250.h:65
void(* Mpu9250ConfigSet)(void *mpu, uint8_t _reg, uint8_t _val)
Configuration function prototype.
Definition: mpu9250.h:118
#define MPU9250_ACCEL_SENS_8G_DEN
Definition: mpu9250.h:92
uint8_t nb_slave_init
number of already configured/initialized slaves
Definition: mpu9250.h:145
#define MPU9250_DEFAULT_DLPF_GYRO_CFG
Default internal sampling (1kHz, 42Hz LP Bandwidth)
Definition: mpu9250.h:45
#define MPU9250_GYRO_SENS_1000
Definition: mpu9250.h:67
#define MPU9250_ACCEL_SENS_4G_DEN
Definition: mpu9250.h:89
uint8_t nb_slaves
number of used I2C slaves
Definition: mpu9250.h:144
enum Mpu9250GyroRanges gyro_range
deg/s Range
Definition: mpu9250.h:131
#define MPU9250_DEFAULT_CLK_SEL
Default clock: PLL with X gyro reference.
Definition: mpu9250.h:49
#define MPU9250_GYRO_SENS_250_NUM
Definition: mpu9250.h:62
uint8_t nb_bytes
number of bytes to read starting with MPU9250_REG_INT_STATUS
Definition: mpu9250.h:135
bool i2c_bypass
Bypass MPU I2C.
Definition: mpu9250.h:142
#define MPU9250_DEFAULT_DLPF_ACCEL_CFG
Default internal sampling (1kHz, 42Hz LP Bandwidth)
Definition: mpu9250.h:43
#define MPU9250_ACCEL_SENS_2G_NUM
Definition: mpu9250.h:85
#define MPU9250_ACCEL_SENS_2G_DEN
Definition: mpu9250.h:86
#define MPU9250_ACCEL_SENS_16G_NUM
Definition: mpu9250.h:94
enum Mpu9250DLPFAccel dlpf_accel_cfg
Digital Low Pass Filter for accelerometer.
Definition: mpu9250.h:129
uint8_t smplrt_div
Sample rate divider.
Definition: mpu9250.h:128
#define MPU9250_GYRO_SENS_250_DEN
Definition: mpu9250.h:63
#define MPU9250_GYRO_SENS_1000_DEN
Definition: mpu9250.h:69
#define MPU9250_ACCEL_SENS_4G
Definition: mpu9250.h:87
enum Mpu9250AccelRanges accel_range
g Range
Definition: mpu9250.h:132
bool mpu9250_configure_i2c_slaves(Mpu9250ConfigSet mpu_set, void *mpu)
Configure I2C slaves of the MPU.
Definition: mpu9250_i2c.c:175
#define MPU9250_DEFAULT_FS_SEL
Default gyro full scale range +- 2000°/s.
Definition: mpu9250.h:39
#define MPU9250_ACCEL_SENS_8G
Definition: mpu9250.h:90
#define MPU9250_ACCEL_SENS_8G_NUM
Definition: mpu9250.h:91
#define MPU9250_ACCEL_SENS_16G_DEN
Definition: mpu9250.h:95
@ MPU9250_CONF_ACCEL
Definition: mpu9250.h:111
@ MPU9250_CONF_RESET
Definition: mpu9250.h:104
@ MPU9250_CONF_GYRO
Definition: mpu9250.h:110
@ MPU9250_CONF_DONE
Definition: mpu9250.h:114
@ MPU9250_CONF_DLPF_GYRO
Definition: mpu9250.h:109
@ MPU9250_CONF_USER_RESET
Definition: mpu9250.h:105
@ MPU9250_CONF_SD
Definition: mpu9250.h:107
@ MPU9250_CONF_INT_ENABLE
Definition: mpu9250.h:113
@ MPU9250_CONF_I2C_SLAVES
Definition: mpu9250.h:112
@ MPU9250_CONF_DLPF_ACCEL
Definition: mpu9250.h:108
@ MPU9250_CONF_PWR
Definition: mpu9250.h:106
#define MPU9250_ACCEL_SENS_4G_NUM
Definition: mpu9250.h:88
bool drdy_int_enable
Enable Data Ready Interrupt.
Definition: mpu9250.h:133
#define MPU9250_GYRO_SENS_250
default gyro sensitivy from the datasheet sens = 1/ [LSB/(deg/s)] * pi/180 * 2^INT32_RATE_FRAC ex: MP...
Definition: mpu9250.h:61
#define MPU9250_GYRO_SENS_500_DEN
Definition: mpu9250.h:66
#define MPU9250_I2C_MST_RESET
Definition: mpu9250_regs.h:128
#define MPU9250_SIG_COND_RESET
Definition: mpu9250_regs.h:127
#define MPU9250_REG_ACCEL_CONFIG_2
Definition: mpu9250_regs.h:56
#define MPU9250_REG_INT_ENABLE
Definition: mpu9250_regs.h:92
#define MPU9250_REG_USER_CTRL
Definition: mpu9250_regs.h:41
#define MPU9250_REG_ACCEL_CONFIG
Definition: mpu9250_regs.h:55
#define MPU9250_FIFO_RESET
Definition: mpu9250_regs.h:129
#define MPU9250_REG_SMPLRT_DIV
Definition: mpu9250_regs.h:52
#define MPU9250_REG_GYRO_CONFIG
Definition: mpu9250_regs.h:54
#define MPU9250_REG_CONFIG
Definition: mpu9250_regs.h:53
#define MPU9250_REG_PWR_MGMT_1
Definition: mpu9250_regs.h:42
static const struct usb_config_descriptor config
Definition: usb_ser_hw.c:200