Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Compass/AP_Compass_MMC5xx3.h
9316 views
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
#pragma once
16
17
#include "AP_Compass_config.h"
18
19
#if AP_COMPASS_MMC5XX3_ENABLED
20
21
#include <AP_Common/AP_Common.h>
22
#include <AP_HAL/AP_HAL.h>
23
#include <AP_HAL/Device.h>
24
#include <AP_Math/AP_Math.h>
25
26
#include "AP_Compass.h"
27
#include "AP_Compass_Backend.h"
28
29
#ifndef HAL_COMPASS_MMC5xx3_I2C_ADDR
30
# define HAL_COMPASS_MMC5xx3_I2C_ADDR 0x30
31
#endif
32
33
class AP_Compass_MMC5XX3 : public AP_Compass_Backend
34
{
35
public:
36
static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::Device> dev,
37
bool force_external,
38
enum Rotation rotation);
39
40
void read() override;
41
42
static constexpr const char *name = "MMC5983";
43
44
private:
45
AP_Compass_MMC5XX3(AP_HAL::OwnPtr<AP_HAL::Device> dev,
46
bool force_external,
47
enum Rotation rotation);
48
49
AP_HAL::OwnPtr<AP_HAL::Device> dev;
50
51
enum class MMCState {
52
STATE_SET,
53
STATE_SET_MEASURE,
54
STATE_SET_WAIT,
55
STATE_RESET_MEASURE,
56
STATE_RESET_WAIT,
57
STATE_MEASURE,
58
} state;
59
60
/**
61
* Device periodic callback to read data from the sensor.
62
*/
63
bool init();
64
void timer();
65
void accumulate_field(Vector3f &field);
66
67
bool force_external;
68
Vector3f offset;
69
uint16_t measure_count;
70
bool have_initial_offset;
71
uint32_t refill_start_ms;
72
uint32_t last_sample_ms;
73
74
uint8_t data0[6];
75
76
enum Rotation rotation;
77
};
78
79
#endif // AP_COMPASS_MMC5XX3_ENABLED
80
81