Paparazzi UAS v7.0_unstable
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
38
45
52
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
82{
83 switch (config->init_status) {
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 */
94 config->init_status++;
95 break;
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;
117 /* configure gyro range */
118 mpu_set(mpu, MPU9250_REG_GYRO_CONFIG, (config->gyro_range << 3));
119 config->init_status++;
120 break;
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 */
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;
143 config->initialized = true;
144 break;
145 default:
146 break;
147 }
148}
angular rates
uint16_t foo
Definition main_demo5.c:58
const struct FloatRates MPU9250_GYRO_SENS_F[4]
Definition mpu9250.c:39
const struct FloatVect3 MPU9250_ACCEL_SENS_F[4]
Definition mpu9250.c:53
void mpu9250_send_config(Mpu9250ConfigSet mpu_set, void *mpu, struct Mpu9250Config *config)
Configuration sequence called once before normal use.
Definition mpu9250.c:81
const float MPU9250_GYRO_SENS[4]
Definition mpu9250.c:32
const float MPU9250_ACCEL_SENS[4]
Definition mpu9250.c:46
void mpu9250_set_default_config(struct Mpu9250Config *c)
Definition mpu9250.c:60
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:77
#define MPU9250_DEFAULT_SMPLRT_DIV
Default sample rate divider.
Definition mpu9250.h:38
#define MPU9250_GYRO_SENS_500
Definition mpu9250.h:63
enum Mpu9250DLPFGyro dlpf_gyro_cfg
Digital Low Pass Filter for gyroscope.
Definition mpu9250.h:115
#define MPU9250_GYRO_SENS_2000
Definition mpu9250.h:65
uint8_t clk_sel
Clock select.
Definition mpu9250.h:119
#define MPU9250_ACCEL_SENS_16G
Definition mpu9250.h:80
#define MPU9250_DEFAULT_AFS_SEL
Default accel full scale range +- 16g.
Definition mpu9250.h:42
void(* Mpu9250ConfigSet)(void *mpu, uint8_t _reg, uint8_t _val)
Configuration function prototype.
Definition mpu9250.h:103
uint8_t nb_slave_init
number of already configured/initialized slaves
Definition mpu9250.h:130
#define MPU9250_DEFAULT_DLPF_GYRO_CFG
Default internal sampling (1kHz, 42Hz LP Bandwidth)
Definition mpu9250.h:46
#define MPU9250_GYRO_SENS_1000
Definition mpu9250.h:64
uint8_t nb_slaves
number of used I2C slaves
Definition mpu9250.h:129
enum Mpu9250GyroRanges gyro_range
deg/s Range
Definition mpu9250.h:116
#define MPU9250_DEFAULT_CLK_SEL
Default clock: PLL with X gyro reference.
Definition mpu9250.h:50
uint8_t nb_bytes
number of bytes to read starting with MPU9250_REG_INT_STATUS
Definition mpu9250.h:120
bool i2c_bypass
Bypass MPU I2C.
Definition mpu9250.h:127
#define MPU9250_DEFAULT_DLPF_ACCEL_CFG
Default internal sampling (1kHz, 42Hz LP Bandwidth)
Definition mpu9250.h:44
enum Mpu9250DLPFAccel dlpf_accel_cfg
Digital Low Pass Filter for accelerometer.
Definition mpu9250.h:114
uint8_t smplrt_div
Sample rate divider.
Definition mpu9250.h:113
#define MPU9250_ACCEL_SENS_4G
Definition mpu9250.h:78
enum Mpu9250AccelRanges accel_range
g Range
Definition mpu9250.h:117
bool mpu9250_configure_i2c_slaves(Mpu9250ConfigSet mpu_set, void *mpu)
Configure I2C slaves of the MPU.
#define MPU9250_DEFAULT_FS_SEL
Default gyro full scale range +- 2000°/s.
Definition mpu9250.h:40
#define MPU9250_ACCEL_SENS_8G
Definition mpu9250.h:79
@ MPU9250_CONF_ACCEL
Definition mpu9250.h:96
@ MPU9250_CONF_RESET
Definition mpu9250.h:89
@ MPU9250_CONF_GYRO
Definition mpu9250.h:95
@ MPU9250_CONF_DONE
Definition mpu9250.h:99
@ MPU9250_CONF_DLPF_GYRO
Definition mpu9250.h:94
@ MPU9250_CONF_USER_RESET
Definition mpu9250.h:90
@ MPU9250_CONF_SD
Definition mpu9250.h:92
@ MPU9250_CONF_INT_ENABLE
Definition mpu9250.h:98
@ MPU9250_CONF_I2C_SLAVES
Definition mpu9250.h:97
@ MPU9250_CONF_DLPF_ACCEL
Definition mpu9250.h:93
@ MPU9250_CONF_PWR
Definition mpu9250.h:91
bool drdy_int_enable
Enable Data Ready Interrupt.
Definition mpu9250.h:118
#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:62
#define MPU9250_I2C_MST_RESET
#define MPU9250_SIG_COND_RESET
#define MPU9250_REG_ACCEL_CONFIG_2
#define MPU9250_REG_INT_ENABLE
#define MPU9250_REG_USER_CTRL
#define MPU9250_REG_ACCEL_CONFIG
#define MPU9250_FIFO_RESET
#define MPU9250_REG_SMPLRT_DIV
#define MPU9250_REG_GYRO_CONFIG
#define MPU9250_REG_CONFIG
#define MPU9250_REG_PWR_MGMT_1
static const struct usb_config_descriptor config
Definition usb_ser_hw.c:200