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_BMM150.h
Views: 1798
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
19
#include "AP_Compass_config.h"
20
21
#if AP_COMPASS_BMM150_ENABLED
22
23
#include <AP_Common/AP_Common.h>
24
#include <AP_HAL/AP_HAL.h>
25
#include <AP_HAL/I2CDevice.h>
26
#include <AP_Math/AP_Math.h>
27
28
#include "AP_Compass.h"
29
#include "AP_Compass_Backend.h"
30
31
#define BMM150_I2C_ADDR_MIN 0x10
32
#define BMM150_I2C_ADDR_MAX 0x13
33
34
class AP_Compass_BMM150 : public AP_Compass_Backend
35
{
36
public:
37
static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev, bool force_external, enum Rotation rotation);
38
39
void read() override;
40
41
static constexpr const char *name = "BMM150";
42
43
private:
44
AP_Compass_BMM150(AP_HAL::OwnPtr<AP_HAL::Device> dev, bool force_external, enum Rotation rotation);
45
46
/**
47
* Device periodic callback to read data from the sensor.
48
*/
49
bool init();
50
void _update();
51
bool _load_trim_values();
52
int16_t _compensate_xy(int16_t xy, uint32_t rhall, int32_t txy1, int32_t txy2) const;
53
int16_t _compensate_z(int16_t z, uint32_t rhall) const;
54
55
AP_HAL::OwnPtr<AP_HAL::Device> _dev;
56
57
uint8_t _compass_instance;
58
59
struct {
60
int8_t x1;
61
int8_t y1;
62
int8_t x2;
63
int8_t y2;
64
uint16_t z1;
65
int16_t z2;
66
int16_t z3;
67
int16_t z4;
68
uint8_t xy1;
69
int8_t xy2;
70
uint16_t xyz1;
71
} _dig;
72
73
uint32_t _last_read_ms;
74
enum Rotation _rotation;
75
bool _force_external;
76
};
77
78
#endif // AP_COMPASS_BMM150_ENABLED
79
80