From 19ae09e9d9c15925936c0bcc0ab649d123a73c2c Mon Sep 17 00:00:00 2001 From: CoderNotCute <30313912+smartmx@users.noreply.github.com> Date: Tue, 4 Jul 2023 07:55:44 +0800 Subject: [PATCH] fix some bugs --- examples/mfbd_demo_rtt.c | 89 ++++++++++++++++++++++++++++++++++++++++ mfbd_sd.h | 31 ++++++++------ 2 files changed, 107 insertions(+), 13 deletions(-) diff --git a/examples/mfbd_demo_rtt.c b/examples/mfbd_demo_rtt.c index b40df67..23c6c9e 100644 --- a/examples/mfbd_demo_rtt.c +++ b/examples/mfbd_demo_rtt.c @@ -10,12 +10,14 @@ * 2022-04-16 smartmx drop list definitions, use arraylist, each group has all btn types. * 2022-08-05 smartmx add reset params function. * 2022-08-15 smartmx fix bugs. + * 2023-07-03 smartmx add Section Definition option. * */ #include #include #include "mfbd.h" +#include "mfbd_sd.h" void bsp_btn_value_report(mfbd_btn_code_t btn_value); unsigned char bsp_btn_check(mfbd_btn_index_t btn_index); @@ -36,6 +38,81 @@ unsigned char bsp_btn_check(mfbd_btn_index_t btn_index); #define BTN_WK_UP GET_PIN(A, 0) #endif +#if MFBD_USE_SECTION_DEFINITION +/* use section definition. */ + +#if MFBD_PARAMS_SAME_IN_GROUP + +/* tbtn test */ +#if MFBD_USE_TINY_BUTTON +/* MFBD_TBTN_DEFINE(NAME, BTN_INDEX, FILTER_TIME, BTN_DOWN_CODE, BTN_UP_CODE) */ +MFBD_TBTN_DEFINE(test_btns, test_tbtn, 1, 0x1201, 0x1200); +#endif /* MFBD_USE_TINY_BUTTON */ + +/* nbtn test */ +#if MFBD_USE_NORMAL_BUTTON +/* MFBD_NBTN_DEFINE(NAME, BTN_INDEX, BTN_DOWN_CODE, BTN_UP_CODE, BTN_LONG_CODE) */ +MFBD_NBTN_DEFINE(test_btns, test_nbtn1, 3, 0x1401, 0x1400, 0x1402); + +MFBD_NBTN_DEFINE(test_btns, test_nbtn, 2, 0x1301, 0x1300, 0x1301); +#endif /* MFBD_USE_NORMAL_BUTTON */ + +/* mbtn test */ +#if MFBD_USE_MULTIFUCNTION_BUTTON +/* MFBD_MBTN_DEFINE(NAME, BTN_INDEX, MAX_MULTICLICK_STATE, BTN_DOWN_CODE, BTN_UP_CODE, BTN_LONG_CODE, ...) */ +MFBD_MBTN_DEFINE(test_btns, test_mbtn, 4, 3, 0x1501, 0x1500, 0x1501, 0x1511, 0x1521, 0x1531); +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ + +#else + +/* tbtn test */ +#if MFBD_USE_TINY_BUTTON +/* MFBD_TBTN_DEFINE(NAME, BTN_INDEX, FILTER_TIME, BTN_DOWN_CODE, BTN_UP_CODE) */ +MFBD_TBTN_DEFINE(test_btns, test_tbtn, 1, 3, 0x1201, 0x1200); +#endif /* MFBD_USE_TINY_BUTTON */ + +/* nbtn test */ +#if MFBD_USE_NORMAL_BUTTON +/* MFBD_NBTN_DEFINE(NAME, BTN_INDEX, FILTER_TIME, REPEAT_TIME, LONG_TIME, BTN_DOWN_CODE, BTN_UP_CODE, BTN_LONG_CODE) */ +MFBD_NBTN_DEFINE(test_btns, test_nbtn1, 3, 3, 0, 150, 0x1401, 0x1400, 0x1402); + +MFBD_NBTN_DEFINE(test_btns, test_nbtn, 2, 3, 30, 150, 0x1301, 0x1300, 0x1301); +#endif /* MFBD_USE_NORMAL_BUTTON */ + +/* mbtn test */ +#if MFBD_USE_MULTIFUCNTION_BUTTON +/* MFBD_MBTN_DEFINE(NAME, BTN_INDEX, FILTER_TIME, REPEAT_TIME, LONG_TIME, MULTICLICK_TIME, MAX_MULTICLICK_STATE, BTN_DOWN_CODE, BTN_UP_CODE, BTN_LONG_CODE, ...) */ +MFBD_MBTN_DEFINE(test_btns, test_mbtn, 4, 3, 30, 150, 75, 3, 0x1501, 0x1500, 0x1501, 0x1511, 0x1521, 0x1531); +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ + +#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ + +//MFBD_GROUP_DEFINE(test_btns, bsp_btn_check, bsp_btn_value_report, 3, 30, 150, 75); +//MFBD_GROUP_DEFINE(test_btns, bsp_btn_check, bsp_btn_value_report); + +const mfbd_group_t MFBD_GROUP_NAME(test_btns) = { + bsp_btn_check, + bsp_btn_value_report, +#if MFBD_PARAMS_SAME_IN_GROUP + +#if MFBD_USE_TINY_BUTTON || MFBD_USE_NORMAL_BUTTON || MFBD_USE_MULTIFUCNTION_BUTTON + 3, +#endif /* MFBD_USE_TINY_BUTTON || MFBD_USE_NORMAL_BUTTON || MFBD_USE_MULTIFUCNTION_BUTTON */ + +#if MFBD_USE_NORMAL_BUTTON || MFBD_USE_MULTIFUCNTION_BUTTON + 30, + 150, +#endif /* MFBD_USE_NORMAL_BUTTON || MFBD_USE_MULTIFUCNTION_BUTTON */ + +#if MFBD_USE_MULTIFUCNTION_BUTTON + 75, +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ + +#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +}; + +#else + #if MFBD_PARAMS_SAME_IN_GROUP /* tbtn test */ @@ -130,6 +207,8 @@ const mfbd_group_t test_btn_group = }; +#endif /*MFBD_USE_SECTION_DEFINITION*/ + unsigned char bsp_btn_check(mfbd_btn_index_t btn_index) { switch (btn_index) @@ -173,7 +252,17 @@ static void mfbd_scan(void *arg) { while (1) { + #if MFBD_USE_SECTION_DEFINITION + /* use section definition. */ + + MFBD_GROUP_SCAN(test_btns); + + #else + mfbd_group_scan(&test_btn_group); /* scan button group */ + + #endif /*MFBD_USE_SECTION_DEFINITION*/ + rt_thread_mdelay(10); /* scan period: 10ms */ } } diff --git a/mfbd_sd.h b/mfbd_sd.h index 740b503..0d416f3 100644 --- a/mfbd_sd.h +++ b/mfbd_sd.h @@ -460,14 +460,14 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd { \ extern const int MFBD_SECTION_START(GROUP, tbtn); \ extern const int MFBD_SECTION_END(GROUP, tbtn); \ - mfbd_tbtn_scan(&(MFBD_GROUP_NAME(GROUP)), &(MFBD_SECTION_START(GROUP, tbtn)), &(MFBD_SECTION_END(GROUP, tbtn))); \ + mfbd_tbtn_scan((const mfbd_group_t *)&(MFBD_GROUP_NAME(GROUP)), (const mfbd_tbtn_info_t *)&(MFBD_SECTION_START(GROUP, tbtn)), (const mfbd_tbtn_info_t *)&(MFBD_SECTION_END(GROUP, tbtn))); \ } while (0) #define MFBD_GROUP_RESET_TBTN(GROUP) \ do \ { \ extern const int MFBD_SECTION_START(GROUP, tbtn); \ extern const int MFBD_SECTION_END(GROUP, tbtn); \ - mfbd_tbtn_reset(&(MFBD_SECTION_START(GROUP, tbtn)), &(MFBD_SECTION_END(GROUP, tbtn))); \ + mfbd_tbtn_reset((const mfbd_tbtn_info_t *)&(MFBD_SECTION_START(GROUP, tbtn)), (const mfbd_tbtn_info_t *)&(MFBD_SECTION_END(GROUP, tbtn))); \ } while (0) #else #define MFBD_GROUP_SCAN_TBTN(GROUP) do{} while(0) @@ -480,14 +480,14 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd { \ extern const int MFBD_SECTION_START(GROUP, nbtn); \ extern const int MFBD_SECTION_END(GROUP, nbtn); \ - mfbd_nbtn_scan(&(MFBD_GROUP_NAME(GROUP)), &(MFBD_SECTION_START(GROUP, nbtn)), &(MFBD_SECTION_END(GROUP, nbtn))); \ + mfbd_nbtn_scan((const mfbd_group_t *)&(MFBD_GROUP_NAME(GROUP)), (const mfbd_nbtn_info_t *)&(MFBD_SECTION_START(GROUP, nbtn)), (const mfbd_nbtn_info_t *)&(MFBD_SECTION_END(GROUP, nbtn))); \ } while (0) #define MFBD_GROUP_RESET_NBTN(GROUP) \ do \ { \ extern const int MFBD_SECTION_START(GROUP, nbtn); \ extern const int MFBD_SECTION_END(GROUP, nbtn); \ - mfbd_nbtn_reset(&(MFBD_SECTION_START(GROUP, nbtn)), &(MFBD_SECTION_END(GROUP, nbtn))); \ + mfbd_nbtn_reset((const mfbd_nbtn_info_t *)&(MFBD_SECTION_START(GROUP, nbtn)), (const mfbd_nbtn_info_t *)&(MFBD_SECTION_END(GROUP, nbtn))); \ } while (0) #else #define MFBD_GROUP_SCAN_NBTN(GROUP) do{} while(0) @@ -500,14 +500,14 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd { \ extern const int MFBD_SECTION_START(GROUP, mbtn); \ extern const int MFBD_SECTION_END(GROUP, mbtn); \ - mfbd_mbtn_scan(&(MFBD_GROUP_NAME(GROUP)), &(MFBD_SECTION_START(GROUP, mbtn)), &(MFBD_SECTION_END(GROUP, mbtn))); \ + mfbd_mbtn_scan((const mfbd_group_t *)&(MFBD_GROUP_NAME(GROUP)), (const mfbd_mbtn_info_t *)&(MFBD_SECTION_START(GROUP, mbtn)), (const mfbd_mbtn_info_t *)&(MFBD_SECTION_END(GROUP, mbtn))); \ } while (0) #define MFBD_GROUP_RESET_MBTN(GROUP) \ do \ { \ extern const int MFBD_SECTION_START(GROUP, mbtn); \ extern const int MFBD_SECTION_END(GROUP, mbtn); \ - mfbd_mbtn_reset(&(MFBD_SECTION_START(GROUP, mbtn)), &(MFBD_SECTION_END(GROUP, mbtn))); \ + mfbd_mbtn_reset((const mfbd_mbtn_info_t *)&(MFBD_SECTION_START(GROUP, mbtn)), (const mfbd_mbtn_info_t *)&(MFBD_SECTION_END(GROUP, mbtn))); \ } while (0) #else #define MFBD_GROUP_SCAN_MBTN(GROUP) do{} while(0) @@ -520,7 +520,12 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd #define MFBD_GROUP_SCAN_TBTN(GROUP) \ do \ { \ - mfbd_tbtn_scan(&(MFBD_GROUP_NAME(GROUP)), MFBD_SECTION_START(GROUP, tbtn), MFBD_SECTION_END(GROUP, tbtn)); \ + mfbd_tbtn_scan((const mfbd_group_t *)&(MFBD_GROUP_NAME(GROUP)), (const mfbd_tbtn_info_t *)MFBD_SECTION_START(GROUP, tbtn), (const mfbd_tbtn_info_t *)MFBD_SECTION_END(GROUP, tbtn)); \ + } while (0) +#define MFBD_GROUP_RESET_TBTN(GROUP) \ + do \ + { \ + mfbd_tbtn_reset((const mfbd_tbtn_info_t *)MFBD_SECTION_START(GROUP, nbtn), (const mfbd_tbtn_info_t *)MFBD_SECTION_END(GROUP, nbtn)); \ } while (0) #else #define MFBD_GROUP_SCAN_TBTN(GROUP) do{} while(0) @@ -529,12 +534,12 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd #define MFBD_GROUP_SCAN_NBTN(GROUP) \ do \ { \ - mfbd_nbtn_scan(&(MFBD_GROUP_NAME(GROUP)), MFBD_SECTION_START(GROUP, nbtn), MFBD_SECTION_END(GROUP, nbtn)); \ + mfbd_nbtn_scan((const mfbd_group_t *)&(MFBD_GROUP_NAME(GROUP)), (const mfbd_nbtn_info_t *)MFBD_SECTION_START(GROUP, nbtn), (const mfbd_nbtn_info_t *)MFBD_SECTION_END(GROUP, nbtn)); \ } while (0) #define MFBD_GROUP_RESET_NBTN(GROUP) \ do \ { \ - mfbd_nbtn_reset(MFBD_SECTION_START(GROUP, nbtn), MFBD_SECTION_END(GROUP, nbtn)); \ + mfbd_nbtn_reset((const mfbd_nbtn_info_t *)MFBD_SECTION_START(GROUP, nbtn), (const mfbd_nbtn_info_t *)MFBD_SECTION_END(GROUP, nbtn)); \ } while (0) #else #define MFBD_GROUP_SCAN_NBTN(GROUP) do{} while(0) @@ -544,12 +549,12 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd #define MFBD_GROUP_SCAN_MBTN(GROUP) \ do \ { \ - mfbd_mbtn_scan(&(MFBD_GROUP_NAME(GROUP)), MFBD_SECTION_START(GROUP, mbtn), MFBD_SECTION_END(GROUP, mbtn)); \ + mfbd_mbtn_scan((const mfbd_group_t *)&(MFBD_GROUP_NAME(GROUP)), (const mfbd_mbtn_info_t *)MFBD_SECTION_START(GROUP, mbtn), (const mfbd_mbtn_info_t *)MFBD_SECTION_END(GROUP, mbtn)); \ } while (0) #define MFBD_GROUP_RESET_MBTN(GROUP) \ do \ { \ - mfbd_mbtn_reset(MFBD_SECTION_START(GROUP, mbtn), MFBD_SECTION_END(GROUP, mbtn)); \ + mfbd_mbtn_reset((const mfbd_mbtn_info_t *)MFBD_SECTION_START(GROUP, mbtn), (const mfbd_mbtn_info_t *)MFBD_SECTION_END(GROUP, mbtn)); \ } while (0) #else #define MFBD_GROUP_SCAN_MBTN(GROUP) do{} while(0) @@ -632,7 +637,7 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd } \ } while(0) #else -#define MFBD_GROUP_SCAN_AFTER(GROUP) do{} while(0) +#define MFBD_GROUP_SCAN_PREPARE(GROUP) do{} while(0) #endif /* MFBD_USE_BTN_SCAN_PRE_FUNC */ #if MFBD_USE_BTN_SCAN_AFTER_FUNC @@ -645,7 +650,7 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd } \ } while(0) #else -#define MFBD_GROUP_SCAN_AFTER(GROUP) do{} while(0) +#define MFBD_GROUP_SCAN_AFTER(GROUP) do{} while(0) #endif /* MFBD_USE_BTN_SCAN_AFTER_FUNC */ /*