Key.h 3.92 KB
Newer Older
hu's avatar
hu committed
1 2 3 4 5 6 7 8
#ifndef KEY_H__
#define KEY_H__

#include "TYW_stdint.h"

/*
说明:
1、按键类型分为两类:
hu's avatar
hu committed
9 10
    1)CAN按键。
    2)单纯硬线按键,AD按键。
hu's avatar
hu committed
11 12 13 14 15 16 17 18 19
2、按键触发时间:
1)短按动作在抬手时触发、
2)长按动作(或超长按)在时间达到,按住时就可触发。
3)OFF到ON(或ON到OFF)在各个电源状态时按键按下时间满足后即可触发,不必抬手。

*/
/*所有按键枚举,目前最多支持8个按键*/
typedef enum
{
hu's avatar
hu committed
20
    KEY_UP   = 0U,
hu's avatar
hu committed
21 22 23 24 25
    KEY_DOWN,
    KEY_ENTER,
    KEY_RETURN,
    KEY_MENU,
    KEY_NUM_MAX,
hu's avatar
hu committed
26 27 28 29 30 31 32 33

} Key_Num_en_t;

/*--------------------------Do not modify the following--------------------------------*/
/*--------------------------Do not modify the following--------------------------------*/
/*--------------------------Do not modify the following--------------------------------*/
typedef enum
{
hu's avatar
hu committed
34
    // KEY_TYPE_CAN = 0U, /*CAN按键。按键不需要消抖*/
hu's avatar
hu committed
35
    // KEY_TYPE_LINE,      /*硬线按键,包含AD按键。按键需要消抖*/
hu's avatar
hu committed
36

hu's avatar
hu committed
37 38
    /*按键检测方式选择*/
    KEY_NO_DEBOUNCE_RISE = 0U, /*按键不需要消抖,并且在无效状态切换到有效状态的上升沿触发按键动作*/
hu's avatar
hu committed
39
    KEY_NO_DEBOUNCE_FALL,      /*按键不需要消抖,并且在有效状态切换到无效状态的下降沿触发按键动作*/
hu's avatar
hu committed
40

hu's avatar
hu committed
41
    KEY_NEED_DEBOUNCE_NORMAL, /*按键需要消抖,短按松手触发,长按,超超按,按住即可触发*/
hu's avatar
hu committed
42

hu's avatar
hu committed
43
    KEY_TYPE_MAX,
hu's avatar
hu committed
44 45 46 47 48
} Key_Type_en_t;

/*按键相关设置返回状态*/
typedef enum
{
hu's avatar
hu committed
49 50
    KEY_SET_OK = 0U,
    KEY_SET_ERROR,
hu's avatar
hu committed
51

hu's avatar
hu committed
52
    KEY_SET_MAX,
hu's avatar
hu committed
53 54 55 56
} Key_Set_en_t;
/*按键IG状态*/
typedef enum
{
hu's avatar
hu committed
57 58 59
    KEY_IG_INVALID = 0U,
    KEY_IG_OFF,
    KEY_IG_ON,
hu's avatar
hu committed
60 61 62 63 64 65

} Key_IGN_en_t;
/*-----实时传入的键值--------*/
typedef enum
{

hu's avatar
hu committed
66 67 68
    KEY_CAN_NONE = 0U,              /*CAN按键时,按键无动作*/
    KEY_CAN_SHORT_PRESS,            /*CAN按键时,按键短按动作*/
    KEY_CAN_LONG_PRESS,             /*CAN按键时,按键长按动作*/
hu's avatar
hu committed
69
    KEY_CAN_LONG_PRESS_NOT_RELEASE, /*CAN按键时,按键长按不松手动作,触发动作超长按*/
hu's avatar
hu committed
70

hu's avatar
hu committed
71
    KEY_LINE_PRESS,  /*硬线按键时,按键按下*/
hu's avatar
hu committed
72
    KEY_LINE_LOOSEN, /*硬线按键时,按键松开*/
hu's avatar
hu committed
73

hu's avatar
hu committed
74
    KEY_REAL_STATUS_MAX,
hu's avatar
hu committed
75 76 77 78 79

} Key_Real_Status_en_t;
/*按键支持的具体动作*/
typedef enum
{
hu's avatar
hu committed
80 81 82 83 84 85
    KEY_EVENT_NONE = 0U,
    KEY_EVENT_SHORT_PRESS,
    KEY_EVENT_LONG_PRESS,
    KEY_EVENT_SUPER_LONG_PRESS,
    KEY_EVENT_OFF_TO_ON,
    KEY_EVENT_ON_TO_OFF,
hu's avatar
hu committed
86

hu's avatar
hu committed
87
    KEY_EVENT_MAX,
hu's avatar
hu committed
88 89 90 91 92

} Key_Event_en_t;

typedef struct
{
hu's avatar
hu committed
93
    uint32_t u32KeyRAMAddr; /* 数据缓冲地址 */
hu's avatar
hu committed
94
    uint16_t u16KeyRAMLen;  /* 数据缓冲大小:以uint32_t为单位*/
hu's avatar
hu committed
95 96 97 98 99 100 101 102
} Key_RAM_Attribute_st_t;

typedef Key_Real_Status_en_t (*Key_Real_Status_Read)(void);
typedef void (*Key_Operation)(Key_Event_en_t enKeyEvent);

/*每个按键的属性*/
typedef struct
{
hu's avatar
hu committed
103 104 105 106 107 108
    /*按键类型,是CAN的还是硬线的*/
    Key_Type_en_t enKeyType;
    /*获取按键实时状态的回调函数*/
    Key_Real_Status_Read pfnKeyReadStatusCallBack;
    /*按键触发动作的回调函数*/
    Key_Operation pfnKeyOperationCallBack;
hu's avatar
hu committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129

} Key_Attribute_st_t;

/*--------------------------------------------------------------------------------------------*/
extern const Key_Attribute_st_t stKeyAttribute[KEY_NUM_MAX];

/*------------------------------------------------------------------------------------*/

/*10ms调用一次*/
extern void Key_Service(void);
/*首次上电时调用一次即可*/
extern void Key_Init(void);
/*对于硬线按键而言,判断短按的时间参数*/
extern Key_Set_en_t Key_Parameter_Set_Short_Press_Time(uint16_t u16Time);
/*对于硬线按键而言,判断长按的时间参数*/
extern Key_Set_en_t Key_Parameter_Set_Long_Press_Time(uint16_t u16Time);
/*对于硬线按键而言,判断超长按的时间参数*/
extern Key_Set_en_t Key_Parameter_Set_Super_Long_Press_Time(uint16_t u16Time);
/*获取IG状态*/
extern Key_IGN_en_t Key_Get_IGN_Status(void);

hu's avatar
hu committed
130 131
extern uint8_t Common_Get_RetMenu_Flag(void);

hu's avatar
hu committed
132
#endif