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