11/**
2- * @File: flexible_button_demo .c
2+ * @File: demo_tos_evb_mx_plus .c
33 * @Author: MurphyZhao
44 * @Date: 2018-09-29
55 *
2020 * See the License for the specific language governing permissions and
2121 * limitations under the License.
2222 *
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+ *
2328 * Change logs:
2429 * 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
2732*/
2833
34+ #include "stdio.h"
2935#include "mcu_init.h"
3036#include "cmsis_os.h"
3137
32- #include "stm32l4xx_hal.h"
33- #include "stdio.h"
38+ #include "main.h"
3439
3540#include "flexible_button.h"
3641
3742#define FLEXIBLE_BTN_STK_SIZE 512
3843static void button_scan (void * arg );
3944osThreadDef (button_scan , osPriorityNormal , 1 , FLEXIBLE_BTN_STK_SIZE );
4045
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
4449#endif
4550
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
4954#endif
5055
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
5459#endif
5560
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
5964#endif
6065
6166#define ENUM_TO_STR (e ) (#e)
6267
6368typedef enum
6469{
65- USER_BUTTON_0 = 0 ,
66- USER_BUTTON_1 ,
70+ USER_BUTTON_1 = 0 ,
6771 USER_BUTTON_2 ,
6872 USER_BUTTON_3 ,
73+ USER_BUTTON_4 ,
6974 USER_BUTTON_MAX
7075} user_button_t ;
7176
@@ -85,10 +90,10 @@ static char *enum_event_string[] = {
8590};
8691
8792static 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 ),
9297 ENUM_TO_STR (USER_BUTTON_MAX ),
9398};
9499
@@ -102,17 +107,17 @@ static uint8_t common_btn_read(void *arg)
102107
103108 switch (btn -> id )
104109 {
105- case USER_BUTTON_0 :
106- value = HAL_GPIO_ReadPin (PORT_KEY1 , PIN_KEY1 );
107- break ;
108110 case USER_BUTTON_1 :
109- value = HAL_GPIO_ReadPin (PORT_KEY2 , PIN_KEY2 ); ;
111+ value = HAL_GPIO_ReadPin (PORT_KEY1 , PIN_KEY1 ) ;
110112 break ;
111113 case USER_BUTTON_2 :
112- value = HAL_GPIO_ReadPin (PORT_KEY3 , PIN_KEY3 ); ;
114+ value = HAL_GPIO_ReadPin (PORT_KEY2 , PIN_KEY2 ) ;
113115 break ;
114116 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 );
116121 break ;
117122 default :
118123 break ;
@@ -130,9 +135,10 @@ static void common_btn_evt_cb(void *arg)
130135 btn -> event , enum_event_string [btn -> event ],
131136 btn -> click_cnt );
132137
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 ))
134140 {
135- printf ("[combination]: button 0 and button 1 \r\n" );
141+ printf ("[combination]: button 1 and button 2 \r\n" );
136142 }
137143}
138144
@@ -155,12 +161,12 @@ static void user_button_init(void)
155161 __HAL_RCC_GPIOB_CLK_ENABLE ();
156162 __HAL_RCC_GPIOC_CLK_ENABLE ();
157163
158- GPIO_InitStruct .Pin = PIN_KEY1 | PIN_KEY2 | PIN_KEY4 ;
164+ GPIO_InitStruct .Pin = PIN_KEY1 | PIN_KEY3 | PIN_KEY4 ;
159165 GPIO_InitStruct .Mode = GPIO_MODE_INPUT ;
160166 GPIO_InitStruct .Pull = GPIO_PULLUP ;
161167 HAL_GPIO_Init (GPIOB , & GPIO_InitStruct );
162168
163- GPIO_InitStruct .Pin = PIN_KEY3 ;
169+ GPIO_InitStruct .Pin = PIN_KEY2 ;
164170 GPIO_InitStruct .Mode = GPIO_MODE_INPUT ;
165171 GPIO_InitStruct .Pull = GPIO_PULLUP ;
166172 HAL_GPIO_Init (GPIOC , & GPIO_InitStruct );
@@ -179,6 +185,12 @@ static void user_button_init(void)
179185 }
180186}
181187
188+ /**
189+ * flex_button_main
190+ *
191+ * @brief please call this function in application.
192+ *
193+ */
182194int flex_button_main (void )
183195{
184196 user_button_init ();
0 commit comments