54 ScheduledWorkItem(MODULE_NAME,
px4::device_bus_to_wq(this->get_device_id())),
146 uint8_t retries = 10;
195 if ((
int)frequency == 0) {
199 if (frequency <= 25 / 32) {
203 }
else if (frequency <= 25 / 16) {
207 }
else if (frequency <= 25 / 8) {
211 }
else if (frequency <= 25 / 4) {
215 }
else if (frequency <= 25 / 2) {
219 }
else if (frequency <= 25) {
223 }
else if (frequency <= 50) {
227 }
else if (frequency <= 100) {
231 }
else if (frequency <= 200) {
235 }
else if (frequency <= 400) {
239 }
else if (frequency <= 800) {
243 }
else if (frequency > 800) {
262 if ((
int)frequency == 0) {
266 if (frequency <= 25) {
270 }
else if (frequency <= 50) {
274 }
else if (frequency <= 100) {
278 }
else if (frequency <= 200) {
282 }
else if (frequency <= 400) {
286 }
else if (frequency <= 800) {
290 }
else if (frequency <= 1600) {
294 }
else if (frequency > 1600) {
311 bandwidth = bandwidth;
348 ::printf(
"error triggered\n");
355 uint8_t cmd[2] = { (uint8_t)(reg |
DIR_READ), 0};
357 transfer(cmd, cmd,
sizeof(cmd));
365 uint8_t cmd[3] = { (uint8_t)(reg |
DIR_READ), 0, 0 };
367 transfer(cmd, cmd,
sizeof(cmd));
369 return (uint16_t)(cmd[1] << 8) | cmd[2];
380 transfer(cmd,
nullptr,
sizeof(cmd));
423 }
else if (max_g <= 4) {
428 }
else if (max_g <= 8) {
433 }
else if (max_g <= 16) {
461 if (max_dps <= 125) {
466 }
else if (max_dps <= 250) {
471 }
else if (max_dps <= 500) {
476 }
else if (max_dps <= 1000) {
481 }
else if (max_dps <= 2000) {
597 if (
OK != transfer((uint8_t *)&bmi_report, ((uint8_t *)&bmi_report),
sizeof(bmi_report))) {
603 if ((!(status & (0x80))) && (!(status & (0x04)))) {
618 report.temp = ((temp_h << 8) + temp_l);
622 report.accel_x = bmi_report.accel_x;
623 report.accel_y = bmi_report.accel_y;
624 report.accel_z = bmi_report.accel_z;
626 report.gyro_x = bmi_report.gyro_x;
627 report.gyro_y = bmi_report.gyro_y;
628 report.gyro_z = bmi_report.gyro_z;
630 if (report.accel_x == 0 &&
631 report.accel_y == 0 &&
632 report.accel_z == 0 &&
634 report.gyro_x == 0 &&
635 report.gyro_y == 0 &&
636 report.gyro_z == 0) {
666 const float temperature = 23.0f + report.temp * 1.0f / 512.0f;
688 _px4_accel.
update(timestamp_sample, bmi_report.accel_x, bmi_report.accel_y, bmi_report.accel_z);
689 _px4_gyro.
update(timestamp_sample, bmi_report.gyro_x, bmi_report.gyro_y, bmi_report.gyro_z);
713 ::printf(
"reg %02x:%02x should be %02x\n",
720 ::printf(
"reg %02x:%02x was bad %02x\n",
734 printf(
"BMI160 registers\n");
736 for (uint8_t reg = 0x40; reg <= 0x47; reg++) {
738 printf(
"%02x:%02x ", (
unsigned)reg, (
unsigned)v);
#define BMI_GYRO_RANGE_2000_DPS
#define BMI_GYRO_RANGE_500_DPS
#define BMI160_ACCEL_DEFAULT_RANGE_G
uint16_t read_reg16(unsigned reg)
void start()
Start automatic measurement.
#define BMI_GYRO_RATE_200
static struct vehicle_status_s status
uint8_t _checked_bad[BMI160_NUM_CHECKED_REGISTERS]
#define BMI_ACCEL_RATE_25_16
measure the time elapsed performing an event
void set_sample_rate(unsigned rate)
int accel_set_sample_rate(float desired_sample_rate_hz)
#define BMI160_GYRO_DEFAULT_RATE
void write_reg(unsigned reg, uint8_t value)
Write a register in the BMI160.
uint8_t _checked_values[BMI160_NUM_CHECKED_REGISTERS]
#define BMI_ACCEL_RATE_25_8
void update(hrt_abstime timestamp, float x, float y, float z)
#define BMI_GYRO_RATE_3200
int gyro_set_sample_rate(float desired_sample_rate_hz)
#define BMI_ACCEL_RATE_25
#define BMI_ACCEL_RANGE_2_G
void measure()
Fetch measurements from the sensor and update the report buffers.
#define BMI_ACCEL_RANGE_16_G
void _set_dlpf_filter(uint16_t frequency_hz)
Namespace encapsulating all device framework classes, functions and data.
count the number of times an event occurs
void modify_reg(unsigned reg, uint8_t clearbits, uint8_t setbits)
Modify a register in the BMI160.
void set_device_type(uint8_t devtype)
void stop()
Stop automatic measurement.
#define BMI_ACCEL_RANGE_4_G
static constexpr float CONSTANTS_ONE_G
void set_error_count(uint64_t error_count)
#define BMI_GYRO_NORMAL_MODE
#define BMI_ACCEL_RATE_1600
PX4Accelerometer _px4_accel
#define BMI_ACCEL_RANGE_8_G
#define BMI_GYRO_RANGE_1000_DPS
#define BMI_ACCEL_RATE_25_2
perf_counter_t _sample_perf
perf_counter_t _accel_reads
void update(hrt_abstime timestamp, float x, float y, float z)
void perf_count(perf_counter_t handle)
Count a performance event.
#define BMI160_GYRO_DEFAULT_RANGE_DPS
Report conversation within the BMI160, including command byte and interrupt status.
perf_counter_t _good_transfers
#define BMI_GYRO_BWP_NORMAL
void perf_free(perf_counter_t handle)
Free a counter.
void init()
Activates/configures the hardware registers.
void set_temperature(float temperature)
#define BMI160_TIMER_REDUCTION
Rotation
Enum for board and external compass rotations.
#define BMIREG_INT_OUT_CTRL
void write_checked_reg(unsigned reg, uint8_t value)
Write a register in the BMI160, updating _checked_values.
BMI160(int bus, uint32_t device, enum Rotation rotation)
perf_counter_t _duplicates
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
#define BMI_ACCEL_RATE_100
perf_counter_t _bad_registers
perf_counter_t _gyro_reads
unsigned _dlpf_freq
whoami result
void set_error_count(uint64_t error_count)
void perf_end(perf_counter_t handle)
End a performance event.
#define BMI_ACCEL_NORMAL_MODE
#define BMI_GYRO_RATE_800
#define BMI_ACCEL_RATE_25_32
perf_counter_t _reset_retries
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
#define DRV_GYR_DEVTYPE_BMI160
static constexpr int BMI160_NUM_CHECKED_REGISTERS
void set_scale(float scale)
#define BMI_GYRO_RATE_1600
#define BMI_ACCEL_RATE_25_4
void check_registers(void)
void set_temperature(float temperature)
#define BMI_GYRO_RATE_100
#define BMI_ACCEL_RATE_200
#define BMI_ACCEL_RATE_800
uint8_t read_reg(unsigned reg)
Read a register from the BMI160.
void print_info()
Diagnostics - print some basic information about the driver.
void perf_print_counter(perf_counter_t handle)
Print one performance counter to stdout.
uint64_t perf_event_count(perf_counter_t handle)
Return current event_count.
#define DRV_ACC_DEVTYPE_BMI160
#define BMI_GYRO_RATE_400
#define BMI_GYRO_RANGE_250_DPS
#define BMI_ACCEL_BWP_NORMAL
int set_gyro_range(unsigned max_dps)
#define BMI_GYRO_RANGE_125_DPS
void set_scale(float scale)
perf_counter_t _bad_transfers
#define BMI160_ACCEL_DEFAULT_RATE
#define BMI_ACCEL_RATE_50
#define BMI_ACCEL_RATE_400
void set_device_type(uint8_t devtype)
static const uint8_t _checked_registers[BMI160_NUM_CHECKED_REGISTERS]
int set_accel_range(unsigned max_g)
Set the BMI160 measurement range.
void perf_begin(perf_counter_t handle)
Begin a performance event.
#define DEVICE_DEBUG(FMT,...)
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
#define BMI160_SOFT_RESET