PX4 Firmware
PX4 Autopilot Software http://px4.io
l3gd20.cpp File Reference

Driver for the ST L3GD20 MEMS and L3GD20H mems gyros connected via SPI. More...

#include <drivers/device/spi.h>
#include <lib/conversion/rotation.h>
#include <lib/drivers/gyroscope/PX4Gyroscope.hpp>
#include <perf/perf_counter.h>
#include <px4_platform_common/getopt.h>
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
Include dependency graph for l3gd20.cpp:

Go to the source code of this file.

Classes

class  L3GD20
 

Namespaces

 l3gd20
 Local functions in support of the shell command.
 

Macros

#define L3GD20_DEVICE_PATH   "/dev/l3gd20"
 
#define SENSOR_BOARD_ROTATION_000_DEG   0
 
#define SENSOR_BOARD_ROTATION_090_DEG   1
 
#define SENSOR_BOARD_ROTATION_180_DEG   2
 
#define SENSOR_BOARD_ROTATION_270_DEG   3
 
#define DIR_READ   (1<<7)
 
#define DIR_WRITE   (0<<7)
 
#define ADDR_INCREMENT   (1<<6)
 
#define ADDR_WHO_AM_I   0x0F
 
#define WHO_I_AM_H   0xD7
 
#define WHO_I_AM   0xD4
 
#define WHO_I_AM_L3G4200D   0xD3 /* for L3G4200D */
 
#define ADDR_CTRL_REG1   0x20
 
#define REG1_RATE_LP_MASK   0xF0 /* Mask to guard partial register update */
 
#define RATE_95HZ_LP_25HZ   ((0<<7) | (0<<6) | (0<<5) | (1<<4))
 
#define RATE_190HZ_LP_25HZ   ((0<<7) | (1<<6) | (0<<5) | (1<<4))
 
#define RATE_190HZ_LP_50HZ   ((0<<7) | (1<<6) | (1<<5) | (0<<4))
 
#define RATE_190HZ_LP_70HZ   ((0<<7) | (1<<6) | (1<<5) | (1<<4))
 
#define RATE_380HZ_LP_20HZ   ((1<<7) | (0<<6) | (1<<5) | (0<<4))
 
#define RATE_380HZ_LP_25HZ   ((1<<7) | (0<<6) | (0<<5) | (1<<4))
 
#define RATE_380HZ_LP_50HZ   ((1<<7) | (0<<6) | (1<<5) | (0<<4))
 
#define RATE_380HZ_LP_100HZ   ((1<<7) | (0<<6) | (1<<5) | (1<<4))
 
#define RATE_760HZ_LP_30HZ   ((1<<7) | (1<<6) | (0<<5) | (0<<4))
 
#define RATE_760HZ_LP_35HZ   ((1<<7) | (1<<6) | (0<<5) | (1<<4))
 
#define RATE_760HZ_LP_50HZ   ((1<<7) | (1<<6) | (1<<5) | (0<<4))
 
#define RATE_760HZ_LP_100HZ   ((1<<7) | (1<<6) | (1<<5) | (1<<4))
 
#define ADDR_CTRL_REG2   0x21
 
#define ADDR_CTRL_REG3   0x22
 
#define ADDR_CTRL_REG4   0x23
 
#define REG4_RANGE_MASK   0x30 /* Mask to guard partial register update */
 
#define RANGE_250DPS   (0<<4)
 
#define RANGE_500DPS   (1<<4)
 
#define RANGE_2000DPS   (3<<4)
 
#define ADDR_CTRL_REG5   0x24
 
#define ADDR_REFERENCE   0x25
 
#define ADDR_OUT_TEMP   0x26
 
#define ADDR_STATUS_REG   0x27
 
#define ADDR_OUT_X_L   0x28
 
#define ADDR_OUT_X_H   0x29
 
#define ADDR_OUT_Y_L   0x2A
 
#define ADDR_OUT_Y_H   0x2B
 
#define ADDR_OUT_Z_L   0x2C
 
#define ADDR_OUT_Z_H   0x2D
 
#define ADDR_FIFO_CTRL_REG   0x2E
 
#define ADDR_FIFO_SRC_REG   0x2F
 
#define ADDR_INT1_CFG   0x30
 
#define ADDR_INT1_SRC   0x31
 
#define ADDR_INT1_TSH_XH   0x32
 
#define ADDR_INT1_TSH_XL   0x33
 
#define ADDR_INT1_TSH_YH   0x34
 
#define ADDR_INT1_TSH_YL   0x35
 
#define ADDR_INT1_TSH_ZH   0x36
 
#define ADDR_INT1_TSH_ZL   0x37
 
#define ADDR_INT1_DURATION   0x38
 
#define ADDR_LOW_ODR   0x39
 
#define REG1_POWER_NORMAL   (1<<3)
 
#define REG1_Z_ENABLE   (1<<2)
 
#define REG1_Y_ENABLE   (1<<1)
 
#define REG1_X_ENABLE   (1<<0)
 
#define REG4_BDU   (1<<7)
 
#define REG4_BLE   (1<<6)
 
#define REG5_FIFO_ENABLE   (1<<6)
 
#define REG5_REBOOT_MEMORY   (1<<7)
 
#define STATUS_ZYXOR   (1<<7)
 
#define STATUS_ZOR   (1<<6)
 
#define STATUS_YOR   (1<<5)
 
#define STATUS_XOR   (1<<4)
 
#define STATUS_ZYXDA   (1<<3)
 
#define STATUS_ZDA   (1<<2)
 
#define STATUS_YDA   (1<<1)
 
#define STATUS_XDA   (1<<0)
 
#define FIFO_CTRL_BYPASS_MODE   (0<<5)
 
#define FIFO_CTRL_FIFO_MODE   (1<<5)
 
#define FIFO_CTRL_STREAM_MODE   (1<<6)
 
#define FIFO_CTRL_STREAM_TO_FIFO_MODE   (3<<5)
 
#define FIFO_CTRL_BYPASS_TO_STREAM_MODE   (1<<7)
 
#define L3GD20_DEFAULT_RATE   760
 
#define L3G4200D_DEFAULT_RATE   800
 
#define L3GD20_MAX_OUTPUT_RATE   280
 
#define L3GD20_DEFAULT_RANGE_DPS   2000
 
#define L3GD20_DEFAULT_FILTER_FREQ   30
 
#define L3GD20_TEMP_OFFSET_CELSIUS   40
 
#define L3GD20_MAX_OFFSET   0.45f
 max offset: 25 degrees/s More...
 
#define SENSOR_BOARD_ROTATION_DEFAULT   SENSOR_BOARD_ROTATION_270_DEG
 
#define L3GD20_TIMER_REDUCTION   600
 

Functions

__EXPORT int l3gd20_main (int argc, char *argv[])
 
void l3gd20::usage ()
 Prints info about the driver argument usage. More...
 
void l3gd20::start (bool external_bus, enum Rotation rotation)
 Start the driver. More...
 
void l3gd20::info ()
 Print a little info about the driver. More...
 
void l3gd20::regdump (void)
 Dump the register information. More...
 
void l3gd20::test_error (void)
 trigger an error More...
 

Variables

L3GD20l3gd20::g_dev
 

Detailed Description

Driver for the ST L3GD20 MEMS and L3GD20H mems gyros connected via SPI.

Note: With the exception of the self-test feature, the ST L3G4200D is also supported by this driver.

Definition in file l3gd20.cpp.

Macro Definition Documentation

◆ ADDR_CTRL_REG1

#define ADDR_CTRL_REG1   0x20

Definition at line 68 of file l3gd20.cpp.

Referenced by L3GD20::reset(), and L3GD20::set_samplerate().

◆ ADDR_CTRL_REG2

#define ADDR_CTRL_REG2   0x21

Definition at line 85 of file l3gd20.cpp.

Referenced by L3GD20::reset().

◆ ADDR_CTRL_REG3

#define ADDR_CTRL_REG3   0x22

Definition at line 86 of file l3gd20.cpp.

Referenced by L3GD20::reset(), and L3GD20::test_error().

◆ ADDR_CTRL_REG4

#define ADDR_CTRL_REG4   0x23

Definition at line 87 of file l3gd20.cpp.

Referenced by L3GD20::reset(), and L3GD20::set_range().

◆ ADDR_CTRL_REG5

#define ADDR_CTRL_REG5   0x24

◆ ADDR_FIFO_CTRL_REG

#define ADDR_FIFO_CTRL_REG   0x2E

Definition at line 103 of file l3gd20.cpp.

Referenced by L3GD20::reset().

◆ ADDR_FIFO_SRC_REG

#define ADDR_FIFO_SRC_REG   0x2F

Definition at line 104 of file l3gd20.cpp.

◆ ADDR_INCREMENT

#define ADDR_INCREMENT   (1<<6)

Definition at line 60 of file l3gd20.cpp.

Referenced by L3GD20::measure().

◆ ADDR_INT1_CFG

#define ADDR_INT1_CFG   0x30

Definition at line 105 of file l3gd20.cpp.

◆ ADDR_INT1_DURATION

#define ADDR_INT1_DURATION   0x38

Definition at line 113 of file l3gd20.cpp.

◆ ADDR_INT1_SRC

#define ADDR_INT1_SRC   0x31

Definition at line 106 of file l3gd20.cpp.

◆ ADDR_INT1_TSH_XH

#define ADDR_INT1_TSH_XH   0x32

Definition at line 107 of file l3gd20.cpp.

◆ ADDR_INT1_TSH_XL

#define ADDR_INT1_TSH_XL   0x33

Definition at line 108 of file l3gd20.cpp.

◆ ADDR_INT1_TSH_YH

#define ADDR_INT1_TSH_YH   0x34

Definition at line 109 of file l3gd20.cpp.

◆ ADDR_INT1_TSH_YL

#define ADDR_INT1_TSH_YL   0x35

Definition at line 110 of file l3gd20.cpp.

◆ ADDR_INT1_TSH_ZH

#define ADDR_INT1_TSH_ZH   0x36

Definition at line 111 of file l3gd20.cpp.

◆ ADDR_INT1_TSH_ZL

#define ADDR_INT1_TSH_ZL   0x37

Definition at line 112 of file l3gd20.cpp.

◆ ADDR_LOW_ODR

#define ADDR_LOW_ODR   0x39

Definition at line 114 of file l3gd20.cpp.

Referenced by L3GD20::disable_i2c().

◆ ADDR_OUT_TEMP

#define ADDR_OUT_TEMP   0x26

Definition at line 95 of file l3gd20.cpp.

Referenced by L3GD20::measure().

◆ ADDR_OUT_X_H

#define ADDR_OUT_X_H   0x29

Definition at line 98 of file l3gd20.cpp.

◆ ADDR_OUT_X_L

#define ADDR_OUT_X_L   0x28

Definition at line 97 of file l3gd20.cpp.

Referenced by LIS3MDL::collect().

◆ ADDR_OUT_Y_H

#define ADDR_OUT_Y_H   0x2B

Definition at line 100 of file l3gd20.cpp.

◆ ADDR_OUT_Y_L

#define ADDR_OUT_Y_L   0x2A

Definition at line 99 of file l3gd20.cpp.

◆ ADDR_OUT_Z_H

#define ADDR_OUT_Z_H   0x2D

Definition at line 102 of file l3gd20.cpp.

◆ ADDR_OUT_Z_L

#define ADDR_OUT_Z_L   0x2C

Definition at line 101 of file l3gd20.cpp.

◆ ADDR_REFERENCE

#define ADDR_REFERENCE   0x25

Definition at line 94 of file l3gd20.cpp.

◆ ADDR_STATUS_REG

#define ADDR_STATUS_REG   0x27

Definition at line 96 of file l3gd20.cpp.

◆ ADDR_WHO_AM_I

#define ADDR_WHO_AM_I   0x0F

Definition at line 63 of file l3gd20.cpp.

Referenced by L3GD20::probe().

◆ DIR_READ

#define DIR_READ   (1<<7)

Definition at line 58 of file l3gd20.cpp.

Referenced by L3GD20::measure(), and L3GD20::read_reg().

◆ DIR_WRITE

#define DIR_WRITE   (0<<7)

Definition at line 59 of file l3gd20.cpp.

Referenced by L3GD20::write_reg().

◆ FIFO_CTRL_BYPASS_MODE

#define FIFO_CTRL_BYPASS_MODE   (0<<5)

Definition at line 139 of file l3gd20.cpp.

Referenced by L3GD20::reset().

◆ FIFO_CTRL_BYPASS_TO_STREAM_MODE

#define FIFO_CTRL_BYPASS_TO_STREAM_MODE   (1<<7)

Definition at line 143 of file l3gd20.cpp.

◆ FIFO_CTRL_FIFO_MODE

#define FIFO_CTRL_FIFO_MODE   (1<<5)

Definition at line 140 of file l3gd20.cpp.

◆ FIFO_CTRL_STREAM_MODE

#define FIFO_CTRL_STREAM_MODE   (1<<6)

Definition at line 141 of file l3gd20.cpp.

◆ FIFO_CTRL_STREAM_TO_FIFO_MODE

#define FIFO_CTRL_STREAM_TO_FIFO_MODE   (3<<5)

Definition at line 142 of file l3gd20.cpp.

◆ L3G4200D_DEFAULT_RATE

#define L3G4200D_DEFAULT_RATE   800

Definition at line 146 of file l3gd20.cpp.

Referenced by L3GD20::start().

◆ L3GD20_DEFAULT_FILTER_FREQ

#define L3GD20_DEFAULT_FILTER_FREQ   30

Definition at line 149 of file l3gd20.cpp.

◆ L3GD20_DEFAULT_RANGE_DPS

#define L3GD20_DEFAULT_RANGE_DPS   2000

Definition at line 148 of file l3gd20.cpp.

Referenced by L3GD20::reset().

◆ L3GD20_DEFAULT_RATE

#define L3GD20_DEFAULT_RATE   760

Definition at line 145 of file l3gd20.cpp.

◆ L3GD20_DEVICE_PATH

#define L3GD20_DEVICE_PATH   "/dev/l3gd20"

Definition at line 49 of file l3gd20.cpp.

Referenced by l3gd20::start().

◆ L3GD20_MAX_OFFSET

#define L3GD20_MAX_OFFSET   0.45f

max offset: 25 degrees/s

Definition at line 152 of file l3gd20.cpp.

◆ L3GD20_MAX_OUTPUT_RATE

#define L3GD20_MAX_OUTPUT_RATE   280

Definition at line 147 of file l3gd20.cpp.

◆ L3GD20_TEMP_OFFSET_CELSIUS

#define L3GD20_TEMP_OFFSET_CELSIUS   40

Definition at line 150 of file l3gd20.cpp.

Referenced by L3GD20::measure().

◆ L3GD20_TIMER_REDUCTION

#define L3GD20_TIMER_REDUCTION   600

Definition at line 164 of file l3gd20.cpp.

Referenced by L3GD20::start().

◆ RANGE_2000DPS

#define RANGE_2000DPS   (3<<4)

Definition at line 91 of file l3gd20.cpp.

Referenced by L3GD20::set_range().

◆ RANGE_250DPS

#define RANGE_250DPS   (0<<4)

Definition at line 89 of file l3gd20.cpp.

Referenced by L3GD20::set_range().

◆ RANGE_500DPS

#define RANGE_500DPS   (1<<4)

Definition at line 90 of file l3gd20.cpp.

Referenced by L3GD20::set_range().

◆ RATE_190HZ_LP_25HZ

#define RATE_190HZ_LP_25HZ   ((0<<7) | (1<<6) | (0<<5) | (1<<4))

Definition at line 73 of file l3gd20.cpp.

◆ RATE_190HZ_LP_50HZ

#define RATE_190HZ_LP_50HZ   ((0<<7) | (1<<6) | (1<<5) | (0<<4))

Definition at line 74 of file l3gd20.cpp.

Referenced by L3GD20::set_samplerate().

◆ RATE_190HZ_LP_70HZ

#define RATE_190HZ_LP_70HZ   ((0<<7) | (1<<6) | (1<<5) | (1<<4))

Definition at line 75 of file l3gd20.cpp.

◆ RATE_380HZ_LP_100HZ

#define RATE_380HZ_LP_100HZ   ((1<<7) | (0<<6) | (1<<5) | (1<<4))

Definition at line 79 of file l3gd20.cpp.

◆ RATE_380HZ_LP_20HZ

#define RATE_380HZ_LP_20HZ   ((1<<7) | (0<<6) | (1<<5) | (0<<4))

Definition at line 76 of file l3gd20.cpp.

◆ RATE_380HZ_LP_25HZ

#define RATE_380HZ_LP_25HZ   ((1<<7) | (0<<6) | (0<<5) | (1<<4))

Definition at line 77 of file l3gd20.cpp.

◆ RATE_380HZ_LP_50HZ

#define RATE_380HZ_LP_50HZ   ((1<<7) | (0<<6) | (1<<5) | (0<<4))

Definition at line 78 of file l3gd20.cpp.

Referenced by L3GD20::set_samplerate().

◆ RATE_760HZ_LP_100HZ

#define RATE_760HZ_LP_100HZ   ((1<<7) | (1<<6) | (1<<5) | (1<<4))

Definition at line 83 of file l3gd20.cpp.

◆ RATE_760HZ_LP_30HZ

#define RATE_760HZ_LP_30HZ   ((1<<7) | (1<<6) | (0<<5) | (0<<4))

Definition at line 80 of file l3gd20.cpp.

◆ RATE_760HZ_LP_35HZ

#define RATE_760HZ_LP_35HZ   ((1<<7) | (1<<6) | (0<<5) | (1<<4))

Definition at line 81 of file l3gd20.cpp.

◆ RATE_760HZ_LP_50HZ

#define RATE_760HZ_LP_50HZ   ((1<<7) | (1<<6) | (1<<5) | (0<<4))

Definition at line 82 of file l3gd20.cpp.

Referenced by L3GD20::set_samplerate().

◆ RATE_95HZ_LP_25HZ

#define RATE_95HZ_LP_25HZ   ((0<<7) | (0<<6) | (0<<5) | (1<<4))

Definition at line 72 of file l3gd20.cpp.

Referenced by L3GD20::set_samplerate().

◆ REG1_POWER_NORMAL

#define REG1_POWER_NORMAL   (1<<3)

Definition at line 118 of file l3gd20.cpp.

Referenced by L3GD20::reset(), and L3GD20::set_samplerate().

◆ REG1_RATE_LP_MASK

#define REG1_RATE_LP_MASK   0xF0 /* Mask to guard partial register update */

Definition at line 69 of file l3gd20.cpp.

◆ REG1_X_ENABLE

#define REG1_X_ENABLE   (1<<0)

Definition at line 121 of file l3gd20.cpp.

Referenced by L3GD20::reset(), and L3GD20::set_samplerate().

◆ REG1_Y_ENABLE

#define REG1_Y_ENABLE   (1<<1)

Definition at line 120 of file l3gd20.cpp.

Referenced by L3GD20::reset(), and L3GD20::set_samplerate().

◆ REG1_Z_ENABLE

#define REG1_Z_ENABLE   (1<<2)

Definition at line 119 of file l3gd20.cpp.

Referenced by L3GD20::reset(), and L3GD20::set_samplerate().

◆ REG4_BDU

#define REG4_BDU   (1<<7)

Definition at line 123 of file l3gd20.cpp.

Referenced by L3GD20::reset(), and L3GD20::set_range().

◆ REG4_BLE

#define REG4_BLE   (1<<6)

Definition at line 124 of file l3gd20.cpp.

◆ REG4_RANGE_MASK

#define REG4_RANGE_MASK   0x30 /* Mask to guard partial register update */

Definition at line 88 of file l3gd20.cpp.

◆ REG5_FIFO_ENABLE

#define REG5_FIFO_ENABLE   (1<<6)

Definition at line 127 of file l3gd20.cpp.

Referenced by L3GD20::reset().

◆ REG5_REBOOT_MEMORY

#define REG5_REBOOT_MEMORY   (1<<7)

Definition at line 128 of file l3gd20.cpp.

◆ SENSOR_BOARD_ROTATION_000_DEG

#define SENSOR_BOARD_ROTATION_000_DEG   0

Definition at line 52 of file l3gd20.cpp.

Referenced by L3GD20::measure().

◆ SENSOR_BOARD_ROTATION_090_DEG

#define SENSOR_BOARD_ROTATION_090_DEG   1

Definition at line 53 of file l3gd20.cpp.

Referenced by L3GD20::measure().

◆ SENSOR_BOARD_ROTATION_180_DEG

#define SENSOR_BOARD_ROTATION_180_DEG   2

Definition at line 54 of file l3gd20.cpp.

Referenced by L3GD20::measure(), and L3GD20::probe().

◆ SENSOR_BOARD_ROTATION_270_DEG

#define SENSOR_BOARD_ROTATION_270_DEG   3

Definition at line 55 of file l3gd20.cpp.

Referenced by L3GD20::measure().

◆ SENSOR_BOARD_ROTATION_DEFAULT

#define SENSOR_BOARD_ROTATION_DEFAULT   SENSOR_BOARD_ROTATION_270_DEG

Definition at line 155 of file l3gd20.cpp.

Referenced by L3GD20::probe().

◆ STATUS_XDA

#define STATUS_XDA   (1<<0)

Definition at line 137 of file l3gd20.cpp.

◆ STATUS_XOR

#define STATUS_XOR   (1<<4)

Definition at line 133 of file l3gd20.cpp.

◆ STATUS_YDA

#define STATUS_YDA   (1<<1)

Definition at line 136 of file l3gd20.cpp.

◆ STATUS_YOR

#define STATUS_YOR   (1<<5)

Definition at line 132 of file l3gd20.cpp.

◆ STATUS_ZDA

#define STATUS_ZDA   (1<<2)

Definition at line 135 of file l3gd20.cpp.

◆ STATUS_ZOR

#define STATUS_ZOR   (1<<6)

Definition at line 131 of file l3gd20.cpp.

◆ STATUS_ZYXDA

#define STATUS_ZYXDA   (1<<3)

Definition at line 134 of file l3gd20.cpp.

Referenced by L3GD20::measure().

◆ STATUS_ZYXOR

#define STATUS_ZYXOR   (1<<7)

Definition at line 130 of file l3gd20.cpp.

◆ WHO_I_AM

#define WHO_I_AM   0xD4

Definition at line 65 of file l3gd20.cpp.

Referenced by LSM303D::probe(), and L3GD20::probe().

◆ WHO_I_AM_H

#define WHO_I_AM_H   0xD7

Definition at line 64 of file l3gd20.cpp.

Referenced by L3GD20::probe().

◆ WHO_I_AM_L3G4200D

#define WHO_I_AM_L3G4200D   0xD3 /* for L3G4200D */

Definition at line 66 of file l3gd20.cpp.

Referenced by L3GD20::probe().

Function Documentation

◆ l3gd20_main()

int l3gd20_main ( int  argc,
char *  argv[] 
)

Definition at line 872 of file l3gd20.cpp.

References l3gd20::info(), l3gd20::regdump(), ROTATION_NONE, l3gd20::start(), l3gd20::test_error(), and l3gd20::usage().

Here is the call graph for this function: