AP_Compass_QMC5883L.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_QMC5883L_I2C_ADDR
  25. #define HAL_COMPASS_QMC5883L_I2C_ADDR 0x0D
  26. #endif
  27. /*
  28. setup default orientations
  29. */
  30. #ifndef HAL_COMPASS_QMC5883L_ORIENTATION_EXTERNAL
  31. #define HAL_COMPASS_QMC5883L_ORIENTATION_EXTERNAL ROTATION_ROLL_180
  32. #endif
  33. #ifndef HAL_COMPASS_QMC5883L_ORIENTATION_INTERNAL
  34. #define HAL_COMPASS_QMC5883L_ORIENTATION_INTERNAL ROTATION_ROLL_180_YAW_270
  35. #endif
  36. class AP_Compass_QMC5883L : public AP_Compass_Backend
  37. {
  38. public:
  39. static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev,
  40. bool force_external,
  41. enum Rotation rotation);
  42. void read() override;
  43. static constexpr const char *name = "QMC5883L";
  44. private:
  45. AP_Compass_QMC5883L(AP_HAL::OwnPtr<AP_HAL::Device> dev,
  46. bool force_external,
  47. enum Rotation rotation);
  48. void _dump_registers();
  49. bool _check_whoami();
  50. void timer();
  51. bool init();
  52. AP_HAL::OwnPtr<AP_HAL::Device> _dev;
  53. enum Rotation _rotation;
  54. uint8_t _instance;
  55. bool _force_external:1;
  56. };