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_MMC5xx3.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
#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/I2CDevice.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
uint8_t compass_instance;
68
bool force_external;
69
Vector3f offset;
70
uint16_t measure_count;
71
bool have_initial_offset;
72
uint32_t refill_start_ms;
73
uint32_t last_sample_ms;
74
75
uint8_t data0[6];
76
77
enum Rotation rotation;
78
};
79
80
#endif // AP_COMPASS_MMC5XX3_ENABLED
81
82