Paparazzi UAS  v5.18.0_stable
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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
30 #include "peripherals/mpu60x0.h"
31 
32 const float MPU60X0_GYRO_SENS[4] = {
37 };
38 
44 };
45 
46 const float MPU60X0_ACCEL_SENS[4] = {
51 };
52 
58 };
59 
61 {
62  c->type = MPU60X0;
63  c->clk_sel = MPU60X0_DEFAULT_CLK_SEL;
64  c->smplrt_div = MPU60X0_DEFAULT_SMPLRT_DIV;
65  c->dlpf_cfg = MPU60X0_DEFAULT_DLPF_CFG;
66  c->dlpf_cfg_acc = MPU60X0_DEFAULT_DLPF_CFG_ACC;
67  c->gyro_range = MPU60X0_DEFAULT_FS_SEL;
68  c->accel_range = MPU60X0_DEFAULT_AFS_SEL;
69  c->drdy_int_enable = false;
70 
71  /* Number of bytes to read starting with MPU60X0_REG_INT_STATUS
72  * By default read only gyro and accel data -> 15 bytes.
73  * Increase to include slave data.
74  */
75  c->nb_bytes = 15;
76  c->nb_slaves = 0;
77  c->nb_slave_init = 0;
78 
79  c->i2c_bypass = false;
80 }
81 
82 void mpu60x0_send_config(Mpu60x0ConfigSet mpu_set, void *mpu, struct Mpu60x0Config *config)
83 {
84  switch (config->init_status) {
85  case MPU60X0_CONF_RESET:
86  /* device reset, set register values to defaults */
87  mpu_set(mpu, MPU60X0_REG_PWR_MGMT_1, (1 << 6));
88  config->init_status++;
89  break;
91  /* trigger FIFO, I2C_MST and SIG_COND resets */
92  mpu_set(mpu, MPU60X0_REG_USER_CTRL, ((1 << MPU60X0_FIFO_RESET) |
93  (1 << MPU60X0_I2C_MST_RESET) |
94  (1 << MPU60X0_SIG_COND_RESET)));
95  config->init_status++;
96  break;
97  case MPU60X0_CONF_PWR:
98  /* switch to gyroX clock by default */
99  mpu_set(mpu, MPU60X0_REG_PWR_MGMT_1, ((config->clk_sel) | (0 << 6)));
100  config->init_status++;
101  break;
102  case MPU60X0_CONF_SD:
103  /* configure sample rate divider */
104  mpu_set(mpu, MPU60X0_REG_SMPLRT_DIV, config->smplrt_div);
105  config->init_status++;
106  break;
107  case MPU60X0_CONF_DLPF:
108  /* configure digital low pass filter */
109  mpu_set(mpu, MPU60X0_REG_CONFIG, config->dlpf_cfg);
110  config->init_status++;
111  break;
112  case MPU60X0_CONF_GYRO:
113  /* configure gyro range */
114  mpu_set(mpu, MPU60X0_REG_GYRO_CONFIG, (config->gyro_range << 3));
115  config->init_status++;
116  break;
117  case MPU60X0_CONF_ACCEL:
118  /* configure accelerometer range */
119  mpu_set(mpu, MPU60X0_REG_ACCEL_CONFIG, (config->accel_range << 3));
120  config->init_status++;
121  break;
122  case MPU60X0_CONF_ACCEL2:
123  /* configure accelerometer DLPF (for ICM devices) */
124  if (config->type != MPU60X0) {
125  mpu_set(mpu, MPU60X0_REG_ACCEL_CONFIG2, config->dlpf_cfg_acc);
126  }
127  config->init_status++;
128  break;
130  /* if any, set MPU for I2C slaves and configure them*/
131  if (config->nb_slaves > 0) {
132  /* returns TRUE when all slaves are configured */
133  if (mpu60x0_configure_i2c_slaves(mpu_set, mpu)) {
134  config->init_status++;
135  }
136  } else {
137  config->init_status++;
138  }
139  break;
141  /* configure data ready interrupt */
142  mpu_set(mpu, MPU60X0_REG_INT_ENABLE, (config->drdy_int_enable << 0));
143  config->init_status++;
144  break;
145  case MPU60X0_CONF_UNDOC1:
146  /* configure undocumented register (for ICM devices) to remove 2.7m/s^2 y-acc bias */
147  if (config->type != MPU60X0) {
148  mpu_set(mpu, MPU60X0_REG_UNDOC1, 0xC9);
149  }
150  config->init_status++;
151  break;
152  case MPU60X0_CONF_DONE:
153  config->initialized = true;
154  break;
155  default:
156  break;
157  }
158 }
MPU60X0_REG_GYRO_CONFIG
#define MPU60X0_REG_GYRO_CONFIG
Definition: mpu60x0_regs.h:52
c
VIC slots used for the LPC2148 define name e g gps UART1_VIC_SLOT e g modem SPI1_VIC_SLOT SPI1 in mcu_periph spi_arch c or spi_slave_hs_arch c(and some others not using the SPI peripheral yet..) I2C0_VIC_SLOT 8 mcu_periph/i2c_arch.c I2C1_VIC_SLOT 9 mcu_periph/i2c_arch.c USB_VIC_SLOT 10 usb
MPU60X0_REG_PWR_MGMT_1
#define MPU60X0_REG_PWR_MGMT_1
Definition: mpu60x0_regs.h:40
MPU60X0_DEFAULT_FS_SEL
#define MPU60X0_DEFAULT_FS_SEL
Default gyro full scale range +- 2000°/s.
Definition: mpu60x0.h:39
MPU60X0_REG_INT_ENABLE
#define MPU60X0_REG_INT_ENABLE
Definition: mpu60x0_regs.h:90
MPU60X0_GYRO_SENS_250_DEN
#define MPU60X0_GYRO_SENS_250_DEN
Definition: mpu60x0.h:63
MPU60X0_GYRO_SENS_2000_NUM
#define MPU60X0_GYRO_SENS_2000_NUM
Definition: mpu60x0.h:71
MPU60X0_CONF_I2C_SLAVES
@ MPU60X0_CONF_I2C_SLAVES
Definition: mpu60x0.h:122
MPU60X0
@ MPU60X0
Definition: mpu60x0.h:105
MPU60X0_REG_SMPLRT_DIV
#define MPU60X0_REG_SMPLRT_DIV
Definition: mpu60x0_regs.h:50
MPU60X0_ACCEL_SENS_8G
#define MPU60X0_ACCEL_SENS_8G
Definition: mpu60x0.h:90
MPU60X0_REG_USER_CTRL
#define MPU60X0_REG_USER_CTRL
Definition: mpu60x0_regs.h:39
MPU60X0_FIFO_RESET
#define MPU60X0_FIFO_RESET
Definition: mpu60x0_regs.h:131
MPU60X0_CONF_DONE
@ MPU60X0_CONF_DONE
Definition: mpu60x0.h:125
MPU60X0_CONF_UNDOC1
@ MPU60X0_CONF_UNDOC1
Definition: mpu60x0.h:124
MPU60X0_ACCEL_SENS_2G_DEN
#define MPU60X0_ACCEL_SENS_2G_DEN
Definition: mpu60x0.h:86
MPU60X0_REG_ACCEL_CONFIG2
#define MPU60X0_REG_ACCEL_CONFIG2
Definition: mpu60x0_regs.h:54
MPU60X0_CONF_INT_ENABLE
@ MPU60X0_CONF_INT_ENABLE
Definition: mpu60x0.h:123
MPU60X0_DEFAULT_AFS_SEL
#define MPU60X0_DEFAULT_AFS_SEL
Default accel full scale range +- 16g.
Definition: mpu60x0.h:41
MPU60X0_CONF_ACCEL
@ MPU60X0_CONF_ACCEL
Definition: mpu60x0.h:120
Mpu60x0ConfigSet
void(* Mpu60x0ConfigSet)(void *mpu, uint8_t _reg, uint8_t _val)
Configuration function prototype.
Definition: mpu60x0.h:129
MPU60X0_REG_CONFIG
#define MPU60X0_REG_CONFIG
Definition: mpu60x0_regs.h:51
MPU60X0_GYRO_SENS_500_DEN
#define MPU60X0_GYRO_SENS_500_DEN
Definition: mpu60x0.h:66
MPU60X0_GYRO_SENS_2000
#define MPU60X0_GYRO_SENS_2000
Definition: mpu60x0.h:70
MPU60X0_CONF_PWR
@ MPU60X0_CONF_PWR
Definition: mpu60x0.h:116
MPU60X0_ACCEL_SENS_8G_DEN
#define MPU60X0_ACCEL_SENS_8G_DEN
Definition: mpu60x0.h:92
MPU60X0_ACCEL_SENS_2G
#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
mpu60x0_send_config
void mpu60x0_send_config(Mpu60x0ConfigSet mpu_set, void *mpu, struct Mpu60x0Config *config)
Configuration sequence called once before normal use.
Definition: mpu60x0.c:82
config
static const struct usb_config_descriptor config
Definition: usb_ser_hw.c:200
MPU60X0_ACCEL_SENS_4G_DEN
#define MPU60X0_ACCEL_SENS_4G_DEN
Definition: mpu60x0.h:89
MPU60X0_GYRO_SENS_250_NUM
#define MPU60X0_GYRO_SENS_250_NUM
Definition: mpu60x0.h:62
MPU60X0_CONF_DLPF
@ MPU60X0_CONF_DLPF
Definition: mpu60x0.h:118
mpu60x0.h
MPU60X0_ACCEL_SENS_4G
#define MPU60X0_ACCEL_SENS_4G
Definition: mpu60x0.h:87
MPU60X0_CONF_SD
@ MPU60X0_CONF_SD
Definition: mpu60x0.h:117
MPU60X0_DEFAULT_CLK_SEL
#define MPU60X0_DEFAULT_CLK_SEL
Default clock: PLL with X gyro reference.
Definition: mpu60x0.h:49
MPU60X0_GYRO_SENS_250
#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
MPU60X0_GYRO_SENS_500
#define MPU60X0_GYRO_SENS_500
Definition: mpu60x0.h:64
MPU60X0_GYRO_SENS_500_NUM
#define MPU60X0_GYRO_SENS_500_NUM
Definition: mpu60x0.h:65
MPU60X0_GYRO_SENS_2000_DEN
#define MPU60X0_GYRO_SENS_2000_DEN
Definition: mpu60x0.h:72
MPU60X0_ACCEL_SENS_16G
#define MPU60X0_ACCEL_SENS_16G
Definition: mpu60x0.h:93
MPU60X0_GYRO_SENS_1000
#define MPU60X0_GYRO_SENS_1000
Definition: mpu60x0.h:67
MPU60X0_CONF_RESET
@ MPU60X0_CONF_RESET
Definition: mpu60x0.h:114
MPU60X0_CONF_ACCEL2
@ MPU60X0_CONF_ACCEL2
Definition: mpu60x0.h:121
MPU60X0_GYRO_SENS_FRAC
const int32_t MPU60X0_GYRO_SENS_FRAC[4][2]
Definition: mpu60x0.c:39
MPU60X0_GYRO_SENS_1000_DEN
#define MPU60X0_GYRO_SENS_1000_DEN
Definition: mpu60x0.h:69
int32_t
signed long int32_t
Definition: types.h:19
mpu60x0_configure_i2c_slaves
bool mpu60x0_configure_i2c_slaves(Mpu60x0ConfigSet mpu_set, void *mpu)
Configure I2C slaves of the MPU.
Definition: mpu60x0_i2c.c:135
MPU60X0_DEFAULT_SMPLRT_DIV
#define MPU60X0_DEFAULT_SMPLRT_DIV
Default sample rate divider.
Definition: mpu60x0.h:37
MPU60X0_ACCEL_SENS
const float MPU60X0_ACCEL_SENS[4]
Definition: mpu60x0.c:46
MPU60X0_CONF_GYRO
@ MPU60X0_CONF_GYRO
Definition: mpu60x0.h:119
MPU60X0_GYRO_SENS
const float MPU60X0_GYRO_SENS[4]
Definition: mpu60x0.c:32
MPU60X0_ACCEL_SENS_4G_NUM
#define MPU60X0_ACCEL_SENS_4G_NUM
Definition: mpu60x0.h:88
MPU60X0_ACCEL_SENS_16G_NUM
#define MPU60X0_ACCEL_SENS_16G_NUM
Definition: mpu60x0.h:94
mpu60x0_set_default_config
void mpu60x0_set_default_config(struct Mpu60x0Config *c)
Definition: mpu60x0.c:60
MPU60X0_GYRO_SENS_1000_NUM
#define MPU60X0_GYRO_SENS_1000_NUM
Definition: mpu60x0.h:68
MPU60X0_DEFAULT_DLPF_CFG
#define MPU60X0_DEFAULT_DLPF_CFG
Default internal sampling (1kHz, 98Hz LP Bandwidth)
Definition: mpu60x0.h:43
MPU60X0_I2C_MST_RESET
#define MPU60X0_I2C_MST_RESET
Definition: mpu60x0_regs.h:130
Mpu60x0Config
Definition: mpu60x0.h:138
MPU60X0_ACCEL_SENS_2G_NUM
#define MPU60X0_ACCEL_SENS_2G_NUM
Definition: mpu60x0.h:85
MPU60X0_SIG_COND_RESET
#define MPU60X0_SIG_COND_RESET
Definition: mpu60x0_regs.h:129
MPU60X0_ACCEL_SENS_8G_NUM
#define MPU60X0_ACCEL_SENS_8G_NUM
Definition: mpu60x0.h:91
MPU60X0_REG_ACCEL_CONFIG
#define MPU60X0_REG_ACCEL_CONFIG
Definition: mpu60x0_regs.h:53
MPU60X0_CONF_USER_RESET
@ MPU60X0_CONF_USER_RESET
Definition: mpu60x0.h:115
MPU60X0_DEFAULT_DLPF_CFG_ACC
#define MPU60X0_DEFAULT_DLPF_CFG_ACC
Default internal sampling for accelerometer ICM devices only (1kHz, 99Hz LP Bandwidth)
Definition: mpu60x0.h:45
MPU60X0_ACCEL_SENS_FRAC
const int32_t MPU60X0_ACCEL_SENS_FRAC[4][2]
Definition: mpu60x0.c:53
MPU60X0_REG_UNDOC1
#define MPU60X0_REG_UNDOC1
Definition: mpu60x0_regs.h:55
MPU60X0_ACCEL_SENS_16G_DEN
#define MPU60X0_ACCEL_SENS_16G_DEN
Definition: mpu60x0.h:95