forked from Archive/PX4-Autopilot
rt1170:spi_hw_description:Support Validation and HW selection
This commit is contained in:
parent
d33bb59225
commit
9849abcb63
|
@ -40,6 +40,57 @@
|
|||
|
||||
#include <imxrt_gpio.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_IMXRT_LPSPI1
|
||||
true,
|
||||
#else
|
||||
false,
|
||||
#endif
|
||||
#ifdef CONFIG_IMXRT_LPSPI2
|
||||
true,
|
||||
#else
|
||||
false,
|
||||
#endif
|
||||
#ifdef CONFIG_IMXRT_LPSPI3
|
||||
true,
|
||||
#else
|
||||
false,
|
||||
#endif
|
||||
#ifdef CONFIG_IMXRT_LPSPI4
|
||||
true,
|
||||
#else
|
||||
false,
|
||||
#endif
|
||||
#ifdef CONFIG_IMXRT_LPSPI5
|
||||
true,
|
||||
#else
|
||||
false,
|
||||
#endif
|
||||
#ifdef CONFIG_IMXRT_LPSPI6
|
||||
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;
|
||||
}
|
||||
|
||||
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{};
|
||||
|
@ -132,8 +183,41 @@ static inline constexpr SPI::bus_device_external_cfg_t initSPIConfigExternal(SPI
|
|||
return ret;
|
||||
}
|
||||
|
||||
constexpr bool validateSPIConfig(const px4_spi_bus_t spi_busses_conf[SPI_BUS_MAX_BUS_ITEMS])
|
||||
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_revision,
|
||||
const px4_spi_bus_array_t &bus_items)
|
||||
{
|
||||
return true;
|
||||
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_revision = hw_version_revision;
|
||||
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;
|
||||
}
|
||||
|
||||
#endif // CONFIG_SPI
|
||||
|
|
Loading…
Reference in New Issue