From d1e3ff553be10e2214ff636ca934b80e48de9d80 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Sat, 11 Jan 2020 11:16:58 -0500 Subject: [PATCH] platforms: remove unnecessary i2c platform abstraction --- boards/av/x-v1/src/init.c | 3 +- .../common/include/px4_platform_common/i2c.h | 122 ------------------ .../common/include/px4_platform/micro_hal.h | 1 - platforms/qurt/include/i2c.h | 44 ------- src/lib/drivers/device/nuttx/I2C.cpp | 2 +- src/lib/drivers/device/nuttx/I2C.hpp | 4 +- src/lib/drivers/device/posix/I2C.cpp | 2 +- src/lib/drivers/device/posix/I2C.hpp | 2 - src/lib/drivers/device/qurt/I2C.cpp | 2 +- src/lib/drivers/device/qurt/I2C.hpp | 2 - src/systemcmds/i2cdetect/i2cdetect.cpp | 3 +- 11 files changed, 7 insertions(+), 180 deletions(-) delete mode 100644 platforms/common/include/px4_platform_common/i2c.h delete mode 100644 platforms/qurt/include/i2c.h diff --git a/boards/av/x-v1/src/init.c b/boards/av/x-v1/src/init.c index 0f06bfda55..d85d255423 100644 --- a/boards/av/x-v1/src/init.c +++ b/boards/av/x-v1/src/init.c @@ -70,7 +70,6 @@ #include #include #include -#include #include #include @@ -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; diff --git a/platforms/common/include/px4_platform_common/i2c.h b/platforms/common/include/px4_platform_common/i2c.h deleted file mode 100644 index e283527e3c..0000000000 --- a/platforms/common/include/px4_platform_common/i2c.h +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#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 - -#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 diff --git a/platforms/nuttx/src/px4/common/include/px4_platform/micro_hal.h b/platforms/nuttx/src/px4/common/include/px4_platform/micro_hal.h index 8bf62a5f8d..7d2ee5b256 100644 --- a/platforms/nuttx/src/px4/common/include/px4_platform/micro_hal.h +++ b/platforms/nuttx/src/px4/common/include/px4_platform/micro_hal.h @@ -35,7 +35,6 @@ __BEGIN_DECLS #include -#include /* 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. diff --git a/platforms/qurt/include/i2c.h b/platforms/qurt/include/i2c.h deleted file mode 100644 index 0e567d29a1..0000000000 --- a/platforms/qurt/include/i2c.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** - * include/nuttx/i2c.h - * - * Copyright(C) 2009-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -struct i2c_msg_s { - uint16_t addr; /* Slave address */ - uint16_t flags; /* See I2C_M_* definitions */ - uint8_t *buffer; - int length; -}; diff --git a/src/lib/drivers/device/nuttx/I2C.cpp b/src/lib/drivers/device/nuttx/I2C.cpp index 75af7f3405..872895d651 100644 --- a/src/lib/drivers/device/nuttx/I2C.cpp +++ b/src/lib/drivers/device/nuttx/I2C.cpp @@ -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) { diff --git a/src/lib/drivers/device/nuttx/I2C.hpp b/src/lib/drivers/device/nuttx/I2C.hpp index 6965e82f34..5f472767ff 100644 --- a/src/lib/drivers/device/nuttx/I2C.hpp +++ b/src/lib/drivers/device/nuttx/I2C.hpp @@ -42,7 +42,7 @@ #include "../CDev.hpp" -#include +#include #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}; }; diff --git a/src/lib/drivers/device/posix/I2C.cpp b/src/lib/drivers/device/posix/I2C.cpp index 21dd5d0d0b..fd8119cb94 100644 --- a/src/lib/drivers/device/posix/I2C.cpp +++ b/src/lib/drivers/device/posix/I2C.cpp @@ -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++; diff --git a/src/lib/drivers/device/posix/I2C.hpp b/src/lib/drivers/device/posix/I2C.hpp index 933d9af352..b886413a3f 100644 --- a/src/lib/drivers/device/posix/I2C.hpp +++ b/src/lib/drivers/device/posix/I2C.hpp @@ -42,8 +42,6 @@ #include "../CDev.hpp" -#include - namespace device __EXPORT { diff --git a/src/lib/drivers/device/qurt/I2C.cpp b/src/lib/drivers/device/qurt/I2C.cpp index 46ce6d10c7..665e51e6f5 100644 --- a/src/lib/drivers/device/qurt/I2C.cpp +++ b/src/lib/drivers/device/qurt/I2C.cpp @@ -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) { diff --git a/src/lib/drivers/device/qurt/I2C.hpp b/src/lib/drivers/device/qurt/I2C.hpp index 25dcd46f23..4129021e6a 100644 --- a/src/lib/drivers/device/qurt/I2C.hpp +++ b/src/lib/drivers/device/qurt/I2C.hpp @@ -42,8 +42,6 @@ #include "../CDev.hpp" -#include - namespace device __EXPORT { diff --git a/src/systemcmds/i2cdetect/i2cdetect.cpp b/src/systemcmds/i2cdetect/i2cdetect.cpp index 2d4c3a3091..dc6b56cf8b 100644 --- a/src/systemcmds/i2cdetect/i2cdetect.cpp +++ b/src/systemcmds/i2cdetect/i2cdetect.cpp @@ -42,7 +42,6 @@ #include #include #include -#include 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;