Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
44 };
45 
46 const float MPU9250_ACCEL_SENS[4] = {
51 };
52 
58 };
59 
61 {
68  c->drdy_int_enable = false;
69 
70  /* Number of bytes to read starting with MPU9250_REG_INT_STATUS
71  * By default read only gyro and accel data -> 15 bytes.
72  * Increase to include slave data.
73  */
74  c->nb_bytes = 15;
75  c->nb_slaves = 0;
76  c->nb_slave_init = 0;
77 
78  c->i2c_bypass = false;
79 }
80 
81 void mpu9250_send_config(Mpu9250ConfigSet mpu_set, void *mpu, struct Mpu9250Config *config)
82 {
83  switch (config->init_status) {
84  case MPU9250_CONF_RESET:
85  /* device reset, set register values to defaults */
86  mpu_set(mpu, MPU9250_REG_PWR_MGMT_1, (1 << 6));
87  config->init_status++;
88  break;
90  /* trigger FIFO, I2C_MST and SIG_COND resets */
91  mpu_set(mpu, MPU9250_REG_USER_CTRL, ((1 << MPU9250_FIFO_RESET) |
92  (1 << MPU9250_I2C_MST_RESET) |
93  (1 << MPU9250_SIG_COND_RESET)));
94  config->init_status++;
95  break;
96  case MPU9250_CONF_PWR:
97  /* switch to gyroX clock by default */
98  mpu_set(mpu, MPU9250_REG_PWR_MGMT_1, ((config->clk_sel) | (0 << 6)));
99  config->init_status++;
100  break;
101  case MPU9250_CONF_SD:
102  /* configure sample rate divider */
103  mpu_set(mpu, MPU9250_REG_SMPLRT_DIV, config->smplrt_div);
104  config->init_status++;
105  break;
107  /* configure digital low pass filter for gyroscope */
108  mpu_set(mpu, MPU9250_REG_CONFIG, config->dlpf_gyro_cfg);
109  config->init_status++;
110  break;
112  /* configure digital low pass filter fir accelerometer */
113  mpu_set(mpu, MPU9250_REG_ACCEL_CONFIG_2, config->dlpf_accel_cfg);
114  config->init_status++;
115  break;
116  case MPU9250_CONF_GYRO:
117  /* configure gyro range */
118  mpu_set(mpu, MPU9250_REG_GYRO_CONFIG, (config->gyro_range << 3));
119  config->init_status++;
120  break;
121  case MPU9250_CONF_ACCEL:
122  /* configure accelerometer range */
123  mpu_set(mpu, MPU9250_REG_ACCEL_CONFIG, (config->accel_range << 3));
124  config->init_status++;
125  break;
127  /* if any, set MPU for I2C slaves and configure them*/
128  if (config->nb_slaves > 0) {
129  /* returns TRUE when all slaves are configured */
130  if (mpu9250_configure_i2c_slaves(mpu_set, mpu)) {
131  config->init_status++;
132  }
133  } else {
134  config->init_status++;
135  }
136  break;
138  /* configure data ready interrupt */
139  mpu_set(mpu, MPU9250_REG_INT_ENABLE, (config->drdy_int_enable << 0));
140  config->init_status++;
141  break;
142  case MPU9250_CONF_DONE:
143  config->initialized = true;
144  break;
145  default:
146  break;
147  }
148 }
bool drdy_int_enable
Enable Data Ready Interrupt.
Definition: mpu9250.h:132
const float MPU9250_GYRO_SENS[4]
Definition: mpu9250.c:32
#define MPU9250_GYRO_SENS_1000
Definition: mpu9250.h:66
enum Mpu9250DLPFGyro dlpf_gyro_cfg
Digital Low Pass Filter for gyroscope.
Definition: mpu9250.h:129
#define MPU9250_SIG_COND_RESET
Definition: mpu9250_regs.h:127
MPU-60X0 driver common interface (I2C and SPI).
#define MPU9250_DEFAULT_SMPLRT_DIV
Default sample rate divider.
Definition: mpu9250.h:36
enum Mpu9250GyroRanges gyro_range
deg/s Range
Definition: mpu9250.h:130
enum Mpu9250ConfStatus init_status
init status
Definition: mpu9250.h:135
uint8_t nb_bytes
number of bytes to read starting with MPU9250_REG_INT_STATUS
Definition: mpu9250.h:134
#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:83
uint8_t clk_sel
Clock select.
Definition: mpu9250.h:133
#define MPU9250_GYRO_SENS_1000_NUM
Definition: mpu9250.h:67
#define MPU9250_ACCEL_SENS_16G_NUM
Definition: mpu9250.h:93
#define MPU9250_ACCEL_SENS_4G
Definition: mpu9250.h:86
#define MPU9250_DEFAULT_DLPF_GYRO_CFG
Default internal sampling (1kHz, 42Hz LP Bandwidth)
Definition: mpu9250.h:44
#define MPU9250_REG_ACCEL_CONFIG
Definition: mpu9250_regs.h:55
#define MPU9250_DEFAULT_DLPF_ACCEL_CFG
Default internal sampling (1kHz, 42Hz LP Bandwidth)
Definition: mpu9250.h:42
enum Mpu9250DLPFAccel dlpf_accel_cfg
Digital Low Pass Filter for accelerometer.
Definition: mpu9250.h:128
bool i2c_bypass
Bypass MPU I2C.
Definition: mpu9250.h:141
#define MPU9250_ACCEL_SENS_8G
Definition: mpu9250.h:89
#define MPU9250_ACCEL_SENS_4G_NUM
Definition: mpu9250.h:87
bool mpu9250_configure_i2c_slaves(Mpu9250ConfigSet mpu_set, void *mpu)
Configure I2C slaves of the MPU.
Definition: mpu9250_i2c.c:175
#define MPU9250_REG_PWR_MGMT_1
Definition: mpu9250_regs.h:42
#define MPU9250_FIFO_RESET
Definition: mpu9250_regs.h:129
#define MPU9250_DEFAULT_FS_SEL
Default gyro full scale range +- 2000°/s.
Definition: mpu9250.h:38
#define MPU9250_REG_CONFIG
Definition: mpu9250_regs.h:53
#define MPU9250_ACCEL_SENS_2G_DEN
Definition: mpu9250.h:85
void mpu9250_send_config(Mpu9250ConfigSet mpu_set, void *mpu, struct Mpu9250Config *config)
Configuration sequence called once before normal use.
Definition: mpu9250.c:81
#define MPU9250_GYRO_SENS_2000
Definition: mpu9250.h:69
#define MPU9250_ACCEL_SENS_16G_DEN
Definition: mpu9250.h:94
void(* Mpu9250ConfigSet)(void *mpu, uint8_t _reg, uint8_t _val)
Configuration function prototype.
Definition: mpu9250.h:117
#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:60
const int32_t MPU9250_GYRO_SENS_FRAC[4][2]
Definition: mpu9250.c:39
#define MPU9250_GYRO_SENS_1000_DEN
Definition: mpu9250.h:68
#define MPU9250_I2C_MST_RESET
Definition: mpu9250_regs.h:128
void mpu9250_set_default_config(struct Mpu9250Config *c)
Definition: mpu9250.c:60
const float MPU9250_ACCEL_SENS[4]
Definition: mpu9250.c:46
uint8_t nb_slaves
number of used I2C slaves
Definition: mpu9250.h:143
#define MPU9250_GYRO_SENS_2000_NUM
Definition: mpu9250.h:70
signed long int32_t
Definition: types.h:19
#define MPU9250_DEFAULT_AFS_SEL
Default accel full scale range +- 16g.
Definition: mpu9250.h:40
#define MPU9250_ACCEL_SENS_8G_NUM
Definition: mpu9250.h:90
enum Mpu9250AccelRanges accel_range
g Range
Definition: mpu9250.h:131
#define MPU9250_REG_USER_CTRL
Definition: mpu9250_regs.h:41
#define MPU9250_GYRO_SENS_500_DEN
Definition: mpu9250.h:65
#define MPU9250_REG_ACCEL_CONFIG_2
Definition: mpu9250_regs.h:56
static const struct usb_config_descriptor config
Definition: usb_ser_hw.c:199
#define MPU9250_ACCEL_SENS_2G_NUM
Definition: mpu9250.h:84
#define MPU9250_GYRO_SENS_500
Definition: mpu9250.h:63
#define MPU9250_REG_GYRO_CONFIG
Definition: mpu9250_regs.h:54
#define MPU9250_GYRO_SENS_2000_DEN
Definition: mpu9250.h:71
#define MPU9250_REG_SMPLRT_DIV
Definition: mpu9250_regs.h:52
uint8_t nb_slave_init
number of already configured/initialized slaves
Definition: mpu9250.h:144
#define MPU9250_GYRO_SENS_500_NUM
Definition: mpu9250.h:64
uint8_t smplrt_div
Sample rate divider.
Definition: mpu9250.h:127
bool initialized
config done flag
Definition: mpu9250.h:136
#define MPU9250_ACCEL_SENS_8G_DEN
Definition: mpu9250.h:91
const int32_t MPU9250_ACCEL_SENS_FRAC[4][2]
Definition: mpu9250.c:53
#define MPU9250_GYRO_SENS_250_NUM
Definition: mpu9250.h:61
#define MPU9250_DEFAULT_CLK_SEL
Default clock: PLL with X gyro reference.
Definition: mpu9250.h:48
#define MPU9250_ACCEL_SENS_4G_DEN
Definition: mpu9250.h:88
#define MPU9250_ACCEL_SENS_16G
Definition: mpu9250.h:92
#define MPU9250_GYRO_SENS_250_DEN
Definition: mpu9250.h:62
#define MPU9250_REG_INT_ENABLE
Definition: mpu9250_regs.h:92