CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Compass/AP_Compass_QMC5883P.h
Views: 1798
1
/*
2
* This file is free software: you can redistribute it and/or modify it
3
* under the terms of the GNU General Public License as published by the
4
* Free Software Foundation, either version 3 of the License, or
5
* (at your option) any later version.
6
*
7
* This file is distributed in the hope that it will be useful, but
8
* WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
* See the GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License along
13
* with this program. If not, see <http://www.gnu.org/licenses/>.
14
*
15
* Driver by Lokesh Ramina, Jan 2022
16
*/
17
#pragma once
18
19
#include <AP_HAL/AP_HAL.h>
20
#include <AP_HAL/I2CDevice.h>
21
#include <AP_Math/AP_Math.h>
22
23
#include "AP_Compass_config.h"
24
25
#ifdef AP_COMPASS_QMC5883P_ENABLED
26
27
#include "AP_Compass.h"
28
#include "AP_Compass_Backend.h"
29
30
#ifndef HAL_COMPASS_QMC5883P_I2C_ADDR
31
#define HAL_COMPASS_QMC5883P_I2C_ADDR 0x2C
32
#endif
33
34
/*
35
setup default orientations
36
*/
37
#ifndef HAL_COMPASS_QMC5883P_ORIENTATION_EXTERNAL
38
#define HAL_COMPASS_QMC5883P_ORIENTATION_EXTERNAL ROTATION_ROLL_180
39
#endif
40
41
#ifndef HAL_COMPASS_QMC5883P_ORIENTATION_INTERNAL
42
#define HAL_COMPASS_QMC5883P_ORIENTATION_INTERNAL ROTATION_ROLL_180_YAW_270
43
#endif
44
45
class AP_Compass_QMC5883P : public AP_Compass_Backend
46
{
47
public:
48
static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev,
49
bool force_external,
50
enum Rotation rotation);
51
52
void read() override;
53
54
static constexpr const char *name = "QMC5883P";
55
56
private:
57
AP_Compass_QMC5883P(AP_HAL::OwnPtr<AP_HAL::Device> dev,
58
bool force_external,
59
enum Rotation rotation);
60
61
void _dump_registers();
62
bool _check_whoami();
63
void timer();
64
bool init();
65
66
AP_HAL::OwnPtr<AP_HAL::Device> _dev;
67
68
enum Rotation _rotation;
69
uint8_t _instance;
70
bool _force_external:1;
71
};
72
73
#endif // AP_COMPASS_QMC5883P_ENABLED
74
75