1
0

main.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**************************************************************************//**
  2. *
  3. * @copyright (C) 2019 Nuvoton Technology Corp. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2020-12-12 Wayne First version
  10. *
  11. ******************************************************************************/
  12. #include <rtconfig.h>
  13. #include <rtdevice.h>
  14. #if defined(RT_USING_PIN)
  15. #include <drv_gpio.h>
  16. /* defined the LED_R pin: PB13 */
  17. #define LED_R NU_GET_PININDEX(NU_PB, 13)
  18. /* defined the LED_Y pin: PB8 */
  19. #define LED_Y NU_GET_PININDEX(NU_PB, 8)
  20. #if !defined(BSP_USING_USBH)
  21. /* defined the Key1 pin: PE10 */
  22. #define KEY_1 NU_GET_PININDEX(NU_PE, 10)
  23. /* defined the Key2 pin: PE12 */
  24. #define KEY_2 NU_GET_PININDEX(NU_PE, 12)
  25. static uint32_t u32Key1 = KEY_1;
  26. static uint32_t u32Key2 = KEY_2;
  27. void nu_button_cb(void *args)
  28. {
  29. uint32_t u32Key = *((uint32_t *)(args));
  30. switch (u32Key)
  31. {
  32. case KEY_1:
  33. rt_pin_write(LED_Y, PIN_HIGH);
  34. break;
  35. case KEY_2:
  36. rt_pin_write(LED_Y, PIN_LOW);
  37. break;
  38. }
  39. }
  40. #endif
  41. #endif
  42. int main(int argc, char **argv)
  43. {
  44. #if defined(RT_USING_PIN)
  45. int counter = 1000;
  46. /* set LED_R pin mode to output */
  47. rt_pin_mode(LED_R, PIN_MODE_OUTPUT);
  48. /* set LED_Y pin mode to output */
  49. rt_pin_mode(LED_Y, PIN_MODE_OUTPUT);
  50. #if !defined(BSP_USING_USBH)
  51. /* set KEY_1 pin mode to input */
  52. rt_pin_mode(KEY_1, PIN_MODE_INPUT_PULLUP);
  53. /* set KEY_2 pin mode to output */
  54. rt_pin_mode(KEY_2, PIN_MODE_INPUT_PULLUP);
  55. rt_pin_attach_irq(KEY_1, PIN_IRQ_MODE_FALLING, nu_button_cb, &u32Key1);
  56. rt_pin_irq_enable(KEY_1, PIN_IRQ_ENABLE);
  57. rt_pin_attach_irq(KEY_2, PIN_IRQ_MODE_FALLING, nu_button_cb, &u32Key2);
  58. rt_pin_irq_enable(KEY_2, PIN_IRQ_ENABLE);
  59. #endif
  60. while (counter--)
  61. {
  62. rt_pin_write(LED_R, PIN_HIGH);
  63. rt_thread_mdelay(100);
  64. rt_pin_write(LED_R, PIN_LOW);
  65. rt_thread_mdelay(100);
  66. }
  67. #endif
  68. return 0;
  69. }