65 #include <px4_platform_common/getopt.h> 66 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp> 85 #if defined(PX4_I2C_MPU6050_ADDR) || \ 86 defined(PX4_I2C_MPU6000_ADDR) || \ 87 defined(PX4_I2C_ICM_20608_G_ADDR) 99 #define DIR_WRITE 0x00 102 #define MPUREG_WHOAMI 0x75 103 #define MPUREG_SMPLRT_DIV 0x19 104 #define MPUREG_CONFIG 0x1A 105 #define MPUREG_GYRO_CONFIG 0x1B 106 #define MPUREG_ACCEL_CONFIG 0x1C 107 #define MPUREG_FIFO_EN 0x23 108 #define MPUREG_INT_PIN_CFG 0x37 109 #define MPUREG_INT_ENABLE 0x38 110 #define MPUREG_INT_STATUS 0x3A 111 #define MPUREG_ACCEL_XOUT_H 0x3B 112 #define MPUREG_ACCEL_XOUT_L 0x3C 113 #define MPUREG_ACCEL_YOUT_H 0x3D 114 #define MPUREG_ACCEL_YOUT_L 0x3E 115 #define MPUREG_ACCEL_ZOUT_H 0x3F 116 #define MPUREG_ACCEL_ZOUT_L 0x40 117 #define MPUREG_TEMP_OUT_H 0x41 118 #define MPUREG_TEMP_OUT_L 0x42 119 #define MPUREG_GYRO_XOUT_H 0x43 120 #define MPUREG_GYRO_XOUT_L 0x44 121 #define MPUREG_GYRO_YOUT_H 0x45 122 #define MPUREG_GYRO_YOUT_L 0x46 123 #define MPUREG_GYRO_ZOUT_H 0x47 124 #define MPUREG_GYRO_ZOUT_L 0x48 125 #define MPUREG_USER_CTRL 0x6A 126 #define MPUREG_PWR_MGMT_1 0x6B 127 #define MPUREG_PWR_MGMT_2 0x6C 128 #define MPUREG_FIFO_COUNTH 0x72 129 #define MPUREG_FIFO_COUNTL 0x73 130 #define MPUREG_FIFO_R_W 0x74 131 #define MPUREG_PRODUCT_ID 0x0C 132 #define MPUREG_TRIM1 0x0D 133 #define MPUREG_TRIM2 0x0E 134 #define MPUREG_TRIM3 0x0F 135 #define MPUREG_TRIM4 0x10 136 #define MPU_GYRO_DLPF_CFG_256HZ_NOLPF2 0x00 // delay: 0.98ms 137 #define MPU_GYRO_DLPF_CFG_188HZ 0x01 // delay: 1.9ms 138 #define MPU_GYRO_DLPF_CFG_98HZ 0x02 // delay: 2.8ms 139 #define MPU_GYRO_DLPF_CFG_42HZ 0x03 // delay: 4.8ms 140 #define MPU_GYRO_DLPF_CFG_20HZ 0x04 // delay: 8.3ms 141 #define MPU_GYRO_DLPF_CFG_10HZ 0x05 // delay: 13.4ms 142 #define MPU_GYRO_DLPF_CFG_5HZ 0x06 // delay: 18.6ms 143 #define MPU_GYRO_DLPF_CFG_2100HZ_NOLPF 0x07 144 #define MPU_DLPF_CFG_MASK 0x07 147 #define BIT_SLEEP 0x40 148 #define BIT_H_RESET 0x80 149 #define BITS_CLKSEL 0x07 150 #define MPU_CLK_SEL_PLLGYROX 0x01 151 #define MPU_CLK_SEL_PLLGYROZ 0x03 152 #define MPU_EXT_SYNC_GYROX 0x02 153 #define BITS_GYRO_ST_X 0x80 154 #define BITS_GYRO_ST_Y 0x40 155 #define BITS_GYRO_ST_Z 0x20 156 #define BITS_FS_250DPS 0x00 157 #define BITS_FS_500DPS 0x08 158 #define BITS_FS_1000DPS 0x10 159 #define BITS_FS_2000DPS 0x18 160 #define BITS_FS_MASK 0x18 161 #define BIT_INT_ANYRD_2CLEAR 0x10 162 #define BIT_RAW_RDY_EN 0x01 163 #define BIT_I2C_IF_DIS 0x10 164 #define BIT_INT_STATUS_DATA 0x01 166 #define MPU_WHOAMI_6000 0x68 167 #define ICM_WHOAMI_20602 0x12 168 #define ICM_WHOAMI_20608 0xaf 169 #define ICM_WHOAMI_20689 0x98 173 #define ICMREG_ACCEL_CONFIG2 0x1D 174 #define ICM_ACC_DLPF_CFG_1046HZ_NOLPF 0x00 175 #define ICM_ACC_DLPF_CFG_218HZ 0x01 176 #define ICM_ACC_DLPF_CFG_99HZ 0x02 177 #define ICM_ACC_DLPF_CFG_44HZ 0x03 178 #define ICM_ACC_DLPF_CFG_21HZ 0x04 179 #define ICM_ACC_DLPF_CFG_10HZ 0x05 180 #define ICM_ACC_DLPF_CFG_5HZ 0x06 181 #define ICM_ACC_DLPF_CFG_420HZ 0x07 186 #define MPUREG_ICM_UNDOC1 0x11 187 #define MPUREG_ICM_UNDOC1_VALUE 0xc9 192 #define ICM20602_REV_01 1 193 #define ICM20602_REV_02 2 197 #define ICM20608_REV_FF 0xff // In the past, was thought to be not returning a value. But seem repeatable. 201 #define ICM20689_REV_FE 0xfe 202 #define ICM20689_REV_03 0x03 203 #define ICM20689_REV_04 0x04 208 #define MPU6000ES_REV_C4 0x14 209 #define MPU6000ES_REV_C5 0x15 210 #define MPU6000ES_REV_D6 0x16 211 #define MPU6000ES_REV_D7 0x17 212 #define MPU6000ES_REV_D8 0x18 213 #define MPU6000_REV_C4 0x54 214 #define MPU6000_REV_C5 0x55 215 #define MPU6000_REV_D6 0x56 216 #define MPU6000_REV_D7 0x57 217 #define MPU6000_REV_D8 0x58 218 #define MPU6000_REV_D9 0x59 219 #define MPU6000_REV_D10 0x5A 220 #define MPU6050_REV_D8 0x28 // TODO:Need verification 222 #define MPU6000_ACCEL_DEFAULT_RANGE_G 16 224 #define MPU6000_GYRO_DEFAULT_RANGE_G 8 225 #define MPU6000_GYRO_DEFAULT_RATE 1000 228 #define MPU6000_DEFAULT_ONCHIP_FILTER_FREQ 98 230 #pragma pack(push, 1) 248 #define MPU_MAX_READ_BUFFER_SIZE (sizeof(MPUReport) + 1) 249 #define MPU_MAX_WRITE_BUFFER_SIZE (2) 257 #define MPU6000_LOW_BUS_SPEED 0 258 #define MPU6000_HIGH_BUS_SPEED 0x8000 259 # define MPU6000_IS_HIGH_SPEED(r) ((r) & MPU6000_HIGH_BUS_SPEED) 260 # define MPU6000_REG(r) ((r) &~MPU6000_HIGH_BUS_SPEED) 261 # define MPU6000_SET_SPEED(r, s) ((r)|(s)) 262 # define MPU6000_HIGH_SPEED_OP(r) MPU6000_SET_SPEED((r), MPU6000_HIGH_BUS_SPEED) 263 # define MPU6000_LOW_SPEED_OP(r) MPU6000_REG((r)) 273 #define MPU6000_TIMER_REDUCTION 200 299 void print_registers();
301 #ifndef CONSTRAINED_FLASH 307 int factory_self_test();
337 unsigned _call_interval{1000};
342 unsigned _sample_rate{1000};
350 uint8_t _register_wait{0};
351 uint64_t _reset_wait{0};
356 static constexpr
int MPU6000_CHECKED_PRODUCT_ID_INDEX = 0;
357 static constexpr
int MPU6000_NUM_CHECKED_REGISTERS = 10;
372 uint8_t _checked_values[MPU6000_NUM_CHECKED_REGISTERS];
373 uint8_t _checked_next{0};
377 volatile bool _in_factory_test{
false};
380 uint16_t _last_accel[3] {};
381 bool _got_duplicate{
false};
409 uint16_t read_reg16(
unsigned reg);
418 int write_reg(
unsigned reg, uint8_t value);
429 void modify_reg(
unsigned reg, uint8_t clearbits, uint8_t setbits);
437 void write_checked_reg(
unsigned reg, uint8_t value);
445 int set_accel_range(
unsigned max_g);
450 void _set_dlpf_filter(uint16_t frequency_hz);
451 void _set_icm_acc_dlpf_filter(uint16_t frequency_hz);
456 void _set_sample_rate(
unsigned desired_sample_rate_hz);
461 void check_registers(
void);
device::Device * MPU6000_SPI_interface(int bus, int device_type, bool external_bus)
perf_counter_t _reset_retries
#define MPUREG_GYRO_CONFIG
Definition of geo / math functions to perform geodesic calculations.
bool is_mpu_device()
is_mpu_device
#define MPU6000_LOW_BUS_SPEED
A set of useful macros for enhanced runtime and compile time error detection and warning suppression...
#define MPUREG_PWR_MGMT_1
int reset(enum LPS22HB_BUS busid)
Reset the driver.
#define MPUREG_SMPLRT_DIV
perf_counter_t _sample_perf
bool is_icm_device()
is_icm_device
#define MPUREG_PRODUCT_ID
PX4Accelerometer _px4_accel
void test_error()
trigger an error
Report conversation within the mpu, including command byte and interrupt status.
#define MPUREG_ACCEL_CONFIG
void init()
Activates/configures the hardware registers.
perf_counter_t _bad_registers
Definition of commonly used conversions.
Rotation
Enum for board and external compass rotations.
perf_counter_t _bad_transfers
int MPU6000_probe(device::Device *dev, int device_type)
#define MPUREG_INT_PIN_CFG
device::Device * MPU6000_I2C_interface(int bus, int device_type, bool external_bus)
perf_counter_t _duplicates
Fundamental base class for all physical drivers (I2C, SPI).
device::Device * _interface
#define MPUREG_ICM_UNDOC1
#define MPUREG_INT_ENABLE
static constexpr uint8_t _checked_registers[]
Performance measuring tools.
Base class for devices connected via I2C.