-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy pathmain.c
146 lines (112 loc) · 3.25 KB
/
main.c
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
#include "button.h"
/**
******************************************************************
变量声明
******************************************************************
*/
Button_t Button1;
Button_t Button2;
/**
******************************************************************
函数声明
******************************************************************
*/
static void BSP_Init(void);
void Btn1_Dowm_CallBack(void *btn)
{
PRINT_INFO("Button1 单击!");
}
void Btn1_Double_CallBack(void *btn)
{
PRINT_INFO("Button1 双击!");
}
void Btn1_Long_CallBack(void *btn)
{
PRINT_INFO("Button1 长按!");
}
void Btn1_Continuos_CallBack(void *btn)
{
PRINT_INFO("Button1 连按!");
}
void Btn1_ContinuosFree_CallBack(void *btn)
{
PRINT_INFO("Button1 连按释放!");
}
void Btn2_Dowm_CallBack(void *btn)
{
PRINT_INFO("Button2 单击!");
}
void Btn2_Double_CallBack(void *btn)
{
PRINT_INFO("Button2 双击!");
}
void Btn2_Long_CallBack(void *btn)
{
PRINT_INFO("Button2 长按!");
}
void Btn2_Continuos_CallBack(void *btn)
{
PRINT_INFO("Button2 连按!");
}
void Btn2_ContinuosFree_CallBack(void *btn)
{
PRINT_INFO("Button2 连按释放!");
}
/**
******************************************************************
* @brief 主函数
* @author jiejie
* @version V1.0
* @date 2018-xx-xx
******************************************************************
*/
int main(void)
{
uint32_t i = 100000;
BSP_Init();
Button_Create("Button1",
&Button1,
Read_KEY1_Level,
KEY_ON);
Button_Attach(&Button1,BUTTON_DOWM,Btn1_Dowm_CallBack); //单击
Button_Attach(&Button1,BUTTON_DOUBLE,Btn1_Double_CallBack); //双击
Button_Attach(&Button1,BUTTON_CONTINUOS,Btn1_Continuos_CallBack); //连按
Button_Attach(&Button1,BUTTON_CONTINUOS_FREE,Btn1_ContinuosFree_CallBack); //连按释放
Button_Attach(&Button1,BUTTON_LONG,Btn1_Long_CallBack); //长按
Button_Create("Button2",
&Button2,
Read_KEY2_Level,
KEY_ON);
Button_Attach(&Button2,BUTTON_DOWM,Btn2_Dowm_CallBack); //单击
Button_Attach(&Button2,BUTTON_DOUBLE,Btn2_Double_CallBack); //双击
Button_Attach(&Button2,BUTTON_CONTINUOS,Btn2_Continuos_CallBack); //连按
Button_Attach(&Button2,BUTTON_CONTINUOS_FREE,Btn2_ContinuosFree_CallBack); //连按释放
Button_Attach(&Button2,BUTTON_LONG,Btn2_Long_CallBack); //长按
Get_Button_Event(&Button1);
Get_Button_Event(&Button2);
while(1)
{
Button_Process(); //需要周期调用按键处理函数
Delay_ms(20);
}
}
/**
******************************************************************
* @brief BSP_Init,用于所有板级初始化
* @author jiejie
* @version V1.0
* @date 2018-xx-xx
******************************************************************
*/
static void BSP_Init(void)
{
/* LED 初始化 */
LED_GPIO_Config();
/* 串口初始化 */
USART_Config();
/* 按键初始化 */
Key_GPIO_Config();
/* 打印信息 */
PRINT_INFO("welcome to learn jiejie stm32 library!\n");
}
/********************************END OF FILE***************************************/