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#include <common.h>
31#include <asm/io.h>
32#include <asm/arch/gpio.h>
33#include <asm/arch/at91_pmc.h>
34#include <status_led.h>
35
36static unsigned int saved_state[3] = {STATUS_LED_OFF,
37 STATUS_LED_OFF, STATUS_LED_OFF};
38
39void coloured_LED_init(void)
40{
41 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
42
43
44 writel(ATMEL_ID_PIOC, &pmc->pcer);
45
46 at91_set_gpio_output(CONFIG_RED_LED, 1);
47 at91_set_gpio_output(CONFIG_GREEN_LED, 1);
48 at91_set_gpio_output(CONFIG_YELLOW_LED, 1);
49
50 at91_set_gpio_value(CONFIG_RED_LED, 0);
51 at91_set_gpio_value(CONFIG_GREEN_LED, 1);
52 at91_set_gpio_value(CONFIG_YELLOW_LED, 0);
53}
54
55void red_led_on(void)
56{
57 at91_set_gpio_value(CONFIG_RED_LED, 1);
58 saved_state[STATUS_LED_RED] = STATUS_LED_ON;
59}
60
61void red_led_off(void)
62{
63 at91_set_gpio_value(CONFIG_RED_LED, 0);
64 saved_state[STATUS_LED_RED] = STATUS_LED_OFF;
65}
66
67void green_led_on(void)
68{
69 at91_set_gpio_value(CONFIG_GREEN_LED, 1);
70 saved_state[STATUS_LED_GREEN] = STATUS_LED_ON;
71}
72
73void green_led_off(void)
74{
75 at91_set_gpio_value(CONFIG_GREEN_LED, 0);
76 saved_state[STATUS_LED_GREEN] = STATUS_LED_OFF;
77}
78
79void yellow_led_on(void)
80{
81 at91_set_gpio_value(CONFIG_YELLOW_LED, 1);
82 saved_state[STATUS_LED_YELLOW] = STATUS_LED_ON;
83}
84
85void yellow_led_off(void)
86{
87 at91_set_gpio_value(CONFIG_YELLOW_LED, 0);
88 saved_state[STATUS_LED_YELLOW] = STATUS_LED_OFF;
89}
90
91void __led_init(led_id_t mask, int state)
92{
93 __led_set(mask, state);
94}
95
96void __led_toggle(led_id_t mask)
97{
98 if (STATUS_LED_RED == mask) {
99 if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
100 red_led_off();
101 else
102 red_led_on();
103
104 } else if (STATUS_LED_GREEN == mask) {
105 if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN])
106 green_led_off();
107 else
108 green_led_on();
109
110 } else if (STATUS_LED_YELLOW == mask) {
111 if (STATUS_LED_ON == saved_state[STATUS_LED_YELLOW])
112 yellow_led_off();
113 else
114 yellow_led_on();
115 }
116}
117
118void __led_set(led_id_t mask, int state)
119{
120 if (STATUS_LED_RED == mask) {
121 if (STATUS_LED_ON == state)
122 red_led_on();
123 else
124 red_led_off();
125
126 } else if (STATUS_LED_GREEN == mask) {
127 if (STATUS_LED_ON == state)
128 green_led_on();
129 else
130 green_led_off();
131
132 } else if (STATUS_LED_YELLOW == mask) {
133 if (STATUS_LED_ON == state)
134 yellow_led_on();
135 else
136 yellow_led_off();
137 }
138}
139