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