37 #define DIR_WRITE 0x80 57 SPI(
"ADIS16477", nullptr, bus, device,
SPIDEV_MODE3, 1000000),
58 ScheduledWorkItem(MODULE_NAME,
px4::device_bus_to_wq(get_device_id())),
64 #ifdef GPIO_SPI1_RESET_ADIS16477 66 px4_arch_configgpio(GPIO_SPI1_RESET_ADIS16477);
67 #endif // GPIO_SPI1_RESET_ADIS16477 94 PX4_DEBUG(
"SPI setup failed");
105 #ifdef GPIO_SPI1_RESET_ADIS16477 107 px4_arch_gpiowrite(GPIO_SPI1_RESET_ADIS16477, 0);
112 px4_arch_gpiowrite(GPIO_SPI1_RESET_ADIS16477, 1);
118 #endif // GPIO_SPI1_RESET_ADIS16477 125 static constexpr uint16_t MSC_CTRL_DEFAULT = 0x00C1;
130 if (msc_ctrl != MSC_CTRL_DEFAULT) {
131 PX4_ERR(
"invalid setup, MSC_CTRL=%#X", msc_ctrl);
137 static constexpr uint16_t FILT_CTRL_SETUP = 0x0004;
143 if (filt_ctrl != FILT_CTRL_SETUP) {
144 PX4_ERR(
"invalid setup, FILT_CTRL=%#X", filt_ctrl);
151 static constexpr uint16_t DEC_RATE_SETUP = 0x0001;
157 if (dec_rate != DEC_RATE_SETUP) {
158 PX4_ERR(
"invalid setup, DEC_RATE=%#X", dec_rate);
171 for (
int i = 0; i < 5; i++) {
175 PX4_DEBUG(
"PRODUCT: %X", product_id);
181 PX4_ERR(
"probe attempt %d: self test failed, resetting", i);
186 PX4_ERR(
"probe attempt %d: read product id failed, resetting", i);
208 if (diag_stat != 0) {
209 PX4_ERR(
"DIAG_STAT: %#X", diag_stat);
219 PX4_DEBUG(
"self test sensor");
230 if (diag_stat != 0) {
231 PX4_ERR(
"DIAG_STAT: %#X", diag_stat);
243 cmd[0] = ((reg |
DIR_READ) << 8) & 0xff00;
244 transferhword(cmd,
nullptr, 1);
246 transferhword(
nullptr, cmd, 1);
258 transfer(cmd, cmd,
sizeof(cmd));
266 cmd[0] = ((reg |
DIR_WRITE) << 8) | (0x00ff & value);
267 cmd[1] = (((reg + 0x1) |
DIR_WRITE) << 8) | ((0xff00 & value) >> 8);
269 transferhword(cmd,
nullptr, 1);
271 transferhword(cmd + 1,
nullptr, 1);
278 #ifdef GPIO_SPI1_DRDY1_ADIS16477 293 #ifdef GPIO_SPI1_DRDY1_ADIS16477 295 px4_arch_gpiosetevent(GPIO_SPI1_DRDY1_ADIS16477,
false,
false,
false,
nullptr,
nullptr);
329 static_assert(
sizeof(adis_report) == (176 / 8),
"ADIS16477 report not 176 bits");
333 if (
OK != transferhword((uint16_t *)&adis_report, ((uint16_t *)&adis_report),
sizeof(adis_report) /
sizeof(uint16_t))) {
350 uint8_t *checksum_helper = (uint8_t *)&adis_report.diag_stat;
352 uint8_t checksum = 0;
354 for (
int i = 0; i < 18; i++) {
355 checksum += checksum_helper[i];
358 if (adis_report.checksum != checksum) {
359 PX4_DEBUG(
"adis_report.checksum: %X vs calculated: %X", adis_report.checksum, checksum);
368 if (adis_report.diag_stat != 0) {
376 const float temperature = adis_report.temp * 0.1f;
380 _px4_accel.
update(timestamp_sample, adis_report.accel_x, adis_report.accel_y, adis_report.accel_z);
381 _px4_gyro.
update(timestamp_sample, adis_report.gyro_x, adis_report.gyro_y, adis_report.gyro_z);
static constexpr uint16_t PROD_ID_ADIS16477
measure the time elapsed performing an event
void set_sample_rate(unsigned rate)
static constexpr uint8_t MSC_CTRL
static constexpr uint8_t T_STALL
void update(hrt_abstime timestamp, float x, float y, float z)
static constexpr uint8_t DEC_RATE
perf_counter_t _sample_perf
void write_reg16(uint8_t reg, uint16_t value)
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
#define DRV_ACC_DEVTYPE_ADIS16477
ADIS16477(int bus, uint32_t device, enum Rotation rotation=ROTATION_NONE)
void update(hrt_abstime timestamp, float x, float y, float z)
void write_reg(uint8_t reg, uint8_t value)
void perf_count(perf_counter_t handle)
Count a performance event.
static constexpr uint8_t FILT_CTRL
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 DIAG_STAT
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 > &)
uint16_t read_reg16(uint8_t reg)
static int data_ready_interrupt(int irq, void *context, void *arg)
void perf_end(perf_counter_t handle)
End a performance event.
PX4Accelerometer _px4_accel
static constexpr uint8_t GLOB_CMD
void start()
Start automatic measurement.
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
void set_scale(float scale)
int measure()
Fetch measurements from the sensor and update the report buffers.
static constexpr uint32_t ADIS16477_DEFAULT_RATE
void set_temperature(float temperature)
void stop()
Stop automatic measurement.
void perf_print_counter(perf_counter_t handle)
Print one performance counter to stdout.
perf_counter_t _bad_transfers
#define DRV_GYR_DEVTYPE_ADIS16477
static constexpr uint8_t PROD_ID
void set_scale(float scale)
void set_device_type(uint8_t devtype)
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).