1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author        Notes
8  * 2021-10-10     Sherman       first version
9  * 2021-11-03     Sherman       Add icu_sample
10  */
11 
12 #include <rtthread.h>
13 #include "hal_data.h"
14 #include <rtdevice.h>
15 
16 #define LED3_PIN    BSP_IO_PORT_01_PIN_06
17 #define USER_INPUT  "P105"
18 
hal_entry(void)19 void hal_entry(void)
20 {
21     rt_kprintf("\nHello RT-Thread!\n");
22 
23     while (1)
24     {
25         rt_pin_write(LED3_PIN, PIN_HIGH);
26         rt_thread_mdelay(500);
27         rt_pin_write(LED3_PIN, PIN_LOW);
28         rt_thread_mdelay(500);
29     }
30 }
31 
irq_callback_test(void * args)32 void irq_callback_test(void *args)
33 {
34     rt_kprintf("\n IRQ00 triggered \n");
35 }
36 
icu_sample(void)37 void icu_sample(void)
38 {
39     /* init */
40     rt_uint32_t pin = rt_pin_get(USER_INPUT);
41     rt_kprintf("\n pin number : 0x%04X \n", pin);
42     rt_err_t err = rt_pin_attach_irq(pin, PIN_IRQ_MODE_RISING, irq_callback_test, RT_NULL);
43     if(RT_EOK != err)
44     {
45         rt_kprintf("\n attach irq failed. \n");
46     }
47     err = rt_pin_irq_enable(pin, PIN_IRQ_ENABLE);
48     if(RT_EOK != err)
49     {
50         rt_kprintf("\n enable irq failed. \n");
51     }
52 }
53 MSH_CMD_EXPORT(icu_sample, icu sample);
54