AP_Compass_IST8310.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (C) 2016 Emlid Ltd. All rights reserved.
  3. *
  4. * This file is free software: you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This file is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. * See the GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #pragma once
  18. #include <AP_Common/AP_Common.h>
  19. #include <AP_HAL/AP_HAL.h>
  20. #include <AP_HAL/I2CDevice.h>
  21. #include <AP_Math/AP_Math.h>
  22. #include "AP_Compass.h"
  23. #include "AP_Compass_Backend.h"
  24. #ifndef HAL_COMPASS_IST8310_I2C_ADDR
  25. #define HAL_COMPASS_IST8310_I2C_ADDR 0x0E
  26. #endif
  27. class AP_Compass_IST8310 : public AP_Compass_Backend
  28. {
  29. public:
  30. static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev,
  31. bool force_external,
  32. enum Rotation rotation);
  33. void read() override;
  34. static constexpr const char *name = "IST8310";
  35. private:
  36. AP_Compass_IST8310(AP_HAL::OwnPtr<AP_HAL::Device> dev,
  37. bool force_external,
  38. enum Rotation rotation);
  39. void timer();
  40. bool init();
  41. void start_conversion();
  42. AP_HAL::OwnPtr<AP_HAL::Device> _dev;
  43. AP_HAL::Device::PeriodicHandle _periodic_handle;
  44. AP_HAL::Util::perf_counter_t _perf_xfer_err;
  45. AP_HAL::Util::perf_counter_t _perf_bad_data;
  46. enum Rotation _rotation;
  47. uint8_t _instance;
  48. bool _ignore_next_sample;
  49. bool _force_external;
  50. };