44 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp> 49 #define DIR_READ (1<<7) 50 #define DIR_WRITE (0<<7) 51 #define ADDR_INCREMENT (1<<6) 54 #define ADDR_WHO_AM_I 0x0F 57 #define ADDR_OUT_TEMP_L 0x05 59 #define ADDR_STATUS_A 0x27 61 #define ADDR_CTRL_REG0 0x1F 62 #define ADDR_CTRL_REG1 0x20 63 #define ADDR_CTRL_REG2 0x21 64 #define ADDR_CTRL_REG3 0x22 65 #define ADDR_CTRL_REG4 0x23 66 #define ADDR_CTRL_REG5 0x24 67 #define ADDR_CTRL_REG6 0x25 68 #define ADDR_CTRL_REG7 0x26 70 #define REG1_RATE_BITS_A ((1<<7) | (1<<6) | (1<<5) | (1<<4)) 71 #define REG1_POWERDOWN_A ((0<<7) | (0<<6) | (0<<5) | (0<<4)) 72 #define REG1_RATE_3_125HZ_A ((0<<7) | (0<<6) | (0<<5) | (1<<4)) 73 #define REG1_RATE_6_25HZ_A ((0<<7) | (0<<6) | (1<<5) | (0<<4)) 74 #define REG1_RATE_12_5HZ_A ((0<<7) | (0<<6) | (1<<5) | (1<<4)) 75 #define REG1_RATE_25HZ_A ((0<<7) | (1<<6) | (0<<5) | (0<<4)) 76 #define REG1_RATE_50HZ_A ((0<<7) | (1<<6) | (0<<5) | (1<<4)) 77 #define REG1_RATE_100HZ_A ((0<<7) | (1<<6) | (1<<5) | (0<<4)) 78 #define REG1_RATE_200HZ_A ((0<<7) | (1<<6) | (1<<5) | (1<<4)) 79 #define REG1_RATE_400HZ_A ((1<<7) | (0<<6) | (0<<5) | (0<<4)) 80 #define REG1_RATE_800HZ_A ((1<<7) | (0<<6) | (0<<5) | (1<<4)) 81 #define REG1_RATE_1600HZ_A ((1<<7) | (0<<6) | (1<<5) | (0<<4)) 83 #define REG1_BDU_UPDATE (1<<3) 84 #define REG1_Z_ENABLE_A (1<<2) 85 #define REG1_Y_ENABLE_A (1<<1) 86 #define REG1_X_ENABLE_A (1<<0) 88 #define REG2_ANTIALIAS_FILTER_BW_BITS_A ((1<<7) | (1<<6)) 89 #define REG2_AA_FILTER_BW_773HZ_A ((0<<7) | (0<<6)) 90 #define REG2_AA_FILTER_BW_194HZ_A ((0<<7) | (1<<6)) 91 #define REG2_AA_FILTER_BW_362HZ_A ((1<<7) | (0<<6)) 92 #define REG2_AA_FILTER_BW_50HZ_A ((1<<7) | (1<<6)) 94 #define REG2_FULL_SCALE_BITS_A ((1<<5) | (1<<4) | (1<<3)) 95 #define REG2_FULL_SCALE_2G_A ((0<<5) | (0<<4) | (0<<3)) 96 #define REG2_FULL_SCALE_4G_A ((0<<5) | (0<<4) | (1<<3)) 97 #define REG2_FULL_SCALE_6G_A ((0<<5) | (1<<4) | (0<<3)) 98 #define REG2_FULL_SCALE_8G_A ((0<<5) | (1<<4) | (1<<3)) 99 #define REG2_FULL_SCALE_16G_A ((1<<5) | (0<<4) | (0<<3)) 101 #define REG5_ENABLE_T (1<<7) 103 #define REG5_RES_HIGH_M ((1<<6) | (1<<5)) 104 #define REG5_RES_LOW_M ((0<<6) | (0<<5)) 106 #define REG5_RATE_BITS_M ((1<<4) | (1<<3) | (1<<2)) 107 #define REG5_RATE_3_125HZ_M ((0<<4) | (0<<3) | (0<<2)) 108 #define REG5_RATE_6_25HZ_M ((0<<4) | (0<<3) | (1<<2)) 109 #define REG5_RATE_12_5HZ_M ((0<<4) | (1<<3) | (0<<2)) 110 #define REG5_RATE_25HZ_M ((0<<4) | (1<<3) | (1<<2)) 111 #define REG5_RATE_50HZ_M ((1<<4) | (0<<3) | (0<<2)) 112 #define REG5_RATE_100HZ_M ((1<<4) | (0<<3) | (1<<2)) 113 #define REG5_RATE_DO_NOT_USE_M ((1<<4) | (1<<3) | (0<<2)) 115 #define REG6_FULL_SCALE_BITS_M ((1<<6) | (1<<5)) 116 #define REG6_FULL_SCALE_2GA_M ((0<<6) | (0<<5)) 117 #define REG6_FULL_SCALE_4GA_M ((0<<6) | (1<<5)) 118 #define REG6_FULL_SCALE_8GA_M ((1<<6) | (0<<5)) 119 #define REG6_FULL_SCALE_12GA_M ((1<<6) | (1<<5)) 121 #define REG7_CONT_MODE_M ((0<<1) | (0<<0)) 123 #define REG_STATUS_A_NEW_ZYXADA 0x08 126 #define LSM303D_ACCEL_DEFAULT_RANGE_G 16 127 #define LSM303D_ACCEL_DEFAULT_RATE 800 128 #define LSM303D_ACCEL_DEFAULT_ONCHIP_FILTER_FREQ 50 130 #define LSM303D_MAG_DEFAULT_RANGE_GA 2 131 #define LSM303D_MAG_DEFAULT_RATE 100 139 #define LSM303D_TIMER_REDUCTION 200 143 class LSM303D :
public device::SPI,
public px4::ScheduledWorkItem
201 void write_reg(
unsigned reg, uint8_t value);
212 void modify_reg(
unsigned reg, uint8_t clearbits, uint8_t setbits);
void check_registers(void)
check key registers for correct values
uint8_t _checked_values[LSM303D_NUM_CHECKED_REGISTERS]
int mag_set_samplerate(unsigned frequency)
Set the LSM303D internal mag sampling frequency.
perf_counter_t _bad_registers
uint8_t _constant_accel_count
void write_checked_reg(unsigned reg, uint8_t value)
Write a register in the LSM303D, updating _checked_values.
Definition of geo / math functions to perform geodesic calculations.
PX4Accelerometer _px4_accel
void modify_reg(unsigned reg, uint8_t clearbits, uint8_t setbits)
Modify a register in the LSM303D.
uint8_t read_reg(unsigned reg)
Read a register from the LSM303D.
Namespace encapsulating all device framework classes, functions and data.
int accel_set_onchip_lowpass_filter_bandwidth(unsigned bandwidth)
Set the LSM303D on-chip anti-alias filter bandwith.
int accel_set_samplerate(unsigned frequency)
Set the LSM303D internal accel sampling frequency.
void print_info()
Diagnostics - print some basic information about the driver.
perf_counter_t _accel_sample_perf
perf_counter_t _bad_values
#define LSM303D_ACCEL_DEFAULT_RATE
Rotation
Enum for board and external compass rotations.
unsigned _call_accel_interval
void write_reg(unsigned reg, uint8_t value)
Write a register in the LSM303D.
unsigned _call_mag_interval
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
perf_counter_t _accel_duplicates
LSM303D(int bus, uint32_t device, enum Rotation rotation)
#define LSM303D_MAG_DEFAULT_RATE
perf_counter_t _mag_sample_perf
void measureAccelerometer()
Fetch accel measurements from the sensor and update the report ring.
int accel_set_range(unsigned max_g)
Set the LSM303D accel measurement range.
hrt_abstime _mag_last_measure
__EXPORT int lsm303d_main(int argc, char *argv[])
static constexpr int LSM303D_NUM_CHECKED_REGISTERS
int mag_set_range(unsigned max_g)
Set the LSM303D mag measurement range.
void disable_i2c()
disable I2C on the chip
void measureMagnetometer()
Fetch mag measurements from the sensor and update the report ring.
Performance measuring tools.