mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
driver/mpu9x50: Rename mpu9150 to mpu9x50
Rename all files Rename all variables, methods and methodcalls Rename all folders Add to the makefiles Add to doc
This commit is contained in:
parent
8a877b58df
commit
2df5d6048d
@ -6,7 +6,7 @@ endif
|
||||
ifneq (,$(filter saul_default,$(USEMODULE)))
|
||||
USEMODULE += saul_gpio
|
||||
endif
|
||||
# add support for the MPU-9150 as default saul device
|
||||
# add support for the MPU-9X50 as default saul device
|
||||
ifneq (,$(filter saul_default,$(USEMODULE)))
|
||||
USEMODULE += mpu9150
|
||||
USEMODULE += mpu9x50
|
||||
endif
|
||||
|
@ -150,28 +150,28 @@ on the inclusion.
|
||||
| IRQ Line | PA10 |
|
||||
|
||||
|
||||
### MPU-9150 Nine-Axis MotionTracking Device
|
||||
### MPU-9X50 Nine-Axis MotionTracking Device
|
||||
|
||||
The MSB-IoT is equipped with a MPU-9150 MotionTracking Device from
|
||||
The MSB-IoT is equipped with a MPU-9X50 MotionTracking Device from
|
||||
Invensense. The device combines a gyroscope, a magnetometer and an accelerometer
|
||||
in one module.
|
||||
|
||||
Due to licensing issues, the current MPU-9150 driver implementation for RIOT
|
||||
Due to licensing issues, the current MPU-9X50 driver implementation for RIOT
|
||||
is not based on Invensense's 'Motion Driver' library and offers only a limited
|
||||
set of features. Nonetheless, the RIOT driver allows to configure and read
|
||||
values from all three sensors of the device. For an overview on the supported
|
||||
features, you can check the driver's documentation in @ref drivers_mpu9150.
|
||||
features, you can check the driver's documentation in @ref drivers_mpu9x50.
|
||||
|
||||
A sample RIOT application for the MPU-9150 that utilizes the driver can be
|
||||
found [here](https://github.com/RIOT-OS/RIOT/tree/master/tests/driver_mpu9150).
|
||||
A sample RIOT application for the MPU-9X50 that utilizes the driver can be
|
||||
found [here](https://github.com/RIOT-OS/RIOT/tree/master/tests/driver_mpu9x50).
|
||||
|
||||
| Product | MPU-9150 |
|
||||
| Product | MPU-9X50 |
|
||||
|:--------------------- |:------------------------------------------------------------------------------------------------- |
|
||||
| Type | Nine-Axis MotionTracking Device (Gyro, Accel and Compass) |
|
||||
| Vendor | Invensense |
|
||||
| Product Specification | [Product Specification](http://www.invensense.com/mems/gyro/documents/PS-MPU-9150A-00v4_3.pdf) |
|
||||
| Register Map | [Register Map](http://www.invensense.com/mems/gyro/documents/RM-MPU-9150A-00v4_2.pdf) |
|
||||
| Driver | @ref drivers_mpu9150 |
|
||||
| Product Specification | [Product Specification](http://www.invensense.com/mems/gyro/documents/PS-MPU-9X50A-00v4_3.pdf) |
|
||||
| Register Map | [Register Map](http://www.invensense.com/mems/gyro/documents/RM-MPU-9X50A-00v4_2.pdf) |
|
||||
| Driver | @ref drivers_mpu9x50 |
|
||||
| I²C Device | I2C1 (Mapped to I2C_0 in RIOT) |
|
||||
| SCL | PB6 |
|
||||
| SDA | PB7 |
|
||||
|
@ -322,9 +322,10 @@ ifneq (,$(filter mpl3115a2,$(USEMODULE)))
|
||||
FEATURES_REQUIRED += periph_i2c
|
||||
endif
|
||||
|
||||
ifneq (,$(filter mpu9150,$(USEMODULE)))
|
||||
ifneq (,$(filter mpu9%50,$(USEMODULE)))
|
||||
FEATURES_REQUIRED += periph_i2c
|
||||
USEMODULE += xtimer
|
||||
USEMODULE += mpu9x50
|
||||
endif
|
||||
|
||||
ifneq (,$(filter mq3,$(USEMODULE)))
|
||||
|
@ -194,8 +194,8 @@ ifneq (,$(filter mpl3115a2,$(USEMODULE)))
|
||||
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/mpl3115a2/include
|
||||
endif
|
||||
|
||||
ifneq (,$(filter mpu9150,$(USEMODULE)))
|
||||
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/mpu9150/include
|
||||
ifneq (,$(filter mpu9x50,$(USEMODULE)))
|
||||
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/mpu9x50/include
|
||||
endif
|
||||
|
||||
ifneq (,$(filter mrf24j40,$(USEMODULE)))
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Freie Universität Berlin
|
||||
* 2019 HAW Hamburg
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
@ -7,22 +8,23 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup drivers_mpu9150 MPU-9150 accelerometer/magnetometer/gyroscope
|
||||
* @defgroup drivers_mpu9x50 MPU-9X50 (MPU9150 and MPU9250) accelerometer/magnetometer/gyroscope
|
||||
* @ingroup drivers_sensors
|
||||
* @ingroup drivers_saul
|
||||
* @brief Device driver interface for the MPU-9150
|
||||
* @brief Device driver interface for the MPU-9X50 (MPU9150 and MPU9250)
|
||||
*
|
||||
* This driver provides @ref drivers_saul capabilities.
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Device driver interface for the MPU-9150
|
||||
* @brief Device driver interface for the MPU-9X50 (MPU9150 and MPU9250)
|
||||
*
|
||||
* @author Fabian Nack <nack@inf.fu-berlin.de>
|
||||
* @author Jannes Volkens <jannes.volkens@haw-hamburg.de>
|
||||
*/
|
||||
|
||||
#ifndef MPU9150_H
|
||||
#define MPU9150_H
|
||||
#ifndef MPU9X50_H
|
||||
#define MPU9X50_H
|
||||
|
||||
#include "periph/i2c.h"
|
||||
|
||||
@ -34,278 +36,293 @@ extern "C" {
|
||||
* @name Sample rate macro definitions
|
||||
* @{
|
||||
*/
|
||||
#define MPU9150_MIN_SAMPLE_RATE (4)
|
||||
#define MPU9150_MAX_SAMPLE_RATE (1000)
|
||||
#define MPU9150_DEFAULT_SAMPLE_RATE (50)
|
||||
#define MPU9150_MIN_COMP_SMPL_RATE (1)
|
||||
#define MPU9150_MAX_COMP_SMPL_RATE (100)
|
||||
#define MPU9X50_MIN_SAMPLE_RATE (4)
|
||||
#define MPU9X50_MAX_SAMPLE_RATE (1000)
|
||||
#define MPU9X50_DEFAULT_SAMPLE_RATE (50)
|
||||
#define MPU9X50_MIN_COMP_SMPL_RATE (1)
|
||||
#define MPU9X50_MAX_COMP_SMPL_RATE (100)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Power Management 1 register macros
|
||||
* @{
|
||||
*/
|
||||
#define MPU9150_PWR_WAKEUP (0x00)
|
||||
#define MPU9150_PWR_PLL (0x01)
|
||||
#define MPU9150_PWR_RESET (0x80)
|
||||
#define MPU9X50_PWR_WAKEUP (0x00)
|
||||
#define MPU9X50_PWR_PLL (0x01)
|
||||
#define MPU9X50_PWR_RESET (0x80)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Power Management 2 register macros
|
||||
* @{
|
||||
*/
|
||||
#define MPU9150_PWR_GYRO (0x07)
|
||||
#define MPU9150_PWR_ACCEL (0x38)
|
||||
#define MPU9X50_PWR_GYRO (0x07)
|
||||
#define MPU9X50_PWR_ACCEL (0x38)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Sleep times in microseconds
|
||||
* @{
|
||||
*/
|
||||
#define MPU9150_COMP_MODE_SLEEP_US (1000)
|
||||
#define MPU9150_BYPASS_SLEEP_US (3000)
|
||||
#define MPU9150_PWR_CHANGE_SLEEP_US (50000)
|
||||
#define MPU9150_RESET_SLEEP_US (100000)
|
||||
#define MPU9X50_COMP_MODE_SLEEP_US (1000)
|
||||
#define MPU9X50_BYPASS_SLEEP_US (3000)
|
||||
#define MPU9X50_PWR_CHANGE_SLEEP_US (50000)
|
||||
#define MPU9X50_RESET_SLEEP_US (100000)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name MPU-9150 compass operating modes and reg values
|
||||
* @name MPU-9X50 compass operating modes and reg values
|
||||
* @{
|
||||
*/
|
||||
#define MPU9150_COMP_POWER_DOWN (0x00)
|
||||
#define MPU9150_COMP_SINGLE_MEASURE (0x01)
|
||||
#define MPU9150_COMP_SELF_TEST (0x08)
|
||||
#define MPU9150_COMP_FUSE_ROM (0x0F)
|
||||
#define MPU9150_COMP_WHOAMI_ANSWER (0x48)
|
||||
#define MPU9X50_COMP_POWER_DOWN (0x00)
|
||||
#define MPU9X50_COMP_SINGLE_MEASURE (0x01)
|
||||
#define MPU9X50_COMP_SELF_TEST (0x08)
|
||||
#define MPU9X50_COMP_FUSE_ROM (0x0F)
|
||||
#define MPU9X50_COMP_WHOAMI_ANSWER (0x48) /**< MPU9X50 WHO_AM_I answer register */
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @ingroup config
|
||||
* @{
|
||||
*/
|
||||
#ifdef MODULE_MPU9150
|
||||
#define MPU9X50_TEMP_SENSITIVITY 340
|
||||
#define MPU9X50_TEMP_OFFSET 35
|
||||
#elif MODULE_MPU9250
|
||||
#define MPU9X50_TEMP_SENSITIVITY 333.87
|
||||
#define MPU9X50_TEMP_OFFSET 21
|
||||
#else
|
||||
#error "MPU9X50 DRIVER not selected or supported"
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief Power enum values
|
||||
*/
|
||||
typedef enum {
|
||||
MPU9150_SENSOR_PWR_OFF = 0x00,
|
||||
MPU9150_SENSOR_PWR_ON = 0x01,
|
||||
} mpu9150_pwr_t;
|
||||
MPU9X50_SENSOR_PWR_OFF = 0x00,
|
||||
MPU9X50_SENSOR_PWR_ON = 0x01,
|
||||
} mpu9x50_pwr_t;
|
||||
|
||||
/**
|
||||
* @brief Possible MPU-9150 hardware addresses (wiring specific)
|
||||
* @brief Possible MPU-9X50 hardware addresses (wiring specific)
|
||||
*/
|
||||
typedef enum {
|
||||
MPU9150_HW_ADDR_HEX_68 = 0x68,
|
||||
MPU9150_HW_ADDR_HEX_69 = 0x69,
|
||||
} mpu9150_hw_addr_t;
|
||||
MPU9X50_HW_ADDR_HEX_68 = 0x68,
|
||||
MPU9X50_HW_ADDR_HEX_69 = 0x69,
|
||||
} mpu9x50_hw_addr_t;
|
||||
|
||||
/**
|
||||
* @brief Possible compass addresses (wiring specific)
|
||||
*/
|
||||
typedef enum {
|
||||
MPU9150_COMP_ADDR_HEX_0C = 0x0C,
|
||||
MPU9150_COMP_ADDR_HEX_0D = 0x0D,
|
||||
MPU9150_COMP_ADDR_HEX_0E = 0x0E,
|
||||
MPU9150_COMP_ADDR_HEX_0F = 0x0F,
|
||||
} mpu9150_comp_addr_t;
|
||||
MPU9X50_COMP_ADDR_HEX_0C = 0x0C,
|
||||
MPU9X50_COMP_ADDR_HEX_0D = 0x0D,
|
||||
MPU9X50_COMP_ADDR_HEX_0E = 0x0E,
|
||||
MPU9X50_COMP_ADDR_HEX_0F = 0x0F,
|
||||
} mpu9x50_comp_addr_t;
|
||||
|
||||
/**
|
||||
* @brief Possible full scale ranges for the gyroscope
|
||||
*/
|
||||
typedef enum {
|
||||
MPU9150_GYRO_FSR_250DPS = 0x00,
|
||||
MPU9150_GYRO_FSR_500DPS = 0x01,
|
||||
MPU9150_GYRO_FSR_1000DPS = 0x02,
|
||||
MPU9150_GYRO_FSR_2000DPS = 0x03,
|
||||
} mpu9150_gyro_ranges_t;
|
||||
MPU9X50_GYRO_FSR_250DPS = 0x00,
|
||||
MPU9X50_GYRO_FSR_500DPS = 0x01,
|
||||
MPU9X50_GYRO_FSR_1000DPS = 0x02,
|
||||
MPU9X50_GYRO_FSR_2000DPS = 0x03,
|
||||
} mpu9x50_gyro_ranges_t;
|
||||
|
||||
/**
|
||||
* @brief Possible full scale ranges for the accelerometer
|
||||
*/
|
||||
typedef enum {
|
||||
MPU9150_ACCEL_FSR_2G = 0x00,
|
||||
MPU9150_ACCEL_FSR_4G = 0x01,
|
||||
MPU9150_ACCEL_FSR_8G = 0x02,
|
||||
MPU9150_ACCEL_FSR_16G = 0x03,
|
||||
} mpu9150_accel_ranges_t;
|
||||
MPU9X50_ACCEL_FSR_2G = 0x00,
|
||||
MPU9X50_ACCEL_FSR_4G = 0x01,
|
||||
MPU9X50_ACCEL_FSR_8G = 0x02,
|
||||
MPU9X50_ACCEL_FSR_16G = 0x03,
|
||||
} mpu9x50_accel_ranges_t;
|
||||
|
||||
/**
|
||||
* @brief Possible low pass filter values
|
||||
*/
|
||||
typedef enum {
|
||||
MPU9150_FILTER_188HZ = 0x01,
|
||||
MPU9150_FILTER_98HZ = 0x02,
|
||||
MPU9150_FILTER_42HZ = 0x03,
|
||||
MPU9150_FILTER_20HZ = 0x04,
|
||||
MPU9150_FILTER_10HZ = 0x05,
|
||||
MPU9150_FILTER_5HZ = 0x06,
|
||||
} mpu9150_lpf_t;
|
||||
MPU9X50_FILTER_188HZ = 0x01,
|
||||
MPU9X50_FILTER_98HZ = 0x02,
|
||||
MPU9X50_FILTER_42HZ = 0x03,
|
||||
MPU9X50_FILTER_20HZ = 0x04,
|
||||
MPU9X50_FILTER_10HZ = 0x05,
|
||||
MPU9X50_FILTER_5HZ = 0x06,
|
||||
} mpu9x50_lpf_t;
|
||||
|
||||
/**
|
||||
* @brief MPU-9150 result vector struct
|
||||
* @brief MPU-9X50 result vector struct
|
||||
*/
|
||||
typedef struct {
|
||||
int16_t x_axis; /**< X-Axis measurement result */
|
||||
int16_t y_axis; /**< Y-Axis measurement result */
|
||||
int16_t z_axis; /**< Z-Axis measurement result */
|
||||
} mpu9150_results_t;
|
||||
} mpu9x50_results_t;
|
||||
|
||||
/**
|
||||
* @brief Configuration struct for the MPU-9150 sensor
|
||||
* @brief Configuration struct for the MPU-9X50 sensor
|
||||
*/
|
||||
typedef struct {
|
||||
mpu9150_pwr_t accel_pwr; /**< Accel power status (on/off) */
|
||||
mpu9150_pwr_t gyro_pwr; /**< Gyro power status (on/off) */
|
||||
mpu9150_pwr_t compass_pwr; /**< Compass power status (on/off) */
|
||||
mpu9150_gyro_ranges_t gyro_fsr; /**< Configured gyro full-scale range */
|
||||
mpu9150_accel_ranges_t accel_fsr; /**< Configured accel full-scale range */
|
||||
mpu9x50_pwr_t accel_pwr; /**< Accel power status (on/off) */
|
||||
mpu9x50_pwr_t gyro_pwr; /**< Gyro power status (on/off) */
|
||||
mpu9x50_pwr_t compass_pwr; /**< Compass power status (on/off) */
|
||||
mpu9x50_gyro_ranges_t gyro_fsr; /**< Configured gyro full-scale range */
|
||||
mpu9x50_accel_ranges_t accel_fsr; /**< Configured accel full-scale range */
|
||||
uint16_t sample_rate; /**< Configured sample rate for accel and gyro */
|
||||
uint8_t compass_sample_rate; /**< Configured compass sample rate */
|
||||
uint8_t compass_x_adj; /**< Compass X-Axis sensitivity adjustment value */
|
||||
uint8_t compass_y_adj; /**< Compass Y-Axis sensitivity adjustment value */
|
||||
uint8_t compass_z_adj; /**< Compass Z-Axis sensitivity adjustment value */
|
||||
} mpu9150_status_t;
|
||||
} mpu9x50_status_t;
|
||||
|
||||
/**
|
||||
* @brief Device initialization parameters
|
||||
*/
|
||||
typedef struct {
|
||||
i2c_t i2c; /**< I2C device which is used */
|
||||
uint8_t addr; /**< Hardware address of the MPU-9150 */
|
||||
uint8_t comp_addr; /**< Address of the MPU-9150s compass */
|
||||
uint8_t addr; /**< Hardware address of the MPU-9X50 */
|
||||
uint8_t comp_addr; /**< Address of the MPU-9X50s compass */
|
||||
uint16_t sample_rate; /**< Sample rate */
|
||||
} mpu9150_params_t;
|
||||
} mpu9x50_params_t;
|
||||
|
||||
/**
|
||||
* @brief Device descriptor for the MPU-9150 sensor
|
||||
* @brief Device descriptor for the MPU9X50 sensor
|
||||
*/
|
||||
typedef struct {
|
||||
mpu9150_params_t params; /**< Device initialization parameters */
|
||||
mpu9150_status_t conf; /**< Device configuration */
|
||||
} mpu9150_t;
|
||||
mpu9x50_params_t params; /**< Device initialization parameters */
|
||||
mpu9x50_status_t conf; /**< Device configuration */
|
||||
} mpu9x50_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize the given MPU9150 device
|
||||
* @brief Initialize the given MPU9X50 device
|
||||
*
|
||||
* @param[out] dev Initialized device descriptor of MPU9150 device
|
||||
* @param[out] dev Initialized device descriptor of MPU9X50 device
|
||||
* @param[in] params Initialization parameters
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return -1 if given I2C is not enabled in board config
|
||||
*/
|
||||
int mpu9150_init(mpu9150_t *dev, const mpu9150_params_t *params);
|
||||
int mpu9x50_init(mpu9x50_t *dev, const mpu9x50_params_t *params);
|
||||
|
||||
/**
|
||||
* @brief Enable or disable accelerometer power
|
||||
*
|
||||
* @param[in] dev Device descriptor of MPU9150 device
|
||||
* @param[in] dev Device descriptor of MPU9X50 device
|
||||
* @param[in] pwr_conf Target power setting: PWR_ON or PWR_OFF
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return -1 if given I2C is not enabled in board config
|
||||
*/
|
||||
int mpu9150_set_accel_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf);
|
||||
int mpu9x50_set_accel_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf);
|
||||
|
||||
/**
|
||||
* @brief Enable or disable gyroscope power
|
||||
*
|
||||
* @param[in] dev Device descriptor of MPU9150 device
|
||||
* @param[in] dev Device descriptor of MPU9X50 device
|
||||
* @param[in] pwr_conf Target power setting: PWR_ON or PWR_OFF
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return -1 if given I2C is not enabled in board config
|
||||
*/
|
||||
int mpu9150_set_gyro_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf);
|
||||
int mpu9x50_set_gyro_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf);
|
||||
|
||||
/**
|
||||
* @brief Enable or disable compass power
|
||||
*
|
||||
* @param[in] dev Device descriptor of MPU9150 device
|
||||
* @param[in] dev Device descriptor of MPU9X50 device
|
||||
* @param[in] pwr_conf Target power setting: PWR_ON or PWR_OFF
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return -1 if given I2C is not enabled in board config
|
||||
*/
|
||||
int mpu9150_set_compass_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf);
|
||||
int mpu9x50_set_compass_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf);
|
||||
|
||||
/**
|
||||
* @brief Read angular speed values from the given MPU9150 device, returned in dps
|
||||
* @brief Read angular speed values from the given MPU9X50 device, returned in dps
|
||||
*
|
||||
* The raw gyroscope data is read from the sensor and normalized with respect to
|
||||
* the configured gyroscope full-scale range.
|
||||
*
|
||||
* @param[in] dev Device descriptor of MPU9150 device to read from
|
||||
* @param[in] dev Device descriptor of MPU9X50 device to read from
|
||||
* @param[out] output Result vector in dps per axis
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return -1 if device's I2C is not enabled in board config
|
||||
* @return -2 if gyro full-scale range is configured wrong
|
||||
*/
|
||||
int mpu9150_read_gyro(const mpu9150_t *dev, mpu9150_results_t *output);
|
||||
int mpu9x50_read_gyro(const mpu9x50_t *dev, mpu9x50_results_t *output);
|
||||
|
||||
/**
|
||||
* @brief Read acceleration values from the given MPU9150 device, returned in mG
|
||||
* @brief Read acceleration values from the given MPU9X50 device, returned in mG
|
||||
*
|
||||
* The raw acceleration data is read from the sensor and normalized with respect to
|
||||
* the configured accelerometer full-scale range.
|
||||
*
|
||||
* @param[in] dev Device descriptor of MPU9150 device to read from
|
||||
* @param[in] dev Device descriptor of MPU9X50 device to read from
|
||||
* @param[out] output Result vector in mG per axis
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return -1 if device's I2C is not enabled in board config
|
||||
* @return -2 if accel full-scale range is configured wrong
|
||||
*/
|
||||
int mpu9150_read_accel(const mpu9150_t *dev, mpu9150_results_t *output);
|
||||
int mpu9x50_read_accel(const mpu9x50_t *dev, mpu9x50_results_t *output);
|
||||
|
||||
/**
|
||||
* @brief Read magnetic field values from the given MPU9150 device, returned in mikroT
|
||||
* @brief Read magnetic field values from the given MPU9X50 device, returned in mikroT
|
||||
*
|
||||
* The raw compass data is read from the sensor and normalized with respect to
|
||||
* the compass full-scale range (which can not be configured).
|
||||
*
|
||||
* @param[in] dev Device descriptor of MPU9150 device to read from
|
||||
* @param[in] dev Device descriptor of MPU9X50 device to read from
|
||||
* @param[out] output Result vector in mikroT per axis
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return -1 if device's I2C is not enabled in board config
|
||||
*/
|
||||
int mpu9150_read_compass(const mpu9150_t *dev, mpu9150_results_t *output);
|
||||
int mpu9x50_read_compass(const mpu9x50_t *dev, mpu9x50_results_t *output);
|
||||
|
||||
/**
|
||||
* @brief Read temperature value from the given MPU9150 device, returned in m°C
|
||||
* @brief Read temperature value from the given MPU9X50 device, returned in m°C
|
||||
*
|
||||
* @note
|
||||
* The measured temperature is slightly higher than the real room temperature.
|
||||
* Tests showed that the offset varied around 2-3 °C (but no warranties here).
|
||||
*
|
||||
* @param[in] dev Device descriptor of MPU9150 device to read from
|
||||
* @param[in] dev Device descriptor of MPU9X50 device to read from
|
||||
* @param[out] output Temperature in m°C
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return -1 if device's I2C is not enabled in board config
|
||||
*/
|
||||
int mpu9150_read_temperature(const mpu9150_t *dev, int32_t *output);
|
||||
int mpu9x50_read_temperature(const mpu9x50_t *dev, int32_t *output);
|
||||
|
||||
/**
|
||||
* @brief Set the full-scale range for raw gyroscope data
|
||||
*
|
||||
* @param[in] dev Device descriptor of MPU9150 device
|
||||
* @param[in] dev Device descriptor of MPU9X50 device
|
||||
* @param[in] fsr Target full-scale range
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return -1 if device's I2C is not enabled in board config
|
||||
* @return -2 if given full-scale target value is not valid
|
||||
*/
|
||||
int mpu9150_set_gyro_fsr(mpu9150_t *dev, mpu9150_gyro_ranges_t fsr);
|
||||
int mpu9x50_set_gyro_fsr(mpu9x50_t *dev, mpu9x50_gyro_ranges_t fsr);
|
||||
|
||||
/**
|
||||
* @brief Set the full-scale range for raw accelerometer data
|
||||
*
|
||||
* @param[in] dev Device descriptor of MPU9150 device
|
||||
* @param[in] dev Device descriptor of MPU9X50 device
|
||||
* @param[in] fsr Target full-scale range
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return -1 if device's I2C is not enabled in board config
|
||||
* @return -2 if given full-scale target value is not valid
|
||||
*/
|
||||
int mpu9150_set_accel_fsr(mpu9150_t *dev, mpu9150_accel_ranges_t fsr);
|
||||
int mpu9x50_set_accel_fsr(mpu9x50_t *dev, mpu9x50_accel_ranges_t fsr);
|
||||
|
||||
/**
|
||||
* @brief Set the rate at which the gyroscope and accelerometer data is sampled
|
||||
@ -314,14 +331,14 @@ int mpu9150_set_accel_fsr(mpu9150_t *dev, mpu9150_accel_ranges_t fsr);
|
||||
* slightly differ. If necessary, check the actual set value in the device's
|
||||
* config member afterwards.
|
||||
*
|
||||
* @param[in] dev Device descriptor of MPU9150 device
|
||||
* @param[in] dev Device descriptor of MPU9X50 device
|
||||
* @param[in] rate Target sample rate in Hz
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return -1 if device's I2C is not enabled in board config
|
||||
* @return -2 if given target sample rate is not valid
|
||||
*/
|
||||
int mpu9150_set_sample_rate(mpu9150_t *dev, uint16_t rate);
|
||||
int mpu9x50_set_sample_rate(mpu9x50_t *dev, uint16_t rate);
|
||||
|
||||
/**
|
||||
* @brief Set the rate at which the compass data is sampled
|
||||
@ -331,18 +348,18 @@ int mpu9150_set_sample_rate(mpu9150_t *dev, uint16_t rate);
|
||||
* slightly differ. If necessary, check the actual set value in the device's
|
||||
* config member afterwards.
|
||||
*
|
||||
* @param[in] dev Device descriptor of MPU9150 device
|
||||
* @param[in] dev Device descriptor of MPU9X50 device
|
||||
* @param[in] rate Target sample rate in Hz
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return -1 if device's I2C is not enabled in board config
|
||||
* @return -2 if given target sample rate is not valid
|
||||
*/
|
||||
int mpu9150_set_compass_sample_rate(mpu9150_t *dev, uint8_t rate);
|
||||
int mpu9x50_set_compass_sample_rate(mpu9x50_t *dev, uint8_t rate);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MPU9150_H */
|
||||
#endif /* MPU9X50_H */
|
||||
/** @} */
|
@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup drivers_mpu9150
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Register and bit definitions for the MPU-9150 9-Axis Motion Sensor
|
||||
*
|
||||
* @author Fabian Nack <nack@inf.fu-berlin.de>
|
||||
*/
|
||||
|
||||
#ifndef MPU9150_REGS_H
|
||||
#define MPU9150_REGS_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name MPU-9150 register definitions
|
||||
* @{
|
||||
*/
|
||||
#define MPU9150_YG_OFFS_TC_REG (0x01)
|
||||
#define MPU9150_RATE_DIV_REG (0x19)
|
||||
#define MPU9150_LPF_REG (0x1A)
|
||||
#define MPU9150_GYRO_CFG_REG (0x1B)
|
||||
#define MPU9150_ACCEL_CFG_REG (0x1C)
|
||||
#define MPU9150_FIFO_EN_REG (0x23)
|
||||
#define MPU9150_I2C_MST_REG (0x24)
|
||||
#define MPU9150_SLAVE0_ADDR_REG (0x25)
|
||||
#define MPU9150_SLAVE0_REG_REG (0x26)
|
||||
#define MPU9150_SLAVE0_CTRL_REG (0x27)
|
||||
#define MPU9150_SLAVE1_ADDR_REG (0x28)
|
||||
#define MPU9150_SLAVE1_REG_REG (0x29)
|
||||
#define MPU9150_SLAVE1_CTRL_REG (0x2A)
|
||||
#define MPU9150_SLAVE4_CTRL_REG (0x34)
|
||||
#define MPU9150_INT_PIN_CFG_REG (0x37)
|
||||
#define MPU9150_INT_ENABLE_REG (0x38)
|
||||
#define MPU9150_DMP_INT_STATUS (0x39)
|
||||
#define MPU9150_INT_STATUS (0x3A)
|
||||
#define MPU9150_ACCEL_START_REG (0x3B)
|
||||
#define MPU9150_TEMP_START_REG (0x41)
|
||||
#define MPU9150_GYRO_START_REG (0x43)
|
||||
#define MPU9150_EXT_SENS_DATA_START_REG (0x49)
|
||||
#define MPU9150_COMPASS_DATA_START_REG (0x4A)
|
||||
#define MPU9150_SLAVE0_DATA_OUT_REG (0x63)
|
||||
#define MPU9150_SLAVE1_DATA_OUT_REG (0x64)
|
||||
#define MPU9150_SLAVE2_DATA_OUT_REG (0x65)
|
||||
#define MPU9150_SLAVE3_DATA_OUT_REG (0x66)
|
||||
#define MPU9150_I2C_DELAY_CTRL_REG (0x67)
|
||||
#define MPU9150_USER_CTRL_REG (0x6A)
|
||||
#define MPU9150_PWR_MGMT_1_REG (0x6B)
|
||||
#define MPU9150_PWR_MGMT_2_REG (0x6C)
|
||||
#define MPU9150_FIFO_COUNT_START_REG (0x72)
|
||||
#define MPU9150_FIFO_RW_REG (0x74)
|
||||
#define MPU9150_WHO_AM_I_REG (0x75)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Compass register definitions
|
||||
* @{
|
||||
*/
|
||||
#define COMPASS_WHOAMI_REG (0x00)
|
||||
#define COMPASS_ST1_REG (0x02)
|
||||
#define COMPASS_DATA_START_REG (0x03)
|
||||
#define COMPASS_ST2_REG (0x09)
|
||||
#define COMPASS_CNTL_REG (0x0A)
|
||||
#define COMPASS_ASTC_REG (0x0C)
|
||||
#define COMPASS_ASAX_REG (0x10)
|
||||
#define COMPASS_ASAY_REG (0x11)
|
||||
#define COMPASS_ASAZ_REG (0x12)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name MPU9150 bitfield definitions
|
||||
* @{
|
||||
*/
|
||||
#define BIT_SLV0_DELAY_EN (0x01)
|
||||
#define BIT_SLV1_DELAY_EN (0x02)
|
||||
#define BIT_I2C_BYPASS_EN (0x02)
|
||||
#define BIT_I2C_MST_EN (0x20)
|
||||
#define BIT_PWR_MGMT1_SLEEP (0x40)
|
||||
#define BIT_WAIT_FOR_ES (0x40)
|
||||
#define BIT_I2C_MST_VDDIO (0x80)
|
||||
#define BIT_SLAVE_RW (0x80)
|
||||
#define BIT_SLAVE_EN (0x80)
|
||||
#define BIT_DMP_EN (0x80)
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MPU9150_REGS_H */
|
||||
/** @} */
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup drivers_mpu9150
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Default configuration for MPU9150 devices
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*/
|
||||
|
||||
#ifndef MPU9150_PARAMS_H
|
||||
#define MPU9150_PARAMS_H
|
||||
|
||||
#include "board.h"
|
||||
#include "saul_reg.h"
|
||||
#include "mpu9150.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name Default configuration parameters for the MPU9150 driver
|
||||
* @{
|
||||
*/
|
||||
#ifndef MPU9150_PARAM_I2C
|
||||
#define MPU9150_PARAM_I2C I2C_DEV(0)
|
||||
#endif
|
||||
#ifndef MPU9150_PARAM_ADDR
|
||||
#define MPU9150_PARAM_ADDR (MPU9150_HW_ADDR_HEX_68)
|
||||
#endif
|
||||
#ifndef MPU9150_PARAM_COMP_ADDR
|
||||
#define MPU9150_PARAM_COMP_ADDR (MPU9150_COMP_ADDR_HEX_0C)
|
||||
#endif
|
||||
#ifndef MPU9150_PARAM_SAMPLE_RATE
|
||||
#define MPU9150_PARAM_SAMPLE_RATE (MPU9150_DEFAULT_SAMPLE_RATE)
|
||||
#endif
|
||||
|
||||
#ifndef MPU9150_PARAMS
|
||||
#define MPU9150_PARAMS { .i2c = MPU9150_PARAM_I2C, \
|
||||
.addr = MPU9150_PARAM_ADDR, \
|
||||
.comp_addr = MPU9150_PARAM_COMP_ADDR, \
|
||||
.sample_rate = MPU9150_PARAM_SAMPLE_RATE }
|
||||
#endif
|
||||
#ifndef MPU9150_SAUL_INFO
|
||||
#define MPU9150_SAUL_INFO { .name = "mpu9150" }
|
||||
#endif
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
* @brief MPU9150 configuration
|
||||
*/
|
||||
static const mpu9150_params_t mpu9150_params[] =
|
||||
{
|
||||
MPU9150_PARAMS
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Additional meta information to keep in the SAUL registry
|
||||
*/
|
||||
static const saul_reg_info_t mpu9150_saul_info[] =
|
||||
{
|
||||
MPU9150_SAUL_INFO
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MPU9150_PARAMS_H */
|
||||
/** @} */
|
@ -1,3 +1 @@
|
||||
MODULE = mpu9150
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
81
drivers/mpu9x50/include/mpu9x50_params.h
Normal file
81
drivers/mpu9x50/include/mpu9x50_params.h
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Inria
|
||||
* 2019 HAW Hamburg
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup drivers_mpu9x50
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Default configuration for MPU9X50 (MPU9150 and MPU9250) devices
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
* @author Jannes Volkens <jannes.volkens@haw-hamburg.de>
|
||||
*/
|
||||
|
||||
#ifndef MPU9X50_PARAMS_H
|
||||
#define MPU9X50_PARAMS_H
|
||||
|
||||
#include "board.h"
|
||||
#include "saul_reg.h"
|
||||
#include "mpu9x50.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name Default configuration parameters for the MPU9X50 driver
|
||||
* @{
|
||||
*/
|
||||
#ifndef MPU9X50_PARAM_I2C
|
||||
#define MPU9X50_PARAM_I2C I2C_DEV(0)
|
||||
#endif
|
||||
#ifndef MPU9X50_PARAM_ADDR
|
||||
#define MPU9X50_PARAM_ADDR (MPU9X50_HW_ADDR_HEX_68)
|
||||
#endif
|
||||
#ifndef MPU9X50_PARAM_COMP_ADDR
|
||||
#define MPU9X50_PARAM_COMP_ADDR (MPU9X50_COMP_ADDR_HEX_0C)
|
||||
#endif
|
||||
#ifndef MPU9X50_PARAM_SAMPLE_RATE
|
||||
#define MPU9X50_PARAM_SAMPLE_RATE (MPU9X50_DEFAULT_SAMPLE_RATE)
|
||||
#endif
|
||||
|
||||
#ifndef MPU9X50_PARAMS
|
||||
#define MPU9X50_PARAMS { .i2c = MPU9X50_PARAM_I2C, \
|
||||
.addr = MPU9X50_PARAM_ADDR, \
|
||||
.comp_addr = MPU9X50_PARAM_COMP_ADDR, \
|
||||
.sample_rate = MPU9X50_PARAM_SAMPLE_RATE }
|
||||
#endif
|
||||
#ifndef MPU9X50_SAUL_INFO
|
||||
#define MPU9X50_SAUL_INFO { .name = "mpu9x50" }
|
||||
#endif
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
* @brief MPU9X50 configuration
|
||||
*/
|
||||
static const mpu9x50_params_t mpu9x50_params[] =
|
||||
{
|
||||
MPU9X50_PARAMS
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Additional meta information to keep in the SAUL registry
|
||||
*/
|
||||
static const saul_reg_info_t mpu9x50_saul_info[] =
|
||||
{
|
||||
MPU9X50_SAUL_INFO
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MPU9X50_PARAMS_H */
|
||||
/** @} */
|
105
drivers/mpu9x50/include/mpu9x50_regs.h
Normal file
105
drivers/mpu9x50/include/mpu9x50_regs.h
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Freie Universität Berlin
|
||||
* 2019 HAW Hamburg
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup drivers_mpu9x50
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Register and bit definitions for the MPU-9X50 (MPU9150 and MPU9250) 9-Axis Motion Sensor
|
||||
*
|
||||
* @author Fabian Nack <nack@inf.fu-berlin.de>
|
||||
* @author Jannes Volkens <jannes.volkens@haw-hamburg.de>
|
||||
*/
|
||||
|
||||
#ifndef MPU9X50_REGS_H
|
||||
#define MPU9X50_REGS_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name MPU-9X50 register definitions
|
||||
* @{
|
||||
*/
|
||||
#define MPU9X50_YG_OFFS_TC_REG (0x01)
|
||||
#define MPU9X50_RATE_DIV_REG (0x19)
|
||||
#define MPU9X50_LPF_REG (0x1A)
|
||||
#define MPU9X50_GYRO_CFG_REG (0x1B)
|
||||
#define MPU9X50_ACCEL_CFG_REG (0x1C)
|
||||
#define MPU9X50_FIFO_EN_REG (0x23)
|
||||
#define MPU9X50_I2C_MST_REG (0x24)
|
||||
#define MPU9X50_SLAVE0_ADDR_REG (0x25)
|
||||
#define MPU9X50_SLAVE0_REG_REG (0x26)
|
||||
#define MPU9X50_SLAVE0_CTRL_REG (0x27)
|
||||
#define MPU9X50_SLAVE1_ADDR_REG (0x28)
|
||||
#define MPU9X50_SLAVE1_REG_REG (0x29)
|
||||
#define MPU9X50_SLAVE1_CTRL_REG (0x2A)
|
||||
#define MPU9X50_SLAVE4_CTRL_REG (0x34)
|
||||
#define MPU9X50_INT_PIN_CFG_REG (0x37)
|
||||
#define MPU9X50_INT_ENABLE_REG (0x38)
|
||||
#define MPU9X50_DMP_INT_STATUS (0x39)
|
||||
#define MPU9X50_INT_STATUS (0x3A)
|
||||
#define MPU9X50_ACCEL_START_REG (0x3B)
|
||||
#define MPU9X50_TEMP_START_REG (0x41)
|
||||
#define MPU9X50_GYRO_START_REG (0x43)
|
||||
#define MPU9X50_EXT_SENS_DATA_START_REG (0x49)
|
||||
#define MPU9X50_COMPASS_DATA_START_REG (0x4A)
|
||||
#define MPU9X50_SLAVE0_DATA_OUT_REG (0x63)
|
||||
#define MPU9X50_SLAVE1_DATA_OUT_REG (0x64)
|
||||
#define MPU9X50_SLAVE2_DATA_OUT_REG (0x65)
|
||||
#define MPU9X50_SLAVE3_DATA_OUT_REG (0x66)
|
||||
#define MPU9X50_I2C_DELAY_CTRL_REG (0x67)
|
||||
#define MPU9X50_USER_CTRL_REG (0x6A)
|
||||
#define MPU9X50_PWR_MGMT_1_REG (0x6B)
|
||||
#define MPU9X50_PWR_MGMT_2_REG (0x6C)
|
||||
#define MPU9X50_FIFO_COUNT_START_REG (0x72)
|
||||
#define MPU9X50_FIFO_RW_REG (0x74)
|
||||
#define MPU9X50_WHO_AM_I_REG (0x75)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Compass register definitions
|
||||
* @{
|
||||
*/
|
||||
#define COMPASS_WHOAMI_REG (0x00)
|
||||
#define COMPASS_ST1_REG (0x02)
|
||||
#define COMPASS_DATA_START_REG (0x03)
|
||||
#define COMPASS_ST2_REG (0x09)
|
||||
#define COMPASS_CNTL_REG (0x0A)
|
||||
#define COMPASS_ASTC_REG (0x0C)
|
||||
#define COMPASS_ASAX_REG (0x10)
|
||||
#define COMPASS_ASAY_REG (0x11)
|
||||
#define COMPASS_ASAZ_REG (0x12)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name MPU9X50 bitfield definitions
|
||||
* @{
|
||||
*/
|
||||
#define BIT_SLV0_DELAY_EN (0x01)
|
||||
#define BIT_SLV1_DELAY_EN (0x02)
|
||||
#define BIT_I2C_BYPASS_EN (0x02)
|
||||
#define BIT_I2C_MST_EN (0x20)
|
||||
#define BIT_PWR_MGMT1_SLEEP (0x40)
|
||||
#define BIT_WAIT_FOR_ES (0x40)
|
||||
#define BIT_I2C_MST_VDDIO (0x80)
|
||||
#define BIT_SLAVE_RW (0x80)
|
||||
#define BIT_SLAVE_EN (0x80)
|
||||
#define BIT_DMP_EN (0x80)
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MPU9X50_REGS_H */
|
||||
/** @} */
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Freie Universität Berlin
|
||||
* 2019 HAW Hamburg
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
@ -7,19 +8,20 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup drivers_mpu9150
|
||||
* @ingroup drivers_mpu9x50
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Device driver implementation for the MPU-9150 9-Axis Motion Sensor
|
||||
* @brief Device driver implementation for the MPU-9X50 (MPU9150 and MPU9250) 9-Axis Motion Sensor
|
||||
*
|
||||
* @author Fabian Nack <nack@inf.fu-berlin.de>
|
||||
* @author Jannes Volkens <jannes.volkens@haw-hamburg.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "mpu9150.h"
|
||||
#include "mpu9150-regs.h"
|
||||
#include "mpu9x50.h"
|
||||
#include "mpu9x50-regs.h"
|
||||
#include "periph/i2c.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
@ -34,12 +36,12 @@
|
||||
#define DEV_COMP_ADDR (dev->params.comp_addr)
|
||||
|
||||
/* Default config settings */
|
||||
static const mpu9150_status_t DEFAULT_STATUS = {
|
||||
.accel_pwr = MPU9150_SENSOR_PWR_ON,
|
||||
.gyro_pwr = MPU9150_SENSOR_PWR_ON,
|
||||
.compass_pwr = MPU9150_SENSOR_PWR_ON,
|
||||
.gyro_fsr = MPU9150_GYRO_FSR_250DPS,
|
||||
.accel_fsr = MPU9150_ACCEL_FSR_16G,
|
||||
static const mpu9x50_status_t DEFAULT_STATUS = {
|
||||
.accel_pwr = MPU9X50_SENSOR_PWR_ON,
|
||||
.gyro_pwr = MPU9X50_SENSOR_PWR_ON,
|
||||
.compass_pwr = MPU9X50_SENSOR_PWR_ON,
|
||||
.gyro_fsr = MPU9X50_GYRO_FSR_250DPS,
|
||||
.accel_fsr = MPU9X50_ACCEL_FSR_16G,
|
||||
.sample_rate = 0,
|
||||
.compass_sample_rate = 0,
|
||||
.compass_x_adj = 0,
|
||||
@ -48,15 +50,15 @@ static const mpu9150_status_t DEFAULT_STATUS = {
|
||||
};
|
||||
|
||||
/* Internal function prototypes */
|
||||
static int compass_init(mpu9150_t *dev);
|
||||
static void conf_bypass(const mpu9150_t *dev, uint8_t bypass_enable);
|
||||
static void conf_lpf(const mpu9150_t *dev, uint16_t rate);
|
||||
static int compass_init(mpu9x50_t *dev);
|
||||
static void conf_bypass(const mpu9x50_t *dev, uint8_t bypass_enable);
|
||||
static void conf_lpf(const mpu9x50_t *dev, uint16_t rate);
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
* MPU9150 Core API *
|
||||
* MPU9X50 Core API *
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
int mpu9150_init(mpu9150_t *dev, const mpu9150_params_t *params)
|
||||
int mpu9x50_init(mpu9x50_t *dev, const mpu9x50_params_t *params)
|
||||
{
|
||||
dev->params = *params;
|
||||
|
||||
@ -67,22 +69,22 @@ int mpu9150_init(mpu9150_t *dev, const mpu9150_params_t *params)
|
||||
/* Acquire exclusive access */
|
||||
i2c_acquire(DEV_I2C);
|
||||
|
||||
/* Reset MPU9150 registers and afterwards wake up the chip */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_RESET, 0);
|
||||
xtimer_usleep(MPU9150_RESET_SLEEP_US);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_WAKEUP, 0);
|
||||
/* Reset MPU9X50 registers and afterwards wake up the chip */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_1_REG, MPU9X50_PWR_RESET, 0);
|
||||
xtimer_usleep(MPU9X50_RESET_SLEEP_US);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_1_REG, MPU9X50_PWR_WAKEUP, 0);
|
||||
|
||||
/* Release the bus, it is acquired again inside each function */
|
||||
i2c_release(DEV_I2C);
|
||||
|
||||
/* Set default full scale ranges and sample rate */
|
||||
mpu9150_set_gyro_fsr(dev, MPU9150_GYRO_FSR_2000DPS);
|
||||
mpu9150_set_accel_fsr(dev, MPU9150_ACCEL_FSR_2G);
|
||||
mpu9150_set_sample_rate(dev, dev->params.sample_rate);
|
||||
mpu9x50_set_gyro_fsr(dev, MPU9X50_GYRO_FSR_2000DPS);
|
||||
mpu9x50_set_accel_fsr(dev, MPU9X50_ACCEL_FSR_2G);
|
||||
mpu9x50_set_sample_rate(dev, dev->params.sample_rate);
|
||||
|
||||
/* Disable interrupt generation */
|
||||
i2c_acquire(DEV_I2C);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_INT_ENABLE_REG, REG_RESET, 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_INT_ENABLE_REG, REG_RESET, 0);
|
||||
|
||||
/* Initialize magnetometer */
|
||||
if (compass_init(dev)) {
|
||||
@ -91,20 +93,20 @@ int mpu9150_init(mpu9150_t *dev, const mpu9150_params_t *params)
|
||||
}
|
||||
/* Release the bus, it is acquired again inside each function */
|
||||
i2c_release(DEV_I2C);
|
||||
mpu9150_set_compass_sample_rate(dev, 10);
|
||||
mpu9x50_set_compass_sample_rate(dev, 10);
|
||||
/* Enable all sensors */
|
||||
i2c_acquire(DEV_I2C);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_PLL, 0);
|
||||
i2c_read_reg(DEV_I2C, DEV_ADDR, MPU9150_PWR_MGMT_2_REG, &temp, 0);
|
||||
temp &= ~(MPU9150_PWR_ACCEL | MPU9150_PWR_GYRO);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_PWR_MGMT_2_REG, temp, 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_1_REG, MPU9X50_PWR_PLL, 0);
|
||||
i2c_read_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_2_REG, &temp, 0);
|
||||
temp &= ~(MPU9X50_PWR_ACCEL | MPU9X50_PWR_GYRO);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_2_REG, temp, 0);
|
||||
i2c_release(DEV_I2C);
|
||||
xtimer_usleep(MPU9150_PWR_CHANGE_SLEEP_US);
|
||||
xtimer_usleep(MPU9X50_PWR_CHANGE_SLEEP_US);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mpu9150_set_accel_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf)
|
||||
int mpu9x50_set_accel_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf)
|
||||
{
|
||||
uint8_t pwr_1_setting, pwr_2_setting;
|
||||
|
||||
@ -118,34 +120,34 @@ int mpu9150_set_accel_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf)
|
||||
}
|
||||
|
||||
/* Read current power management 2 configuration */
|
||||
i2c_read_reg(DEV_I2C, DEV_ADDR, MPU9150_PWR_MGMT_2_REG, &pwr_2_setting, 0);
|
||||
i2c_read_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_2_REG, &pwr_2_setting, 0);
|
||||
/* Prepare power register settings */
|
||||
if (pwr_conf == MPU9150_SENSOR_PWR_ON) {
|
||||
pwr_1_setting = MPU9150_PWR_WAKEUP;
|
||||
pwr_2_setting &= ~(MPU9150_PWR_ACCEL);
|
||||
if (pwr_conf == MPU9X50_SENSOR_PWR_ON) {
|
||||
pwr_1_setting = MPU9X50_PWR_WAKEUP;
|
||||
pwr_2_setting &= ~(MPU9X50_PWR_ACCEL);
|
||||
}
|
||||
else {
|
||||
pwr_1_setting = BIT_PWR_MGMT1_SLEEP;
|
||||
pwr_2_setting |= MPU9150_PWR_ACCEL;
|
||||
pwr_2_setting |= MPU9X50_PWR_ACCEL;
|
||||
}
|
||||
/* Configure power management 1 register if needed */
|
||||
if ((dev->conf.gyro_pwr == MPU9150_SENSOR_PWR_OFF)
|
||||
&& (dev->conf.compass_pwr == MPU9150_SENSOR_PWR_OFF)) {
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_PWR_MGMT_1_REG, pwr_1_setting, 0);
|
||||
if ((dev->conf.gyro_pwr == MPU9X50_SENSOR_PWR_OFF)
|
||||
&& (dev->conf.compass_pwr == MPU9X50_SENSOR_PWR_OFF)) {
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_1_REG, pwr_1_setting, 0);
|
||||
}
|
||||
/* Enable/disable accelerometer standby in power management 2 register */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_PWR_MGMT_2_REG, pwr_2_setting, 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_2_REG, pwr_2_setting, 0);
|
||||
|
||||
/* Release the bus */
|
||||
i2c_release(DEV_I2C);
|
||||
|
||||
dev->conf.accel_pwr = pwr_conf;
|
||||
xtimer_usleep(MPU9150_PWR_CHANGE_SLEEP_US);
|
||||
xtimer_usleep(MPU9X50_PWR_CHANGE_SLEEP_US);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mpu9150_set_gyro_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf)
|
||||
int mpu9x50_set_gyro_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf)
|
||||
{
|
||||
uint8_t pwr_2_setting;
|
||||
|
||||
@ -159,41 +161,41 @@ int mpu9150_set_gyro_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf)
|
||||
}
|
||||
|
||||
/* Read current power management 2 configuration */
|
||||
i2c_read_reg(DEV_I2C, DEV_ADDR, MPU9150_PWR_MGMT_2_REG, &pwr_2_setting, 0);
|
||||
i2c_read_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_2_REG, &pwr_2_setting, 0);
|
||||
/* Prepare power register settings */
|
||||
if (pwr_conf == MPU9150_SENSOR_PWR_ON) {
|
||||
if (pwr_conf == MPU9X50_SENSOR_PWR_ON) {
|
||||
/* Set clock to pll */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_PLL, 0);
|
||||
pwr_2_setting &= ~(MPU9150_PWR_GYRO);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_1_REG, MPU9X50_PWR_PLL, 0);
|
||||
pwr_2_setting &= ~(MPU9X50_PWR_GYRO);
|
||||
}
|
||||
else {
|
||||
/* Configure power management 1 register */
|
||||
if ((dev->conf.accel_pwr == MPU9150_SENSOR_PWR_OFF)
|
||||
&& (dev->conf.compass_pwr == MPU9150_SENSOR_PWR_OFF)) {
|
||||
/* All sensors turned off, put the MPU-9150 to sleep */
|
||||
if ((dev->conf.accel_pwr == MPU9X50_SENSOR_PWR_OFF)
|
||||
&& (dev->conf.compass_pwr == MPU9X50_SENSOR_PWR_OFF)) {
|
||||
/* All sensors turned off, put the MPU-9X50 to sleep */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR,
|
||||
MPU9150_PWR_MGMT_1_REG, BIT_PWR_MGMT1_SLEEP, 0);
|
||||
MPU9X50_PWR_MGMT_1_REG, BIT_PWR_MGMT1_SLEEP, 0);
|
||||
}
|
||||
else {
|
||||
/* Reset clock to internal oscillator */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR,
|
||||
MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_WAKEUP, 0);
|
||||
MPU9X50_PWR_MGMT_1_REG, MPU9X50_PWR_WAKEUP, 0);
|
||||
}
|
||||
pwr_2_setting |= MPU9150_PWR_GYRO;
|
||||
pwr_2_setting |= MPU9X50_PWR_GYRO;
|
||||
}
|
||||
/* Enable/disable gyroscope standby in power management 2 register */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_PWR_MGMT_2_REG, pwr_2_setting, 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_2_REG, pwr_2_setting, 0);
|
||||
|
||||
/* Release the bus */
|
||||
i2c_release(DEV_I2C);
|
||||
|
||||
dev->conf.gyro_pwr = pwr_conf;
|
||||
xtimer_usleep(MPU9150_PWR_CHANGE_SLEEP_US);
|
||||
xtimer_usleep(MPU9X50_PWR_CHANGE_SLEEP_US);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mpu9150_set_compass_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf)
|
||||
int mpu9x50_set_compass_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf)
|
||||
{
|
||||
uint8_t pwr_1_setting, usr_ctrl_setting, s1_do_setting;
|
||||
|
||||
@ -207,54 +209,54 @@ int mpu9150_set_compass_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf)
|
||||
}
|
||||
|
||||
/* Read current user control configuration */
|
||||
i2c_read_reg(DEV_I2C, DEV_ADDR, MPU9150_USER_CTRL_REG, &usr_ctrl_setting, 0);
|
||||
i2c_read_reg(DEV_I2C, DEV_ADDR, MPU9X50_USER_CTRL_REG, &usr_ctrl_setting, 0);
|
||||
/* Prepare power register settings */
|
||||
if (pwr_conf == MPU9150_SENSOR_PWR_ON) {
|
||||
pwr_1_setting = MPU9150_PWR_WAKEUP;
|
||||
s1_do_setting = MPU9150_COMP_SINGLE_MEASURE;
|
||||
if (pwr_conf == MPU9X50_SENSOR_PWR_ON) {
|
||||
pwr_1_setting = MPU9X50_PWR_WAKEUP;
|
||||
s1_do_setting = MPU9X50_COMP_SINGLE_MEASURE;
|
||||
usr_ctrl_setting |= BIT_I2C_MST_EN;
|
||||
}
|
||||
else {
|
||||
pwr_1_setting = BIT_PWR_MGMT1_SLEEP;
|
||||
s1_do_setting = MPU9150_COMP_POWER_DOWN;
|
||||
s1_do_setting = MPU9X50_COMP_POWER_DOWN;
|
||||
usr_ctrl_setting &= ~(BIT_I2C_MST_EN);
|
||||
}
|
||||
/* Configure power management 1 register if needed */
|
||||
if ((dev->conf.gyro_pwr == MPU9150_SENSOR_PWR_OFF)
|
||||
&& (dev->conf.accel_pwr == MPU9150_SENSOR_PWR_OFF)) {
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_PWR_MGMT_1_REG, pwr_1_setting, 0);
|
||||
if ((dev->conf.gyro_pwr == MPU9X50_SENSOR_PWR_OFF)
|
||||
&& (dev->conf.accel_pwr == MPU9X50_SENSOR_PWR_OFF)) {
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_1_REG, pwr_1_setting, 0);
|
||||
}
|
||||
/* Configure mode writing by slave line 1 */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_SLAVE1_DATA_OUT_REG, s1_do_setting, 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_SLAVE1_DATA_OUT_REG, s1_do_setting, 0);
|
||||
/* Enable/disable I2C master mode */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_USER_CTRL_REG, usr_ctrl_setting, 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_USER_CTRL_REG, usr_ctrl_setting, 0);
|
||||
|
||||
/* Release the bus */
|
||||
i2c_release(DEV_I2C);
|
||||
|
||||
dev->conf.compass_pwr = pwr_conf;
|
||||
xtimer_usleep(MPU9150_PWR_CHANGE_SLEEP_US);
|
||||
xtimer_usleep(MPU9X50_PWR_CHANGE_SLEEP_US);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mpu9150_read_gyro(const mpu9150_t *dev, mpu9150_results_t *output)
|
||||
int mpu9x50_read_gyro(const mpu9x50_t *dev, mpu9x50_results_t *output)
|
||||
{
|
||||
uint8_t data[6];
|
||||
int16_t temp;
|
||||
float fsr;
|
||||
|
||||
switch (dev->conf.gyro_fsr) {
|
||||
case MPU9150_GYRO_FSR_250DPS:
|
||||
case MPU9X50_GYRO_FSR_250DPS:
|
||||
fsr = 250.0;
|
||||
break;
|
||||
case MPU9150_GYRO_FSR_500DPS:
|
||||
case MPU9X50_GYRO_FSR_500DPS:
|
||||
fsr = 500.0;
|
||||
break;
|
||||
case MPU9150_GYRO_FSR_1000DPS:
|
||||
case MPU9X50_GYRO_FSR_1000DPS:
|
||||
fsr = 1000.0;
|
||||
break;
|
||||
case MPU9150_GYRO_FSR_2000DPS:
|
||||
case MPU9X50_GYRO_FSR_2000DPS:
|
||||
fsr = 2000.0;
|
||||
break;
|
||||
default:
|
||||
@ -266,7 +268,7 @@ int mpu9150_read_gyro(const mpu9150_t *dev, mpu9150_results_t *output)
|
||||
return -1;
|
||||
}
|
||||
/* Read raw data */
|
||||
i2c_read_regs(DEV_I2C, DEV_ADDR, MPU9150_GYRO_START_REG, data, 6, 0);
|
||||
i2c_read_regs(DEV_I2C, DEV_ADDR, MPU9X50_GYRO_START_REG, data, 6, 0);
|
||||
/* Release the bus */
|
||||
i2c_release(DEV_I2C);
|
||||
|
||||
@ -281,23 +283,23 @@ int mpu9150_read_gyro(const mpu9150_t *dev, mpu9150_results_t *output)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mpu9150_read_accel(const mpu9150_t *dev, mpu9150_results_t *output)
|
||||
int mpu9x50_read_accel(const mpu9x50_t *dev, mpu9x50_results_t *output)
|
||||
{
|
||||
uint8_t data[6];
|
||||
int16_t temp;
|
||||
float fsr;
|
||||
|
||||
switch (dev->conf.accel_fsr) {
|
||||
case MPU9150_ACCEL_FSR_2G:
|
||||
case MPU9X50_ACCEL_FSR_2G:
|
||||
fsr = 2000.0;
|
||||
break;
|
||||
case MPU9150_ACCEL_FSR_4G:
|
||||
case MPU9X50_ACCEL_FSR_4G:
|
||||
fsr = 4000.0;
|
||||
break;
|
||||
case MPU9150_ACCEL_FSR_8G:
|
||||
case MPU9X50_ACCEL_FSR_8G:
|
||||
fsr = 8000.0;
|
||||
break;
|
||||
case MPU9150_ACCEL_FSR_16G:
|
||||
case MPU9X50_ACCEL_FSR_16G:
|
||||
fsr = 16000.0;
|
||||
break;
|
||||
default:
|
||||
@ -309,7 +311,7 @@ int mpu9150_read_accel(const mpu9150_t *dev, mpu9150_results_t *output)
|
||||
return -1;
|
||||
}
|
||||
/* Read raw data */
|
||||
i2c_read_regs(DEV_I2C, DEV_ADDR, MPU9150_ACCEL_START_REG, data, 6, 0);
|
||||
i2c_read_regs(DEV_I2C, DEV_ADDR, MPU9X50_ACCEL_START_REG, data, 6, 0);
|
||||
/* Release the bus */
|
||||
i2c_release(DEV_I2C);
|
||||
|
||||
@ -324,7 +326,7 @@ int mpu9150_read_accel(const mpu9150_t *dev, mpu9150_results_t *output)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mpu9150_read_compass(const mpu9150_t *dev, mpu9150_results_t *output)
|
||||
int mpu9x50_read_compass(const mpu9x50_t *dev, mpu9x50_results_t *output)
|
||||
{
|
||||
uint8_t data[6];
|
||||
|
||||
@ -333,7 +335,7 @@ int mpu9150_read_compass(const mpu9150_t *dev, mpu9150_results_t *output)
|
||||
return -1;
|
||||
}
|
||||
/* Read raw data */
|
||||
i2c_read_regs(DEV_I2C, DEV_ADDR, MPU9150_EXT_SENS_DATA_START_REG, data, 6, 0);
|
||||
i2c_read_regs(DEV_I2C, DEV_ADDR, MPU9X50_EXT_SENS_DATA_START_REG, data, 6, 0);
|
||||
/* Release the bus */
|
||||
i2c_release(DEV_I2C);
|
||||
|
||||
@ -357,7 +359,7 @@ int mpu9150_read_compass(const mpu9150_t *dev, mpu9150_results_t *output)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mpu9150_read_temperature(const mpu9150_t *dev, int32_t *output)
|
||||
int mpu9x50_read_temperature(const mpu9x50_t *dev, int32_t *output)
|
||||
{
|
||||
uint8_t data[2];
|
||||
int16_t temp;
|
||||
@ -367,7 +369,7 @@ int mpu9150_read_temperature(const mpu9150_t *dev, int32_t *output)
|
||||
return -1;
|
||||
}
|
||||
/* Read raw temperature value */
|
||||
i2c_read_regs(DEV_I2C, DEV_ADDR, MPU9150_TEMP_START_REG, data, 2, 0);
|
||||
i2c_read_regs(DEV_I2C, DEV_ADDR, MPU9X50_TEMP_START_REG, data, 2, 0);
|
||||
/* Release the bus */
|
||||
i2c_release(DEV_I2C);
|
||||
|
||||
@ -377,22 +379,22 @@ int mpu9150_read_temperature(const mpu9150_t *dev, int32_t *output)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mpu9150_set_gyro_fsr(mpu9150_t *dev, mpu9150_gyro_ranges_t fsr)
|
||||
int mpu9x50_set_gyro_fsr(mpu9x50_t *dev, mpu9x50_gyro_ranges_t fsr)
|
||||
{
|
||||
if (dev->conf.gyro_fsr == fsr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (fsr) {
|
||||
case MPU9150_GYRO_FSR_250DPS:
|
||||
case MPU9150_GYRO_FSR_500DPS:
|
||||
case MPU9150_GYRO_FSR_1000DPS:
|
||||
case MPU9150_GYRO_FSR_2000DPS:
|
||||
case MPU9X50_GYRO_FSR_250DPS:
|
||||
case MPU9X50_GYRO_FSR_500DPS:
|
||||
case MPU9X50_GYRO_FSR_1000DPS:
|
||||
case MPU9X50_GYRO_FSR_2000DPS:
|
||||
if (i2c_acquire(DEV_I2C)) {
|
||||
return -1;
|
||||
}
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR,
|
||||
MPU9150_GYRO_CFG_REG, (fsr << 3), 0);
|
||||
MPU9X50_GYRO_CFG_REG, (fsr << 3), 0);
|
||||
i2c_release(DEV_I2C);
|
||||
dev->conf.gyro_fsr = fsr;
|
||||
break;
|
||||
@ -403,22 +405,22 @@ int mpu9150_set_gyro_fsr(mpu9150_t *dev, mpu9150_gyro_ranges_t fsr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mpu9150_set_accel_fsr(mpu9150_t *dev, mpu9150_accel_ranges_t fsr)
|
||||
int mpu9x50_set_accel_fsr(mpu9x50_t *dev, mpu9x50_accel_ranges_t fsr)
|
||||
{
|
||||
if (dev->conf.accel_fsr == fsr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (fsr) {
|
||||
case MPU9150_ACCEL_FSR_2G:
|
||||
case MPU9150_ACCEL_FSR_4G:
|
||||
case MPU9150_ACCEL_FSR_8G:
|
||||
case MPU9150_ACCEL_FSR_16G:
|
||||
case MPU9X50_ACCEL_FSR_2G:
|
||||
case MPU9X50_ACCEL_FSR_4G:
|
||||
case MPU9X50_ACCEL_FSR_8G:
|
||||
case MPU9X50_ACCEL_FSR_16G:
|
||||
if (i2c_acquire(DEV_I2C)) {
|
||||
return -1;
|
||||
}
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR,
|
||||
MPU9150_ACCEL_CFG_REG, (fsr << 3), 0);
|
||||
MPU9X50_ACCEL_CFG_REG, (fsr << 3), 0);
|
||||
i2c_release(DEV_I2C);
|
||||
dev->conf.accel_fsr = fsr;
|
||||
break;
|
||||
@ -429,11 +431,11 @@ int mpu9150_set_accel_fsr(mpu9150_t *dev, mpu9150_accel_ranges_t fsr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mpu9150_set_sample_rate(mpu9150_t *dev, uint16_t rate)
|
||||
int mpu9x50_set_sample_rate(mpu9x50_t *dev, uint16_t rate)
|
||||
{
|
||||
uint8_t divider;
|
||||
|
||||
if ((rate < MPU9150_MIN_SAMPLE_RATE) || (rate > MPU9150_MAX_SAMPLE_RATE)) {
|
||||
if ((rate < MPU9X50_MIN_SAMPLE_RATE) || (rate > MPU9X50_MAX_SAMPLE_RATE)) {
|
||||
return -2;
|
||||
}
|
||||
else if (dev->conf.sample_rate == rate) {
|
||||
@ -446,7 +448,7 @@ int mpu9150_set_sample_rate(mpu9150_t *dev, uint16_t rate)
|
||||
if (i2c_acquire(DEV_I2C)) {
|
||||
return -1;
|
||||
}
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_RATE_DIV_REG, divider, 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_RATE_DIV_REG, divider, 0);
|
||||
|
||||
/* Store configured sample rate */
|
||||
dev->conf.sample_rate = 1000 / (((uint16_t) divider) + 1);
|
||||
@ -458,11 +460,11 @@ int mpu9150_set_sample_rate(mpu9150_t *dev, uint16_t rate)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mpu9150_set_compass_sample_rate(mpu9150_t *dev, uint8_t rate)
|
||||
int mpu9x50_set_compass_sample_rate(mpu9x50_t *dev, uint8_t rate)
|
||||
{
|
||||
uint8_t divider;
|
||||
|
||||
if ((rate < MPU9150_MIN_COMP_SMPL_RATE) || (rate > MPU9150_MAX_COMP_SMPL_RATE)
|
||||
if ((rate < MPU9X50_MIN_COMP_SMPL_RATE) || (rate > MPU9X50_MAX_COMP_SMPL_RATE)
|
||||
|| (rate > dev->conf.sample_rate)) {
|
||||
return -2;
|
||||
}
|
||||
@ -476,7 +478,7 @@ int mpu9150_set_compass_sample_rate(mpu9150_t *dev, uint8_t rate)
|
||||
if (i2c_acquire(DEV_I2C)) {
|
||||
return -1;
|
||||
}
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_SLAVE4_CTRL_REG, divider, 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_SLAVE4_CTRL_REG, divider, 0);
|
||||
i2c_release(DEV_I2C);
|
||||
|
||||
/* Store configured sample rate */
|
||||
@ -494,7 +496,7 @@ int mpu9150_set_compass_sample_rate(mpu9150_t *dev, uint8_t rate)
|
||||
* Caution: This internal function does not acquire exclusive access to the I2C bus.
|
||||
* Acquisation and release is supposed to be handled by the calling function.
|
||||
*/
|
||||
static int compass_init(mpu9150_t *dev)
|
||||
static int compass_init(mpu9x50_t *dev)
|
||||
{
|
||||
uint8_t data[3];
|
||||
|
||||
@ -509,51 +511,51 @@ static int compass_init(mpu9150_t *dev)
|
||||
}
|
||||
|
||||
/* Configure Power Down mode */
|
||||
i2c_write_reg(DEV_I2C, DEV_COMP_ADDR, COMPASS_CNTL_REG, MPU9150_COMP_POWER_DOWN, 0);
|
||||
xtimer_usleep(MPU9150_COMP_MODE_SLEEP_US);
|
||||
i2c_write_reg(DEV_I2C, DEV_COMP_ADDR, COMPASS_CNTL_REG, MPU9X50_COMP_POWER_DOWN, 0);
|
||||
xtimer_usleep(MPU9X50_COMP_MODE_SLEEP_US);
|
||||
/* Configure Fuse ROM access */
|
||||
i2c_write_reg(DEV_I2C, DEV_COMP_ADDR, COMPASS_CNTL_REG, MPU9150_COMP_FUSE_ROM, 0);
|
||||
xtimer_usleep(MPU9150_COMP_MODE_SLEEP_US);
|
||||
i2c_write_reg(DEV_I2C, DEV_COMP_ADDR, COMPASS_CNTL_REG, MPU9X50_COMP_FUSE_ROM, 0);
|
||||
xtimer_usleep(MPU9X50_COMP_MODE_SLEEP_US);
|
||||
/* Read sensitivity adjustment values from Fuse ROM */
|
||||
i2c_read_regs(DEV_I2C, DEV_COMP_ADDR, COMPASS_ASAX_REG, data, 3, 0);
|
||||
dev->conf.compass_x_adj = data[0];
|
||||
dev->conf.compass_y_adj = data[1];
|
||||
dev->conf.compass_z_adj = data[2];
|
||||
/* Configure Power Down mode again */
|
||||
i2c_write_reg(DEV_I2C, DEV_COMP_ADDR, COMPASS_CNTL_REG, MPU9150_COMP_POWER_DOWN, 0);
|
||||
xtimer_usleep(MPU9150_COMP_MODE_SLEEP_US);
|
||||
i2c_write_reg(DEV_I2C, DEV_COMP_ADDR, COMPASS_CNTL_REG, MPU9X50_COMP_POWER_DOWN, 0);
|
||||
xtimer_usleep(MPU9X50_COMP_MODE_SLEEP_US);
|
||||
|
||||
/* Disable Bypass Mode to configure MPU as master to the compass */
|
||||
conf_bypass(dev, 0);
|
||||
|
||||
/* Configure MPU9150 for single master mode */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_I2C_MST_REG, BIT_WAIT_FOR_ES, 0);
|
||||
/* Configure MPU9X50 for single master mode */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_I2C_MST_REG, BIT_WAIT_FOR_ES, 0);
|
||||
|
||||
/* Set up slave line 0 */
|
||||
/* Slave line 0 reads the compass data */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR,
|
||||
MPU9150_SLAVE0_ADDR_REG, (BIT_SLAVE_RW | DEV_COMP_ADDR), 0);
|
||||
MPU9X50_SLAVE0_ADDR_REG, (BIT_SLAVE_RW | DEV_COMP_ADDR), 0);
|
||||
/* Slave line 0 read starts at compass data register */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_SLAVE0_REG_REG, COMPASS_DATA_START_REG, 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_SLAVE0_REG_REG, COMPASS_DATA_START_REG, 0);
|
||||
/* Enable slave line 0 and configure read length to 6 consecutive registers */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_SLAVE0_CTRL_REG, (BIT_SLAVE_EN | 0x06), 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_SLAVE0_CTRL_REG, (BIT_SLAVE_EN | 0x06), 0);
|
||||
|
||||
/* Set up slave line 1 */
|
||||
/* Slave line 1 writes to the compass */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_SLAVE1_ADDR_REG, DEV_COMP_ADDR, 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_SLAVE1_ADDR_REG, DEV_COMP_ADDR, 0);
|
||||
/* Slave line 1 write starts at compass control register */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_SLAVE1_REG_REG, COMPASS_CNTL_REG, 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_SLAVE1_REG_REG, COMPASS_CNTL_REG, 0);
|
||||
/* Enable slave line 1 and configure write length to 1 register */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_SLAVE1_CTRL_REG, (BIT_SLAVE_EN | 0x01), 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_SLAVE1_CTRL_REG, (BIT_SLAVE_EN | 0x01), 0);
|
||||
/* Configure data which is written by slave line 1 to compass control */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR,
|
||||
MPU9150_SLAVE1_DATA_OUT_REG, MPU9150_COMP_SINGLE_MEASURE, 0);
|
||||
MPU9X50_SLAVE1_DATA_OUT_REG, MPU9X50_COMP_SINGLE_MEASURE, 0);
|
||||
|
||||
/* Slave line 0 and 1 operate at each sample */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR,
|
||||
MPU9150_I2C_DELAY_CTRL_REG, (BIT_SLV0_DELAY_EN | BIT_SLV1_DELAY_EN), 0);
|
||||
MPU9X50_I2C_DELAY_CTRL_REG, (BIT_SLV0_DELAY_EN | BIT_SLV1_DELAY_EN), 0);
|
||||
/* Set I2C bus to VDD */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_YG_OFFS_TC_REG, BIT_I2C_MST_VDDIO, 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_YG_OFFS_TC_REG, BIT_I2C_MST_VDDIO, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -563,22 +565,22 @@ static int compass_init(mpu9150_t *dev)
|
||||
* Caution: This internal function does not acquire exclusive access to the I2C bus.
|
||||
* Acquisation and release is supposed to be handled by the calling function.
|
||||
*/
|
||||
static void conf_bypass(const mpu9150_t *dev, uint8_t bypass_enable)
|
||||
static void conf_bypass(const mpu9x50_t *dev, uint8_t bypass_enable)
|
||||
{
|
||||
uint8_t data;
|
||||
i2c_read_reg(DEV_I2C, DEV_ADDR, MPU9150_USER_CTRL_REG, &data, 0);
|
||||
i2c_read_reg(DEV_I2C, DEV_ADDR, MPU9X50_USER_CTRL_REG, &data, 0);
|
||||
|
||||
if (bypass_enable) {
|
||||
data &= ~(BIT_I2C_MST_EN);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_USER_CTRL_REG, data, 0);
|
||||
xtimer_usleep(MPU9150_BYPASS_SLEEP_US);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_INT_PIN_CFG_REG, BIT_I2C_BYPASS_EN, 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_USER_CTRL_REG, data, 0);
|
||||
xtimer_usleep(MPU9X50_BYPASS_SLEEP_US);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_INT_PIN_CFG_REG, BIT_I2C_BYPASS_EN, 0);
|
||||
}
|
||||
else {
|
||||
data |= BIT_I2C_MST_EN;
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_USER_CTRL_REG, data, 0);
|
||||
xtimer_usleep(MPU9150_BYPASS_SLEEP_US);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_INT_PIN_CFG_REG, REG_RESET, 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_USER_CTRL_REG, data, 0);
|
||||
xtimer_usleep(MPU9X50_BYPASS_SLEEP_US);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_INT_PIN_CFG_REG, REG_RESET, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -587,30 +589,30 @@ static void conf_bypass(const mpu9150_t *dev, uint8_t bypass_enable)
|
||||
* Caution: This internal function does not acquire exclusive access to the I2C bus.
|
||||
* Acquisation and release is supposed to be handled by the calling function.
|
||||
*/
|
||||
static void conf_lpf(const mpu9150_t *dev, uint16_t half_rate)
|
||||
static void conf_lpf(const mpu9x50_t *dev, uint16_t half_rate)
|
||||
{
|
||||
mpu9150_lpf_t lpf_setting;
|
||||
mpu9x50_lpf_t lpf_setting;
|
||||
|
||||
/* Get target LPF configuration setting */
|
||||
if (half_rate >= 188) {
|
||||
lpf_setting = MPU9150_FILTER_188HZ;
|
||||
lpf_setting = MPU9X50_FILTER_188HZ;
|
||||
}
|
||||
else if (half_rate >= 98) {
|
||||
lpf_setting = MPU9150_FILTER_98HZ;
|
||||
lpf_setting = MPU9X50_FILTER_98HZ;
|
||||
}
|
||||
else if (half_rate >= 42) {
|
||||
lpf_setting = MPU9150_FILTER_42HZ;
|
||||
lpf_setting = MPU9X50_FILTER_42HZ;
|
||||
}
|
||||
else if (half_rate >= 20) {
|
||||
lpf_setting = MPU9150_FILTER_20HZ;
|
||||
lpf_setting = MPU9X50_FILTER_20HZ;
|
||||
}
|
||||
else if (half_rate >= 10) {
|
||||
lpf_setting = MPU9150_FILTER_10HZ;
|
||||
lpf_setting = MPU9X50_FILTER_10HZ;
|
||||
}
|
||||
else {
|
||||
lpf_setting = MPU9150_FILTER_5HZ;
|
||||
lpf_setting = MPU9X50_FILTER_5HZ;
|
||||
}
|
||||
|
||||
/* Write LPF setting to configuration register */
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9150_LPF_REG, lpf_setting, 0);
|
||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_LPF_REG, lpf_setting, 0);
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Inria
|
||||
* 2019 HAW Hamburg
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
@ -7,13 +8,14 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup drivers_mpu9150
|
||||
* @ingroup drivers_mpu9x50
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief MPU9150 adaption to the RIOT actuator/sensor interface
|
||||
* @brief MPU9X50 adaption to the RIOT actuator/sensor interface
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
* @author Jannes Volkens <jannes.volkens@haw-hamburg.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
@ -21,11 +23,11 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "saul.h"
|
||||
#include "mpu9150.h"
|
||||
#include "mpu9x50.h"
|
||||
|
||||
static int read_acc(const void *dev, phydat_t *res)
|
||||
{
|
||||
int ret = mpu9150_read_accel((const mpu9150_t *)dev, (mpu9150_results_t *)res->val);
|
||||
int ret = mpu9x50_read_accel((const mpu9x50_t *)dev, (mpu9x50_results_t *)res->val);
|
||||
if (ret < 0) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
@ -38,7 +40,7 @@ static int read_acc(const void *dev, phydat_t *res)
|
||||
|
||||
static int read_gyro(const void *dev, phydat_t *res)
|
||||
{
|
||||
int ret = mpu9150_read_gyro((const mpu9150_t *)dev, (mpu9150_results_t *)res->val);
|
||||
int ret = mpu9x50_read_gyro((const mpu9x50_t *)dev, (mpu9x50_results_t *)res->val);
|
||||
if (ret < 0) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
@ -51,7 +53,7 @@ static int read_gyro(const void *dev, phydat_t *res)
|
||||
|
||||
static int read_mag(const void *dev, phydat_t *res)
|
||||
{
|
||||
int ret = mpu9150_read_compass((const mpu9150_t *)dev, (mpu9150_results_t *)res->val);
|
||||
int ret = mpu9x50_read_compass((const mpu9x50_t *)dev, (mpu9x50_results_t *)res->val);
|
||||
if (ret < 0) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
@ -62,19 +64,19 @@ static int read_mag(const void *dev, phydat_t *res)
|
||||
return 3;
|
||||
}
|
||||
|
||||
const saul_driver_t mpu9150_saul_acc_driver = {
|
||||
const saul_driver_t mpu9x50_saul_acc_driver = {
|
||||
.read = read_acc,
|
||||
.write = saul_notsup,
|
||||
.type = SAUL_SENSE_ACCEL,
|
||||
};
|
||||
|
||||
const saul_driver_t mpu9150_saul_gyro_driver = {
|
||||
const saul_driver_t mpu9x50_saul_gyro_driver = {
|
||||
.read = read_gyro,
|
||||
.write = saul_notsup,
|
||||
.type = SAUL_SENSE_GYRO,
|
||||
};
|
||||
|
||||
const saul_driver_t mpu9150_saul_mag_driver = {
|
||||
const saul_driver_t mpu9x50_saul_mag_driver = {
|
||||
.read = read_mag,
|
||||
.write = saul_notsup,
|
||||
.type = SAUL_SENSE_MAG,
|
@ -112,6 +112,10 @@ PSEUDOMODULES += cc1100
|
||||
PSEUDOMODULES += cc1100e
|
||||
PSEUDOMODULES += cc1101
|
||||
|
||||
# include variants of MPU9X50 drivers as pseudo modules
|
||||
PSEUDOMODULES += mpu9150
|
||||
PSEUDOMODULES += mpu9250
|
||||
|
||||
# include variants of mrf24j40 drivers as pseudo modules
|
||||
PSEUDOMODULES += mrf24j40m%
|
||||
|
||||
|
@ -482,9 +482,9 @@ void auto_init(void)
|
||||
extern void auto_init_mpl3115a2(void);
|
||||
auto_init_mpl3115a2();
|
||||
#endif
|
||||
#ifdef MODULE_MPU9150
|
||||
extern void auto_init_mpu9150(void);
|
||||
auto_init_mpu9150();
|
||||
#ifdef MODULE_MPU9X50
|
||||
extern void auto_init_mpu9x50(void);
|
||||
auto_init_mpu9x50();
|
||||
#endif
|
||||
#ifdef MODULE_OPT3001
|
||||
extern void auto_init_opt3001(void);
|
||||
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* @ingroup sys_auto_init_saul
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Auto initialization of MPU9150 accelerometer/magnetometer
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef MODULE_MPU9150
|
||||
|
||||
#include "assert.h"
|
||||
#include "log.h"
|
||||
#include "saul_reg.h"
|
||||
#include "mpu9150.h"
|
||||
#include "mpu9150_params.h"
|
||||
|
||||
/**
|
||||
* @brief Define the number of configured sensors
|
||||
*/
|
||||
#define MPU9150_NUM ARRAY_SIZE(mpu9150_params)
|
||||
|
||||
/**
|
||||
* @brief Allocate memory for the device descriptors
|
||||
*/
|
||||
static mpu9150_t mpu9150_devs[MPU9150_NUM];
|
||||
|
||||
/**
|
||||
* @brief Memory for the SAUL registry entries
|
||||
*/
|
||||
static saul_reg_t saul_entries[MPU9150_NUM * 3];
|
||||
|
||||
/**
|
||||
* @brief Define the number of saul info
|
||||
*/
|
||||
#define MPU9150_INFO_NUM ARRAY_SIZE(mpu9150_saul_info)
|
||||
|
||||
/**
|
||||
* @name Reference the driver structs
|
||||
* @{
|
||||
*/
|
||||
extern saul_driver_t mpu9150_saul_acc_driver;
|
||||
extern saul_driver_t mpu9150_saul_gyro_driver;
|
||||
extern saul_driver_t mpu9150_saul_mag_driver;
|
||||
|
||||
/** @} */
|
||||
|
||||
void auto_init_mpu9150(void)
|
||||
{
|
||||
assert(MPU9150_NUM == MPU9150_INFO_NUM);
|
||||
|
||||
for (unsigned int i = 0; i < MPU9150_NUM; i++) {
|
||||
LOG_DEBUG("[auto_init_saul] initializing mpu9150 #%u\n", i);
|
||||
|
||||
if (mpu9150_init(&mpu9150_devs[i], &mpu9150_params[i]) < 0) {
|
||||
LOG_ERROR("[auto_init_saul] error initializing mpu9150 #%u\n", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
saul_entries[(i * 3)].dev = &(mpu9150_devs[i]);
|
||||
saul_entries[(i * 3)].name = mpu9150_saul_info[i].name;
|
||||
saul_entries[(i * 3)].driver = &mpu9150_saul_acc_driver;
|
||||
saul_entries[(i * 3) + 1].dev = &(mpu9150_devs[i]);
|
||||
saul_entries[(i * 3) + 1].name = mpu9150_saul_info[i].name;
|
||||
saul_entries[(i * 3) + 1].driver = &mpu9150_saul_gyro_driver;
|
||||
saul_entries[(i * 3) + 2].dev = &(mpu9150_devs[i]);
|
||||
saul_entries[(i * 3) + 2].name = mpu9150_saul_info[i].name;
|
||||
saul_entries[(i * 3) + 2].driver = &mpu9150_saul_mag_driver;
|
||||
saul_reg_add(&(saul_entries[(i * 3)]));
|
||||
saul_reg_add(&(saul_entries[(i * 3) + 1]));
|
||||
saul_reg_add(&(saul_entries[(i * 3) + 2]));
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
typedef int dont_be_pedantic;
|
||||
#endif /* MODULE_MPU9150 */
|
89
sys/auto_init/saul/auto_init_mpu9x50.c
Normal file
89
sys/auto_init/saul/auto_init_mpu9x50.c
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* @ingroup sys_auto_init_saul
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Auto initialization of MPU9X50 (MPU9150 and MPU9250) accelerometer/magnetometer
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef MODULE_MPU9X50
|
||||
|
||||
#include "assert.h"
|
||||
#include "log.h"
|
||||
#include "saul_reg.h"
|
||||
#include "mpu9x50.h"
|
||||
#include "mpu9x50_params.h"
|
||||
|
||||
/**
|
||||
* @brief Define the number of configured sensors
|
||||
*/
|
||||
#define MPU9X50_NUM ARRAY_SIZE(mpu9x50_params)
|
||||
|
||||
/**
|
||||
* @brief Allocate memory for the device descriptors
|
||||
*/
|
||||
static mpu9x50_t mpu9x50_devs[MPU9X50_NUM];
|
||||
|
||||
/**
|
||||
* @brief Memory for the SAUL registry entries
|
||||
*/
|
||||
static saul_reg_t saul_entries[MPU9X50_NUM * 3];
|
||||
|
||||
/**
|
||||
* @brief Define the number of saul info
|
||||
*/
|
||||
#define MPU9X50_INFO_NUM ARRAY_SIZE(mpu9x50_saul_info)
|
||||
|
||||
/**
|
||||
* @name Reference the driver structs
|
||||
* @{
|
||||
*/
|
||||
extern saul_driver_t mpu9x50_saul_acc_driver;
|
||||
extern saul_driver_t mpu9x50_saul_gyro_driver;
|
||||
extern saul_driver_t mpu9x50_saul_mag_driver;
|
||||
|
||||
/** @} */
|
||||
|
||||
void auto_init_mpu9x50(void)
|
||||
{
|
||||
assert(MPU9X50_NUM == MPU9X50_INFO_NUM);
|
||||
|
||||
for (unsigned int i = 0; i < MPU9X50_NUM; i++) {
|
||||
LOG_DEBUG("[auto_init_saul] initializing mpu9x50 #%u\n", i);
|
||||
|
||||
if (mpu9x50_init(&mpu9x50_devs[i], &mpu9x50_params[i]) < 0) {
|
||||
LOG_ERROR("[auto_init_saul] error initializing mpu9x50 #%u\n", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
saul_entries[(i * 3)].dev = &(mpu9x50_devs[i]);
|
||||
saul_entries[(i * 3)].name = mpu9x50_saul_info[i].name;
|
||||
saul_entries[(i * 3)].driver = &mpu9x50_saul_acc_driver;
|
||||
saul_entries[(i * 3) + 1].dev = &(mpu9x50_devs[i]);
|
||||
saul_entries[(i * 3) + 1].name = mpu9x50_saul_info[i].name;
|
||||
saul_entries[(i * 3) + 1].driver = &mpu9x50_saul_gyro_driver;
|
||||
saul_entries[(i * 3) + 2].dev = &(mpu9x50_devs[i]);
|
||||
saul_entries[(i * 3) + 2].name = mpu9x50_saul_info[i].name;
|
||||
saul_entries[(i * 3) + 2].driver = &mpu9x50_saul_mag_driver;
|
||||
saul_reg_add(&(saul_entries[(i * 3)]));
|
||||
saul_reg_add(&(saul_entries[(i * 3) + 1]));
|
||||
saul_reg_add(&(saul_entries[(i * 3) + 2]));
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
typedef int dont_be_pedantic;
|
||||
#endif /* MODULE_MPU9X50 */
|
@ -2,8 +2,9 @@ include ../Makefile.tests_common
|
||||
|
||||
BOARD_INSUFFICIENT_MEMORY := arduino-duemilanove arduino-leonardo arduino-nano\
|
||||
arduino-uno
|
||||
DRIVER ?= mpu9150
|
||||
|
||||
USEMODULE += mpu9150
|
||||
USEMODULE += $(DRIVER)
|
||||
USEMODULE += xtimer
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
@ -1,8 +1,8 @@
|
||||
# About
|
||||
This is a test application for the MPU-9150 Nine-Axis Driver.
|
||||
This is a test application for the MPU-9X50 (MPU9150 and MPU9250) Nine-Axis Driver.
|
||||
|
||||
# Usage
|
||||
The application will initialize the MPU-9150 motion sensor with the following parameters:
|
||||
The application will initialize the MPU-9X50 (MPU9150 and MPU9250) motion sensor with the following parameters:
|
||||
- Accelerometer: ON
|
||||
- Gyroscope: ON
|
||||
- Magnetometer: ON
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Freie Universität Berlin
|
||||
* 2019 HAW Hamburg
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
@ -11,9 +12,10 @@
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Test application for the MPU-9150 Nine-Axis driver
|
||||
* @brief Test application for the MPU-9X50 (MPU9150 and MPU9250) Nine-Axis driver
|
||||
*
|
||||
* @author Fabian Nack <nack@inf.fu-berlin.de>
|
||||
* @author Jannes Volkens <jannes.volkens@haw-hamburg.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
@ -24,22 +26,22 @@
|
||||
#include "xtimer.h"
|
||||
#include "board.h"
|
||||
|
||||
#include "mpu9150.h"
|
||||
#include "mpu9150_params.h"
|
||||
#include "mpu9x50.h"
|
||||
#include "mpu9x50_params.h"
|
||||
|
||||
#define SLEEP_USEC (1000 * 1000u)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
mpu9150_t dev;
|
||||
mpu9150_results_t measurement;
|
||||
mpu9x50_t dev;
|
||||
mpu9x50_results_t measurement;
|
||||
int32_t temperature;
|
||||
int result;
|
||||
|
||||
puts("MPU-9150 test application\n");
|
||||
puts("MPU-9X50 test application\n");
|
||||
|
||||
printf("+------------Initializing------------+\n");
|
||||
result = mpu9150_init(&dev, &mpu9150_params[0]);
|
||||
result = mpu9x50_init(&dev, &mpu9x50_params[0]);
|
||||
|
||||
if (result == -1) {
|
||||
puts("[Error] The given i2c is not enabled");
|
||||
@ -50,12 +52,12 @@ int main(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
mpu9150_set_sample_rate(&dev, 200);
|
||||
mpu9x50_set_sample_rate(&dev, 200);
|
||||
if (dev.conf.sample_rate != 200) {
|
||||
puts("[Error] The sample rate was not set correctly");
|
||||
return 1;
|
||||
}
|
||||
mpu9150_set_compass_sample_rate(&dev, 100);
|
||||
mpu9x50_set_compass_sample_rate(&dev, 100);
|
||||
if (dev.conf.compass_sample_rate != 100) {
|
||||
puts("[Error] The compass sample rate was not set correctly");
|
||||
return 1;
|
||||
@ -74,19 +76,19 @@ int main(void)
|
||||
printf("\n+--------Starting Measurements--------+\n");
|
||||
while (1) {
|
||||
/* Get accel data in milli g */
|
||||
mpu9150_read_accel(&dev, &measurement);
|
||||
mpu9x50_read_accel(&dev, &measurement);
|
||||
printf("Accel data [milli g] - X: %"PRId16" Y: %"PRId16" Z: %"PRId16"\n",
|
||||
measurement.x_axis, measurement.y_axis, measurement.z_axis);
|
||||
/* Get gyro data in dps */
|
||||
mpu9150_read_gyro(&dev, &measurement);
|
||||
mpu9x50_read_gyro(&dev, &measurement);
|
||||
printf("Gyro data [dps] - X: %"PRId16" Y: %"PRId16" Z: %"PRId16"\n",
|
||||
measurement.x_axis, measurement.y_axis, measurement.z_axis);
|
||||
/* Get compass data in mikro Tesla */
|
||||
mpu9150_read_compass(&dev, &measurement);
|
||||
mpu9x50_read_compass(&dev, &measurement);
|
||||
printf("Compass data [micro T] - X: %"PRId16" Y: %"PRId16" Z: %"PRId16"\n",
|
||||
measurement.x_axis, measurement.y_axis, measurement.z_axis);
|
||||
/* Get temperature in milli degrees celsius */
|
||||
mpu9150_read_temperature(&dev, &temperature);
|
||||
mpu9x50_read_temperature(&dev, &temperature);
|
||||
printf("Temperature [milli deg] : %"PRId32"\n", temperature);
|
||||
printf("\n+-------------------------------------+\n");
|
||||
|
Loading…
Reference in New Issue
Block a user