mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 16:43:35 +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,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
|
||||
|
||||
Reference in New Issue
Block a user