Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_Compass/AP_Compass_BMM350.h
Views: 1798
/*1* This file is free software: you can redistribute it and/or modify it2* under the terms of the GNU General Public License as published by the3* Free Software Foundation, either version 3 of the License, or4* (at your option) any later version.5*6* This file is distributed in the hope that it will be useful, but7* WITHOUT ANY WARRANTY; without even the implied warranty of8* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.9* See the GNU General Public License for more details.10*11* You should have received a copy of the GNU General Public License along12* with this program. If not, see <http://www.gnu.org/licenses/>.13*/1415#pragma once1617#include "AP_Compass_config.h"1819#if AP_COMPASS_BMM350_ENABLED2021#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>2526#include "AP_Compass.h"27#include "AP_Compass_Backend.h"2829#define BMM350_I2C_ADDR_MIN 0x1430#define BMM350_I2C_ADDR_MAX 0x17313233class AP_Compass_BMM350 : public AP_Compass_Backend34{35public:36static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::Device> dev,37bool force_external,38enum Rotation rotation);3940void read() override;4142static constexpr const char *name = "BMM350";4344private:45AP_Compass_BMM350(AP_HAL::OwnPtr<AP_HAL::Device> dev,46bool force_external,47enum Rotation rotation);4849AP_HAL::OwnPtr<AP_HAL::Device> _dev;5051/**52* @brief BMM350 offset/sensitivity coefficient structure53*/54struct vector4f55{56float x; // x axis57float y; // y axis58float z; // z axis59float temp; // Temperature60};6162/**63* @brief BMM350 magnetometer cross axis compensation structure64*/65struct cross_axis66{67float cross_x_y;68float cross_y_x;69float cross_z_x;70float cross_z_y;71};7273/**74* @brief BMM350 magnetometer compensate structure75*/76struct mag_compensate77{78struct vector4f offset_coef; // Offset coefficient79struct vector4f sensit_coef; // Sensitivity coefficient80Vector3f tco; // Temperature coefficient of the offset81Vector3f tcs; // Temperature coefficient of the sensitivity82float t0_reading; // Initialize T0_reading parameter83struct cross_axis cross_axis; // Cross axis compensation84};8586enum power_mode87{88POWER_MODE_SUSPEND = 0,89POWER_MODE_NORMAL = 1,90POWER_MODE_FORCED = 3,91POWER_MODE_FORCED_FAST = 492};9394/**95* Device periodic callback to read data from the sensor.96*/97bool init();98void timer();99bool read_otp_data();100bool wait_pmu_cmd_ready(const uint8_t cmd, const uint32_t timeout);101bool mag_reset_and_wait();102bool set_power_mode(const enum power_mode mode);103bool read_bytes(const uint8_t reg, uint8_t *out, const uint16_t read_len);104105uint8_t _compass_instance;106bool _force_external;107enum Rotation _rotation;108struct mag_compensate _mag_comp; // Structure for mag compensate109};110111#endif // AP_COMPASS_BMM350_ENABLED112113114