Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Compass/AP_Compass_QMC5883L.h
9660 views
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
19
#include "AP_Compass_config.h"
20
21
#if AP_COMPASS_QMC5883L_ENABLED
22
23
#include <AP_Common/AP_Common.h>
24
#include <AP_HAL/AP_HAL.h>
25
#include <AP_HAL/Device.h>
26
#include <AP_Math/AP_Math.h>
27
28
#include "AP_Compass.h"
29
#include "AP_Compass_Backend.h"
30
31
#ifndef HAL_COMPASS_QMC5883L_I2C_ADDR
32
#define HAL_COMPASS_QMC5883L_I2C_ADDR 0x0D
33
#endif
34
35
/*
36
setup default orientations
37
*/
38
#ifndef HAL_COMPASS_QMC5883L_ORIENTATION_EXTERNAL
39
#define HAL_COMPASS_QMC5883L_ORIENTATION_EXTERNAL ROTATION_ROLL_180
40
#endif
41
42
#ifndef HAL_COMPASS_QMC5883L_ORIENTATION_INTERNAL
43
#define HAL_COMPASS_QMC5883L_ORIENTATION_INTERNAL ROTATION_ROLL_180_YAW_270
44
#endif
45
46
class AP_Compass_QMC5883L : public AP_Compass_Backend
47
{
48
public:
49
static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::Device> dev,
50
bool force_external,
51
enum Rotation rotation);
52
53
void read() override;
54
55
static constexpr const char *name = "QMC5883L";
56
57
private:
58
AP_Compass_QMC5883L(AP_HAL::OwnPtr<AP_HAL::Device> dev,
59
bool force_external,
60
enum Rotation rotation);
61
62
void _dump_registers();
63
bool _check_whoami();
64
void timer();
65
bool init();
66
67
AP_HAL::OwnPtr<AP_HAL::Device> _dev;
68
69
enum Rotation _rotation;
70
bool _force_external;
71
};
72
73
#endif // AP_COMPASS_QMC5883L_ENABLED
74
75