1
1
/**
2
- * @File: flexible_button_demo .c
2
+ * @File: demo_tos_evb_mx_plus .c
3
3
* @Author: MurphyZhao
4
4
* @Date: 2018-09-29
5
5
*
20
20
* See the License for the specific language governing permissions and
21
21
* limitations under the License.
22
22
*
23
+ * message:
24
+ * This demo is base on TencentOSTiny EVB_MX+, reference
25
+ * https://github.com/Tencent/TencentOS-tiny
26
+ * Hardware: TencentOSTiny EVB_MX+.
27
+ *
23
28
* Change logs:
24
29
* Date Author Notes
25
- * 2018-09-29 MurphyZhao First add
26
- * 2019-08-02 MurphyZhao Migrate code to github.com/murphyzhao account
30
+ * 2020-01-20 MurphyZhao First add
31
+ * 2020-02-14 MurphyZhao Fix Key mismatch problem and fix grammar bug
27
32
*/
28
33
34
+ #include "stdio.h"
29
35
#include "mcu_init.h"
30
36
#include "cmsis_os.h"
31
37
32
- #include "stm32l4xx_hal.h"
33
- #include "stdio.h"
38
+ #include "main.h"
34
39
35
40
#include "flexible_button.h"
36
41
37
42
#define FLEXIBLE_BTN_STK_SIZE 512
38
43
static void button_scan (void * arg );
39
44
osThreadDef (button_scan , osPriorityNormal , 1 , FLEXIBLE_BTN_STK_SIZE );
40
45
41
- #ifndef PIN_KEY1
42
- #define PORT_KEY1 GPIOB
43
- #define PIN_KEY1 GPIO_PIN_12 // PB12
46
+ #ifndef PIN_KEY4
47
+ #define PORT_KEY4 GPIOB
48
+ #define PIN_KEY4 GPIO_PIN_12 // PB12
44
49
#endif
45
50
46
- #ifndef PIN_KEY2
47
- #define PORT_KEY2 GPIOB
48
- #define PIN_KEY2 GPIO_PIN_2 // PB2
51
+ #ifndef PIN_KEY3
52
+ #define PORT_KEY3 GPIOB
53
+ #define PIN_KEY3 GPIO_PIN_2 // PB2
49
54
#endif
50
55
51
- #ifndef PIN_KEY3
52
- #define PORT_KEY3 GPIOC
53
- #define PIN_KEY3 GPIO_PIN_10 // PC10
56
+ #ifndef PIN_KEY2
57
+ #define PORT_KEY2 GPIOC
58
+ #define PIN_KEY2 GPIO_PIN_10 // PC10
54
59
#endif
55
60
56
- #ifndef PIN_KEY4
57
- #define PORT_KEY4 GPIOB
58
- #define PIN_KEY4 GPIO_PIN_13 // PB13
61
+ #ifndef PIN_KEY1
62
+ #define PORT_KEY1 GPIOB
63
+ #define PIN_KEY1 GPIO_PIN_13 // PB13
59
64
#endif
60
65
61
66
#define ENUM_TO_STR (e ) (#e)
62
67
63
68
typedef enum
64
69
{
65
- USER_BUTTON_0 = 0 ,
66
- USER_BUTTON_1 ,
70
+ USER_BUTTON_1 = 0 ,
67
71
USER_BUTTON_2 ,
68
72
USER_BUTTON_3 ,
73
+ USER_BUTTON_4 ,
69
74
USER_BUTTON_MAX
70
75
} user_button_t ;
71
76
@@ -85,10 +90,10 @@ static char *enum_event_string[] = {
85
90
};
86
91
87
92
static char * enum_btn_id_string [] = {
88
- ENUM_TO_STR (USER_BUTTON_0 ),
89
- ENUM_TO_STR (USER_BUTTON_1 ),
90
- ENUM_TO_STR (USER_BUTTON_2 ),
91
- ENUM_TO_STR (USER_BUTTON_3 ),
93
+ ENUM_TO_STR (F1 ),
94
+ ENUM_TO_STR (F2 ),
95
+ ENUM_TO_STR (F3 ),
96
+ ENUM_TO_STR (F4 ),
92
97
ENUM_TO_STR (USER_BUTTON_MAX ),
93
98
};
94
99
@@ -102,17 +107,17 @@ static uint8_t common_btn_read(void *arg)
102
107
103
108
switch (btn -> id )
104
109
{
105
- case USER_BUTTON_0 :
106
- value = HAL_GPIO_ReadPin (PORT_KEY1 , PIN_KEY1 );
107
- break ;
108
110
case USER_BUTTON_1 :
109
- value = HAL_GPIO_ReadPin (PORT_KEY2 , PIN_KEY2 ); ;
111
+ value = HAL_GPIO_ReadPin (PORT_KEY1 , PIN_KEY1 ) ;
110
112
break ;
111
113
case USER_BUTTON_2 :
112
- value = HAL_GPIO_ReadPin (PORT_KEY3 , PIN_KEY3 ); ;
114
+ value = HAL_GPIO_ReadPin (PORT_KEY2 , PIN_KEY2 ) ;
113
115
break ;
114
116
case USER_BUTTON_3 :
115
- value = HAL_GPIO_ReadPin (PORT_KEY4 , PIN_KEY4 );;
117
+ value = HAL_GPIO_ReadPin (PORT_KEY3 , PIN_KEY3 );
118
+ break ;
119
+ case USER_BUTTON_4 :
120
+ value = HAL_GPIO_ReadPin (PORT_KEY4 , PIN_KEY4 );
116
121
break ;
117
122
default :
118
123
break ;
@@ -130,9 +135,10 @@ static void common_btn_evt_cb(void *arg)
130
135
btn -> event , enum_event_string [btn -> event ],
131
136
btn -> click_cnt );
132
137
133
- if (flex_button_event_read (& user_button [USER_BUTTON_0 ]) == flex_button_event_read (& user_button [USER_BUTTON_1 ]) == FLEX_BTN_PRESS_CLICK )
138
+ if ((flex_button_event_read (& user_button [USER_BUTTON_1 ]) == FLEX_BTN_PRESS_CLICK ) && \
139
+ (flex_button_event_read (& user_button [USER_BUTTON_2 ]) == FLEX_BTN_PRESS_CLICK ))
134
140
{
135
- printf ("[combination]: button 0 and button 1 \r\n" );
141
+ printf ("[combination]: button 1 and button 2 \r\n" );
136
142
}
137
143
}
138
144
@@ -155,12 +161,12 @@ static void user_button_init(void)
155
161
__HAL_RCC_GPIOB_CLK_ENABLE ();
156
162
__HAL_RCC_GPIOC_CLK_ENABLE ();
157
163
158
- GPIO_InitStruct .Pin = PIN_KEY1 | PIN_KEY2 | PIN_KEY4 ;
164
+ GPIO_InitStruct .Pin = PIN_KEY1 | PIN_KEY3 | PIN_KEY4 ;
159
165
GPIO_InitStruct .Mode = GPIO_MODE_INPUT ;
160
166
GPIO_InitStruct .Pull = GPIO_PULLUP ;
161
167
HAL_GPIO_Init (GPIOB , & GPIO_InitStruct );
162
168
163
- GPIO_InitStruct .Pin = PIN_KEY3 ;
169
+ GPIO_InitStruct .Pin = PIN_KEY2 ;
164
170
GPIO_InitStruct .Mode = GPIO_MODE_INPUT ;
165
171
GPIO_InitStruct .Pull = GPIO_PULLUP ;
166
172
HAL_GPIO_Init (GPIOC , & GPIO_InitStruct );
@@ -179,6 +185,12 @@ static void user_button_init(void)
179
185
}
180
186
}
181
187
188
+ /**
189
+ * flex_button_main
190
+ *
191
+ * @brief please call this function in application.
192
+ *
193
+ */
182
194
int flex_button_main (void )
183
195
{
184
196
user_button_init ();
0 commit comments