├── firmwares └── .gitkeep ├── CC2530DB ├── settings │ ├── GenericApp.reggroups │ └── GenericApp.dnx └── GenericApp.eww ├── hardware ├── v1 │ ├── case_v1.STL │ └── Keypad_V1_1.rar ├── 4_buttons │ ├── SW.rar │ ├── STL.rar │ └── Project_EasyEDA.zip └── v2 │ ├── Keypad_mini2.rar │ ├── case_v2_8key_top.STL │ └── case_v2_8key_bottom.STL ├── images ├── z2m_exposes.png ├── orig-freepad │ ├── v1 │ │ ├── 0.png │ │ ├── 1.jpg │ │ ├── 2.jpg │ │ ├── 3.jpg │ │ ├── 4.jpg │ │ ├── 5.jpg │ │ ├── 6.png │ │ ├── 7.jpg │ │ ├── 8.jpg │ │ ├── 9.jpg │ │ ├── 10.jpg │ │ ├── 11.jpg │ │ ├── 12.jpg │ │ ├── 13.jpg │ │ ├── 14.jpg │ │ ├── 15.jpg │ │ ├── 16.jpg │ │ ├── 17.jpg │ │ ├── 18.jpg │ │ ├── 19.jpg │ │ └── 20.jpg │ └── v2 │ │ ├── 0.jpg │ │ ├── 1.jpg │ │ ├── 2.jpg │ │ ├── 3.jpg │ │ ├── 4.jpg │ │ ├── 5.jpg │ │ ├── 6.jpg │ │ ├── 7.jpg │ │ ├── 8.jpg │ │ ├── 9.jpg │ │ ├── 10.jpg │ │ ├── 11.jpg │ │ ├── 12.jpg │ │ ├── 13.jpg │ │ ├── 14.jpg │ │ ├── 15.jpg │ │ ├── 16.jpg │ │ ├── 17.jpg │ │ ├── 18.jpg │ │ ├── 19.jpg │ │ ├── 20.jpg │ │ ├── 21.jpg │ │ ├── 22.jpg │ │ ├── 23.jpg │ │ ├── 24.png │ │ ├── 25.png │ │ └── zigbee_keypad22.png ├── zigbee_keypad13.jpg └── letv-freepad │ ├── freepad_letv.png │ ├── freepad_letv_1.png │ ├── freepad_letv_2.png │ ├── freepad_letv_5.png │ ├── freepad_letv_6.png │ ├── freepad_letv_7.png │ ├── freepad_letv_8.png │ ├── freepad_letv_9.png │ ├── freepad_letv_11.png │ ├── freepad_letv_12.png │ ├── freepad_letv_13.png │ └── freepad_letv_but_map.png ├── .gitmodules ├── Source ├── version.h ├── OSAL_FreePadApp.c ├── preinclude.h ├── zcl_freepadapp.h ├── f8wConfig.cfg ├── hal_key.c ├── zcl_freepadapp_data.c ├── hal_board_cfg.h └── zcl_freepadapp.c ├── .release-it.yml ├── .clang-format ├── code_gen.py ├── ver.py ├── .gitignore ├── patches ├── 0001-fix-defaults-for-TL.patch └── 0001-fix-reporting.patch ├── .vscode └── c_cpp_properties.json ├── README.md ├── README_LETV.md ├── z2m-converter ├── FreePad_LeTV_8.js └── DIYRuZ_FreePad.js ├── README_FREEPAD_v2.md ├── README_FREEPAD_v1.md └── LICENSE /firmwares/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /CC2530DB/settings/GenericApp.reggroups: -------------------------------------------------------------------------------- 1 | group = "io", "P0" 2 | group = "Unnamed2", "P1" 3 | -------------------------------------------------------------------------------- /hardware/v1/case_v1.STL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/hardware/v1/case_v1.STL -------------------------------------------------------------------------------- /images/z2m_exposes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/z2m_exposes.png -------------------------------------------------------------------------------- /hardware/4_buttons/SW.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/hardware/4_buttons/SW.rar -------------------------------------------------------------------------------- /hardware/4_buttons/STL.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/hardware/4_buttons/STL.rar -------------------------------------------------------------------------------- /hardware/v1/Keypad_V1_1.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/hardware/v1/Keypad_V1_1.rar -------------------------------------------------------------------------------- /hardware/v2/Keypad_mini2.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/hardware/v2/Keypad_mini2.rar -------------------------------------------------------------------------------- /images/orig-freepad/v1/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/0.png -------------------------------------------------------------------------------- /images/orig-freepad/v1/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/1.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/2.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/3.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/4.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/5.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/6.png -------------------------------------------------------------------------------- /images/orig-freepad/v1/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/7.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/8.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/9.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/0.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/1.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/2.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/3.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/4.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/5.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/6.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/7.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/8.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/9.jpg -------------------------------------------------------------------------------- /images/zigbee_keypad13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/zigbee_keypad13.jpg -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "zstack-lib"] 2 | path = zstack-lib 3 | url = git@github.com:diyruz/zstack-lib.git 4 | -------------------------------------------------------------------------------- /Source/version.h: -------------------------------------------------------------------------------- 1 | extern const uint8 zclFreePadApp_DateCode[]; 2 | extern const char zclFreePadApp_DateCodeNT[]; -------------------------------------------------------------------------------- /images/orig-freepad/v1/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/10.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/11.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/12.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/13.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/14.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/15.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/15.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/16.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/16.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/17.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/17.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/18.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/18.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/19.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/19.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v1/20.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v1/20.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/10.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/11.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/12.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/13.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/14.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/15.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/15.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/16.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/16.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/17.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/17.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/18.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/18.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/19.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/19.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/20.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/20.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/21.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/21.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/22.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/22.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/23.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/23.jpg -------------------------------------------------------------------------------- /images/orig-freepad/v2/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/24.png -------------------------------------------------------------------------------- /images/orig-freepad/v2/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/25.png -------------------------------------------------------------------------------- /hardware/v2/case_v2_8key_top.STL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/hardware/v2/case_v2_8key_top.STL -------------------------------------------------------------------------------- /hardware/v2/case_v2_8key_bottom.STL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/hardware/v2/case_v2_8key_bottom.STL -------------------------------------------------------------------------------- /.release-it.yml: -------------------------------------------------------------------------------- 1 | git: 2 | requireCleanWorkingDir: false 3 | github: 4 | release: true 5 | assets: ["firmwares/DIYRuZ_*.hex"] -------------------------------------------------------------------------------- /hardware/4_buttons/Project_EasyEDA.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/hardware/4_buttons/Project_EasyEDA.zip -------------------------------------------------------------------------------- /images/letv-freepad/freepad_letv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/letv-freepad/freepad_letv.png -------------------------------------------------------------------------------- /images/letv-freepad/freepad_letv_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/letv-freepad/freepad_letv_1.png -------------------------------------------------------------------------------- /images/letv-freepad/freepad_letv_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/letv-freepad/freepad_letv_2.png -------------------------------------------------------------------------------- /images/letv-freepad/freepad_letv_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/letv-freepad/freepad_letv_5.png -------------------------------------------------------------------------------- /images/letv-freepad/freepad_letv_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/letv-freepad/freepad_letv_6.png -------------------------------------------------------------------------------- /images/letv-freepad/freepad_letv_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/letv-freepad/freepad_letv_7.png -------------------------------------------------------------------------------- /images/letv-freepad/freepad_letv_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/letv-freepad/freepad_letv_8.png -------------------------------------------------------------------------------- /images/letv-freepad/freepad_letv_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/letv-freepad/freepad_letv_9.png -------------------------------------------------------------------------------- /images/letv-freepad/freepad_letv_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/letv-freepad/freepad_letv_11.png -------------------------------------------------------------------------------- /images/letv-freepad/freepad_letv_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/letv-freepad/freepad_letv_12.png -------------------------------------------------------------------------------- /images/letv-freepad/freepad_letv_13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/letv-freepad/freepad_letv_13.png -------------------------------------------------------------------------------- /images/orig-freepad/v2/zigbee_keypad22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/orig-freepad/v2/zigbee_keypad22.png -------------------------------------------------------------------------------- /images/letv-freepad/freepad_letv_but_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xyzroe/freepad/master/images/letv-freepad/freepad_letv_but_map.png -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | # We'll use defaults from the LLVM style, but with 4 columns indentation. 3 | BasedOnStyle: LLVM 4 | IndentWidth: 4 5 | ColumnLimit: 140 -------------------------------------------------------------------------------- /code_gen.py: -------------------------------------------------------------------------------- 1 | 2 | # key_num = 1 3 | # for rowcode in [4, 8, 16, 32, 64]: 4 | # for colcode in [4, 8, 16, 32]: 5 | # # print("rowcode: {0} {0:b}".format(rowcode)) 6 | # code = (((rowcode << 2) | colcode >> 1)) >> 1 7 | # print(f'case { hex(code)}: // row={rowcode} col={colcode}') 8 | # print(f' return {key_num};') 9 | # key_num += 1 10 | 11 | 12 | 13 | for idx in range(1, 20): 14 | code = """ 15 | {{ 16 | {{SWITCH_CONFIG,{{ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW,(void *)&zclFreePadApp_SwitchTypes[{0}]}}}},\n 17 | {{SWITCH_CONFIG,{{ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchConfigs[{0}]}}}}\n 18 | }},\n 19 | """.format(idx) 20 | print(code) -------------------------------------------------------------------------------- /ver.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | from os.path import dirname, join 3 | cwd = dirname(__file__) 4 | now = datetime.now() 5 | dt_string = now.strftime("%d/%m/%Y %H:%M") 6 | print("date and time =", dt_string) 7 | with open(join(cwd, './Source/version.c'), 'w') as f: 8 | chars = ["'{0}'".format(char) for char in dt_string] 9 | f.write(""" 10 | #ifndef ZCL_FREEPADAPP_VERSION_H 11 | #define ZCL_FREEPADAPP_VERSION_H 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | """ 18 | ) 19 | f.write('#include "version.h"\n') 20 | code = """const uint8 zclFreePadApp_DateCode[] = {{ {0}, {1} }};\n""".format(len(chars), ', '.join(chars)) 21 | f.write(code) 22 | code = """const char zclFreePadApp_DateCodeNT[] = \"{0}\";\n""".format(dt_string) 23 | f.write(code) 24 | f.write(""" 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif /* ZCL_FREEPADAPP_VERSION_H */ 30 | """) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IAR C-STAT and C-RUN 2 | # Comment this out if you use C-Stat or C-Run to compile/analyze your project 3 | *.ewt 4 | 5 | # IAR Debugger files 6 | *.ewd 7 | 8 | 9 | # IAR Settings 10 | **/settings/*.crun 11 | **/settings/*.dbgdt 12 | **/settings/*.cspy 13 | **/settings/*.cspy.* 14 | **/settings/*.xcl 15 | **/settings/*.dni 16 | **/settings/*.wsdt 17 | **/settings/*.wspos 18 | 19 | # IAR Debug Exe 20 | **/CoordinatorEB/Exe/ 21 | 22 | # IAR Debug List 23 | **/CoordinatorEB/List 24 | 25 | # IAR Debug Obj 26 | **/CoordinatorEB/Obj/*.pbd 27 | **/CoordinatorEB/Obj/*.pbd.* 28 | **/CoordinatorEB/Obj/*.pbi 29 | **/CoordinatorEB/Obj/*.pbi.* 30 | **/CoordinatorEB/Obj/*.r51 31 | 32 | # Log files 33 | **.log 34 | 35 | # IAR backup files 36 | Backup* 37 | 38 | # IAR .dep files 39 | *.dep 40 | 41 | # Compiled Binaries 42 | *.bin 43 | *.elf 44 | *.map 45 | 46 | # Trash files 47 | *.bak 48 | 49 | # CC2530DB 50 | 51 | CC2530DB/CHDTECH_DEV 52 | CC2530DB/DIYRuZ_* 53 | Source/version.c 54 | !.vscode/ 55 | .vscode/settings.json 56 | firmwares/* -------------------------------------------------------------------------------- /patches/0001-fix-defaults-for-TL.patch: -------------------------------------------------------------------------------- 1 | From 560dee0a02babf11a2583bab4843faee75dca929 Mon Sep 17 00:00:00 2001 2 | From: nur 3 | Date: Tue, 26 May 2020 16:25:34 +0800 4 | Subject: [PATCH] fix defaults for TL 5 | 6 | --- 7 | Components/stack/bdb/bdb_interface.h | 4 ++-- 8 | 1 file changed, 2 insertions(+), 2 deletions(-) 9 | 10 | diff --git a/Components/stack/bdb/bdb_interface.h b/Components/stack/bdb/bdb_interface.h 11 | index 2cb5d99..be0baba 100644 12 | --- a/Components/stack/bdb/bdb_interface.h 13 | +++ b/Components/stack/bdb/bdb_interface.h 14 | @@ -182,10 +182,10 @@ extern "C" 15 | // For certification only: 16 | #define TOUCHLINK_ENC_KEY TOUCHLINK_CERTIFICATION_ENC_KEY 17 | #define TOUCHLINK_LINK_KEY TOUCHLINK_CERTIFICATION_LINK_KEY 18 | -#define TOUCHLINK_KEY_INDEX TOUCHLINK_KEY_INDEX_CERT 19 | +#define TOUCHLINK_KEY_INDEX TOUCHLINK_KEY_INDEX_MASTER 20 | 21 | // For internal EP's simple descriptor 22 | -#define TOUCHLINK_INTERNAL_ENDPOINT 13 23 | +#define TOUCHLINK_INTERNAL_ENDPOINT 42 24 | #define TOUCHLINK_INTERNAL_DEVICE_ID 0xE15E 25 | #define TOUCHLINK_INTERNAL_FLAGS 0 26 | #define TOUCHLINK_DEFAULT_IDENTIFY_TIME 3 27 | -- 28 | 2.24.2 (Apple Git-127) 29 | 30 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [{ 3 | "name": "Mac", 4 | "forcedInclude": ["${workspaceRoot}/Source/preinclude.h"], 5 | "defines": ["HAL_BOARD_FREEPAD", "HAL_UART=TRUE", "FREEPAD_ENABLE_TL"], 6 | "includePath": [ 7 | "${workspaceRoot}", 8 | "${env:ZSTACK_PATH}/Components/mac/include/", 9 | "${env:ZSTACK_PATH}/Components/mt", 10 | "${env:ZSTACK_PATH}/Components/zmac", 11 | "${env:ZSTACK_PATH}/Components/zmac/f8w", 12 | "${env:ZSTACK_PATH}/Components/osal/include", 13 | "${env:ZSTACK_PATH}/Components/stack/af", 14 | "${env:ZSTACK_PATH}/Components/stack/bdb", 15 | "${env:ZSTACK_PATH}/Components/stack/sec", 16 | "${env:ZSTACK_PATH}/Components/stack/sys", 17 | "${env:ZSTACK_PATH}/Components/stack/zdo", 18 | "${env:ZSTACK_PATH}/Components/stack/GP", 19 | "${env:ZSTACK_PATH}/Components/stack/nwk", 20 | "${env:ZSTACK_PATH}/Components/stack/zcl", 21 | "${env:ZSTACK_PATH}/Components/hal/target/CC2530EB/", 22 | "${env:ZSTACK_PATH}/Components/hal/include/", 23 | "${env:ZSTACK_PATH}/Components/services/saddr/", 24 | "${env:ZSTACK_PATH}/Components/services/sdata/", 25 | "${env:ZSTACK_PATH}/Projects/zstack/ZMain/TI2530DB", 26 | "${env:ZSTACK_PATH}/Projects/zstack/HomeAutomation/Source" 27 | ], 28 | "intelliSenseMode": "clang-x64", 29 | "compilerPath": "/usr/bin/clang", 30 | "cStandard": "c99", 31 | "cppStandard": "c++17" 32 | }], 33 | "version": 4 34 | } -------------------------------------------------------------------------------- /CC2530DB/GenericApp.eww: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $WS_DIR$\GenericApp.ewp 5 | 6 | 7 | 8 | FREEPADS 9 | 10 | GenericApp 11 | DIYRuZ_FreePad 12 | 13 | 14 | GenericApp 15 | DIYRuZ_FreePad_PM3 16 | 17 | 18 | GenericApp 19 | DIYRuZ_FreePad_TL_PM3 20 | 21 | 22 | GenericApp 23 | DIYRuZ_FreePad_LeTV_TL_PM3 24 | 25 | 26 | GenericApp 27 | DIYRuZ_FreePad_LeTV 28 | 29 | 30 | GenericApp 31 | DIYRuZ_FreePad_LeTV_PM3 32 | 33 | 34 | GenericApp 35 | DIYRuZ_FreePad_LeTV_TL 36 | 37 | 38 | GenericApp 39 | DIYRuZ_FreePad_TL 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Source/OSAL_FreePadApp.c: -------------------------------------------------------------------------------- 1 | #include "OSAL.h" 2 | #include "OSAL_Tasks.h" 3 | #include "ZComDef.h" 4 | #include "hal_drivers.h" 5 | 6 | #include "APS.h" 7 | 8 | #include "ZDApp.h" 9 | #include "nwk.h" 10 | 11 | #include "bdb_interface.h" 12 | #ifdef FREEPAD_ENABLE_TL 13 | #include "bdb_touchlink_initiator.h" 14 | #include "stub_aps.h" 15 | #include "tl_resetter.h" 16 | #endif 17 | 18 | #include "Debug.h" 19 | #include "battery.h" 20 | #include "commissioning.h" 21 | #include "factory_reset.h" 22 | #include "zcl_freepadapp.h" 23 | 24 | const pTaskEventHandlerFn tasksArr[] = {macEventLoop, 25 | nwk_event_loop, 26 | Hal_ProcessEvent, 27 | APS_event_loop, 28 | ZDApp_event_loop, 29 | zcl_event_loop, 30 | #ifdef FREEPAD_ENABLE_TL 31 | StubAPS_ProcessEvent, 32 | touchLinkInitiator_event_loop, 33 | #endif 34 | bdb_event_loop, 35 | zclFreePadApp_event_loop, 36 | zclCommissioning_event_loop, 37 | zclFactoryResetter_loop, 38 | zclBattery_event_loop 39 | #ifdef FREEPAD_ENABLE_TL 40 | , 41 | zclTouchLinkRestter_event_loop 42 | #endif 43 | }; 44 | 45 | const uint8 tasksCnt = sizeof(tasksArr) / sizeof(tasksArr[0]); 46 | uint16 *tasksEvents; 47 | 48 | void osalInitTasks(void) { 49 | uint8 taskID = 0; 50 | DebugInit(); 51 | 52 | tasksEvents = (uint16 *)osal_mem_alloc(sizeof(uint16) * tasksCnt); 53 | osal_memset(tasksEvents, 0, (sizeof(uint16) * tasksCnt)); 54 | macTaskInit(taskID++); 55 | nwk_init(taskID++); 56 | Hal_Init(taskID++); 57 | APS_Init(taskID++); 58 | ZDApp_Init(taskID++); 59 | zcl_Init(taskID++); 60 | #ifdef FREEPAD_ENABLE_TL 61 | StubAPS_Init(taskID++); 62 | touchLinkInitiator_Init(taskID++); 63 | #endif 64 | bdb_Init(taskID++); 65 | zclFreePadApp_Init(taskID++); 66 | zclCommissioning_Init(taskID++); 67 | zclFactoryResetter_Init(taskID++); 68 | zclBattery_Init(taskID++); 69 | #ifdef FREEPAD_ENABLE_TL 70 | zclTouchLinkRestter_Init(taskID++); 71 | #endif 72 | } 73 | 74 | /********************************************************************* 75 | *********************************************************************/ 76 | -------------------------------------------------------------------------------- /Source/preinclude.h: -------------------------------------------------------------------------------- 1 | #define TC_LINKKEY_JOIN 2 | #define NV_INIT 3 | #define NV_RESTORE 4 | // to make TL work, need patch this macroses in SDK 5 | // #define TOUCHLINK_KEY_INDEX TOUCHLINK_KEY_INDEX_MASTER 6 | // #define TOUCHLINK_INTERNAL_ENDPOINT 42 7 | 8 | #define TP2_LEGACY_ZC 9 | // patch sdk 10 | // #define ZDSECMGR_TC_ATTEMPT_DEFAULT_KEY TRUE 11 | 12 | #define NWK_AUTO_POLL 13 | #define MULTICAST_ENABLED FALSE 14 | 15 | #define ZCL_READ 16 | #define ZCL_WRITE 17 | #define ZCL_BASIC 18 | #define ZCL_IDENTIFY 19 | #define ZCL_ON_OFF 20 | #define ZCL_LEVEL_CTRL 21 | #define ZCL_REPORTING_DEVICE 22 | 23 | //TODO: PM3 refactor z2m converters 24 | // #define BDB_REPORTING 25 | // #define FREEPAD_ENABLE_TL 26 | #ifdef FREEPAD_ENABLE_TL 27 | #define INTER_PAN 28 | #define BDB_TL_INITIATOR 29 | #endif 30 | 31 | 32 | #define DISABLE_GREENPOWER_BASIC_PROXY 33 | #define BDB_FINDING_BINDING_CAPABILITY_ENABLED 1 34 | 35 | 36 | #define ISR_KEYINTERRUPT 37 | #define HAL_BUZZER FALSE 38 | 39 | #define HAL_LED TRUE 40 | #define HAL_LCD FALSE 41 | #define BLINK_LEDS TRUE 42 | 43 | // one of this boards 44 | // #define HAL_BOARD_FREEPAD 45 | // #define HAL_BOARD_LETV 46 | // #define HAL_BOARD_CHDTECH_DEV 47 | 48 | #if !defined(HAL_BOARD_FREEPAD) && !defined(HAL_BOARD_CHDTECH_DEV) && !defined(HAL_BOARD_LETV) 49 | #error "Board type must be defined" 50 | #endif 51 | 52 | #if defined(FREEPAD_ENABLE_TL) && BDB_REPORTING 53 | #define INT_HEAP_LEN (3000 - 0x38) 54 | #endif 55 | 56 | #ifndef INT_HEAP_LEN 57 | #define INT_HEAP_LEN 3000 58 | #endif 59 | 60 | #if defined(HAL_BOARD_LETV) 61 | #define FREEPAD_BUTTONS_COUNT 8 62 | #else 63 | #define FREEPAD_BUTTONS_COUNT 20 64 | #endif 65 | 66 | 67 | #if defined(HAL_BOARD_FREEPAD) || defined(HAL_BOARD_LETV) 68 | #define POWER_SAVING 69 | #endif 70 | 71 | #if defined(HAL_BOARD_CHDTECH_DEV) 72 | // #define DO_DEBUG_UART 73 | // #define OSALMEM_METRICS TRUE 74 | #endif 75 | 76 | #ifdef DO_DEBUG_UART 77 | #define HAL_UART TRUE 78 | #define HAL_UART_DMA 1 79 | #define INT_HEAP_LEN 2197 80 | #endif 81 | 82 | #ifdef DO_DEBUG_MT 83 | #define HAL_UART TRUE 84 | #define HAL_UART_DMA 1 85 | #define HAL_UART_ISR 2 86 | #define INT_HEAP_LEN (2688-0xC4-0x15-0x44-0x20-0x1E) 87 | 88 | #define MT_TASK 89 | 90 | #define MT_UTIL_FUNC 91 | #define MT_UART_DEFAULT_BAUDRATE HAL_UART_BR_115200 92 | #define MT_UART_DEFAULT_OVERFLOW FALSE 93 | 94 | #define ZTOOL_P1 95 | 96 | #define MT_APP_FUNC 97 | #define MT_APP_CNF_FUNC 98 | #define MT_SYS_FUNC 99 | #define MT_ZDO_FUNC 100 | #define MT_ZDO_MGMT 101 | #define MT_DEBUG_FUNC 102 | #endif 103 | 104 | 105 | #include "hal_board_cfg.h" 106 | -------------------------------------------------------------------------------- /Source/zcl_freepadapp.h: -------------------------------------------------------------------------------- 1 | #ifndef ZCL_FREEPADAPP_H 2 | #define ZCL_FREEPADAPP_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /********************************************************************* 9 | * INCLUDES 10 | */ 11 | #include "version.h" 12 | #include "zcl.h" 13 | 14 | 15 | /********************************************************************* 16 | * CONSTANTS 17 | */ 18 | 19 | #define FREEPAD_NW_SWITCH_ACTIONS 0x1000 20 | #define FREEPAD_NW_SWITCH_TYPES 0x2000 21 | 22 | #define HAL_UNKNOWN_BUTTON HAL_KEY_CODE_NOKEY 23 | // Application Events 24 | 25 | #define FREEPADAPP_CONST_ONE_MINUTE_IN_MS ((uint32) 60 * (uint32) 1000) 26 | 27 | 28 | #define FREEPADAPP_SEND_KEYS_EVT 0x0001 29 | #define FREEPADAPP_HOLD_START_EVT 0x0002 30 | #define FREEPADAPP_SAVE_ATTRS_EVT 0x0004 31 | 32 | #define FREEPADAPP_SEND_KEYS_DELAY 250 33 | #define FREEPADAPP_HOLD_START_DELAY (FREEPADAPP_SEND_KEYS_DELAY + 750) 34 | 35 | 36 | #define FREEPAD_ATTRS_COUNT 2 37 | 38 | #define FREEPADAPP_LEVEL_STEP_SIZE 43 //255/6 39 | #define FREEPADAPP_LEVEL_TRANSITION_TIME 10 40 | 41 | #define FREEPADAPP_COLOR_LEVEL_STEP_X_SIZE 1000 42 | #define FREEPADAPP_COLOR_LEVEL_STEP_Y_SIZE 1000 43 | #define FREEPADAPP_COLOR_LEVEL_TRANSITION_TIME 0 44 | 45 | 46 | /********************************************************************* 47 | * MACROS 48 | */ 49 | /********************************************************************* 50 | * TYPEDEFS 51 | */ 52 | 53 | /********************************************************************* 54 | * VARIABLES 55 | */ 56 | extern uint8 zclFreePadApp_SwitchActions[]; 57 | extern uint8 zclFreePadApp_SwitchTypes[]; 58 | 59 | 60 | extern SimpleDescriptionFormat_t zclFreePadApp_SimpleDescs[]; 61 | 62 | 63 | 64 | // attribute list 65 | extern CONST zclAttrRec_t zclFreePadApp_Attrs[][FREEPAD_ATTRS_COUNT]; 66 | extern CONST zclAttrRec_t zclFreePadApp_AttrsFirstEP[]; 67 | extern CONST uint8 zclFreePadApp_AttrsFirstEPCount; 68 | 69 | 70 | // FREEPADAPP_TODO: Declare application specific attributes here 71 | 72 | /********************************************************************* 73 | * FUNCTIONS 74 | */ 75 | 76 | /* 77 | * Initialization for the task 78 | */ 79 | extern void zclFreePadApp_Init(byte task_id); 80 | extern void zclFreePadApp_InitClusters(void); 81 | extern byte zclFreePadApp_KeyCodeToButton(byte key); 82 | 83 | /* 84 | * Event Process for the task 85 | */ 86 | extern UINT16 zclFreePadApp_event_loop(byte task_id, UINT16 events); 87 | 88 | /********************************************************************* 89 | *********************************************************************/ 90 | 91 | 92 | extern void zclFreePadApp_ResetAttributesToDefaultValues(void); 93 | 94 | #ifdef __cplusplus 95 | } 96 | #endif 97 | 98 | #endif /* ZCL_FREEPADAPP_H */ 99 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Freepad 2 | 3 | Freepad is an open source Zigbee remote intended to be used to have a customizable keypad to control your smart home devices. 4 | 5 | There are different hardware versions of the console. 6 | More details on the links: 7 | * [Freepad v1](https://github.com/diyruz/freepad/README_FREEPAD_v1.md) 8 | * [Freepad v2](https://github.com/diyruz/freepad/README_FREEPAD_v2.md) 9 | * [LeTV mod](https://github.com/diyruz/freepad/README_FREEPAD_LETV.md) 10 | 11 | ## Features list: 12 | 1. Single/double/tripple/quadriple/many_x/hold&release 13 | 2. Touchlink reset 14 | 3. ONOFF bind 15 | 4. Level control bind 16 | 5. Bindings configuration 17 | 6. Remote reset 18 | 19 | ## How to join: 20 | 1. Press and hold the *first* button for 3-10 seconds (depending on whether the device is connected to the network) until the LED on the device flashes. 21 | 2. Wait, if the connection is successful, the device will blink 5 times. 22 | 3. If the connection fails, the device will blink 3 times. 23 | 24 | ***Find button mapping at project page*** 25 | 26 | ### Support 27 | The keypad is supported in: 28 | * zigbee2mqtt via int & ext converter 29 | * ioBroker 30 | * SLS Gateway 31 | 32 | ## Settings 33 | In zigbee2mqtt you could change setting at Exposes tab. 34 | ![](/images/z2m_exposes.png) 35 | 36 | ### Work modes 37 | By default remote works as custom switch, with multiple clicks, but this behavior has own drawback. 38 | In order to detect multiple clicks, remote sends commands with 300ms delay. 39 | You can change this behavior by cost of double/triple/etc clicks. 40 | 41 | To do that you need to change 42 | 43 | `ZCL_CLUSTER_ID_GEN_ON_OFF_SWITCH_CONFIG` cluster `ATTRID_ON_OFF_SWITCH_TYPE` attribute 44 | 45 | Values are: 46 | 47 | `ON_OFF_SWITCH_TYPE_MOMENTARY` (0) -> no delay, but no multiple clicks, only single 48 | 49 | ```bash 50 | mosquitto_pub -t "zigbee2mqtt/FN/BUTTON_NUM/set/switch_type" -m '0' 51 | ``` 52 | 53 | `ON_OFF_SWITCH_TYPE_MULTIFUNCTION` (2) -> 300ms delay, full set of clicks 54 | 55 | ```bash 56 | mosquitto_pub -t "zigbee2mqtt/FN/BUTTON_NUM/set/switch_type" -m '2' 57 | ``` 58 | 59 | 60 | ### ONOFF cluster binding 61 | By default command is TOGGLE, but you can change this behavior. 62 | 63 | Change `ZCL_CLUSTER_ID_GEN_ON_OFF_SWITCH_CONFIG` clusters attribute `ATTRID_ON_OFF_SWITCH_ACTIONS` 64 | 65 | `ON_OFF_SWITCH_ACTIONS_ON` 66 | 67 | ```bash 68 | mosquitto_pub -t "zigbee2mqtt/FN/BUTTON_NUM/set/switch_actions" -m '0' 69 | ``` 70 | 71 | `ON_OFF_SWITCH_ACTIONS_OFF` 72 | 73 | ```bash 74 | mosquitto_pub -t "zigbee2mqtt/FN/BUTTON_NUM/set/switch_actions" -m '1' 75 | ``` 76 | 77 | `ON_OFF_SWITCH_ACTIONS_TOGGLE` (default value) 78 | 79 | ```bash 80 | mosquitto_pub -t "zigbee2mqtt/FN/BUTTON_NUM/set/switch_actions" -m '2' 81 | ``` 82 | 83 | ### Video 84 | [@Vlad_Kolobov](http://t.me/@MoNo320) recorded a video showing the speed in two modes 85 | [![video_speed_compare](https://img.youtube.com/vi/XvhNs9Tn12M/0.jpg)](https://www.youtube.com/watch?v=XvhNs9Tn12M) 86 | -------------------------------------------------------------------------------- /README_LETV.md: -------------------------------------------------------------------------------- 1 | ![](/images/letv-freepad/freepad_letv_12.png) 2 | 3 | Some time ago, digging TaoBao, Jager has found an interesting miniature ZigBee remote control keypad with eight buttons. 4 | As this device is powered by a CC2530 chip, an idea appeared in Jager's head to flash it with a great [freepad](https://github.com/diyruz/freepad/) firmware, which was used in Jager's previous remote controls. 5 | 6 | UPD: This keypad has appeared on [AliExpress](https://aliexpress.ru/item/1005001962088229.html?&sku_id=12000018238549831) 7 | 8 | Keypad has 8 buttons, two-colored led, and is powered by CR2032 lithium cell. 9 | 10 | ![](/images/letv-freepad/freepad_letv_13.png) 11 | ![](/images/letv-freepad/freepad_letv_2.png) 12 | 13 | 14 | It is quite easy to disassemble this device. The case is held by plastic latches, and two screws hid beneath the white ring. 15 | 16 | ![](/images/letv-freepad/freepad_letv_5.png) 17 | 18 | A totally disassembled keypad looks like this: 19 | 20 | ![](/images/letv-freepad/freepad_letv.png) 21 | 22 | ![](/images/letv-freepad/freepad_letv_3.png) 23 | 24 | There are membrane buttons, held by a scotch duct-tape on the PCB. 25 | The scotch-tape hides firmware flashing pads, so you need to remove it or cut a window to have access. 26 | 27 | ![](/images/letv-freepad/freepad_letv_1.png) 28 | 29 | As you can see, contacts are located in a pretty chaotic order. I don't wish to solder wires and that's why I decided to make a flashing adapter. 30 | 31 | ![](/images/letv-freepad/freepad_letv_6.png) 32 | 33 | ![](/images/letv-freepad/freepad_letv_7.png) 34 | 35 | ![](/images/letv-freepad/freepad_letv_8.png) 36 | 37 | The only thing you need to do is to upload the modified by [@xyzroe](https://t.me/xyzroe) version of freepad [firmware](https://github.com/diyruz/freepad/) with any 38 | situated flashing [method](https://zigbee.wiki/books/%D0%BF%D1%80%D0%BE%D1%88%D0%B8%D0%B2%D0%BA%D0%B8/page/%D0%BF%D1%80%D0%BE%D1%88%D0%B8%D0%B2%D0%BA%D0%B0-cc2531cc2530). 39 | Zigbee2mqtt converter file is included in the package archive. 40 | 41 | Here is how the device attached to the [SLS Gateway](https://slsys.github.io/Gateway/README_rus.html) looks like: 42 | 43 | ![](/images/letv-freepad/freepad_letv_9.png) 44 | ![](/images/letv-freepad/freepad_letv_11.png) 45 | 46 | ### What's button mapping? 47 | ![](/images/letv-freepad/freepad_letv_but_map.png) 48 | 49 | 50 | ### Links 51 | - [DXF-file](https://github.com/diyruz/freepad/hardware/letv) by [Jager](https://t.me/Jager_f) 52 | for DIY flashing adapter. 53 | 54 | 55 | - [Freepad firmware releases](https://github.com/diyruz/freepad/releases/latest) 56 | choose firmware hex file with __LeTV__ suffix. 57 | 58 | 59 | - [Flash instruction (in Russian)](https://zigbee.wiki/books/%D0%BF%D1%80%D0%BE%D1%88%D0%B8%D0%B2%D0%BA%D0%B8/page/%D0%BF%D1%80%D0%BE%D1%88%D0%B8%D0%B2%D0%BA%D0%B0-cc2531cc2530) 60 | In Russian for now, but links and pictures are not less useful. 61 | 62 | [Original post by Jager](https://modkam.ru/?p=1791) 63 | -------------------------------------------------------------------------------- /z2m-converter/FreePad_LeTV_8.js: -------------------------------------------------------------------------------- 1 | module.paths.push(require.main.path+ '/node_modules') //sovle Cannot find module 'zigbee-herdsman-converters' 2 | 3 | const { 4 | fromZigbeeConverters, 5 | toZigbeeConverters, 6 | exposes 7 | } = require('zigbee-herdsman-converters'); 8 | 9 | const e = exposes.presets; 10 | 11 | const genMultistateInputClusterId = 18; 12 | 13 | const getKey = (object, value) => { 14 | for (const key in object) { 15 | if (object[key] == value) return key; 16 | } 17 | }; 18 | const bind = async (endpoint, target, clusters) => { 19 | for (const cluster of clusters) { 20 | await endpoint.bind(cluster, target); 21 | } 22 | }; 23 | 24 | const ACCESS_STATE = 0b001, ACCESS_WRITE = 0b010, ACCESS_READ = 0b100; 25 | 26 | const device = { 27 | zigbeeModel: ['FreePad_LeTV_8'], 28 | model: 'FreePad_LeTV_8', 29 | vendor: 'DIYRuZ', 30 | description: '[LeTV 8 button keypad](https://modkam.ru/?p=1791)', 31 | supports: 'single, double, triple, quadruple, many, hold/release', 32 | fromZigbee: [fromZigbeeConverters.diyruz_freepad_clicks, fromZigbeeConverters.diyruz_freepad_config, fromZigbeeConverters.battery], 33 | exposes: [e.battery(), e.action(['*_single', '*_double', '*_triple', '*_quadruple', '*_release'])].concat(((enpoinsCount) => { 34 | const features = []; 35 | for (let i = 1; i <= enpoinsCount; i++) { 36 | const epName = `button_${i}`; 37 | features.push( 38 | exposes.enum('switch_type', exposes.access.ALL, ['toggle', 'momentary', 'multifunction']).withEndpoint(epName)); 39 | features.push(exposes.enum('switch_actions', exposes.access.ALL, ['on', 'off', 'toggle']).withEndpoint(epName)); 40 | } 41 | return features; 42 | })(8)), 43 | toZigbee: [toZigbeeConverters.diyruz_freepad_on_off_config, toZigbeeConverters.factory_reset], 44 | meta: {configureKey: 1}, 45 | configure: async (device, coordinatorEndpoint) => { 46 | const endpoint = device.getEndpoint(1); 47 | await bind(endpoint, coordinatorEndpoint, ['genPowerCfg']); 48 | if (device.applicationVersion < 3) { // Legacy PM2 firmwares 49 | const payload = [{ 50 | attribute: 'batteryPercentageRemaining', 51 | minimumReportInterval: 0, 52 | maximumReportInterval: 3600, 53 | reportableChange: 0, 54 | }, { 55 | attribute: 'batteryVoltage', 56 | minimumReportInterval: 0, 57 | maximumReportInterval: 3600, 58 | reportableChange: 0, 59 | }]; 60 | await endpoint.configureReporting('genPowerCfg', payload); 61 | } 62 | device.endpoints.forEach(async (ep) => { 63 | if (ep.outputClusters.includes(18)) { 64 | await bind(ep, coordinatorEndpoint, ['genMultistateInput']); 65 | } 66 | }); 67 | }, 68 | endpoint: (device) => { 69 | return { 70 | button_1: 1, button_2: 2, button_3: 3, button_4: 4, button_5: 5, 71 | button_6: 6, button_7: 7, button_8: 8 72 | }; 73 | }, 74 | }; 75 | 76 | module.exports = device; 77 | -------------------------------------------------------------------------------- /CC2530DB/settings/GenericApp.dnx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 1 6 | 90 7 | 1 8 | 1 9 | 1 10 | main 11 | 0 12 | 50 13 | 14 | 15 | _ 1238 679 2122 1219 16 | 17 | 18 | 919786274 19 | 20 | 21 | 0 22 | 23 | 24 | 1 25 | 26 | 27 | _ 0 28 | 29 | 30 | 0 31 | 1 32 | 0 33 | 0 34 | 35 | 36 | 37 | 0 38 | 39 | 40 | 1 41 | 42 | 43 | 0 44 | 0 45 | 1 46 | 0 47 | 1 48 | 0 49 | 50 | 51 | 0 52 | 0 53 | 1 54 | 0 55 | 1 56 | 57 | 58 | 0 59 | 60 | 61 | 1 62 | 63 | 64 | 0 65 | 0 66 | 0 67 | 1 68 | 1 69 | 1 70 | 71 | 72 | 0 73 | 1 74 | 75 | 76 | 50000000 77 | 0 78 | 79 | 80 | _ 0 81 | _ "" 82 | _ 0 83 | 84 | 85 | _ 0 86 | _ "" 87 | 88 | 89 | _ "STD_CODE" "{C:\Z-Stack 3.0.2\Components\stack\bdb\bdb_Reporting.c}.2241.6" 1 0 0 0 "" 0 "" 90 | _ "STD_CODE" "{C:\Z-Stack 3.0.2\Components\stack\bdb\bdb_Reporting.c}.2258.3" 1 0 0 0 "" 0 "" 91 | 2 92 | 93 | 94 | 0 95 | 1 96 | 97 | 98 | 0 99 | 0 100 | 101 | 102 | -------------------------------------------------------------------------------- /patches/0001-fix-reporting.patch: -------------------------------------------------------------------------------- 1 | From e2b3bd1496acd8f1a901466548b2280b1ad99bac Mon Sep 17 00:00:00 2001 2 | From: nur 3 | Date: Tue, 26 May 2020 16:25:51 +0800 4 | Subject: [PATCH] fix reporting 5 | 6 | --- 7 | Components/stack/bdb/bdb_Reporting.c | 28 ++++++++++++++++++++++------ 8 | 1 file changed, 22 insertions(+), 6 deletions(-) 9 | 10 | diff --git a/Components/stack/bdb/bdb_Reporting.c b/Components/stack/bdb/bdb_Reporting.c 11 | index 7a601f2..42c610d 100644 12 | --- a/Components/stack/bdb/bdb_Reporting.c 13 | +++ b/Components/stack/bdb/bdb_Reporting.c 14 | @@ -1662,7 +1662,7 @@ static uint8 bdb_RepLoadCfgRecords( void ) 15 | static void bdb_RepReport( uint8 specificCLusterEndpointIndex ) 16 | { 17 | afAddrType_t dstAddr; 18 | - zclReportCmd_t *pReportCmd; 19 | + zclReportCmd_t *pReportCmd = NULL; 20 | uint8 i; 21 | 22 | bdbReportAttrClusterEndpoint_t* clusterEndpointItem = NULL; 23 | @@ -1681,14 +1681,21 @@ static void bdb_RepReport( uint8 specificCLusterEndpointIndex ) 24 | // actually send the report 25 | if( clusterEndpointItem->consolidatedMaxReportInt != ZCL_REPORTING_OFF && clusterEndpointItem->attrLinkedList.numItems ) 26 | { 27 | + uint8 *pAttrData = NULL; 28 | + uint8 *pAttrDataTemp = NULL; 29 | + 30 | dstAddr.addrMode = (afAddrMode_t)AddrNotPresent; 31 | dstAddr.addr.shortAddr = 0; 32 | dstAddr.endPoint = clusterEndpointItem->endpoint; 33 | dstAddr.panId = _NIB.nwkPanId; 34 | 35 | + // List of attributes to report 36 | pReportCmd = osal_mem_alloc( sizeof( zclReportCmd_t ) + (clusterEndpointItem->attrLinkedList.numItems * sizeof( zclReport_t )) ); 37 | - if ( pReportCmd != NULL ) 38 | + // List of attribute data 39 | + pAttrData = osal_mem_alloc(clusterEndpointItem->attrLinkedList.numItems * BDBREPORTING_MAX_ANALOG_ATTR_SIZE); 40 | + if ( (pReportCmd != NULL) && (pAttrData != NULL) ) 41 | { 42 | + pAttrDataTemp = pAttrData; 43 | pReportCmd->numAttr = clusterEndpointItem->attrLinkedList.numItems; 44 | for ( i = 0; i < clusterEndpointItem->attrLinkedList.numItems; ++ i ) 45 | { 46 | @@ -1699,13 +1706,16 @@ static void bdb_RepReport( uint8 specificCLusterEndpointIndex ) 47 | bdbLinkedListAttrItem_t* attrListItem = bdb_linkedListAttrGetAtIndex( &clusterEndpointItem->attrLinkedList, i ); 48 | if(attrListItem!=NULL) 49 | { 50 | - pReportCmd->attrList[i].attrID = attrListItem->data->attrID; 51 | zclAttribute_t attrRec; 52 | + pReportCmd->attrList[i].attrID = attrListItem->data->attrID; 53 | uint8 attrRes = bdb_RepFindAttrEntry( clusterEndpointItem->endpoint, clusterEndpointItem->cluster, attrListItem->data->attrID, &attrRec ); 54 | if( attrRes == BDBREPORTING_TRUE ) 55 | { 56 | - pReportCmd->attrList[i].dataType = attrRec.dataType; 57 | - pReportCmd->attrList[i].attrData = attrRec.dataPtr; 58 | + pReportCmd->attrList[i].dataType = attrRec.dataType; 59 | + pReportCmd->attrList[i].attrData = pAttrDataTemp; 60 | + // Copy data to current attribute data pointer 61 | + pAttrDataTemp = osal_memcpy(pAttrDataTemp, attrRec.dataPtr, BDBREPORTING_MAX_ANALOG_ATTR_SIZE); 62 | + 63 | //Update last value reported 64 | if( zclAnalogDataType( attrRec.dataType ) ) 65 | { 66 | @@ -1720,9 +1730,15 @@ static void bdb_RepReport( uint8 specificCLusterEndpointIndex ) 67 | zcl_SendReportCmd( clusterEndpointItem->endpoint, &dstAddr, 68 | clusterEndpointItem->cluster, pReportCmd, 69 | ZCL_FRAME_SERVER_CLIENT_DIR, BDB_REPORTING_DISABLE_DEFAULT_RSP, bdb_getZCLFrameCounter( ) ); 70 | - 71 | + } 72 | + if( (pReportCmd != NULL ) ) 73 | + { 74 | osal_mem_free( pReportCmd ); 75 | } 76 | + if ( (pAttrData != NULL) ) 77 | + { 78 | + osal_mem_free( pAttrData ); 79 | + } 80 | } 81 | } 82 | 83 | -- 84 | 2.24.2 (Apple Git-127) 85 | 86 | -------------------------------------------------------------------------------- /README_FREEPAD_v2.md: -------------------------------------------------------------------------------- 1 | ![](/images/orig-freepad/v2/19.jpg) 2 | 3 | The first version of the Zigbee remote control is good, but this option is not suitable when mobility is needed. For this reason, a second version appeared, in which Jager tried to make a more compact version. 4 | 5 | Since 20 buttons are not always and not always needed, Jager had to come up with a board design that allows you to assemble 3 versions of remotes, for 20, 12, and 8 buttons. The following is a process with pictures and short explanations. 6 | 7 | The circuit is almost identical to the first version 8 | ![](/images/orig-freepad/v2/0.jpg) 9 | 10 | using the Zigbee module from EBYTE E18-MS1-PCB 11 | ![](/images/orig-freepad/v2/1.jpg) 12 | 13 | compact buttons 3x4x2 mm 14 | ![](/images/orig-freepad/v2/2.jpg) 15 | 16 | The board is wired in DiTrace 17 | ![](/images/orig-freepad/v2/3.jpg) 18 | Note that the contact pads for the buttons are not designed for 4 pin buttons, as it might seem, these are options for a different offset from the center, due to the design of the case. 19 | 20 | Perforation is clearly visible on the renders, in these places unnecessary buttons are “broken off”. The very idea of ​​separating the excess is certainly not new, but those restrictions are imposed on the flight of thought. manufacturer's conditions. Instead of cutouts, Jager had to make holes with a diameter of 0.3 mm. 21 | ![](/images/orig-freepad/v2/4.jpg) 22 | 23 | Boards ordered in JLCPCB 24 | ![](/images/orig-freepad/v2/5.jpg) 25 | 26 | Minimum soldering 27 | ![](/images/orig-freepad/v2/6.jpg) 28 | 29 | Made a variant of the case for eight buttons in the form of a keychain. 30 | ![](/images/orig-freepad/v2/7.jpg) 31 | ![](/images/orig-freepad/v2/8.jpg) 32 | ![](/images/orig-freepad/v2/9.jpg) 33 | ![](/images/orig-freepad/v2/10.jpg) 34 | 35 | The general idea is this, the insert on top of the board allows you to distribute the force over a larger area 36 | ![](/images/orig-freepad/v2/11.jpg) 37 | 38 | Printed on 3d printer 39 | ![](/images/orig-freepad/v2/12.jpg) 40 | 41 | First tried on 42 | ![](/images/orig-freepad/v2/13.jpg) 43 | 44 | The keyboard 45 | ![](/images/orig-freepad/v2/14.jpg) 46 | 47 | Different colors 48 | ![](/images/orig-freepad/v2/15.jpg) 49 | 50 | Lamination will protect the paper keyboard 51 | 52 | ![](/images/orig-freepad/v2/16.jpg) 53 | 54 | Remains only to cut and try 55 | ![](/images/orig-freepad/v2/17.jpg) 56 | ![](/images/orig-freepad/v2/18.jpg) 57 | 58 | In scale 59 | ![](/images/orig-freepad/v2/19.jpg) 60 | ![](/images/orig-freepad/v2/20.jpg) 61 | 62 | Compared to first version 63 | ![](/images/orig-freepad/v2/21.jpg) 64 | 65 | From the software point of view, the consoles are identical. 66 | 67 | @anonymass has written a open source firmware. The firmware has a lot of options, binding, multi-click, etc. High stability and speed. 68 | 69 | @nick7zmail repeated the construction, making the original keyboard 70 | ![](/images/orig-freepad/v2/22.jpg) 71 | 72 | but he did not stop there and made various housing options, for 8, 12, and 20 buttons. 73 | ![](/images/orig-freepad/v2/23.jpg) 74 | 75 | @Madjestik58 designed and manufactured his version of the 4 button remote all necessary files for manufacturing are included. 76 | ![](/images/orig-freepad/v2/24.png) 77 | 78 | 79 | Another version of the case for the keypad from obihoernchen 80 | ![](/images/orig-freepad/v2/25.png) 81 | 82 | ### What's button mapping? 83 | ![](/images/orig-freepad/v2/zigbee_keypad22.png) 84 | 85 | ### Files to reproduce 86 | * [Gerbers and STL for 8 button](https://github.com/diyruz/freepad/hardware/v2) by [Jager](https://t.me/Jager_f) 87 | * [EasyEDA and STL for 4 button](https://github.com/diyruz/freepad/hardware/4_buttons) by [@Madjestik58](https://t.me/Madjestik58) 88 | * [Housing for 8, 12 and 20 buttons](https://www.thingiverse.com/thing:4161582) by [@nick7zmail](https://connect.smartliving.ru/profile/225) 89 | * [Housing for 20 buttons](https://www.thingiverse.com/thing:4668986) by [obihoernchen](https://www.thingiverse.com/obihoernchen) 90 | * [Firmware](https://github.com/diyruz/freepad/releases) by [@anonymass](https://t.me/anonymass) 91 | choose firmware hex file __without LeTV__ suffix 92 | 93 | [Original post by Jager](https://modkam.ru/?p=1264) 94 | -------------------------------------------------------------------------------- /README_FREEPAD_v1.md: -------------------------------------------------------------------------------- 1 | ![](/images/orig-freepad/v1/14.jpg) 2 | 3 | This is a kind of universal remote control, which displays the most frequently used functions in a particular room. This can be lighting control, multimedia equipment, various UD scenarios, etc. 4 | 5 | This remote control will live in the kitchen, the icons show that it will be possible to control the light, hood, music, set the timer. 6 | 7 | The device is based on a module from EBYTE E18-MS1-PCB or E18-MS1PA1-PCB if an increased communication range is required. 8 | ![](/images/orig-freepad/v2/1.jpg) 9 | The advantages of this module are cheapness and ultra-low consumption, 0.4 μA in deep sleep mode. 10 | 11 | The scheme uses a matrix of 20 buttons. The remote control is powered by one CR2032 element if a 2.5mW module is used, and from two elements via an LDO when using a 100mW module. There is also a LED and a buzzer on the diagram to indicate both the actual operation of the buttons and the display of service modes. 12 | ![](/images/orig-freepad/v1/0.png) 13 | 14 | The dimensions of the device are determined by buttons 12x12x7.3 mm with transparent covers, I must say on AliExpress, their choice is very limited and this is practically the only option. There is a version with contacts for surface mounting. , but you can also use such as in the picture, it is enough to "bite off" the legs flush with the body. 15 | ![](/images/orig-freepad/v1/1.jpg) 16 | 17 | The board was spread in DipTrace 18 | ![](/images/orig-freepad/v1/2.jpg) 19 | 20 | Virtual result 21 | ![](/images/orig-freepad/v1/3.jpg) 22 | ![](/images/orig-freepad/v1/4.jpg) 23 | Satisfied with the result, Jager place an order for the boards. 24 | 25 | While the boards are being manufactured, Jager engaged in the case, 26 | ![](/images/orig-freepad/v1/5.jpg) 27 | ![](/images/orig-freepad/v1/6.png) 28 | 29 | Then print on a 3D printer. For fastening to a metal surface, magnets 9 x 1.5 mm are provided, with an effort they snap into place. Fastening the board with M3x5 screws. 30 | ![](/images/orig-freepad/v1/7.jpg) 31 | 32 | The upper part can also be printed, but it is much more aesthetically pleasing to cut out with a laser from plexiglass. Light transmittance 2%, enough to see the glow of the LED and hide the insides, 3mm thick. Held in place by friction. 33 | ![](/images/orig-freepad/v1/8.jpg) 34 | 35 | Printed pictograms for buttons 36 | ![](/images/orig-freepad/v1/9.jpg) 37 | 38 | The boards are ready 39 | ![](/images/orig-freepad/v1/10.jpg) 40 | 41 | a little soldering 42 | ![](/images/orig-freepad/v1/11.jpg) 43 | 44 | and can be assembled for size estimation, 45 | ![](/images/orig-freepad/v1/12.jpg) 46 | ![](/images/orig-freepad/v1/13.jpg) 47 | 48 | in comparison with the IKEA TRÅDFRI remote control 49 | ![](/images/orig-freepad/v1/14.jpg) 50 | 51 | element AA 52 | ![](/images/orig-freepad/v1/15.jpg) 53 | 54 | Variant of fastening to a metal surface 55 | ![](/images/orig-freepad/v1/16.jpg) 56 | 57 | The original firmware was written by Vladislav @DJONvl, support in the ioBroker driver was provided by Kirov Ilya @goofyk, for which special thanks to them. 58 | ![](/images/orig-freepad/v1/17.jpg) 59 | 60 | Consumption corresponds to the one declared by the manufacturer, which will allow the remote control to work from one CR2032 element from 1 to 2 years. 61 | ![](/images/orig-freepad/v1/18.jpg) 62 | 63 | The firmware implements both light and sound indications of pressing. There is a network presence control (if the device is out of the network, pressing the buttons is not confirmed by light and sound). Work on the functionality of the firmware continues, possibly binding, and other options will appear. 64 | 65 | @anonymass has written a new open-source firmware. The firmware added a lot of new options, binding, multi-click, etc. Significantly improved stability and speed. 66 | 67 | @Madjestik58 made his version of the case using other buttons, 12x12 5mm high. It turned out great! 68 | 69 | ![](/images/orig-freepad/v1/19.jpg) 70 | 71 | ### What's button mapping? 72 | ![](/images/orig-freepad/v1/20.jpg) 73 | 74 | ### Files to reproduce 75 | * [Gerbers, STL, DXF](https://github.com/diyruz/freepad/hardware/v2) by [Jager](https://t.me/Jager_f) 76 | 77 | * [Another housing](https://www.thingiverse.com/thing:4256330) by [@Madjestik58](https://t.me/Madjestik58) 78 | 79 | * [NEW firmware](https://github.com/diyruz/freepad/releases) by [@anonymass](https://t.me/anonymass) 80 | choose firmware hex file __without LeTV__ suffix 81 | 82 | * [OLD original firmware hex](https://github.com/diyruz/freepad/hardware/v1/maxPW_key17setup_DIYRuZ_KEYPAD20.hex) by @DJONvl 83 | 84 | [Original post by Jager](https://modkam.ru/?p=1114) 85 | -------------------------------------------------------------------------------- /z2m-converter/DIYRuZ_FreePad.js: -------------------------------------------------------------------------------- 1 | const zigbeeHerdsmanConverters = require('zigbee-herdsman-converters'); 2 | const genMultistateInputClusterId = 18; 3 | 4 | const getKey = (object, value) => { 5 | for (const key in object) { 6 | if (object[key] == value) return key; 7 | } 8 | }; 9 | const bind = async (endpoint, target, clusters) => { 10 | for (const cluster of clusters) { 11 | await endpoint.bind(cluster, target); 12 | } 13 | }; 14 | 15 | const fz = { 16 | diyruz_freepad_clicks: { 17 | cluster: 'genMultistateInput', 18 | type: ['readResponse', 'attributeReport'], 19 | convert: (model, msg, publish, options, meta) => { 20 | const button = getKey(model.endpoint(msg.device), msg.endpoint.ID); 21 | const lookup = { 22 | 0: 'hold', 23 | 1: 'single', 24 | 2: 'double', 25 | 3: 'triple', 26 | 4: 'quadruple', 27 | 255: 'release', 28 | }; 29 | const clicks = msg.data['presentValue']; 30 | const action = lookup[clicks] ? lookup[clicks] : `many_${clicks}`; 31 | return { 32 | action: `${button}_${action}`, 33 | }; 34 | }, 35 | }, 36 | }; 37 | 38 | const tz = { 39 | diyruz_freepad_on_off_config: { 40 | key: ['switch_type', 'switch_actions'], 41 | convertSet: async (entity, key, value, meta) => { 42 | const switchTypesLookup = { 43 | toggle: 0x00, 44 | momentary: 0x01, 45 | multifunction: 0x02, 46 | }; 47 | const switchActionsLookup = { 48 | on: 0x00, 49 | off: 0x01, 50 | toggle: 0x02, 51 | }; 52 | const intVal = parseInt(value, 10); 53 | const switchType = switchTypesLookup.hasOwnProperty(value) ? switchTypesLookup[value] : intVal; 54 | const switchActions = switchActionsLookup.hasOwnProperty(value) ? switchActionsLookup[value] : intVal; 55 | 56 | const payloads = { 57 | switch_type: { 58 | switchType, 59 | }, 60 | switch_actions: { 61 | switchActions, 62 | }, 63 | }; 64 | 65 | await entity.write('genOnOffSwitchCfg', payloads[key]); 66 | }, 67 | }, 68 | }; 69 | 70 | const device = { 71 | zigbeeModel: ['DIYRuZ_FreePad'], 72 | model: 'DIYRuZ_FreePad', 73 | vendor: 'DIYRuZ', 74 | description: '[DiY 8/12/20 button keypad](http://modkam.ru/?p=1114)', 75 | supports: 'single, double, triple, quadruple, many, hold/release', 76 | fromZigbee: [fz.diyruz_freepad_clicks, zigbeeHerdsmanConverters.fromZigbeeConverters.battery], 77 | toZigbee: [tz.diyruz_freepad_on_off_config, zigbeeHerdsmanConverters.toZigbeeConverters.factory_reset], 78 | meta: { 79 | configureKey: 1, 80 | }, 81 | configure: async (device, coordinatorEndpoint) => { 82 | const endpoint = device.getEndpoint(1); 83 | await bind(endpoint, coordinatorEndpoint, ['genPowerCfg']); 84 | if (device.applicationVersion < 3) { //Legacy PM2 firmwares 85 | const payload = [{ 86 | attribute: 'batteryPercentageRemaining', 87 | minimumReportInterval: 0, 88 | maximumReportInterval: 3600, 89 | reportableChange: 0, 90 | }, { 91 | attribute: 'batteryVoltage', 92 | minimumReportInterval: 0, 93 | maximumReportInterval: 3600, 94 | reportableChange: 0, 95 | }]; 96 | await endpoint.configureReporting('genPowerCfg', payload); 97 | } 98 | 99 | 100 | device.endpoints.forEach(async (ep) => { 101 | if (ep.outputClusters.includes(genMultistateInputClusterId)) { 102 | await bind(ep, coordinatorEndpoint, ['genMultistateInput']); 103 | } 104 | }); 105 | }, 106 | endpoint: (device) => { 107 | return { 108 | button_1: 1, 109 | button_2: 2, 110 | button_3: 3, 111 | button_4: 4, 112 | button_5: 5, 113 | button_6: 6, 114 | button_7: 7, 115 | button_8: 8, 116 | button_9: 9, 117 | button_10: 10, 118 | button_11: 11, 119 | button_12: 12, 120 | button_13: 13, 121 | button_14: 14, 122 | button_15: 15, 123 | button_16: 16, 124 | button_17: 17, 125 | button_18: 18, 126 | button_19: 19, 127 | button_20: 20, 128 | }; 129 | }, 130 | }; 131 | 132 | module.exports = device; -------------------------------------------------------------------------------- /Source/f8wConfig.cfg: -------------------------------------------------------------------------------- 1 | /* 2 | * f8wConfig.cfg 3 | * 4 | * Compiler command-line options used to define a TI Z-Stack ZigBee device. 5 | * To move an option from here to the project file, comment out or delete the 6 | * option from this file and enter it into the "Define Symbols" box under the 7 | * Preprocessor tab of the C/C++ Compiler Project Options. New user defined 8 | * options may be added to this file, as necessary. 9 | * 10 | * Each macro is prefixed with '-D'. The entries are to be constructed as if 11 | * they are to be on the compiler command line invocation (which they are). 12 | * 13 | * NOTE: The RHS (Right-Hand-Side) must be quoted if there are embedded blanks. 14 | * See the DEFAULT_KEY definition for an example. 15 | */ 16 | 17 | /* Enable ZigBee-Pro */ 18 | -DZIGBEEPRO 19 | 20 | /* Set to 1 to enable security. To disable set to 0 */ 21 | -DSECURE=1 22 | -DZG_SECURE_DYNAMIC=0 23 | 24 | /* Enable the Reflector */ 25 | -DREFLECTOR 26 | 27 | /* Default channel is Channel 11 - 0x0B */ 28 | // Channels are defined in the following: 29 | // 0 : 868 MHz 0x00000001 30 | // 1 - 10 : 915 MHz 0x000007FE 31 | // 11 - 26 : 2.4 GHz 0x07FFF800 32 | // 33 | //-DMAX_CHANNELS_868MHZ 0x00000001 34 | //-DMAX_CHANNELS_915MHZ 0x000007FE 35 | //-DMAX_CHANNELS_24GHZ 0x07FFF800 36 | //-DDEFAULT_CHANLIST=0x04000000 // 26 - 0x1A 37 | //-DDEFAULT_CHANLIST=0x02000000 // 25 - 0x19 38 | //-DDEFAULT_CHANLIST=0x01000000 // 24 - 0x18 39 | //-DDEFAULT_CHANLIST=0x00800000 // 23 - 0x17 40 | //-DDEFAULT_CHANLIST=0x00400000 // 22 - 0x16 41 | //-DDEFAULT_CHANLIST=0x00200000 // 21 - 0x15 42 | //-DDEFAULT_CHANLIST=0x00100000 // 20 - 0x14 43 | //-DDEFAULT_CHANLIST=0x00080000 // 19 - 0x13 44 | //-DDEFAULT_CHANLIST=0x00040000 // 18 - 0x12 45 | //-DDEFAULT_CHANLIST=0x00020000 // 17 - 0x11 46 | //-DDEFAULT_CHANLIST=0x00010000 // 16 - 0x10 47 | //-DDEFAULT_CHANLIST=0x00008000 // 15 - 0x0F 48 | //-DDEFAULT_CHANLIST=0x00004000 // 14 - 0x0E 49 | //-DDEFAULT_CHANLIST=0x00002000 // 13 - 0x0D 50 | //-DDEFAULT_CHANLIST=0x00001000 // 12 - 0x0C 51 | -DDEFAULT_CHANLIST=0x07FFF800 // all 52 | 53 | /* Define the default PAN ID. 54 | * 55 | * Setting this to a value other than 0xFFFF causes 56 | * ZDO_COORD to use this value as its PAN ID and 57 | * Routers and end devices to join PAN with this ID 58 | */ 59 | -DZDAPP_CONFIG_PAN_ID=0xFFFF 60 | 61 | /* Minimum number of milliseconds to hold off the start of the device 62 | * in the network and the minimum delay between joining cycles. 63 | */ 64 | -DNWK_START_DELAY=100 65 | 66 | /* Mask for the random joining delay. This value is masked with 67 | * the return from osal_rand() to get a random delay time for 68 | * each joining cycle. This random value is added to NWK_START_DELAY. 69 | * For example, a value of 0x007F will be a joining delay of 0 to 127 70 | * milliseconds. 71 | */ 72 | -DEXTENDED_JOINING_RANDOM_MASK=0x007F 73 | 74 | /* Minimum number of milliseconds to delay between each beacon request 75 | * in a joining cycle. 76 | */ 77 | -DBEACON_REQUEST_DELAY=100 78 | 79 | /* Mask for the random beacon request delay. This value is masked with the 80 | * return from osal_rand() to get a random delay time for each joining cycle. 81 | * This random value is added to DBEACON_REQUEST_DELAY. For example, a value 82 | * of 0x00FF will be a beacon request delay of 0 to 255 milliseconds. 83 | */ 84 | -DBEACON_REQ_DELAY_MASK=0x00FF 85 | 86 | /* Jitter mask for the link status report timer. This value is masked with the 87 | * return from osal_rand() to add a random delay to _NIB.nwkLinkStatusPeriod. 88 | * For example, a value of 0x007F allows a jitter between 0-127 milliseconds. 89 | */ 90 | -DLINK_STATUS_JITTER_MASK=0x007F 91 | 92 | /* in seconds; set to 0 to turn off route expiry */ 93 | -DROUTE_EXPIRY_TIME=30 94 | 95 | /* This number is used by polled devices, since the spec'd formula 96 | * doesn't work for sleeping end devices. For non-polled devices, 97 | * a formula is used. Value is in 2 milliseconds periods 98 | */ 99 | -DAPSC_ACK_WAIT_DURATION_POLLED=3000 100 | 101 | /* Default indirect message holding timeout value: 102 | * 1-65535 (0 -> 65536) X CNT_RTG_TIMER X RTG_TIMER_INTERVAL 103 | */ 104 | -DNWK_INDIRECT_MSG_TIMEOUT=7 105 | 106 | /* The number of simultaneous route discoveries in network */ 107 | -DMAX_RREQ_ENTRIES=8 108 | 109 | /* The maximum number of retries allowed after a transmission failure */ 110 | -DAPSC_MAX_FRAME_RETRIES=3 111 | 112 | /* Max number of times retry looking for the next hop address of a message */ 113 | -DNWK_MAX_DATA_RETRIES=2 114 | 115 | /* Number of times retry to poll parent before indicating loss of synchronization 116 | * with parent. Note that larger value will cause longer delay for the child to 117 | * rejoin the network. 118 | */ 119 | -DMAX_POLL_FAILURE_RETRIES=2 120 | 121 | /* The number of items in the broadcast table */ 122 | -DMAX_BCAST=9 123 | 124 | /* The maximum number of groups in the groups table */ 125 | -DAPS_MAX_GROUPS=1 126 | 127 | /* Number of entries in the regular routing table plus additional 128 | * entries for route repair 129 | */ 130 | -DMAX_RTG_ENTRIES=40 131 | 132 | /* Maximum number of entries in the Binding table. */ 133 | -DNWK_MAX_BINDING_ENTRIES=40 134 | 135 | /* Maximum number of cluster IDs for each binding table entry. 136 | * Note that any value other than the default value may cause a 137 | * compilation warning but Device Binding will function correctly. 138 | */ 139 | -DMAX_BINDING_CLUSTER_IDS=4 140 | 141 | /* Default security key. */ 142 | -DDEFAULT_KEY="{0}" 143 | 144 | /* Reset when ASSERT occurs, otherwise flash LEDs */ 145 | //-DASSERT_RESET 146 | 147 | /* Set the MAC MAX Frame Size (802.15.4 default is 102) */ 148 | -DMAC_MAX_FRAME_SIZE=116 149 | 150 | /* Minimum transmissions attempted for Channel Interference detection, 151 | * Frequency Agility can be disabled by setting this parameter to zero. 152 | */ 153 | -DZDNWKMGR_MIN_TRANSMISSIONS=20 154 | 155 | /* Compiler keywords */ 156 | -DCONST="const __code" 157 | -DGENERIC=__generic 158 | 159 | /**************************************** 160 | * The following are for End Devices only 161 | ***************************************/ 162 | 163 | -DRFD_RCVC_ALWAYS_ON=FALSE 164 | 165 | /* The number of milliseconds to wait between data request polls to the coordinator. */ 166 | -DPOLL_RATE=1000 167 | 168 | /* This is used after receiving a data indication to poll immediately 169 | * for queued messages...in milliseconds. 170 | */ 171 | -DQUEUED_POLL_RATE=100 172 | 173 | /* This is used after receiving a data confirmation to poll immediately 174 | * for response messages...in milliseconds 175 | */ 176 | -DRESPONSE_POLL_RATE=100 177 | 178 | /* This is used as an alternate response poll rate only for rejoin request. 179 | * This rate is determined by the response time of the parent that the device 180 | * is trying to join. 181 | */ 182 | -DREJOIN_POLL_RATE=440 183 | 184 | /* Rejoin retry backoff silent period timer duration in milliseconds - default 15 minutes according to HA test spec */ 185 | -DREJOIN_BACKOFF=900000 186 | 187 | /* Rejoin retry backoff scan timer duration in milliseconds - default 15 minutes according to HA test spec */ 188 | -DREJOIN_SCAN=900000 189 | 190 | /* Latest sample apps use LED4 and do not use S1 switch */ 191 | -DENABLE_LED4_DISABLE_S1 192 | -------------------------------------------------------------------------------- /Source/hal_key.c: -------------------------------------------------------------------------------- 1 | /************************************************************************************************** 2 | * INCLUDES 3 | **************************************************************************************************/ 4 | #include "hal_key.h" 5 | #include "Debug.h" 6 | #include "hal_adc.h" 7 | #include "hal_defs.h" 8 | #include "hal_drivers.h" 9 | #include "hal_led.h" 10 | #include "hal_mcu.h" 11 | #include "hal_types.h" 12 | #include "osal.h" 13 | #include 14 | 15 | /************************************************************************************************** 16 | * MACROS 17 | **************************************************************************************************/ 18 | 19 | /************************************************************************************************** 20 | * CONSTANTS 21 | **************************************************************************************************/ 22 | 23 | #define HAL_KEY_BIT0 0x01 24 | #define HAL_KEY_BIT1 0x02 25 | #define HAL_KEY_BIT2 0x04 26 | #define HAL_KEY_BIT3 0x08 27 | #define HAL_KEY_BIT4 0x10 28 | #define HAL_KEY_BIT5 0x20 29 | #define HAL_KEY_BIT6 0x40 30 | #define HAL_KEY_BIT7 0x80 31 | 32 | #define HAL_KEY_RISING_EDGE 0 33 | #define HAL_KEY_FALLING_EDGE 1 34 | 35 | #define HAL_KEY_DEBOUNCE_VALUE 25 // TODO: adjust this value 36 | 37 | #if defined(HAL_BOARD_FREEPAD) 38 | #define HAL_KEY_P0_GPIO_PINS (HAL_KEY_BIT2 | HAL_KEY_BIT3 | HAL_KEY_BIT4 | HAL_KEY_BIT5 | HAL_KEY_BIT6) 39 | #define HAL_KEY_P0_INPUT_PINS (HAL_KEY_BIT2 | HAL_KEY_BIT3 | HAL_KEY_BIT4 | HAL_KEY_BIT5 | HAL_KEY_BIT6) 40 | 41 | #elif defined(HAL_BOARD_LETV) 42 | #define HAL_KEY_P0_GPIO_PINS (HAL_KEY_BIT0 | HAL_KEY_BIT1 | HAL_KEY_BIT2 | HAL_KEY_BIT3 | HAL_KEY_BIT4 | HAL_KEY_BIT5 | HAL_KEY_BIT6 | HAL_KEY_BIT7) 43 | #define HAL_KEY_P1_GPIO_PINS 0x00 44 | #define HAL_KEY_P2_GPIO_PINS 0x00 45 | 46 | #define HAL_KEY_P0_INPUT_PINS (HAL_KEY_BIT0 | HAL_KEY_BIT1 | HAL_KEY_BIT2 | HAL_KEY_BIT3 | HAL_KEY_BIT4 | HAL_KEY_BIT5 | HAL_KEY_BIT6 | HAL_KEY_BIT7) 47 | #define HAL_KEY_P1_INPUT_PINS 0x00 48 | #define HAL_KEY_P2_INPUT_PINS 0x00 49 | 50 | #define HAL_KEY_P0_INTERRUPT_PINS (HAL_KEY_BIT0 | HAL_KEY_BIT1 | HAL_KEY_BIT2 | HAL_KEY_BIT3 | HAL_KEY_BIT4 | HAL_KEY_BIT5 | HAL_KEY_BIT6 | HAL_KEY_BIT7) 51 | #define HAL_KEY_P1_INTERRUPT_PINS 0x00 52 | #define HAL_KEY_P2_INTERRUPT_PINS 0x00 53 | 54 | #elif defined(HAL_BOARD_CHDTECH_DEV) 55 | #define HAL_KEY_P0_GPIO_PINS (HAL_KEY_BIT1) 56 | #define HAL_KEY_P1_GPIO_PINS 0x00 57 | #define HAL_KEY_P2_GPIO_PINS (HAL_KEY_BIT0) 58 | 59 | #define HAL_KEY_P0_INPUT_PINS (HAL_KEY_BIT1) 60 | #define HAL_KEY_P1_INPUT_PINS 0x00 61 | #define HAL_KEY_P2_INPUT_PINS (HAL_KEY_BIT0) 62 | 63 | #define HAL_KEY_P0_INTERRUPT_PINS (HAL_KEY_BIT1) 64 | #define HAL_KEY_P1_INTERRUPT_PINS 0x00 65 | #define HAL_KEY_P2_INTERRUPT_PINS (HAL_KEY_BIT0) 66 | #endif 67 | 68 | #if defined(HAL_BOARD_FREEPAD) 69 | #define HAL_KEY_P1_GPIO_PINS (HAL_KEY_BIT2 | HAL_KEY_BIT3 | HAL_KEY_BIT4 | HAL_KEY_BIT5) 70 | #define HAL_KEY_P2_GPIO_PINS 0x00 71 | 72 | #define HAL_KEY_P1_INPUT_PINS (HAL_KEY_BIT2 | HAL_KEY_BIT3 | HAL_KEY_BIT4 | HAL_KEY_BIT5) 73 | 74 | #define HAL_KEY_P0_INTERRUPT_PINS HAL_KEY_P0_INPUT_PINS 75 | #define HAL_KEY_P1_INTERRUPT_PINS 0x00 76 | 77 | #define HAL_KEY_P2_INTERRUPT_PINS 0x00 78 | #endif 79 | 80 | /************************************************************************************************** 81 | * TYPEDEFS 82 | **************************************************************************************************/ 83 | 84 | /************************************************************************************************** 85 | * GLOBAL VARIABLES 86 | **************************************************************************************************/ 87 | static halKeyCBack_t pHalKeyProcessFunction; 88 | bool Hal_KeyIntEnable; 89 | 90 | uint8 halSaveIntKey; /* used by ISR to save state of interrupt-driven keys */ 91 | 92 | static uint8 halKeyTimerRunning; // Set to true while polling timer is running in interrupt 93 | // enabled mode 94 | 95 | /************************************************************************************************** 96 | * FUNCTIONS - Local 97 | **************************************************************************************************/ 98 | void halProcessKeyInterrupt(void); 99 | 100 | void HalKeyInit(void) { 101 | P0SEL &= ~HAL_KEY_P0_GPIO_PINS; 102 | P1SEL &= ~HAL_KEY_P1_GPIO_PINS; 103 | P2SEL &= ~HAL_KEY_P2_GPIO_PINS; 104 | 105 | #if defined(HAL_BOARD_FREEPAD) 106 | /** 107 | * columns (p1) 108 | **/ 109 | 110 | P1DIR |= HAL_KEY_P1_INPUT_PINS; // set as output 111 | P1 |= HAL_KEY_P1_INPUT_PINS; // set high 112 | P1INP |= HAL_KEY_P1_INPUT_PINS; // set tri state 113 | //////////////////////////////////////////// 114 | /** 115 | * row pins 116 | **/ 117 | 118 | P0DIR &= ~HAL_KEY_P0_INPUT_PINS; // set input 119 | P0INP &= ~HAL_KEY_P0_INPUT_PINS; // pull pins 120 | P2INP |= HAL_KEY_BIT5; // pull down port0 121 | HAL_BOARD_DELAY_USEC(50); 122 | 123 | #elif defined(HAL_BOARD_LETV) 124 | P0DIR &= ~(HAL_KEY_P0_INPUT_PINS); 125 | P1DIR &= ~(HAL_KEY_P1_INPUT_PINS); 126 | P2DIR &= ~(HAL_KEY_P2_INPUT_PINS); 127 | 128 | #elif defined(HAL_BOARD_CHDTECH_DEV) 129 | P0DIR &= ~(HAL_KEY_P0_INPUT_PINS); 130 | P1DIR &= ~(HAL_KEY_P1_INPUT_PINS); 131 | P2DIR &= ~(HAL_KEY_P2_INPUT_PINS); 132 | 133 | #endif 134 | pHalKeyProcessFunction = NULL; 135 | 136 | halKeyTimerRunning = FALSE; 137 | } 138 | 139 | void HalKeyConfig(bool interruptEnable, halKeyCBack_t cback) { 140 | Hal_KeyIntEnable = true; 141 | pHalKeyProcessFunction = cback; 142 | P0IEN |= HAL_KEY_P0_INTERRUPT_PINS; 143 | P1IEN |= HAL_KEY_P1_INTERRUPT_PINS; 144 | P2IEN |= HAL_KEY_P2_INTERRUPT_PINS; 145 | #if defined(HAL_BOARD_FREEPAD) 146 | PICTL &= ~HAL_KEY_BIT0; // set rising edge on port 0 147 | // enable intrupt on row pins 148 | IEN1 |= HAL_KEY_BIT5; // enable port0 int 149 | 150 | #elif defined(HAL_BOARD_LETV) 151 | PICTL |= HAL_KEY_BIT0; // set falling edge on port 0 152 | IEN1 |= HAL_KEY_BIT5; // enable port0 int 153 | 154 | #elif defined(HAL_BOARD_CHDTECH_DEV) 155 | PICTL |= HAL_KEY_BIT0 | HAL_KEY_BIT3; // set falling edge on port 0 and 2 156 | IEN1 |= HAL_KEY_BIT5; // enable port0 int 157 | IEN2 |= HAL_KEY_BIT1; // enable port2 int 158 | 159 | #endif 160 | } 161 | uint8 HalKeyRead(void) { 162 | 163 | uint8 key = HAL_KEY_CODE_NOKEY; 164 | #if defined(HAL_BOARD_FREEPAD) 165 | uint8 row, col; 166 | row = P0 & HAL_KEY_P0_INPUT_PINS; 167 | 168 | if (row) { 169 | // row is 0x8, 0x10, 0x20, 0x40 or , 0x80 depending on row that is pressed 170 | // Now find out which col it was by changing row IO's to input and driving 171 | // the col IO's as O/P. 172 | col = 0; 173 | // set pull downs on col pins 174 | 175 | // P1 &= ~HAL_KEY_P1_INPUT_PINS; 176 | P1DIR &= ~HAL_KEY_P1_INPUT_PINS; // set p1 as input 177 | P1INP &= ~HAL_KEY_P1_INPUT_PINS; // set as pull pins 178 | P2INP |= HAL_KEY_BIT6; // pull down port1 179 | 180 | // P1 &= ~HAL_KEY_P1_INPUT_PINS; //set low on p1 pins 181 | 182 | P0INP |= HAL_KEY_P0_INPUT_PINS; // set as tri state 183 | P0DIR |= HAL_KEY_P0_INPUT_PINS; // set p0 as output 184 | P0 |= HAL_KEY_P0_INPUT_PINS; // set high on p0 185 | 186 | HAL_BOARD_DELAY_USEC(50); 187 | 188 | col = P1 & HAL_KEY_P1_INPUT_PINS; 189 | 190 | // set P0:0-2 as output - high ready for next press 191 | P1DIR |= HAL_KEY_P1_INPUT_PINS; // set as output 192 | P1 |= HAL_KEY_P1_INPUT_PINS; // set high 193 | // all pulls tri-states 194 | P1INP |= HAL_KEY_P1_INPUT_PINS; // set tri state 195 | 196 | P0DIR &= ~HAL_KEY_P0_INPUT_PINS; // set input 197 | P0INP &= ~HAL_KEY_P0_INPUT_PINS; // pull pins 198 | P2INP |= HAL_KEY_BIT5; // pull down port0 199 | 200 | key = (((row << 2) | col >> 1)) >> 1; 201 | } 202 | // LREP("row %d col %d key 0x%X %d \r\n", row, col, key, key); 203 | 204 | #elif defined(HAL_BOARD_LETV) 205 | 206 | if (ACTIVE_LOW(P0 & HAL_KEY_BIT0)) { 207 | key = 0x01; // P00 208 | } 209 | if (ACTIVE_LOW(P0 & HAL_KEY_BIT1)) { 210 | key = 0x02; // P01 211 | } 212 | if (ACTIVE_LOW(P0 & HAL_KEY_BIT2)) { 213 | key = 0x03; // P02 214 | } 215 | if (ACTIVE_LOW(P0 & HAL_KEY_BIT3)) { 216 | key = 0x04; // P03 217 | } 218 | if (ACTIVE_LOW(P0 & HAL_KEY_BIT4)) { 219 | key = 0x05; // P04 220 | } 221 | if (ACTIVE_LOW(P0 & HAL_KEY_BIT5)) { 222 | key = 0x06; // P05 223 | } 224 | if (ACTIVE_LOW(P0 & HAL_KEY_BIT6)) { 225 | key = 0x07; // P06 226 | } 227 | if (ACTIVE_LOW(P0 & HAL_KEY_BIT7)) { 228 | key = 0x08; // P07 229 | } 230 | 231 | #elif defined(HAL_BOARD_CHDTECH_DEV) 232 | 233 | if (ACTIVE_LOW(P0 & HAL_KEY_P0_INPUT_PINS)) { 234 | key = 0x01; 235 | } 236 | 237 | if (ACTIVE_LOW(P2 & HAL_KEY_P2_INPUT_PINS)) { 238 | key = 0x02; 239 | } 240 | 241 | #endif 242 | 243 | return key; 244 | } 245 | void HalKeyPoll(void) { 246 | uint8 keys = 0; 247 | 248 | keys = HalKeyRead(); 249 | 250 | if (pHalKeyProcessFunction) { 251 | (pHalKeyProcessFunction)(keys, HAL_KEY_STATE_NORMAL); 252 | } 253 | 254 | if (keys != HAL_KEY_CODE_NOKEY) { 255 | osal_start_timerEx(Hal_TaskID, HAL_KEY_EVENT, 200); 256 | } else { 257 | halKeyTimerRunning = FALSE; 258 | } 259 | } 260 | void halProcessKeyInterrupt(void) { 261 | if (!halKeyTimerRunning) { 262 | halKeyTimerRunning = TRUE; 263 | osal_start_timerEx(Hal_TaskID, HAL_KEY_EVENT, HAL_KEY_DEBOUNCE_VALUE); 264 | } 265 | } 266 | 267 | void HalKeyEnterSleep(void) { 268 | uint8 clkcmd = CLKCONCMD; 269 | uint8 clksta = CLKCONSTA; 270 | // Switch to 16MHz before setting the DC/DC to bypass to reduce risk of flash corruption 271 | CLKCONCMD = (CLKCONCMD_16MHZ | OSC_32KHZ); 272 | // wait till clock speed stablizes 273 | while (CLKCONSTA != (CLKCONCMD_16MHZ | OSC_32KHZ)) 274 | ; 275 | 276 | CLKCONCMD = clkcmd; 277 | while (CLKCONSTA != (clksta)) 278 | ; 279 | } 280 | 281 | uint8 HalKeyExitSleep(void) { 282 | uint8 clkcmd = CLKCONCMD; 283 | // Switch to 16MHz before setting the DC/DC to on to reduce risk of flash corruption 284 | CLKCONCMD = (CLKCONCMD_16MHZ | OSC_32KHZ); 285 | // wait till clock speed stablizes 286 | while (CLKCONSTA != (CLKCONCMD_16MHZ | OSC_32KHZ)) 287 | ; 288 | 289 | CLKCONCMD = clkcmd; 290 | 291 | /* Wake up and read keys */ 292 | return (HalKeyRead()); 293 | } 294 | 295 | HAL_ISR_FUNCTION(halKeyPort0Isr, P0INT_VECTOR) { 296 | HAL_ENTER_ISR(); 297 | 298 | if (P0IFG & HAL_KEY_P0_INTERRUPT_PINS) { 299 | halProcessKeyInterrupt(); 300 | } 301 | 302 | P0IFG &= ~HAL_KEY_P0_INTERRUPT_PINS; 303 | P0IF = 0; 304 | 305 | CLEAR_SLEEP_MODE(); 306 | HAL_EXIT_ISR(); 307 | } 308 | 309 | HAL_ISR_FUNCTION(halKeyPort1Isr, P1INT_VECTOR) { 310 | HAL_ENTER_ISR(); 311 | 312 | if (P1IFG & HAL_KEY_P1_INTERRUPT_PINS) { 313 | halProcessKeyInterrupt(); 314 | } 315 | 316 | P1IFG &= ~HAL_KEY_P1_INTERRUPT_PINS; 317 | P1IF = 0; 318 | 319 | CLEAR_SLEEP_MODE(); 320 | HAL_EXIT_ISR(); 321 | } 322 | 323 | HAL_ISR_FUNCTION(halKeyPort2Isr, P2INT_VECTOR) { 324 | HAL_ENTER_ISR(); 325 | 326 | if (P2IFG & HAL_KEY_P2_INTERRUPT_PINS) { 327 | halProcessKeyInterrupt(); 328 | } 329 | 330 | P2IFG &= ~HAL_KEY_P2_INTERRUPT_PINS; 331 | P2IF = 0; 332 | 333 | CLEAR_SLEEP_MODE(); 334 | HAL_EXIT_ISR(); 335 | } -------------------------------------------------------------------------------- /Source/zcl_freepadapp_data.c: -------------------------------------------------------------------------------- 1 | #include "AF.h" 2 | #include "OSAL.h" 3 | #include "ZComDef.h" 4 | #include "ZDConfig.h" 5 | 6 | #include "zcl.h" 7 | #include "zcl_general.h" 8 | #include "zcl_ha.h" 9 | 10 | #include "zcl_freepadapp.h" 11 | 12 | #include "battery.h" 13 | #include "version.h" 14 | /********************************************************************* 15 | * CONSTANTS 16 | */ 17 | #define FREEPADAPP_DEVICE_VERSION 2 18 | 19 | #define FREEPADAPP_FLAGS 0 20 | 21 | #define FREEPADAPP_HWVERSION 1 22 | #define FREEPADAPP_ZCLVERSION 1 23 | 24 | /********************************************************************* 25 | * TYPEDEFS 26 | */ 27 | 28 | /********************************************************************* 29 | * MACROS 30 | */ 31 | 32 | /********************************************************************* 33 | * GLOBAL VARIABLES 34 | */ 35 | 36 | // Global attributes 37 | const uint16 zclFreePadApp_clusterRevision_all = 0x0001; 38 | 39 | // Basic Cluster 40 | const uint8 zclFreePadApp_HWRevision = FREEPADAPP_HWVERSION; 41 | const uint8 zclFreePadApp_ZCLVersion = FREEPADAPP_ZCLVERSION; 42 | 43 | #if BDB_REPORTING 44 | const uint8 zclFreePadApp_ApplicationVersion = 2; 45 | #else 46 | const uint8 zclFreePadApp_ApplicationVersion = 3; 47 | #endif 48 | const uint8 zclFreePadApp_StackVersion = 4; 49 | 50 | //{lenght, 'd', 'a', 't', 'a'} 51 | const uint8 zclFreePadApp_ManufacturerName[] = {9, 'm', 'o', 'd', 'k', 'a', 'm', '.', 'r', 'u'}; 52 | #if defined(HAL_BOARD_LETV) 53 | const uint8 zclFreePadApp_ModelId[] = {14, 'F', 'r', 'e', 'e', 'P', 'a', 'd', '_', 'L', 'e', 'T', 'V', '_', '8'}; 54 | #else 55 | const uint8 zclFreePadApp_ModelId[] = {14, 'D', 'I', 'Y', 'R', 'u', 'Z', '_', 'F', 'r', 'e', 'e', 'P', 'a', 'd'}; 56 | #endif 57 | 58 | const uint8 zclFreePadApp_PowerSource = POWER_SOURCE_BATTERY; 59 | 60 | uint8 zclFreePadApp_SwitchActions[FREEPAD_BUTTONS_COUNT]; 61 | uint8 zclFreePadApp_SwitchTypes[FREEPAD_BUTTONS_COUNT]; 62 | 63 | /********************************************************************* 64 | * ATTRIBUTE DEFINITIONS - Uses REAL cluster IDs 65 | */ 66 | #define R ACCESS_CONTROL_READ 67 | #define RR R | ACCESS_REPORTABLE 68 | #define RW (R | ACCESS_CONTROL_WRITE | ACCESS_CONTROL_AUTH_WRITE) 69 | #define BASIC ZCL_CLUSTER_ID_GEN_BASIC 70 | #define POWER_CFG ZCL_CLUSTER_ID_GEN_POWER_CFG 71 | #define SWITCH_CONFIG ZCL_CLUSTER_ID_GEN_ON_OFF_SWITCH_CONFIG 72 | #define ON_OFF ZCL_CLUSTER_ID_GEN_ON_OFF 73 | #define MS_INP_BASIC ZCL_CLUSTER_ID_GEN_MULTISTATE_INPUT_BASIC 74 | #define ZCL_UINT8 ZCL_DATATYPE_UINT8 75 | 76 | 77 | CONST zclAttrRec_t zclFreePadApp_AttrsFirstEP[] = { 78 | {BASIC, {ATTRID_BASIC_ZCL_VERSION, ZCL_UINT8, R, (void *)&zclFreePadApp_ZCLVersion}}, 79 | {BASIC, {ATTRID_BASIC_APPL_VERSION, ZCL_UINT8, R, (void *)&zclFreePadApp_ApplicationVersion}}, 80 | {BASIC, {ATTRID_BASIC_STACK_VERSION, ZCL_UINT8, R, (void *)&zclFreePadApp_StackVersion}}, 81 | {BASIC, {ATTRID_BASIC_HW_VERSION, ZCL_UINT8, R, (void *)&zclFreePadApp_HWRevision}}, 82 | 83 | {BASIC, {ATTRID_BASIC_MANUFACTURER_NAME, ZCL_DATATYPE_CHAR_STR, R, (void *)zclFreePadApp_ManufacturerName}}, 84 | {BASIC, {ATTRID_BASIC_MODEL_ID, ZCL_DATATYPE_CHAR_STR, R, (void *)zclFreePadApp_ModelId}}, 85 | {BASIC, {ATTRID_BASIC_DATE_CODE, ZCL_DATATYPE_CHAR_STR, R, (void *)zclFreePadApp_DateCode}}, 86 | {BASIC, {ATTRID_BASIC_POWER_SOURCE, ZCL_DATATYPE_ENUM8, R, (void *)&zclFreePadApp_PowerSource}}, 87 | {BASIC, {ATTRID_BASIC_SW_BUILD_ID, ZCL_UINT8, R, (void *)&zclFreePadApp_ApplicationVersion}}, 88 | {BASIC, {ATTRID_CLUSTER_REVISION, ZCL_DATATYPE_UINT16, R, (void *)&zclFreePadApp_clusterRevision_all}}, 89 | {POWER_CFG, {ATTRID_POWER_CFG_BATTERY_VOLTAGE, ZCL_UINT8, RR, (void *)&zclBattery_Voltage}}, 90 | {POWER_CFG, {ATTRID_POWER_CFG_BATTERY_PERCENTAGE_REMAINING, ZCL_UINT8, RR, (void *)&zclBattery_PercentageRemainig}}, 91 | 92 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[0]}}, 93 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[0]}}}; 94 | 95 | CONST zclAttrRec_t zclFreePadApp_Attrs[][FREEPAD_ATTRS_COUNT] = { 96 | 97 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[1]}}, 98 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[1]}}}, 99 | 100 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[2]}}, 101 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[2]}}}, 102 | 103 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[3]}}, 104 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[3]}}}, 105 | 106 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[4]}}, 107 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[4]}}}, 108 | 109 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[5]}}, 110 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[5]}}}, 111 | 112 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[6]}}, 113 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[6]}}}, 114 | 115 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[7]}}, 116 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[7]}}}, 117 | 118 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[8]}}, 119 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[8]}}}, 120 | 121 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[9]}}, 122 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[9]}}}, 123 | 124 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[10]}}, 125 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[10]}}}, 126 | 127 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[11]}}, 128 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[11]}}}, 129 | 130 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[12]}}, 131 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[12]}}}, 132 | 133 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[13]}}, 134 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[13]}}}, 135 | 136 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[14]}}, 137 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[14]}}}, 138 | 139 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[15]}}, 140 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[15]}}}, 141 | 142 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[16]}}, 143 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[16]}}}, 144 | 145 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[17]}}, 146 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[17]}}}, 147 | 148 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[18]}}, 149 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[18]}}}, 150 | 151 | {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[19]}}, 152 | {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[19]}}} 153 | 154 | }; 155 | uint8 CONST zclFreePadApp_AttrsFirstEPCount = (sizeof(zclFreePadApp_AttrsFirstEP) / sizeof(zclFreePadApp_AttrsFirstEP[0])); 156 | 157 | const cId_t zclFreePadApp_InClusterList[] = {ZCL_CLUSTER_ID_GEN_BASIC}; 158 | 159 | #define FREEPAD_MAX_INCLUSTERS (sizeof(zclFreePadApp_InClusterList) / sizeof(zclFreePadApp_InClusterList[0])) 160 | 161 | const cId_t zclFreePadApp_OutClusterListOdd[] = {ON_OFF, MS_INP_BASIC}; 162 | const cId_t zclFreePadApp_OutClusterListNth14[] = {ON_OFF, MS_INP_BASIC, ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL, 163 | ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL}; 164 | const cId_t zclFreePadApp_OutClusterListEven[] = {ON_OFF, MS_INP_BASIC}; 165 | 166 | #define FREEPAD_MAX_OUTCLUSTERS_NTH14 (sizeof(zclFreePadApp_OutClusterListNth14) / sizeof(zclFreePadApp_OutClusterListNth14[0])) 167 | #define FREEPAD_MAX_OUTCLUSTERS_EVEN (sizeof(zclFreePadApp_OutClusterListEven) / sizeof(zclFreePadApp_OutClusterListEven[0])) 168 | #define FREEPAD_MAX_OUTCLUSTERS_ODD (sizeof(zclFreePadApp_OutClusterListOdd) / sizeof(zclFreePadApp_OutClusterListOdd[0])) 169 | 170 | SimpleDescriptionFormat_t zclFreePadApp_SimpleDescs[FREEPAD_BUTTONS_COUNT]; 171 | void zclFreePadApp_InitClusters(void) { 172 | for (uint8 i = 0; i < FREEPAD_BUTTONS_COUNT; i++) { 173 | uint8 endPoint = i + 1; 174 | zclFreePadApp_SimpleDescs[i].EndPoint = endPoint; 175 | zclFreePadApp_SimpleDescs[i].AppProfId = ZCL_HA_PROFILE_ID; 176 | zclFreePadApp_SimpleDescs[i].AppDeviceId = ZCL_HA_DEVICEID_REMOTE_CONTROL; 177 | zclFreePadApp_SimpleDescs[i].AppDevVer = FREEPADAPP_DEVICE_VERSION; 178 | zclFreePadApp_SimpleDescs[i].Reserved = FREEPADAPP_FLAGS; // AF_V1_SUPPORT uses for AppFlags:4. 179 | 180 | if (endPoint == 1) { 181 | zclFreePadApp_SimpleDescs[i].AppNumInClusters = FREEPAD_MAX_INCLUSTERS; 182 | zclFreePadApp_SimpleDescs[i].pAppInClusterList = (cId_t *)zclFreePadApp_InClusterList; 183 | } else { 184 | zclFreePadApp_SimpleDescs[i].AppNumInClusters = 0; 185 | zclFreePadApp_SimpleDescs[i].pAppInClusterList = (cId_t *)NULL; 186 | } 187 | 188 | if (endPoint % 4 == 1) { // every 1 in 4 189 | zclFreePadApp_SimpleDescs[i].AppNumOutClusters = FREEPAD_MAX_OUTCLUSTERS_NTH14; 190 | zclFreePadApp_SimpleDescs[i].pAppOutClusterList = (cId_t *)zclFreePadApp_OutClusterListNth14; 191 | } else if (endPoint % 2 == 0) { 192 | zclFreePadApp_SimpleDescs[i].AppNumOutClusters = FREEPAD_MAX_OUTCLUSTERS_EVEN; 193 | zclFreePadApp_SimpleDescs[i].pAppOutClusterList = (cId_t *)zclFreePadApp_OutClusterListEven; 194 | } else { 195 | zclFreePadApp_SimpleDescs[i].AppNumOutClusters = FREEPAD_MAX_OUTCLUSTERS_ODD; 196 | zclFreePadApp_SimpleDescs[i].pAppOutClusterList = (cId_t *)zclFreePadApp_OutClusterListOdd; 197 | } 198 | } 199 | } 200 | 201 | byte zclFreePadApp_KeyCodeToButton(byte key) { 202 | switch (key) { 203 | #if defined(HAL_BOARD_FREEPAD) 204 | case 0x9: // row=4 col=4 205 | return 1; 206 | case 0xa: // row=4 col=8 207 | return 2; 208 | case 0xc: // row=4 col=16 209 | return 3; 210 | case 0x8: // row=4 col=32 211 | return 4; 212 | case 0x11: // row=8 col=4 213 | return 5; 214 | case 0x12: // row=8 col=8 215 | return 6; 216 | case 0x14: // row=8 col=16 217 | return 7; 218 | case 0x18: // row=8 col=32 219 | return 8; 220 | case 0x21: // row=16 col=4 221 | return 9; 222 | case 0x22: // row=16 col=8 223 | return 10; 224 | case 0x24: // row=16 col=16 225 | return 11; 226 | case 0x28: // row=16 col=32 227 | return 12; 228 | case 0x41: // row=32 col=4 229 | return 13; 230 | case 0x42: // row=32 col=8 231 | return 14; 232 | case 0x44: // row=32 col=16 233 | return 15; 234 | case 0x48: // row=32 col=32 235 | return 16; 236 | case 0x81: // row=64 col=4 237 | return 17; 238 | case 0x82: // row=64 col=8 239 | return 18; 240 | case 0x84: // row=64 col=16 241 | return 19; 242 | case 0x88: // row=64 col=32 243 | return 20; 244 | #elif defined(HAL_BOARD_LETV) 245 | case 0x1: // 1 246 | return 1; 247 | case 0x2: // 2 248 | return 2; 249 | case 0x3: // 3 250 | return 3; 251 | case 0x4: // 4 252 | return 4; 253 | case 0x5: // 5 254 | return 5; 255 | case 0x6: // 6 256 | return 6; 257 | case 0x7: // 7 258 | return 7; 259 | case 0x8: // 8 260 | return 8; 261 | #elif defined(HAL_BOARD_CHDTECH_DEV) 262 | case 0x1: // row=4 col=4 263 | return 1; 264 | case 0x2: // row=4 col=8 265 | return 2; 266 | #endif 267 | 268 | default: 269 | return HAL_UNKNOWN_BUTTON; 270 | break; 271 | } 272 | } 273 | 274 | void zclFreePadApp_ResetAttributesToDefaultValues(void) { 275 | for (uint8 i = 0; i < FREEPAD_BUTTONS_COUNT; i++) { 276 | zclFreePadApp_SwitchActions[i] = ON_OFF_SWITCH_ACTIONS_TOGGLE; 277 | zclFreePadApp_SwitchTypes[i] = ON_OFF_SWITCH_TYPE_MULTIFUNCTION; 278 | } 279 | } -------------------------------------------------------------------------------- /Source/hal_board_cfg.h: -------------------------------------------------------------------------------- 1 | #ifndef HAL_BOARD_CFG_H 2 | #define HAL_BOARD_CFG_H 3 | 4 | 5 | /* ------------------------------------------------------------------------------------------------ 6 | * Includes 7 | * ------------------------------------------------------------------------------------------------ 8 | */ 9 | 10 | #include "hal_mcu.h" 11 | #include "hal_defs.h" 12 | #include "hal_types.h" 13 | 14 | 15 | 16 | /* ------------------------------------------------------------------------------------------------ 17 | * Clock Speed 18 | * ------------------------------------------------------------------------------------------------ 19 | */ 20 | 21 | #define HAL_CPU_CLOCK_MHZ 32 22 | 23 | /* 32 kHz clock source select in CLKCONCMD */ 24 | #if !defined (OSC32K_CRYSTAL_INSTALLED) || (defined (OSC32K_CRYSTAL_INSTALLED) && (OSC32K_CRYSTAL_INSTALLED == TRUE)) 25 | #define OSC_32KHZ 0x00 /* external 32 KHz xosc */ 26 | #else 27 | #define OSC_32KHZ 0x80 /* internal 32 KHz rcosc */ 28 | #endif 29 | 30 | #define HAL_CLOCK_STABLE() 31 | 32 | /* ------------------------------------------------------------------------------------------------ 33 | * Key Release detect support 34 | * ------------------------------------------------------------------------------------------------ 35 | */ 36 | #define HAL_KEY_CODE_NOKEY 0xff 37 | 38 | 39 | /* ------------------------------------------------------------------------------------------------ 40 | * LED Configuration 41 | * ------------------------------------------------------------------------------------------------ 42 | */ 43 | 44 | // TODO: review all HAL_BOARD_CC2530EB_REV17 and replace with HAL_BOARD_CC2530RC 45 | // if applicable. 46 | #define HAL_NUM_LEDS 0 47 | 48 | #define HAL_LED_BLINK_DELAY() st( { volatile uint32 i; for (i=0; i<0x5800; i++) { }; } ) 49 | #define ACTIVE_LOW ! 50 | #define ACTIVE_HIGH !! /* double negation forces result to be '1' */ 51 | 52 | /* ------------------------------------------------------------------------------------------------ 53 | * OSAL NV implemented by internal flash pages. 54 | * ------------------------------------------------------------------------------------------------ 55 | */ 56 | 57 | // Flash is partitioned into 8 banks of 32 KB or 16 pages. 58 | #define HAL_FLASH_PAGE_PER_BANK 16 59 | // Flash is constructed of 128 pages of 2 KB. 60 | #define HAL_FLASH_PAGE_SIZE 2048 61 | #define HAL_FLASH_WORD_SIZE 4 62 | 63 | // CODE banks get mapped into the XDATA range 8000-FFFF. 64 | #define HAL_FLASH_PAGE_MAP 0x8000 65 | 66 | // The last 16 bytes of the last available page are reserved for flash lock bits. 67 | // NV page definitions must coincide with segment declaration in project *.xcl file. 68 | #if defined NON_BANKED 69 | #define HAL_FLASH_LOCK_BITS 16 70 | #define HAL_NV_PAGE_END 30 71 | #define HAL_NV_PAGE_CNT 2 72 | #else 73 | #define HAL_FLASH_LOCK_BITS 16 74 | #define HAL_NV_PAGE_END 126 75 | #define HAL_NV_PAGE_CNT 6 76 | #endif 77 | 78 | // Re-defining Z_EXTADDR_LEN here so as not to include a Z-Stack .h file. 79 | #define HAL_FLASH_IEEE_SIZE 8 80 | #define HAL_FLASH_IEEE_PAGE (HAL_NV_PAGE_END+1) 81 | #define HAL_FLASH_IEEE_OSET (HAL_FLASH_PAGE_SIZE - HAL_FLASH_LOCK_BITS - HAL_FLASH_IEEE_SIZE) 82 | #define HAL_INFOP_IEEE_OSET 0xC 83 | 84 | #define HAL_FLASH_DEV_PRIVATE_KEY_OSET 0x7D2 85 | #define HAL_FLASH_CA_PUBLIC_KEY_OSET 0x7BC 86 | #define HAL_FLASH_IMPLICIT_CERT_OSET 0x78C 87 | 88 | #define HAL_NV_PAGE_BEG (HAL_NV_PAGE_END-HAL_NV_PAGE_CNT+1) 89 | // Used by DMA macros to shift 1 to create a mask for DMA registers. 90 | #define HAL_NV_DMA_CH 0 91 | #define HAL_DMA_CH_RX 3 92 | #define HAL_DMA_CH_TX 4 93 | 94 | #define HAL_NV_DMA_GET_DESC() HAL_DMA_GET_DESC0() 95 | #define HAL_NV_DMA_SET_ADDR(a) HAL_DMA_SET_ADDR_DESC0((a)) 96 | 97 | /* ------------------------------------------------------------------------------------------------ 98 | * Serial Boot Loader: reserving the first 4 pages of flash and other memory in cc2530-sb.xcl. 99 | * ------------------------------------------------------------------------------------------------ 100 | */ 101 | 102 | #define HAL_SB_IMG_ADDR 0x2000 103 | #define HAL_SB_CRC_ADDR 0x2090 104 | // Size of internal flash less 4 pages for boot loader, 6 pages for NV, & 1 page for lock bits. 105 | #define HAL_SB_IMG_SIZE (0x40000 - 0x2000 - 0x3000 - 0x0800) 106 | 107 | /* ------------------------------------------------------------------------------------------------ 108 | * Macros 109 | * ------------------------------------------------------------------------------------------------ 110 | */ 111 | 112 | /* ----------- RF-frontend Connection Initialization ---------- */ 113 | #if defined HAL_PA_LNA || defined HAL_PA_LNA_CC2590 114 | extern void MAC_RfFrontendSetup(void); 115 | #define HAL_BOARD_RF_FRONTEND_SETUP() MAC_RfFrontendSetup() 116 | #else 117 | #define HAL_BOARD_RF_FRONTEND_SETUP() 118 | #endif 119 | 120 | 121 | /* ------------------------------------------------------------------------------------------------ 122 | * Macros 123 | * ------------------------------------------------------------------------------------------------ 124 | */ 125 | 126 | #define CLKCONCMD_VALUE (CLKCONCMD_32MHZ | OSC_32KHZ) 127 | 128 | /* ----------- Cache Prefetch control ---------- */ 129 | #define PREFETCH_ENABLE() st( FCTL = 0x08; ) 130 | #define PREFETCH_DISABLE() st( FCTL = 0x04; ) 131 | 132 | /* ----------- Board Initialization ---------- */ 133 | #define HAL_BOARD_INIT() \ 134 | { \ 135 | uint16 i; \ 136 | \ 137 | SLEEPCMD &= ~OSC_PD; /* turn on 16MHz RC and 32MHz XOSC */ \ 138 | while (!(SLEEPSTA & XOSC_STB)); /* wait for 32MHz XOSC stable */ \ 139 | asm("NOP"); /* chip bug workaround */ \ 140 | for (i=0; i<504; i++) asm("NOP"); /* Require 63us delay for all revs */ \ 141 | CLKCONCMD = CLKCONCMD_VALUE; /* Select 32MHz XOSC and the source for 32K clock */ \ 142 | while (CLKCONSTA != CLKCONCMD_VALUE); /* Wait for the change to be effective */ \ 143 | SLEEPCMD |= OSC_PD; /* turn off 16MHz RC */ \ 144 | \ 145 | /* Turn on cache prefetch mode */ \ 146 | PREFETCH_ENABLE(); \ 147 | HAL_TURN_OFF_LED1(); \ 148 | LED1_DDR |= LED1_BV; \ 149 | HAL_TURN_OFF_LED2(); \ 150 | LED2_DDR |= LED2_BV; \ 151 | } 152 | 153 | /* ----------- Debounce ---------- */ 154 | #define HAL_DEBOUNCE(expr) { int i; for (i=0; i<500; i++) { if (!(expr)) i = 0; } } 155 | 156 | /* ----------- Push Buttons ---------- */ 157 | #define HAL_PUSH_BUTTON1() (0) 158 | #define HAL_PUSH_BUTTON2() (0) 159 | #define HAL_PUSH_BUTTON3() (0) 160 | #define HAL_PUSH_BUTTON4() (0) 161 | #define HAL_PUSH_BUTTON5() (0) 162 | #define HAL_PUSH_BUTTON6() (0) 163 | 164 | /* ----------- LED's ---------- */ 165 | 166 | #if defined(HAL_BOARD_FREEPAD) 167 | #define LED1_BV BV(1) 168 | #define LED1_SBIT P0_1 169 | #define LED1_DDR P0DIR 170 | #define LED1_POLARITY ACTIVE_HIGH 171 | #define LED2_BV BV(1) 172 | #define LED2_SBIT P0_1 173 | #define LED2_DDR P0DIR 174 | #define LED2_POLARITY ACTIVE_HIGH 175 | 176 | #elif defined(HAL_BOARD_LETV) 177 | /* 1 - P1_0 Red */ 178 | #define LED1_BV BV(0) 179 | #define LED1_SBIT P1_0 180 | #define LED1_DDR P1DIR 181 | #define LED1_POLARITY ACTIVE_LOW 182 | /* 2 - P1_1 Green */ 183 | #define LED2_BV BV(1) 184 | #define LED2_SBIT P1_1 185 | #define LED2_DDR P1DIR 186 | #define LED2_POLARITY ACTIVE_LOW 187 | 188 | #elif defined(HAL_BOARD_CHDTECH_DEV) 189 | /* 1 - P1_0 Зеленый */ 190 | #define LED1_BV BV(0) 191 | #define LED1_SBIT P1_0 192 | #define LED1_DDR P1DIR 193 | #define LED1_POLARITY ACTIVE_LOW 194 | /* 1 - P1_0 Зеленый */ 195 | #define LED2_BV BV(0) 196 | #define LED2_SBIT P1_0 197 | #define LED2_DDR P1DIR 198 | #define LED2_POLARITY ACTIVE_LOW 199 | #endif 200 | 201 | 202 | #define HAL_TURN_OFF_LED1() st( LED1_SBIT = LED1_POLARITY (0); ) 203 | #define HAL_TURN_OFF_LED2() st( LED2_SBIT = LED2_POLARITY (0); ) 204 | #define HAL_TURN_OFF_LED3() asm("NOP") 205 | #define HAL_TURN_OFF_LED4() asm("NOP") 206 | 207 | #define HAL_TURN_ON_LED1() st( LED1_SBIT = LED1_POLARITY (1); ) 208 | #define HAL_TURN_ON_LED2() st( LED2_SBIT = LED2_POLARITY (1); ) 209 | #define HAL_TURN_ON_LED3() asm("NOP") 210 | #define HAL_TURN_ON_LED4() asm("NOP") 211 | 212 | #define HAL_TOGGLE_LED1() st( if (LED1_SBIT) { LED1_SBIT = 0; } else { LED1_SBIT = 1;} ) 213 | #define HAL_TOGGLE_LED2() st( if (LED2_SBIT) { LED2_SBIT = 0; } else { LED2_SBIT = 1;} ) 214 | #define HAL_TOGGLE_LED3() asm("NOP") 215 | #define HAL_TOGGLE_LED4() asm("NOP") 216 | 217 | #define HAL_STATE_LED1() (LED1_POLARITY (LED1_SBIT)) 218 | #define HAL_STATE_LED2() (LED2_POLARITY (LED2_SBIT)) 219 | #define HAL_STATE_LED3() 0 220 | #define HAL_STATE_LED4() 0 221 | 222 | /* ----------- Minimum safe bus voltage ---------- */ 223 | 224 | // Vdd/3 / Internal Reference X ENOB --> (Vdd / 3) / 1.15 X 127 225 | #define VDD_2_0 74 // 2.0 V required to safely read/write internal flash. 226 | #define VDD_2_7 100 // 2.7 V required for the Numonyx device. 227 | 228 | #define VDD_MIN_RUN VDD_2_0 229 | #define VDD_MIN_NV (VDD_2_0+4) // 5% margin over minimum to survive a page erase and compaction. 230 | #define VDD_MIN_GOOD (VDD_2_0+8) // 10% margin over minimum to survive a page erase and compaction. 231 | #define VDD_MIN_XNV (VDD_2_7+5) // 5% margin over minimum to survive a page erase and compaction. 232 | 233 | /* ----------- Delay macro ---------- */ 234 | #define HAL_BOARD_DELAY_USEC( usec ) \ 235 | { \ 236 | uint16 i; \ 237 | \ 238 | for (i = 0; i < ((usec) * 8); i++) \ 239 | { \ 240 | asm("NOP"); \ 241 | } \ 242 | } 243 | 244 | /* ------------------------------------------------------------------------------------------------ 245 | * Driver Configuration 246 | * ------------------------------------------------------------------------------------------------ 247 | */ 248 | 249 | /* Set to TRUE enable H/W TIMER usage, FALSE disable it */ 250 | #ifndef HAL_TIMER 251 | #define HAL_TIMER FALSE 252 | #endif 253 | 254 | /* Set to TRUE enable ADC usage, FALSE disable it */ 255 | #ifndef HAL_ADC 256 | #define HAL_ADC TRUE 257 | #endif 258 | 259 | /* Set to TRUE enable DMA usage, FALSE disable it */ 260 | #ifndef HAL_DMA 261 | #define HAL_DMA TRUE 262 | #endif 263 | 264 | /* Set to TRUE enable Flash access, FALSE disable it */ 265 | #ifndef HAL_FLASH 266 | #define HAL_FLASH TRUE 267 | #endif 268 | 269 | /* Set to TRUE enable AES usage, FALSE disable it */ 270 | #ifndef HAL_AES 271 | #define HAL_AES TRUE 272 | #endif 273 | 274 | #ifndef HAL_AES_DMA 275 | #define HAL_AES_DMA FALSE 276 | #endif 277 | 278 | /* Set to TRUE enable LCD usage, FALSE disable it */ 279 | #ifndef HAL_LCD 280 | #define HAL_LCD FALSE 281 | #endif 282 | 283 | /* Set to TRUE enable LED usage, FALSE disable it */ 284 | #ifndef HAL_LED 285 | #define HAL_LED FALSE 286 | #endif 287 | #if (!defined BLINK_LEDS) && (HAL_LED == TRUE) 288 | #define BLINK_LEDS 289 | #endif 290 | 291 | #ifndef HAL_MOTION 292 | #define HAL_MOTION FASLE 293 | #endif 294 | 295 | /* Set to TRUE enable KEY usage, FALSE disable it */ 296 | #ifndef HAL_KEY 297 | #define HAL_KEY TRUE 298 | #endif 299 | 300 | /* Set to TRUE enable UART usage, FALSE disable it */ 301 | #ifndef HAL_UART 302 | #define HAL_UART FALSE 303 | #endif 304 | 305 | #if HAL_UART 306 | #ifndef HAL_UART_DMA 307 | #if HAL_DMA 308 | #if (defined ZAPP_P2) || (defined ZTOOL_P2) 309 | #define HAL_UART_DMA 2 310 | #else 311 | #define HAL_UART_DMA 1 312 | #endif 313 | #else 314 | #define HAL_UART_DMA 0 315 | #endif 316 | #endif 317 | 318 | #ifndef HAL_UART_ISR 319 | #if HAL_UART_DMA // Default preference for DMA over ISR. 320 | #define HAL_UART_ISR 0 321 | #elif (defined ZAPP_P2) || (defined ZTOOL_P2) 322 | #define HAL_UART_ISR 2 323 | #else 324 | #define HAL_UART_ISR 1 325 | #endif 326 | #endif 327 | 328 | #if (HAL_UART_DMA && (HAL_UART_DMA == HAL_UART_ISR)) 329 | #error HAL_UART_DMA & HAL_UART_ISR must be different. 330 | #endif 331 | 332 | // Used to set P2 priority - USART0 over USART1 if both are defined. 333 | #if ((HAL_UART_DMA == 1) || (HAL_UART_ISR == 1)) 334 | #define HAL_UART_PRIPO 0x00 335 | #else 336 | #define HAL_UART_PRIPO 0x40 337 | #endif 338 | 339 | #else 340 | #define HAL_UART_DMA 0 341 | #define HAL_UART_ISR 0 342 | #endif 343 | 344 | /* USB is not used for CC2530 configuration */ 345 | #define HAL_UART_USB 0 346 | 347 | #ifndef HAL_BUZZER 348 | #define HAL_BUZZER TRUE 349 | #endif 350 | 351 | /******************************************************************************************************* 352 | */ 353 | #endif 354 | -------------------------------------------------------------------------------- /Source/zcl_freepadapp.c: -------------------------------------------------------------------------------- 1 | 2 | #include "AF.h" 3 | #include "OSAL.h" 4 | #include "OSAL_Clock.h" 5 | #include "OSAL_PwrMgr.h" 6 | #include "ZComDef.h" 7 | #include "ZDApp.h" 8 | #include "ZDObject.h" 9 | #include "math.h" 10 | 11 | #include "nwk_util.h" 12 | #include "zcl.h" 13 | #include "zcl_diagnostic.h" 14 | #include "zcl_freepadapp.h" 15 | #include "zcl_general.h" 16 | #include "zcl_lighting.h" 17 | 18 | #include "bdb.h" 19 | #include "bdb_interface.h" 20 | 21 | #include "Debug.h" 22 | #include "commissioning.h" 23 | #include "factory_reset.h" 24 | #include "onboard.h" 25 | #include "tl_resetter.h" 26 | 27 | /* HAL */ 28 | #include "hal_drivers.h" 29 | #include "hal_key.h" 30 | #include "hal_led.h" 31 | 32 | #include "battery.h" 33 | #include "version.h" 34 | /********************************************************************* 35 | * MACROS 36 | */ 37 | #define HAL_KEY_CODE_RELEASE_KEY HAL_KEY_CODE_NOKEY 38 | 39 | #define HOLD_CODE 0 40 | #define RELEASE_CODE 255 41 | 42 | /********************************************************************* 43 | * CONSTANTS 44 | */ 45 | 46 | /********************************************************************* 47 | * TYPEDEFS 48 | */ 49 | 50 | /********************************************************************* 51 | * GLOBAL VARIABLES 52 | */ 53 | extern bool requestNewTrustCenterLinkKey; 54 | byte zclFreePadApp_TaskID; 55 | 56 | /********************************************************************* 57 | * GLOBAL FUNCTIONS 58 | */ 59 | 60 | /********************************************************************* 61 | * LOCAL VARIABLES 62 | */ 63 | 64 | bool holdSend = false; 65 | byte currentKeyCode = 0; 66 | byte clicksCount = 0; 67 | 68 | afAddrType_t inderect_DstAddr = {.addrMode = (afAddrMode_t)AddrNotPresent, .endPoint = 0, .addr.shortAddr = 0}; 69 | 70 | /********************************************************************* 71 | * LOCAL FUNCTIONS 72 | */ 73 | static void zclFreePadApp_HandleKeys(byte shift, byte keys); 74 | static void zclFreePadApp_SendButtonPress(uint8 endPoint, byte clicksCount); 75 | static void zclFreePadApp_SendKeys(byte keyCode, byte pressCount, byte pressTime); 76 | static void zclFreepadApp_SendKeysToBinds(byte keyCode, byte pressCount, byte pressTime); 77 | static void zclFreePadApp_BasicResetCB(void); 78 | static ZStatus_t zclFreePadApp_ReadWriteAuthCB(afAddrType_t *srcAddr, zclAttrRec_t *pAttr, uint8 oper); 79 | static void zclFreePadApp_SaveAttributesToNV(void); 80 | static void zclFreePadApp_RestoreAttributesFromNV(void); 81 | /********************************************************************* 82 | * ZCL General Profile Callback table 83 | */ 84 | static zclGeneral_AppCallbacks_t zclFreePadApp_CmdCallbacks = { 85 | zclFreePadApp_BasicResetCB, // Basic Cluster Reset command 86 | NULL, // Identify Trigger Effect command 87 | NULL, // On/Off cluster commands 88 | NULL, // On/Off cluster enhanced command Off with Effect 89 | NULL, // On/Off cluster enhanced command On with Recall Global Scene 90 | NULL, // On/Off cluster enhanced command On with Timed Off 91 | NULL, // RSSI Location command 92 | NULL // RSSI Location Response command 93 | }; 94 | // static CONST zclAttrRec_t attrs[FREEPAD_BUTTONS_COUNT]; 95 | 96 | static void zclFreePadApp_BasicResetCB(void) { 97 | LREPMaster("zclFreePadApp_BasicResetCB\r\n"); 98 | zclFreePadApp_ResetAttributesToDefaultValues(); 99 | zclFreePadApp_SaveAttributesToNV(); 100 | } 101 | 102 | /* 103 | this is workaround, since we don't have CB after attribute write, we will hack into write auth CB 104 | and save attributes few secons later 105 | */ 106 | static ZStatus_t zclFreePadApp_ReadWriteAuthCB(afAddrType_t *srcAddr, zclAttrRec_t *pAttr, uint8 oper) { 107 | LREPMaster("AUTH CB called\r\n"); 108 | 109 | osal_start_timerEx(zclFreePadApp_TaskID, FREEPADAPP_SAVE_ATTRS_EVT, 2000); 110 | return ZSuccess; 111 | } 112 | void zclFreePadApp_Init(byte task_id) { 113 | // this is important to allow connects throught routers 114 | // to make this work, coordinator should be compiled with this flag #define TP2_LEGACY_ZC 115 | requestNewTrustCenterLinkKey = FALSE; 116 | 117 | zclFreePadApp_TaskID = task_id; 118 | zclFreePadApp_ResetAttributesToDefaultValues(); 119 | zclFreePadApp_RestoreAttributesFromNV(); 120 | zclFreePadApp_InitClusters(); 121 | 122 | zclGeneral_RegisterCmdCallbacks(1, &zclFreePadApp_CmdCallbacks); 123 | 124 | zcl_registerAttrList(zclFreePadApp_SimpleDescs[0].EndPoint, zclFreePadApp_AttrsFirstEPCount, zclFreePadApp_AttrsFirstEP); 125 | bdb_RegisterSimpleDescriptor(&zclFreePadApp_SimpleDescs[0]); 126 | zcl_registerReadWriteCB(zclFreePadApp_SimpleDescs[0].EndPoint, NULL, zclFreePadApp_ReadWriteAuthCB); 127 | 128 | for (uint8 i = 1; i < FREEPAD_BUTTONS_COUNT; i++) { 129 | zcl_registerAttrList(zclFreePadApp_SimpleDescs[i].EndPoint, FREEPAD_ATTRS_COUNT, zclFreePadApp_Attrs[i - 1]); 130 | bdb_RegisterSimpleDescriptor(&zclFreePadApp_SimpleDescs[i]); 131 | zcl_registerReadWriteCB(zclFreePadApp_SimpleDescs[i].EndPoint, NULL, zclFreePadApp_ReadWriteAuthCB); 132 | } 133 | zcl_registerForMsg(zclFreePadApp_TaskID); 134 | 135 | // Register for all key events - This app will handle all key events 136 | RegisterForKeys(zclFreePadApp_TaskID); 137 | 138 | LREP("Started build %s \r\n", zclFreePadApp_DateCodeNT); 139 | ZMacSetTransmitPower(TX_PWR_PLUS_4); // set 4dBm 140 | } 141 | 142 | static void zclFreepadApp_SendKeysToBinds(byte keyCode, byte pressCount, bool isRelease) { 143 | byte button = zclFreePadApp_KeyCodeToButton(keyCode); 144 | uint8 endPoint = zclFreePadApp_SimpleDescs[button - 1].EndPoint; 145 | uint8 switchAction = zclFreePadApp_SwitchActions[button - 1]; 146 | LREP("button %d clicks %d isRelease %d action %d\r\n", button, pressCount, isRelease, switchAction); 147 | 148 | switch (switchAction) { 149 | case ON_OFF_SWITCH_ACTIONS_OFF: 150 | zclGeneral_SendOnOff_CmdOff(endPoint, &inderect_DstAddr, TRUE, bdb_getZCLFrameCounter()); 151 | break; 152 | case ON_OFF_SWITCH_ACTIONS_ON: 153 | zclGeneral_SendOnOff_CmdOn(endPoint, &inderect_DstAddr, TRUE, bdb_getZCLFrameCounter()); 154 | break; 155 | case ON_OFF_SWITCH_ACTIONS_TOGGLE: 156 | default: 157 | zclGeneral_SendOnOff_CmdToggle(endPoint, &inderect_DstAddr, TRUE, bdb_getZCLFrameCounter()); 158 | break; 159 | } 160 | 161 | if (button % 2 == 0) { 162 | // even numbers (2 4, send up to lower odd number) 163 | zclGeneral_SendLevelControlStepWithOnOff(endPoint - 1, &inderect_DstAddr, LEVEL_STEP_UP, FREEPADAPP_LEVEL_STEP_SIZE, 164 | FREEPADAPP_LEVEL_TRANSITION_TIME, TRUE, bdb_getZCLFrameCounter()); 165 | 166 | zclLighting_ColorControl_Send_StepColorCmd(endPoint - 1, &inderect_DstAddr, 1000, 0, 0, true, bdb_getZCLFrameCounter()); 167 | // works zclLighting_ColorControl_Send_MoveToColorCmd( endPoint - 1, &inderect_DstAddr, 45914, 19615, 0, TRUE, 168 | // bdb_getZCLFrameCounter()); 169 | 170 | // zclLighting_ColorControl_Send_StepColorCmd( endPoint - 1, &inderect_DstAddr, 1000, 1000, 0, TRUE, bdb_getZCLFrameCounter()); 171 | // zclLighting_ColorControl_Send_StepHueCmd(endPoint - 1, &inderect_DstAddr, LIGHTING_STEP_HUE_UP, 100, 0, TRUE, 172 | // bdb_getZCLFrameCounter()); 173 | 174 | } else { 175 | // odd number (1 3, send LEVEL_MOVE_DOWN to self) 176 | zclGeneral_SendLevelControlStepWithOnOff(endPoint, &inderect_DstAddr, LEVEL_STEP_DOWN, FREEPADAPP_LEVEL_STEP_SIZE, 177 | FREEPADAPP_LEVEL_TRANSITION_TIME, TRUE, bdb_getZCLFrameCounter()); 178 | 179 | zclLighting_ColorControl_Send_StepColorCmd(endPoint - 1, &inderect_DstAddr, -1000, 0, 0, true, bdb_getZCLFrameCounter()); 180 | // zclLighting_ColorControl_Send_StepSaturationCmd(endPoint, &inderect_DstAddr, LIGHTING_STEP_SATURATION_UP, 100, 0, TRUE, 181 | // bdb_getZCLFrameCounter()); 182 | // works zclLighting_ColorControl_Send_MoveToColorCmd( endPoint, &inderect_DstAddr, 11298, 48942, 0, TRUE, 183 | // bdb_getZCLFrameCounter()); 184 | } 185 | 186 | if (button % 4 == 1) { 187 | zclLighting_ColorControl_Send_StepColorCmd(endPoint, &inderect_DstAddr, FREEPADAPP_COLOR_LEVEL_STEP_X_SIZE, 188 | FREEPADAPP_COLOR_LEVEL_STEP_Y_SIZE, FREEPADAPP_COLOR_LEVEL_TRANSITION_TIME, true, 189 | bdb_getZCLFrameCounter()); 190 | } else if (button % 4 == 2) { 191 | zclLighting_ColorControl_Send_StepColorCmd(endPoint - 1, &inderect_DstAddr, -FREEPADAPP_COLOR_LEVEL_STEP_X_SIZE, 192 | FREEPADAPP_COLOR_LEVEL_STEP_Y_SIZE, FREEPADAPP_COLOR_LEVEL_TRANSITION_TIME, true, 193 | bdb_getZCLFrameCounter()); 194 | } else if (button % 4 == 3) { 195 | zclLighting_ColorControl_Send_StepColorCmd(endPoint - 2, &inderect_DstAddr, FREEPADAPP_COLOR_LEVEL_STEP_X_SIZE, 196 | FREEPADAPP_COLOR_LEVEL_STEP_Y_SIZE, FREEPADAPP_COLOR_LEVEL_TRANSITION_TIME, true, 197 | bdb_getZCLFrameCounter()); 198 | } else if (button % 4 == 0) { 199 | zclLighting_ColorControl_Send_StepColorCmd(endPoint - 3, &inderect_DstAddr, -FREEPADAPP_COLOR_LEVEL_STEP_X_SIZE, 200 | FREEPADAPP_COLOR_LEVEL_STEP_Y_SIZE, FREEPADAPP_COLOR_LEVEL_TRANSITION_TIME, true, 201 | bdb_getZCLFrameCounter()); 202 | } 203 | } 204 | 205 | static void zclFreePadApp_SendKeys(byte keyCode, byte pressCount, bool isRelease) { 206 | byte button = zclFreePadApp_KeyCodeToButton(keyCode); 207 | uint8 endPoint = zclFreePadApp_SimpleDescs[button - 1].EndPoint; 208 | if (isRelease) { 209 | zclFreePadApp_SendButtonPress(endPoint, RELEASE_CODE); 210 | } else { 211 | zclFreePadApp_SendButtonPress(endPoint, pressCount); 212 | } 213 | } 214 | 215 | uint16 zclFreePadApp_event_loop(uint8 task_id, uint16 events) { 216 | afIncomingMSGPacket_t *MSGpkt; 217 | 218 | (void)task_id; // Intentionally unreferenced parameter 219 | if (events & SYS_EVENT_MSG) { 220 | while ((MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive(zclFreePadApp_TaskID))) { 221 | 222 | switch (MSGpkt->hdr.event) { 223 | 224 | case KEY_CHANGE: 225 | zclFreePadApp_HandleKeys(((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys); 226 | break; 227 | 228 | case ZCL_INCOMING_MSG: 229 | if (((zclIncomingMsg_t *)MSGpkt)->attrCmd) { 230 | osal_mem_free(((zclIncomingMsg_t *)MSGpkt)->attrCmd); 231 | } 232 | break; 233 | 234 | default: 235 | break; 236 | } 237 | 238 | // Release the memory 239 | osal_msg_deallocate((uint8 *)MSGpkt); 240 | } 241 | 242 | // return unprocessed events 243 | return (events ^ SYS_EVENT_MSG); 244 | } 245 | 246 | if (events & FREEPADAPP_SEND_KEYS_EVT) { 247 | LREPMaster("FREEPADAPP_SEND_KEYS_EVT\r\n"); 248 | zclFreePadApp_SendKeys(currentKeyCode, clicksCount, holdSend); 249 | clicksCount = 0; 250 | currentKeyCode = 0; 251 | holdSend = false; 252 | return (events ^ FREEPADAPP_SEND_KEYS_EVT); 253 | } 254 | 255 | if (events & FREEPADAPP_HOLD_START_EVT) { 256 | LREPMaster("FREEPADAPP_HOLD_START_EVT\r\n"); 257 | byte button = zclFreePadApp_KeyCodeToButton(currentKeyCode); 258 | 259 | uint8 endPoint = zclFreePadApp_SimpleDescs[button - 1].EndPoint; 260 | zclFreePadApp_SendButtonPress(endPoint, HOLD_CODE); 261 | holdSend = true; 262 | 263 | return (events ^ FREEPADAPP_HOLD_START_EVT); 264 | } 265 | 266 | if (events & FREEPADAPP_SAVE_ATTRS_EVT) { 267 | LREPMaster("FREEPADAPP_SAVE_ATTRS_EVT\r\n"); 268 | zclFreePadApp_SaveAttributesToNV(); 269 | return (events ^ FREEPADAPP_SAVE_ATTRS_EVT); 270 | } 271 | // Discard unknown events 272 | return 0; 273 | } 274 | 275 | static void zclFreePadApp_SendButtonPress(uint8 endPoint, uint8 clicksCount) { 276 | 277 | const uint8 NUM_ATTRIBUTES = 1; 278 | zclReportCmd_t *pReportCmd; 279 | pReportCmd = osal_mem_alloc(sizeof(zclReportCmd_t) + (NUM_ATTRIBUTES * sizeof(zclReport_t))); 280 | if (pReportCmd != NULL) { 281 | pReportCmd->numAttr = NUM_ATTRIBUTES; 282 | pReportCmd->attrList[0].attrID = ATTRID_IOV_BASIC_PRESENT_VALUE; 283 | pReportCmd->attrList[0].dataType = ZCL_DATATYPE_UINT8; 284 | pReportCmd->attrList[0].attrData = (void *)(&clicksCount); 285 | 286 | zcl_SendReportCmd(endPoint, &inderect_DstAddr, ZCL_CLUSTER_ID_GEN_MULTISTATE_INPUT_BASIC, pReportCmd, ZCL_FRAME_CLIENT_SERVER_DIR, 287 | TRUE, bdb_getZCLFrameCounter()); 288 | } 289 | osal_mem_free(pReportCmd); 290 | } 291 | 292 | static void zclFreePadApp_HandleKeys(byte shift, byte keyCode) { 293 | static uint32 pressTime = 0; 294 | static byte prevKeyCode = 0; 295 | if (keyCode == prevKeyCode) { 296 | return; 297 | } 298 | LREP("devState %d bdbNodeIsOnANetwork %d \r\n", devState, bdbAttributes.bdbNodeIsOnANetwork); 299 | 300 | prevKeyCode = keyCode; 301 | 302 | if (keyCode == HAL_KEY_CODE_RELEASE_KEY) { 303 | zclFactoryResetter_HandleKeys(HAL_KEY_RELEASE, keyCode); 304 | zclBattery_HandleKeys(HAL_KEY_RELEASE, keyCode); 305 | zclTouchLinkRestter_HandleKeys(HAL_KEY_RELEASE, keyCode); 306 | byte prevButton = zclFreePadApp_KeyCodeToButton(currentKeyCode); 307 | uint8 prevSwitchType = zclFreePadApp_SwitchTypes[prevButton - 1]; 308 | 309 | switch (prevSwitchType) { 310 | case ON_OFF_SWITCH_TYPE_TOGGLE: 311 | case ON_OFF_SWITCH_TYPE_MOMENTARY: 312 | LREPMaster("Rlease \r\n"); 313 | break; 314 | 315 | case ON_OFF_SWITCH_TYPE_MULTIFUNCTION: 316 | default: 317 | if (pressTime > 0) { 318 | pressTime = 0; 319 | osal_start_timerEx(zclFreePadApp_TaskID, FREEPADAPP_SEND_KEYS_EVT, FREEPADAPP_SEND_KEYS_DELAY); 320 | osal_stop_timerEx(zclFreePadApp_TaskID, FREEPADAPP_HOLD_START_EVT); 321 | } 322 | break; 323 | } 324 | 325 | } else { 326 | byte button = zclFreePadApp_KeyCodeToButton(keyCode); 327 | // TODO: implement proper keys task 328 | zclCommissioning_HandleKeys(HAL_KEY_PRESS, keyCode); 329 | if (button == 1) { 330 | zclFactoryResetter_HandleKeys(HAL_KEY_PRESS, keyCode); 331 | } 332 | 333 | zclTouchLinkRestter_HandleKeys(HAL_KEY_PRESS, button); 334 | 335 | uint8 switchType = zclFreePadApp_SwitchTypes[button - 1]; 336 | 337 | HalLedSet(HAL_LED_2, HAL_LED_MODE_BLINK); 338 | pressTime = osal_getClock(); 339 | 340 | currentKeyCode = keyCode; 341 | zclFreepadApp_SendKeysToBinds(keyCode, 1, false); 342 | switch (switchType) { 343 | case ON_OFF_SWITCH_TYPE_TOGGLE: 344 | case ON_OFF_SWITCH_TYPE_MOMENTARY: 345 | clicksCount = 0; 346 | zclFreePadApp_SendKeys(keyCode, 1, false); 347 | LREPMaster("ON_OFF_SWITCH_TYPE_TOGGLE or ON_OFF_SWITCH_TYPE_MOMENTARY\r\n"); 348 | break; 349 | 350 | case ON_OFF_SWITCH_TYPE_MULTIFUNCTION: 351 | default: 352 | clicksCount++; 353 | LREPMaster("ON_OFF_SWITCH_TYPE_MULTIFUNCTION or default\r\n"); 354 | osal_stop_timerEx(zclFreePadApp_TaskID, FREEPADAPP_SEND_KEYS_EVT); 355 | osal_start_timerEx(zclFreePadApp_TaskID, FREEPADAPP_HOLD_START_EVT, FREEPADAPP_HOLD_START_DELAY); 356 | break; 357 | } 358 | } 359 | } 360 | 361 | static void zclFreePadApp_RestoreAttributesFromNV(void) { 362 | LREPMaster("Restoring attributes to NV\r\n"); 363 | 364 | if (osal_nv_item_init(FREEPAD_NW_SWITCH_ACTIONS, FREEPAD_BUTTONS_COUNT, &zclFreePadApp_SwitchActions) == ZSuccess) { 365 | if (osal_nv_read(FREEPAD_NW_SWITCH_ACTIONS, 0, FREEPAD_BUTTONS_COUNT, &zclFreePadApp_SwitchActions) != ZSuccess) { 366 | LREPMaster("fail FREEPAD_NW_SWITCH_ACTIONS\r\n"); 367 | } 368 | } 369 | if (osal_nv_item_init(FREEPAD_NW_SWITCH_TYPES, FREEPAD_BUTTONS_COUNT, &zclFreePadApp_SwitchTypes) == ZSuccess) { 370 | if (osal_nv_read(FREEPAD_NW_SWITCH_TYPES, 0, FREEPAD_BUTTONS_COUNT, &zclFreePadApp_SwitchTypes) != ZSuccess) { 371 | LREPMaster("fail FREEPAD_NW_SWITCH_TYPES\r\n"); 372 | } 373 | } 374 | } 375 | static void zclFreePadApp_SaveAttributesToNV(void) { 376 | LREPMaster("Saving attributes to NV\r\n"); 377 | if (osal_nv_item_init(FREEPAD_NW_SWITCH_ACTIONS, FREEPAD_BUTTONS_COUNT, &zclFreePadApp_SwitchActions) == ZSuccess) { 378 | osal_nv_write(FREEPAD_NW_SWITCH_ACTIONS, 0, FREEPAD_BUTTONS_COUNT, &zclFreePadApp_SwitchActions); 379 | } 380 | if (osal_nv_item_init(FREEPAD_NW_SWITCH_TYPES, FREEPAD_BUTTONS_COUNT, &zclFreePadApp_SwitchTypes) == ZSuccess) { 381 | osal_nv_write(FREEPAD_NW_SWITCH_TYPES, 0, FREEPAD_BUTTONS_COUNT, &zclFreePadApp_SwitchTypes); 382 | } 383 | } 384 | 385 | /**************************************************************************** 386 | ****************************************************************************/ 387 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------