mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-15 19:03:33 +08:00
px4_fmu-v4: add runtime external SPI4 detection to support pmw3901 (#11301)
* The build is built with SPI4. At run time the signal GPIO_8266_GPIO2 it tested. If it is low the SPI4 is configured. If it is high SPI4 is not configured. * board_common: Add Notion of Board has bus manifest
This commit is contained in:
committed by
Daniel Agar
parent
53a127beb9
commit
6f9a9b3d2c
@@ -1075,6 +1075,24 @@ __EXPORT bool px4_spi_bus_external(int bus);
|
||||
|
||||
#endif /* BOARD_HAS_SIMPLE_HW_VERSIONING */
|
||||
|
||||
/************************************************************************************
|
||||
* Name: board_has_bus
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
enum board_bus_types {
|
||||
BOARD_SPI_BUS = 1,
|
||||
BOARD_I2C_BUS = 2
|
||||
};
|
||||
|
||||
#if defined(BOARD_HAS_BUS_MANIFEST)
|
||||
|
||||
__EXPORT bool board_has_bus(enum board_bus_types type, uint32_t bus);
|
||||
|
||||
#else
|
||||
# define board_has_bus(t, b) true
|
||||
#endif /* BOARD_HAS_BUS_MANIFEST */
|
||||
|
||||
/************************************************************************************
|
||||
* Name: board_hardfault_init
|
||||
*
|
||||
|
||||
@@ -79,20 +79,25 @@
|
||||
#include <board_config.h>
|
||||
|
||||
/* Configuration Constants */
|
||||
#if defined PX4_SPI_BUS_EXPANSION // crazyflie
|
||||
#define PMW3901_BUS PX4_SPI_BUS_EXPANSION
|
||||
#elif defined PX4_SPI_BUS_EXTERNAL1 // fmu-v5
|
||||
#define PMW3901_BUS PX4_SPI_BUS_EXTERNAL1
|
||||
|
||||
#if defined PX4_SPI_BUS_EXPANSION // crazyflie
|
||||
# define PMW3901_BUS PX4_SPI_BUS_EXPANSION
|
||||
#elif defined PX4_SPI_BUS_EXTERNAL1 // fmu-v5
|
||||
# define PMW3901_BUS PX4_SPI_BUS_EXTERNAL1
|
||||
#elif defined PX4_SPI_BUS_EXTERNAL // fmu-v4 extspi
|
||||
# define PMW3901_BUS PX4_SPI_BUS_EXTERNAL
|
||||
#else
|
||||
#error "add the required spi bus from board_config.h here"
|
||||
# error "add the required spi bus from board_config.h here"
|
||||
#endif
|
||||
|
||||
#if defined PX4_SPIDEV_EXPANSION_2 // crazyflie flow deck
|
||||
#define PMW3901_SPIDEV PX4_SPIDEV_EXPANSION_2
|
||||
#elif defined PX4_SPIDEV_EXTERNAL1_1 // fmu-v5 ext CS1
|
||||
#define PMW3901_SPIDEV PX4_SPIDEV_EXTERNAL1_1
|
||||
#if defined PX4_SPIDEV_EXPANSION_2 // crazyflie flow deck
|
||||
# define PMW3901_SPIDEV PX4_SPIDEV_EXPANSION_2
|
||||
#elif defined PX4_SPIDEV_EXTERNAL1_1 // fmu-v5 ext CS1
|
||||
# define PMW3901_SPIDEV PX4_SPIDEV_EXTERNAL1_1
|
||||
#elif defined PX4_SPIDEV_EXTERNAL // fmu-v4 extspi
|
||||
# define PMW3901_SPIDEV PX4_SPIDEV_EXTERNAL
|
||||
#else
|
||||
#error "add the required spi dev from board_config.h here"
|
||||
# error "add the required spi dev from board_config.h here"
|
||||
#endif
|
||||
|
||||
#define PMW3901_SPI_BUS_SPEED (2000000L) // 2MHz
|
||||
|
||||
@@ -94,7 +94,14 @@ SPI::init()
|
||||
|
||||
/* attach to the spi bus */
|
||||
if (_dev == nullptr) {
|
||||
_dev = px4_spibus_initialize(get_device_bus());
|
||||
int bus = get_device_bus();
|
||||
|
||||
if (!board_has_bus(BOARD_SPI_BUS, bus)) {
|
||||
ret = -ENOENT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
_dev = px4_spibus_initialize(bus);
|
||||
}
|
||||
|
||||
if (_dev == nullptr) {
|
||||
|
||||
Reference in New Issue
Block a user