1 /*
2 * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3 */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <aos/errno.h>
8 #include <aos/kernel.h>
9 #include "aos/init.h"
10 #include "board.h"
11 #include <k_api.h>
12 #include "aos/cli.h"
13 #include "led.h"
14 #include "hal_gpio.h"
15 #include "hal_iomux_haas1000.h"
16
17 extern uint32_t led_test_flag;
18 aos_task_t g_led_test_task;
19
led_blink(void)20 void led_blink(void)
21 {
22 unsigned int led_id = 0;
23
24 while (led_test_flag) {
25 if (led_id % 2 == 0) {
26 led_switch(1, LED_ON);
27 led_switch(2, LED_ON);
28 led_switch(3, LED_ON);
29 } else {
30 led_switch(1, LED_OFF);
31 led_switch(2, LED_OFF);
32 led_switch(3, LED_OFF);
33 }
34 aos_msleep(500);
35 led_id++;
36 }
37 }
38
led_test_process(void)39 void led_test_process(void)
40 {
41 printf("\r\n\r\n");
42 printf("***************************************************************\r\n");
43 printf("************************* LED Test ****************************\r\n");
44 printf("***************************************************************\r\n");
45 printf("*How to test: If the light flashes normally, press the function key *\r\n");
46 printf("***************************************************************\r\n");
47 printf("===== LED test : Start=====\r\n");
48
49 aos_task_create(&g_led_test_task, "led_blink", led_blink, NULL, NULL, 4096, 30, 0x01u);
50 }
51
led_test_task_delete(void)52 void led_test_task_delete(void)
53 {
54 aos_task_delete(&g_led_test_task);
55 }
56
handle_led_cmd(char * pwbuf,int blen,int argc,char ** argv)57 static void handle_led_cmd(char *pwbuf, int blen, int argc, char **argv)
58 {
59 int id;
60 char *onoff;
61
62 if (argc < 2) {
63 printf("Usage: led id on/off\n");
64 printf("Example: led 3 on\n");
65 return;
66 }
67 id = atoi(argv[1]);
68 onoff = argv[2];
69
70 if (0 == strcmp(onoff, "on")) {
71 led_switch(id, LED_ON);
72 } else if (0 == strcmp(onoff, "off")) {
73 led_switch(id, LED_OFF);
74 }
75 }
76
77 static struct cli_command led_cmd = {
78 .name = "led",
79 .help = "led [3, on/off]",
80 .function = handle_led_cmd
81 };
82
led_test(void)83 void led_test(void)
84 {
85 aos_cli_register_command(&led_cmd);
86 led_test_flag = 1;
87 led_test_process();
88 }
89