mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-28 19:32:36 +08:00
refactor bmm150: use driver base class
This commit is contained in:
@@ -12,7 +12,7 @@ ist8310 -X start
|
||||
qmc5883 -X start
|
||||
|
||||
# Internal Mag I2C bus roll 180, yaw 90
|
||||
bmm150 -R 10 start
|
||||
bmm150 -I -R 10 start
|
||||
|
||||
# Onboard I2C baros
|
||||
bmp280 -I start
|
||||
|
||||
@@ -27,7 +27,7 @@ hmc5883 -C -T -X start
|
||||
qmc5883 -X start
|
||||
|
||||
# Possible internal compass
|
||||
bmm150 start
|
||||
bmm150 -I start
|
||||
|
||||
# Possible internal Baro
|
||||
bmp388 -I start
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,36 @@
|
||||
#ifndef BMM150_HPP_
|
||||
#define BMM150_HPP_
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2020 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
|
||||
@@ -19,8 +50,7 @@
|
||||
#include <px4_platform_common/log.h>
|
||||
|
||||
#include <perf/perf_counter.h>
|
||||
#include <systemlib/err.h>
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
#include <systemlib/conversions.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
@@ -37,10 +67,6 @@
|
||||
#include <lib/conversion/rotation.h>
|
||||
|
||||
|
||||
#define BMM150_DEVICE_PATH_MAG "/dev/bmm150_i2c_int"
|
||||
|
||||
#define BMM150_DEVICE_PATH_MAG_EXT "/dev/bmm150_i2c_ext"
|
||||
|
||||
#define BMM150_SLAVE_ADDRESS 0x10
|
||||
|
||||
#define BMM150_BUS_SPEED 1000*100
|
||||
@@ -191,35 +217,33 @@ struct bmm150_data {
|
||||
};
|
||||
|
||||
|
||||
class BMM150 : public device::I2C, public px4::ScheduledWorkItem
|
||||
class BMM150 : public device::I2C, public I2CSPIDriver<BMM150>
|
||||
{
|
||||
public:
|
||||
BMM150(int bus, const char *path, enum Rotation rotation);
|
||||
BMM150(I2CSPIBusOption bus_option, const int bus, int bus_frequency, enum Rotation rotation);
|
||||
virtual ~BMM150();
|
||||
|
||||
virtual int init();
|
||||
virtual ssize_t read(struct file *filp, char *buffer, size_t buflen);
|
||||
virtual int ioctl(struct file *filp, int cmd, unsigned long arg);
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
/**
|
||||
* Stop automatic measurement.
|
||||
*/
|
||||
void stop();
|
||||
int init() override;
|
||||
ssize_t read(struct file *filp, char *buffer, size_t buflen) override;
|
||||
int ioctl(struct file *filp, int cmd, unsigned long arg) override;
|
||||
|
||||
/**
|
||||
* Diagnostics - print some basic information about the driver.
|
||||
*/
|
||||
void print_info();
|
||||
void print_status() override;
|
||||
|
||||
void print_registers();
|
||||
|
||||
void RunImpl();
|
||||
|
||||
void custom_method(const BusCLIArguments &cli) override;
|
||||
|
||||
protected:
|
||||
virtual int probe();
|
||||
int probe() override;
|
||||
|
||||
private:
|
||||
|
||||
bool _running;
|
||||
|
||||
/* altitude conversion calibration */
|
||||
unsigned _call_interval;
|
||||
|
||||
@@ -277,8 +301,6 @@ private:
|
||||
int measure(); //start measure
|
||||
int collect(); //get results and publish
|
||||
|
||||
void Run() override;
|
||||
|
||||
/**
|
||||
* Read the specified number of bytes from BMM150.
|
||||
*
|
||||
@@ -363,5 +385,3 @@ private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* BMM150_HPP_ */
|
||||
|
||||
Reference in New Issue
Block a user