Skip to content

Commit 0e2eb6a

Browse files
committed
[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>
1 parent fb041f3 commit 0e2eb6a

File tree

4 files changed

+57
-38
lines changed

4 files changed

+57
-38
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ARMCC -O0 优化的情况下,FlexibleButton 资源占用如下:
3535

3636
## 快速体验
3737

38-
FlexibleButton 库中提供了一个测试例程 [`./flexible_button_demo.c`](./flexible_button_demo.c),该例程基于 RT-Thread OS 进行测试,硬件平台选择了 *RT-Thread IoT Board Pandora v2.51* 开发板。当然你可以选择使用其他的 OS,或者使用裸机测试,只需要移除 OS 相关的特性即可。
38+
FlexibleButton 库中提供了一个测试例程 [`./examples/demo_rtt_iotboard.c`](./examples/demo_rtt_iotboard.c),该例程基于 RT-Thread OS 进行测试,硬件平台选择了 *RT-Thread IoT Board Pandora v2.51* 开发板。当然你可以选择使用其他的 OS,或者使用裸机测试,只需要移除 OS 相关的特性即可。
3939

4040
如果你使用自己的硬件平台,只需要将 FlexibleButton 库源码和例程加入你既有的工程下即可。
4141

@@ -294,7 +294,7 @@ void flex_button_scan(void);
294294

295295
### 关于组合按键
296296

297-
该按键库仅做了底层的按键扫描处理,一次扫描可以确定所有的按键状态,并上报对应的按键事件,如果需要支持组合按键,请再封一层,根据按键库返回的事件封装需要的组合按键。[示例程序](./flexible_button_demo.c)提供了简单的实现。
297+
该按键库仅做了底层的按键扫描处理,一次扫描可以确定所有的按键状态,并上报对应的按键事件,如果需要支持组合按键,请再封一层,根据按键库返回的事件封装需要的组合按键。[示例程序](./examples/demo_rtt_iotboard.c)提供了简单的实现。
298298

299299
### 关于矩阵键盘
300300

Diff for: SConscript

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ flexible_button.c
1111
''')
1212

1313
if GetDepend(['PKG_USING_FLEXIBLE_BUTTON_DEMO']):
14-
src += Glob("flexible_button_demo.c")
14+
src += Glob("examples/demo_rtt_iotboard.c")
1515

1616
CPPPATH = [cwd]
1717

Diff for: flexible_button_demo.c renamed to examples/demo_rtt_iotboard.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @File: flexible_button_demo.c
2+
* @File: demo_rtt_iotboard.c
33
* @Author: MurphyZhao
44
* @Date: 2018-09-29
55
*
@@ -20,10 +20,16 @@
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 rt-thread IoT Board, reference
25+
* https://github.com/RT-Thread/IoT_Board
26+
* Hardware version: RT-Thread IoT Board Pandora v2.51.
27+
*
2328
* Change logs:
2429
* Date Author Notes
2530
* 2018-09-29 MurphyZhao First add
2631
* 2019-08-02 MurphyZhao Migrate code to github.com/murphyzhao account
32+
* 2020-02-14 MurphyZhao Fix grammar bug
2733
*/
2834

2935
#include <rtthread.h>
@@ -119,7 +125,8 @@ static void common_btn_evt_cb(void *arg)
119125
btn->event, enum_event_string[btn->event],
120126
btn->click_cnt);
121127

122-
if (flex_button_event_read(&user_button[USER_BUTTON_0]) == flex_button_event_read(&user_button[USER_BUTTON_1]) == FLEX_BTN_PRESS_CLICK)
128+
if ((flex_button_event_read(&user_button[USER_BUTTON_0]) == FLEX_BTN_PRESS_CLICK) &&\
129+
(flex_button_event_read(&user_button[USER_BUTTON_1]) == FLEX_BTN_PRESS_CLICK))
123130
{
124131
rt_kprintf("[combination]: button 0 and button 1\n");
125132
}

Diff for: flexible_button_tencentos_tiny_demo.c renamed to examples/demo_tos_evb_mx_plus.c

+45-33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @File: flexible_button_demo.c
2+
* @File: demo_tos_evb_mx_plus.c
33
* @Author: MurphyZhao
44
* @Date: 2018-09-29
55
*
@@ -20,52 +20,57 @@
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
3843
static void button_scan(void *arg);
3944
osThreadDef(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

6368
typedef 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

8792
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),
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+
*/
182194
int flex_button_main(void)
183195
{
184196
user_button_init();

0 commit comments

Comments
 (0)