Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
led_hw.h
Go to the documentation of this file.
1 /*
2  * Paparazzi $Id$
3  *
4  * Copyright (C) 2009 Antoine Drouin <poinix@gmail.com>
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
24 #ifndef LED_HW_H
25 #define LED_HW_H
26 
27 #include <stm32/gpio.h>
28 #include <stm32/rcc.h>
29 
30 #include BOARD_CONFIG
31 
32 #include "std.h"
33 
34 
35 /*
36  *
37  * Regular GPIO driven LEDs
38  *
39  */
40 #ifndef LED_STP08
41 
42 #define _LED_GPIO_CLK(i) i
43 #define _LED_GPIO(i) i
44 #define _LED_GPIO_PIN(i) i
45 #define _LED_AFIO_REMAP(i) i
46 
47 #define LED_GPIO_CLK(i) _LED_GPIO_CLK(LED_ ## i ## _GPIO_CLK)
48 #define LED_GPIO(i) _LED_GPIO(LED_ ## i ## _GPIO)
49 #define LED_GPIO_PIN(i) _LED_GPIO_PIN(LED_ ## i ## _GPIO_PIN)
50 #define LED_AFIO_REMAP(i) _LED_AFIO_REMAP(LED_ ## i ## _AFIO_REMAP)
51 
52 /* set pin as output */
53 #define LED_INIT(i) { \
54  GPIO_InitTypeDef GPIO_InitStructure; \
55  RCC_APB2PeriphClockCmd(LED_GPIO_CLK(i), ENABLE); \
56  GPIO_InitStructure.GPIO_Pin = LED_GPIO_PIN(i); \
57  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; \
58  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; \
59  GPIO_Init(LED_GPIO(i), &GPIO_InitStructure); \
60  LED_AFIO_REMAP(i); \
61  }
62 
63 #define LED_ON(i) {LED_GPIO(i)->BRR = LED_GPIO_PIN(i);}
64 #define LED_OFF(i) { LED_GPIO(i)->BSRR = LED_GPIO_PIN(i);}
65 #define LED_TOGGLE(i) { LED_GPIO(i)->ODR ^= LED_GPIO_PIN(i);}
66 
67 #define LED_PERIODIC() {}
68 
69 
70 /*
71  *
72  * Shift register driven LEDs
73  *
74  */
75 #else /* LED_STP08 */
76 #define NB_LED 8
77 extern uint8_t led_status[NB_LED];
78 /* Lisa/L uses a shift register for driving LEDs */
79 /* PA8 led_clk */
80 /* PC15 led_data */
81 
82 #define LED_INIT(_i) { \
83  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); \
84  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); \
85  GPIO_InitTypeDef GPIO_InitStructure; \
86  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; \
87  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; \
88  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; \
89  GPIO_Init(GPIOA, &GPIO_InitStructure); \
90  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; \
91  GPIO_Init(GPIOC, &GPIO_InitStructure); \
92  for(uint8_t i=0; i<NB_LED; i++) \
93  led_status[i] = FALSE; \
94  }
95 
96 #define LED_ON(i) { led_status[i] = TRUE; }
97 #define LED_OFF(i) { led_status[i] = FALSE; }
98 #define LED_TOGGLE(i) {led_status[i] = !led_status[i];}
99 
100 #define LED_PERIODIC() { \
101  for (uint8_t cnt = 0; cnt < NB_LED; cnt++) { \
102  if (led_status[cnt]) \
103  GPIOC->BSRR = GPIO_Pin_15; \
104  else \
105  GPIOC->BRR = GPIO_Pin_15; \
106  GPIOA->BSRR = GPIO_Pin_8; /* clock rising edge */ \
107  GPIOA->BRR = GPIO_Pin_8; /* clock falling edge */ \
108  } \
109  }
110 
111 #endif /* LED_STP08 */
112 
113 #endif /* LED_HW_H */
unsigned char uint8_t
Definition: types.h:14