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_LSM303D.h
Views: 1798
1
#pragma once
2
3
#include "AP_Compass_config.h"
4
5
#if AP_COMPASS_LSM303D_ENABLED
6
7
#include <AP_Common/AP_Common.h>
8
#include <AP_HAL/AP_HAL.h>
9
#include <AP_HAL/Device.h>
10
#include <AP_Math/AP_Math.h>
11
12
#include "AP_Compass.h"
13
#include "AP_Compass_Backend.h"
14
15
class AP_Compass_LSM303D : public AP_Compass_Backend
16
{
17
public:
18
static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::Device> dev,
19
enum Rotation rotation);
20
21
static constexpr const char *name = "LSM303D";
22
23
void read() override;
24
25
virtual ~AP_Compass_LSM303D() { }
26
27
private:
28
AP_Compass_LSM303D(AP_HAL::OwnPtr<AP_HAL::Device> dev);
29
30
bool init(enum Rotation rotation);
31
uint8_t _register_read(uint8_t reg);
32
void _register_write(uint8_t reg, uint8_t val);
33
void _register_modify(uint8_t reg, uint8_t clearbits, uint8_t setbits);
34
bool _block_read(uint8_t reg, uint8_t *buf, uint32_t size);
35
36
bool _read_sample();
37
38
bool _data_ready();
39
bool _hardware_init();
40
void _update();
41
void _disable_i2c();
42
bool _mag_set_range(uint8_t max_ga);
43
bool _mag_set_samplerate(uint16_t frequency);
44
45
AP_HAL::DigitalSource *_drdy_pin_m;
46
AP_HAL::OwnPtr<AP_HAL::Device> _dev;
47
48
float _mag_range_scale;
49
int16_t _mag_x;
50
int16_t _mag_y;
51
int16_t _mag_z;
52
53
uint8_t _compass_instance;
54
bool _initialised;
55
56
uint8_t _mag_range_ga;
57
uint8_t _mag_samplerate;
58
uint8_t _reg7_expected;
59
};
60
61
#endif // AP_COMPASS_LSM303D_ENABLED
62
63