AP_HAL_Linux: don't manually define number of spi devices
It's error-prone, let's make the compiler define it for us.
This commit is contained in:
parent
82314ee4a3
commit
b211b86204
@ -1,3 +1,4 @@
|
||||
#include <AP_Common.h>
|
||||
#include <AP_HAL.h>
|
||||
|
||||
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
|
||||
@ -23,7 +24,7 @@ extern const AP_HAL::HAL& hal;
|
||||
#define KHZ (1000U)
|
||||
|
||||
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXF || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLE
|
||||
LinuxSPIDeviceDriver LinuxSPIDeviceManager::_device[LINUX_SPI_DEVICE_NUM_DEVICES] = {
|
||||
LinuxSPIDeviceDriver LinuxSPIDeviceManager::_device[] = {
|
||||
// different SPI tables per board subtype
|
||||
LinuxSPIDeviceDriver(1, 0, AP_HAL::SPIDevice_LSM9DS0_AM, SPI_MODE_3, 8, BBB_P9_17, 10*MHZ,10*MHZ),
|
||||
LinuxSPIDeviceDriver(1, 0, AP_HAL::SPIDevice_LSM9DS0_G, SPI_MODE_3, 8, BBB_P8_9, 10*MHZ,10*MHZ),
|
||||
@ -34,13 +35,13 @@ LinuxSPIDeviceDriver LinuxSPIDeviceManager::_device[LINUX_SPI_DEVICE_NUM_DEVICES
|
||||
LinuxSPIDeviceDriver(2, 0, AP_HAL::SPIDevice_Dataflash, SPI_MODE_3, 8, BBB_P8_12, 6*MHZ, 6*MHZ),
|
||||
};
|
||||
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
|
||||
LinuxSPIDeviceDriver LinuxSPIDeviceManager::_device[LINUX_SPI_DEVICE_NUM_DEVICES] = {
|
||||
LinuxSPIDeviceDriver LinuxSPIDeviceManager::_device[] = {
|
||||
/* MPU9250 is restricted to 1MHz for non-data and interrupt registers */
|
||||
LinuxSPIDeviceDriver(0, 1, AP_HAL::SPIDevice_MPU9250, SPI_MODE_0, 8, SPI_CS_KERNEL, 1*MHZ, 16*MHZ),
|
||||
LinuxSPIDeviceDriver(0, 0, AP_HAL::SPIDevice_Ublox, SPI_MODE_0, 8, SPI_CS_KERNEL, 250*KHZ, 4*MHZ),
|
||||
};
|
||||
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
|
||||
LinuxSPIDeviceDriver LinuxSPIDeviceManager::_device[LINUX_SPI_DEVICE_NUM_DEVICES] = {
|
||||
LinuxSPIDeviceDriver LinuxSPIDeviceManager::_device[] = {
|
||||
/* MPU9250 is restricted to 1MHz for non-data and interrupt registers */
|
||||
LinuxSPIDeviceDriver(2, 0, AP_HAL::SPIDevice_MPU9250, SPI_MODE_3, 8, SPI_CS_KERNEL, 1*MHZ, 20*MHZ),
|
||||
LinuxSPIDeviceDriver(2, 1, AP_HAL::SPIDevice_MS5611, SPI_MODE_3, 8, SPI_CS_KERNEL, 10*MHZ,10*MHZ),
|
||||
@ -50,6 +51,8 @@ LinuxSPIDeviceDriver LinuxSPIDeviceManager::_device[LINUX_SPI_DEVICE_NUM_DEVICES
|
||||
LinuxSPIDeviceDriver LinuxSPIDeviceManager::_device[0];
|
||||
#endif
|
||||
|
||||
#define LINUX_SPI_DEVICE_NUM_DEVICES ARRAY_SIZE(LinuxSPIDeviceManager::_device)
|
||||
|
||||
// have a separate semaphore per bus
|
||||
LinuxSemaphore LinuxSPIDeviceManager::_semaphore[LINUX_SPI_MAX_BUSES];
|
||||
|
||||
|
@ -5,16 +5,6 @@
|
||||
#include <AP_HAL_Linux.h>
|
||||
#include "Semaphores.h"
|
||||
|
||||
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXF || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLE
|
||||
#define LINUX_SPI_DEVICE_NUM_DEVICES 6
|
||||
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
|
||||
#define LINUX_SPI_DEVICE_NUM_DEVICES 2
|
||||
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
|
||||
#define LINUX_SPI_DEVICE_NUM_DEVICES 2
|
||||
#else
|
||||
#define LINUX_SPI_DEVICE_NUM_DEVICES 0
|
||||
#endif
|
||||
|
||||
// Most platforms won't need to declare the spidev bus offset
|
||||
#ifndef LINUX_SPIDEV_BUS_OFFSET
|
||||
#define LINUX_SPIDEV_BUS_OFFSET 0
|
||||
@ -65,7 +55,7 @@ public:
|
||||
static void transaction(LinuxSPIDeviceDriver &driver, const uint8_t *tx, uint8_t *rx, uint16_t len);
|
||||
|
||||
private:
|
||||
static LinuxSPIDeviceDriver _device[LINUX_SPI_DEVICE_NUM_DEVICES];
|
||||
static LinuxSPIDeviceDriver _device[];
|
||||
static LinuxSemaphore _semaphore[LINUX_SPI_MAX_BUSES];
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user