Skip to content

Commit 4f39969

Browse files
committed
Add LED Driver for Ox64 BL808
1 parent 8f75f37 commit 4f39969

File tree

9 files changed

+494
-4
lines changed

9 files changed

+494
-4
lines changed

Image

900 KB
Binary file not shown.

boards/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,6 +1947,7 @@ config ARCH_BOARD_K230_CANMV
19471947
config ARCH_BOARD_BL808_OX64
19481948
bool "PINE64 Ox64"
19491949
depends on ARCH_CHIP_BL808
1950+
select ARCH_HAVE_LEDS
19501951
---help---
19511952
This options selects support for NuttX on PINE64 Ox64 based
19521953
on Bouffalo Lab BL808 SoC.

boards/risc-v/bl808/ox64/configs/nsh/defconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ CONFIG_DEBUG_SYMBOLS=y
4444
CONFIG_DEV_ZERO=y
4545
CONFIG_ELF=y
4646
CONFIG_EXAMPLES_HELLO=m
47+
CONFIG_EXAMPLES_LEDS=y
4748
CONFIG_FS_PROCFS=y
4849
CONFIG_FS_ROMFS=y
4950
CONFIG_IDLETHREAD_STACKSIZE=3072
@@ -83,3 +84,5 @@ CONFIG_TESTING_OSTEST=y
8384
CONFIG_UART3_BAUD=2000000
8485
CONFIG_UART3_SERIAL_CONSOLE=y
8586
CONFIG_USEC_PER_TICK=1000
87+
CONFIG_USERLED=y
88+
CONFIG_USERLED_LOWER=y

boards/risc-v/bl808/ox64/include/board.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@
3131
* Pre-processor Definitions
3232
****************************************************************************/
3333

34+
/* LED definitions **********************************************************/
35+
36+
/* LED index values for use with board_userled() */
37+
38+
typedef enum
39+
{
40+
BOARD_LED1 = 0, /* Green LED */
41+
BOARD_LED2 = 1, /* Red LED */
42+
BOARD_LED3 = 2, /* Blue LED */
43+
BOARD_LEDS /* Number of LEDs */
44+
} led_typedef_enum;
45+
46+
/* LED bits for use with board_userled_all() */
47+
48+
#define BOARD_LED1_BIT (1 << BOARD_LED1)
49+
#define BOARD_LED2_BIT (1 << BOARD_LED2)
50+
#define BOARD_LED3_BIT (1 << BOARD_LED3)
51+
52+
/* Auto LEDs */
53+
3454
#define LED_STARTED 0 /* N/A */
3555
#define LED_HEAPALLOCATE 1 /* N/A */
3656
#define LED_IRQSENABLED 2 /* N/A */
@@ -39,7 +59,7 @@
3959
#define LED_SIGNAL 5 /* N/A */
4060
#define LED_ASSERTION 6 /* N/A */
4161
#define LED_PANIC 7 /* N/A */
42-
#define LED_CPU 8 /* LED */
62+
#define LED_IDLE 8 /* LED */
4363

4464
/****************************************************************************
4565
* Public Types

boards/risc-v/bl808/ox64/src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ include $(TOPDIR)/Make.defs
2222

2323
RCSRCS = etc/init.d/rc.sysinit etc/init.d/rcS
2424

25-
CSRCS = bl808_appinit.c
25+
CSRCS = bl808_appinit.c bl808_autoleds.c bl808_userleds.c
2626

2727
include $(TOPDIR)/boards/Board.mk

boards/risc-v/bl808/ox64/src/bl808_appinit.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,24 @@ void board_late_initialize(void)
167167

168168
#endif
169169

170+
#ifdef CONFIG_USERLED
171+
////TODO: Move to bringup.c
172+
/* Register the LED driver */
173+
174+
int ret = userled_lower_initialize("/dev/userleds");
175+
if (ret < 0)
176+
{
177+
syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret);
178+
}
179+
#endif
180+
170181
////TODO
171182
#define GPIO_PIN 29
172183
#define GPIO_ATTR (GPIO_OUTPUT | GPIO_FUNC_SWGPIO)
173184

174185
_info("Config GPIO: pin=%d, attr=0x%x\n", GPIO_PIN, GPIO_ATTR);
175-
int ret = bl808_configgpio(GPIO_PIN, GPIO_ATTR);
176-
DEBUGASSERT(ret == OK);
186+
int ret2 = bl808_configgpio(GPIO_PIN, GPIO_ATTR);
187+
DEBUGASSERT(ret2 == OK);
177188

178189
_info("Set GPIO: pin=%d\n", GPIO_PIN);
179190
bl808_gpiowrite(GPIO_PIN, true);
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
/****************************************************************************
2+
* boards/arm64/a64/pinephone/src/pinephone_autoleds.c
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
/****************************************************************************
22+
* Included Files
23+
****************************************************************************/
24+
25+
#include <nuttx/config.h>
26+
27+
#include <stdint.h>
28+
#include <stdbool.h>
29+
#include <debug.h>
30+
31+
#include <sys/param.h>
32+
33+
#include <nuttx/board.h>
34+
#include <arch/board/board.h>
35+
36+
#include "chip.h"
37+
////#include "arm64_internal.h"
38+
////#include "pinephone.h"
39+
40+
#ifdef CONFIG_ARCH_LEDS
41+
42+
/****************************************************************************
43+
* Private Data
44+
****************************************************************************/
45+
46+
/* LED index */
47+
48+
// static const uint32_t g_led_map[BOARD_LEDS] =
49+
// {
50+
// LED1,
51+
// LED2,
52+
// LED3
53+
// };
54+
55+
static bool g_initialized;
56+
57+
/****************************************************************************
58+
* Private Functions
59+
****************************************************************************/
60+
61+
/* Turn on selected led */
62+
63+
static void bl808_led_on(led_typedef_enum led_num)
64+
{
65+
////TODO: gpio_write(g_led_map[led_num], true);
66+
}
67+
68+
/* Turn off selected led */
69+
70+
static void bl808_led_off(led_typedef_enum led_num)
71+
{
72+
////TODO: gpio_write(g_led_map[led_num], false);
73+
}
74+
75+
/****************************************************************************
76+
* Public Functions
77+
****************************************************************************/
78+
79+
/****************************************************************************
80+
* Name: board_autoled_initialize
81+
*
82+
* Description:
83+
* This function is called very early in initialization to perform board-
84+
* specific initialization of LED-related resources. This includes such
85+
* things as, for example, configure GPIO pins to drive the LEDs and also
86+
* putting the LEDs in their correct initial state.
87+
*
88+
* NOTE: In most architectures, board_autoled_initialize() is called from
89+
* board-specific initialization logic. But there are a few architectures
90+
* where this initialization function is still called from common chip
91+
* architecture logic. This interface is not, however, a common board
92+
* interface in any event and, hence, the usage of the name
93+
* board_autoled_initialize is deprecated.
94+
*
95+
* WARNING: This interface name will eventually be removed; do not use it
96+
* in new board ports. New implementations should use the naming
97+
* conventions for "Microprocessor-Specific Interfaces" or the "Board-
98+
* Specific Interfaces" as described above.
99+
*
100+
* Input Parameters:
101+
* None
102+
*
103+
* Returned Value:
104+
* None
105+
*
106+
****************************************************************************/
107+
108+
void board_autoled_initialize(void)
109+
{
110+
int i;
111+
112+
/* Configure the LED GPIO for output. */
113+
114+
for (i = 0; i < BOARD_LEDS; i++)
115+
{
116+
////TODO: int ret = gpio_config(g_led_map[i]);
117+
////TODO: DEBUGASSERT(ret == OK);
118+
}
119+
}
120+
121+
/****************************************************************************
122+
* Name: board_autoled_on
123+
*
124+
* Description:
125+
* Set the LED configuration into the ON condition for the state provided
126+
* by the led parameter. This may be one of:
127+
*
128+
* LED_STARTED NuttX has been started
129+
* LED_HEAPALLOCATE Heap has been allocated
130+
* LED_IRQSENABLED Interrupts enabled
131+
* LED_STACKCREATED Idle stack created
132+
* LED_INIRQ In an interrupt
133+
* LED_SIGNAL In a signal handler
134+
* LED_ASSERTION An assertion failed
135+
* LED_PANIC The system has crashed
136+
* LED_IDLE MCU is in sleep mode
137+
*
138+
* Where these values are defined in a board-specific way in the standard
139+
* board.h header file exported by every architecture.
140+
*
141+
* Input Parameters:
142+
* led - Identifies the LED state to put in the ON state (which may or may
143+
* not equate to turning an LED on)
144+
*
145+
* Returned Value:
146+
* None
147+
*
148+
****************************************************************************/
149+
150+
void board_autoled_on(int led)
151+
{
152+
switch (led)
153+
{
154+
case LED_HEAPALLOCATE:
155+
bl808_led_on(BOARD_LED1);
156+
break;
157+
158+
case LED_IRQSENABLED:
159+
bl808_led_on(BOARD_LED2);
160+
break;
161+
162+
case LED_STACKCREATED:
163+
bl808_led_on(BOARD_LED3);
164+
g_initialized = true;
165+
break;
166+
167+
case LED_INIRQ:
168+
bl808_led_on(BOARD_LED1);
169+
bl808_led_on(BOARD_LED2);
170+
break;
171+
172+
case LED_SIGNAL:
173+
bl808_led_on(BOARD_LED1);
174+
bl808_led_on(BOARD_LED3);
175+
break;
176+
177+
case LED_ASSERTION:
178+
bl808_led_on(BOARD_LED2);
179+
bl808_led_on(BOARD_LED3);
180+
break;
181+
182+
case LED_PANIC:
183+
bl808_led_on(BOARD_LED1);
184+
break;
185+
186+
case LED_IDLE:
187+
bl808_led_on(BOARD_LED2);
188+
break;
189+
190+
default:
191+
break;
192+
}
193+
}
194+
195+
/****************************************************************************
196+
* Name: board_autoled_off
197+
*
198+
* Description:
199+
* Set the LED configuration into the OFF condition for the state provided
200+
* by the led parameter. This may be one of:
201+
*
202+
* LED_INIRQ Leaving an interrupt
203+
* LED_SIGNAL Leaving a signal handler
204+
* LED_ASSERTION Recovering from an assertion failure
205+
* LED_PANIC The system has crashed (blinking).
206+
* LED_IDLE MCU is not in sleep mode
207+
*
208+
* Where these values are defined in a board-specific way in the standard
209+
* board.h header file exported by every architecture.
210+
*
211+
* Input Parameters:
212+
* led - Identifies the LED state to put in the OFF state (which may or may
213+
* not equate to turning an LED off)
214+
*
215+
* Returned Value:
216+
* None
217+
*
218+
****************************************************************************/
219+
220+
void board_autoled_off(int led)
221+
{
222+
switch (led)
223+
{
224+
case LED_SIGNAL:
225+
bl808_led_off(BOARD_LED1);
226+
bl808_led_off(BOARD_LED3);
227+
break;
228+
229+
case LED_INIRQ:
230+
bl808_led_off(BOARD_LED1);
231+
bl808_led_off(BOARD_LED2);
232+
break;
233+
234+
case LED_ASSERTION:
235+
bl808_led_off(BOARD_LED2);
236+
bl808_led_off(BOARD_LED3);
237+
break;
238+
239+
case LED_PANIC:
240+
bl808_led_off(BOARD_LED1);
241+
break;
242+
243+
case LED_IDLE:
244+
bl808_led_off(BOARD_LED2);
245+
break;
246+
247+
default:
248+
break;
249+
}
250+
}
251+
252+
#endif /* CONFIG_ARCH_LEDS */

0 commit comments

Comments
 (0)