[fix] fix grammar bug, and fix tencent evb mx+ key mismatch problem

[update] change dirs and add examples directory

Signed-off-by: MurphyZhao <d2014zjt@163.com>
This commit is contained in:
MurphyZhao 2020-02-14 18:25:02 +08:00
parent fb041f30f3
commit 0e2eb6abd5
4 changed files with 58 additions and 39 deletions

View File

@ -35,7 +35,7 @@ ARMCC -O0 优化的情况下FlexibleButton 资源占用如下:
## 快速体验
FlexibleButton 库中提供了一个测试例程 [`./flexible_button_demo.c`](./flexible_button_demo.c),该例程基于 RT-Thread OS 进行测试,硬件平台选择了 *RT-Thread IoT Board Pandora v2.51* 开发板。当然你可以选择使用其他的 OS或者使用裸机测试只需要移除 OS 相关的特性即可。
FlexibleButton 库中提供了一个测试例程 [`./examples/demo_rtt_iotboard.c`](./examples/demo_rtt_iotboard.c),该例程基于 RT-Thread OS 进行测试,硬件平台选择了 *RT-Thread IoT Board Pandora v2.51* 开发板。当然你可以选择使用其他的 OS或者使用裸机测试只需要移除 OS 相关的特性即可。
如果你使用自己的硬件平台,只需要将 FlexibleButton 库源码和例程加入你既有的工程下即可。
@ -294,7 +294,7 @@ void flex_button_scan(void);
### 关于组合按键
该按键库仅做了底层的按键扫描处理,一次扫描可以确定所有的按键状态,并上报对应的按键事件,如果需要支持组合按键,请再封一层,根据按键库返回的事件封装需要的组合按键。[示例程序](./flexible_button_demo.c)提供了简单的实现。
该按键库仅做了底层的按键扫描处理,一次扫描可以确定所有的按键状态,并上报对应的按键事件,如果需要支持组合按键,请再封一层,根据按键库返回的事件封装需要的组合按键。[示例程序](./examples/demo_rtt_iotboard.c)提供了简单的实现。
### 关于矩阵键盘

View File

@ -11,7 +11,7 @@ flexible_button.c
''')
if GetDepend(['PKG_USING_FLEXIBLE_BUTTON_DEMO']):
src += Glob("flexible_button_demo.c")
src += Glob("examples/demo_rtt_iotboard.c")
CPPPATH = [cwd]

View File

@ -1,5 +1,5 @@
/**
* @File: flexible_button_demo.c
* @File: demo_rtt_iotboard.c
* @Author: MurphyZhao
* @Date: 2018-09-29
*
@ -20,10 +20,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* message:
* This demo is base on rt-thread IoT Board, reference
* https://github.com/RT-Thread/IoT_Board
* Hardware version: RT-Thread IoT Board Pandora v2.51.
*
* Change logs:
* Date Author Notes
* 2018-09-29 MurphyZhao First add
* 2019-08-02 MurphyZhao Migrate code to github.com/murphyzhao account
* 2020-02-14 MurphyZhao Fix grammar bug
*/
#include <rtthread.h>
@ -119,7 +125,8 @@ 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_0]) == FLEX_BTN_PRESS_CLICK) &&\
(flex_button_event_read(&user_button[USER_BUTTON_1]) == FLEX_BTN_PRESS_CLICK))
{
rt_kprintf("[combination]: button 0 and button 1\n");
}

View File

@ -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
#endif
#ifndef PIN_KEY2
#define PORT_KEY2 GPIOB
#define PIN_KEY2 GPIO_PIN_2 // PB2
#ifndef PIN_KEY4
#define PORT_KEY4 GPIOB
#define PIN_KEY4 GPIO_PIN_12 // PB12
#endif
#ifndef PIN_KEY3
#define PORT_KEY3 GPIOC
#define PIN_KEY3 GPIO_PIN_10 // PC10
#define PORT_KEY3 GPIOB
#define PIN_KEY3 GPIO_PIN_2 // PB2
#endif
#ifndef PIN_KEY4
#define PORT_KEY4 GPIOB
#define PIN_KEY4 GPIO_PIN_13 // PB13
#ifndef PIN_KEY2
#define PORT_KEY2 GPIOC
#define PIN_KEY2 GPIO_PIN_10 // PC10
#endif
#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:
case USER_BUTTON_1:
value = HAL_GPIO_ReadPin(PORT_KEY1, PIN_KEY1);
break;
case USER_BUTTON_1:
value = HAL_GPIO_ReadPin(PORT_KEY2, PIN_KEY2);;
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();