mpu9x50.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Freie Universität Berlin
3  * 2019 HAW Hamburg
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
26 #ifndef MPU9X50_H
27 #define MPU9X50_H
28 
29 #include "periph/i2c.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
39 #define MPU9X50_MIN_SAMPLE_RATE (4)
40 #define MPU9X50_MAX_SAMPLE_RATE (1000)
41 #define MPU9X50_DEFAULT_SAMPLE_RATE (50)
42 #define MPU9X50_MIN_COMP_SMPL_RATE (1)
43 #define MPU9X50_MAX_COMP_SMPL_RATE (100)
44 
49 typedef enum {
50  MPU9X50_SENSOR_PWR_OFF = 0x00,
51  MPU9X50_SENSOR_PWR_ON = 0x01,
53 
57 typedef enum {
58  MPU9X50_HW_ADDR_HEX_68 = 0x68,
59  MPU9X50_HW_ADDR_HEX_69 = 0x69,
61 
65 typedef enum {
66  MPU9X50_COMP_ADDR_HEX_0C = 0x0C,
67  MPU9X50_COMP_ADDR_HEX_0D = 0x0D,
68  MPU9X50_COMP_ADDR_HEX_0E = 0x0E,
69  MPU9X50_COMP_ADDR_HEX_0F = 0x0F,
71 
75 typedef enum {
76  MPU9X50_GYRO_FSR_250DPS = 0x00,
77  MPU9X50_GYRO_FSR_500DPS = 0x01,
78  MPU9X50_GYRO_FSR_1000DPS = 0x02,
79  MPU9X50_GYRO_FSR_2000DPS = 0x03,
81 
85 typedef enum {
86  MPU9X50_ACCEL_FSR_2G = 0x00,
87  MPU9X50_ACCEL_FSR_4G = 0x01,
88  MPU9X50_ACCEL_FSR_8G = 0x02,
89  MPU9X50_ACCEL_FSR_16G = 0x03,
91 
95 typedef enum {
96  MPU9X50_FILTER_188HZ = 0x01,
97  MPU9X50_FILTER_98HZ = 0x02,
98  MPU9X50_FILTER_42HZ = 0x03,
99  MPU9X50_FILTER_20HZ = 0x04,
100  MPU9X50_FILTER_10HZ = 0x05,
101  MPU9X50_FILTER_5HZ = 0x06,
102 } mpu9x50_lpf_t;
103 
107 typedef struct {
108  int16_t x_axis;
109  int16_t y_axis;
110  int16_t z_axis;
112 
116 typedef struct {
122  uint16_t sample_rate;
124  uint8_t compass_x_adj;
125  uint8_t compass_y_adj;
126  uint8_t compass_z_adj;
128 
132 typedef struct {
134  uint8_t addr;
135  uint8_t comp_addr;
136  uint16_t sample_rate;
138 
142 typedef struct {
145 } mpu9x50_t;
146 
156 int mpu9x50_init(mpu9x50_t *dev, const mpu9x50_params_t *params);
157 
168 
179 
190 
204 int mpu9x50_read_gyro(const mpu9x50_t *dev, mpu9x50_results_t *output);
205 
219 int mpu9x50_read_accel(const mpu9x50_t *dev, mpu9x50_results_t *output);
220 
233 int mpu9x50_read_compass(const mpu9x50_t *dev, mpu9x50_results_t *output);
234 
248 int mpu9x50_read_temperature(const mpu9x50_t *dev, int32_t *output);
249 
261 
273 
288 int mpu9x50_set_sample_rate(mpu9x50_t *dev, uint16_t rate);
289 
305 int mpu9x50_set_compass_sample_rate(mpu9x50_t *dev, uint8_t rate);
306 
307 #ifdef __cplusplus
308 }
309 #endif
310 
311 #endif /* MPU9X50_H */
312 
mpu9x50_params_t::i2c
i2c_t i2c
I2C device which is used.
Definition: mpu9x50.h:133
mpu9x50_status_t
Configuration struct for the MPU-9X50 sensor.
Definition: mpu9x50.h:116
mpu9x50_hw_addr_t
mpu9x50_hw_addr_t
Possible MPU-9X50 hardware addresses (wiring specific)
Definition: mpu9x50.h:57
mpu9x50_status_t::sample_rate
uint16_t sample_rate
Configured sample rate for accel and gyro.
Definition: mpu9x50.h:122
mpu9x50_t::conf
mpu9x50_status_t conf
Device configuration.
Definition: mpu9x50.h:144
mpu9x50_set_accel_fsr
int mpu9x50_set_accel_fsr(mpu9x50_t *dev, mpu9x50_accel_ranges_t fsr)
Set the full-scale range for raw accelerometer data.
mpu9x50_set_accel_power
int mpu9x50_set_accel_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf)
Enable or disable accelerometer power.
mpu9x50_read_compass
int mpu9x50_read_compass(const mpu9x50_t *dev, mpu9x50_results_t *output)
Read magnetic field values from the given MPU9X50 device, returned in mikroT.
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
mpu9x50_set_gyro_power
int mpu9x50_set_gyro_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf)
Enable or disable gyroscope power.
mpu9x50_status_t::accel_fsr
mpu9x50_accel_ranges_t accel_fsr
Configured accel full-scale range.
Definition: mpu9x50.h:121
mpu9x50_status_t::compass_x_adj
uint8_t compass_x_adj
Compass X-Axis sensitivity adjustment value.
Definition: mpu9x50.h:124
mpu9x50_set_compass_sample_rate
int mpu9x50_set_compass_sample_rate(mpu9x50_t *dev, uint8_t rate)
Set the rate at which the compass data is sampled.
mpu9x50_set_gyro_fsr
int mpu9x50_set_gyro_fsr(mpu9x50_t *dev, mpu9x50_gyro_ranges_t fsr)
Set the full-scale range for raw gyroscope data.
mpu9x50_status_t::gyro_pwr
mpu9x50_pwr_t gyro_pwr
Gyro power status (on/off)
Definition: mpu9x50.h:118
mpu9x50_accel_ranges_t
mpu9x50_accel_ranges_t
Possible full scale ranges for the accelerometer.
Definition: mpu9x50.h:85
mpu9x50_t::params
mpu9x50_params_t params
Device initialization parameters.
Definition: mpu9x50.h:143
mpu9x50_t
Device descriptor for the MPU9X50 sensor.
Definition: mpu9x50.h:142
mpu9x50_params_t::comp_addr
uint8_t comp_addr
Address of the MPU-9X50s compass.
Definition: mpu9x50.h:135
mpu9x50_status_t::accel_pwr
mpu9x50_pwr_t accel_pwr
Accel power status (on/off)
Definition: mpu9x50.h:117
mpu9x50_status_t::compass_pwr
mpu9x50_pwr_t compass_pwr
Compass power status (on/off)
Definition: mpu9x50.h:119
mpu9x50_results_t::z_axis
int16_t z_axis
Z-Axis measurement result.
Definition: mpu9x50.h:110
mpu9x50_status_t::compass_z_adj
uint8_t compass_z_adj
Compass Z-Axis sensitivity adjustment value.
Definition: mpu9x50.h:126
mpu9x50_params_t
Device initialization parameters.
Definition: mpu9x50.h:132
mpu9x50_pwr_t
mpu9x50_pwr_t
Power enum values.
Definition: mpu9x50.h:49
mpu9x50_gyro_ranges_t
mpu9x50_gyro_ranges_t
Possible full scale ranges for the gyroscope.
Definition: mpu9x50.h:75
mpu9x50_status_t::compass_sample_rate
uint8_t compass_sample_rate
Configured compass sample rate.
Definition: mpu9x50.h:123
mpu9x50_results_t::x_axis
int16_t x_axis
X-Axis measurement result.
Definition: mpu9x50.h:108
mpu9x50_results_t::y_axis
int16_t y_axis
Y-Axis measurement result.
Definition: mpu9x50.h:109
mpu9x50_read_gyro
int mpu9x50_read_gyro(const mpu9x50_t *dev, mpu9x50_results_t *output)
Read angular speed values from the given MPU9X50 device, returned in dps.
mpu9x50_status_t::compass_y_adj
uint8_t compass_y_adj
Compass Y-Axis sensitivity adjustment value.
Definition: mpu9x50.h:125
mpu9x50_set_sample_rate
int mpu9x50_set_sample_rate(mpu9x50_t *dev, uint16_t rate)
Set the rate at which the gyroscope and accelerometer data is sampled.
mpu9x50_lpf_t
mpu9x50_lpf_t
Possible low pass filter values.
Definition: mpu9x50.h:95
mpu9x50_set_compass_power
int mpu9x50_set_compass_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf)
Enable or disable compass power.
mpu9x50_results_t
MPU-9X50 result vector struct.
Definition: mpu9x50.h:107
mpu9x50_status_t::gyro_fsr
mpu9x50_gyro_ranges_t gyro_fsr
Configured gyro full-scale range.
Definition: mpu9x50.h:120
mpu9x50_params_t::sample_rate
uint16_t sample_rate
Sample rate.
Definition: mpu9x50.h:136
mpu9x50_comp_addr_t
mpu9x50_comp_addr_t
Possible compass addresses (wiring specific)
Definition: mpu9x50.h:65
i2c.h
Low-level I2C peripheral driver interface definition.
mpu9x50_read_accel
int mpu9x50_read_accel(const mpu9x50_t *dev, mpu9x50_results_t *output)
Read acceleration values from the given MPU9X50 device, returned in mG.
mpu9x50_init
int mpu9x50_init(mpu9x50_t *dev, const mpu9x50_params_t *params)
Initialize the given MPU9X50 device.
mpu9x50_params_t::addr
uint8_t addr
Hardware address of the MPU-9X50.
Definition: mpu9x50.h:134
mpu9x50_read_temperature
int mpu9x50_read_temperature(const mpu9x50_t *dev, int32_t *output)
Read temperature value from the given MPU9X50 device, returned in m°C.