AP_Compass_IST8308.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (C) 2018 Lucas De Marchi. 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 2 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_IST8308_I2C_ADDR
  25. #define HAL_COMPASS_IST8308_I2C_ADDR 0x0C
  26. #endif
  27. class AP_Compass_IST8308 : 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 = "IST8308";
  35. private:
  36. AP_Compass_IST8308(AP_HAL::OwnPtr<AP_HAL::Device> dev,
  37. bool force_external,
  38. enum Rotation rotation);
  39. void timer();
  40. bool init();
  41. AP_HAL::OwnPtr<AP_HAL::Device> _dev;
  42. AP_HAL::Util::perf_counter_t _perf_xfer_err;
  43. enum Rotation _rotation;
  44. uint8_t _instance;
  45. bool _force_external;
  46. };