summaryrefslogtreecommitdiff
path: root/bsp/nuvoton/nk-rtu980/applications/main.c
blob: 73992209ed2fd0e0c3db6cc9d83cac8d784fe7d5 (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
/**************************************************************************//**
*
* @copyright (C) 2019 Nuvoton Technology Corp. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date            Author       Notes
* 2020-12-12      Wayne        First version
*
******************************************************************************/

#include <rtconfig.h>
#include <rtdevice.h>

#if defined(RT_USING_PIN)
#include <drv_gpio.h>

/* defined the LED_G1 pin: PC3 */
#define LED_G1   NU_GET_PININDEX(NU_PC, 3)

/* defined the LED_G2 pin: PC11 */
#define LED_G2   NU_GET_PININDEX(NU_PC, 11)

/* defined the BUTTON pin: PC15 */
#define BUTTON   NU_GET_PININDEX(NU_PC, 15)

static uint32_t u32Button = BUTTON;

void nu_button_cb(void *args)
{
    static int u32ToggleFlag = 0;
    uint32_t u32Key = *((uint32_t *)(args));

    switch (u32Key)
    {
    case BUTTON:
        u32ToggleFlag = ~u32ToggleFlag;
        rt_pin_write(LED_G1, u32ToggleFlag);
        break;
    }
}
#endif

int main(int argc, char **argv)
{
#if defined(RT_USING_PIN)
    int counter = 1000;

    /* set LED_G1 pin mode to output */
    rt_pin_mode(LED_G1, PIN_MODE_OUTPUT);

    /* set LED_G2 pin mode to output */
    rt_pin_mode(LED_G2, PIN_MODE_OUTPUT);

    /* set BUTTON pin mode to input */
    rt_pin_mode(BUTTON, PIN_MODE_INPUT_PULLUP);
    rt_pin_attach_irq(BUTTON, PIN_IRQ_MODE_FALLING, nu_button_cb, &u32Button);
    rt_pin_irq_enable(BUTTON, PIN_IRQ_ENABLE);

    while (counter--)
    {
        rt_pin_write(LED_G2, PIN_HIGH);
        rt_thread_mdelay(200);
        rt_pin_write(LED_G2, PIN_LOW);
        rt_thread_mdelay(200);
    }
#endif

    return 0;
}