Conversation
- 新增 include/multi_button.h:公共API,button_t类型,uint32_t tick计数器,user_data指针 - 新增 include/multi_button_cfg.h:编译期可覆盖配置(BTN_USER_CFG_FILE支持) - 新增 src/multi_button.c:4状态有限状态机实现(消除原REPEAT状态歧义转换) - 状态机简化为 IDLE→PRESSED→RELEASED→LONG_HOLD,转换逻辑更清晰 - tick计数器从uint16_t升级为uint32_t,消除长时间运行溢出风险 - 新增button_tick_single()支持用户自管理按键集合 - 新增button_get_state()/button_get_id()查询接口,const正确性 - 添加MULTI_BUTTON_VERSION_*版本宏 Co-authored-by: 0x1abin <0x1abin@gmail.com>
Co-authored-by: 0x1abin <0x1abin@gmail.com>
- 使用button_t/button_event_t等新类型命名 - 使用button_tick()替代button_ticks() - basic_example:修复仿真时序,sim_tick保证FSM超时正确触发 - advanced_example:演示user_data上下文传递和动态回调重配置 - poll_example:展示button_get_state()等新查询接口 Co-authored-by: 0x1abin <0x1abin@gmail.com>
- Makefile:适配include/src目录,添加EXTRA_CFLAGS变量支持自定义配置 - 新增CMakeLists.txt:支持CMake构建、安装和作为子项目集成 - .gitignore:添加cmake_build等忽略项 Co-authored-by: 0x1abin <0x1abin@gmail.com>
Co-authored-by: 0x1abin <0x1abin@gmail.com>
|
Cursor Agent can help with this pull request. Just |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor the MultiButton module to improve architecture, simplify the state machine, enhance configurability, and add CMake support.
This refactoring addresses several issues: simplifying the 5-state FSM to a more robust 4-state FSM, upgrading the tick counter to
uint32_tto prevent overflow, isolating configuration viaBTN_USER_CFG_FILE, addingvoid *user_datafor context, introducing properinclude/andsrc/directory structure, improvingconstcorrectness, exposingbutton_tick_single(), and adding CMake build support.