update credits
[librepilot.git] / flight / pios / inc / pios_mpu6000_config.h
blob96270847a5bef72b82de86d0769fa32b1cf8c931
1 /**
2 ******************************************************************************
3 * @addtogroup PIOS PIOS Core hardware abstraction layer
4 * @{
5 * @addtogroup PIOS_MPU6000 OpenPilot layer configuration utilities
6 * @brief provides mpu6000 configuration helpers function
7 * @{
9 * @file PIOS_MPU6000_CONFIG.h
10 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013.
11 * @brief MPU6000 UAVO-based configuration functions
12 * @see The GNU Public License (GPL) Version 3
14 ******************************************************************************
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 * for more details.
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #ifndef PIOS_MPU6000_CONFIG_H
33 #define PIOS_MPU6000_CONFIG_H
35 #include "mpugyroaccelsettings.h"
36 #include "pios_mpu6000.h"
38 #define PIOS_MPU6000_CONFIG_MAP_GYROSCALE(x) \
39 (x == MPUGYROACCELSETTINGS_GYROSCALE_SCALE_250 ? PIOS_MPU6000_SCALE_250_DEG : \
40 x == MPUGYROACCELSETTINGS_GYROSCALE_SCALE_500 ? PIOS_MPU6000_SCALE_500_DEG : \
41 x == MPUGYROACCELSETTINGS_GYROSCALE_SCALE_1000 ? PIOS_MPU6000_SCALE_1000_DEG : \
42 PIOS_MPU6000_SCALE_2000_DEG)
44 #define PIOS_MPU6000_CONFIG_MAP_ACCELSCALE(x) \
45 (x == MPUGYROACCELSETTINGS_ACCELSCALE_SCALE_2G ? PIOS_MPU6000_ACCEL_2G : \
46 x == MPUGYROACCELSETTINGS_ACCELSCALE_SCALE_4G ? PIOS_MPU6000_ACCEL_4G : \
47 x == MPUGYROACCELSETTINGS_ACCELSCALE_SCALE_16G ? PIOS_MPU6000_ACCEL_16G : \
48 PIOS_MPU6000_ACCEL_8G)
50 #define PIOS_MPU6000_CONFIG_MAP_FILTERSETTING(x) \
51 (x == MPUGYROACCELSETTINGS_FILTERSETTING_LOWPASS_188_HZ ? PIOS_MPU6000_LOWPASS_188_HZ : \
52 x == MPUGYROACCELSETTINGS_FILTERSETTING_LOWPASS_98_HZ ? PIOS_MPU6000_LOWPASS_98_HZ : \
53 x == MPUGYROACCELSETTINGS_FILTERSETTING_LOWPASS_42_HZ ? PIOS_MPU6000_LOWPASS_42_HZ : \
54 x == MPUGYROACCELSETTINGS_FILTERSETTING_LOWPASS_20_HZ ? PIOS_MPU6000_LOWPASS_20_HZ : \
55 x == MPUGYROACCELSETTINGS_FILTERSETTING_LOWPASS_10_HZ ? PIOS_MPU6000_LOWPASS_10_HZ : \
56 x == MPUGYROACCELSETTINGS_FILTERSETTING_LOWPASS_5_HZ ? PIOS_MPU6000_LOWPASS_5_HZ : \
57 PIOS_MPU6000_LOWPASS_256_HZ)
58 /**
59 * @brief Updates MPU6000 config based on Mpu6000Settings UAVO
60 * @returns 0 if succeed or -1 otherwise
62 int32_t PIOS_MPU6000_CONFIG_Configure()
64 MPUGyroAccelSettingsData mpuSettings;
66 MPUGyroAccelSettingsGet(&mpuSettings);
67 return PIOS_MPU6000_ConfigureRanges(
68 PIOS_MPU6000_CONFIG_MAP_GYROSCALE(mpuSettings.GyroScale),
69 PIOS_MPU6000_CONFIG_MAP_ACCELSCALE(mpuSettings.AccelScale),
70 PIOS_MPU6000_CONFIG_MAP_FILTERSETTING(mpuSettings.FilterSetting)
74 #endif /* PIOS_MPU6000_CONFIG_H */