Skip to content

Commit

Permalink
[fix] fix grammar bug, and fix tencent evb mx+ key mismatch problem
Browse files Browse the repository at this point in the history
[update] change dirs and add examples directory

Signed-off-by: MurphyZhao <[email protected]>
  • Loading branch information
murphyzhao committed Feb 15, 2020
1 parent fb041f3 commit 0e2eb6a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 38 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 库源码和例程加入你既有的工程下即可。

Expand Down Expand Up @@ -294,7 +294,7 @@ void flex_button_scan(void);
### 关于组合按键
该按键库仅做了底层的按键扫描处理,一次扫描可以确定所有的按键状态,并上报对应的按键事件,如果需要支持组合按键,请再封一层,根据按键库返回的事件封装需要的组合按键。[示例程序](./flexible_button_demo.c)提供了简单的实现。
该按键库仅做了底层的按键扫描处理,一次扫描可以确定所有的按键状态,并上报对应的按键事件,如果需要支持组合按键,请再封一层,根据按键库返回的事件封装需要的组合按键。[示例程序](./examples/demo_rtt_iotboard.c)提供了简单的实现。
### 关于矩阵键盘
Expand Down
2 changes: 1 addition & 1 deletion SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
11 changes: 9 additions & 2 deletions flexible_button_demo.c → examples/demo_rtt_iotboard.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @File: flexible_button_demo.c
* @File: demo_rtt_iotboard.c
* @Author: MurphyZhao
* @Date: 2018-09-29
*
Expand All @@ -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>
Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @File: flexible_button_demo.c
* @File: demo_tos_evb_mx_plus.c
* @Author: MurphyZhao
* @Date: 2018-09-29
*
Expand All @@ -20,52 +20,57 @@
* 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"

#define FLEXIBLE_BTN_STK_SIZE 512
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;

Expand All @@ -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),
};

Expand All @@ -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;
Expand All @@ -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");
}
}

Expand All @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit 0e2eb6a

Please sign in to comment.