From f5c8754d756ff1fb03d2208542b69762cc40bb77 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 12 Jan 2018 12:49:33 +1100 Subject: [PATCH] HAL_ChibiOS: use ARRAY_SIZE_SIMPLE this allows for boards without a device type (eg. no SPI bus) --- libraries/AP_HAL_ChibiOS/AnalogIn.cpp | 2 +- libraries/AP_HAL_ChibiOS/GPIO.cpp | 6 +++--- libraries/AP_HAL_ChibiOS/I2CDevice.cpp | 6 +++--- libraries/AP_HAL_ChibiOS/RCOutput.cpp | 2 +- libraries/AP_HAL_ChibiOS/SPIDevice.cpp | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/AnalogIn.cpp b/libraries/AP_HAL_ChibiOS/AnalogIn.cpp index bdf3017549..23b15f6aaa 100644 --- a/libraries/AP_HAL_ChibiOS/AnalogIn.cpp +++ b/libraries/AP_HAL_ChibiOS/AnalogIn.cpp @@ -58,7 +58,7 @@ const ChibiAnalogIn::pin_info ChibiAnalogIn::pin_config[] = { { 15, VOLTAGE_SCALING*2 }, // analog airspeed sensor, 2:1 scaling }; -#define ADC_GRP1_NUM_CHANNELS ARRAY_SIZE(ChibiAnalogIn::pin_config) +#define ADC_GRP1_NUM_CHANNELS ARRAY_SIZE_SIMPLE(ChibiAnalogIn::pin_config) // samples filled in by ADC DMA engine adcsample_t ChibiAnalogIn::samples[ADC_DMA_BUF_DEPTH*ADC_GRP1_NUM_CHANNELS]; diff --git a/libraries/AP_HAL_ChibiOS/GPIO.cpp b/libraries/AP_HAL_ChibiOS/GPIO.cpp index 8e26a65d76..b0d73c31e0 100644 --- a/libraries/AP_HAL_ChibiOS/GPIO.cpp +++ b/libraries/AP_HAL_ChibiOS/GPIO.cpp @@ -49,7 +49,7 @@ static struct gpio_entry { #endif }; -#define NUM_PINS ARRAY_SIZE(_gpio_tab) +#define NUM_PINS ARRAY_SIZE_SIMPLE(_gpio_tab) #define PIN_ENABLED(pin) ((pin)= 50 && pin_num <= 55) { // enable GPIOs based on BRD_PWM_COUNT diff --git a/libraries/AP_HAL_ChibiOS/I2CDevice.cpp b/libraries/AP_HAL_ChibiOS/I2CDevice.cpp index a0d41df2bd..c4ca329b35 100644 --- a/libraries/AP_HAL_ChibiOS/I2CDevice.cpp +++ b/libraries/AP_HAL_ChibiOS/I2CDevice.cpp @@ -31,7 +31,7 @@ static const struct I2CInfo { using namespace ChibiOS; extern const AP_HAL::HAL& hal; -I2CBus I2CDeviceManager::businfo[ARRAY_SIZE(I2CD)]; +I2CBus I2CDeviceManager::businfo[ARRAY_SIZE_SIMPLE(I2CD)]; // get a handle for DMA sharing DMA channels with other subsystems void I2CBus::dma_init(void) @@ -44,7 +44,7 @@ void I2CBus::dma_init(void) // setup I2C buses I2CDeviceManager::I2CDeviceManager(void) { - for (uint8_t i=0; i= ARRAY_SIZE(I2CD)) { + if (bus >= ARRAY_SIZE_SIMPLE(I2CD)) { return AP_HAL::OwnPtr(nullptr); } auto dev = AP_HAL::OwnPtr(new I2CDevice(bus, address, bus_clock, use_smbus, timeout_ms)); diff --git a/libraries/AP_HAL_ChibiOS/RCOutput.cpp b/libraries/AP_HAL_ChibiOS/RCOutput.cpp index 673a7e5843..8bdc827d73 100644 --- a/libraries/AP_HAL_ChibiOS/RCOutput.cpp +++ b/libraries/AP_HAL_ChibiOS/RCOutput.cpp @@ -58,7 +58,7 @@ const struct ChibiRCOutput::pwm_group ChibiRCOutput::pwm_group_list[] = } }; -#define NUM_GROUPS ARRAY_SIZE(pwm_group_list) +#define NUM_GROUPS ARRAY_SIZE_SIMPLE(pwm_group_list) void ChibiRCOutput::init() { diff --git a/libraries/AP_HAL_ChibiOS/SPIDevice.cpp b/libraries/AP_HAL_ChibiOS/SPIDevice.cpp index a3a3d7f524..af6755c8a8 100644 --- a/libraries/AP_HAL_ChibiOS/SPIDevice.cpp +++ b/libraries/AP_HAL_ChibiOS/SPIDevice.cpp @@ -276,12 +276,12 @@ SPIDeviceManager::get_device(const char *name) { /* Find the bus description in the table */ uint8_t i; - for (i = 0; i(nullptr); }