mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-19 09:54:15 +01:00
Moves pios_led functionality to pios_gpio and makes pios_led a thin layer over pios_gpio. Supports configuring multiple sets of GPIOs.
This commit is contained in:
parent
2a0533e5e3
commit
e246ecf536
81
flight/pios/common/pios_led.c
Normal file
81
flight/pios/common/pios_led.c
Normal file
@ -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 <pios_gpio_priv.h>
|
||||
#include <pios_gpio.h>
|
||||
|
||||
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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -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 */
|
||||
|
||||
|
@ -31,21 +31,9 @@
|
||||
#ifndef PIOS_LED_PRIV_H
|
||||
#define PIOS_LED_PRIV_H
|
||||
|
||||
#include <pios.h>
|
||||
#include <pios_stm32.h>
|
||||
#include <pios_gpio_priv.h>
|
||||
|
||||
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 */
|
||||
|
||||
|
@ -81,6 +81,8 @@
|
||||
#include "semphr.h"
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <pios_architecture.h>
|
||||
|
||||
#ifdef PIOS_INCLUDE_TASK_MONITOR
|
||||
|
@ -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 <pios_gpio_priv.h>
|
||||
|
||||
/**
|
||||
* 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 */
|
||||
|
@ -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 <pios_led_priv.h>
|
||||
|
||||
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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -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 <pios_gpio_priv.h>
|
||||
|
||||
/**
|
||||
* 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 */
|
||||
|
@ -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 <pios_led_priv.h>
|
||||
|
||||
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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -31,7 +31,7 @@
|
||||
#if defined(PIOS_INCLUDE_LED)
|
||||
|
||||
#include <pios_led_priv.h>
|
||||
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;
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
#if defined(PIOS_INCLUDE_LED)
|
||||
|
||||
#include <pios_led_priv.h>
|
||||
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;
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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)
|
||||
|
@ -30,7 +30,7 @@
|
||||
#if defined(PIOS_INCLUDE_LED)
|
||||
|
||||
#include <pios_led_priv.h>
|
||||
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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#if defined(PIOS_INCLUDE_LED)
|
||||
|
||||
#include <pios_led_priv.h>
|
||||
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:
|
||||
|
@ -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
|
||||
|
@ -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 */
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -28,7 +28,7 @@
|
||||
#if defined(PIOS_INCLUDE_LED)
|
||||
|
||||
#include <pios_led_priv.h>
|
||||
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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 */
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user