PX4 Firmware
PX4 Autopilot Software http://px4.io
LSM303D.hpp File Reference

Driver for the ST LSM303D MEMS accelerometer / magnetometer connected via SPI. More...

#include <drivers/device/spi.h>
#include <ecl/geo/geo.h>
#include <perf/perf_counter.h>
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
#include <lib/drivers/accelerometer/PX4Accelerometer.hpp>
#include <lib/drivers/magnetometer/PX4Magnetometer.hpp>
Include dependency graph for LSM303D.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  LSM303D
 

Macros

#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   0x49
 
#define ADDR_OUT_TEMP_L   0x05
 
#define ADDR_STATUS_A   0x27
 
#define ADDR_CTRL_REG0   0x1F
 
#define ADDR_CTRL_REG1   0x20
 
#define ADDR_CTRL_REG2   0x21
 
#define ADDR_CTRL_REG3   0x22
 
#define ADDR_CTRL_REG4   0x23
 
#define ADDR_CTRL_REG5   0x24
 
#define ADDR_CTRL_REG6   0x25
 
#define ADDR_CTRL_REG7   0x26
 
#define REG1_RATE_BITS_A   ((1<<7) | (1<<6) | (1<<5) | (1<<4))
 
#define REG1_POWERDOWN_A   ((0<<7) | (0<<6) | (0<<5) | (0<<4))
 
#define REG1_RATE_3_125HZ_A   ((0<<7) | (0<<6) | (0<<5) | (1<<4))
 
#define REG1_RATE_6_25HZ_A   ((0<<7) | (0<<6) | (1<<5) | (0<<4))
 
#define REG1_RATE_12_5HZ_A   ((0<<7) | (0<<6) | (1<<5) | (1<<4))
 
#define REG1_RATE_25HZ_A   ((0<<7) | (1<<6) | (0<<5) | (0<<4))
 
#define REG1_RATE_50HZ_A   ((0<<7) | (1<<6) | (0<<5) | (1<<4))
 
#define REG1_RATE_100HZ_A   ((0<<7) | (1<<6) | (1<<5) | (0<<4))
 
#define REG1_RATE_200HZ_A   ((0<<7) | (1<<6) | (1<<5) | (1<<4))
 
#define REG1_RATE_400HZ_A   ((1<<7) | (0<<6) | (0<<5) | (0<<4))
 
#define REG1_RATE_800HZ_A   ((1<<7) | (0<<6) | (0<<5) | (1<<4))
 
#define REG1_RATE_1600HZ_A   ((1<<7) | (0<<6) | (1<<5) | (0<<4))
 
#define REG1_BDU_UPDATE   (1<<3)
 
#define REG1_Z_ENABLE_A   (1<<2)
 
#define REG1_Y_ENABLE_A   (1<<1)
 
#define REG1_X_ENABLE_A   (1<<0)
 
#define REG2_ANTIALIAS_FILTER_BW_BITS_A   ((1<<7) | (1<<6))
 
#define REG2_AA_FILTER_BW_773HZ_A   ((0<<7) | (0<<6))
 
#define REG2_AA_FILTER_BW_194HZ_A   ((0<<7) | (1<<6))
 
#define REG2_AA_FILTER_BW_362HZ_A   ((1<<7) | (0<<6))
 
#define REG2_AA_FILTER_BW_50HZ_A   ((1<<7) | (1<<6))
 
#define REG2_FULL_SCALE_BITS_A   ((1<<5) | (1<<4) | (1<<3))
 
#define REG2_FULL_SCALE_2G_A   ((0<<5) | (0<<4) | (0<<3))
 
#define REG2_FULL_SCALE_4G_A   ((0<<5) | (0<<4) | (1<<3))
 
#define REG2_FULL_SCALE_6G_A   ((0<<5) | (1<<4) | (0<<3))
 
#define REG2_FULL_SCALE_8G_A   ((0<<5) | (1<<4) | (1<<3))
 
#define REG2_FULL_SCALE_16G_A   ((1<<5) | (0<<4) | (0<<3))
 
#define REG5_ENABLE_T   (1<<7)
 
#define REG5_RES_HIGH_M   ((1<<6) | (1<<5))
 
#define REG5_RES_LOW_M   ((0<<6) | (0<<5))
 
#define REG5_RATE_BITS_M   ((1<<4) | (1<<3) | (1<<2))
 
#define REG5_RATE_3_125HZ_M   ((0<<4) | (0<<3) | (0<<2))
 
#define REG5_RATE_6_25HZ_M   ((0<<4) | (0<<3) | (1<<2))
 
#define REG5_RATE_12_5HZ_M   ((0<<4) | (1<<3) | (0<<2))
 
#define REG5_RATE_25HZ_M   ((0<<4) | (1<<3) | (1<<2))
 
#define REG5_RATE_50HZ_M   ((1<<4) | (0<<3) | (0<<2))
 
#define REG5_RATE_100HZ_M   ((1<<4) | (0<<3) | (1<<2))
 
#define REG5_RATE_DO_NOT_USE_M   ((1<<4) | (1<<3) | (0<<2))
 
#define REG6_FULL_SCALE_BITS_M   ((1<<6) | (1<<5))
 
#define REG6_FULL_SCALE_2GA_M   ((0<<6) | (0<<5))
 
#define REG6_FULL_SCALE_4GA_M   ((0<<6) | (1<<5))
 
#define REG6_FULL_SCALE_8GA_M   ((1<<6) | (0<<5))
 
#define REG6_FULL_SCALE_12GA_M   ((1<<6) | (1<<5))
 
#define REG7_CONT_MODE_M   ((0<<1) | (0<<0))
 
#define REG_STATUS_A_NEW_ZYXADA   0x08
 
#define LSM303D_ACCEL_DEFAULT_RANGE_G   16
 
#define LSM303D_ACCEL_DEFAULT_RATE   800
 
#define LSM303D_ACCEL_DEFAULT_ONCHIP_FILTER_FREQ   50
 
#define LSM303D_MAG_DEFAULT_RANGE_GA   2
 
#define LSM303D_MAG_DEFAULT_RATE   100
 
#define LSM303D_TIMER_REDUCTION   200
 

Functions

__EXPORT int lsm303d_main (int argc, char *argv[])
 

Detailed Description

Driver for the ST LSM303D MEMS accelerometer / magnetometer connected via SPI.

Definition in file LSM303D.hpp.

Macro Definition Documentation

◆ ADDR_CTRL_REG0

#define ADDR_CTRL_REG0   0x1F

Definition at line 61 of file LSM303D.hpp.

◆ ADDR_CTRL_REG1

#define ADDR_CTRL_REG1   0x20

Definition at line 62 of file LSM303D.hpp.

◆ ADDR_CTRL_REG2

#define ADDR_CTRL_REG2   0x21

Definition at line 63 of file LSM303D.hpp.

◆ ADDR_CTRL_REG3

#define ADDR_CTRL_REG3   0x22

Definition at line 64 of file LSM303D.hpp.

◆ ADDR_CTRL_REG4

#define ADDR_CTRL_REG4   0x23

Definition at line 65 of file LSM303D.hpp.

◆ ADDR_CTRL_REG5

#define ADDR_CTRL_REG5   0x24

Definition at line 66 of file LSM303D.hpp.

◆ ADDR_CTRL_REG6

#define ADDR_CTRL_REG6   0x25

Definition at line 67 of file LSM303D.hpp.

Referenced by LSM303D::mag_set_range().

◆ ADDR_CTRL_REG7

#define ADDR_CTRL_REG7   0x26

Definition at line 68 of file LSM303D.hpp.

Referenced by LSM303D::reset().

◆ ADDR_INCREMENT

#define ADDR_INCREMENT   (1<<6)

Definition at line 51 of file LSM303D.hpp.

◆ ADDR_OUT_TEMP_L

#define ADDR_OUT_TEMP_L   0x05

Definition at line 57 of file LSM303D.hpp.

Referenced by LSM303D::measureMagnetometer().

◆ ADDR_STATUS_A

#define ADDR_STATUS_A   0x27

Definition at line 59 of file LSM303D.hpp.

Referenced by LSM303D::measureAccelerometer().

◆ ADDR_WHO_AM_I

#define ADDR_WHO_AM_I   0x0F

Definition at line 54 of file LSM303D.hpp.

◆ DIR_READ

#define DIR_READ   (1<<7)

Definition at line 49 of file LSM303D.hpp.

◆ DIR_WRITE

#define DIR_WRITE   (0<<7)

Definition at line 50 of file LSM303D.hpp.

◆ LSM303D_ACCEL_DEFAULT_ONCHIP_FILTER_FREQ

#define LSM303D_ACCEL_DEFAULT_ONCHIP_FILTER_FREQ   50

Definition at line 128 of file LSM303D.hpp.

Referenced by LSM303D::reset().

◆ LSM303D_ACCEL_DEFAULT_RANGE_G

#define LSM303D_ACCEL_DEFAULT_RANGE_G   16

Definition at line 126 of file LSM303D.hpp.

Referenced by LSM303D::reset().

◆ LSM303D_ACCEL_DEFAULT_RATE

#define LSM303D_ACCEL_DEFAULT_RATE   800

Definition at line 127 of file LSM303D.hpp.

Referenced by LSM303D::reset().

◆ LSM303D_MAG_DEFAULT_RANGE_GA

#define LSM303D_MAG_DEFAULT_RANGE_GA   2

Definition at line 130 of file LSM303D.hpp.

Referenced by LSM303D::reset().

◆ LSM303D_MAG_DEFAULT_RATE

#define LSM303D_MAG_DEFAULT_RATE   100

Definition at line 131 of file LSM303D.hpp.

Referenced by LSM303D::reset().

◆ LSM303D_TIMER_REDUCTION

#define LSM303D_TIMER_REDUCTION   200

Definition at line 139 of file LSM303D.hpp.

Referenced by LSM303D::start().

◆ REG1_BDU_UPDATE

#define REG1_BDU_UPDATE   (1<<3)

Definition at line 83 of file LSM303D.hpp.

Referenced by LSM303D::reset().

◆ REG1_POWERDOWN_A

#define REG1_POWERDOWN_A   ((0<<7) | (0<<6) | (0<<5) | (0<<4))

Definition at line 71 of file LSM303D.hpp.

◆ REG1_RATE_100HZ_A

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

Definition at line 77 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_samplerate().

◆ REG1_RATE_12_5HZ_A

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

Definition at line 74 of file LSM303D.hpp.

◆ REG1_RATE_1600HZ_A

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

Definition at line 81 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_samplerate().

◆ REG1_RATE_200HZ_A

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

Definition at line 78 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_samplerate().

◆ REG1_RATE_25HZ_A

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

Definition at line 75 of file LSM303D.hpp.

◆ REG1_RATE_3_125HZ_A

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

Definition at line 72 of file LSM303D.hpp.

◆ REG1_RATE_400HZ_A

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

Definition at line 79 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_samplerate().

◆ REG1_RATE_50HZ_A

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

Definition at line 76 of file LSM303D.hpp.

◆ REG1_RATE_6_25HZ_A

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

Definition at line 73 of file LSM303D.hpp.

◆ REG1_RATE_800HZ_A

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

Definition at line 80 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_samplerate(), and LSM303D::reset().

◆ REG1_RATE_BITS_A

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

Definition at line 70 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_samplerate().

◆ REG1_X_ENABLE_A

#define REG1_X_ENABLE_A   (1<<0)

Definition at line 86 of file LSM303D.hpp.

Referenced by LSM303D::reset().

◆ REG1_Y_ENABLE_A

#define REG1_Y_ENABLE_A   (1<<1)

Definition at line 85 of file LSM303D.hpp.

Referenced by LSM303D::reset().

◆ REG1_Z_ENABLE_A

#define REG1_Z_ENABLE_A   (1<<2)

Definition at line 84 of file LSM303D.hpp.

Referenced by LSM303D::reset().

◆ REG2_AA_FILTER_BW_194HZ_A

#define REG2_AA_FILTER_BW_194HZ_A   ((0<<7) | (1<<6))

Definition at line 90 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_onchip_lowpass_filter_bandwidth().

◆ REG2_AA_FILTER_BW_362HZ_A

#define REG2_AA_FILTER_BW_362HZ_A   ((1<<7) | (0<<6))

Definition at line 91 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_onchip_lowpass_filter_bandwidth().

◆ REG2_AA_FILTER_BW_50HZ_A

#define REG2_AA_FILTER_BW_50HZ_A   ((1<<7) | (1<<6))

Definition at line 92 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_onchip_lowpass_filter_bandwidth().

◆ REG2_AA_FILTER_BW_773HZ_A

#define REG2_AA_FILTER_BW_773HZ_A   ((0<<7) | (0<<6))

Definition at line 89 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_onchip_lowpass_filter_bandwidth().

◆ REG2_ANTIALIAS_FILTER_BW_BITS_A

#define REG2_ANTIALIAS_FILTER_BW_BITS_A   ((1<<7) | (1<<6))

Definition at line 88 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_onchip_lowpass_filter_bandwidth().

◆ REG2_FULL_SCALE_16G_A

#define REG2_FULL_SCALE_16G_A   ((1<<5) | (0<<4) | (0<<3))

Definition at line 99 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_range().

◆ REG2_FULL_SCALE_2G_A

#define REG2_FULL_SCALE_2G_A   ((0<<5) | (0<<4) | (0<<3))

Definition at line 95 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_range().

◆ REG2_FULL_SCALE_4G_A

#define REG2_FULL_SCALE_4G_A   ((0<<5) | (0<<4) | (1<<3))

Definition at line 96 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_range().

◆ REG2_FULL_SCALE_6G_A

#define REG2_FULL_SCALE_6G_A   ((0<<5) | (1<<4) | (0<<3))

Definition at line 97 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_range().

◆ REG2_FULL_SCALE_8G_A

#define REG2_FULL_SCALE_8G_A   ((0<<5) | (1<<4) | (1<<3))

Definition at line 98 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_range().

◆ REG2_FULL_SCALE_BITS_A

#define REG2_FULL_SCALE_BITS_A   ((1<<5) | (1<<4) | (1<<3))

Definition at line 94 of file LSM303D.hpp.

Referenced by LSM303D::accel_set_range().

◆ REG5_ENABLE_T

#define REG5_ENABLE_T   (1<<7)

Definition at line 101 of file LSM303D.hpp.

Referenced by LSM303D::reset().

◆ REG5_RATE_100HZ_M

#define REG5_RATE_100HZ_M   ((1<<4) | (0<<3) | (1<<2))

Definition at line 112 of file LSM303D.hpp.

Referenced by LSM303D::mag_set_samplerate().

◆ REG5_RATE_12_5HZ_M

#define REG5_RATE_12_5HZ_M   ((0<<4) | (1<<3) | (0<<2))

Definition at line 109 of file LSM303D.hpp.

◆ REG5_RATE_25HZ_M

#define REG5_RATE_25HZ_M   ((0<<4) | (1<<3) | (1<<2))

Definition at line 110 of file LSM303D.hpp.

Referenced by LSM303D::mag_set_samplerate().

◆ REG5_RATE_3_125HZ_M

#define REG5_RATE_3_125HZ_M   ((0<<4) | (0<<3) | (0<<2))

Definition at line 107 of file LSM303D.hpp.

◆ REG5_RATE_50HZ_M

#define REG5_RATE_50HZ_M   ((1<<4) | (0<<3) | (0<<2))

Definition at line 111 of file LSM303D.hpp.

Referenced by LSM303D::mag_set_samplerate().

◆ REG5_RATE_6_25HZ_M

#define REG5_RATE_6_25HZ_M   ((0<<4) | (0<<3) | (1<<2))

Definition at line 108 of file LSM303D.hpp.

◆ REG5_RATE_BITS_M

#define REG5_RATE_BITS_M   ((1<<4) | (1<<3) | (1<<2))

Definition at line 106 of file LSM303D.hpp.

Referenced by LSM303D::mag_set_samplerate().

◆ REG5_RATE_DO_NOT_USE_M

#define REG5_RATE_DO_NOT_USE_M   ((1<<4) | (1<<3) | (0<<2))

Definition at line 113 of file LSM303D.hpp.

◆ REG5_RES_HIGH_M

#define REG5_RES_HIGH_M   ((1<<6) | (1<<5))

Definition at line 103 of file LSM303D.hpp.

Referenced by LSM303D::reset().

◆ REG5_RES_LOW_M

#define REG5_RES_LOW_M   ((0<<6) | (0<<5))

Definition at line 104 of file LSM303D.hpp.

◆ REG6_FULL_SCALE_12GA_M

#define REG6_FULL_SCALE_12GA_M   ((1<<6) | (1<<5))

Definition at line 119 of file LSM303D.hpp.

Referenced by LSM303D::mag_set_range().

◆ REG6_FULL_SCALE_2GA_M

#define REG6_FULL_SCALE_2GA_M   ((0<<6) | (0<<5))

Definition at line 116 of file LSM303D.hpp.

Referenced by LSM303D::mag_set_range().

◆ REG6_FULL_SCALE_4GA_M

#define REG6_FULL_SCALE_4GA_M   ((0<<6) | (1<<5))

Definition at line 117 of file LSM303D.hpp.

Referenced by LSM303D::mag_set_range().

◆ REG6_FULL_SCALE_8GA_M

#define REG6_FULL_SCALE_8GA_M   ((1<<6) | (0<<5))

Definition at line 118 of file LSM303D.hpp.

Referenced by LSM303D::mag_set_range().

◆ REG6_FULL_SCALE_BITS_M

#define REG6_FULL_SCALE_BITS_M   ((1<<6) | (1<<5))

Definition at line 115 of file LSM303D.hpp.

Referenced by LSM303D::mag_set_range().

◆ REG7_CONT_MODE_M

#define REG7_CONT_MODE_M   ((0<<1) | (0<<0))

Definition at line 121 of file LSM303D.hpp.

Referenced by LSM303D::reset().

◆ REG_STATUS_A_NEW_ZYXADA

#define REG_STATUS_A_NEW_ZYXADA   0x08

Definition at line 123 of file LSM303D.hpp.

Referenced by LSM303D::measureAccelerometer().

◆ WHO_I_AM

#define WHO_I_AM   0x49

Definition at line 55 of file LSM303D.hpp.

Function Documentation

◆ lsm303d_main()

__EXPORT int lsm303d_main ( int  argc,
char *  argv[] 
)

Definition at line 128 of file lsm303d_main.cpp.

References errx, lsm303d::info(), ROTATION_NONE, lsm303d::start(), and lsm303d::usage().

Here is the call graph for this function: