forked from apache/nuttx
/
bl808_userleds.c
211 lines (187 loc) · 6.74 KB
/
bl808_userleds.c
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/****************************************************************************
* boards/arm64/a64/pinephone/src/pinephone_userleds.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <sys/param.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include "chip.h"
////#include "arm64_internal.h"
////#include "pinephone.h"
#ifdef CONFIG_USERLED
/****************************************************************************
* Private Data
****************************************************************************/
/* LED index */
// static const uint32_t g_led_map[BOARD_LEDS] =
// {
// LED1,
// LED2,
// LED3
// };
static const uint32_t g_led_setmap[BOARD_LEDS] =
{
BOARD_LED1_BIT,
BOARD_LED2_BIT,
BOARD_LED3_BIT
};
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_userled_initialize
*
* Description:
* This function may called from application-specific logic during its
* to perform board-specific initialization of LED resources. This
* includes such things as, for example, configure GPIO pins to drive the
* LEDs and also putting the LEDs in their correct initial state.
*
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
* LEDs. If CONFIG_ARCH_LEDS is not defined, then this interfaces may be
* available to control the LEDs directly from user board logic or
* indirectly user applications (via the common LED character driver).
*
* Most boards have only a few LEDs and in those cases all LEDs may be
* used by the NuttX LED logic exclusively and may not be available for
* use by user logic if CONFIG_ARCH_LEDS=y.
*
* NOTE: The LED number is returned.
*
* Input Parameters:
* None
*
* Returned Value:
* Number of LEDs on board
*
****************************************************************************/
uint32_t board_userled_initialize(void)
{
_info("\n");////
int i;
/* Configure the LED GPIO for output. */
for (i = 0; i < BOARD_LEDS; i++)
{
////TODO: int ret = a64_pio_config(g_led_map[i]);
////TODO: DEBUGASSERT(ret == OK);
}
return BOARD_LEDS;
}
/****************************************************************************
* Name: board_userled
*
* Description:
* This interface may be used by application specific logic to set the
* state of a single LED. Definitions for the led identification are
* provided in the board-specific board.h header file that may be included
* like:
*
* #included <arch/board/board.h>
*
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
* LEDs. If CONFIG_ARCH_LEDS is not defined, then this interfaces may be
* available to control the LEDs directly from user board logic or
* indirectly user applications (via the common LED character driver).
*
* Most boards have only a few LEDs and in those cases all LEDs may be
* used by the NuttX LED logic exclusively and may not be available for
* use by user logic if CONFIG_ARCH_LEDS=y.
*
* Input Parameters:
* led - LED number
* ledon - True if LED should be turned on; False to turn off
*
* Returned Value:
* None
*
****************************************************************************/
void board_userled(int led, bool ledon)
{
_info("led=%d, ledon=%d\n", led, ledon);////
if ((unsigned)led < BOARD_LEDS)
{
////TODO: a64_pio_write(g_led_map[led], ledon);
}
}
/****************************************************************************
* Name: board_userled_all
*
* Description:
* This interface may be used by application specific logic to set the
* state of all board LED. Definitions for the led set member
* identification is provided in the board-specific board.h header file
* that may be includedlike:
*
* #included <arch/board/board.h>
*
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
* LEDs. If CONFIG_ARCH_LEDS is not defined, then this interfaces may be
* available to control the LEDs directly from user board logic or
* indirectly user applications (via the common LED character driver).
*
* Most boards have only a few LEDs and in those cases all LEDs may be
* used by the NuttX LED logic exclusively and may not be available for
* use by user logic if CONFIG_ARCH_LEDS=y.
*
* Input Parameters:
* ledset - Bitset of LEDs to be turned on and off
*
* Returned Value:
* None
*
****************************************************************************/
void board_userled_all(uint32_t ledset)
{
_info("ledset=0x%x\n", ledset);////
int i;
// For LED 0 to 2...
for (i = 0; i < BOARD_LEDS; i++)
{
// Get the desired state of the LED
bool val = ((ledset & g_led_setmap[i]) != 0);
_info("led=%d, val=%d\n", i, val);////
// If this is LED 0...
if (i == 0)
{
// Switch it On or Off?
if (val)
{
// Switch LED 0 (GPIO 29) to On:
// Set gpio_cfg29 to (1 << 6) | (11 << 8) | (0 << 30) | (0 << 4) | (1 << 24)
// mw 0x20000938 0x1000b40 1
*(volatile uint32_t *) 0x20000938 = 0x1000b40;
}
else
{
// Switch LED 0 (GPIO 29) to Off:
// Set gpio_cfg29 to (1 << 6) | (11 << 8) | (0 << 30) | (0 << 4) | (0 << 24)
// mw 0x20000938 0xb40 1
*(volatile uint32_t *) 0x20000938 = 0xb40;
}
}
////TODO: a64_pio_write(g_led_map[i], (ledset & g_led_setmap[i]) != 0);
}
}
#endif /* CONFIG_USERLED */