diff --git a/boards/modalai/voxl2-slpi/default.px4board b/boards/modalai/voxl2-slpi/default.px4board index 92892fd5e0..70ac1a43a9 100644 --- a/boards/modalai/voxl2-slpi/default.px4board +++ b/boards/modalai/voxl2-slpi/default.px4board @@ -1,6 +1,7 @@ CONFIG_PLATFORM_QURT=y CONFIG_BOARD_TOOLCHAIN="qurt" CONFIG_DRIVERS_ACTUATORS_MODALAI_ESC=y +CONFIG_DRIVERS_POWER_MONITOR_VOXLPM=y CONFIG_DRIVERS_QSHELL_QURT=y CONFIG_MODULES_EKF2=y CONFIG_MODULES_LAND_DETECTOR=y diff --git a/boards/modalai/voxl2-slpi/src/CMakeLists.txt b/boards/modalai/voxl2-slpi/src/CMakeLists.txt index 111ec4fd9a..51dbb0c311 100644 --- a/boards/modalai/voxl2-slpi/src/CMakeLists.txt +++ b/boards/modalai/voxl2-slpi/src/CMakeLists.txt @@ -38,6 +38,7 @@ set(DISABLE_PARAMS_MODULE_SCOPING TRUE PARENT_SCOPE) add_library(drivers_board board_config.h + i2c.cpp init.c spi.cpp ) diff --git a/boards/modalai/voxl2-slpi/src/board_config.h b/boards/modalai/voxl2-slpi/src/board_config.h index 45e9d09539..453245568e 100644 --- a/boards/modalai/voxl2-slpi/src/board_config.h +++ b/boards/modalai/voxl2-slpi/src/board_config.h @@ -44,6 +44,7 @@ /* * I2C buses */ +#define CONFIG_I2C 1 #define PX4_NUMBER_I2C_BUSES 3 /* diff --git a/boards/modalai/voxl2-slpi/src/i2c.cpp b/boards/modalai/voxl2-slpi/src/i2c.cpp new file mode 100644 index 0000000000..6befbedb1a --- /dev/null +++ b/boards/modalai/voxl2-slpi/src/i2c.cpp @@ -0,0 +1,42 @@ +/**************************************************************************** + * + * 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. + * + ****************************************************************************/ + +#include +#include +#include + +constexpr px4_i2c_bus_t px4_i2c_buses[I2C_BUS_MAX_BUS_ITEMS] = { + initI2CBusExternal(1), + initI2CBusExternal(2), + initI2CBusInternal(5) +}; diff --git a/platforms/qurt/include/px4_arch/i2c_hw_description.h b/platforms/qurt/include/px4_arch/i2c_hw_description.h new file mode 100644 index 0000000000..fb511f42fd --- /dev/null +++ b/platforms/qurt/include/px4_arch/i2c_hw_description.h @@ -0,0 +1,52 @@ +/**************************************************************************** + * + * 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 + +static inline constexpr px4_i2c_bus_t initI2CBusInternal(int bus) +{ + px4_i2c_bus_t ret{}; + ret.bus = bus; + ret.is_external = false; + return ret; +} + +static inline constexpr px4_i2c_bus_t initI2CBusExternal(int bus) +{ + px4_i2c_bus_t ret{}; + ret.bus = bus; + ret.is_external = true; + return ret; +} diff --git a/src/lib/drivers/device/CMakeLists.txt b/src/lib/drivers/device/CMakeLists.txt index 819f45b229..c949db9dd5 100644 --- a/src/lib/drivers/device/CMakeLists.txt +++ b/src/lib/drivers/device/CMakeLists.txt @@ -41,7 +41,7 @@ if (${PX4_PLATFORM} STREQUAL "nuttx") list(APPEND SRCS_PLATFORM nuttx/SPI.cpp) endif() elseif((${PX4_PLATFORM} MATCHES "qurt")) - # list(APPEND SRCS_PLATFORM qurt/I2C.cpp) + list(APPEND SRCS_PLATFORM qurt/I2C.cpp) list(APPEND SRCS_PLATFORM qurt/SPI.cpp) list(APPEND SRCS_PLATFORM qurt/uart.c) elseif(UNIX AND NOT APPLE) #TODO: add linux PX4 platform type diff --git a/src/lib/drivers/device/qurt/I2C.cpp b/src/lib/drivers/device/qurt/I2C.cpp index d3fc6bd04f..c2b70f66d3 100644 --- a/src/lib/drivers/device/qurt/I2C.cpp +++ b/src/lib/drivers/device/qurt/I2C.cpp @@ -42,8 +42,11 @@ #include "I2C.hpp" -#include +#if defined(CONFIG_I2C) + #include +#include +#include namespace device { @@ -69,6 +72,11 @@ I2C::I2C(uint8_t device_type, const char *name, const int bus, const uint16_t ad PX4_INFO("*** I2C Device ID 0x%x %d", _device_id.devid, _device_id.devid); } +I2C::I2C(const I2CSPIDriverConfig &config) + : I2C(config.devid_driver_index, config.module_name, config.bus, config.i2c_address, config.bus_frequency) +{ +} + I2C::~I2C() { } @@ -157,3 +165,5 @@ I2C::transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const } } // namespace device + +#endif diff --git a/src/lib/drivers/device/qurt/I2C.hpp b/src/lib/drivers/device/qurt/I2C.hpp index 8e2e4c7e7d..7f1d59bc0a 100644 --- a/src/lib/drivers/device/qurt/I2C.hpp +++ b/src/lib/drivers/device/qurt/I2C.hpp @@ -37,11 +37,14 @@ * Base class for devices connected via I2C. */ -#ifndef _DEVICE_I2C_H -#define _DEVICE_I2C_H +#pragma once -#include #include "../CDev.hpp" +#include + +#if defined(CONFIG_I2C) + +struct I2CSPIDriverConfig; namespace device __EXPORT { @@ -92,6 +95,7 @@ protected: * @param frequency I2C bus frequency for the device (currently not used) */ I2C(uint8_t device_type, const char *name, const int bus, const uint16_t address, const uint32_t frequency); + I2C(const I2CSPIDriverConfig &config); virtual ~I2C(); /** diff --git a/src/modules/muorb/slpi/uORBProtobufChannel.cpp b/src/modules/muorb/slpi/uORBProtobufChannel.cpp index 425167e599..64026bfa2f 100644 --- a/src/modules/muorb/slpi/uORBProtobufChannel.cpp +++ b/src/modules/muorb/slpi/uORBProtobufChannel.cpp @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -280,6 +281,10 @@ int px4muorb_orb_initialize(fc_func_ptrs *func_ptrs, int32_t clock_offset_us) uORB::ProtobufChannel::GetInstance()->RegisterSendHandler(muorb_func_ptrs.topic_data_func_ptr); + // Configure the I2C driver function pointers + device::I2C::configure_callbacks(muorb_func_ptrs._config_i2c_bus_func_t, muorb_func_ptrs._set_i2c_address_func_t, + muorb_func_ptrs._i2c_transfer_func_t); + // Configure the SPI driver function pointers device::SPI::configure_callbacks(muorb_func_ptrs._config_spi_bus_func_t, muorb_func_ptrs._spi_transfer_func_t);