1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2017-09-14     Haley        the first version
9  */
10 
11 #include <rtthread.h>
12 #include <rtdevice.h>
13 #include "board.h"
14 
15 #define AM_GPIO_LED0                46
16 #define AM_GPIO_LED1                47
17 #define AM_GPIO_LED2                48
18 #define AM_GPIO_LED3                49
19 
20 /**
21  * @brief Turns on the requested LED.
22  *
23  * @param LEDNum is the LED number for the light to turn on.
24  *
25  * This function turns on a single LED.
26  *
27  * @return None.
28  */
rt_hw_led_on(rt_uint8_t LEDNum)29 void rt_hw_led_on(rt_uint8_t LEDNum)
30 {
31 #ifdef RT_USING_PIN
32     if(LEDNum == 0)
33         rt_pin_write(AM_GPIO_LED0, PIN_LOW);
34 
35     else if(LEDNum == 1)
36         rt_pin_write(AM_GPIO_LED1, PIN_LOW);
37 
38     else if(LEDNum == 2)
39         rt_pin_write(AM_GPIO_LED2, PIN_LOW);
40 
41     else if(LEDNum == 3)
42         rt_pin_write(AM_GPIO_LED3, PIN_LOW);
43 #endif
44 }
45 
46 /**
47  * @brief Turns off the requested LED.
48  *
49  * @param LEDNum is the LED number for the light to turn off.
50  *
51  * This function turns off a single LED.
52  *
53  * @return None.
54  */
rt_hw_led_off(rt_uint8_t LEDNum)55 void rt_hw_led_off(rt_uint8_t LEDNum)
56 {
57 #ifdef RT_USING_PIN
58     if(LEDNum == 0)
59         rt_pin_write(AM_GPIO_LED0, PIN_HIGH);
60 
61     else if(LEDNum == 1)
62         rt_pin_write(AM_GPIO_LED1, PIN_HIGH);
63 
64     else if(LEDNum == 2)
65         rt_pin_write(AM_GPIO_LED2, PIN_HIGH);
66 
67     else if(LEDNum == 3)
68         rt_pin_write(AM_GPIO_LED3, PIN_HIGH);
69 #endif
70 }
71 
72 /**
73  * @brief Configures the necessary pins for an array of LEDs
74  *
75  * @param None.
76  *
77  * This function configures a GPIO to drive an LED in a low-power way.
78  *
79  * @return None.
80  */
rt_hw_led_init(void)81 int rt_hw_led_init(void)
82 {
83 #ifdef RT_USING_PIN
84 #if defined(RT_USING_LED0)
85     /* config led */
86     rt_pin_mode(AM_GPIO_LED0, PIN_MODE_OUTPUT);
87 
88     /* turns off the led */
89     rt_hw_led_off(0);
90 #endif /* RT_USING_LED0 */
91 
92 #if defined(RT_USING_LED1)
93     /* config led */
94     rt_pin_mode(AM_GPIO_LED1, PIN_MODE_OUTPUT);
95 
96     /* turns off the led */
97     rt_hw_led_off(1);
98 #endif /* RT_USING_LED1 */
99 
100 #if defined(RT_USING_LED2)
101     /* config led */
102     rt_pin_mode(AM_GPIO_LED2, PIN_MODE_OUTPUT);
103 
104     /* turns off the led */
105     rt_hw_led_off(2);
106 #endif /* RT_USING_LED0 */
107 
108 #if defined(RT_USING_LED3)
109     /* config led */
110     rt_pin_mode(AM_GPIO_LED3, PIN_MODE_OUTPUT);
111 
112     /* turns off the led */
113     rt_hw_led_off(3);
114 #endif /* RT_USING_LED1 */
115 #endif
116 
117     rt_kprintf("led_init!\n");
118 
119     return 0;
120 }
121 #ifdef RT_USING_COMPONENTS_INIT
122 INIT_DEVICE_EXPORT(rt_hw_led_init);
123 #endif
124 
125 #ifdef RT_USING_FINSH
126 #include <finsh.h>
127 
led(rt_uint32_t led,rt_uint32_t state)128 void led(rt_uint32_t led, rt_uint32_t state)
129 {
130     /* set led status */
131     switch (state)
132     {
133     case 0:
134         rt_hw_led_off(led);
135         break;
136     case 1:
137         rt_hw_led_on(led);
138         break;
139     default:
140         break;
141     }
142 }
143 FINSH_FUNCTION_EXPORT(led, turn led (0 - 3) on (1) or off (0).)
144 #endif
145 
146 /*@}*/
147