目次
STM32移植嵌入式开源按键框架
MultiButton简介
multi_button.c文件
multi_button.h文件
按键变乱
案例利用方法
学习分析
STM32移植嵌入式开源按键框架
本日移植了一款嵌入式按键框架工程MultiButton,MultiButton是一个小巧简朴易用的变乱驱动型按键驱动模块。
Github地点:GitHub - 0x1abin/MultiButton: Button driver for embedded system
现于2024.04.15举行移植,详细就两个文件:multi_button的c文件和h文件。
MultiButton简介
MultiButton 是一个小巧简朴易用的变乱驱动型按键驱动模块,可无穷量扩展按键,按键变乱的回调异步处置惩罚方式可以简化你的步调布局,去除冗余的按键处置惩罚硬编码,让你的按键业务逻辑更清楚。
multi_button.c文件
把license内容放到代码首段。
- /*
- * MIT License
- * Copyright (c) 2018 Zibin Zheng
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
- /* github:https://github.com/0x1abin/MultiButton */
- #include "driver_button.h"
- #define EVENT_CB(ev) if(handle->cb[ev])handle->cb[ev]((void*)handle)
- #define PRESS_REPEAT_MAX_NUM 15 /*!< The maximum value of the repeat counter */
- //button handle list head.
- static struct Button* head_handle = NULL;
- static void button_handler(struct Button* handle);
- /**
- * @brief Initializes the button struct handle.
- * @param handle: the button handle struct.
- * @param pin_level: read the HAL GPIO of the connected button level.
- * @param active_level: pressed GPIO level.
- * @param button_id: the button id.
- * @retval None
- */
- void button_init(struct Button* handle, uint8_t(*pin_level)(uint8_t), uint8_t active_level, uint8_t
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!qidao123.com:ToB企服之家,中国第一个企服评测及软件市场,开放入驻,技术点评得现金 |