main.c 864 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. *
  3. * SPDX-License-Identifier: Apache-2.0
  4. *
  5. * Change Logs:
  6. * Date Author Notes
  7. * 2020-09-05 DongBowen first version
  8. */
  9. #include "board.h"
  10. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. #define LED_PIN GET_PIN(C, 13)
  13. #define LED_PERIOD (RT_TICK_PER_SECOND / 5)
  14. #define KEY_PIN GET_PIN(B, 12)
  15. void key_handle(void *args)
  16. {
  17. rt_kprintf("key pressed!\n");
  18. }
  19. int main(void)
  20. {
  21. rt_pin_mode(KEY_PIN, PIN_MODE_INPUT_PULLUP);
  22. rt_pin_attach_irq(KEY_PIN, PIN_IRQ_MODE_FALLING, key_handle, RT_NULL);
  23. rt_pin_irq_enable(KEY_PIN, PIN_IRQ_ENABLE);
  24. rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
  25. while (1)
  26. {
  27. rt_pin_write(LED_PIN, PIN_HIGH);
  28. rt_thread_delay(LED_PERIOD / 2);
  29. rt_pin_write(LED_PIN, PIN_LOW);
  30. rt_thread_delay(LED_PERIOD / 2);
  31. };
  32. }