1
0

user_key.c 833 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2006-2022, 100ask Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-06-06 Alen Add key code for 100ask f103 mini
  9. */
  10. #include <rtthread.h>
  11. #include <drv_gpio.h>
  12. #ifdef BSP_USING_USER_KEY
  13. #define KEY GET_PIN(A, 0)
  14. static void KEY_IRQHandler(void *args)
  15. {
  16. rt_kprintf("Key Status: ");
  17. if(rt_pin_read(KEY) == 0)
  18. {
  19. rt_kprintf("pressed.\r\n");
  20. }
  21. else
  22. {
  23. rt_kprintf("released.\r\n");
  24. }
  25. }
  26. static int rt_hw_user_key_init(void)
  27. {
  28. rt_pin_mode(KEY, PIN_IRQ_MODE_RISING_FALLING);
  29. rt_pin_attach_irq(KEY, PIN_IRQ_MODE_RISING_FALLING, KEY_IRQHandler, RT_NULL);
  30. rt_pin_irq_enable(KEY, RT_TRUE);
  31. return RT_EOK;
  32. }
  33. INIT_COMPONENT_EXPORT(rt_hw_user_key_init);
  34. #endif