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
|
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017-09-14 Haley the first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#define AM_GPIO_LED0 46
#define AM_GPIO_LED1 47
#define AM_GPIO_LED2 48
#define AM_GPIO_LED3 49
/**
* @brief Turns on the requested LED.
*
* @param LEDNum is the LED number for the light to turn on.
*
* This function turns on a single LED.
*
* @return None.
*/
void rt_hw_led_on(rt_uint8_t LEDNum)
{
#ifdef RT_USING_PIN
if(LEDNum == 0)
rt_pin_write(AM_GPIO_LED0, PIN_LOW);
else if(LEDNum == 1)
rt_pin_write(AM_GPIO_LED1, PIN_LOW);
else if(LEDNum == 2)
rt_pin_write(AM_GPIO_LED2, PIN_LOW);
else if(LEDNum == 3)
rt_pin_write(AM_GPIO_LED3, PIN_LOW);
#endif
}
/**
* @brief Turns off the requested LED.
*
* @param LEDNum is the LED number for the light to turn off.
*
* This function turns off a single LED.
*
* @return None.
*/
void rt_hw_led_off(rt_uint8_t LEDNum)
{
#ifdef RT_USING_PIN
if(LEDNum == 0)
rt_pin_write(AM_GPIO_LED0, PIN_HIGH);
else if(LEDNum == 1)
rt_pin_write(AM_GPIO_LED1, PIN_HIGH);
else if(LEDNum == 2)
rt_pin_write(AM_GPIO_LED2, PIN_HIGH);
else if(LEDNum == 3)
rt_pin_write(AM_GPIO_LED3, PIN_HIGH);
#endif
}
/**
* @brief Configures the necessary pins for an array of LEDs
*
* @param None.
*
* This function configures a GPIO to drive an LED in a low-power way.
*
* @return None.
*/
int rt_hw_led_init(void)
{
#ifdef RT_USING_PIN
#if defined(RT_USING_LED0)
/* config led */
rt_pin_mode(AM_GPIO_LED0, PIN_MODE_OUTPUT);
/* turns off the led */
rt_hw_led_off(0);
#endif /* RT_USING_LED0 */
#if defined(RT_USING_LED1)
/* config led */
rt_pin_mode(AM_GPIO_LED1, PIN_MODE_OUTPUT);
/* turns off the led */
rt_hw_led_off(1);
#endif /* RT_USING_LED1 */
#if defined(RT_USING_LED2)
/* config led */
rt_pin_mode(AM_GPIO_LED2, PIN_MODE_OUTPUT);
/* turns off the led */
rt_hw_led_off(2);
#endif /* RT_USING_LED0 */
#if defined(RT_USING_LED3)
/* config led */
rt_pin_mode(AM_GPIO_LED3, PIN_MODE_OUTPUT);
/* turns off the led */
rt_hw_led_off(3);
#endif /* RT_USING_LED1 */
#endif
rt_kprintf("led_init!\n");
return 0;
}
#ifdef RT_USING_COMPONENTS_INIT
INIT_DEVICE_EXPORT(rt_hw_led_init);
#endif
#ifdef RT_USING_FINSH
#include <finsh.h>
void led(rt_uint32_t led, rt_uint32_t state)
{
/* set led status */
switch (state)
{
case 0:
rt_hw_led_off(led);
break;
case 1:
rt_hw_led_on(led);
break;
default:
break;
}
}
FINSH_FUNCTION_EXPORT(led, turn led (0 - 3) on (1) or off (0).)
#endif
/*@}*/
|