// // Created by iflyt on 2025/3/2. // #ifndef EXTI_KEY_MANAGER_H #define EXTI_KEY_MANAGER_H #include #include #define X_ORIGIN_PIN GPIO_PIN_6 #define X_LIMIT_PIN GPIO_PIN_7 #define X_PORT GPIOB #define Y_ORIGIN_PIN GPIO_PIN_9 #define Y_LIMIT_PIN GPIO_PIN_10 #define Y_PORT GPIOB #define Z_ORIGIN_PIN GPIO_PIN_13 #define Z_LIMIT_PIN GPIO_PIN_14 #define Z_PORT GPIOB #define EXTI_PIN_COUNT 8 /* * 按键信息管理类 */ typedef struct { GPIO_TypeDef *port; uint16_t pin; GPIO_PinState activeLevel; // 有效电平 } B_PinInfo; /** * 外部按键 key 信息 */ struct EXITKeyInfo { uint16_t gpio_pin; GPIO_PinState pin_state; }; // 外部中断按键管理类类 class ExtiKeyManager { public: // 获取单例实例的静态方法 static ExtiKeyManager* ins(); // 删除拷贝构造函数和赋值运算符,防止复制实例 ExtiKeyManager(const ExtiKeyManager&) = delete; ExtiKeyManager& operator=(const ExtiKeyManager&) = delete; static void handleInterrupt(uint16_t gpio_pin, GPIO_PinState pin_state); static bool isPinTriggered(uint16_t targetPin); static GPIO_TypeDef* getPortByPin(uint16_t pin); private: ExtiKeyManager(); ~ExtiKeyManager(); static bool isPinStateTriggered(const uint16_t pin, const bool state); static void handleKeyInterrupts(void* arg); void processKeyEvent(const uint16_t gpio_pin, const bool is_triggerd); private: static ExtiKeyManager* s_instance; osMessageQueueId_t keyQueue_; static EXITKeyInfo exit_key_info_; const static B_PinInfo pinInfos[EXTI_PIN_COUNT]; }; #ifdef __cplusplus extern "C" { #endif void EX_GPIO_Init(void); uint16_t getORIGINPin(uint32_t motor_index); uint16_t getAxisLimitPin(uint32_t motor_index); #ifdef __cplusplus } #endif #endif //BUTTON_MANAGER_H