input_scan.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. ******************************************************************************
  3. * @file input_scan.h
  4. * @brief 编码器/按键扫描模块公共接口
  5. *
  6. * 负责:
  7. * - 3个按键的消抖检测 (SW_KEY / SW1_KEY / SW2_KEY)
  8. * - 2个旋转编码器的正交解码 (SW1 / SW2)
  9. * - 编码器变速调节逻辑
  10. *
  11. * 事件标志由本模块定义, main.c 通过 extern 读取后处理.
  12. ******************************************************************************
  13. */
  14. #ifndef __INPUT_SCAN_H
  15. #define __INPUT_SCAN_H
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #include <stdint.h>
  20. /* ========== 按键事件标志 (在 ScanButtons 中置位, 主循环中清除) ========== */
  21. extern volatile uint8_t g_swKeyEdge; /* SW_KEY 短按释放标志 */
  22. extern volatile uint8_t g_sw1KeyEdge; /* SW1_KEY 短按释放标志 */
  23. extern volatile uint8_t g_sw2KeyEdge; /* SW2_KEY 短按释放标志 */
  24. extern volatile uint8_t g_swKeyLongPress; /* SW_KEY 长按5s标志 (1=触发, 2=已处理) */
  25. /* ========== 双键同按状态 (在 ScanButtons 中维护) ========== */
  26. extern volatile uint8_t g_bothPressFlag; /* 两编码器键同按标志 */
  27. extern volatile uint16_t g_bothPressMs; /* 同按持续时间 (ms) */
  28. /* ========== 函数接口 ========== */
  29. /**
  30. * @brief 初始化输入扫描模块
  31. * 读取编码器和按键的初始状态, 防止上电后产生误触发.
  32. * 须在 GPIO 初始化之后、TIM3 启动之前调用.
  33. */
  34. void InputScan_Init(void);
  35. /**
  36. * @brief 扫描所有按键 (在 TIM3 中断中每 1ms 调用)
  37. * 外部上拉, 低电平有效, 包含边沿检测.
  38. */
  39. void ScanButtons(void);
  40. /**
  41. * @brief 扫描所有编码器 (在 TIM3 中断中每 1ms 调用)
  42. * SW1: 低音音量; SW2: 主音量 LR
  43. */
  44. void ScanEncoders(void);
  45. #ifdef __cplusplus
  46. }
  47. #endif
  48. #endif /* __INPUT_SCAN_H */