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

#include "TYW_stdint.h"

hu's avatar
hu committed
6 7 8
#define K_Line_User_RYLQQ       100
#define K_Line_User_KQGZJ       100

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

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

} 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
37 38
    // KEY_TYPE_CAN = 0U, /*CAN按键。按键不需要消抖*/
    // KEY_TYPE_LINE,	   /*硬线按键,包含AD按键。按键需要消抖*/
hu's avatar
hu committed
39

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

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

hu's avatar
hu committed
46
    KEY_TYPE_MAX,
hu's avatar
hu committed
47 48 49 50 51
} Key_Type_en_t;

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

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

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

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

hu's avatar
hu committed
74 75
    KEY_LINE_PRESS,	 /*硬线按键时,按键按下*/
    KEY_LINE_LOOSEN, /*硬线按键时,按键松开*/
hu's avatar
hu committed
76

hu's avatar
hu committed
77
    KEY_REAL_STATUS_MAX,
hu's avatar
hu committed
78 79 80 81 82

} Key_Real_Status_en_t;
/*按键支持的具体动作*/
typedef enum
{
hu's avatar
hu committed
83 84 85 86 87 88
    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
89

hu's avatar
hu committed
90
    KEY_EVENT_MAX,
hu's avatar
hu committed
91 92 93 94 95

} Key_Event_en_t;

typedef struct
{
hu's avatar
hu committed
96 97
    uint32_t u32KeyRAMAddr; /* 数据缓冲地址 */
    uint16_t u16KeyRAMLen;	/* 数据缓冲大小:以uint32_t为单位*/
hu's avatar
hu committed
98 99 100 101 102 103 104 105
} 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
106 107 108 109 110 111
    /*按键类型,是CAN的还是硬线的*/
    Key_Type_en_t enKeyType;
    /*获取按键实时状态的回调函数*/
    Key_Real_Status_Read pfnKeyReadStatusCallBack;
    /*按键触发动作的回调函数*/
    Key_Operation pfnKeyOperationCallBack;
hu's avatar
hu committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

} 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);

#endif