key_app.c 796 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "bsp.h"
  2. #include "gpio.h"
  3. #include "board_gpio.h"
  4. #include "multi_button.h"
  5. uint8_t btn1_id = 0;
  6. struct Button btn1;
  7. extern RF_States rf_statues;
  8. static uint8_t read_button_GPIO(uint8_t button_id)
  9. {
  10. // you can share the GPIO read function with multiple Buttons
  11. switch(button_id)
  12. {
  13. case 0:
  14. return Gpio_GetInputIO(GPIO_PORT_KEY, GPIO_PIN_KEY);
  15. break;
  16. default:
  17. return 0;
  18. break;
  19. }
  20. }
  21. static void BTN1_SINGLE_CLICK_Handler(void* btn)
  22. {
  23. //do something...
  24. //HAL_DBG_TRACE_INFO("button SINGLE_CLICK\r\n");
  25. rf_statues = RF_START_TX;
  26. }
  27. void multibutton_init(void)
  28. {
  29. button_init(&btn1, read_button_GPIO, 0, btn1_id);
  30. button_attach(&btn1, SINGLE_CLICK,BTN1_SINGLE_CLICK_Handler);
  31. button_start(&btn1);
  32. }