mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-16 05:43:34 +08:00
deprecate df_bmp280_wrapper and replace with in tree bmp280
- deprecate DriverFramework bmp280 driver (df_bmp280_wrapper) - update beaglebone blue and snapdragon flight eagle boards to use in tree bmp280 - update posix (really just linux) and qurt I2C wrappers - tested on beaglebone blue
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2016 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
include_directories(../../../lib/DriverFramework/drivers)
|
||||
|
||||
px4_add_module(
|
||||
MODULE platforms__posix__drivers__df_bmp280_wrapper
|
||||
MAIN df_bmp280_wrapper
|
||||
SRCS
|
||||
df_bmp280_wrapper.cpp
|
||||
DEPENDS
|
||||
git_driverframework
|
||||
df_driver_framework
|
||||
df_bmp280
|
||||
)
|
||||
@@ -1,300 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2016 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file df_bmp280_wrapper.cpp
|
||||
* Lightweight driver to access the BMP280 of the DriverFramework.
|
||||
*
|
||||
* @author Julian Oes <julian@oes.ch>
|
||||
*/
|
||||
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
#include <px4_platform_common/getopt.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <perf/perf_counter.h>
|
||||
#include <systemlib/err.h>
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <drivers/drv_baro.h>
|
||||
|
||||
#include <board_config.h>
|
||||
//#include <mathlib/math/filter/LowPassFilter2p.hpp>
|
||||
|
||||
#include <bmp280/BMP280.hpp>
|
||||
#include <DevMgr.hpp>
|
||||
|
||||
|
||||
extern "C" { __EXPORT int df_bmp280_wrapper_main(int argc, char *argv[]); }
|
||||
|
||||
using namespace DriverFramework;
|
||||
|
||||
|
||||
class DfBmp280Wrapper : public BMP280
|
||||
{
|
||||
public:
|
||||
DfBmp280Wrapper();
|
||||
~DfBmp280Wrapper();
|
||||
|
||||
|
||||
/**
|
||||
* Start automatic measurement.
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int start();
|
||||
|
||||
/**
|
||||
* Stop automatic measurement.
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int stop();
|
||||
|
||||
private:
|
||||
int _publish(struct baro_sensor_data &data);
|
||||
|
||||
orb_advert_t _baro_topic;
|
||||
|
||||
int _baro_orb_class_instance;
|
||||
|
||||
perf_counter_t _baro_sample_perf;
|
||||
|
||||
};
|
||||
|
||||
DfBmp280Wrapper::DfBmp280Wrapper() :
|
||||
BMP280(BARO_DEVICE_PATH),
|
||||
_baro_topic(nullptr),
|
||||
_baro_orb_class_instance(-1),
|
||||
_baro_sample_perf(perf_alloc(PC_ELAPSED, "df_baro_read"))
|
||||
{
|
||||
}
|
||||
|
||||
DfBmp280Wrapper::~DfBmp280Wrapper()
|
||||
{
|
||||
perf_free(_baro_sample_perf);
|
||||
}
|
||||
|
||||
int DfBmp280Wrapper::start()
|
||||
{
|
||||
/* Init device and start sensor. */
|
||||
int ret = init();
|
||||
|
||||
if (ret != 0) {
|
||||
PX4_ERR("BMP280 init fail: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = BMP280::start();
|
||||
|
||||
if (ret != 0) {
|
||||
PX4_ERR("BMP280 start fail: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(__DF_BBBLUE)
|
||||
PX4_INFO("BMP280 started");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DfBmp280Wrapper::stop()
|
||||
{
|
||||
/* Stop sensor. */
|
||||
int ret = BMP280::stop();
|
||||
|
||||
if (ret != 0) {
|
||||
PX4_ERR("BMP280 stop fail: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DfBmp280Wrapper::_publish(struct baro_sensor_data &data)
|
||||
{
|
||||
perf_begin(_baro_sample_perf);
|
||||
|
||||
sensor_baro_s baro_report = {};
|
||||
baro_report.timestamp = hrt_absolute_time();
|
||||
baro_report.error_count = data.error_counter;
|
||||
|
||||
baro_report.pressure = data.pressure_pa / 100.0f; // to mbar
|
||||
baro_report.temperature = data.temperature_c;
|
||||
|
||||
// TODO: when is this ever blocked?
|
||||
if (!(m_pub_blocked)) {
|
||||
|
||||
if (_baro_topic == nullptr) {
|
||||
_baro_topic = orb_advertise_multi(ORB_ID(sensor_baro), &baro_report,
|
||||
&_baro_orb_class_instance, ORB_PRIO_DEFAULT);
|
||||
|
||||
} else {
|
||||
orb_publish(ORB_ID(sensor_baro), _baro_topic, &baro_report);
|
||||
}
|
||||
}
|
||||
|
||||
perf_end(_baro_sample_perf);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
namespace df_bmp280_wrapper
|
||||
{
|
||||
|
||||
DfBmp280Wrapper *g_dev = nullptr;
|
||||
|
||||
int start(/* enum Rotation rotation */);
|
||||
int stop();
|
||||
int info();
|
||||
void usage();
|
||||
|
||||
int start(/*enum Rotation rotation*/)
|
||||
{
|
||||
g_dev = new DfBmp280Wrapper(/*rotation*/);
|
||||
|
||||
if (g_dev == nullptr) {
|
||||
PX4_ERR("failed instantiating DfBmp280Wrapper object");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = g_dev->start();
|
||||
|
||||
if (ret != 0) {
|
||||
PX4_ERR("DfBmp280Wrapper start failed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Open the IMU sensor
|
||||
DevHandle h;
|
||||
DevMgr::getHandle(BARO_DEVICE_PATH, h);
|
||||
|
||||
if (!h.isValid()) {
|
||||
DF_LOG_INFO("Error: unable to obtain a valid handle for the receiver at: %s (%d)",
|
||||
BARO_DEVICE_PATH, h.getError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
DevMgr::releaseHandle(h);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stop()
|
||||
{
|
||||
if (g_dev == nullptr) {
|
||||
PX4_ERR("driver not running");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ret = g_dev->stop();
|
||||
|
||||
if (ret != 0) {
|
||||
PX4_ERR("driver could not be stopped");
|
||||
return ret;
|
||||
}
|
||||
|
||||
delete g_dev;
|
||||
g_dev = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a little info about the driver.
|
||||
*/
|
||||
int
|
||||
info()
|
||||
{
|
||||
if (g_dev == nullptr) {
|
||||
PX4_ERR("driver not running");
|
||||
return 1;
|
||||
}
|
||||
|
||||
PX4_DEBUG("state @ %p", g_dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
PX4_WARN("Usage: df_bmp280_wrapper 'start', 'info', 'stop'");
|
||||
}
|
||||
|
||||
} // namespace df_bmp280_wrapper
|
||||
|
||||
|
||||
int
|
||||
df_bmp280_wrapper_main(int argc, char *argv[])
|
||||
{
|
||||
int ret = 0;
|
||||
int myoptind = 1;
|
||||
|
||||
if (argc <= 1) {
|
||||
df_bmp280_wrapper::usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *verb = argv[myoptind];
|
||||
|
||||
|
||||
if (!strcmp(verb, "start")) {
|
||||
ret = df_bmp280_wrapper::start();
|
||||
}
|
||||
|
||||
else if (!strcmp(verb, "stop")) {
|
||||
ret = df_bmp280_wrapper::stop();
|
||||
}
|
||||
|
||||
else if (!strcmp(verb, "info")) {
|
||||
ret = df_bmp280_wrapper::info();
|
||||
}
|
||||
|
||||
else {
|
||||
df_bmp280_wrapper::usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2012-2017 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2012-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
|
||||
@@ -62,17 +62,20 @@
|
||||
#define DRV_MAG_DEVTYPE_QMC5883 0x08
|
||||
#define DRV_MAG_DEVTYPE_AK09916 0x09
|
||||
#define DRV_DEVTYPE_ICM20948 0x0A
|
||||
|
||||
#define DRV_ACC_DEVTYPE_LSM303D 0x11
|
||||
#define DRV_ACC_DEVTYPE_BMA180 0x12
|
||||
#define DRV_ACC_DEVTYPE_MPU6000 0x13
|
||||
#define DRV_ACC_DEVTYPE_ACCELSIM 0x14
|
||||
#define DRV_ACC_DEVTYPE_MPU9250 0x16
|
||||
#define DRV_ACC_DEVTYPE_BMI160 0x17
|
||||
|
||||
#define DRV_GYR_DEVTYPE_MPU6000 0x21
|
||||
#define DRV_GYR_DEVTYPE_L3GD20 0x22
|
||||
#define DRV_GYR_DEVTYPE_GYROSIM 0x23
|
||||
#define DRV_GYR_DEVTYPE_MPU9250 0x24
|
||||
#define DRV_GYR_DEVTYPE_BMI160 0x25
|
||||
|
||||
#define DRV_RNG_DEVTYPE_MB12XX 0x31
|
||||
#define DRV_RNG_DEVTYPE_LL40LS 0x32
|
||||
#define DRV_ACC_DEVTYPE_MPU6050 0x33
|
||||
@@ -92,12 +95,13 @@
|
||||
#define DRV_ACC_DEVTYPE_BMI055 0x41
|
||||
#define DRV_GYR_DEVTYPE_BMI055 0x42
|
||||
#define DRV_MAG_DEVTYPE_BMM150 0x43
|
||||
#define DRV_BARO_DEVTYPE_BMP285 0x44
|
||||
|
||||
#define DRV_DIFF_PRESS_DEVTYPE_ETS3 0x45
|
||||
#define DRV_DIFF_PRESS_DEVTYPE_MS4525 0x46
|
||||
#define DRV_DIFF_PRESS_DEVTYPE_MS5525 0x47
|
||||
#define DRV_DIFF_PRESS_DEVTYPE_SDP31 0x48
|
||||
#define DRV_DIFF_PRESS_DEVTYPE_SDP32 0x49
|
||||
|
||||
#define DRV_DIFF_PRESS_DEVTYPE_SDP33 0x50
|
||||
#define DRV_BARO_DEVTYPE_MPL3115A2 0x51
|
||||
#define DRV_ACC_DEVTYPE_FXOS8701C 0x52
|
||||
@@ -108,6 +112,7 @@
|
||||
#define DRV_GYR_DEVTYPE_ADIS16448 0x57
|
||||
#define DRV_BARO_DEVTYPE_LPS22HB 0x58
|
||||
#define DRV_ACC_DEVTYPE_ADIS16477 0x59
|
||||
|
||||
#define DRV_GYR_DEVTYPE_ADIS16477 0x60
|
||||
#define DRV_ACC_DEVTYPE_LSM303AGR 0x61
|
||||
#define DRV_MAG_DEVTYPE_LSM303AGR 0x62
|
||||
|
||||
@@ -487,9 +487,6 @@ start(int argc, char *argv[])
|
||||
while (1) {
|
||||
const int busses_to_try[] = {
|
||||
PX4_I2C_BUS_EXPANSION,
|
||||
#ifdef PX4_I2C_BUS_ESC
|
||||
PX4_I2C_BUS_ESC,
|
||||
#endif
|
||||
#ifdef PX4_I2C_BUS_ONBOARD
|
||||
PX4_I2C_BUS_ONBOARD,
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2012-2015 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2012-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
|
||||
@@ -32,7 +32,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file i2c.cpp
|
||||
* @file I2C.cpp
|
||||
*
|
||||
* Base class for devices attached via the I2C bus.
|
||||
*
|
||||
@@ -42,6 +42,8 @@
|
||||
|
||||
#include "I2C.hpp"
|
||||
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
|
||||
namespace device
|
||||
{
|
||||
/*
|
||||
@@ -169,19 +171,19 @@ out:
|
||||
int
|
||||
I2C::transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const unsigned recv_len)
|
||||
{
|
||||
px4_i2c_msg_t msgv[2];
|
||||
unsigned msgs;
|
||||
int ret = PX4_ERROR;
|
||||
unsigned retry_count = 0;
|
||||
|
||||
if (_dev == nullptr) {
|
||||
PX4_ERR("I2C device not opened");
|
||||
return 1;
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
do {
|
||||
DEVICE_DEBUG("transfer out %p/%u in %p/%u", send, send_len, recv, recv_len);
|
||||
msgs = 0;
|
||||
|
||||
px4_i2c_msg_t msgv[2] {};
|
||||
unsigned msgs = 0;
|
||||
|
||||
if (send_len > 0) {
|
||||
msgv[msgs].frequency = _bus_clocks[get_device_bus() - 1];
|
||||
@@ -205,10 +207,15 @@ I2C::transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = I2C_TRANSFER(_dev, &msgv[0], msgs);
|
||||
int ret_transfer = I2C_TRANSFER(_dev, &msgv[0], msgs);
|
||||
|
||||
/* success */
|
||||
if (ret == PX4_OK) {
|
||||
if (ret_transfer != 0) {
|
||||
DEVICE_DEBUG("I2C transfer failed, result %d", ret_transfer);
|
||||
ret = PX4_ERROR;
|
||||
|
||||
} else {
|
||||
// success
|
||||
ret = PX4_OK;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2012-2019 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2016-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
|
||||
@@ -32,7 +32,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file i2c.cpp
|
||||
* @file I2C.cpp
|
||||
*
|
||||
* Base class for devices attached via the I2C bus.
|
||||
*
|
||||
@@ -109,6 +109,7 @@ out:
|
||||
|
||||
if ((ret != OK) && !(_fd < 0)) {
|
||||
::close(_fd);
|
||||
_fd = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -117,19 +118,19 @@ out:
|
||||
int
|
||||
I2C::transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const unsigned recv_len)
|
||||
{
|
||||
struct i2c_msg msgv[2];
|
||||
unsigned msgs;
|
||||
int ret = PX4_ERROR;
|
||||
unsigned retry_count = 0;
|
||||
|
||||
if (_fd < 0) {
|
||||
PX4_ERR("I2C device not opened");
|
||||
return 1;
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
do {
|
||||
DEVICE_DEBUG("transfer out %p/%u in %p/%u", send, send_len, recv, recv_len);
|
||||
msgs = 0;
|
||||
|
||||
unsigned msgs = 0;
|
||||
struct i2c_msg msgv[2] {};
|
||||
|
||||
if (send_len > 0) {
|
||||
msgv[msgs].addr = get_device_address();
|
||||
@@ -151,24 +152,19 @@ I2C::transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
struct i2c_rdwr_ioctl_data packets;
|
||||
|
||||
i2c_rdwr_ioctl_data packets{};
|
||||
packets.msgs = msgv;
|
||||
|
||||
packets.nmsgs = msgs;
|
||||
|
||||
ret = ::ioctl(_fd, I2C_RDWR, (unsigned long)&packets);
|
||||
int ret_ioctl = ::ioctl(_fd, I2C_RDWR, (unsigned long)&packets);
|
||||
|
||||
if (ret == -1) {
|
||||
if (ret_ioctl == -1) {
|
||||
DEVICE_DEBUG("I2C transfer failed");
|
||||
ret = PX4_ERROR;
|
||||
|
||||
} else {
|
||||
// success
|
||||
ret = PX4_OK;
|
||||
}
|
||||
|
||||
/* success */
|
||||
if (ret == PX4_OK) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
|
||||
* Copyright (C) 2016-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
|
||||
@@ -32,7 +32,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file i2c.h
|
||||
* @file I2C.hpp
|
||||
*
|
||||
* Base class for devices connected via I2C.
|
||||
*/
|
||||
@@ -44,11 +44,6 @@
|
||||
|
||||
#include <px4_platform_common/i2c.h>
|
||||
|
||||
#ifdef __PX4_LINUX
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
#endif
|
||||
|
||||
namespace device __EXPORT
|
||||
{
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2012-2015 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2016-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
|
||||
@@ -32,7 +32,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file i2c.cpp
|
||||
* @file I2C.cpp
|
||||
*
|
||||
* Base class for devices attached via the I2C bus.
|
||||
*
|
||||
@@ -42,13 +42,14 @@
|
||||
|
||||
#include "I2C.hpp"
|
||||
|
||||
#include "dev_fs_lib_i2c.h"
|
||||
#include <dev_fs_lib_i2c.h>
|
||||
|
||||
namespace device
|
||||
{
|
||||
|
||||
I2C::I2C(const char *name, const char *devname, const int bus, const uint16_t address, const uint32_t frequency) :
|
||||
CDev(name, devname)
|
||||
CDev(name, devname),
|
||||
_frequency(frequency)
|
||||
{
|
||||
DEVICE_DEBUG("I2C::I2C name = %s devname = %s", name, devname);
|
||||
// fill in _device_id fields for a I2C device
|
||||
@@ -70,26 +71,43 @@ I2C::~I2C()
|
||||
int
|
||||
I2C::init()
|
||||
{
|
||||
// Assume the driver set the desired bus frequency. There is no standard
|
||||
// way to set it from user space.
|
||||
|
||||
// do base class init, which will create device node, etc
|
||||
int ret = CDev::init();
|
||||
|
||||
if (ret != PX4_OK) {
|
||||
DEVICE_DEBUG("CDev::init failed");
|
||||
return ret;
|
||||
}
|
||||
int ret = PX4_ERROR;
|
||||
|
||||
// Open the actual I2C device
|
||||
char dev_path[16];
|
||||
char dev_path[16] {};
|
||||
snprintf(dev_path, sizeof(dev_path), "/dev/iic-%i", get_device_bus());
|
||||
_fd = ::open(dev_path, O_RDWR);
|
||||
|
||||
if (_fd < 0) {
|
||||
PX4_ERR("could not open %s", dev_path);
|
||||
px4_errno = errno;
|
||||
return PX4_ERROR;
|
||||
DEVICE_DEBUG("failed to init I2C");
|
||||
ret = -ENOENT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
// call the probe function to check whether the device is present
|
||||
ret = probe();
|
||||
|
||||
if (ret != OK) {
|
||||
DEVICE_DEBUG("probe failed");
|
||||
goto out;
|
||||
}
|
||||
|
||||
// do base class init, which will create device node, etc
|
||||
ret = CDev::init();
|
||||
|
||||
if (ret != OK) {
|
||||
DEVICE_DEBUG("cdev init failed");
|
||||
goto out;
|
||||
}
|
||||
|
||||
// tell the world where we are
|
||||
DEVICE_LOG("on I2C bus %d at 0x%02x", get_device_bus(), get_device_address());
|
||||
|
||||
out:
|
||||
|
||||
if ((ret != OK) && !(_fd < 0)) {
|
||||
::close(_fd);
|
||||
_fd = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -98,21 +116,50 @@ I2C::init()
|
||||
int
|
||||
I2C::transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const unsigned recv_len)
|
||||
{
|
||||
dspal_i2c_ioctl_combined_write_read ioctl_write_read{};
|
||||
int ret = PX4_ERROR;
|
||||
unsigned retry_count = 0;
|
||||
|
||||
ioctl_write_read.write_buf = (uint8_t *)send;
|
||||
ioctl_write_read.write_buf_len = send_len;
|
||||
ioctl_write_read.read_buf = recv;
|
||||
ioctl_write_read.read_buf_len = recv_len;
|
||||
|
||||
int bytes_read = ::ioctl(_fd, I2C_IOCTL_RDWR, &ioctl_write_read);
|
||||
|
||||
if (bytes_read != (ssize_t)recv_len) {
|
||||
PX4_ERR("read register reports a read of %d bytes, but attempted to read %d bytes", bytes_read, recv_len);
|
||||
return -1;
|
||||
if (_fd < 0) {
|
||||
PX4_ERR("I2C device not opened");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
return 0;
|
||||
do {
|
||||
DEVICE_DEBUG("transfer out %p/%u in %p/%u", send, send_len, recv, recv_len);
|
||||
|
||||
dspal_i2c_ioctl_slave_config slave_config{};
|
||||
slave_config.slave_address = get_device_address();
|
||||
slave_config.bus_frequency_in_khz = _frequency / 1000;
|
||||
slave_config.byte_transer_timeout_in_usecs = 10000; // 10 ms
|
||||
int ret_config = ::ioctl(_fd, I2C_IOCTL_SLAVE, &slave_config);
|
||||
|
||||
if (ret_config < 0) {
|
||||
DEVICE_DEBUG("Could not set slave config, result: %d", ret_config);
|
||||
}
|
||||
|
||||
|
||||
dspal_i2c_ioctl_combined_write_read ioctl_write_read{};
|
||||
|
||||
ioctl_write_read.write_buf = (uint8_t *)send;
|
||||
ioctl_write_read.write_buf_len = send_len;
|
||||
ioctl_write_read.read_buf = recv;
|
||||
ioctl_write_read.read_buf_len = recv_len;
|
||||
|
||||
int bytes_read = ::ioctl(_fd, I2C_IOCTL_RDWR, &ioctl_write_read);
|
||||
|
||||
if (bytes_read != (int)recv_len) {
|
||||
DEVICE_DEBUG("I2C transfer failed, bytes read %d", bytes_read);
|
||||
ret = PX4_ERROR;
|
||||
|
||||
} else {
|
||||
// success
|
||||
ret = PX4_OK;
|
||||
break;
|
||||
}
|
||||
|
||||
} while (retry_count++ < _retries);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace device
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
|
||||
* Copyright (C) 2016-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
|
||||
@@ -32,7 +32,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file i2c.h
|
||||
* @file I2C.hpp
|
||||
*
|
||||
* Base class for devices connected via I2C.
|
||||
*/
|
||||
@@ -44,11 +44,6 @@
|
||||
|
||||
#include <px4_platform_common/i2c.h>
|
||||
|
||||
#ifdef __PX4_LINUX
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
#endif
|
||||
|
||||
namespace device __EXPORT
|
||||
{
|
||||
|
||||
@@ -109,6 +104,7 @@ protected:
|
||||
virtual bool external() const override { return px4_i2c_bus_external(_device_id.devid_s.bus); }
|
||||
|
||||
private:
|
||||
uint32_t _frequency{0};
|
||||
int _fd{-1};
|
||||
|
||||
};
|
||||
|
||||
@@ -53,8 +53,6 @@ if (NOT ${PX4_PLATFORM} STREQUAL "qurt")
|
||||
simulator_mavlink.cpp)
|
||||
endif()
|
||||
|
||||
add_subdirectory(ledsim)
|
||||
|
||||
px4_add_module(
|
||||
MODULE modules__simulator
|
||||
MAIN simulator
|
||||
@@ -70,7 +68,6 @@ px4_add_module(
|
||||
git_mavlink_v2
|
||||
battery
|
||||
conversion
|
||||
drivers__ledsim
|
||||
git_ecl
|
||||
ecl_geo
|
||||
drivers_accelerometer
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2015 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
px4_add_library(drivers__ledsim led.cpp)
|
||||
target_link_libraries(drivers__ledsim PRIVATE drivers__led)
|
||||
@@ -1,135 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2013 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file led.cpp
|
||||
*
|
||||
* LED driver.
|
||||
*/
|
||||
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <drivers/drv_board_led.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "VirtDevObj.hpp"
|
||||
|
||||
using namespace DriverFramework;
|
||||
|
||||
/*
|
||||
* Ideally we'd be able to get these from up_internal.h,
|
||||
* but since we want to be able to disable the NuttX use
|
||||
* of leds for system indication at will and there is no
|
||||
* separate switch, we need to build independent of the
|
||||
* CONFIG_ARCH_LEDS configuration switch.
|
||||
*/
|
||||
__BEGIN_DECLS
|
||||
extern void led_init();
|
||||
extern void led_on(int led);
|
||||
extern void led_off(int led);
|
||||
extern void led_toggle(int led);
|
||||
__END_DECLS
|
||||
|
||||
class LED : public VirtDevObj
|
||||
{
|
||||
public:
|
||||
LED();
|
||||
~LED() override = default;
|
||||
|
||||
int init() override;
|
||||
int devIOCTL(unsigned long cmd, unsigned long arg) override;
|
||||
|
||||
protected:
|
||||
void _measure() override {}
|
||||
};
|
||||
|
||||
LED::LED() :
|
||||
VirtDevObj("led", "/dev/ledsim", LED_BASE_DEVICE_PATH, 0)
|
||||
{
|
||||
// force immediate init/device registration
|
||||
init();
|
||||
}
|
||||
|
||||
int
|
||||
LED::init()
|
||||
{
|
||||
int ret = VirtDevObj::init();
|
||||
|
||||
if (ret == 0) {
|
||||
led_init();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
LED::devIOCTL(unsigned long cmd, unsigned long arg)
|
||||
{
|
||||
int result = OK;
|
||||
|
||||
switch (cmd) {
|
||||
case LED_ON:
|
||||
led_on(arg);
|
||||
break;
|
||||
|
||||
case LED_OFF:
|
||||
led_off(arg);
|
||||
break;
|
||||
|
||||
case LED_TOGGLE:
|
||||
led_toggle(arg);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
result = VirtDevObj::devIOCTL(cmd, arg);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
LED *gLED;
|
||||
}
|
||||
|
||||
void
|
||||
drv_led_start(void)
|
||||
{
|
||||
if (gLED == nullptr) {
|
||||
gLED = new LED;
|
||||
|
||||
if (gLED != nullptr) {
|
||||
gLED->init();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,8 +86,6 @@ int Simulator::start(int argc, char *argv[])
|
||||
_instance = new Simulator();
|
||||
|
||||
if (_instance) {
|
||||
drv_led_start();
|
||||
|
||||
if (argc == 4 && strcmp(argv[2], "-u") == 0) {
|
||||
_instance->set_ip(InternetProtocol::UDP);
|
||||
_instance->set_port(atoi(argv[3]));
|
||||
|
||||
Reference in New Issue
Block a user