summaryrefslogtreecommitdiff
path: root/bsp/nuvoton/nk-980iot/applications/main.c
blob: 53de4f85dcd05e0512462c202146fcdca4682026 (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) 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_R pin: PB13 */
#define LED_R   NU_GET_PININDEX(NU_PB, 13)

/* defined the LED_Y pin: PB8 */
#define LED_Y   NU_GET_PININDEX(NU_PB, 8)

#if !defined(BSP_USING_USBH)
/* defined the Key1 pin: PE10 */
#define KEY_1   NU_GET_PININDEX(NU_PE, 10)

/* defined the Key2 pin: PE12 */
#define KEY_2   NU_GET_PININDEX(NU_PE, 12)

static uint32_t u32Key1 = KEY_1;
static uint32_t u32Key2 = KEY_2;

void nu_button_cb(void *args)
{
    uint32_t u32Key = *((uint32_t *)(args));

    switch (u32Key)
    {
    case KEY_1:
        rt_pin_write(LED_Y, PIN_HIGH);
        break;
    case KEY_2:
        rt_pin_write(LED_Y, PIN_LOW);
        break;
    }
}
#endif

#endif

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

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

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

#if !defined(BSP_USING_USBH)
    /* set KEY_1 pin mode to input */
    rt_pin_mode(KEY_1, PIN_MODE_INPUT_PULLUP);

    /* set KEY_2 pin mode to output */
    rt_pin_mode(KEY_2, PIN_MODE_INPUT_PULLUP);

    rt_pin_attach_irq(KEY_1, PIN_IRQ_MODE_FALLING, nu_button_cb, &u32Key1);
    rt_pin_irq_enable(KEY_1, PIN_IRQ_ENABLE);

    rt_pin_attach_irq(KEY_2, PIN_IRQ_MODE_FALLING, nu_button_cb, &u32Key2);
    rt_pin_irq_enable(KEY_2, PIN_IRQ_ENABLE);
#endif

    while (counter--)
    {
        rt_pin_write(LED_R, PIN_HIGH);
        rt_thread_mdelay(100);
        rt_pin_write(LED_R, PIN_LOW);
        rt_thread_mdelay(100);
    }

#endif

    return 0;
}