AP_Compass_BMM150.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (C) 2016 Intel Corporation. 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. class AP_Compass_BMM150 : public AP_Compass_Backend
  25. {
  26. public:
  27. static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev, enum Rotation rotation);
  28. void read() override;
  29. static constexpr const char *name = "BMM150";
  30. private:
  31. AP_Compass_BMM150(AP_HAL::OwnPtr<AP_HAL::Device> dev, enum Rotation rotation);
  32. /**
  33. * Device periodic callback to read data from the sensor.
  34. */
  35. bool init();
  36. void _update();
  37. bool _load_trim_values();
  38. int16_t _compensate_xy(int16_t xy, uint32_t rhall, int32_t txy1, int32_t txy2);
  39. int16_t _compensate_z(int16_t z, uint32_t rhall);
  40. AP_HAL::OwnPtr<AP_HAL::Device> _dev;
  41. uint8_t _compass_instance;
  42. struct {
  43. int8_t x1;
  44. int8_t y1;
  45. int8_t x2;
  46. int8_t y2;
  47. uint16_t z1;
  48. int16_t z2;
  49. int16_t z3;
  50. int16_t z4;
  51. uint8_t xy1;
  52. int8_t xy2;
  53. uint16_t xyz1;
  54. } _dig;
  55. uint32_t _last_read_ms;
  56. AP_HAL::Util::perf_counter_t _perf_err;
  57. enum Rotation _rotation;
  58. };