├── LICENSE ├── README.md ├── SConscript ├── button.c ├── button.h ├── debug.h ├── include.h ├── main.c ├── png ├── 1.png ├── 10.png ├── 11.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png └── 9.png └── redef.h /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ButtonDrive 2 | 自己写的一个按键驱动,支持单双击、连按、长按;采用回调处理按键事件(自定义消抖时间),使用只需3步,创建按键,按键事件与回调处理函数链接映射,周期检查按键。 3 | 源码地址:[https://github.com/jiejieTop/ButtonDrive](https://github.com/jiejieTop/ButtonDrive) 4 | 5 | ## 版权和许可 6 | 7 | ButtonDrive 遵循 [Apache License v2.0](https://github.com/jiejieTop/mqttclient/blob/master/LICENSE) 开源许可协议,可以免费在商业产品中使用,并且不需要公开私有代码。 8 | 9 | [Apache License v2.0](https://github.com/jiejieTop/mqttclient/blob/master/LICENSE) 鼓励代码共享和尊重原作者的著作权,可以自由的使用,修改源代码,也可以将修改后的代码作为开源或者专有软件再发布(作为开源或闭源商业软件),但必须根据协议保留原作者版权声明。 10 | 11 | ## 前言 12 | 前几天写了个按键驱动,参考了[MulitButton](https://github.com/0x1abin/MultiButton)的数据结构的用法,逻辑实现并不一样。 13 | 在这里感谢所有的开源开发者,让我从中学到了很多,同时网络也是一个好平台,也希望所有的开发者能形成良性循环,从网络中学知识,回馈到网络中去。感谢[MulitButton](https://github.com/0x1abin/MultiButton)的作者[0x1abin](https://github.com/0x1abin),感谢两位rtt的大佬:[大法师](https://github.com/uestczyh222)、[流光](https://github.com/liu2guang)。 14 | ## Button_drive简介 15 | Button_drive是一个小巧的按键驱动,支持单击、双击、长按、连续触发等(后续可以在按键控制块中添加触发事件),理论上可无限量扩展Button,Button_drive采用按键触发事件回调方式处理业务逻辑,支持在RTOS中使用,我目前仅在[RT-Thread](https://github.com/RT-Thread/rt-thread)上测试过。 16 | 写按键驱动的目的是想要将用户按键逻辑与按键处理事件分离,用户无需处理复杂麻烦的逻辑事件。 17 | 18 | ## Button_drive使用效果 19 | 1. **单击与长按** 20 | 21 | ![单击与长按](png/1.png) 22 | 23 | 2. **双击** 24 | 25 | ![双击](png/2.png) 26 | 27 | 3. **连按** 28 | 29 | ![连按](png/3.png) 30 | 31 | 4. **连按释放** 32 | 33 | ![连按释放](png/4.png) 34 | 35 | ## 使用方法 36 | 1. 创建按键句柄 37 | ```c 38 | Button_t Button1; 39 | Button_t Button2; 40 | ``` 41 | 2. 创建按键,初始化按键信息,包括按键名字、按键电平检测函数接口、按键触发电平。 42 | ```c 43 | Button_Create("Button1", //按键名字 44 | &Button1, //按键句柄 45 | Read_Button1_Level, //按键电平检测函数接口 46 | BTN_TRIGGER); //触发电平 47 | 48 | ...... 49 | ``` 50 | 3. 按键触发事件与事件回调函数链接映射,当按键事件被触发的时候,自动跳转回调函数中处理业务逻辑。 51 | ```c 52 | Button_Attach(&Button1,BUTTON_DOWM,Btn2_Dowm_CallBack); //按键单击 53 | Button_Attach(&Button1,BUTTON_DOUBLE,Btn2_Double_CallBack); //双击 54 | Button_Attach(&Button1,BUTTON_LONG,Btn2_Long_CallBack); //长按 55 | 56 | ....... 57 | ``` 58 | 4. 周期调用回调按键处理函数即可,建议调用周期20-50ms。 59 | ```c 60 | Button_Process(); //需要周期调用按键处理函数 61 | ``` 62 | 63 | --- 64 | 需要用户实现的 **2** 个函数: 65 | 66 | - 按键电平检测接口: 67 | ```c 68 | uint8_t Read_Button1_Level(void) 69 | { 70 | return GPIO_ReadInputDataBit(BTN1_GPIO_PORT,BTN1_GPIO_PIN); 71 | } 72 | 73 | uint8_t Read_Button2_Level(void) 74 | { 75 | return GPIO_ReadInputDataBit(BTN2_GPIO_PORT,BTN2_GPIO_PIN); 76 | } 77 | 78 | // 这是我在stm32上简单测试的伪代码,以实际源码为准 79 | 80 | ``` 81 | 82 | - 按键逻辑处理 83 | ```c 84 | void Btn1_Dowm_CallBack(void *btn) 85 | { 86 | PRINT_INFO("Button1 单击!"); 87 | } 88 | 89 | void Btn1_Double_CallBack(void *btn) 90 | { 91 | PRINT_INFO("Button1 双击!"); 92 | } 93 | 94 | void Btn1_Long_CallBack(void *btn) 95 | { 96 | PRINT_INFO("Button1 长按!"); 97 | 98 | Button_Delete(&Button2); 99 | PRINT_INFO("删除Button1"); 100 | Search_Button(); 101 | } 102 | ``` 103 | 104 | ## 特点 105 | Button_drive开放源码,按键控制块采用数据结构方式,按键事件采用枚举类型,确保不会重复,也便于添加用户需要逻辑,采用宏定义方式定义消抖时间、连按触发时间、双击时间间隔、长按时间等,便于修改。 106 | 同时所有被创建的按键采用单链表方式连击,用户只管创建,无需理会按键处理,只需调用`Button_Process()`即可,在函数中会自动遍历所有被创建的按键。 107 | 支持按键删除操作,用户无需在代码中删除对应的按键创建于映射链接代码,也无需删除关于按键的任何回调事件处理函数,只需调用`Button_Delete()`函数即可,这样子,就不会处理关于被删除按键的任何状态。当然目前按键内存不会释放,如果使用os的话,建议释放按键内存。 108 | ##### 按键控制块 109 | ```c 110 | /* 111 | 每个按键对应1个全局的结构体变量。 112 | 其成员变量是实现消抖和多种按键状态所必须的 113 | */ 114 | typedef struct button 115 | { 116 | /* 下面是一个函数指针,指向判断按键手否按下的函数 */ 117 | uint8_t (*Read_Button_Level)(void); /* 读取按键电平函数,需要用户实现 */ 118 | 119 | char Name[BTN_NAME_MAX]; 120 | 121 | uint8_t Button_State : 4; /* 按键当前状态(按下还是弹起) */ 122 | uint8_t Button_Last_State : 4; /* 上一次的按键状态,用于判断双击 */ 123 | uint8_t Button_Trigger_Level : 2; /* 按键触发电平 */ 124 | uint8_t Button_Last_Level : 2; /* 按键当前电平 */ 125 | 126 | uint8_t Button_Trigger_Event; /* 按键触发事件,单击,双击,长按等 */ 127 | 128 | Button_CallBack CallBack_Function[number_of_event]; 129 | uint8_t Button_Cycle; /* 连续按键周期 */ 130 | 131 | uint8_t Timer_Count; /* 计时 */ 132 | uint8_t Debounce_Time; /* 消抖时间 */ 133 | 134 | uint8_t Long_Time; /* 按键按下持续时间 */ 135 | 136 | struct button *Next; 137 | 138 | }Button_t; 139 | 140 | ``` 141 | ##### 触发事件 142 | ```c 143 | typedef enum { 144 | BUTTON_DOWM = 0, 145 | BUTTON_UP, 146 | BUTTON_DOUBLE, 147 | BUTTON_LONG, 148 | BUTTON_CONTINUOS, 149 | BUTTON_CONTINUOS_FREE, 150 | BUTTON_ALL_RIGGER, 151 | number_of_event, /* 触发回调的事件 */ 152 | NONE_TRIGGER 153 | }Button_Event; 154 | 155 | ``` 156 | ##### 宏定义选择 157 | ```c 158 | #define BTN_NAME_MAX 32 //名字最大为32字节 159 | 160 | /* 按键消抖时间40ms, 建议调用周期为20ms 161 | 只有连续检测到40ms状态不变才认为有效,包括弹起和按下两种事件 162 | */ 163 | 164 | #define CONTINUOS_TRIGGER 0 //是否支持连续触发,连发的话就不要检测单双击与长按了 165 | 166 | /* 是否支持单击&双击同时存在触发,如果选择开启宏定义的话,单双击都回调,只不过单击会延迟响应, 167 | 因为必须判断单击之后是否触发了双击否则,延迟时间是双击间隔时间 BUTTON_DOUBLE_TIME。 168 | 而如果不开启这个宏定义,建议工程中只存在单击/双击中的一个,否则,在双击响应的时候会触发一次单击, 169 | 因为双击必须是有一次按下并且释放之后才产生的 */ 170 | #define SINGLE_AND_DOUBLE_TRIGGER 1 171 | 172 | /* 是否支持长按释放才触发,如果打开这个宏定义,那么长按释放之后才触发单次长按, 173 | 否则在长按指定时间就一直触发长按,触发周期由 BUTTON_LONG_CYCLE 决定 */ 174 | #define LONG_FREE_TRIGGER 0 175 | 176 | #define BUTTON_DEBOUNCE_TIME 2 //消抖时间 (n-1)*调用周期 177 | #define BUTTON_CONTINUOS_CYCLE 1 //连按触发周期时间 (n-1)*调用周期 178 | #define BUTTON_LONG_CYCLE 1 //长按触发周期时间 (n-1)*调用周期 179 | #define BUTTON_DOUBLE_TIME 15 //双击间隔时间 (n-1)*调用周期 建议在200-600ms 180 | #define BUTTON_LONG_TIME 50 /* 持续n秒((n-1)*调用周期 ms),认为长按事件 */ 181 | 182 | #define TRIGGER_CB(event) \ 183 | if(btn->CallBack_Function[event]) \ 184 | btn->CallBack_Function[event]((Button_t*)btn) 185 | ``` 186 | 187 | ##### 例子 188 | ```c 189 | Button_Create("Button1", 190 | &Button1, 191 | Read_KEY1_Level, 192 | KEY_ON); 193 | Button_Attach(&Button1,BUTTON_DOWM,Btn1_Dowm_CallBack); //单击 194 | Button_Attach(&Button1,BUTTON_DOUBLE,Btn1_Double_CallBack); //双击 195 | Button_Attach(&Button1,BUTTON_CONTINUOS,Btn1_Continuos_CallBack); //连按 196 | Button_Attach(&Button1,BUTTON_CONTINUOS_FREE,Btn1_ContinuosFree_CallBack); //连按释放 197 | Button_Attach(&Button1,BUTTON_LONG,Btn1_Long_CallBack); //长按 198 | 199 | 200 | Button_Create("Button2", 201 | &Button2, 202 | Read_KEY2_Level, 203 | KEY_ON); 204 | Button_Attach(&Button2,BUTTON_DOWM,Btn2_Dowm_CallBack); //单击 205 | Button_Attach(&Button2,BUTTON_DOUBLE,Btn2_Double_CallBack); //双击 206 | Button_Attach(&Button2,BUTTON_CONTINUOS,Btn2_Continuos_CallBack); //连按 207 | Button_Attach(&Button2,BUTTON_CONTINUOS_FREE,Btn2_ContinuosFree_CallBack); //连按释放 208 | Button_Attach(&Button2,BUTTON_LONG,Btn2_Long_CallBack); //长按 209 | 210 | Get_Button_Event(&Button1); 211 | Get_Button_Event(&Button2); 212 | ``` 213 | 214 | 215 | ## 后续 216 | [流光](https://github.com/liu2guang)大佬的要求,让我玩一玩RTT的[rtkpgs](https://github.com/liu2guang/buildpkg),打算用Button_drive练一练手吧。 217 | 218 | ## ButtonDrive在env使用 219 | 目前我已将按键驱动做成软件包(packages),如果使用RT-Thread操作系统的话,可以在env中直接配置使用! 220 | 221 | 步骤如下: 222 | 223 | 1. **选择在线软件包** 224 | 225 | ![](png/5.png) 226 | 227 | 2. **选择软件包属性为外设相关** 228 | 229 | ![](png/6.png) 230 | 231 | 3. **选择button_drive** 232 | 233 | ![](png/7.png) 234 | 235 | 4. **进入驱动的选项配置(自带默认属性)** 236 | 237 | ![](png/8.png) 238 | 239 | 5. **如果不懂按键的配置是什么意思,按下“shift+?”,即可有解释** 240 | 241 | ![](png/9.png) 242 | 243 | 6. **编译生成mdk/iar工程** 244 | 245 | ![](png/10.png) 246 | 247 | ![](png/11.png) 248 | -------------------------------------------------------------------------------- /SConscript: -------------------------------------------------------------------------------- 1 | #-*- encoding: utf-8 -*- 2 | #--------------------------------------------------------------------------------- 3 | # @File: Sconscript 4 | # @Author: liu2guang 5 | # @Date: 2018-09-19 18:07:00(v0.1.0) 6 | # 7 | # @LICENSE: GPLv3: https://github.com/rtpkgs/buildpkg/blob/master/LICENSE. 8 | # 9 | #--------------------------------------------------------------------------------- 10 | import os 11 | from building import * 12 | Import('RTT_ROOT') 13 | Import('rtconfig') 14 | 15 | #--------------------------------------------------------------------------------- 16 | # Package configuration 17 | #--------------------------------------------------------------------------------- 18 | PKGNAME = "button" 19 | VERSION = "v1.0.0" 20 | DEPENDS = ["PKG_USING_BUTTON"] 21 | 22 | #--------------------------------------------------------------------------------- 23 | # Compile the configuration 24 | #--------------------------------------------------------------------------------- 25 | SOURCES = ["button.c"] 26 | 27 | CPPPATH = [] 28 | CCFLAGS = " -std=gnu99" # no pass 29 | ASFLAGS = "" 30 | 31 | LOCAL_CPPPATH = [""] 32 | LOCAL_CCFLAGS = " -std=gnu99" 33 | LOCAL_ASFLAGS = "" 34 | 35 | CPPDEFINES = ["CPPDEFINES"] 36 | LOCAL_CPPDEFINES = ["LOCAL_CPPDEFINES"] 37 | 38 | LIBS = ["libmm"] # keil libmm, gcc mm 39 | LIBPATH = [os.path.join(GetCurrentDir(), "")] 40 | 41 | LINKFLAGS = "" 42 | 43 | #--------------------------------------------------------------------------------- 44 | # Feature clip configuration, optional 45 | #--------------------------------------------------------------------------------- 46 | 47 | #--------------------------------------------------------------------------------- 48 | # Compiler platform configuration, optional 49 | #--------------------------------------------------------------------------------- 50 | if rtconfig.CROSS_TOOL == "gcc": 51 | pass 52 | 53 | if rtconfig.CROSS_TOOL == "iar": 54 | pass 55 | 56 | if rtconfig.CROSS_TOOL == "keil": 57 | pass 58 | 59 | #--------------------------------------------------------------------------------- 60 | # Warning: internal related processing, developers do not modify!!! 61 | #--------------------------------------------------------------------------------- 62 | 63 | #--------------------------------------------------------------------------------- 64 | # System variables 65 | #--------------------------------------------------------------------------------- 66 | objs = [] 67 | root = GetCurrentDir() 68 | 69 | #--------------------------------------------------------------------------------- 70 | # Add relative path support for CPPPATH and LOCAL_CPPPATH 71 | #--------------------------------------------------------------------------------- 72 | for index, value in enumerate(CPPPATH): 73 | if string.find(value, root) == False: 74 | CPPPATH[index] = os.path.join(root, value) 75 | 76 | for index, value in enumerate(LOCAL_CPPPATH): 77 | if string.find(value, root) == False: 78 | LOCAL_CPPPATH[index] = os.path.join(root, value) 79 | 80 | if rtconfig.CROSS_TOOL == "gcc": # no test 81 | for index, value in enumerate(LIBS): 82 | if value.startswith("lib") == True: 83 | print("Automatic fix the nonstandard lib name, %s -> %s" % (LIBS[index], LIBS[index].lstrip("lib"))) 84 | LIBS[index] = LIBS[index].lstrip("lib") 85 | 86 | elif rtconfig.CROSS_TOOL == "keil": 87 | for index, value in enumerate(LIBS): 88 | if value.startswith("lib") == False: 89 | print("Automatic fix the nonstandard lib name, %s -> %s" % (LIBS[index], "lib" + LIBS[index])) 90 | LIBS[index] = "lib" + LIBS[index] 91 | 92 | LIBPATH += [root] 93 | 94 | #--------------------------------------------------------------------------------- 95 | # Sub target 96 | #--------------------------------------------------------------------------------- 97 | list = os.listdir(root) 98 | if GetDepend(DEPENDS): 99 | for d in list: 100 | path = os.path.join(root, d) 101 | if os.path.isfile(os.path.join(path, 'SConscript')): 102 | objs = objs + SConscript(os.path.join(d, 'SConscript')) 103 | 104 | #--------------------------------------------------------------------------------- 105 | # Main target 106 | #--------------------------------------------------------------------------------- 107 | objs = DefineGroup(name = PKGNAME, src = SOURCES, depend = DEPENDS, 108 | CPPPATH = CPPPATH, 109 | CCFLAGS = CCFLAGS, 110 | ASFLAGS = ASFLAGS, 111 | LOCAL_CPPPATH = LOCAL_CPPPATH, 112 | LOCAL_CCFLAGS = LOCAL_CCFLAGS, 113 | LOCAL_ASFLAGS = LOCAL_ASFLAGS, 114 | CPPDEFINES = CPPDEFINES, 115 | LOCAL_CPPDEFINES = LOCAL_CPPDEFINES, 116 | LIBS = LIBS, 117 | LIBPATH = LIBPATH, 118 | LINKFLAGS = LINKFLAGS) 119 | 120 | Return("objs") 121 | -------------------------------------------------------------------------------- /button.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/button.c -------------------------------------------------------------------------------- /button.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/button.h -------------------------------------------------------------------------------- /debug.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEBUG_H 2 | #define _DEBUG_H 3 | /************************************************************ 4 | * @brief debug.h 5 | * @author jiejie 6 | * @github https://github.com/jiejieTop 7 | * @date 2018-xx-xx 8 | * @version v1.0 9 | * @note 此文件用于打印日志信息 10 | ***********************************************************/ 11 | /** 12 | * @name Debug print 13 | * @{ 14 | */ 15 | #define PRINT_DEBUG_ENABLE 0 /* 打印调试信息 */ 16 | #define PRINT_ERR_ENABLE 0 /* 打印错误信息 */ 17 | #define PRINT_INFO_ENABLE 0 /* 打印个人信息 */ 18 | 19 | 20 | #if PRINT_DEBUG_ENABLE 21 | #define PRINT_DEBUG(fmt, args...) do{(printf("\n[DEBUG] >> "), printf(fmt, ##args));}while(0) 22 | #else 23 | #define PRINT_DEBUG(fmt, args...) 24 | #endif 25 | 26 | #if PRINT_ERR_ENABLE 27 | #define PRINT_ERR(fmt, args...) do{(printf("\n[ERR] >> "), printf(fmt, ##args));}while(0) 28 | #else 29 | #define PRINT_ERR(fmt, args...) 30 | #endif 31 | 32 | #if PRINT_INFO_ENABLE 33 | #define PRINT_INFO(fmt, args...) do{(printf("\n[INFO] >> "), printf(fmt, ##args));}while(0) 34 | #else 35 | #define PRINT_INFO(fmt, args...) 36 | #endif 37 | 38 | /**@} */ 39 | 40 | //针对不同的编译器调用不同的stdint.h文件 41 | #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) 42 | #include 43 | #endif 44 | 45 | /* 断言 Assert */ 46 | #define AssertCalled(char,int) printf("\nError:%s,%d\r\n",char,int) 47 | #define ASSERT(x) if((x)==0) AssertCalled(__FILE__,__LINE__) 48 | 49 | typedef enum 50 | { 51 | ASSERT_ERR = 0, /* 错误 */ 52 | ASSERT_SUCCESS = !ASSERT_ERR /* 正确 */ 53 | } Assert_ErrorStatus; 54 | 55 | typedef enum 56 | { 57 | FALSE = 0, /* 假 */ 58 | TRUE = !FALSE /* 真 */ 59 | }ResultStatus; 60 | 61 | 62 | 63 | #endif /* __DEBUG_H */ 64 | 65 | -------------------------------------------------------------------------------- /include.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/include.h -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/main.c -------------------------------------------------------------------------------- /png/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/png/1.png -------------------------------------------------------------------------------- /png/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/png/10.png -------------------------------------------------------------------------------- /png/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/png/11.png -------------------------------------------------------------------------------- /png/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/png/2.png -------------------------------------------------------------------------------- /png/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/png/3.png -------------------------------------------------------------------------------- /png/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/png/4.png -------------------------------------------------------------------------------- /png/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/png/5.png -------------------------------------------------------------------------------- /png/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/png/6.png -------------------------------------------------------------------------------- /png/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/png/7.png -------------------------------------------------------------------------------- /png/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/png/8.png -------------------------------------------------------------------------------- /png/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/png/9.png -------------------------------------------------------------------------------- /redef.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiejieTop/ButtonDrive/18fab8f295cfc7243cd58ab2c5be01dcb3c27497/redef.h --------------------------------------------------------------------------------