key_drivers.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef __KEY_DRIVERS_H
  2. #define __KEY_DRIVERS_H
  3. #include "stm32f1xx_hal.h"
  4. //按键状态
  5. typedef enum {
  6. Key_Status_NoPress = 0U, //无
  7. Key_Status_ShortPress, //短按
  8. Key_Status_LongPress //长按
  9. }Key_Status_t;
  10. //按键类型定义
  11. typedef struct //缓冲区各变量,用于相关函数的参数
  12. {
  13. uint16_t *ADC_result; //GPIO_PIN_x
  14. uint8_t Trg; //按键触发标志
  15. uint8_t Cont; //计数
  16. uint8_t PressFlasg; //按键按下标识
  17. uint16_t TimeCnt; //按键计时
  18. Key_Status_t KeyStatus; //按键状态
  19. }Key_TypeDef;
  20. //按键状态编码
  21. typedef union
  22. {
  23. struct
  24. {
  25. uint8_t Power :1;//Power
  26. uint8_t Walk :1;//Walk
  27. uint8_t Add :1;//+
  28. uint8_t Dec :1;//-
  29. uint8_t Set :1;//Set
  30. uint8_t Light :1;//Light
  31. uint8_t RS3 :1;
  32. uint8_t RS4 :1;
  33. }Key_Bit;
  34. uint8_t Code;
  35. }KeyScanCode_Struct_t;
  36. extern Key_TypeDef Key_On_Off;
  37. extern Key_TypeDef Key_Walk;
  38. extern Key_TypeDef Key_Light;
  39. extern Key_TypeDef Key_Set;
  40. extern Key_TypeDef Key_Down;
  41. extern Key_TypeDef Key_Up;
  42. //按键GPIO初始化
  43. void KeyInitial(void);
  44. //按键检测函数
  45. void Key_Check(Key_TypeDef* Key, uint8_t DelayTime);
  46. extern void KeyParamInit(Key_TypeDef * Key);
  47. extern void KeyParamInit_no_cont(Key_TypeDef * Key);
  48. //按键扫描编码
  49. KeyScanCode_Struct_t KeyScan(void);
  50. #endif