diff options
author | Ash Charles <ashcharles@gmail.com> | 2014-05-14 09:19:30 -0700 |
---|---|---|
committer | Ash Charles <ashcharles@gmail.com> | 2014-05-14 09:19:30 -0700 |
commit | cbc559b6d6285f169e352dde2a205be12aef9ea8 (patch) | |
tree | 047f960ab712ce1351db1f8f85a36700ba1269d7 /src | |
parent | 2d29c5bd72f77d572a8f83480e841051236b3645 (diff) | |
download | px4-firmware-cbc559b6d6285f169e352dde2a205be12aef9ea8.tar.gz px4-firmware-cbc559b6d6285f169e352dde2a205be12aef9ea8.tar.bz2 px4-firmware-cbc559b6d6285f169e352dde2a205be12aef9ea8.zip |
[l3gd20] Make gyro orientation board-overridable
As discussed [1], provide a default SENSOR_BOARD_ROTATION
(270 degrees as this seems most common) and let boards override it
as necessary.
[1] https://github.com/gumstix/m4-firmware/commit/7d0850a710b3ac9e9e165beb36389577d0e5adcb#commitcomment-6315550
Signed-off-by: Ash Charles <ashcharles@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/drivers/boards/aerocore/board_config.h | 1 | ||||
-rw-r--r-- | src/drivers/l3gd20/l3gd20.cpp | 24 |
2 files changed, 9 insertions, 16 deletions
diff --git a/src/drivers/boards/aerocore/board_config.h b/src/drivers/boards/aerocore/board_config.h index 814065fcb..70142a314 100644 --- a/src/drivers/boards/aerocore/board_config.h +++ b/src/drivers/boards/aerocore/board_config.h @@ -65,6 +65,7 @@ __BEGIN_DECLS /* Gyro */ #define GPIO_EXTI_GYRO_DRDY (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTD|GPIO_PIN0) +#define SENSOR_BOARD_ROTATION_DEFAULT 3 /* SENSOR_BOARD_ROTATION_270_DEG */ /* Accel & Mag */ #define GPIO_EXTI_MAG_DRDY (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTD|GPIO_PIN1) diff --git a/src/drivers/l3gd20/l3gd20.cpp b/src/drivers/l3gd20/l3gd20.cpp index b9571dc4b..37e72388b 100644 --- a/src/drivers/l3gd20/l3gd20.cpp +++ b/src/drivers/l3gd20/l3gd20.cpp @@ -171,10 +171,14 @@ static const int ERROR = -1; #define FIFO_CTRL_BYPASS_TO_STREAM_MODE (1<<7) #define L3GD20_DEFAULT_RATE 760 -#define L3G4200D_DEFAULT_RATE 800 +#define L3G4200D_DEFAULT_RATE 800 #define L3GD20_DEFAULT_RANGE_DPS 2000 #define L3GD20_DEFAULT_FILTER_FREQ 30 +#ifndef SENSOR_BOARD_ROTATION_DEFAULT +#define SENSOR_BOARD_ROTATION_DEFAULT SENSOR_BOARD_ROTATION_270_DEG +#endif + extern "C" { __EXPORT int l3gd20_main(int argc, char *argv[]); } class L3GD20 : public device::SPI @@ -333,7 +337,7 @@ L3GD20::L3GD20(int bus, const char* path, spi_dev_e device) : _gyro_topic(-1), _class_instance(-1), _current_rate(0), - _orientation(SENSOR_BOARD_ROTATION_270_DEG), + _orientation(SENSOR_BOARD_ROTATION_DEFAULT), _read(0), _sample_perf(perf_alloc(PC_ELAPSED, "l3gd20_read")), _reschedules(perf_alloc(PC_COUNT, "l3gd20_reschedules")), @@ -423,17 +427,7 @@ L3GD20::probe() /* verify that the device is attached and functioning, accept L3GD20 and L3GD20H */ if (read_reg(ADDR_WHO_AM_I) == WHO_I_AM) { - #ifdef CONFIG_ARCH_BOARD_PX4FMU_V1 - _orientation = SENSOR_BOARD_ROTATION_270_DEG; - #elif CONFIG_ARCH_BOARD_PX4FMU_V2 - _orientation = SENSOR_BOARD_ROTATION_270_DEG; - /* AeroCore won't reach here but the pre-processor doesn't know this so it hits the error condition */ - #elif CONFIG_ARCH_BOARD_AEROCORE - _orientation = SENSOR_BOARD_ROTATION_270_DEG; - #else - #error This driver needs a board selection, either CONFIG_ARCH_BOARD_PX4FMU_V1, CONFIG_ARCH_BOARD_PX4FMU_V2 or CONFIG_ARCH_BOARD_AEROCORE - #endif - + _orientation = SENSOR_BOARD_ROTATION_DEFAULT; success = true; } @@ -446,9 +440,7 @@ L3GD20::probe() /* Detect the L3G4200D used on AeroCore */ if (read_reg(ADDR_WHO_AM_I) == WHO_I_AM_L3G4200D) { _is_l3g4200d = true; - #ifdef CONFIG_ARCH_BOARD_AEROCORE - _orientation = SENSOR_BOARD_ROTATION_270_DEG; - #endif + _orientation = SENSOR_BOARD_ROTATION_DEFAULT; success = true; } |