2015-08-17 21:09:52 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2016-03-21 12:01:53 -03:00
|
|
|
#include <AP_HAL/Device.h>
|
2015-08-17 21:09:52 -03:00
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
|
2016-03-10 20:41:18 -04:00
|
|
|
#include "AP_Compass.h"
|
2015-08-17 21:09:52 -03:00
|
|
|
#include "AP_Compass_Backend.h"
|
|
|
|
|
|
|
|
class AP_Compass_LSM303D : public AP_Compass_Backend
|
|
|
|
{
|
|
|
|
public:
|
2018-08-06 19:21:27 -03:00
|
|
|
static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::Device> dev,
|
2016-11-09 07:34:19 -04:00
|
|
|
enum Rotation = ROTATION_NONE);
|
2016-03-21 10:13:42 -03:00
|
|
|
|
2016-05-13 13:47:05 -03:00
|
|
|
static constexpr const char *name = "LSM303D";
|
|
|
|
|
2016-03-21 10:13:42 -03:00
|
|
|
void read() override;
|
|
|
|
|
2016-03-21 12:01:53 -03:00
|
|
|
virtual ~AP_Compass_LSM303D() { }
|
|
|
|
|
2016-03-21 10:13:42 -03:00
|
|
|
private:
|
2018-08-06 19:21:27 -03:00
|
|
|
AP_Compass_LSM303D(AP_HAL::OwnPtr<AP_HAL::Device> dev);
|
2015-08-17 21:09:52 -03:00
|
|
|
|
2016-11-09 07:34:19 -04:00
|
|
|
bool init(enum Rotation rotation);
|
2016-03-21 10:13:42 -03:00
|
|
|
uint8_t _register_read(uint8_t reg);
|
|
|
|
void _register_write(uint8_t reg, uint8_t val);
|
|
|
|
void _register_modify(uint8_t reg, uint8_t clearbits, uint8_t setbits);
|
2016-03-21 12:01:53 -03:00
|
|
|
bool _block_read(uint8_t reg, uint8_t *buf, uint32_t size);
|
|
|
|
|
|
|
|
bool _read_sample();
|
|
|
|
|
2016-03-21 10:13:42 -03:00
|
|
|
bool _data_ready();
|
|
|
|
bool _hardware_init();
|
2017-01-13 15:26:14 -04:00
|
|
|
void _update();
|
2016-03-21 10:13:42 -03:00
|
|
|
void _disable_i2c();
|
|
|
|
bool _mag_set_range(uint8_t max_ga);
|
|
|
|
bool _mag_set_samplerate(uint16_t frequency);
|
|
|
|
|
|
|
|
AP_HAL::DigitalSource *_drdy_pin_m;
|
2016-03-21 12:01:53 -03:00
|
|
|
AP_HAL::OwnPtr<AP_HAL::Device> _dev;
|
2016-03-21 10:13:42 -03:00
|
|
|
|
|
|
|
float _mag_range_scale;
|
|
|
|
int16_t _mag_x;
|
|
|
|
int16_t _mag_y;
|
|
|
|
int16_t _mag_z;
|
|
|
|
|
|
|
|
uint8_t _compass_instance;
|
|
|
|
bool _initialised;
|
|
|
|
|
|
|
|
uint8_t _mag_range_ga;
|
|
|
|
uint8_t _mag_samplerate;
|
|
|
|
uint8_t _reg7_expected;
|
2015-08-17 21:09:52 -03:00
|
|
|
};
|