37 #define DIR_WRITE 0x80 52 static constexpr uint8_t
CONFIG = 0x0A;
70 SPI(
"ADIS16497", nullptr, bus, device,
SPIDEV_MODE3, 5000000),
71 ScheduledWorkItem(MODULE_NAME,
px4::device_bus_to_wq(get_device_id())),
77 #ifdef GPIO_SPI1_RESET_ADIS16497 79 px4_arch_configgpio(GPIO_SPI1_RESET_ADIS16497);
80 #endif // GPIO_SPI1_RESET_ADIS16497 107 PX4_DEBUG(
"SPI setup failed");
118 #ifdef GPIO_SPI1_RESET_ADIS16497 120 px4_arch_gpiowrite(GPIO_SPI1_RESET_ADIS16497, 0);
125 px4_arch_gpiowrite(GPIO_SPI1_RESET_ADIS16497, 1);
132 #endif // GPIO_SPI1_RESET_ADIS16497 141 static constexpr uint16_t FNCTIO_CTRL_DEFAULT = 0x000D;
149 if (fnctio_ctrl != FNCTIO_CTRL_DEFAULT) {
150 PX4_ERR(
"Invalid setup, FNCTIO_CTRL=%#X", fnctio_ctrl);
155 static constexpr uint16_t CONFIG_DEFAULT = 0x00C0;
163 if (config != CONFIG_DEFAULT) {
164 PX4_ERR(
"Invalid setup, CONFIG=%#X", config);
169 static constexpr uint16_t DEC_RATE_DEFAULT = 0x0003;
177 if (dec_rate != DEC_RATE_DEFAULT) {
178 PX4_ERR(
"Invalid setup, DEC_RATE=%#X", dec_rate);
183 static constexpr uint16_t NULL_CNFG_DEFAULT = 0x0000;
191 if (null_cnfg != NULL_CNFG_DEFAULT) {
192 PX4_ERR(
"Invalid setup, NULL_CNFG=%#X", null_cnfg);
197 static constexpr uint16_t FILTR_BNK_0_SETUP = 0x0000;
198 static constexpr uint16_t FILTR_BNK_1_SETUP = 0x0000;
207 if (filtr_bnk_0 != FILTR_BNK_0_SETUP) {
208 PX4_ERR(
"Invalid setup, FILTR_BNK_0=%#X", filtr_bnk_0);
214 if (filtr_bnk_1 != FILTR_BNK_1_SETUP) {
215 PX4_ERR(
"Invalid setup, FILTR_BNK_1=%#X", filtr_bnk_1);
239 for (
int i = 0; i < 5; i++) {
247 PX4_DEBUG(
"PRODUCT: %X", product_id);
253 PX4_ERR(
"probe attempt %d: self test failed, resetting", i);
258 PX4_ERR(
"probe attempt %d: read product id failed, resetting", i);
285 if (sys_e_flag != 0) {
286 PX4_ERR(
"SYS_E_FLAG: %#X", sys_e_flag);
291 if (diag_sts_flag != 0) {
292 PX4_ERR(
"DIAG_STS: %#X", diag_sts_flag);
306 cmd[0] = ((reg |
DIR_READ) << 8) & 0xff00;
307 transferhword(cmd,
nullptr, 1);
309 transferhword(
nullptr, cmd, 1);
321 transfer(cmd, cmd,
sizeof(cmd));
329 cmd[0] = ((reg |
DIR_WRITE) << 8) | (0x00ff & value);
330 cmd[1] = (((reg + 0x1) |
DIR_WRITE) << 8) | ((0xff00 & value) >> 8);
332 transferhword(cmd,
nullptr, 1);
334 transferhword(cmd + 1,
nullptr, 1);
341 #ifdef GPIO_SPI1_DRDY1_ADIS16497 356 #ifdef GPIO_SPI1_DRDY1_ADIS16497 358 px4_arch_gpiosetevent(GPIO_SPI1_DRDY1_ADIS16497,
false,
false,
false,
nullptr,
nullptr);
392 static_assert(
sizeof(adis_report) == (320 / 8),
"ADIS16497 report not 320 bits");
396 if (
OK != transferhword((uint16_t *)&adis_report, ((uint16_t *)&adis_report),
sizeof(adis_report) /
sizeof(uint16_t))) {
404 static constexpr uint16_t BURST_ID_DEFAULT = 0xA5A5;
406 if (adis_report.BURST_ID != BURST_ID_DEFAULT) {
407 PX4_DEBUG(
"BURST_ID: %#X", adis_report.BURST_ID);
416 if (adis_report.SYS_E_FLAG != 0) {
417 PX4_DEBUG(
"SYS_E_FLAG: %#X", adis_report.SYS_E_FLAG);
425 uint32_t checksum = uint32_t(adis_report.CRC_UPR) << 16 | adis_report.CRC_LWR;
426 uint32_t checksum_calc =
crc32((uint16_t *)&adis_report.SYS_E_FLAG, 15);
428 if (checksum != checksum_calc) {
429 PX4_DEBUG(
"CHECKSUM: %#X vs. calculated: %#X", checksum, checksum_calc);
441 const float temperature = (int16_t(adis_report.TEMP_OUT) * 0.0125f) + 25.0
f;
447 float xraw_f = (int32_t(adis_report.X_ACCEL_OUT) << 16 | adis_report.X_ACCEL_LOW) / 65536.0
f;
448 float yraw_f = (int32_t(adis_report.Y_ACCEL_OUT) << 16 | adis_report.Y_ACCEL_LOW) / 65536.0
f;
449 float zraw_f = (int32_t(adis_report.Z_ACCEL_OUT) << 16 | adis_report.Z_ACCEL_LOW) / 65536.0
f;
454 float xraw_f = (int32_t(adis_report.X_GYRO_OUT) << 16 | adis_report.X_GYRO_LOW) / 65536.0
f;
455 float yraw_f = (int32_t(adis_report.Y_GYRO_OUT) << 16 | adis_report.Y_GYRO_LOW) / 65536.0
f;
456 float zraw_f = (int32_t(adis_report.Z_GYRO_OUT) << 16 | adis_report.Z_GYRO_LOW) / 65536.0
f;
#define DRV_GYR_DEVTYPE_ADIS16497
measure the time elapsed performing an event
void set_sample_rate(unsigned rate)
#define DRV_ACC_DEVTYPE_ADIS16497
void update(hrt_abstime timestamp, float x, float y, float z)
static constexpr uint8_t SYS_E_FLAG
static constexpr uint8_t FNCTIO_CTRL
static constexpr uint8_t RANG_MDL
Namespace encapsulating all device framework classes, functions and data.
count the number of times an event occurs
void set_device_type(uint8_t devtype)
static constexpr float CONSTANTS_ONE_G
void set_error_count(uint64_t error_count)
static constexpr uint8_t DEC_RATE
void write_reg(uint8_t reg, uint8_t value)
static constexpr uint8_t PROD_ID
void update(hrt_abstime timestamp, float x, float y, float z)
static constexpr uint8_t GLOB_CMD
uint32_t crc32(const uint16_t *data, size_t len) const
void perf_count(perf_counter_t handle)
Count a performance event.
static constexpr uint16_t PROD_ID_ADIS16497
void perf_free(perf_counter_t handle)
Free a counter.
void init()
Activates/configures the hardware registers.
void set_temperature(float temperature)
static constexpr uint8_t CONFIG
void set_sample_rate(unsigned rate)
Rotation
Enum for board and external compass rotations.
constexpr T radians(T degrees)
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
perf_counter_t _bad_transfers
static constexpr uint8_t FILTR_BNK_0
void set_error_count(uint64_t error_count)
void perf_end(perf_counter_t handle)
End a performance event.
static constexpr uint8_t GPIO_CTRL
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
static int data_ready_interrupt(int irq, void *context, void *arg)
void stop()
Stop automatic measurement.
void set_scale(float scale)
static constexpr uint8_t NULL_CNFG
void set_temperature(float temperature)
int measure()
Fetch measurements from the sensor and update the report buffers.
static constexpr uint8_t BURST_CMD
static constexpr uint8_t DIAG_STS
perf_counter_t _sample_perf
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.
static constexpr uint8_t PAGE_ID
void write_reg16(uint8_t reg, uint16_t value)
static constexpr uint8_t FILTR_BNK_1
static constexpr uint8_t SYNC_SCALE
void set_scale(float scale)
void set_device_type(uint8_t devtype)
PX4Accelerometer _px4_accel
ADIS16497(int bus, uint32_t device, enum Rotation rotation=ROTATION_NONE)
static constexpr uint8_t T_STALL
void perf_begin(perf_counter_t handle)
Begin a performance event.
static constexpr uint32_t ADIS16497_DEFAULT_RATE
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
uint16_t read_reg16(uint8_t reg)
void start()
Start automatic measurement.