main.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_G1 pin: PC3 */
  17. #define LED_G1 NU_GET_PININDEX(NU_PC, 3)
  18. /* defined the LED_G2 pin: PC11 */
  19. #define LED_G2 NU_GET_PININDEX(NU_PC, 11)
  20. /* defined the BUTTON pin: PC15 */
  21. #define BUTTON NU_GET_PININDEX(NU_PC, 15)
  22. static uint32_t u32Button = BUTTON;
  23. void nu_button_cb(void *args)
  24. {
  25. static int u32ToggleFlag = 0;
  26. uint32_t u32Key = *((uint32_t *)(args));
  27. switch (u32Key)
  28. {
  29. case BUTTON:
  30. u32ToggleFlag = ~u32ToggleFlag;
  31. rt_pin_write(LED_G1, u32ToggleFlag);
  32. break;
  33. }
  34. }
  35. #endif
  36. int main(int argc, char **argv)
  37. {
  38. #if defined(RT_USING_PIN)
  39. int counter = 1000;
  40. /* set LED_G1 pin mode to output */
  41. rt_pin_mode(LED_G1, PIN_MODE_OUTPUT);
  42. /* set LED_G2 pin mode to output */
  43. rt_pin_mode(LED_G2, PIN_MODE_OUTPUT);
  44. /* set BUTTON pin mode to input */
  45. rt_pin_mode(BUTTON, PIN_MODE_INPUT_PULLUP);
  46. rt_pin_attach_irq(BUTTON, PIN_IRQ_MODE_FALLING, nu_button_cb, &u32Button);
  47. rt_pin_irq_enable(BUTTON, PIN_IRQ_ENABLE);
  48. while (counter--)
  49. {
  50. rt_pin_write(LED_G2, PIN_HIGH);
  51. rt_thread_mdelay(200);
  52. rt_pin_write(LED_G2, PIN_LOW);
  53. rt_thread_mdelay(200);
  54. }
  55. #endif
  56. return 0;
  57. }