summaryrefslogtreecommitdiff
path: root/bsp/hc32l136/applications/main.c
blob: a8e957d53ccae54403c25793db7a1359d10ae8c8 (plain)
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
/*
 * Copyright (C) 2021, Huada Semiconductor Co., Ltd.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-09-07     PJQ          first version
 */


/*******************************************************************************
 * Include files
 ******************************************************************************/
#include "board.h"

#include <rtthread.h>
#include <rtdevice.h>

/*******************************************************************************
 * Local type definitions ('typedef')
 ******************************************************************************/

/*******************************************************************************
 * Local pre-processor symbols/macros ('#define')
 ******************************************************************************/

/* defined the LED pin: PC9 */
#define LED_PIN                 GET_PIN(D, 5)
#define KEY_PIN                 GET_PIN(B, 9)

/*******************************************************************************
 * Global variable definitions (declared in header file with 'extern')
 ******************************************************************************/

/*******************************************************************************
 * Local function prototypes ('static')
 ******************************************************************************/

/*******************************************************************************
 * Local variable definitions ('static')
 ******************************************************************************/
 uint8_t flag;

/*******************************************************************************
 * Function implementation - global ('extern') and local ('static')
 ******************************************************************************/
void key_handler(void *param)
{
    flag = ~flag;
}

/**
 *******************************************************************************
 ** \brief  Main function of GPIO output
 **
 ** \param  None
 **
 ** \retval int32_t Return value, if needed
 **
 ******************************************************************************/
int main(void)
{
    rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
    rt_pin_attach_irq(KEY_PIN, PIN_IRQ_MODE_FALLING, key_handler, RT_NULL);
    rt_pin_irq_enable(KEY_PIN, PIN_IRQ_ENABLE);
    
    while(1)
    {
        if (flag == 0)
        {
            rt_pin_write(LED_PIN, PIN_HIGH);
            rt_thread_delay(500);
            rt_pin_write(LED_PIN, PIN_LOW);
            rt_thread_delay(500);
        }
        else
        {
            rt_pin_write(LED_PIN, PIN_HIGH);
            rt_thread_delay(2000);
            rt_pin_write(LED_PIN, PIN_LOW);
            rt_thread_delay(2000);
        }
     }
}

/*******************************************************************************
 * EOF (not truncated)
 ******************************************************************************/