1 /*
2 * Copyright (C) 2021, Huada Semiconductor Co., Ltd.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2021-09-07 PJQ first version
9 */
10
11
12 /*******************************************************************************
13 * Include files
14 ******************************************************************************/
15 #include "board.h"
16
17 #include <rtthread.h>
18 #include <rtdevice.h>
19
20 /*******************************************************************************
21 * Local type definitions ('typedef')
22 ******************************************************************************/
23
24 /*******************************************************************************
25 * Local pre-processor symbols/macros ('#define')
26 ******************************************************************************/
27
28 /* defined the LED pin: PC9 */
29 #define LED_PIN GET_PIN(D, 5)
30 #define KEY_PIN GET_PIN(B, 9)
31
32 /*******************************************************************************
33 * Global variable definitions (declared in header file with 'extern')
34 ******************************************************************************/
35
36 /*******************************************************************************
37 * Local function prototypes ('static')
38 ******************************************************************************/
39
40 /*******************************************************************************
41 * Local variable definitions ('static')
42 ******************************************************************************/
43 uint8_t flag;
44
45 /*******************************************************************************
46 * Function implementation - global ('extern') and local ('static')
47 ******************************************************************************/
key_handler(void * param)48 void key_handler(void *param)
49 {
50 flag = ~flag;
51 }
52
53 /**
54 *******************************************************************************
55 ** \brief Main function of GPIO output
56 **
57 ** \param None
58 **
59 ** \retval int32_t Return value, if needed
60 **
61 ******************************************************************************/
main(void)62 int main(void)
63 {
64 rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
65 rt_pin_attach_irq(KEY_PIN, PIN_IRQ_MODE_FALLING, key_handler, RT_NULL);
66 rt_pin_irq_enable(KEY_PIN, PIN_IRQ_ENABLE);
67
68 while(1)
69 {
70 if (flag == 0)
71 {
72 rt_pin_write(LED_PIN, PIN_HIGH);
73 rt_thread_delay(500);
74 rt_pin_write(LED_PIN, PIN_LOW);
75 rt_thread_delay(500);
76 }
77 else
78 {
79 rt_pin_write(LED_PIN, PIN_HIGH);
80 rt_thread_delay(2000);
81 rt_pin_write(LED_PIN, PIN_LOW);
82 rt_thread_delay(2000);
83 }
84 }
85 }
86
87 /*******************************************************************************
88 * EOF (not truncated)
89 ******************************************************************************/
90