基质喷涂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.8 KiB

  1. //
  2. // Created by iflyt on 2025/3/2.
  3. //
  4. #ifndef EXTI_KEY_MANAGER_H
  5. #define EXTI_KEY_MANAGER_H
  6. #include <stm32f4xx_hal.h>
  7. #include <cmsis_os2.h>
  8. #define X_ORIGIN_PIN GPIO_PIN_6
  9. #define X_LIMIT_PIN GPIO_PIN_7
  10. #define X_PORT GPIOB
  11. #define Y_ORIGIN_PIN GPIO_PIN_9
  12. #define Y_LIMIT_PIN GPIO_PIN_10
  13. #define Y_PORT GPIOB
  14. #define Z_ORIGIN_PIN GPIO_PIN_13
  15. #define Z_LIMIT_PIN GPIO_PIN_14
  16. #define Z_PORT GPIOB
  17. #define EXTI_PIN_COUNT 8
  18. /*
  19. *
  20. */
  21. typedef struct {
  22. GPIO_TypeDef *port;
  23. uint16_t pin;
  24. GPIO_PinState activeLevel; // 有效电平
  25. } B_PinInfo;
  26. /**
  27. * key
  28. */
  29. struct EXITKeyInfo {
  30. uint16_t gpio_pin;
  31. GPIO_PinState pin_state;
  32. };
  33. // 外部中断按键管理类类
  34. class ExtiKeyManager {
  35. public:
  36. // 获取单例实例的静态方法
  37. static ExtiKeyManager* ins();
  38. // 删除拷贝构造函数和赋值运算符,防止复制实例
  39. ExtiKeyManager(const ExtiKeyManager&) = delete;
  40. ExtiKeyManager& operator=(const ExtiKeyManager&) = delete;
  41. static void handleInterrupt(uint16_t gpio_pin, GPIO_PinState pin_state);
  42. static bool isPinTriggered(uint16_t targetPin);
  43. static GPIO_TypeDef* getPortByPin(uint16_t pin);
  44. private:
  45. ExtiKeyManager();
  46. ~ExtiKeyManager();
  47. static bool isPinStateTriggered(const uint16_t pin, const bool state);
  48. static void handleKeyInterrupts(void* arg);
  49. void processKeyEvent(const uint16_t gpio_pin, const bool is_triggerd);
  50. private:
  51. static ExtiKeyManager* s_instance;
  52. osMessageQueueId_t keyQueue_;
  53. static EXITKeyInfo exit_key_info_;
  54. const static B_PinInfo pinInfos[EXTI_PIN_COUNT];
  55. };
  56. #ifdef __cplusplus
  57. extern "C" {
  58. #endif
  59. void EX_GPIO_Init(void);
  60. uint16_t getORIGINPin(uint32_t motor_index);
  61. uint16_t getAxisLimitPin(uint32_t motor_index);
  62. #ifdef __cplusplus
  63. }
  64. #endif
  65. #endif //BUTTON_MANAGER_H