Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
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 "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_peripheral_enable_clock(&RCC_APB2ENR, \
75  RCC_APB2ENR_IOPAEN | \
76  RCC_APB2ENR_IOPCEN); \
77  gpio_set_mode(GPIOA, \
78  GPIO_MODE_OUTPUT_50_MHZ, \
79  GPIO_CNF_OUTPUT_PUSHPULL, \
80  GPIO8); \
81  gpio_set_mode(GPIOC, \
82  GPIO_MODE_OUTPUT_50_MHZ, \
83  GPIO_CNF_OUTPUT_PUSHPULL, \
84  GPIO15); \
85  for(uint8_t _cnt=0; _cnt<NB_LED; _cnt++) \
86  led_status[_cnt] = FALSE; \
87  }
88 
89 #define LED_ON(i) { led_status[i] = TRUE; }
90 #define LED_OFF(i) { led_status[i] = FALSE; }
91 #define LED_TOGGLE(i) {led_status[i] = !led_status[i];}
92 
93 #define LED_PERIODIC() { \
94  for (uint8_t _cnt = 0; _cnt < NB_LED; _cnt++) { \
95  if (led_status[_cnt]) \
96  gpio_set(GPIOC, GPIO15); \
97  else \
98  gpio_clear(GPIOC, GPIO15); \
99  gpio_set(GPIOA, GPIO8); /* clock rising edge */ \
100  gpio_clear(GPIOA, GPIO8); /* clock falling edge */ \
101  } \
102  }
103 
104 #endif /* LED_STP08 */
105 
106 #endif /* LED_HW_H */
Some architecture independent helper functions for GPIOs.
unsigned char uint8_t
Definition: types.h:14