mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-30 15:45:33 +08:00
SPI config: use enum to specify bus
This commit is contained in:
@@ -379,6 +379,13 @@ static inline constexpr uint32_t getGPIOPin(GPIO::Pin pin)
|
||||
namespace SPI
|
||||
{
|
||||
|
||||
enum class Bus {
|
||||
LPSPI1 = 1,
|
||||
LPSPI2,
|
||||
LPSPI3,
|
||||
LPSPI4,
|
||||
};
|
||||
|
||||
using CS = GPIO::GPIOPin; ///< chip-select pin
|
||||
using DRDY = GPIO::GPIOPin; ///< data ready pin
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ static inline constexpr px4_spi_bus_device_t initSPIDevice(uint32_t devid, SPI::
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline constexpr px4_spi_bus_t initSPIBus(int bus, const px4_spi_bus_devices_t &devices,
|
||||
static inline constexpr px4_spi_bus_t initSPIBus(SPI::Bus bus, const px4_spi_bus_devices_t &devices,
|
||||
GPIO::GPIOPin power_enable = {})
|
||||
{
|
||||
px4_spi_bus_t ret{};
|
||||
@@ -88,7 +88,7 @@ static inline constexpr px4_spi_bus_t initSPIBus(int bus, const px4_spi_bus_devi
|
||||
}
|
||||
}
|
||||
|
||||
ret.bus = bus;
|
||||
ret.bus = (int)bus;
|
||||
ret.is_external = false;
|
||||
|
||||
if (power_enable.port != GPIO::PortInvalid) {
|
||||
@@ -104,7 +104,7 @@ 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)
|
||||
static inline constexpr px4_spi_bus_t initSPIBusExternal(SPI::Bus bus, const bus_device_external_cfg_array_t &devices)
|
||||
{
|
||||
px4_spi_bus_t ret{};
|
||||
|
||||
@@ -116,7 +116,7 @@ static inline constexpr px4_spi_bus_t initSPIBusExternal(int bus, const bus_devi
|
||||
ret.devices[i] = initSPIDevice(i, devices.devices[i].cs_gpio, devices.devices[i].drdy_gpio);
|
||||
}
|
||||
|
||||
ret.bus = bus;
|
||||
ret.bus = (int)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
|
||||
|
||||
@@ -232,6 +232,12 @@ static inline constexpr uint32_t getGPIOPin(GPIO::Pin pin)
|
||||
namespace SPI
|
||||
{
|
||||
|
||||
enum class Bus {
|
||||
SPI0 = 1,
|
||||
SPI1,
|
||||
SPI2,
|
||||
};
|
||||
|
||||
using CS = GPIO::GPIOPin; ///< chip-select pin
|
||||
using DRDY = GPIO::GPIOPin; ///< data ready pin
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ static inline constexpr px4_spi_bus_device_t initSPIDevice(uint32_t devid, SPI::
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline constexpr px4_spi_bus_t initSPIBus(int bus, const px4_spi_bus_devices_t &devices,
|
||||
static inline constexpr px4_spi_bus_t initSPIBus(SPI::Bus bus, const px4_spi_bus_devices_t &devices,
|
||||
GPIO::GPIOPin power_enable = {})
|
||||
{
|
||||
px4_spi_bus_t ret{};
|
||||
@@ -82,7 +82,7 @@ static inline constexpr px4_spi_bus_t initSPIBus(int bus, const px4_spi_bus_devi
|
||||
}
|
||||
}
|
||||
|
||||
ret.bus = bus;
|
||||
ret.bus = (int)bus;
|
||||
ret.is_external = false;
|
||||
|
||||
if (power_enable.port != GPIO::PortInvalid) {
|
||||
@@ -98,7 +98,7 @@ 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)
|
||||
static inline constexpr px4_spi_bus_t initSPIBusExternal(SPI::Bus bus, const bus_device_external_cfg_array_t &devices)
|
||||
{
|
||||
px4_spi_bus_t ret{};
|
||||
|
||||
@@ -110,7 +110,7 @@ static inline constexpr px4_spi_bus_t initSPIBusExternal(int bus, const bus_devi
|
||||
ret.devices[i] = initSPIDevice(i, devices.devices[i].cs_gpio, devices.devices[i].drdy_gpio);
|
||||
}
|
||||
|
||||
ret.bus = bus;
|
||||
ret.bus = (int)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
|
||||
|
||||
@@ -289,6 +289,15 @@ static inline constexpr uint32_t getGPIOPin(GPIO::Pin pin)
|
||||
namespace SPI
|
||||
{
|
||||
|
||||
enum class Bus {
|
||||
SPI1 = 1,
|
||||
SPI2,
|
||||
SPI3,
|
||||
SPI4,
|
||||
SPI5,
|
||||
SPI6,
|
||||
};
|
||||
|
||||
using CS = GPIO::GPIOPin; ///< chip-select pin
|
||||
using DRDY = GPIO::GPIOPin; ///< data ready pin
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ static inline constexpr px4_spi_bus_device_t initSPIDevice(uint32_t devid, SPI::
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline constexpr px4_spi_bus_t initSPIBus(int bus, const px4_spi_bus_devices_t &devices,
|
||||
static inline constexpr px4_spi_bus_t initSPIBus(SPI::Bus bus, const px4_spi_bus_devices_t &devices,
|
||||
GPIO::GPIOPin power_enable = {})
|
||||
{
|
||||
px4_spi_bus_t ret{};
|
||||
@@ -84,7 +84,7 @@ static inline constexpr px4_spi_bus_t initSPIBus(int bus, const px4_spi_bus_devi
|
||||
}
|
||||
}
|
||||
|
||||
ret.bus = bus;
|
||||
ret.bus = (int)bus;
|
||||
ret.is_external = false;
|
||||
|
||||
if (power_enable.port != GPIO::PortInvalid) {
|
||||
@@ -100,7 +100,7 @@ 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)
|
||||
static inline constexpr px4_spi_bus_t initSPIBusExternal(SPI::Bus bus, const bus_device_external_cfg_array_t &devices)
|
||||
{
|
||||
px4_spi_bus_t ret{};
|
||||
|
||||
@@ -112,7 +112,7 @@ static inline constexpr px4_spi_bus_t initSPIBusExternal(int bus, const bus_devi
|
||||
ret.devices[i] = initSPIDevice(i, devices.devices[i].cs_gpio, devices.devices[i].drdy_gpio);
|
||||
}
|
||||
|
||||
ret.bus = bus;
|
||||
ret.bus = (int)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
|
||||
|
||||
Reference in New Issue
Block a user