AP_OpticalFlow_Pixart.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include "OpticalFlow.h"
  3. #include <AP_HAL/utility/OwnPtr.h>
  4. class AP_OpticalFlow_Pixart : public OpticalFlow_backend
  5. {
  6. public:
  7. /// constructor
  8. AP_OpticalFlow_Pixart(const char *devname, OpticalFlow &_frontend);
  9. // init - initialise the sensor
  10. void init() override {}
  11. // update - read latest values from sensor and fill in x,y and totals.
  12. void update(void) override;
  13. // detect if the sensor is available
  14. static AP_OpticalFlow_Pixart *detect(const char *devname, OpticalFlow &_frontend);
  15. private:
  16. AP_HAL::OwnPtr<AP_HAL::SPIDevice> _dev;
  17. enum {
  18. PIXART_3900=0,
  19. PIXART_3901=1
  20. } model;
  21. struct RegData {
  22. uint8_t reg;
  23. uint8_t value;
  24. };
  25. struct PACKED MotionBurst {
  26. uint8_t motion;
  27. uint8_t observation;
  28. int16_t delta_x;
  29. int16_t delta_y;
  30. uint8_t squal;
  31. uint8_t rawdata_sum;
  32. uint8_t max_raw;
  33. uint8_t min_raw;
  34. uint8_t shutter_upper;
  35. uint8_t shutter_lower;
  36. } burst;
  37. struct {
  38. Vector2l sum;
  39. uint32_t last_frame_us;
  40. uint32_t sum_us;
  41. Vector2f gyro;
  42. } integral;
  43. static const uint8_t srom_data[];
  44. static const uint8_t srom_id;
  45. static const RegData init_data_3900[];
  46. static const RegData init_data_3901_1[];
  47. static const RegData init_data_3901_2[];
  48. const float flow_pixel_scaling = 1.26e-3;
  49. // setup sensor
  50. bool setup_sensor(void);
  51. void reg_write(uint8_t reg, uint8_t value);
  52. uint8_t reg_read(uint8_t reg);
  53. int16_t reg_read16s(uint8_t reg);
  54. uint16_t reg_read16u(uint8_t reg);
  55. void srom_download(void);
  56. void load_configuration(const RegData *init_data, uint16_t n);
  57. void timer(void);
  58. void motion_burst(void);
  59. uint32_t last_burst_us;
  60. uint32_t last_update_ms;
  61. };