-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathuKey.h
More file actions
216 lines (165 loc) · 4.64 KB
/
uKey.h
File metadata and controls
216 lines (165 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/** ,-... ..-.
* ./:::::\ /:::::ヽ
* /::::::::::::;ゝ--──-- .._/:::::::ヽ
* /,.-‐''"′ \:::::::|
* / ヽ.::|
* / ● ヽ|
* l ... ● l
* .| (_人__丿 ... |
* l l
* ` . /
* `. .__ ./
* /`'''.‐‐──‐‐‐┬---
* File : key.h
* This file is part of aRTOS
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef KEY_H_
#define KEY_H_
/**
* @addtogroup std C lib include
*/
/*@{*/
#include <stdint.h>
/*@}*/
/**
* @addtogroup Key function configure
*/
/*@{*/
/**
* 实时系统(RTOS)类型
* @note 0: No OS
* 1: RTX4
* 2: aRTOS
*/
#define KEY_OS_TYPE (1)
/**
* 按键数目
* @note 包括普通按键,多重组合按键,Shift按键
*/
#define KEY_NUMBER (3)
/**
* 是否使用shift按键
* @note none
*/
#define USE_SHIFT_KEY (0)
/**
* 长按键判断周期
* @note 按键扫描周期 * KEY_PRESS_DLY = 长按判定
*/
#define KEY_PRESS_DLY (20)
/**
* 长按键判断周期
* @note 按键扫描周期 * KEY_PRESS_TMR = 长按发射一次
*/
#define KEY_PRESS_TMR (3)
/**
* 按键缓冲区大小
* @note none
*/
#define KEY_BUFFER_SIZE (KEY_NUMBER * 2)
/*@}*/
/**
* @addtogroup 按照按键数确定bitmap
*/
/*@{*/
#if KEY_NUMBER < 9
typedef uint8_t uKey_Bitmap_t;
#elif KEY_NUMBER < 17
typedef uint16_t uKey_Bitmap_t;
#else
typedef uint32_t uKey_Bitmap_t;
#endif
/*@}*/
/**
* @addtogroup simplify list define
*/
/*@{*/
struct __list_t {
struct __list_t *previous; /**< 前节点 */
struct __list_t *next; /**< 后节点 */
};
/*@}*/
/**
* @addtogroup Key object define
*/
/*@{*/
/**
* 按键类型
* @note 描述某key可触发的动作
*/
#define KEY_TYPE_SHORT 0x00 /**< 可短按连发 */
#define KEY_TYPE_LONG 0x01 /**< 不可连发,长按 */
#define KEY_TYPE_MULTI 0x02 /**< 多重按键 */
/**
* key 触发电平类型
* @note none
*/
#define KEY_LEVEL_HIGHT 0x01 /**< 高电平触发 */
#define KEY_LEVEL_LOW 0x00 /**< 低电平触发 */
/**
* key 按下类型
* @note 描述某key触发的动作类型
*/
#define KEY_IS_NONE 0x00 /**< 保留 */
#define KEY_IS_SP 0x01 /**< 短按 */
#define KEY_IS_LP 0x02 /**< 长按 */
#define KEY_IS_SSP 0x03 /**< shift + 短按 */
#define KEY_IS_SLP 0x04 /**< shift + 长按 */
typedef uint8_t uKey_type_t;
/**
* key 对象
* @note 描述某key的配置
*/
typedef struct uKeyDef {
uint8_t type; /**< 按键类型 */
uint8_t level; /**< 按键电平 */
uKey_Bitmap_t value; /**< 按键内部触发值 */
uKey_Bitmap_t value2; /**< 按键内部触发值,用于触发多个按键同时按下的值 */
uKey_Bitmap_t valueLong; /**< 按键长按内部触发值 */
uint32_t port; /**< 按键port */
uint32_t gpio; /**< 按键GPIO */
void (*callback)(void *obj, uKey_type_t type); /**< 按键触发回调 */
struct __list_t list; /**< 对象链表头 */
} uKeyDef_t;
/*@}*/
/**
* @addtogroup Key addons functions
*/
/*@{*/
/**
* key callback
* @note none
*/
#define uKey_Callback(name) \
void name(void *obj, uKey_type_t type)
/**
* key 获取按键值类型
* @note none
*/
#define SELF_PRESS_TYPE \
type
/*@}*/
/**
* @addtogroup Key functions define
*/
/*@{*/
extern void uKey_Startup(void);
extern void uKey_ShiftKeySet(uint32_t port, uint32_t gpio);
extern void uKey_ObjInsert(uKeyDef_t *obj);
extern uint8_t uKey_GetPressType(uKeyDef_t *obj, uKey_Bitmap_t vaule);
/*@}*/
#endif