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
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
37
44
45
52
53
60
62{
63 c->type = MPU60X0;
70 c->drdy_int_enable = false;
71
72 /* Number of bytes to read starting with MPU60X0_REG_INT_STATUS
73 * By default read only gyro and accel data -> 15 bytes.
74 * Increase to include slave data.
75 */
76 c->nb_bytes = 15;
77 c->nb_slaves = 0;
78 c->nb_slave_init = 0;
79
80 c->i2c_bypass = false;
81}
82
84{
85 switch (config->init_status) {
87 /* device reset, set register values to defaults */
88 mpu_set(mpu, MPU60X0_REG_PWR_MGMT_1, (1 << 6));
89 config->init_status++;
90 break;
92 /* trigger FIFO, I2C_MST and SIG_COND resets */
96 config->init_status++;
97 break;
99 /* switch to gyroX clock by default */
100 mpu_set(mpu, MPU60X0_REG_PWR_MGMT_1, ((config->clk_sel) | (0 << 6)));
101 config->init_status++;
102 break;
103 case MPU60X0_CONF_SD:
104 /* configure sample rate divider */
105 mpu_set(mpu, MPU60X0_REG_SMPLRT_DIV, config->smplrt_div);
106 config->init_status++;
107 break;
109 /* configure digital low pass filter */
110 mpu_set(mpu, MPU60X0_REG_CONFIG, config->dlpf_cfg);
111 config->init_status++;
112 break;
114 /* configure gyro range */
115 mpu_set(mpu, MPU60X0_REG_GYRO_CONFIG, (config->gyro_range << 3));
116 config->init_status++;
117 break;
119 /* configure accelerometer range */
120 mpu_set(mpu, MPU60X0_REG_ACCEL_CONFIG, (config->accel_range << 3));
121 config->init_status++;
122 break;
124 /* configure accelerometer DLPF (for ICM devices) */
125 if (config->type != MPU60X0) {
126 mpu_set(mpu, MPU60X0_REG_ACCEL_CONFIG2, config->dlpf_cfg_acc);
127 }
128 config->init_status++;
129 break;
131 /* if any, set MPU for I2C slaves and configure them*/
132 if (config->nb_slaves > 0) {
133 /* returns TRUE when all slaves are configured */
135 config->init_status++;
136 }
137 } else {
138 config->init_status++;
139 }
140 break;
142 /* configure data ready interrupt */
143 mpu_set(mpu, MPU60X0_REG_INT_ENABLE, (config->drdy_int_enable << 0));
144 config->init_status++;
145 break;
147 /* configure undocumented register (for ICM devices) to remove 2.7m/s^2 y-acc bias */
148 if (config->type != MPU60X0) {
149 mpu_set(mpu, MPU60X0_REG_UNDOC1, 0xC9);
150 }
151 config->init_status++;
152 break;
154 config->initialized = true;
155 break;
156 default:
157 break;
158 }
159}
angular rates
uint16_t foo
Definition main_demo5.c:58
void mpu60x0_set_default_config(struct Mpu60x0Config *c)
Definition mpu60x0.c:61
const struct FloatVect3 MPU60X0_ACCEL_SENS_F[4]
Definition mpu60x0.c:54
void mpu60x0_send_config(Mpu60x0ConfigSet mpu_set, void *mpu, struct Mpu60x0Config *config)
Configuration sequence called once before normal use.
Definition mpu60x0.c:83
const float MPU60X0_ACCEL_SENS[4]
Definition mpu60x0.c:46
const float MPU60X0_GYRO_SENS[4]
Definition mpu60x0.c:31
const struct FloatRates MPU60X0_GYRO_SENS_F[4]
Definition mpu60x0.c:38
MPU-60X0 driver common interface (I2C and SPI).
#define MPU60X0_DEFAULT_AFS_SEL
Default accel full scale range +- 16g.
Definition mpu60x0.h:42
#define MPU60X0_GYRO_SENS_2000
Definition mpu60x0.h:65
#define MPU60X0_DEFAULT_FS_SEL
Default gyro full scale range +- 2000°/s.
Definition mpu60x0.h:40
#define MPU60X0_DEFAULT_SMPLRT_DIV
Default sample rate divider.
Definition mpu60x0.h:38
#define MPU60X0_DEFAULT_DLPF_CFG_ACC
Default internal sampling for accelerometer ICM devices only (1kHz, 99Hz LP Bandwidth)
Definition mpu60x0.h:46
#define MPU60X0_ACCEL_SENS_16G
Definition mpu60x0.h:79
uint8_t nb_bytes
number of bytes to read starting with MPU60X0_REG_INT_STATUS
Definition mpu60x0.h:130
@ MPU60X0
Definition mpu60x0.h:88
uint8_t smplrt_div
Sample rate divider.
Definition mpu60x0.h:123
uint8_t nb_slaves
number of used I2C slaves
Definition mpu60x0.h:139
uint8_t nb_slave_init
number of already configured/initialized slaves
Definition mpu60x0.h:140
#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:62
enum Mpu60x0DLPF dlpf_cfg
Digital Low Pass Filter.
Definition mpu60x0.h:124
enum Mpu60x0Type type
The type of sensor (MPU60x0, ICM20608, ...)
Definition mpu60x0.h:122
#define MPU60X0_DEFAULT_CLK_SEL
Default clock: PLL with X gyro reference.
Definition mpu60x0.h:50
#define MPU60X0_GYRO_SENS_500
Definition mpu60x0.h:63
#define MPU60X0_ACCEL_SENS_8G
Definition mpu60x0.h:78
#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:76
#define MPU60X0_GYRO_SENS_1000
Definition mpu60x0.h:64
bool i2c_bypass
Bypass MPU I2C.
Definition mpu60x0.h:137
bool drdy_int_enable
Enable Data Ready Interrupt.
Definition mpu60x0.h:128
@ MPU60X0_CONF_I2C_SLAVES
Definition mpu60x0.h:105
@ MPU60X0_CONF_DONE
Definition mpu60x0.h:108
@ MPU60X0_CONF_ACCEL
Definition mpu60x0.h:103
@ MPU60X0_CONF_PWR
Definition mpu60x0.h:99
@ MPU60X0_CONF_GYRO
Definition mpu60x0.h:102
@ MPU60X0_CONF_INT_ENABLE
Definition mpu60x0.h:106
@ MPU60X0_CONF_USER_RESET
Definition mpu60x0.h:98
@ MPU60X0_CONF_RESET
Definition mpu60x0.h:97
@ MPU60X0_CONF_ACCEL2
Definition mpu60x0.h:104
@ MPU60X0_CONF_UNDOC1
Definition mpu60x0.h:107
@ MPU60X0_CONF_SD
Definition mpu60x0.h:100
@ MPU60X0_CONF_DLPF
Definition mpu60x0.h:101
#define MPU60X0_DEFAULT_DLPF_CFG
Default internal sampling (1kHz, 98Hz LP Bandwidth)
Definition mpu60x0.h:44
enum Mpu60x0AccelRanges accel_range
g Range
Definition mpu60x0.h:127
uint8_t clk_sel
Clock select.
Definition mpu60x0.h:129
#define MPU60X0_ACCEL_SENS_4G
Definition mpu60x0.h:77
enum Mpu60x0ACCDLPF dlpf_cfg_acc
Digital Low Pass Filter for acceleremoter (ICM devices only)
Definition mpu60x0.h:125
void(* Mpu60x0ConfigSet)(void *mpu, uint8_t _reg, uint8_t _val)
Configuration function prototype.
Definition mpu60x0.h:112
bool mpu60x0_configure_i2c_slaves(Mpu60x0ConfigSet mpu_set, void *mpu)
Configure I2C slaves of the MPU.
enum Mpu60x0GyroRanges gyro_range
deg/s Range
Definition mpu60x0.h:126
#define MPU60X0_REG_USER_CTRL
#define MPU60X0_FIFO_RESET
#define MPU60X0_REG_GYRO_CONFIG
#define MPU60X0_REG_CONFIG
#define MPU60X0_REG_ACCEL_CONFIG2
#define MPU60X0_REG_PWR_MGMT_1
#define MPU60X0_SIG_COND_RESET
#define MPU60X0_REG_ACCEL_CONFIG
#define MPU60X0_REG_UNDOC1
#define MPU60X0_REG_INT_ENABLE
#define MPU60X0_REG_SMPLRT_DIV
#define MPU60X0_I2C_MST_RESET
static const struct usb_config_descriptor config
Definition usb_ser_hw.c:200