mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 01:12:11 +00:00
platforms: remove unnecessary i2c platform abstraction
This commit is contained in:
@@ -70,7 +70,6 @@
|
||||
#include <drivers/drv_board_led.h>
|
||||
#include <systemlib/px4_macros.h>
|
||||
#include <px4_platform_common/init.h>
|
||||
#include <px4_platform_common/i2c.h>
|
||||
#include <px4_platform/gpio.h>
|
||||
#include <px4_platform/board_dma_alloc.h>
|
||||
|
||||
@@ -217,7 +216,7 @@ static int configure_switch(void)
|
||||
// ethernet switch enable
|
||||
uint8_t txdata[] = {0x51, 0x00, 0x21, 0x00}; //0x5100, 0x2100 MSB to LSB here.
|
||||
|
||||
struct px4_i2c_msg_t msgv;
|
||||
struct i2c_msg_s msgv;
|
||||
|
||||
msgv.frequency = 100000;
|
||||
msgv.addr = 0x5F;
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2015 Mark Charlebois. 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 px4_i2c.h
|
||||
*
|
||||
* Includes device headers depending on the build target
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define PX4_I2C_M_READ 0x0001 /* read data, from slave to master */
|
||||
|
||||
#if defined (__PX4_NUTTX)
|
||||
__BEGIN_DECLS
|
||||
|
||||
/*
|
||||
* Building for NuttX
|
||||
*/
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
#include <nuttx/clock.h>
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
#include <chip.h>
|
||||
#include <arch/board/board.h>
|
||||
#include <arch/chip/chip.h>
|
||||
#include "up_internal.h"
|
||||
#include "up_arch.h"
|
||||
|
||||
#define px4_i2c_msg_t i2c_msg_s
|
||||
|
||||
typedef struct i2c_master_s px4_i2c_dev_t;
|
||||
__END_DECLS
|
||||
|
||||
#elif defined(__PX4_POSIX)
|
||||
#include <stdint.h>
|
||||
|
||||
#define I2C_M_READ 0x0001 /* read data, from slave to master */
|
||||
#define I2C_M_TEN 0x0002 /* ten bit address */
|
||||
#define I2C_M_NORESTART 0x0080 /* message should not begin with (re-)start of transfer */
|
||||
|
||||
// NOTE - This is a copy of the NuttX i2c_msg_s structure
|
||||
|
||||
typedef struct {
|
||||
uint32_t frequency; /* I2C frequency */
|
||||
uint16_t addr; /* Slave address (7- or 10-bit) */
|
||||
uint16_t flags; /* See I2C_M_* definitions */
|
||||
uint8_t *buffer; /* Buffer to be transferred */
|
||||
ssize_t length; /* Length of the buffer in bytes */
|
||||
} px4_i2c_msg_t;
|
||||
|
||||
// NOTE - This is a copy of the NuttX i2c_ops_s structure
|
||||
typedef struct {
|
||||
const struct px4_i2c_ops_t *ops; /* I2C vtable */
|
||||
} px4_i2c_dev_t;
|
||||
|
||||
//#define SPI_SELECT(d,id,s) ((d)->ops->select(d,id,s))
|
||||
#define SPI_SELECT(d,id,s)
|
||||
|
||||
// FIXME - Stub implementation
|
||||
// Original version commented out
|
||||
//#define I2C_TRANSFER(d,m,c) ((d)->ops->transfer(d,m,c))
|
||||
inline int I2C_TRANSFER(px4_i2c_dev_t *dev, px4_i2c_msg_t *msg, int count);
|
||||
inline int I2C_TRANSFER(px4_i2c_dev_t *dev, px4_i2c_msg_t *msg, int count) { return 0; }
|
||||
|
||||
#ifdef __PX4_QURT
|
||||
|
||||
struct i2c_msg {
|
||||
uint16_t addr; /* Slave address */
|
||||
uint16_t flags; /* See I2C_M_* definitions */
|
||||
uint8_t *buf;
|
||||
int len;
|
||||
};
|
||||
|
||||
#define I2C_RDWR 0x0FFF
|
||||
|
||||
struct i2c_rdwr_ioctl_data {
|
||||
struct i2c_msg *msgs; /* pointers to i2c_msgs */
|
||||
uint32_t nmsgs; /* number of i2c_msgs */
|
||||
};
|
||||
|
||||
// FIXME - The functions are not implemented on QuRT/DSPAL
|
||||
int ioctl(int fd, int flags, unsigned long data);
|
||||
int write(int fd, const char *buffer, int buflen);
|
||||
#endif
|
||||
#else
|
||||
#error "No target platform defined"
|
||||
#endif
|
||||
@@ -35,7 +35,6 @@
|
||||
|
||||
__BEGIN_DECLS
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
|
||||
/* For historical reasons (NuttX STM32 numbering) PX4 bus numbering is 1 based
|
||||
* All PX4 code, including, board code is written to assuming 1 based numbering.
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/i2c.h
|
||||
*
|
||||
* Copyright(C) 2009-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 NuttX 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 <stdint.h>
|
||||
|
||||
struct i2c_msg_s {
|
||||
uint16_t addr; /* Slave address */
|
||||
uint16_t flags; /* See I2C_M_* definitions */
|
||||
uint8_t *buffer;
|
||||
int length;
|
||||
};
|
||||
@@ -182,7 +182,7 @@ I2C::transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const
|
||||
do {
|
||||
DEVICE_DEBUG("transfer out %p/%u in %p/%u", send, send_len, recv, recv_len);
|
||||
|
||||
px4_i2c_msg_t msgv[2] {};
|
||||
i2c_msg_s msgv[2] {};
|
||||
unsigned msgs = 0;
|
||||
|
||||
if (send_len > 0) {
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
#include "../CDev.hpp"
|
||||
|
||||
#include <px4_platform_common/i2c.h>
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
|
||||
#if !defined(CONFIG_I2C)
|
||||
# error I2C support requires CONFIG_I2C
|
||||
@@ -113,7 +113,7 @@ protected:
|
||||
|
||||
private:
|
||||
uint32_t _frequency{0};
|
||||
px4_i2c_dev_t *_dev{nullptr};
|
||||
i2c_master_s *_dev{nullptr};
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ I2C::transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const
|
||||
|
||||
if (recv_len > 0) {
|
||||
msgv[msgs].addr = get_device_address();
|
||||
msgv[msgs].flags = I2C_M_READ;
|
||||
msgv[msgs].flags = I2C_M_RD;
|
||||
msgv[msgs].buf = recv;
|
||||
msgv[msgs].len = recv_len;
|
||||
msgs++;
|
||||
|
||||
@@ -42,8 +42,6 @@
|
||||
|
||||
#include "../CDev.hpp"
|
||||
|
||||
#include <px4_platform_common/i2c.h>
|
||||
|
||||
namespace device __EXPORT
|
||||
{
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ I2C::init()
|
||||
|
||||
// Open the actual I2C device
|
||||
char dev_path[16] {};
|
||||
snprintf(dev_path, sizeof(dev_path), "/dev/iic-%i", get_device_bus());
|
||||
snprintf(dev_path, sizeof(dev_path), DEV_FS_I2C_DEVICE_TYPE_STRING"%i", get_device_bus());
|
||||
_fd = ::open(dev_path, O_RDWR);
|
||||
|
||||
if (_fd < 0) {
|
||||
|
||||
@@ -42,8 +42,6 @@
|
||||
|
||||
#include "../CDev.hpp"
|
||||
|
||||
#include <px4_platform_common/i2c.h>
|
||||
|
||||
namespace device __EXPORT
|
||||
{
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
#include <px4_platform_common/log.h>
|
||||
#include <px4_platform_common/module.h>
|
||||
#include <px4_platform_common/getopt.h>
|
||||
#include <px4_platform_common/i2c.h>
|
||||
|
||||
namespace i2cdetect
|
||||
{
|
||||
@@ -80,7 +79,7 @@ int detect(int bus)
|
||||
do {
|
||||
uint8_t send_data = 0;
|
||||
uint8_t recv_data = 0;
|
||||
px4_i2c_msg_t msgv[2];
|
||||
i2c_msg_s msgv[2] {};
|
||||
|
||||
// send
|
||||
msgv[0].frequency = 100000;
|
||||
|
||||
Reference in New Issue
Block a user