Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces 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 "mcu_periph/gpio.h"
26 #include <libopencm3/stm32/gpio.h>
27 #include <libopencm3/stm32/rcc.h>
28 
29 #include BOARD_CONFIG
30 
31 #include "std.h"
32 
33 /*
34  *
35  * Regular GPIO driven LEDs
36  *
37  */
38 #ifndef LED_STP08
39 
40 #define _LED_EVAL(i) i
41 
42 #define LED_GPIO(i) _LED_EVAL(LED_ ## i ## _GPIO)
43 #define LED_GPIO_PIN(i) _LED_EVAL(LED_ ## i ## _GPIO_PIN)
44 #define LED_GPIO_ON(i) _LED_EVAL(LED_ ## i ## _GPIO_ON)
45 #define LED_GPIO_OFF(i) _LED_EVAL(LED_ ## i ## _GPIO_OFF)
46 #define LED_AFIO_REMAP(i) _LED_EVAL(LED_ ## i ## _AFIO_REMAP)
47 
48 
49 #define LED_INIT(i) { \
50  gpio_setup_output(LED_GPIO(i), LED_GPIO_PIN(i)); \
51  LED_AFIO_REMAP(i); \
52  }
53 
54 #define LED_ON(i) LED_GPIO_ON(i)(LED_GPIO(i), LED_GPIO_PIN(i))
55 #define LED_OFF(i) LED_GPIO_OFF(i)(LED_GPIO(i), LED_GPIO_PIN(i))
56 #define LED_TOGGLE(i) gpio_toggle(LED_GPIO(i), LED_GPIO_PIN(i))
57 
58 #define LED_PERIODIC() {}
59 
60 
61 /*
62  *
63  * Shift register driven LEDs
64  *
65  */
66 #else /* LED_STP08 */
67 #define NB_LED 8
68 extern uint8_t led_status[NB_LED];
69 /* Lisa/L uses a shift register for driving LEDs */
70 /* PA8 led_clk */
71 /* PC15 led_data */
72 
73 #define LED_INIT(_i) { \
74  rcc_periph_clock_enable(RCC_GPIOA); \
75  rcc_periph_clock_enable(RCC_GPIOC); \
76  gpio_set_mode(GPIOA, \
77  GPIO_MODE_OUTPUT_50_MHZ, \
78  GPIO_CNF_OUTPUT_PUSHPULL, \
79  GPIO8); \
80  gpio_set_mode(GPIOC, \
81  GPIO_MODE_OUTPUT_50_MHZ, \
82  GPIO_CNF_OUTPUT_PUSHPULL, \
83  GPIO15); \
84  for(uint8_t _cnt=0; _cnt<NB_LED; _cnt++) \
85  led_status[_cnt] = false; \
86  }
87 
88 #define LED_ON(i) { led_status[i] = true; }
89 #define LED_OFF(i) { led_status[i] = false; }
90 #define LED_TOGGLE(i) {led_status[i] = !led_status[i];}
91 
92 #define LED_PERIODIC() { \
93  for (uint8_t _cnt = 0; _cnt < NB_LED; _cnt++) { \
94  if (led_status[_cnt]) \
95  gpio_set(GPIOC, GPIO15); \
96  else \
97  gpio_clear(GPIOC, GPIO15); \
98  gpio_set(GPIOA, GPIO8); /* clock rising edge */ \
99  gpio_clear(GPIOA, GPIO8); /* clock falling edge */ \
100  } \
101  }
102 
103 #endif /* LED_STP08 */
104 
105 #endif /* LED_HW_H */
Some architecture independent helper functions for GPIOs.
unsigned char uint8_t
Definition: types.h:14