AP_InertialSensor_LSM9DS1.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #include <AP_HAL/AP_HAL.h>
  3. #include <AP_HAL/SPIDevice.h>
  4. #include "AP_InertialSensor.h"
  5. #include "AP_InertialSensor_Backend.h"
  6. /* enable debug to see a register dump on startup */
  7. #define LSM9DS1_DEBUG 0
  8. class AP_InertialSensor_LSM9DS1 : public AP_InertialSensor_Backend
  9. {
  10. public:
  11. virtual ~AP_InertialSensor_LSM9DS1() { }
  12. void start(void) override;
  13. bool update() override;
  14. static AP_InertialSensor_Backend *probe(AP_InertialSensor &imu,
  15. AP_HAL::OwnPtr<AP_HAL::SPIDevice> dev,
  16. enum Rotation rotation);
  17. private:
  18. AP_InertialSensor_LSM9DS1(AP_InertialSensor &imu,
  19. AP_HAL::OwnPtr<AP_HAL::SPIDevice> dev,
  20. int drdy_pin_num_xg,
  21. enum Rotation rotation);
  22. static AP_InertialSensor_Backend *detect(AP_InertialSensor &imu);
  23. struct PACKED sensor_raw_data {
  24. int16_t x;
  25. int16_t y;
  26. int16_t z;
  27. };
  28. enum accel_scale {
  29. A_SCALE_2G = 0,
  30. A_SCALE_4G,
  31. A_SCALE_8G,
  32. A_SCALE_16G
  33. };
  34. void _poll_data();
  35. void _fifo_reset();
  36. bool _init_sensor();
  37. bool _hardware_init();
  38. void _gyro_init();
  39. void _accel_init();
  40. void _set_gyro_scale();
  41. void _set_accel_scale(accel_scale scale);
  42. uint8_t _register_read(uint8_t reg);
  43. void _register_write(uint8_t reg, uint8_t val, bool checked=false);
  44. void _read_data_transaction_x(uint16_t samples);
  45. void _read_data_transaction_g(uint16_t samples);
  46. #if LSM9DS1_DEBUG
  47. void _dump_registers();
  48. #endif
  49. AP_HAL::OwnPtr<AP_HAL::SPIDevice> _dev;
  50. AP_HAL::Semaphore *_spi_sem;
  51. AP_HAL::DigitalSource * _drdy_pin_xg;
  52. float _gyro_scale;
  53. float _accel_scale;
  54. int _drdy_pin_num_xg;
  55. uint8_t _gyro_instance;
  56. uint8_t _accel_instance;
  57. enum Rotation _rotation;
  58. };