Skip to content

嵌入式模块架构#63

Draft
0x1abin wants to merge 5 commits intomasterfrom
cursor/-bc-b391493b-7542-44c8-8217-18c799b789a0-dba5
Draft

嵌入式模块架构#63
0x1abin wants to merge 5 commits intomasterfrom
cursor/-bc-b391493b-7542-44c8-8217-18c799b789a0-dba5

Conversation

@0x1abin
Copy link
Owner

@0x1abin 0x1abin commented Feb 25, 2026

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_t to prevent overflow, isolating configuration via BTN_USER_CFG_FILE, adding void *user_data for context, introducing proper include/ and src/ directory structure, improving const correctness, exposing button_tick_single(), and adding CMake build support.


Open in Web Open in Cursor 

cursoragent and others added 5 commits February 25, 2026 13:12
- 新增 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
Copy link

cursor bot commented Feb 25, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants