-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexample.c
146 lines (112 loc) · 3.49 KB
/
example.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"
/**
******************************************************************
Variable declaration
******************************************************************
*/
Button_t Button1;
Button_t Button2;
/**
******************************************************************
Function declaration
******************************************************************
*/
static void BSP_Init(void);
void Btn1_Dowm_CallBack(void *btn)
{
PRINT_INFO("Button1 Click!");
}
void Btn1_Double_CallBack(void *btn)
{
PRINT_INFO("Button1 Double click!");
}
void Btn1_Long_CallBack(void *btn)
{
PRINT_INFO("Button1 Long press!");
}
void Btn1_Continuos_CallBack(void *btn)
{
PRINT_INFO("Button1 Press continuously!");
}
void Btn1_ContinuosFree_CallBack(void *btn)
{
PRINT_INFO("Button1 Press continuously free!");
}
void Btn2_Dowm_CallBack(void *btn)
{
PRINT_INFO("Button2 Click!");
}
void Btn2_Double_CallBack(void *btn)
{
PRINT_INFO("Button2 Double click!");
}
void Btn2_Long_CallBack(void *btn)
{
PRINT_INFO("Button2 Long press!");
}
void Btn2_Continuos_CallBack(void *btn)
{
PRINT_INFO("Button2 Press continuously!");
}
void Btn2_ContinuosFree_CallBack(void *btn)
{
PRINT_INFO("Button2 Press continuously free!");
}
/**
******************************************************************
* @brief main
* @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); //Click
Button_Attach(&Button1,BUTTON_DOUBLE,Btn1_Double_CallBack); //Double click
Button_Attach(&Button1,BUTTON_CONTINUOS,Btn1_Continuos_CallBack); //Press continuously
Button_Attach(&Button1,BUTTON_CONTINUOS_FREE,Btn1_ContinuosFree_CallBack); //Press continuously free
Button_Attach(&Button1,BUTTON_LONG,Btn1_Long_CallBack); //Long press
Button_Create("Button2",
&Button2,
Read_KEY2_Level,
KEY_ON);
Button_Attach(&Button2,BUTTON_DOWM,Btn2_Dowm_CallBack); //Click
Button_Attach(&Button2,BUTTON_DOUBLE,Btn2_Double_CallBack); //Double click
Button_Attach(&Button2,BUTTON_CONTINUOS,Btn2_Continuos_CallBack); //Press continuously
Button_Attach(&Button2,BUTTON_CONTINUOS_FREE,Btn2_ContinuosFree_CallBack); //Press continuously free
Button_Attach(&Button2,BUTTON_LONG,Btn2_Long_CallBack); //Long press
Get_Button_Event(&Button1);
Get_Button_Event(&Button2);
while(1)
{
Button_Process(); //Need to call the button handler function periodically
Delay_ms(20);
}
}
/**
******************************************************************
* @brief BSP_Init
* @author jiejie
* @version V1.0
* @date 2018-xx-xx
******************************************************************
*/
static void BSP_Init(void)
{
/* LED Config */
LED_GPIO_Config();
/* USART Config */
USART_Config();
/* button config */
Key_GPIO_Config();
/* print info */
PRINT_INFO("welcome to learn jiejie stm32 library!\n");
}
/********************************END OF FILE***************************************/