Paparazzi UAS  v5.15_devel-88-gb3ad7fe
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_DISABLE(i) gpio_setup_input(LED_GPIO(i), LED_GPIO_PIN(i))
59 
60 #define LED_PERIODIC() {}
61 
62 
63 /*
64  *
65  * Shift register driven LEDs
66  *
67  */
68 #else /* LED_STP08 */
69 #define NB_LED 8
70 extern uint8_t led_status[NB_LED];
71 /* Lisa/L uses a shift register for driving LEDs */
72 /* PA8 led_clk */
73 /* PC15 led_data */
74 
75 #define LED_INIT(_i) { \
76  rcc_periph_clock_enable(RCC_GPIOA); \
77  rcc_periph_clock_enable(RCC_GPIOC); \
78  gpio_set_mode(GPIOA, \
79  GPIO_MODE_OUTPUT_50_MHZ, \
80  GPIO_CNF_OUTPUT_PUSHPULL, \
81  GPIO8); \
82  gpio_set_mode(GPIOC, \
83  GPIO_MODE_OUTPUT_50_MHZ, \
84  GPIO_CNF_OUTPUT_PUSHPULL, \
85  GPIO15); \
86  for(uint8_t _cnt=0; _cnt<NB_LED; _cnt++) \
87  led_status[_cnt] = false; \
88  }
89 
90 #define LED_ON(i) { led_status[i] = true; }
91 #define LED_OFF(i) { led_status[i] = false; }
92 #define LED_TOGGLE(i) {led_status[i] = !led_status[i];}
93 #define LED_DISABLE(i) LED_OFF(i)
94 
95 #define LED_PERIODIC() { \
96  for (uint8_t _cnt = 0; _cnt < NB_LED; _cnt++) { \
97  if (led_status[_cnt]) \
98  gpio_set(GPIOC, GPIO15); \
99  else \
100  gpio_clear(GPIOC, GPIO15); \
101  gpio_set(GPIOA, GPIO8); /* clock rising edge */ \
102  gpio_clear(GPIOA, GPIO8); /* clock falling edge */ \
103  } \
104  }
105 
106 #endif /* LED_STP08 */
107 
108 #endif /* LED_HW_H */
Some architecture independent helper functions for GPIOs.
unsigned char uint8_t
Definition: types.h:14