2015-08-17 21:09:52 -03:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
|
|
|
|
#include "Compass.h"
|
|
|
|
#include "AP_Compass_Backend.h"
|
|
|
|
|
|
|
|
class AP_Compass_LSM303D : public AP_Compass_Backend
|
|
|
|
{
|
|
|
|
private:
|
2015-09-11 10:39:29 -03:00
|
|
|
bool _read_raw(void);
|
2015-08-17 21:09:52 -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);
|
|
|
|
bool _data_ready();
|
|
|
|
bool _hardware_init(void);
|
|
|
|
void _collect_samples();
|
|
|
|
void _update();
|
2015-09-11 10:39:29 -03:00
|
|
|
void _disable_i2c(void);
|
|
|
|
uint8_t _mag_set_range(uint8_t max_ga);
|
|
|
|
uint8_t _mag_set_samplerate(uint16_t frequency);
|
2015-08-17 21:09:52 -03:00
|
|
|
|
2015-09-11 11:22:56 -03:00
|
|
|
AP_HAL::SPIDeviceDriver *_spi = nullptr;
|
|
|
|
AP_HAL::Semaphore *_spi_sem = nullptr;
|
|
|
|
AP_HAL::DigitalSource *_drdy_pin_m = nullptr;
|
|
|
|
float _scaling[3] = { 0 };
|
|
|
|
bool _initialised = false;
|
|
|
|
|
|
|
|
int16_t _mag_x = 0;
|
|
|
|
int16_t _mag_y = 0;
|
|
|
|
int16_t _mag_z = 0;
|
2015-09-14 10:22:23 -03:00
|
|
|
float _mag_x_accum = 0.0f;
|
|
|
|
float _mag_y_accum = 0.0f;
|
|
|
|
float _mag_z_accum = 0.0f;
|
2015-09-11 11:22:56 -03:00
|
|
|
uint32_t _last_accum_time = 0;
|
|
|
|
uint32_t _last_update_timestamp = 0;
|
|
|
|
uint8_t _accum_count = 0;
|
|
|
|
|
|
|
|
uint8_t _compass_instance = 0;
|
|
|
|
uint8_t _product_id = 0;
|
|
|
|
|
|
|
|
uint8_t _mag_range_ga = 0;
|
|
|
|
uint8_t _mag_samplerate = 0;
|
|
|
|
uint8_t _reg7_expected = 0;
|
|
|
|
float _mag_range_scale = 0.0f;
|
2015-08-17 21:09:52 -03:00
|
|
|
|
|
|
|
public:
|
|
|
|
AP_Compass_LSM303D(Compass &compass);
|
|
|
|
bool init(void);
|
|
|
|
void read(void);
|
2015-09-14 10:22:23 -03:00
|
|
|
uint32_t get_dev_id();
|
2015-08-17 21:09:52 -03:00
|
|
|
|
|
|
|
// detect the sensor
|
|
|
|
static AP_Compass_Backend *detect_spi(Compass &compass);
|
|
|
|
};
|