|
|
@@ -1,5 +1,5 @@
|
|
|
/**
|
|
|
- * @File: flexible_button_demo.c
|
|
|
+ * @File: demo_tos_evb_mx_plus.c
|
|
|
* @Author: MurphyZhao
|
|
|
* @Date: 2018-09-29
|
|
|
*
|
|
|
@@ -20,17 +20,22 @@
|
|
|
* See the License for the specific language governing permissions and
|
|
|
* limitations under the License.
|
|
|
*
|
|
|
+ * message:
|
|
|
+ * This demo is base on TencentOSTiny EVB_MX+, reference
|
|
|
+ * https://github.com/Tencent/TencentOS-tiny
|
|
|
+ * Hardware: TencentOSTiny EVB_MX+.
|
|
|
+ *
|
|
|
* Change logs:
|
|
|
* Date Author Notes
|
|
|
- * 2018-09-29 MurphyZhao First add
|
|
|
- * 2019-08-02 MurphyZhao Migrate code to github.com/murphyzhao account
|
|
|
+ * 2020-01-20 MurphyZhao First add
|
|
|
+ * 2020-02-14 MurphyZhao Fix Key mismatch problem and fix grammar bug
|
|
|
*/
|
|
|
|
|
|
+#include "stdio.h"
|
|
|
#include "mcu_init.h"
|
|
|
#include "cmsis_os.h"
|
|
|
|
|
|
-#include "stm32l4xx_hal.h"
|
|
|
-#include "stdio.h"
|
|
|
+#include "main.h"
|
|
|
|
|
|
#include "flexible_button.h"
|
|
|
|
|
|
@@ -38,34 +43,34 @@
|
|
|
static void button_scan(void *arg);
|
|
|
osThreadDef(button_scan, osPriorityNormal, 1, FLEXIBLE_BTN_STK_SIZE);
|
|
|
|
|
|
-#ifndef PIN_KEY1
|
|
|
-#define PORT_KEY1 GPIOB
|
|
|
-#define PIN_KEY1 GPIO_PIN_12 // PB12
|
|
|
+#ifndef PIN_KEY4
|
|
|
+#define PORT_KEY4 GPIOB
|
|
|
+#define PIN_KEY4 GPIO_PIN_12 // PB12
|
|
|
#endif
|
|
|
|
|
|
-#ifndef PIN_KEY2
|
|
|
-#define PORT_KEY2 GPIOB
|
|
|
-#define PIN_KEY2 GPIO_PIN_2 // PB2
|
|
|
+#ifndef PIN_KEY3
|
|
|
+#define PORT_KEY3 GPIOB
|
|
|
+#define PIN_KEY3 GPIO_PIN_2 // PB2
|
|
|
#endif
|
|
|
|
|
|
-#ifndef PIN_KEY3
|
|
|
-#define PORT_KEY3 GPIOC
|
|
|
-#define PIN_KEY3 GPIO_PIN_10 // PC10
|
|
|
+#ifndef PIN_KEY2
|
|
|
+#define PORT_KEY2 GPIOC
|
|
|
+#define PIN_KEY2 GPIO_PIN_10 // PC10
|
|
|
#endif
|
|
|
|
|
|
-#ifndef PIN_KEY4
|
|
|
-#define PORT_KEY4 GPIOB
|
|
|
-#define PIN_KEY4 GPIO_PIN_13 // PB13
|
|
|
+#ifndef PIN_KEY1
|
|
|
+#define PORT_KEY1 GPIOB
|
|
|
+#define PIN_KEY1 GPIO_PIN_13 // PB13
|
|
|
#endif
|
|
|
|
|
|
#define ENUM_TO_STR(e) (#e)
|
|
|
|
|
|
typedef enum
|
|
|
{
|
|
|
- USER_BUTTON_0 = 0,
|
|
|
- USER_BUTTON_1,
|
|
|
+ USER_BUTTON_1 = 0,
|
|
|
USER_BUTTON_2,
|
|
|
USER_BUTTON_3,
|
|
|
+ USER_BUTTON_4,
|
|
|
USER_BUTTON_MAX
|
|
|
} user_button_t;
|
|
|
|
|
|
@@ -85,10 +90,10 @@ static char *enum_event_string[] = {
|
|
|
};
|
|
|
|
|
|
static char *enum_btn_id_string[] = {
|
|
|
- ENUM_TO_STR(USER_BUTTON_0),
|
|
|
- ENUM_TO_STR(USER_BUTTON_1),
|
|
|
- ENUM_TO_STR(USER_BUTTON_2),
|
|
|
- ENUM_TO_STR(USER_BUTTON_3),
|
|
|
+ ENUM_TO_STR(F1),
|
|
|
+ ENUM_TO_STR(F2),
|
|
|
+ ENUM_TO_STR(F3),
|
|
|
+ ENUM_TO_STR(F4),
|
|
|
ENUM_TO_STR(USER_BUTTON_MAX),
|
|
|
};
|
|
|
|
|
|
@@ -102,17 +107,17 @@ static uint8_t common_btn_read(void *arg)
|
|
|
|
|
|
switch (btn->id)
|
|
|
{
|
|
|
- case USER_BUTTON_0:
|
|
|
- value = HAL_GPIO_ReadPin(PORT_KEY1, PIN_KEY1);
|
|
|
- break;
|
|
|
case USER_BUTTON_1:
|
|
|
- value = HAL_GPIO_ReadPin(PORT_KEY2, PIN_KEY2);;
|
|
|
+ value = HAL_GPIO_ReadPin(PORT_KEY1, PIN_KEY1);
|
|
|
break;
|
|
|
case USER_BUTTON_2:
|
|
|
- value = HAL_GPIO_ReadPin(PORT_KEY3, PIN_KEY3);;
|
|
|
+ value = HAL_GPIO_ReadPin(PORT_KEY2, PIN_KEY2);
|
|
|
break;
|
|
|
case USER_BUTTON_3:
|
|
|
- value = HAL_GPIO_ReadPin(PORT_KEY4, PIN_KEY4);;
|
|
|
+ value = HAL_GPIO_ReadPin(PORT_KEY3, PIN_KEY3);
|
|
|
+ break;
|
|
|
+ case USER_BUTTON_4:
|
|
|
+ value = HAL_GPIO_ReadPin(PORT_KEY4, PIN_KEY4);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
@@ -130,9 +135,10 @@ static void common_btn_evt_cb(void *arg)
|
|
|
btn->event, enum_event_string[btn->event],
|
|
|
btn->click_cnt);
|
|
|
|
|
|
- if (flex_button_event_read(&user_button[USER_BUTTON_0]) == flex_button_event_read(&user_button[USER_BUTTON_1]) == FLEX_BTN_PRESS_CLICK)
|
|
|
+ if ((flex_button_event_read(&user_button[USER_BUTTON_1]) == FLEX_BTN_PRESS_CLICK) &&\
|
|
|
+ (flex_button_event_read(&user_button[USER_BUTTON_2]) == FLEX_BTN_PRESS_CLICK))
|
|
|
{
|
|
|
- printf("[combination]: button 0 and button 1\r\n");
|
|
|
+ printf("[combination]: button 1 and button 2\r\n");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -155,12 +161,12 @@ static void user_button_init(void)
|
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
|
|
|
|
- GPIO_InitStruct.Pin = PIN_KEY1 | PIN_KEY2 | PIN_KEY4;
|
|
|
+ GPIO_InitStruct.Pin = PIN_KEY1 | PIN_KEY3 | PIN_KEY4;
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
|
|
- GPIO_InitStruct.Pin = PIN_KEY3;
|
|
|
+ GPIO_InitStruct.Pin = PIN_KEY2;
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
|
@@ -179,6 +185,12 @@ static void user_button_init(void)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * flex_button_main
|
|
|
+ *
|
|
|
+ * @brief please call this function in application.
|
|
|
+ *
|
|
|
+*/
|
|
|
int flex_button_main(void)
|
|
|
{
|
|
|
user_button_init();
|