mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-27 18:27:05 +08:00
i2c+spi: extend hw_description for I2C + SPI
This commit is contained in:
@@ -232,3 +232,159 @@ enum class Pad {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GPIO
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace GPIO
|
||||||
|
{
|
||||||
|
enum Port {
|
||||||
|
PortInvalid = 0,
|
||||||
|
Port1,
|
||||||
|
Port2,
|
||||||
|
Port3,
|
||||||
|
Port4,
|
||||||
|
Port5,
|
||||||
|
};
|
||||||
|
enum Pin {
|
||||||
|
Pin0 = 0,
|
||||||
|
Pin1,
|
||||||
|
Pin2,
|
||||||
|
Pin3,
|
||||||
|
Pin4,
|
||||||
|
Pin5,
|
||||||
|
Pin6,
|
||||||
|
Pin7,
|
||||||
|
Pin8,
|
||||||
|
Pin9,
|
||||||
|
Pin10,
|
||||||
|
Pin11,
|
||||||
|
Pin12,
|
||||||
|
Pin13,
|
||||||
|
Pin14,
|
||||||
|
Pin15,
|
||||||
|
Pin16,
|
||||||
|
Pin17,
|
||||||
|
Pin18,
|
||||||
|
Pin19,
|
||||||
|
Pin20,
|
||||||
|
Pin21,
|
||||||
|
Pin22,
|
||||||
|
Pin23,
|
||||||
|
Pin24,
|
||||||
|
Pin25,
|
||||||
|
Pin26,
|
||||||
|
Pin27,
|
||||||
|
Pin28,
|
||||||
|
Pin29,
|
||||||
|
Pin30,
|
||||||
|
Pin31,
|
||||||
|
};
|
||||||
|
struct GPIOPin {
|
||||||
|
Port port;
|
||||||
|
Pin pin;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline constexpr uint32_t getGPIOPort(GPIO::Port port)
|
||||||
|
{
|
||||||
|
switch (port) {
|
||||||
|
case GPIO::Port1: return GPIO_PORT1;
|
||||||
|
|
||||||
|
case GPIO::Port2: return GPIO_PORT2;
|
||||||
|
|
||||||
|
case GPIO::Port3: return GPIO_PORT3;
|
||||||
|
|
||||||
|
case GPIO::Port4: return GPIO_PORT4;
|
||||||
|
|
||||||
|
case GPIO::Port5: return GPIO_PORT5;
|
||||||
|
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline constexpr uint32_t getGPIOPin(GPIO::Pin pin)
|
||||||
|
{
|
||||||
|
switch (pin) {
|
||||||
|
case GPIO::Pin0: return GPIO_PIN0;
|
||||||
|
|
||||||
|
case GPIO::Pin1: return GPIO_PIN1;
|
||||||
|
|
||||||
|
case GPIO::Pin2: return GPIO_PIN2;
|
||||||
|
|
||||||
|
case GPIO::Pin3: return GPIO_PIN3;
|
||||||
|
|
||||||
|
case GPIO::Pin4: return GPIO_PIN4;
|
||||||
|
|
||||||
|
case GPIO::Pin5: return GPIO_PIN5;
|
||||||
|
|
||||||
|
case GPIO::Pin6: return GPIO_PIN6;
|
||||||
|
|
||||||
|
case GPIO::Pin7: return GPIO_PIN7;
|
||||||
|
|
||||||
|
case GPIO::Pin8: return GPIO_PIN8;
|
||||||
|
|
||||||
|
case GPIO::Pin9: return GPIO_PIN9;
|
||||||
|
|
||||||
|
case GPIO::Pin10: return GPIO_PIN10;
|
||||||
|
|
||||||
|
case GPIO::Pin11: return GPIO_PIN11;
|
||||||
|
|
||||||
|
case GPIO::Pin12: return GPIO_PIN12;
|
||||||
|
|
||||||
|
case GPIO::Pin13: return GPIO_PIN13;
|
||||||
|
|
||||||
|
case GPIO::Pin14: return GPIO_PIN14;
|
||||||
|
|
||||||
|
case GPIO::Pin15: return GPIO_PIN15;
|
||||||
|
|
||||||
|
case GPIO::Pin16: return GPIO_PIN16;
|
||||||
|
|
||||||
|
case GPIO::Pin17: return GPIO_PIN17;
|
||||||
|
|
||||||
|
case GPIO::Pin18: return GPIO_PIN18;
|
||||||
|
|
||||||
|
case GPIO::Pin19: return GPIO_PIN19;
|
||||||
|
|
||||||
|
case GPIO::Pin20: return GPIO_PIN20;
|
||||||
|
|
||||||
|
case GPIO::Pin21: return GPIO_PIN21;
|
||||||
|
|
||||||
|
case GPIO::Pin22: return GPIO_PIN22;
|
||||||
|
|
||||||
|
case GPIO::Pin23: return GPIO_PIN23;
|
||||||
|
|
||||||
|
case GPIO::Pin24: return GPIO_PIN24;
|
||||||
|
|
||||||
|
case GPIO::Pin25: return GPIO_PIN25;
|
||||||
|
|
||||||
|
case GPIO::Pin26: return GPIO_PIN26;
|
||||||
|
|
||||||
|
case GPIO::Pin27: return GPIO_PIN27;
|
||||||
|
|
||||||
|
case GPIO::Pin28: return GPIO_PIN28;
|
||||||
|
|
||||||
|
case GPIO::Pin29: return GPIO_PIN29;
|
||||||
|
|
||||||
|
case GPIO::Pin30: return GPIO_PIN30;
|
||||||
|
|
||||||
|
case GPIO::Pin31: return GPIO_PIN31;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace SPI
|
||||||
|
{
|
||||||
|
|
||||||
|
using CS = GPIO::GPIOPin; ///< chip-select pin
|
||||||
|
using DRDY = GPIO::GPIOPin; ///< data ready pin
|
||||||
|
|
||||||
|
struct bus_device_external_cfg_t {
|
||||||
|
CS cs_gpio;
|
||||||
|
DRDY drdy_gpio;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace SPI
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 <px4_arch/hw_description.h>
|
||||||
|
#include <px4_platform_common/i2c.h>
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 <px4_arch/hw_description.h>
|
||||||
|
#include <px4_platform_common/spi.h>
|
||||||
|
|
||||||
|
#include <imxrt_gpio.h>
|
||||||
|
|
||||||
|
#define CS_IOMUX (IOMUX_CMOS_OUTPUT | IOMUX_PULL_UP_100K | IOMUX_DRIVE_33OHM | IOMUX_SPEED_LOW | IOMUX_SLEW_FAST)
|
||||||
|
|
||||||
|
#define DRDY_IOMUX (IOMUX_SCHMITT_TRIGGER | IOMUX_PULL_UP_47K | IOMUX_DRIVE_HIZ)
|
||||||
|
|
||||||
|
#define GENERAL_OUTPUT_IOMUX (IOMUX_CMOS_OUTPUT | IOMUX_PULL_KEEP | IOMUX_DRIVE_33OHM | IOMUX_SPEED_MEDIUM | IOMUX_SLEW_FAST)
|
||||||
|
|
||||||
|
static inline constexpr px4_spi_bus_device_t initSPIDevice(uint32_t devid, SPI::CS cs_gpio, SPI::DRDY drdy_gpio = {})
|
||||||
|
{
|
||||||
|
px4_spi_bus_device_t ret{};
|
||||||
|
ret.cs_gpio = getGPIOPort(cs_gpio.port) | getGPIOPin(cs_gpio.pin) | (GPIO_OUTPUT | GPIO_OUTPUT_ONE | CS_IOMUX);
|
||||||
|
|
||||||
|
if (drdy_gpio.port != GPIO::PortInvalid) {
|
||||||
|
ret.drdy_gpio = getGPIOPort(drdy_gpio.port) | getGPIOPin(drdy_gpio.pin) | (GPIO_INPUT | DRDY_IOMUX);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PX4_SPIDEVID_TYPE(devid) == 0) { // it's a PX4 device (internal or external)
|
||||||
|
ret.devid = PX4_SPIDEV_ID(PX4_SPI_DEVICE_ID, devid);
|
||||||
|
|
||||||
|
} else { // it's a NuttX device (e.g. SPIDEV_FLASH(0))
|
||||||
|
ret.devid = devid;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.devtype_driver = PX4_SPI_DEV_ID(devid);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline constexpr px4_spi_bus_t initSPIBus(int bus, const px4_spi_bus_devices_t &devices,
|
||||||
|
GPIO::GPIOPin power_enable = {})
|
||||||
|
{
|
||||||
|
px4_spi_bus_t ret{};
|
||||||
|
ret.requires_locking = true; // TODO: set this to false once all drivers are converted to use the I2CSPIDriver class
|
||||||
|
|
||||||
|
for (int i = 0; i < SPI_BUS_MAX_DEVICES; ++i) {
|
||||||
|
ret.devices[i] = devices.devices[i];
|
||||||
|
|
||||||
|
// check that the same device is configured only once (the chip-select code depends on that)
|
||||||
|
for (int j = i + 1; j < SPI_BUS_MAX_DEVICES; ++j) {
|
||||||
|
if (ret.devices[j].cs_gpio != 0) {
|
||||||
|
constexpr_assert(ret.devices[i].devid != ret.devices[j].devid, "Same device configured multiple times");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret.devices[i].cs_gpio != 0) {
|
||||||
|
// A bus potentially requires locking if it is accessed by non-PX4 devices (i.e. NuttX drivers)
|
||||||
|
if (PX4_SPI_DEVICE_ID != PX4_SPIDEVID_TYPE(ret.devices[i].devid)) {
|
||||||
|
ret.requires_locking = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.bus = bus;
|
||||||
|
ret.is_external = false;
|
||||||
|
|
||||||
|
if (power_enable.port != GPIO::PortInvalid) {
|
||||||
|
ret.power_enable_gpio = getGPIOPort(power_enable.port) | getGPIOPin(power_enable.pin) |
|
||||||
|
(GPIO_OUTPUT | GPIO_OUTPUT_ZERO | GENERAL_OUTPUT_IOMUX);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// just a wrapper since we cannot pass brace-enclosed initialized arrays directly as arguments
|
||||||
|
struct bus_device_external_cfg_array_t {
|
||||||
|
SPI::bus_device_external_cfg_t devices[SPI_BUS_MAX_DEVICES];
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline constexpr px4_spi_bus_t initSPIBusExternal(int bus, const bus_device_external_cfg_array_t &devices)
|
||||||
|
{
|
||||||
|
px4_spi_bus_t ret{};
|
||||||
|
|
||||||
|
for (int i = 0; i < SPI_BUS_MAX_DEVICES; ++i) {
|
||||||
|
if (devices.devices[i].cs_gpio.port == GPIO::PortInvalid) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.devices[i] = initSPIDevice(i, devices.devices[i].cs_gpio, devices.devices[i].drdy_gpio);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.bus = bus;
|
||||||
|
ret.is_external = true;
|
||||||
|
// TODO: set requires_locking to false once all drivers are converted to use the I2CSPIDriver class
|
||||||
|
ret.requires_locking = true; // external buses are never accessed by NuttX drivers
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline constexpr SPI::bus_device_external_cfg_t initSPIConfigExternal(SPI::CS cs_gpio, SPI::DRDY drdy_gpio = {})
|
||||||
|
{
|
||||||
|
SPI::bus_device_external_cfg_t ret{};
|
||||||
|
ret.cs_gpio = cs_gpio;
|
||||||
|
ret.drdy_gpio = drdy_gpio;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 "../../../kinetis/include/px4_arch/i2c_hw_description.h"
|
||||||
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 "../../../kinetis/include/px4_arch/spi_hw_description.h"
|
||||||
|
|
||||||
|
constexpr bool validateSPIConfig(const px4_spi_bus_t spi_busses_conf[SPI_BUS_MAX_BUS_ITEMS])
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -92,7 +92,8 @@ static inline constexpr uint32_t timerBaseRegister(Timer::Timer timer)
|
|||||||
namespace GPIO
|
namespace GPIO
|
||||||
{
|
{
|
||||||
enum Port {
|
enum Port {
|
||||||
PortA = 0,
|
PortInvalid = 0,
|
||||||
|
PortA,
|
||||||
PortB,
|
PortB,
|
||||||
PortC,
|
PortC,
|
||||||
PortD,
|
PortD,
|
||||||
@@ -150,6 +151,8 @@ static inline constexpr uint32_t getGPIOPort(GPIO::Port port)
|
|||||||
case GPIO::PortD: return PIN_PORTD;
|
case GPIO::PortD: return PIN_PORTD;
|
||||||
|
|
||||||
case GPIO::PortE: return PIN_PORTE;
|
case GPIO::PortE: return PIN_PORTE;
|
||||||
|
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -226,3 +229,15 @@ static inline constexpr uint32_t getGPIOPin(GPIO::Pin pin)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace SPI
|
||||||
|
{
|
||||||
|
|
||||||
|
using CS = GPIO::GPIOPin; ///< chip-select pin
|
||||||
|
using DRDY = GPIO::GPIOPin; ///< data ready pin
|
||||||
|
|
||||||
|
struct bus_device_external_cfg_t {
|
||||||
|
CS cs_gpio;
|
||||||
|
DRDY drdy_gpio;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace SPI
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 <px4_arch/hw_description.h>
|
||||||
|
#include <px4_platform_common/i2c.h>
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -85,6 +85,8 @@ static inline constexpr timer_io_channels_t initIOTimerChannel(const io_timers_t
|
|||||||
case GPIO::PortE:
|
case GPIO::PortE:
|
||||||
gpio_af = PIN_ALT6;
|
gpio_af = PIN_ALT6;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t gpio_pin_port = getGPIOPort(pin.port) | getGPIOPin(pin.pin);
|
uint32_t gpio_pin_port = getGPIOPort(pin.port) | getGPIOPin(pin.pin);
|
||||||
|
|||||||
@@ -0,0 +1,127 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 <px4_arch/hw_description.h>
|
||||||
|
#include <px4_platform_common/spi.h>
|
||||||
|
|
||||||
|
#include <kinetis.h>
|
||||||
|
|
||||||
|
static inline constexpr px4_spi_bus_device_t initSPIDevice(uint32_t devid, SPI::CS cs_gpio, SPI::DRDY drdy_gpio = {})
|
||||||
|
{
|
||||||
|
px4_spi_bus_device_t ret{};
|
||||||
|
ret.cs_gpio = getGPIOPort(cs_gpio.port) | getGPIOPin(cs_gpio.pin) | (GPIO_LOWDRIVE | GPIO_OUTPUT_ONE);
|
||||||
|
|
||||||
|
if (drdy_gpio.port != GPIO::PortInvalid) {
|
||||||
|
ret.drdy_gpio = getGPIOPort(drdy_gpio.port) | getGPIOPin(drdy_gpio.pin) | (GPIO_PULLUP | PIN_INT_BOTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PX4_SPIDEVID_TYPE(devid) == 0) { // it's a PX4 device (internal or external)
|
||||||
|
ret.devid = PX4_SPIDEV_ID(PX4_SPI_DEVICE_ID, devid);
|
||||||
|
|
||||||
|
} else { // it's a NuttX device (e.g. SPIDEV_FLASH(0))
|
||||||
|
ret.devid = devid;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.devtype_driver = PX4_SPI_DEV_ID(devid);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline constexpr px4_spi_bus_t initSPIBus(int bus, const px4_spi_bus_devices_t &devices,
|
||||||
|
GPIO::GPIOPin power_enable = {})
|
||||||
|
{
|
||||||
|
px4_spi_bus_t ret{};
|
||||||
|
ret.requires_locking = true; // TODO: set this to false once all drivers are converted to use the I2CSPIDriver class
|
||||||
|
|
||||||
|
for (int i = 0; i < SPI_BUS_MAX_DEVICES; ++i) {
|
||||||
|
ret.devices[i] = devices.devices[i];
|
||||||
|
|
||||||
|
// check that the same device is configured only once (the chip-select code depends on that)
|
||||||
|
for (int j = i + 1; j < SPI_BUS_MAX_DEVICES; ++j) {
|
||||||
|
if (ret.devices[j].cs_gpio != 0) {
|
||||||
|
constexpr_assert(ret.devices[i].devid != ret.devices[j].devid, "Same device configured multiple times");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret.devices[i].cs_gpio != 0) {
|
||||||
|
// A bus potentially requires locking if it is accessed by non-PX4 devices (i.e. NuttX drivers)
|
||||||
|
if (PX4_SPI_DEVICE_ID != PX4_SPIDEVID_TYPE(ret.devices[i].devid)) {
|
||||||
|
ret.requires_locking = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.bus = bus;
|
||||||
|
ret.is_external = false;
|
||||||
|
|
||||||
|
if (power_enable.port != GPIO::PortInvalid) {
|
||||||
|
ret.power_enable_gpio = getGPIOPort(power_enable.port) | getGPIOPin(power_enable.pin) |
|
||||||
|
(GPIO_HIGHDRIVE | GPIO_OUTPUT_ONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// just a wrapper since we cannot pass brace-enclosed initialized arrays directly as arguments
|
||||||
|
struct bus_device_external_cfg_array_t {
|
||||||
|
SPI::bus_device_external_cfg_t devices[SPI_BUS_MAX_DEVICES];
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline constexpr px4_spi_bus_t initSPIBusExternal(int bus, const bus_device_external_cfg_array_t &devices)
|
||||||
|
{
|
||||||
|
px4_spi_bus_t ret{};
|
||||||
|
|
||||||
|
for (int i = 0; i < SPI_BUS_MAX_DEVICES; ++i) {
|
||||||
|
if (devices.devices[i].cs_gpio.port == GPIO::PortInvalid) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.devices[i] = initSPIDevice(i, devices.devices[i].cs_gpio, devices.devices[i].drdy_gpio);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.bus = bus;
|
||||||
|
ret.is_external = true;
|
||||||
|
// TODO: set requires_locking to false once all drivers are converted to use the I2CSPIDriver class
|
||||||
|
ret.requires_locking = true; // external buses are never accessed by NuttX drivers
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline constexpr SPI::bus_device_external_cfg_t initSPIConfigExternal(SPI::CS cs_gpio, SPI::DRDY drdy_gpio = {})
|
||||||
|
{
|
||||||
|
SPI::bus_device_external_cfg_t ret{};
|
||||||
|
ret.cs_gpio = cs_gpio;
|
||||||
|
ret.drdy_gpio = drdy_gpio;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 "../../../imxrt/include/px4_arch/i2c_hw_description.h"
|
||||||
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 "../../../imxrt/include/px4_arch/spi_hw_description.h"
|
||||||
|
|
||||||
|
constexpr bool validateSPIConfig(const px4_spi_bus_t spi_busses_conf[SPI_BUS_MAX_BUS_ITEMS])
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -167,7 +167,8 @@ static inline constexpr uint32_t timerBaseRegister(Timer::Timer timer)
|
|||||||
namespace GPIO
|
namespace GPIO
|
||||||
{
|
{
|
||||||
enum Port {
|
enum Port {
|
||||||
PortA = 0,
|
PortInvalid = 0,
|
||||||
|
PortA,
|
||||||
PortB,
|
PortB,
|
||||||
PortC,
|
PortC,
|
||||||
PortD,
|
PortD,
|
||||||
@@ -176,6 +177,8 @@ enum Port {
|
|||||||
PortG,
|
PortG,
|
||||||
PortH,
|
PortH,
|
||||||
PortI,
|
PortI,
|
||||||
|
PortJ,
|
||||||
|
PortK,
|
||||||
};
|
};
|
||||||
enum Pin {
|
enum Pin {
|
||||||
Pin0 = 0,
|
Pin0 = 0,
|
||||||
@@ -229,6 +232,14 @@ static inline constexpr uint32_t getGPIOPort(GPIO::Port port)
|
|||||||
|
|
||||||
case GPIO::PortI: return GPIO_PORTI;
|
case GPIO::PortI: return GPIO_PORTI;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef GPIO_PORTJ
|
||||||
|
|
||||||
|
case GPIO::PortJ: return GPIO_PORTJ;
|
||||||
|
#endif
|
||||||
|
#ifdef GPIO_PORTK
|
||||||
|
|
||||||
|
case GPIO::PortK: return GPIO_PORTK;
|
||||||
|
#endif
|
||||||
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
@@ -275,3 +286,16 @@ static inline constexpr uint32_t getGPIOPin(GPIO::Pin pin)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace SPI
|
||||||
|
{
|
||||||
|
|
||||||
|
using CS = GPIO::GPIOPin; ///< chip-select pin
|
||||||
|
using DRDY = GPIO::GPIOPin; ///< data ready pin
|
||||||
|
|
||||||
|
struct bus_device_external_cfg_t {
|
||||||
|
CS cs_gpio;
|
||||||
|
DRDY drdy_gpio;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace SPI
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 <px4_arch/hw_description.h>
|
||||||
|
#include <px4_platform_common/i2c.h>
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 <px4_arch/hw_description.h>
|
||||||
|
#include <px4_platform_common/spi.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include <stm32_gpio.h>
|
||||||
|
|
||||||
|
static inline constexpr px4_spi_bus_device_t initSPIDevice(uint32_t devid, SPI::CS cs_gpio, SPI::DRDY drdy_gpio = {})
|
||||||
|
{
|
||||||
|
px4_spi_bus_device_t ret{};
|
||||||
|
ret.cs_gpio = getGPIOPort(cs_gpio.port) | getGPIOPin(cs_gpio.pin) | (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_2MHz |
|
||||||
|
GPIO_OUTPUT_SET);
|
||||||
|
|
||||||
|
if (drdy_gpio.port != GPIO::PortInvalid) {
|
||||||
|
ret.drdy_gpio = getGPIOPort(drdy_gpio.port) | getGPIOPin(drdy_gpio.pin) | (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PX4_SPIDEVID_TYPE(devid) == 0) { // it's a PX4 device (internal or external)
|
||||||
|
ret.devid = PX4_SPIDEV_ID(PX4_SPI_DEVICE_ID, devid);
|
||||||
|
|
||||||
|
} else { // it's a NuttX device (e.g. SPIDEV_FLASH(0))
|
||||||
|
ret.devid = devid;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.devtype_driver = PX4_SPI_DEV_ID(devid);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline constexpr px4_spi_bus_t initSPIBus(int bus, const px4_spi_bus_devices_t &devices,
|
||||||
|
GPIO::GPIOPin power_enable = {})
|
||||||
|
{
|
||||||
|
px4_spi_bus_t ret{};
|
||||||
|
ret.requires_locking = true; // TODO: set this to false once all drivers are converted to use the I2CSPIDriver class
|
||||||
|
|
||||||
|
for (int i = 0; i < SPI_BUS_MAX_DEVICES; ++i) {
|
||||||
|
ret.devices[i] = devices.devices[i];
|
||||||
|
|
||||||
|
// check that the same device is configured only once (the chip-select code depends on that)
|
||||||
|
for (int j = i + 1; j < SPI_BUS_MAX_DEVICES; ++j) {
|
||||||
|
if (ret.devices[j].cs_gpio != 0) {
|
||||||
|
constexpr_assert(ret.devices[i].devid != ret.devices[j].devid, "Same device configured multiple times");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret.devices[i].cs_gpio != 0) {
|
||||||
|
// A bus potentially requires locking if it is accessed by non-PX4 devices (i.e. NuttX drivers)
|
||||||
|
if (PX4_SPI_DEVICE_ID != PX4_SPIDEVID_TYPE(ret.devices[i].devid)) {
|
||||||
|
ret.requires_locking = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.bus = bus;
|
||||||
|
ret.is_external = false;
|
||||||
|
|
||||||
|
if (power_enable.port != GPIO::PortInvalid) {
|
||||||
|
ret.power_enable_gpio = getGPIOPort(power_enable.port) | getGPIOPin(power_enable.pin) |
|
||||||
|
(GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_2MHz | GPIO_OUTPUT_CLEAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// just a wrapper since we cannot pass brace-enclosed initialized arrays directly as arguments
|
||||||
|
struct bus_device_external_cfg_array_t {
|
||||||
|
SPI::bus_device_external_cfg_t devices[SPI_BUS_MAX_DEVICES];
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline constexpr px4_spi_bus_t initSPIBusExternal(int bus, const bus_device_external_cfg_array_t &devices)
|
||||||
|
{
|
||||||
|
px4_spi_bus_t ret{};
|
||||||
|
|
||||||
|
for (int i = 0; i < SPI_BUS_MAX_DEVICES; ++i) {
|
||||||
|
if (devices.devices[i].cs_gpio.port == GPIO::PortInvalid) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.devices[i] = initSPIDevice(i, devices.devices[i].cs_gpio, devices.devices[i].drdy_gpio);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.bus = bus;
|
||||||
|
ret.is_external = true;
|
||||||
|
// TODO: set requires_locking to false once all drivers are converted to use the I2CSPIDriver class
|
||||||
|
ret.requires_locking = true; // external buses are never accessed by NuttX drivers
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline constexpr SPI::bus_device_external_cfg_t initSPIConfigExternal(SPI::CS cs_gpio, SPI::DRDY drdy_gpio = {})
|
||||||
|
{
|
||||||
|
SPI::bus_device_external_cfg_t ret{};
|
||||||
|
ret.cs_gpio = cs_gpio;
|
||||||
|
ret.drdy_gpio = drdy_gpio;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct px4_spi_bus_array_t {
|
||||||
|
px4_spi_bus_t item[SPI_BUS_MAX_BUS_ITEMS];
|
||||||
|
};
|
||||||
|
static inline constexpr px4_spi_bus_all_hw_t initSPIHWVersion(int hw_version, const px4_spi_bus_array_t &bus_items)
|
||||||
|
{
|
||||||
|
px4_spi_bus_all_hw_t ret{};
|
||||||
|
|
||||||
|
for (int i = 0; i < SPI_BUS_MAX_BUS_ITEMS; ++i) {
|
||||||
|
ret.buses[i] = bus_items.item[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.board_hw_version = hw_version;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
constexpr bool validateSPIConfig(const px4_spi_bus_t spi_buses_conf[SPI_BUS_MAX_BUS_ITEMS]);
|
||||||
|
|
||||||
|
constexpr bool validateSPIConfig(const px4_spi_bus_all_hw_t spi_buses_conf[BOARD_NUM_SPI_CFG_HW_VERSIONS])
|
||||||
|
{
|
||||||
|
for (int ver = 0; ver < BOARD_NUM_SPI_CFG_HW_VERSIONS; ++ver) {
|
||||||
|
validateSPIConfig(spi_buses_conf[ver].buses);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int ver = 1; ver < BOARD_NUM_SPI_CFG_HW_VERSIONS; ++ver) {
|
||||||
|
for (int i = 0; i < SPI_BUS_MAX_BUS_ITEMS; ++i) {
|
||||||
|
const bool equal_power_enable_gpio = spi_buses_conf[ver].buses[i].power_enable_gpio == spi_buses_conf[ver -
|
||||||
|
1].buses[i].power_enable_gpio;
|
||||||
|
// currently board_control_spi_sensors_power_configgpio() depends on that - this restriction can be removed
|
||||||
|
// by ensuring board_control_spi_sensors_power_configgpio() is called after the hw version is determined
|
||||||
|
// and SPI config is initialized.
|
||||||
|
constexpr_assert(equal_power_enable_gpio, "All HW versions must define the same power enable GPIO");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
############################################################################
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
px4_add_library(arch_spi
|
||||||
|
spi.cpp
|
||||||
|
)
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -39,6 +39,7 @@ add_subdirectory(../stm32_common/dshot dshot)
|
|||||||
add_subdirectory(../stm32_common/hrt hrt)
|
add_subdirectory(../stm32_common/hrt hrt)
|
||||||
add_subdirectory(../stm32_common/led_pwm led_pwm)
|
add_subdirectory(../stm32_common/led_pwm led_pwm)
|
||||||
add_subdirectory(../stm32_common/io_pins io_pins)
|
add_subdirectory(../stm32_common/io_pins io_pins)
|
||||||
|
add_subdirectory(../stm32_common/spi spi)
|
||||||
add_subdirectory(../stm32_common/tone_alarm tone_alarm)
|
add_subdirectory(../stm32_common/tone_alarm tone_alarm)
|
||||||
add_subdirectory(../stm32_common/version version)
|
add_subdirectory(../stm32_common/version version)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 "../../../stm32_common/include/px4_arch/i2c_hw_description.h"
|
||||||
|
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 "../../../stm32_common/include/px4_arch/spi_hw_description.h"
|
||||||
|
|
||||||
|
constexpr bool validateSPIConfig(const px4_spi_bus_t spi_busses_conf[SPI_BUS_MAX_BUS_ITEMS])
|
||||||
|
{
|
||||||
|
const bool nuttx_enabled_spi_buses[] = {
|
||||||
|
#ifdef CONFIG_STM32_SPI1
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_STM32_SPI2
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_STM32_SPI3
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_STM32_SPI4
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_STM32_SPI5
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_STM32_SPI6
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < sizeof(nuttx_enabled_spi_buses) / sizeof(nuttx_enabled_spi_buses[0]); ++i) {
|
||||||
|
bool found_bus = false;
|
||||||
|
|
||||||
|
for (int j = 0; j < SPI_BUS_MAX_BUS_ITEMS; ++j) {
|
||||||
|
if (spi_busses_conf[j].bus == (int)i + 1) {
|
||||||
|
found_bus = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Either the bus is enabled in NuttX and configured in spi_busses_conf, or disabled and not configured
|
||||||
|
constexpr_assert(found_bus == nuttx_enabled_spi_buses[i], "SPI bus config mismatch (CONFIG_STM32_SPIx)");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -40,6 +40,7 @@ add_subdirectory(../stm32_common/dshot dshot)
|
|||||||
add_subdirectory(../stm32_common/hrt hrt)
|
add_subdirectory(../stm32_common/hrt hrt)
|
||||||
add_subdirectory(../stm32_common/led_pwm led_pwm)
|
add_subdirectory(../stm32_common/led_pwm led_pwm)
|
||||||
add_subdirectory(../stm32_common/io_pins io_pins)
|
add_subdirectory(../stm32_common/io_pins io_pins)
|
||||||
|
add_subdirectory(../stm32_common/spi spi)
|
||||||
add_subdirectory(../stm32_common/tone_alarm tone_alarm)
|
add_subdirectory(../stm32_common/tone_alarm tone_alarm)
|
||||||
add_subdirectory(../stm32_common/version version)
|
add_subdirectory(../stm32_common/version version)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 "../../../stm32_common/include/px4_arch/i2c_hw_description.h"
|
||||||
|
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 "../../../stm32_common/include/px4_arch/spi_hw_description.h"
|
||||||
|
|
||||||
|
constexpr bool validateSPIConfig(const px4_spi_bus_t spi_busses_conf[SPI_BUS_MAX_BUS_ITEMS])
|
||||||
|
{
|
||||||
|
const bool nuttx_enabled_spi_buses[] = {
|
||||||
|
#ifdef CONFIG_STM32F7_SPI1
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_STM32F7_SPI2
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_STM32F7_SPI3
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_STM32F7_SPI4
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_STM32F7_SPI5
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_STM32F7_SPI6
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < sizeof(nuttx_enabled_spi_buses) / sizeof(nuttx_enabled_spi_buses[0]); ++i) {
|
||||||
|
bool found_bus = false;
|
||||||
|
|
||||||
|
for (int j = 0; j < SPI_BUS_MAX_BUS_ITEMS; ++j) {
|
||||||
|
if (spi_busses_conf[j].bus == (int)i + 1) {
|
||||||
|
found_bus = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Either the bus is enabled in NuttX and configured in spi_busses_conf, or disabled and not configured
|
||||||
|
constexpr_assert(found_bus == nuttx_enabled_spi_buses[i], "SPI bus config mismatch (CONFIG_STM32F7_SPIx)");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -39,6 +39,7 @@ add_subdirectory(../stm32_common/board_reset board_reset)
|
|||||||
add_subdirectory(../stm32_common/dshot dshot)
|
add_subdirectory(../stm32_common/dshot dshot)
|
||||||
add_subdirectory(../stm32_common/hrt hrt)
|
add_subdirectory(../stm32_common/hrt hrt)
|
||||||
add_subdirectory(../stm32_common/io_pins io_pins)
|
add_subdirectory(../stm32_common/io_pins io_pins)
|
||||||
|
add_subdirectory(../stm32_common/spi spi)
|
||||||
add_subdirectory(../stm32_common/tone_alarm tone_alarm)
|
add_subdirectory(../stm32_common/tone_alarm tone_alarm)
|
||||||
add_subdirectory(../stm32_common/version version)
|
add_subdirectory(../stm32_common/version version)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 "../../../stm32_common/include/px4_arch/i2c_hw_description.h"
|
||||||
|
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 "../../../stm32_common/include/px4_arch/spi_hw_description.h"
|
||||||
|
|
||||||
|
constexpr bool validateSPIConfig(const px4_spi_bus_t spi_busses_conf[SPI_BUS_MAX_BUS_ITEMS])
|
||||||
|
{
|
||||||
|
const bool nuttx_enabled_spi_buses[] = {
|
||||||
|
#ifdef CONFIG_STM32H7_SPI1
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_STM32H7_SPI2
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_STM32H7_SPI3
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_STM32H7_SPI4
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_STM32H7_SPI5
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_STM32H7_SPI6
|
||||||
|
true,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < sizeof(nuttx_enabled_spi_buses) / sizeof(nuttx_enabled_spi_buses[0]); ++i) {
|
||||||
|
bool found_bus = false;
|
||||||
|
|
||||||
|
for (int j = 0; j < SPI_BUS_MAX_BUS_ITEMS; ++j) {
|
||||||
|
if (spi_busses_conf[j].bus == (int)i + 1) {
|
||||||
|
found_bus = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Either the bus is enabled in NuttX and configured in spi_busses_conf, or disabled and not configured
|
||||||
|
constexpr_assert(found_bus == nuttx_enabled_spi_buses[i], "SPI bus config mismatch (CONFIG_STM32H7_SPIx)");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 <px4_platform_common/i2c.h>
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 <px4_platform_common/spi.h>
|
||||||
|
|
||||||
|
static inline constexpr px4_spi_bus_device_t initSPIDevice(uint8_t devid_driver, uint8_t cs_index)
|
||||||
|
{
|
||||||
|
px4_spi_bus_device_t ret{};
|
||||||
|
ret.cs_gpio = 1; // set to some non-zero value to indicate this is used
|
||||||
|
ret.devid = PX4_SPIDEV_ID(PX4_SPI_DEVICE_ID, cs_index);
|
||||||
|
ret.devtype_driver = devid_driver;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline constexpr px4_spi_bus_t initSPIBus(int bus, const px4_spi_bus_devices_t &devices)
|
||||||
|
{
|
||||||
|
px4_spi_bus_t ret{};
|
||||||
|
|
||||||
|
for (int i = 0; i < SPI_BUS_MAX_DEVICES; ++i) {
|
||||||
|
ret.devices[i] = devices.devices[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.bus = bus;
|
||||||
|
ret.is_external = false; // all buses are marked internal on Linux
|
||||||
|
ret.requires_locking = false;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 <px4_platform_common/i2c.h>
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* 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 <px4_platform_common/spi.h>
|
||||||
|
|
||||||
|
static inline constexpr px4_spi_bus_device_t initSPIDevice(uint8_t devid_driver)
|
||||||
|
{
|
||||||
|
px4_spi_bus_device_t ret{};
|
||||||
|
ret.cs_gpio = 1; // set to some non-zero value to indicate this is used
|
||||||
|
ret.devid = PX4_SPIDEV_ID(PX4_SPI_DEVICE_ID, 0);
|
||||||
|
ret.devtype_driver = devid_driver;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline constexpr px4_spi_bus_t initSPIBus(int bus, const px4_spi_bus_devices_t &devices)
|
||||||
|
{
|
||||||
|
px4_spi_bus_t ret{};
|
||||||
|
|
||||||
|
for (int i = 0; i < SPI_BUS_MAX_DEVICES; ++i) {
|
||||||
|
ret.devices[i] = devices.devices[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.bus = bus;
|
||||||
|
ret.is_external = false; // all buses are marked internal on QuRT
|
||||||
|
ret.requires_locking = false;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user