From e246ecf53604d153c06bc4ae628584dd2b3913c3 Mon Sep 17 00:00:00 2001 From: Brian Webb Date: Tue, 16 Jul 2013 21:09:48 -0700 Subject: [PATCH] Moves pios_led functionality to pios_gpio and makes pios_led a thin layer over pios_gpio. Supports configuring multiple sets of GPIOs. --- flight/pios/common/pios_led.c | 81 ++++++++ flight/pios/inc/pios_gpio.h | 8 +- flight/pios/inc/pios_led_priv.h | 16 +- flight/pios/pios.h | 2 + flight/pios/stm32f10x/pios_gpio.c | 136 ++++++++++---- flight/pios/stm32f10x/pios_led.c | 159 ---------------- flight/pios/stm32f4xx/pios_gpio.c | 153 +++++++++++---- flight/pios/stm32f4xx/pios_led.c | 177 ------------------ .../boards/coptercontrol/board_hw_defs.c | 20 +- .../coptercontrol/bootloader/pios_board.c | 5 +- .../coptercontrol/firmware/pios_board.c | 4 +- .../targets/boards/oplinkmini/board_hw_defs.c | 14 +- .../boards/oplinkmini/bootloader/pios_board.c | 3 - .../boards/oplinkmini/firmware/pios_board.c | 1 - flight/targets/boards/osd/board_hw_defs.c | 12 +- .../boards/osd/bootloader/inc/pios_config.h | 1 + .../boards/osd/firmware/inc/pios_config.h | 2 +- .../targets/boards/revolution/board_hw_defs.c | 22 ++- .../revolution/bootloader/inc/pios_config.h | 1 + .../boards/revolution/bootloader/pios_board.c | 2 +- .../revolution/firmware/inc/pios_config.h | 2 +- .../boards/revolution/firmware/pios_board.c | 2 +- .../targets/boards/revoproto/board_hw_defs.c | 12 +- .../revoproto/bootloader/inc/pios_config.h | 1 + .../revoproto/firmware/inc/pios_config.h | 2 +- .../common/bootloader_updater/Makefile | 1 + .../bootloader_updater/inc/pios_config.h | 1 + .../common/bootloader_updater/pios_board.c | 7 +- make/apps-defs.mk | 1 + make/boot-defs.mk | 1 + 30 files changed, 364 insertions(+), 485 deletions(-) create mode 100644 flight/pios/common/pios_led.c delete mode 100644 flight/pios/stm32f10x/pios_led.c delete mode 100644 flight/pios/stm32f4xx/pios_led.c diff --git a/flight/pios/common/pios_led.c b/flight/pios/common/pios_led.c new file mode 100644 index 000000000..4e67495fa --- /dev/null +++ b/flight/pios/common/pios_led.c @@ -0,0 +1,81 @@ +/** + ****************************************************************************** + * @addtogroup PIOS PIOS Core hardware abstraction layer + * @{ + * @addtogroup PIOS_LED LED Functions + * @brief STM32 Hardware LED handling code + * @{ + * + * @file pios_led.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @brief LED functions, init, toggle, on & off. + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "pios.h" + +#ifdef PIOS_INCLUDE_LED + +#include +#include + +static uint32_t pios_led_gpios_id; + +/** + * Initialises all the LED's + */ +int32_t PIOS_LED_Init(const struct pios_gpio_cfg *cfg) +{ + PIOS_Assert(cfg); + return PIOS_GPIO_Init(&pios_led_gpios_id, cfg); +} + +/** + * Turn on LED + * \param[in] LED LED id + */ +void PIOS_LED_On(uint32_t led_id) +{ + PIOS_GPIO_On(pios_led_gpios_id, led_id); +} + +/** + * Turn off LED + * \param[in] LED LED id + */ +void PIOS_LED_Off(uint32_t led_id) +{ + PIOS_GPIO_Off(pios_led_gpios_id, led_id); +} + +/** + * Toggle LED on/off + * \param[in] LED LED id + */ +void PIOS_LED_Toggle(uint32_t led_id) +{ + PIOS_GPIO_Toggle(pios_led_gpios_id, led_id); +} + +#endif /* PIOS_INCLUDE_LED */ + +/** + * @} + * @} + */ diff --git a/flight/pios/inc/pios_gpio.h b/flight/pios/inc/pios_gpio.h index aec0ba417..8bad5043e 100644 --- a/flight/pios/inc/pios_gpio.h +++ b/flight/pios/inc/pios_gpio.h @@ -32,11 +32,9 @@ #define PIOS_GPIO_H /* Public Functions */ -extern void PIOS_GPIO_Init(void); -extern void PIOS_GPIO_Enable(uint8_t Pin); -extern void PIOS_GPIO_On(uint8_t Pin); -extern void PIOS_GPIO_Off(uint8_t Pin); -extern void PIOS_GPIO_Toggle(uint8_t Pin); +extern void PIOS_GPIO_On(uint32_t gpios_dev_id, uint8_t gpio_id); +extern void PIOS_GPIO_Off(uint32_t gpios_dev_id, uint8_t gpio_id); +extern void PIOS_GPIO_Toggle(uint32_t gpios_dev_id, uint8_t gpio_id); #endif /* PIOS_GPIO_H */ diff --git a/flight/pios/inc/pios_led_priv.h b/flight/pios/inc/pios_led_priv.h index e0ce76a65..12c9a1350 100644 --- a/flight/pios/inc/pios_led_priv.h +++ b/flight/pios/inc/pios_led_priv.h @@ -31,21 +31,9 @@ #ifndef PIOS_LED_PRIV_H #define PIOS_LED_PRIV_H -#include -#include +#include -struct pios_led { - struct stm32_gpio pin; - uint32_t remap; - bool active_high; -}; - -struct pios_led_cfg { - const struct pios_led *leds; - uint8_t num_leds; -}; - -extern int32_t PIOS_LED_Init(const struct pios_led_cfg *cfg); +extern int32_t PIOS_LED_Init(const struct pios_gpio_cfg *cfg); #endif /* PIOS_LED_PRIV_H */ diff --git a/flight/pios/pios.h b/flight/pios/pios.h index 5a47b676a..1a566627d 100644 --- a/flight/pios/pios.h +++ b/flight/pios/pios.h @@ -81,6 +81,8 @@ #include "semphr.h" #endif +#include + #include #ifdef PIOS_INCLUDE_TASK_MONITOR diff --git a/flight/pios/stm32f10x/pios_gpio.c b/flight/pios/stm32f10x/pios_gpio.c index 81bdac8f2..2f7c8d396 100644 --- a/flight/pios/stm32f10x/pios_gpio.c +++ b/flight/pios/stm32f10x/pios_gpio.c @@ -2,12 +2,12 @@ ****************************************************************************** * @addtogroup PIOS PIOS Core hardware abstraction layer * @{ - * @defgroup PIOS_GPIO GPIO Functions - * @brief GPIO hardware code for STM32 + * @addtogroup PIOS_GPIO GPIO Functions + * @brief STM32 Hardware GPIO handling code * @{ * * @file pios_gpio.c - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013. * @brief GPIO functions, init, toggle, on & off. * @see The GNU Public License (GPL) Version 3 * @@ -32,65 +32,125 @@ #ifdef PIOS_INCLUDE_GPIO -/* Private Function Prototypes */ - -/* Local Variables */ -static GPIO_TypeDef *GPIO_PORT[PIOS_GPIO_NUM] = PIOS_GPIO_PORTS; -static const uint32_t GPIO_PIN[PIOS_GPIO_NUM] = PIOS_GPIO_PINS; -static const uint32_t GPIO_CLK[PIOS_GPIO_NUM] = PIOS_GPIO_CLKS; +#include /** * Initialises all the GPIO's */ -void PIOS_GPIO_Init(void) +int32_t PIOS_GPIO_Init(uint32_t *gpios_dev_id, const struct pios_gpio_cfg *cfg) { - /* Do nothing */ + PIOS_Assert(cfg); + *gpios_dev_id = (uint32_t)cfg; + + for (uint8_t i = 0; i < cfg->num_gpios; i++) { + const struct pios_gpio *gpio = &(cfg->gpios[i]); + + /* Enable the peripheral clock for the GPIO */ + switch ((uint32_t)gpio->pin.gpio) { + case (uint32_t)GPIOA: + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); + break; + case (uint32_t)GPIOB: + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); + break; + case (uint32_t)GPIOC: + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); + break; + default: + PIOS_Assert(0); + break; + } + + if (gpio->remap) { + GPIO_PinRemapConfig(gpio->remap, ENABLE); + } + + GPIO_Init(gpio->pin.gpio, &gpio->pin.init); + + PIOS_GPIO_Off(*gpios_dev_id, i); + } + + return 0; } /** - * Enable a GPIO Pin - * \param[in] Pin Pin Number + * Turn on GPIO + * \param[in] GPIO GPIO id */ -void PIOS_GPIO_Enable(uint8_t Pin) +void PIOS_GPIO_On(uint32_t gpios_dev_id, uint8_t gpio_id) { - // RCC_APB2PeriphClockCmd(GPIO_CLK[Pin], ENABLE); + const struct pios_gpio_cfg *gpio_cfg = (const struct pios_gpio_cfg *)gpios_dev_id; - GPIO_InitTypeDef GPIO_InitStructure; + PIOS_Assert(gpio_cfg); - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; - GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Pin]; - GPIO_Init(GPIO_PORT[Pin], &GPIO_InitStructure); + if (gpio_id >= gpio_cfg->num_gpios) { + /* GPIO index out of range */ + return; + } - /* GPIO's Off */ - GPIO_PORT[Pin]->BSRR = GPIO_PIN[Pin]; + const struct pios_gpio *gpio = &(gpio_cfg->gpios[gpio_id]); + + if (gpio->active_low) { + GPIO_ResetBits(gpio->pin.gpio, gpio->pin.init.GPIO_Pin); + } else { + GPIO_SetBits(gpio->pin.gpio, gpio->pin.init.GPIO_Pin); + } } /** - * Turn on Pin - * \param[in] Pin Pin Number + * Turn off GPIO + * \param[in] GPIO GPIO id */ -void PIOS_GPIO_On(uint8_t Pin) +void PIOS_GPIO_Off(uint32_t gpios_dev_id, uint8_t gpio_id) { - GPIO_PORT[Pin]->BRR = GPIO_PIN[Pin]; + const struct pios_gpio_cfg *gpio_cfg = (const struct pios_gpio_cfg *)gpios_dev_id; + + PIOS_Assert(gpio_cfg); + + if (gpio_id >= gpio_cfg->num_gpios) { + /* GPIO index out of range */ + return; + } + + const struct pios_gpio *gpio = &(gpio_cfg->gpios[gpio_id]); + + if (gpio->active_low) { + GPIO_SetBits(gpio->pin.gpio, gpio->pin.init.GPIO_Pin); + } else { + GPIO_ResetBits(gpio->pin.gpio, gpio->pin.init.GPIO_Pin); + } } /** - * Turn off Pin - * \param[in] Pin Pin Number + * Toggle GPIO on/off + * \param[in] GPIO GPIO id */ -void PIOS_GPIO_Off(uint8_t Pin) +void PIOS_GPIO_Toggle(uint32_t gpios_dev_id, uint8_t gpio_id) { - GPIO_PORT[Pin]->BSRR = GPIO_PIN[Pin]; -} + const struct pios_gpio_cfg *gpio_cfg = (const struct pios_gpio_cfg *)gpios_dev_id; -/** - * Toggle Pin on/off - * \param[in] Pin Pin Number - */ -void PIOS_GPIO_Toggle(uint8_t Pin) -{ - GPIO_PORT[Pin]->ODR ^= GPIO_PIN[Pin]; + PIOS_Assert(gpio_cfg); + + if (gpio_id >= gpio_cfg->num_gpios) { + /* GPIO index out of range */ + return; + } + + const struct pios_gpio *gpio = &(gpio_cfg->gpios[gpio_id]); + + if (GPIO_ReadOutputDataBit(gpio->pin.gpio, gpio->pin.init.GPIO_Pin) == Bit_SET) { + if (gpio->active_low) { + PIOS_GPIO_On(gpios_dev_id, gpio_id); + } else { + PIOS_GPIO_Off(gpios_dev_id, gpio_id); + } + } else { + if (gpio->active_low) { + PIOS_GPIO_Off(gpios_dev_id, gpio_id); + } else { + PIOS_GPIO_On(gpios_dev_id, gpio_id); + } + } } #endif /* PIOS_INCLUDE_GPIO */ diff --git a/flight/pios/stm32f10x/pios_led.c b/flight/pios/stm32f10x/pios_led.c deleted file mode 100644 index 696544189..000000000 --- a/flight/pios/stm32f10x/pios_led.c +++ /dev/null @@ -1,159 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup PIOS PIOS Core hardware abstraction layer - * @{ - * @addtogroup PIOS_LED LED Functions - * @brief STM32 Hardware LED handling code - * @{ - * - * @file pios_led.c - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. - * @brief LED functions, init, toggle, on & off. - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "pios.h" - -#ifdef PIOS_INCLUDE_LED - -#include - -static const struct pios_led_cfg *led_cfg; - -/** - * Initialises all the LED's - */ -int32_t PIOS_LED_Init(const struct pios_led_cfg *cfg) -{ - PIOS_Assert(cfg); - - /* Store away the config in a global used by API functions */ - led_cfg = cfg; - - for (uint8_t i = 0; i < cfg->num_leds; i++) { - const struct pios_led *led = &(cfg->leds[i]); - - /* Enable the peripheral clock for the GPIO */ - switch ((uint32_t)led->pin.gpio) { - case (uint32_t)GPIOA: - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); - break; - case (uint32_t)GPIOB: - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); - break; - case (uint32_t)GPIOC: - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); - break; - default: - PIOS_Assert(0); - break; - } - - if (led->remap) { - GPIO_PinRemapConfig(led->remap, ENABLE); - } - - GPIO_Init(led->pin.gpio, &led->pin.init); - - PIOS_LED_Off(i); - } - - return 0; -} - -/** - * Turn on LED - * \param[in] LED LED id - */ -void PIOS_LED_On(uint32_t led_id) -{ - PIOS_Assert(led_cfg); - - if (led_id >= led_cfg->num_leds) { - /* LED index out of range */ - return; - } - - const struct pios_led *led = &(led_cfg->leds[led_id]); - - if (led->active_high) { - GPIO_SetBits(led->pin.gpio, led->pin.init.GPIO_Pin); - } else { - GPIO_ResetBits(led->pin.gpio, led->pin.init.GPIO_Pin); - } -} - -/** - * Turn off LED - * \param[in] LED LED id - */ -void PIOS_LED_Off(uint32_t led_id) -{ - PIOS_Assert(led_cfg); - - if (led_id >= led_cfg->num_leds) { - /* LED index out of range */ - return; - } - - const struct pios_led *led = &(led_cfg->leds[led_id]); - - if (led->active_high) { - GPIO_ResetBits(led->pin.gpio, led->pin.init.GPIO_Pin); - } else { - GPIO_SetBits(led->pin.gpio, led->pin.init.GPIO_Pin); - } -} - -/** - * Toggle LED on/off - * \param[in] LED LED id - */ -void PIOS_LED_Toggle(uint32_t led_id) -{ - PIOS_Assert(led_cfg); - - if (led_id >= led_cfg->num_leds) { - /* LED index out of range */ - return; - } - - const struct pios_led *led = &(led_cfg->leds[led_id]); - - if (GPIO_ReadOutputDataBit(led->pin.gpio, led->pin.init.GPIO_Pin) == Bit_SET) { - if (led->active_high) { - PIOS_LED_Off(led_id); - } else { - PIOS_LED_On(led_id); - } - } else { - if (led->active_high) { - PIOS_LED_On(led_id); - } else { - PIOS_LED_Off(led_id); - } - } -} - -#endif /* PIOS_INCLUDE_LED */ - -/** - * @} - * @} - */ diff --git a/flight/pios/stm32f4xx/pios_gpio.c b/flight/pios/stm32f4xx/pios_gpio.c index 46850f4c1..2e6c2ce76 100644 --- a/flight/pios/stm32f4xx/pios_gpio.c +++ b/flight/pios/stm32f4xx/pios_gpio.c @@ -2,8 +2,8 @@ ****************************************************************************** * @addtogroup PIOS PIOS Core hardware abstraction layer * @{ - * @defgroup PIOS_GPIO GPIO Functions - * @brief GPIO hardware code for STM32F4xx + * @addtogroup PIOS_GPIO GPIO Functions + * @brief STM32 Hardware GPIO handling code * @{ * * @file pios_gpio.c @@ -32,64 +32,143 @@ #ifdef PIOS_INCLUDE_GPIO -/* Private Function Prototypes */ - -/* Local Variables */ -static GPIO_TypeDef *GPIO_PORT[PIOS_GPIO_NUM] = PIOS_GPIO_PORTS; -static const uint32_t GPIO_PIN[PIOS_GPIO_NUM] = PIOS_GPIO_PINS; +#include /** * Initialises all the GPIO's */ -void PIOS_GPIO_Init(void) +int32_t PIOS_GPIO_Init(uint32_t *gpios_dev_id, const struct pios_gpio_cfg *cfg) { - /* Do nothing */ + PIOS_Assert(cfg); + *gpios_dev_id = (uint32_t)cfg; + + for (uint8_t i = 0; i < cfg->num_gpios; i++) { + const struct pios_gpio *gpio = &(cfg->gpios[i]); + + /* Enable the peripheral clock for the GPIO */ + switch ((uint32_t)gpio->pin.gpio) { + case (uint32_t)GPIOA: + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); + break; + case (uint32_t)GPIOB: + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); + break; + case (uint32_t)GPIOC: + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); + break; + case (uint32_t)GPIOD: + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); + break; + case (uint32_t)GPIOE: + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE); + break; + case (uint32_t)GPIOF: + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE); + break; + case (uint32_t)GPIOG: + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE); + break; + case (uint32_t)GPIOH: + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE); + break; + case (uint32_t)GPIOI: + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI, ENABLE); + break; + default: + PIOS_Assert(0); + break; + } + + if (gpio->remap) { + GPIO_PinAFConfig(gpio->pin.gpio, gpio->pin.init.GPIO_Pin, gpio->remap); + } + + GPIO_Init(gpio->pin.gpio, &gpio->pin.init); + + PIOS_GPIO_Off(*gpios_dev_id, i); + } + + return 0; } /** - * Enable a GPIO Pin - * \param[in] Pin Pin Number + * Turn on GPIO + * \param[in] GPIO GPIO id */ -void PIOS_GPIO_Enable(uint8_t Pin) +void PIOS_GPIO_On(uint32_t gpios_dev_id, uint8_t gpio_id) { - GPIO_InitTypeDef GPIO_InitStructure; + const struct pios_gpio_cfg *gpio_cfg = (const struct pios_gpio_cfg *)gpios_dev_id; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Pin]; - GPIO_Init(GPIO_PORT[Pin], &GPIO_InitStructure); + PIOS_Assert(gpio_cfg); - /* GPIO's Off */ - PIOS_GPIO_Off(Pin); + if (gpio_id >= gpio_cfg->num_gpios) { + /* GPIO index out of range */ + return; + } + + const struct pios_gpio *gpio = &(gpio_cfg->gpios[gpio_id]); + + if (gpio->active_low) { + GPIO_ResetBits(gpio->pin.gpio, gpio->pin.init.GPIO_Pin); + } else { + GPIO_SetBits(gpio->pin.gpio, gpio->pin.init.GPIO_Pin); + } } /** - * Turn on Pin - * \param[in] Pin Pin Number + * Turn off GPIO + * \param[in] GPIO GPIO id */ -void PIOS_GPIO_On(uint8_t Pin) +void PIOS_GPIO_Off(uint32_t gpios_dev_id, uint8_t gpio_id) { - GPIO_ResetBits(GPIO_PORT[Pin], GPIO_PIN[Pin]); + const struct pios_gpio_cfg *gpio_cfg = (const struct pios_gpio_cfg *)gpios_dev_id; + + PIOS_Assert(gpio_cfg); + + if (gpio_id >= gpio_cfg->num_gpios) { + /* GPIO index out of range */ + return; + } + + const struct pios_gpio *gpio = &(gpio_cfg->gpios[gpio_id]); + + if (gpio->active_low) { + GPIO_SetBits(gpio->pin.gpio, gpio->pin.init.GPIO_Pin); + } else { + GPIO_ResetBits(gpio->pin.gpio, gpio->pin.init.GPIO_Pin); + } } /** - * Turn off Pin - * \param[in] Pin Pin Number + * Toggle GPIO on/off + * \param[in] GPIO GPIO id */ -void PIOS_GPIO_Off(uint8_t Pin) +void PIOS_GPIO_Toggle(uint32_t gpios_dev_id, uint8_t gpio_id) { - GPIO_SetBits(GPIO_PORT[Pin], GPIO_PIN[Pin]); -} + const struct pios_gpio_cfg *gpio_cfg = (const struct pios_gpio_cfg *)gpios_dev_id; -/** - * Toggle Pin on/off - * \param[in] Pin Pin Number - */ -void PIOS_GPIO_Toggle(uint8_t Pin) -{ - GPIO_ToggleBits(GPIO_PORT[Pin], GPIO_PIN[Pin]); + PIOS_Assert(gpio_cfg); + + if (gpio_id >= gpio_cfg->num_gpios) { + /* GPIO index out of range */ + return; + } + + const struct pios_gpio *gpio = &(gpio_cfg->gpios[gpio_id]); + + if (GPIO_ReadOutputDataBit(gpio->pin.gpio, gpio->pin.init.GPIO_Pin) == Bit_SET) { + if (gpio->active_low) { + PIOS_GPIO_On(gpios_dev_id, gpio_id); + } else { + PIOS_GPIO_Off(gpios_dev_id, gpio_id); + } + } else { + if (gpio->active_low) { + PIOS_GPIO_Off(gpios_dev_id, gpio_id); + } else { + PIOS_GPIO_On(gpios_dev_id, gpio_id); + } + } } #endif /* PIOS_INCLUDE_GPIO */ diff --git a/flight/pios/stm32f4xx/pios_led.c b/flight/pios/stm32f4xx/pios_led.c deleted file mode 100644 index 45174c645..000000000 --- a/flight/pios/stm32f4xx/pios_led.c +++ /dev/null @@ -1,177 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup PIOS PIOS Core hardware abstraction layer - * @{ - * @addtogroup PIOS_LED LED Functions - * @brief STM32 Hardware LED handling code - * @{ - * - * @file pios_led.c - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. - * @brief LED functions, init, toggle, on & off. - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "pios.h" - -#ifdef PIOS_INCLUDE_LED - -#include - -static const struct pios_led_cfg *led_cfg; - -/** - * Initialises all the LED's - */ -int32_t PIOS_LED_Init(const struct pios_led_cfg *cfg) -{ - PIOS_Assert(cfg); - - /* Store away the config in a global used by API functions */ - led_cfg = cfg; - - for (uint8_t i = 0; i < cfg->num_leds; i++) { - const struct pios_led *led = &(cfg->leds[i]); - - /* Enable the peripheral clock for the GPIO */ - switch ((uint32_t)led->pin.gpio) { - case (uint32_t)GPIOA: - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); - break; - case (uint32_t)GPIOB: - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); - break; - case (uint32_t)GPIOC: - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); - break; - case (uint32_t)GPIOD: - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); - break; - case (uint32_t)GPIOE: - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE); - break; - case (uint32_t)GPIOF: - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE); - break; - case (uint32_t)GPIOG: - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE); - break; - case (uint32_t)GPIOH: - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE); - break; - case (uint32_t)GPIOI: - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI, ENABLE); - break; - default: - PIOS_Assert(0); - break; - } - - if (led->remap) { - GPIO_PinAFConfig(led->pin.gpio, led->pin.init.GPIO_Pin, led->remap); - } - - GPIO_Init(led->pin.gpio, &led->pin.init); - - PIOS_LED_Off(i); - } - - return 0; -} - -/** - * Turn on LED - * \param[in] LED LED id - */ -void PIOS_LED_On(uint32_t led_id) -{ - PIOS_Assert(led_cfg); - - if (led_id >= led_cfg->num_leds) { - /* LED index out of range */ - return; - } - - const struct pios_led *led = &(led_cfg->leds[led_id]); - - if (led->active_high) { - GPIO_SetBits(led->pin.gpio, led->pin.init.GPIO_Pin); - } else { - GPIO_ResetBits(led->pin.gpio, led->pin.init.GPIO_Pin); - } -} - -/** - * Turn off LED - * \param[in] LED LED id - */ -void PIOS_LED_Off(uint32_t led_id) -{ - PIOS_Assert(led_cfg); - - if (led_id >= led_cfg->num_leds) { - /* LED index out of range */ - return; - } - - const struct pios_led *led = &(led_cfg->leds[led_id]); - - if (led->active_high) { - GPIO_ResetBits(led->pin.gpio, led->pin.init.GPIO_Pin); - } else { - GPIO_SetBits(led->pin.gpio, led->pin.init.GPIO_Pin); - } -} - -/** - * Toggle LED on/off - * \param[in] LED LED id - */ -void PIOS_LED_Toggle(uint32_t led_id) -{ - PIOS_Assert(led_cfg); - - if (led_id >= led_cfg->num_leds) { - /* LED index out of range */ - return; - } - - const struct pios_led *led = &(led_cfg->leds[led_id]); - - if (GPIO_ReadOutputDataBit(led->pin.gpio, led->pin.init.GPIO_Pin) == Bit_SET) { - if (led->active_high) { - PIOS_LED_Off(led_id); - } else { - PIOS_LED_On(led_id); - } - } else { - if (led->active_high) { - PIOS_LED_On(led_id); - } else { - PIOS_LED_Off(led_id); - } - } -} - -#endif /* PIOS_INCLUDE_LED */ - -/** - * @} - * @} - */ diff --git a/flight/targets/boards/coptercontrol/board_hw_defs.c b/flight/targets/boards/coptercontrol/board_hw_defs.c index 4b1625e9e..78ba7ba93 100644 --- a/flight/targets/boards/coptercontrol/board_hw_defs.c +++ b/flight/targets/boards/coptercontrol/board_hw_defs.c @@ -31,7 +31,7 @@ #if defined(PIOS_INCLUDE_LED) #include -static const struct pios_led pios_leds_cc[] = { +static const struct pios_gpio pios_leds_cc[] = { [PIOS_LED_HEARTBEAT] = { .pin = { .gpio = GPIOA, @@ -41,15 +41,16 @@ static const struct pios_led pios_leds_cc[] = { .GPIO_Speed = GPIO_Speed_50MHz, }, }, + .active_low = true }, }; -static const struct pios_led_cfg pios_led_cfg_cc = { - .leds = pios_leds_cc, - .num_leds = NELEMENTS(pios_leds_cc), +static const struct pios_gpio_cfg pios_led_cfg_cc = { + .gpios = pios_leds_cc, + .num_gpios = NELEMENTS(pios_leds_cc), }; -static const struct pios_led pios_leds_cc3d[] = { +static const struct pios_gpio pios_leds_cc3d[] = { [PIOS_LED_HEARTBEAT] = { .pin = { .gpio = GPIOB, @@ -60,15 +61,16 @@ static const struct pios_led pios_leds_cc3d[] = { }, }, .remap = GPIO_Remap_SWJ_JTAGDisable, + .active_low = true }, }; -static const struct pios_led_cfg pios_led_cfg_cc3d = { - .leds = pios_leds_cc3d, - .num_leds = NELEMENTS(pios_leds_cc3d), +static const struct pios_gpio_cfg pios_led_cfg_cc3d = { + .gpios = pios_leds_cc3d, + .num_gpios = NELEMENTS(pios_leds_cc3d), }; -const struct pios_led_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(uint32_t board_revision) +const struct pios_gpio_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(uint32_t board_revision) { switch (board_revision) { case BOARD_REVISION_CC: return &pios_led_cfg_cc; diff --git a/flight/targets/boards/coptercontrol/bootloader/pios_board.c b/flight/targets/boards/coptercontrol/bootloader/pios_board.c index 8071a3c32..e0a63193a 100644 --- a/flight/targets/boards/coptercontrol/bootloader/pios_board.c +++ b/flight/targets/boards/coptercontrol/bootloader/pios_board.c @@ -59,13 +59,10 @@ void PIOS_Board_Init(void) /* Delay system */ PIOS_DELAY_Init(); - /* Initialize the PiOS library */ - PIOS_GPIO_Init(); - const struct pios_board_info *bdinfo = &pios_board_info_blob; #if defined(PIOS_INCLUDE_LED) - const struct pios_led_cfg *led_cfg = PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo->board_rev); + const struct pios_gpio_cfg *led_cfg = PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo->board_rev); PIOS_Assert(led_cfg); PIOS_LED_Init(led_cfg); #endif /* PIOS_INCLUDE_LED */ diff --git a/flight/targets/boards/coptercontrol/firmware/pios_board.c b/flight/targets/boards/coptercontrol/firmware/pios_board.c index 4776d940b..e3ac9f653 100644 --- a/flight/targets/boards/coptercontrol/firmware/pios_board.c +++ b/flight/targets/boards/coptercontrol/firmware/pios_board.c @@ -145,7 +145,7 @@ void PIOS_Board_Init(void) const struct pios_board_info *bdinfo = &pios_board_info_blob; #if defined(PIOS_INCLUDE_LED) - const struct pios_led_cfg *led_cfg = PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo->board_rev); + const struct pios_gpio_cfg *led_cfg = PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo->board_rev); PIOS_Assert(led_cfg); PIOS_LED_Init(led_cfg); #endif /* PIOS_INCLUDE_LED */ @@ -865,8 +865,6 @@ void PIOS_Board_Init(void) PIOS_Assert(0); } - PIOS_GPIO_Init(); - /* Make sure we have at least one telemetry link configured or else fail initialization */ PIOS_Assert(pios_com_telem_rf_id || pios_com_telem_usb_id); } diff --git a/flight/targets/boards/oplinkmini/board_hw_defs.c b/flight/targets/boards/oplinkmini/board_hw_defs.c index cd106914a..da3d81b95 100644 --- a/flight/targets/boards/oplinkmini/board_hw_defs.c +++ b/flight/targets/boards/oplinkmini/board_hw_defs.c @@ -27,7 +27,7 @@ #if defined(PIOS_INCLUDE_LED) #include -static const struct pios_led pios_leds[] = { +static const struct pios_gpio pios_leds[] = { [PIOS_LED_USB] = { .pin = { .gpio = GPIOA, @@ -37,6 +37,7 @@ static const struct pios_led pios_leds[] = { .GPIO_Speed = GPIO_Speed_50MHz, }, }, + .active_low = true }, [PIOS_LED_LINK] = { .pin = { @@ -47,6 +48,7 @@ static const struct pios_led pios_leds[] = { .GPIO_Speed = GPIO_Speed_50MHz, }, }, + .active_low = true }, [PIOS_LED_RX] = { .pin = { @@ -57,6 +59,7 @@ static const struct pios_led pios_leds[] = { .GPIO_Speed = GPIO_Speed_50MHz, }, }, + .active_low = true }, [PIOS_LED_TX] = { .pin = { @@ -67,6 +70,7 @@ static const struct pios_led pios_leds[] = { .GPIO_Speed = GPIO_Speed_50MHz, }, }, + .active_low = true }, #ifdef PIOS_RFM22B_DEBUG_ON_TELEM [PIOS_LED_D1] = { @@ -112,12 +116,12 @@ static const struct pios_led pios_leds[] = { #endif /* ifdef PIOS_RFM22B_DEBUG_ON_TELEM */ }; -static const struct pios_led_cfg pios_led_cfg = { - .leds = pios_leds, - .num_leds = NELEMENTS(pios_leds), +static const struct pios_gpio_cfg pios_led_cfg = { + .gpios = pios_leds, + .num_gpios = NELEMENTS(pios_leds), }; -const struct pios_led_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(__attribute__((unused)) uint32_t board_revision) +const struct pios_gpio_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(__attribute__((unused)) uint32_t board_revision) { return &pios_led_cfg; } diff --git a/flight/targets/boards/oplinkmini/bootloader/pios_board.c b/flight/targets/boards/oplinkmini/bootloader/pios_board.c index 94a73e708..4dad876dc 100644 --- a/flight/targets/boards/oplinkmini/bootloader/pios_board.c +++ b/flight/targets/boards/oplinkmini/bootloader/pios_board.c @@ -59,9 +59,6 @@ void PIOS_Board_Init(void) /* Delay system */ PIOS_DELAY_Init(); - /* Initialize the PiOS library */ - PIOS_GPIO_Init(); - #if defined(PIOS_INCLUDE_LED) PIOS_LED_Init(&pios_led_cfg); #endif /* PIOS_INCLUDE_LED */ diff --git a/flight/targets/boards/oplinkmini/firmware/pios_board.c b/flight/targets/boards/oplinkmini/firmware/pios_board.c index 5c429d57e..210c825b9 100644 --- a/flight/targets/boards/oplinkmini/firmware/pios_board.c +++ b/flight/targets/boards/oplinkmini/firmware/pios_board.c @@ -485,7 +485,6 @@ void PIOS_Board_Init(void) #ifdef PIOS_INCLUDE_ADC PIOS_ADC_Init(); #endif - PIOS_GPIO_Init(); } static void PIOS_Board_PPM_callback(const int16_t *channels) diff --git a/flight/targets/boards/osd/board_hw_defs.c b/flight/targets/boards/osd/board_hw_defs.c index ac1ae6e56..d465f09bf 100644 --- a/flight/targets/boards/osd/board_hw_defs.c +++ b/flight/targets/boards/osd/board_hw_defs.c @@ -30,7 +30,7 @@ #if defined(PIOS_INCLUDE_LED) #include -static const struct pios_led pios_leds[] = { +static const struct pios_gpio pios_leds[] = { [PIOS_LED_HEARTBEAT] = { .pin = { .gpio = GPIOB, @@ -42,6 +42,7 @@ static const struct pios_led pios_leds[] = { .GPIO_PuPd = GPIO_PuPd_UP }, }, + .active_low = true }, [PIOS_LED_ALARM] = { .pin = { @@ -54,15 +55,16 @@ static const struct pios_led pios_leds[] = { .GPIO_PuPd = GPIO_PuPd_UP }, }, + .active_low = true }, }; -static const struct pios_led_cfg pios_led_cfg = { - .leds = pios_leds, - .num_leds = NELEMENTS(pios_leds), +static const struct pios_gpio_cfg pios_led_cfg = { + .gpios = pios_leds, + .num_gpios = NELEMENTS(pios_leds), }; -const struct pios_led_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(__attribute__((unused)) uint32_t board_revision) +const struct pios_gpio_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(__attribute__((unused)) uint32_t board_revision) { return &pios_led_cfg; } diff --git a/flight/targets/boards/osd/bootloader/inc/pios_config.h b/flight/targets/boards/osd/bootloader/inc/pios_config.h index cf7b48ee1..148945fc2 100644 --- a/flight/targets/boards/osd/bootloader/inc/pios_config.h +++ b/flight/targets/boards/osd/bootloader/inc/pios_config.h @@ -35,6 +35,7 @@ #define PIOS_INCLUDE_USB_HID #define PIOS_INCLUDE_LED #define PIOS_INCLUDE_IAP +#define PIOS_INCLUDE_GPIO #define PIOS_INCLUDE_COM #define PIOS_INCLUDE_COM_MSG #define PIOS_INCLUDE_BL_HELPER diff --git a/flight/targets/boards/osd/firmware/inc/pios_config.h b/flight/targets/boards/osd/firmware/inc/pios_config.h index a6400957f..1ad6f6629 100644 --- a/flight/targets/boards/osd/firmware/inc/pios_config.h +++ b/flight/targets/boards/osd/firmware/inc/pios_config.h @@ -61,7 +61,7 @@ #define PIOS_INCLUDE_ADC #define PIOS_INCLUDE_I2C #define PIOS_INCLUDE_SPI -/* #define PIOS_INCLUDE_GPIO */ +#define PIOS_INCLUDE_GPIO #define PIOS_INCLUDE_EXTI #define PIOS_INCLUDE_WDG diff --git a/flight/targets/boards/revolution/board_hw_defs.c b/flight/targets/boards/revolution/board_hw_defs.c index 8b1dff63b..6ecec9522 100644 --- a/flight/targets/boards/revolution/board_hw_defs.c +++ b/flight/targets/boards/revolution/board_hw_defs.c @@ -28,7 +28,7 @@ #if defined(PIOS_INCLUDE_LED) #include -static const struct pios_led pios_leds[] = { +static const struct pios_gpio pios_leds[] = { [PIOS_LED_HEARTBEAT] = { .pin = { .gpio = GPIOB, @@ -40,6 +40,7 @@ static const struct pios_led pios_leds[] = { .GPIO_PuPd = GPIO_PuPd_UP }, }, + .active_low = true }, [PIOS_LED_ALARM] = { .pin = { @@ -52,6 +53,7 @@ static const struct pios_led pios_leds[] = { .GPIO_PuPd = GPIO_PuPd_UP }, }, + .active_low = true }, #ifdef PIOS_RFM22B_DEBUG_ON_TELEM [PIOS_LED_D1] = { @@ -105,12 +107,12 @@ static const struct pios_led pios_leds[] = { #endif /* ifdef PIOS_RFM22B_DEBUG_ON_TELEM */ }; -static const struct pios_led_cfg pios_led_cfg = { - .leds = pios_leds, - .num_leds = NELEMENTS(pios_leds), +static const struct pios_gpio_cfg pios_led_cfg = { + .gpios = pios_leds, + .num_gpios = NELEMENTS(pios_leds), }; -static const struct pios_led pios_leds_v2[] = { +static const struct pios_gpio pios_leds_v2[] = { [PIOS_LED_HEARTBEAT] = { .pin = { .gpio = GPIOB, @@ -122,6 +124,7 @@ static const struct pios_led pios_leds_v2[] = { .GPIO_PuPd = GPIO_PuPd_UP }, }, + .active_low = true }, [PIOS_LED_ALARM] = { .pin = { @@ -134,6 +137,7 @@ static const struct pios_led pios_leds_v2[] = { .GPIO_PuPd = GPIO_PuPd_UP }, }, + .active_low = true }, #ifdef PIOS_RFM22B_DEBUG_ON_TELEM [PIOS_LED_D1] = { @@ -187,12 +191,12 @@ static const struct pios_led pios_leds_v2[] = { #endif /* ifdef PIOS_RFM22B_DEBUG_ON_TELEM */ }; -static const struct pios_led_cfg pios_led_v2_cfg = { - .leds = pios_leds_v2, - .num_leds = NELEMENTS(pios_leds_v2), +static const struct pios_gpio_cfg pios_led_v2_cfg = { + .gpios = pios_leds_v2, + .num_gpios = NELEMENTS(pios_leds_v2), }; -const struct pios_led_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(uint32_t board_revision) +const struct pios_gpio_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(uint32_t board_revision) { switch (board_revision) { case 2: diff --git a/flight/targets/boards/revolution/bootloader/inc/pios_config.h b/flight/targets/boards/revolution/bootloader/inc/pios_config.h index d3b203d2e..7f2a165d7 100644 --- a/flight/targets/boards/revolution/bootloader/inc/pios_config.h +++ b/flight/targets/boards/revolution/bootloader/inc/pios_config.h @@ -35,6 +35,7 @@ #define PIOS_INCLUDE_USB_HID #define PIOS_INCLUDE_LED #define PIOS_INCLUDE_IAP +#define PIOS_INCLUDE_GPIO #define PIOS_INCLUDE_COM #define PIOS_INCLUDE_COM_MSG #define PIOS_INCLUDE_BL_HELPER diff --git a/flight/targets/boards/revolution/bootloader/pios_board.c b/flight/targets/boards/revolution/bootloader/pios_board.c index 2256f4785..5352c7f73 100644 --- a/flight/targets/boards/revolution/bootloader/pios_board.c +++ b/flight/targets/boards/revolution/bootloader/pios_board.c @@ -51,7 +51,7 @@ void PIOS_Board_Init() const struct pios_board_info *bdinfo = &pios_board_info_blob; #if defined(PIOS_INCLUDE_LED) - const struct pios_led_cfg *led_cfg = PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo->board_rev); + const struct pios_gpio_cfg *led_cfg = PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo->board_rev); PIOS_Assert(led_cfg); PIOS_LED_Init(led_cfg); #endif /* PIOS_INCLUDE_LED */ diff --git a/flight/targets/boards/revolution/firmware/inc/pios_config.h b/flight/targets/boards/revolution/firmware/inc/pios_config.h index 5d229db01..fbaff9438 100644 --- a/flight/targets/boards/revolution/firmware/inc/pios_config.h +++ b/flight/targets/boards/revolution/firmware/inc/pios_config.h @@ -61,7 +61,7 @@ #define PIOS_INCLUDE_ADC #define PIOS_INCLUDE_I2C #define PIOS_INCLUDE_SPI -/* #define PIOS_INCLUDE_GPIO */ +#define PIOS_INCLUDE_GPIO #define PIOS_INCLUDE_EXTI #define PIOS_INCLUDE_WDG diff --git a/flight/targets/boards/revolution/firmware/pios_board.c b/flight/targets/boards/revolution/firmware/pios_board.c index ffc05ce50..83b5c60fe 100644 --- a/flight/targets/boards/revolution/firmware/pios_board.c +++ b/flight/targets/boards/revolution/firmware/pios_board.c @@ -346,7 +346,7 @@ void PIOS_Board_Init(void) const struct pios_board_info *bdinfo = &pios_board_info_blob; #if defined(PIOS_INCLUDE_LED) - const struct pios_led_cfg *led_cfg = PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo->board_rev); + const struct pios_gpio_cfg *led_cfg = PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo->board_rev); PIOS_Assert(led_cfg); PIOS_LED_Init(led_cfg); #endif /* PIOS_INCLUDE_LED */ diff --git a/flight/targets/boards/revoproto/board_hw_defs.c b/flight/targets/boards/revoproto/board_hw_defs.c index ca6dd0969..574ab2fe8 100644 --- a/flight/targets/boards/revoproto/board_hw_defs.c +++ b/flight/targets/boards/revoproto/board_hw_defs.c @@ -28,7 +28,7 @@ #if defined(PIOS_INCLUDE_LED) #include -static const struct pios_led pios_leds[] = { +static const struct pios_gpio pios_leds[] = { [PIOS_LED_HEARTBEAT] = { .pin = { .gpio = GPIOE, @@ -40,6 +40,7 @@ static const struct pios_led pios_leds[] = { .GPIO_PuPd = GPIO_PuPd_UP }, }, + .active_low = true }, [PIOS_LED_ALARM] = { .pin = { @@ -52,15 +53,16 @@ static const struct pios_led pios_leds[] = { .GPIO_PuPd = GPIO_PuPd_UP }, }, + .active_low = true }, }; -static const struct pios_led_cfg pios_led_cfg = { - .leds = pios_leds, - .num_leds = NELEMENTS(pios_leds), +static const struct pios_gpio_cfg pios_led_cfg = { + .gpios = pios_leds, + .num_gpios = NELEMENTS(pios_leds), }; -const struct pios_led_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(__attribute__((unused)) uint32_t board_revision) +const struct pios_gpio_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(__attribute__((unused)) uint32_t board_revision) { return &pios_led_cfg; } diff --git a/flight/targets/boards/revoproto/bootloader/inc/pios_config.h b/flight/targets/boards/revoproto/bootloader/inc/pios_config.h index cf7b48ee1..148945fc2 100644 --- a/flight/targets/boards/revoproto/bootloader/inc/pios_config.h +++ b/flight/targets/boards/revoproto/bootloader/inc/pios_config.h @@ -35,6 +35,7 @@ #define PIOS_INCLUDE_USB_HID #define PIOS_INCLUDE_LED #define PIOS_INCLUDE_IAP +#define PIOS_INCLUDE_GPIO #define PIOS_INCLUDE_COM #define PIOS_INCLUDE_COM_MSG #define PIOS_INCLUDE_BL_HELPER diff --git a/flight/targets/boards/revoproto/firmware/inc/pios_config.h b/flight/targets/boards/revoproto/firmware/inc/pios_config.h index a4c2042df..c8e3d340c 100644 --- a/flight/targets/boards/revoproto/firmware/inc/pios_config.h +++ b/flight/targets/boards/revoproto/firmware/inc/pios_config.h @@ -61,7 +61,7 @@ #define PIOS_INCLUDE_ADC #define PIOS_INCLUDE_I2C #define PIOS_INCLUDE_SPI -/* #define PIOS_INCLUDE_GPIO */ +#define PIOS_INCLUDE_GPIO #define PIOS_INCLUDE_EXTI #define PIOS_INCLUDE_WDG diff --git a/flight/targets/common/bootloader_updater/Makefile b/flight/targets/common/bootloader_updater/Makefile index 07fa61d1e..8c312d6ac 100644 --- a/flight/targets/common/bootloader_updater/Makefile +++ b/flight/targets/common/bootloader_updater/Makefile @@ -39,6 +39,7 @@ HWDEFSINC = ../../boards/$(BOARD_NAME) # Use file-extension c for "c-only"-files SRC += $(OPSYSTEM)/main.c SRC += $(OPSYSTEM)/pios_board.c +SRC += $(PIOSCOMMON)/pios_led.c ## PIOS Hardware ifeq ($(MCU),cortex-m3) include $(PIOS)/stm32f10x/library.mk diff --git a/flight/targets/common/bootloader_updater/inc/pios_config.h b/flight/targets/common/bootloader_updater/inc/pios_config.h index 8f54f402b..6b74bccc0 100644 --- a/flight/targets/common/bootloader_updater/inc/pios_config.h +++ b/flight/targets/common/bootloader_updater/inc/pios_config.h @@ -35,6 +35,7 @@ #define PIOS_INCLUDE_SYS #define PIOS_INCLUDE_IRQ #define PIOS_INCLUDE_LED +#define PIOS_INCLUDE_GPIO #define PIOS_INCLUDE_BL_HELPER #define PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT diff --git a/flight/targets/common/bootloader_updater/pios_board.c b/flight/targets/common/bootloader_updater/pios_board.c index 1557c7b83..c612608ea 100644 --- a/flight/targets/common/bootloader_updater/pios_board.c +++ b/flight/targets/common/bootloader_updater/pios_board.c @@ -41,13 +41,8 @@ void PIOS_Board_Init(void) /* LEDs */ #if defined(PIOS_INCLUDE_LED) - const struct pios_led_cfg *led_cfg = PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo->board_rev); + const struct pios_gpio_cfg *led_cfg = PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo->board_rev); PIOS_Assert(led_cfg); PIOS_LED_Init(led_cfg); #endif /* PIOS_INCLUDE_LED */ - - /* Initialize the PiOS library */ -#if defined(PIOS_INCLUDE_GPIO) - PIOS_GPIO_Init(); -#endif /* PIOS_INCLUDE_GPIO */ } diff --git a/make/apps-defs.mk b/make/apps-defs.mk index bfbb66c2a..54e2e991e 100644 --- a/make/apps-defs.mk +++ b/make/apps-defs.mk @@ -86,6 +86,7 @@ SRC += $(PIOSCOMMON)/pios_rfm22b.c SRC += $(PIOSCOMMON)/pios_rfm22b_com.c SRC += $(PIOSCOMMON)/pios_sbus.c SRC += $(PIOSCOMMON)/pios_sdcard.c +SRC += $(PIOSCOMMON)/pios_led.c ## PIOS USB related files SRC += $(PIOSCOMMON)/pios_usb_desc_hid_cdc.c diff --git a/make/boot-defs.mk b/make/boot-defs.mk index 6152b39f2..1ebf53d96 100644 --- a/make/boot-defs.mk +++ b/make/boot-defs.mk @@ -55,6 +55,7 @@ SRC += $(PIOSCOMMON)/pios_com_msg.c SRC += $(PIOSCOMMON)/pios_iap.c SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c SRC += $(PIOSCOMMON)/pios_usb_util.c +SRC += $(PIOSCOMMON)/pios_led.c ## Misc library functions SRC += $(FLIGHTLIB)/op_dfu.c