Add Telink Platform (#6682)
* Add Telink Platform
* [Telink] remove unnecessary steps from workflow
* [Telink] update Readme.md flash section with new instruction
* [Telink] Fix compilation errors
* [Telink] Fix remarks from reviewers
* [Telink] update last changes in Matter
* [Telink] Update endpoint numbers for lighting
* [Telink] Remove PublishService and Service module as it is no longer required
* [Telink] Move Zephyr shared files to config/zephyr
* [Telink] Fix after restyle check
* [Telink] remove unnecessary container volume
* [Telink] Add MBEDTLS_ECDSA_DETERMINISTIC to fix compilation error
* [Telink] update after rebase
diff --git a/.github/boring-cyborg.yml b/.github/boring-cyborg.yml
index 2974da8..a3f8eb3 100644
--- a/.github/boring-cyborg.yml
+++ b/.github/boring-cyborg.yml
@@ -130,3 +130,6 @@
zephyr:
- src/platform/Zephyr/*
+
+ telink:
+ - src/platform/telink/*
diff --git a/.github/labeler.yml b/.github/labeler.yml
index 183c1fa..ae076f9 100644
--- a/.github/labeler.yml
+++ b/.github/labeler.yml
@@ -154,3 +154,6 @@
zephyr:
- src/platform/Zephyr/*
+
+telink:
+ - src/platform/telink/*
diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml
new file mode 100644
index 0000000..44b8481
--- /dev/null
+++ b/.github/workflows/examples-telink.yaml
@@ -0,0 +1,41 @@
+# Copyright (c) 2020 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+name: Build example - Telink
+
+on:
+ push:
+ pull_request:
+
+jobs:
+ telink:
+ name: Telink
+ env:
+ BUILD_TYPE: telink
+
+ runs-on: ubuntu-latest
+ if: github.actor != 'restyled-io[bot]'
+
+ container:
+ image: connectedhomeip/chip-build-telink:latest
+ volumes:
+ - "/tmp/bloat_reports:/tmp/bloat_reports"
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+ with:
+ submodules: true
+ - name: Build example Telink Lighting App on TLSR9518ADK80D
+ run: scripts/examples/telink_example.sh lighting-app tlsr9518adk80d
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index a78c138..b36d01e 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -276,6 +276,19 @@
"${workspaceFolder}/examples/shell/nrfconnect/build/nrf5340dk_nrf5340_cpuapp"
]
}
+ },
+ {
+ "label": "Build Telink Lighting Example (TLSR9518ADK80D)",
+ "type": "shell",
+ "command": "source scripts/activate.sh && scripts/examples/telink_example.sh lighting-app tlsr9518adk80d",
+ "group": "build",
+ "problemMatcher": {
+ "base": "$gcc",
+ "fileLocation": [
+ "relative",
+ "${workspaceFolder}/examples/lighting-app/telink/build/tlsr9518adk80d"
+ ]
+ }
}
]
}
diff --git a/config/nrfconnect/chip-module/CMakeLists.txt b/config/nrfconnect/chip-module/CMakeLists.txt
index 894a5a0..2416859 100644
--- a/config/nrfconnect/chip-module/CMakeLists.txt
+++ b/config/nrfconnect/chip-module/CMakeLists.txt
@@ -28,7 +28,7 @@
if (CONFIG_CHIP)
include(ExternalProject)
-include(zephyr-util.cmake)
+include(../../zephyr/zephyr-util.cmake)
# ==============================================================================
# Declare configuration variables and define constants
diff --git a/config/nrfconnect/chip-module/Kconfig b/config/nrfconnect/chip-module/Kconfig
index b8cce34..0969370 100644
--- a/config/nrfconnect/chip-module/Kconfig
+++ b/config/nrfconnect/chip-module/Kconfig
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2020 Project CHIP Authors
+# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,76 +14,7 @@
# limitations under the License.
#
-menuconfig CHIP
- bool "Connected Home over IP protocol stack"
- default n
- select CPLUSPLUS
- imply LIB_CPLUSPLUS
- imply REQUIRES_FULL_LIBC
- imply CBPRINTF_LIBC_SUBSTS
- imply POSIX_API if !ARCH_POSIX
- imply EVENTFD if !ARCH_POSIX
- imply REBOOT
- imply ENTROPY_GENERATOR
- imply NET_UDP
- imply NET_IPV6
- imply NET_CONFIG_NEED_IPV6
- imply NET_SOCKETS
- help
- This option enables Connected Home over IP libraries.
-
-if CHIP
-
-config CHIP_PROJECT_CONFIG
- string "Project configuration file for CHIP"
- help
- Project configuration file for CHIP. If specified, CHIP generic
- configuration files will include the project configuration file which can
- be used to override any CHIP default or platform-specific settings.
-
-config CHIP_OPENTHREAD_CONFIG
- string "Custom OpenThread configuration file"
- help
- This option can be used to replace Zephyr-supplied OpenThread
- configuration file with a custom one.
-
-config CHIP_ZEPHYR_SHELL
- bool "Enable Zephyr-based CHIP shell"
- default n
- imply SHELL
- help
- Add CHIP commands to the Zephyr shell.
-
-config CHIP_STANDALONE_SHELL
- bool "Enable CHIP shell library"
- default n
- depends on !CHIP_ZEPHYR_SHELL
- help
- Link the application with the library containing CHIP shell commands.
-
-config CHIP_PW_RPC
- bool "Enable Pigweed RPC library"
- default n
- help
- Link the application with the library containing Pigweed RPC functionalities.
-
-config CHIP_BUILD_TESTS
- bool "Build CHIP unit tests"
- default n
- help
- This option enables building CHIP unit tests.
-
-config CHIP_DISABLE_CHIPOBLE_ADVERTISING_WHEN_PROVISIONED
- bool "Disable CHIPoBLE advertising when device is fully provisioned"
- default y
- help
- Disable CHIPoBLE advertising when the device achieves a fully provisioned state.
-
-config CHIP_ENABLE_PAIRING_AUTOSTART
- bool "Enable pairing autostart"
- default n
- help
- Open pairing window automatically at application boot time.
+rsource "../../zephyr/Kconfig"
config CHIP_NFC_COMMISSIONING
bool "Enable NFC commissioning support"
@@ -95,21 +26,4 @@
imply NFC_NDEF_URI_REC
imply NFC_NDEF_URI_MSG
help
- Enables NFC commissioning by sharing onboarding payload in NFC tag.
-
-config CHIP_ENABLE_DNSSD_SRP
- bool "Enable support for service registration"
- default y
- imply OPENTHREAD_ECDSA
- imply OPENTHREAD_SRP_CLIENT
- help
- Enables DNS-SD SRP client support
-
-config APP_LINK_WITH_CHIP
- bool "Link 'app' with Connected Home over IP"
- default y
- help
- Add Connected Home over IP header files to the 'app' include path
- and link the 'app' with Connected Home over IP libraries.
-
-endif
+ Enables NFC commissioning by sharing onboarding payload in NFC tag.
\ No newline at end of file
diff --git a/config/telink/app/enable-gnu-std.cmake b/config/telink/app/enable-gnu-std.cmake
new file mode 100644
index 0000000..38bacbe
--- /dev/null
+++ b/config/telink/app/enable-gnu-std.cmake
@@ -0,0 +1,19 @@
+#
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+add_library(gnu17 INTERFACE)
+target_compile_options(gnu17 INTERFACE -std=gnu++17 -D_SYS__PTHREADTYPES_H_)
+target_link_libraries(app PRIVATE gnu17)
\ No newline at end of file
diff --git a/config/telink/app/zephyr.conf b/config/telink/app/zephyr.conf
new file mode 100644
index 0000000..2974d22
--- /dev/null
+++ b/config/telink/app/zephyr.conf
@@ -0,0 +1,94 @@
+#
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+CONFIG_CHIP=y
+
+CONFIG_STD_CPP14=y
+
+CONFIG_LOG=y
+CONFIG_LOG_MODE_MINIMAL=y
+CONFIG_PRINTK=y
+CONFIG_ASSERT=y
+CONFIG_CBPRINTF_LIBC_SUBSTS=y
+
+# Generic networking options
+CONFIG_NETWORKING=y
+CONFIG_NET_CONFIG_SETTINGS=y
+CONFIG_NET_SOCKETS=y
+CONFIG_NET_SOCKETS_POSIX_NAMES=n
+
+# Disable TCP and IPv4 (TCP disabled to avoid heavy traffic)
+CONFIG_NET_TCP=n
+CONFIG_NET_IPV4=n
+
+CONFIG_NET_CONFIG_NEED_IPV4=n
+CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
+CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
+
+# Application stack size
+CONFIG_MAIN_STACK_SIZE=4096
+CONFIG_INIT_STACKS=y
+
+# Disable certain parts of Zephyr IPv6 stack
+CONFIG_NET_IPV6_NBR_CACHE=n
+CONFIG_NET_IPV6_MLD=n
+
+CONFIG_NET_MAX_CONN=1
+CONFIG_NET_MAX_CONTEXTS=1
+
+# Network buffers
+CONFIG_NET_PKT_RX_COUNT=8
+CONFIG_NET_PKT_TX_COUNT=8
+CONFIG_NET_BUF_RX_COUNT=32
+CONFIG_NET_BUF_TX_COUNT=32
+
+# Bluetooth Low Energy configs
+CONFIG_BT=n
+
+# L2 OpenThread enabling
+CONFIG_NET_L2_OPENTHREAD=y
+CONFIG_OPENTHREAD_DEBUG=y
+CONFIG_OPENTHREAD_L2_DEBUG=y
+CONFIG_OPENTHREAD_L2_LOG_LEVEL_INF=y
+
+CONFIG_OPENTHREAD_CHANNEL=26
+
+CONFIG_NET_CONFIG_IEEE802154_DEV_NAME="IEEE802154_b91"
+
+CONFIG_NET_CONFIG_MY_IPV6_ADDR="fdde:ad00:beef::1"
+CONFIG_NET_CONFIG_PEER_IPV6_ADDR="fdde:ad00:beef::2"
+
+# OpenThread configs
+CONFIG_OPENTHREAD_MTD=y
+CONFIG_OPENTHREAD_FTD=n
+CONFIG_OPENTHREAD_SLAAC=y
+CONFIG_OPENTHREAD_DHCP6_CLIENT=y
+CONFIG_OPENTHREAD_SNTP_CLIENT=y
+CONFIG_OPENTHREAD_DNS_CLIENT=y
+CONFIG_OPENTHREAD_MTD_NETDIAG=y
+CONFIG_OPENTHREAD_ENABLE_SERVICE=y
+CONFIG_OPENTHREAD_MANUAL_START=y
+CONFIG_OPENTHREAD_THREAD_STACK_SIZE=6144
+CONFIG_OPENTHREAD_MBEDTLS=y
+
+# mbedTLS tweaks
+CONFIG_MBEDTLS_DEBUG=y
+
+CONFIG_MBEDTLS_USER_CONFIG_ENABLE=y
+CONFIG_MBEDTLS_USER_CONFIG_FILE="telink-mbedtls-config.h"
+
+# TBD: Something wrong with this heap. Need to be investigated. Cirrently just set minimal size
+CONFIG_MBEDTLS_HEAP_SIZE=4
diff --git a/config/telink/chip-gn/.gn b/config/telink/chip-gn/.gn
new file mode 100644
index 0000000..ebab2d7
--- /dev/null
+++ b/config/telink/chip-gn/.gn
@@ -0,0 +1,29 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build_overrides/build.gni")
+import("//build_overrides/chip.gni")
+
+# The location of the build configuration file.
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
+
+# CHIP uses angle bracket includes.
+check_system_includes = true
+
+default_args = {
+ target_cpu = "riscv"
+ target_os = "zephyr"
+
+ import("${chip_root}/config/telink/chip-gn/args.gni")
+}
diff --git a/config/telink/chip-gn/BUILD.gn b/config/telink/chip-gn/BUILD.gn
new file mode 100644
index 0000000..fc91d76
--- /dev/null
+++ b/config/telink/chip-gn/BUILD.gn
@@ -0,0 +1,36 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build_overrides/build.gni")
+import("//build_overrides/chip.gni")
+
+import("${build_root}/chip/tests.gni")
+
+assert(current_os == "zephyr")
+
+declare_args() {
+ chip_build_pw_rpc_lib = false
+}
+
+group("telink") {
+ deps = [ "${chip_root}/src/lib" ]
+
+ if (chip_build_tests) {
+ deps += [ "${chip_root}/src:tests" ]
+ }
+}
+
+group("default") {
+ deps = [ ":telink" ]
+}
diff --git a/config/telink/chip-gn/args.gni b/config/telink/chip-gn/args.gni
new file mode 100644
index 0000000..dd975b1
--- /dev/null
+++ b/config/telink/chip-gn/args.gni
@@ -0,0 +1,26 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build_overrides/chip.gni")
+
+chip_device_platform = "telink"
+
+chip_build_tests = false
+
+chip_project_config_include = ""
+chip_system_project_config_include = ""
+chip_ble_project_config_include = ""
+chip_config_network_layer_ble = false
+
+custom_toolchain = "${chip_root}/config/telink/chip-gn/toolchain:zephyr"
diff --git a/config/telink/chip-gn/toolchain/BUILD.gn b/config/telink/chip-gn/toolchain/BUILD.gn
new file mode 100644
index 0000000..6a9fcbf
--- /dev/null
+++ b/config/telink/chip-gn/toolchain/BUILD.gn
@@ -0,0 +1,33 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/toolchain/gcc_toolchain.gni")
+import("//build_overrides/chip.gni")
+
+declare_args() {
+ zephyr_ar = ""
+ zephyr_cc = ""
+ zephyr_cxx = ""
+}
+
+gcc_toolchain("zephyr") {
+ ar = zephyr_ar
+ cc = zephyr_cc
+ cxx = zephyr_cxx
+
+ toolchain_args = {
+ current_os = "zephyr"
+ is_clang = false
+ }
+}
diff --git a/config/telink/chip-module/CMakeLists.txt b/config/telink/chip-module/CMakeLists.txt
new file mode 100644
index 0000000..27e6584
--- /dev/null
+++ b/config/telink/chip-module/CMakeLists.txt
@@ -0,0 +1,254 @@
+#
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# @file
+# CMake sub-project defining 'chip' target which represents CHIP library
+# Since CHIP doesn't provide native CMake support, ExternalProject
+# module is used to build the required artifacts with GN meta-build
+# system. It is assumed that find_package(Zephyr) has been called before
+# including this file.
+#
+
+if (CONFIG_CHIP)
+
+include(ExternalProject)
+include(../../zephyr/zephyr-util.cmake)
+
+# ==============================================================================
+# Declare configuration variables and define constants
+# ==============================================================================
+
+# C/C++ compiler flags passed to CHIP build system
+list(APPEND CHIP_CFLAGS)
+
+# C compiler flags passed to CHIP build system
+list(APPEND CHIP_CFLAGS_C)
+
+# C++ compiler flags passed to CHIP build system
+list(APPEND CHIP_CFLAGS_CC)
+
+# CHIP libraries that the application should be linked with
+list(APPEND CHIP_LIBRARIES)
+
+# GN meta-build system arguments in the form of 'key1 = value1\nkey2 = value2...' string
+string(APPEND CHIP_GN_ARGS)
+
+# C/C++ compiler flags which should not be forwarded to CHIP
+# build system (e.g. because CHIP configures them on its own)
+set(CHIP_CFLAG_EXCLUDES
+ "-fno-asynchronous-unwind-tables"
+ "-fno-common"
+ "-fno-defer-pop"
+ "-fno-reorder-functions"
+ "-ffunction-sections"
+ "-fdata-sections"
+ "-g*"
+ "-O*"
+ "-W*"
+)
+
+# ==============================================================================
+# Helper macros
+# ==============================================================================
+
+macro(chip_gn_arg_import FILE)
+ string(APPEND CHIP_GN_ARGS "import(\"${FILE}\")\n")
+endmacro()
+
+macro(chip_gn_arg_string ARG STRING)
+ string(APPEND CHIP_GN_ARGS "${ARG} = \"${STRING}\"\n")
+endmacro()
+
+macro(chip_gn_arg_bool ARG BOOLEAN)
+ if (${BOOLEAN})
+ string(APPEND CHIP_GN_ARGS "${ARG} = true\n")
+ else()
+ string(APPEND CHIP_GN_ARGS "${ARG} = false\n")
+ endif()
+endmacro()
+
+macro(chip_gn_arg_cflags ARG CFLAGS)
+ set(CFLAG_EXCLUDES "[")
+ foreach(cflag ${CHIP_CFLAG_EXCLUDES})
+ string(APPEND CFLAG_EXCLUDES "\"${cflag}\", ")
+ endforeach()
+ string(APPEND CFLAG_EXCLUDES "]")
+ string(APPEND CHIP_GN_ARGS "${ARG} = filter_exclude(string_split(\"${CFLAGS}\"), ${CFLAG_EXCLUDES})\n")
+endmacro()
+
+# ==============================================================================
+# Prepare CHIP configuration based on the project Kconfig configuration
+# ==============================================================================
+
+if (NOT CHIP_ROOT)
+ get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../.. REALPATH)
+endif()
+
+set(GN_ROOT_TARGET ${CHIP_ROOT}/config/telink/chip-gn)
+
+if (CONFIG_POSIX_API)
+ list(APPEND CHIP_CFLAGS
+ -D_SYS__PTHREADTYPES_H_
+ -isystem${ZEPHYR_BASE}/include/posix
+ )
+endif()
+
+zephyr_include_directories(${ZEPHYR_BASE}/../modules/crypto/mbedtls/include)
+zephyr_include_directories(${CHIP_ROOT}/src/platform/telink/)
+
+zephyr_get_compile_flags(CHIP_CFLAGS_C C)
+zephyr_get_compile_flags(CHIP_CFLAGS_CC CXX)
+zephyr_get_gnu_cpp_standard(CHIP_CFLAGS_CC)
+
+convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS CHIP_CFLAGS)
+convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS_C CHIP_CFLAGS_C)
+convert_list_of_flags_to_string_of_flags(CHIP_CFLAGS_CC CHIP_CFLAGS_CC)
+
+# Prepare CHIP libraries that the application should be linked with
+
+if (NOT CHIP_LIBRARIES)
+ set(CHIP_LIBRARIES -lCHIP)
+endif()
+
+if (CONFIG_CHIP_LIB_SHELL)
+ list(APPEND CHIP_LIBRARIES -lCHIPShell)
+endif()
+
+if (CONFIG_CHIP_PW_RPC)
+ list(APPEND CHIP_LIBRARIES -lPwRpc)
+endif()
+
+# Set up CHIP project configuration file
+
+if (CONFIG_CHIP_PROJECT_CONFIG)
+ get_filename_component(CHIP_PROJECT_CONFIG
+ ${CONFIG_CHIP_PROJECT_CONFIG}
+ REALPATH
+ BASE_DIR ${CMAKE_SOURCE_DIR}
+ )
+ set(CHIP_PROJECT_CONFIG "<${CHIP_PROJECT_CONFIG}>")
+else()
+ set(CHIP_PROJECT_CONFIG "")
+endif()
+
+# Set up custom OpenThread configuration
+
+if (CONFIG_CHIP_OPENTHREAD_CONFIG)
+ get_filename_component(CHIP_OPENTHREAD_CONFIG
+ ${CONFIG_CHIP_OPENTHREAD_CONFIG}
+ REALPATH
+ BASE_DIR ${CMAKE_SOURCE_DIR}
+ )
+ zephyr_set_openthread_config(${CHIP_OPENTHREAD_CONFIG})
+endif()
+
+# Find required programs
+
+find_program(GN_EXECUTABLE gn)
+if (${GN_EXECUTABLE} STREQUAL GN_EXECUTABLE-NOTFOUND)
+ message(FATAL_ERROR "The 'gn' command was not found. Make sure you have GN installed.")
+else()
+ # Parse the 'gn --version' output to find the installed version.
+ set(MIN_GN_VERSION 1851)
+ execute_process(
+ COMMAND
+ ${GN_EXECUTABLE} --version
+ OUTPUT_VARIABLE gn_version_output
+ ERROR_VARIABLE gn_error_output
+ RESULT_VARIABLE gn_status
+ )
+
+ if(${gn_status} EQUAL 0)
+ if(gn_version_output VERSION_LESS ${MIN_GN_VERSION})
+ message(FATAL_ERROR "Found unsuitable version of 'gn'. Required is at least ${MIN_GN_VERSION}")
+ endif()
+ else()
+ message(FATAL_ERROR "Could NOT find working gn: Found gn (${GN_EXECUTABLE}), but failed to load with:\n ${gn_error_output}")
+ endif()
+endif()
+
+find_package(Python3 REQUIRED)
+
+# ==============================================================================
+# Generate configuration for CHIP GN build system
+# ==============================================================================
+chip_gn_arg_cflags("target_cflags" ${CHIP_CFLAGS})
+chip_gn_arg_cflags("target_cflags_c" ${CHIP_CFLAGS_C})
+chip_gn_arg_cflags("target_cflags_cc" ${CHIP_CFLAGS_CC})
+chip_gn_arg_string("zephyr_ar" ${CMAKE_AR})
+chip_gn_arg_string("zephyr_cc" ${CMAKE_C_COMPILER})
+chip_gn_arg_string("zephyr_cxx" ${CMAKE_CXX_COMPILER})
+chip_gn_arg_string("chip_project_config_include" "${CHIP_PROJECT_CONFIG}")
+chip_gn_arg_string("chip_system_project_config_include" "${CHIP_PROJECT_CONFIG}")
+chip_gn_arg_bool ("is_debug" CONFIG_DEBUG)
+chip_gn_arg_bool ("chip_enable_openthread" CONFIG_NET_L2_OPENTHREAD)
+chip_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_NET_IPV4)
+chip_gn_arg_bool ("chip_build_tests" CONFIG_CHIP_BUILD_TESTS)
+chip_gn_arg_bool ("chip_inet_config_enable_raw_endpoint" CONFIG_CHIP_BUILD_TESTS)
+chip_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS)
+chip_gn_arg_bool ("chip_inet_config_enable_dns_resolver" CONFIG_CHIP_BUILD_TESTS)
+chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL)
+chip_gn_arg_bool ("chip_build_pw_rpc_lib" CONFIG_CHIP_PW_RPC)
+
+if (BOARD STREQUAL "native_posix")
+ chip_gn_arg_string("target_cpu" "x86")
+elseif (BOARD STREQUAL "native_posix_64")
+ chip_gn_arg_string("target_cpu" "x64")
+endif()
+
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/args.gn CONTENT ${CHIP_GN_ARGS})
+
+# ==============================================================================
+# Define 'chip-gn' target that builds CHIP library(ies) with GN build system
+# ==============================================================================
+
+ExternalProject_Add(
+ chip-gn
+ PREFIX ${CMAKE_CURRENT_BINARY_DIR}
+ SOURCE_DIR ${CHIP_ROOT}
+ BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}
+ CONFIGURE_COMMAND ${GN_EXECUTABLE}
+ --root=${CHIP_ROOT}
+ --root-target=${GN_ROOT_TARGET}
+ --dotfile=${GN_ROOT_TARGET}/.gn
+ --script-executable=${Python3_EXECUTABLE}
+ gen --check --fail-on-unused-args ${CMAKE_CURRENT_BINARY_DIR}
+ BUILD_COMMAND ninja
+ INSTALL_COMMAND ""
+ BUILD_BYPRODUCTS ${CHIP_LIBRARIES}
+ BUILD_ALWAYS TRUE
+ USES_TERMINAL_CONFIGURE TRUE
+ USES_TERMINAL_BUILD TRUE
+)
+add_dependencies(chip-gn kernel)
+
+# ==============================================================================
+# Define 'chip' target that exposes CHIP headers & libraries to the application
+# ==============================================================================
+
+zephyr_interface_library_named(chip)
+target_compile_definitions(chip INTERFACE CHIP_HAVE_CONFIG_H)
+target_include_directories(chip INTERFACE
+ ${CHIP_ROOT}/src
+ ${CHIP_ROOT}/src/include
+ ${CHIP_ROOT}/src/lib
+ ${CHIP_ROOT}/third_party/nlassert/repo/include
+ ${CMAKE_CURRENT_BINARY_DIR}/gen/include
+)
+target_link_directories(chip INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/lib)
+target_link_libraries(chip INTERFACE -Wl,--start-group ${CHIP_LIBRARIES} -Wl,--end-group)
+add_dependencies(chip chip-gn)
+
+endif() # CONFIG_CHIP
diff --git a/config/telink/chip-module/zephyr/module.yml b/config/telink/chip-module/zephyr/module.yml
new file mode 100644
index 0000000..4f08a9a
--- /dev/null
+++ b/config/telink/chip-module/zephyr/module.yml
@@ -0,0 +1,19 @@
+#
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+build:
+ cmake: .
+ kconfig: ../../zephyr/Kconfig
diff --git a/config/zephyr/Kconfig b/config/zephyr/Kconfig
new file mode 100644
index 0000000..1dc5c8c
--- /dev/null
+++ b/config/zephyr/Kconfig
@@ -0,0 +1,103 @@
+#
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+menuconfig CHIP
+ bool "Connected Home over IP protocol stack"
+ default n
+ select CPLUSPLUS
+ imply LIB_CPLUSPLUS
+ imply REQUIRES_FULL_LIBC
+ imply CBPRINTF_LIBC_SUBSTS
+ imply POSIX_API if !ARCH_POSIX
+ imply EVENTFD if !ARCH_POSIX
+ imply REBOOT
+ imply ENTROPY_GENERATOR
+ imply NET_UDP
+ imply NET_IPV6
+ imply NET_CONFIG_NEED_IPV6
+ imply NET_SOCKETS
+ help
+ This option enables Connected Home over IP libraries.
+
+if CHIP
+
+config CHIP_PROJECT_CONFIG
+ string "Project configuration file for CHIP"
+ help
+ Project configuration file for CHIP. If specified, CHIP generic
+ configuration files will include the project configuration file which can
+ be used to override any CHIP default or platform-specific settings.
+
+config CHIP_OPENTHREAD_CONFIG
+ string "Custom OpenThread configuration file"
+ help
+ This option can be used to replace Zephyr-supplied OpenThread
+ configuration file with a custom one.
+
+config CHIP_ZEPHYR_SHELL
+ bool "Enable Zephyr-based CHIP shell"
+ default n
+ imply SHELL
+ help
+ Add CHIP commands to the Zephyr shell.
+
+config CHIP_STANDALONE_SHELL
+ bool "Enable CHIP shell library"
+ default n
+ depends on !CHIP_ZEPHYR_SHELL
+ help
+ Link the application with the library containing CHIP shell commands.
+
+config CHIP_PW_RPC
+ bool "Enable Pigweed RPC library"
+ default n
+ help
+ Link the application with the library containing Pigweed RPC functionalities.
+
+config CHIP_BUILD_TESTS
+ bool "Build CHIP unit tests"
+ default n
+ help
+ This option enables building CHIP unit tests.
+
+config CHIP_DISABLE_CHIPOBLE_ADVERTISING_WHEN_PROVISIONED
+ bool "Disable CHIPoBLE advertising when device is fully provisioned"
+ default y
+ help
+ Disable CHIPoBLE advertising when the device achieves a fully provisioned state.
+
+config CHIP_ENABLE_PAIRING_AUTOSTART
+ bool "Enable pairing autostart"
+ default n
+ help
+ Open pairing window automatically at application boot time.
+
+config CHIP_ENABLE_DNSSD_SRP
+ bool "Enable support for service registration"
+ default y
+ imply OPENTHREAD_ECDSA
+ imply OPENTHREAD_SRP_CLIENT
+ help
+ Enables DNS-SD SRP client support
+
+config APP_LINK_WITH_CHIP
+ bool "Link 'app' with Connected Home over IP"
+ default y
+ help
+ Add Connected Home over IP header files to the 'app' include path
+ and link the 'app' with Connected Home over IP libraries.
+
+endif
diff --git a/config/nrfconnect/chip-module/zephyr-util.cmake b/config/zephyr/zephyr-util.cmake
similarity index 98%
rename from config/nrfconnect/chip-module/zephyr-util.cmake
rename to config/zephyr/zephyr-util.cmake
index 2250ad9..91f7398 100644
--- a/config/nrfconnect/chip-module/zephyr-util.cmake
+++ b/config/zephyr/zephyr-util.cmake
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2020 Project CHIP Authors
+# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
diff --git a/examples/lighting-app/telink/CMakeLists.txt b/examples/lighting-app/telink/CMakeLists.txt
new file mode 100644
index 0000000..ca9aa58
--- /dev/null
+++ b/examples/lighting-app/telink/CMakeLists.txt
@@ -0,0 +1,86 @@
+#
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+cmake_minimum_required(VERSION 3.13.1)
+
+get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connectedhomeip REALPATH)
+get_filename_component(NLIO_ROOT ${CHIP_ROOT}/third_party/nlio/repo/include REALPATH)
+get_filename_component(TELINK_COMMON ${CHIP_ROOT}/examples/platform/telink REALPATH)
+get_filename_component(LIGHTING_COMMON ${CHIP_ROOT}/examples/lighting-app/lighting-common REALPATH)
+
+set(CONF_FILE ${CHIP_ROOT}/config/telink/app/zephyr.conf prj.conf)
+
+# Load NCS/Zephyr build system
+list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/telink/chip-module)
+find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
+
+project(chip-telink-lighting-example)
+
+include(${CHIP_ROOT}/config/telink/app/enable-gnu-std.cmake)
+
+target_compile_options(app PRIVATE -fpermissive)
+
+target_include_directories(app PRIVATE
+ include
+ ${LIGHTING_COMMON}
+ ${NLIO_ROOT}
+ ${TELINK_COMMON}/util/include
+ ${TELINK_COMMON}/app/include)
+
+target_sources(app PRIVATE
+ src/AppTask.cpp
+ src/LightingManager.cpp
+ src/main.cpp
+ src/ZclCallbacks.cpp
+ ${LIGHTING_COMMON}/gen/attribute-size.cpp
+ ${LIGHTING_COMMON}/gen/callback-stub.cpp
+ ${LIGHTING_COMMON}/gen/IMClusterCommandHandler.cpp
+ ${TELINK_COMMON}/util/src/LEDWidget.cpp
+ ${TELINK_COMMON}/util/src/ButtonManager.cpp
+ ${TELINK_COMMON}/util/src/ThreadUtil.cpp
+ ${CHIP_ROOT}/src/app/util/DataModelHandler.cpp
+ ${CHIP_ROOT}/src/app/reporting/reporting-default-configuration.cpp
+ ${CHIP_ROOT}/src/app/reporting/reporting.cpp
+ ${CHIP_ROOT}/src/app/util/af-event.cpp
+ ${CHIP_ROOT}/src/app/util/af-main-common.cpp
+ ${CHIP_ROOT}/src/app/util/attribute-list-byte-span.cpp
+ ${CHIP_ROOT}/src/app/util/attribute-size.cpp
+ ${CHIP_ROOT}/src/app/util/attribute-storage.cpp
+ ${CHIP_ROOT}/src/app/util/attribute-table.cpp
+ ${CHIP_ROOT}/src/app/util/binding-table.cpp
+ ${CHIP_ROOT}/src/app/util/chip-message-send.cpp
+ ${CHIP_ROOT}/src/app/util/client-api.cpp
+ ${CHIP_ROOT}/src/app/util/ember-compatibility-functions.cpp
+ ${CHIP_ROOT}/src/app/util/ember-print.cpp
+ ${CHIP_ROOT}/src/app/util/message.cpp
+ ${CHIP_ROOT}/src/app/util/process-cluster-message.cpp
+ ${CHIP_ROOT}/src/app/util/process-global-message.cpp
+ ${CHIP_ROOT}/src/app/util/util.cpp
+ ${CHIP_ROOT}/src/app/server/EchoHandler.cpp
+ ${CHIP_ROOT}/src/app/server/Mdns.cpp
+ ${CHIP_ROOT}/src/app/server/OnboardingCodesUtil.cpp
+ ${CHIP_ROOT}/src/app/server/RendezvousServer.cpp
+ ${CHIP_ROOT}/src/app/server/Server.cpp
+ ${CHIP_ROOT}/src/app/server/StorablePeerConnection.cpp
+ ${CHIP_ROOT}/src/app/clusters/basic/basic.cpp
+ ${CHIP_ROOT}/src/app/clusters/bindings/bindings.cpp
+ ${CHIP_ROOT}/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp
+ ${CHIP_ROOT}/src/app/clusters/on-off-server/on-off-server.cpp
+ ${CHIP_ROOT}/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp
+ ${CHIP_ROOT}/src/app/clusters/level-control/level-control.cpp
+ ${CHIP_ROOT}/src/app/clusters/network-commissioning/network-commissioning-ember.cpp
+ ${CHIP_ROOT}/src/app/clusters/network-commissioning/network-commissioning.cpp
+ ${CHIP_ROOT}/src/app/clusters/trusted-root-certificates-server/trusted-root-certificates-server.cpp
+ )
diff --git a/examples/lighting-app/telink/Readme.md b/examples/lighting-app/telink/Readme.md
new file mode 100644
index 0000000..08919fb
--- /dev/null
+++ b/examples/lighting-app/telink/Readme.md
@@ -0,0 +1,227 @@
+![Telink B91 EVK](http://wiki.telink-semi.cn/wiki/assets/Hardware/B91_Generic_Starter_Kit_Hardware_Guide/connection_chart.png)
+
+## Build
+
+1. Pull docker image from repository:
+
+ ```
+ $ docker pull alexkolosovtelinksemi/chip-build-telink:latest
+ ```
+
+1. Run docker container:
+
+ ```
+ $ docker run -it -v ${CHIP_BASE}:/root/chip alexkolosovtelinksemi/chip-build-telink:latest
+ ```
+
+ here `${CHIP_BASE}` is directory which contains CHIP repo files **!!!Pay
+ attention that OUTPUT_DIR should conatins ABSOLUTE path to output dir**
+
+1. Run build script:
+ ```
+ cd /root/chip/scripts/examples && ./telink_example.sh
+ ```
+1. Exit docker container and collect build artifacts. Firmware binary would be
+ located in
+ **\${CHIP_BASE}/examples/lighting-app/telink/build/tlsr9518adk80d/zephyr/zephyr.bin**
+
+## Flash
+
+### Presetup
+
+To make `west flash` command works following steps should be performed just
+once:
+
+1. Download toolchain:
+ ```
+ $ wget http://wiki.telink-semi.cn/tools_and_sdk/Tools/IDE/telink_riscv_linux_toolchain.zip
+ $ unzip telink_riscv_linux_toolchain.zip
+ ```
+1. Add TELINK_TOOLCHAIN_BASE variable to environment:
+ ```
+ $ export TELINK_TOOLCHAIN_BASE=${PATH_TO_TOOLCHAIN}
+ ```
+1. Setup dependencies:
+
+ ```
+ $ sudo dpkg --add-architecture i386
+ $ sudo apt-get update
+ $ sudo apt-get install -y libc6:i386 libncurses5:i386 libstdc++6:i386
+ ```
+
+### Flashing
+
+1. Go to example directory and flash board with west command
+ ```
+ $ cd ${TELINK_LIGHTING_EXAMPLE_DIR} && west flash
+ ```
+
+## Border Router
+
+### Build
+
+Use following manual to build your own border router:
+https://openthread.io/guides/border-router/build Pay attention that border
+router should be configured as Access Point i.e next command should be executed
+in step 3:
+
+```
+$ BORDER_ROUTING=0 NETWORK_MANAGER=1 ./script/setup
+```
+
+### Setup IPv6
+
+Pay attention that border router shoud be configured as IPv6 access point.
+
+1. To do so perform the following command:
+ ```
+ ip -6 addr add 2001:db8:1::1/64 dev wlan0
+ ```
+2. Add following lines in **/etc/dnsmasq.conf** file:
+ ```
+ enable-ra
+ dhcp-range=2001:db8:1::, ra-only, 64, 12h
+ ```
+
+### Config network
+
+Use [Web GUI](https://openthread.io/guides/border-router/web-gui) to config
+Thread network **tlsr9518adk80d** board supports only static comissioning with
+predefined Thread credentials shown in table below:
+
+| Item | Value |
+| :--------------------- | :------------------------------: |
+| Network name | OpenThreadDemo |
+| Network ExtendedPAN ID | 1111111122222222 |
+| PAN ID | 0x1234 |
+| Passphrase | 123456 |
+| Master Key | 00112233445566778899aabbccddeeff |
+| Channel | 15 |
+| On-Mesh Prefix | fd11:22:: |
+
+## Usage
+
+### UART
+
+To get output from device, connect UART to following pins:
+
+| Name | Pin |
+| :--: | :---------------------------- |
+| RX | PB3 (pin 17 of J34 connector) |
+| TX | PB2 (pin 16 of J34 connector) |
+| GND | GND |
+
+### Buttons
+
+The following buttons are available on **tlsr9518adk80d** board:
+
+| Name | Function | Description |
+| :------- | :--------------- | :---------------------------------------------------------------------------------------------------- |
+| Button 1 | Factory reset | Perform factory reset to forget currently commissioned Thread network and back to uncommisioned state |
+| Button 2 | Lighting control | Manually triggers the lighting state |
+| Button 3 | Thread start | Comission thread with static credentials and enables the Thread on device |
+
+### LEDs
+
+**Red** LED indicates current state of Thread network. It ables to be in
+following states:
+
+| State | Description |
+| :-------------------------- | :--------------------------------------------------------------------------- |
+| Blinks with short pulses | Device is not commisioned to Thread, Thred is disabled |
+| Blinls with frequent pulses | Device is commissioned, Thread enabled. Device trying to JOIN thread network |
+| Blinks with whde pulses | Device commissioned and joined to thread network as CHILD |
+
+**Blue** LED shows current state of lightbulb
+
+### Check connection
+
+1. With your client device (PC, Laptop etc.) connect to BorderRouterAP WiFi
+2. Press Button 3 on **tlsr9518adk80d** board and wait till it joins to Thread
+ network
+3. Find ajusted IPv6 address in UART output of **tlsr9518adk80d**
+4. Perform following command on your client device:
+ ```
+ ping -6 ${IP_ADDRESS_OF_CHIP_DEVICE}
+ ```
+ here `${IP_ADDRESS_OF_CHIP_DEVICE}` is address which you got from UART
+ output of **tlsr9518adk80d** board If everything is ok then `ping` command
+ should perform transactions without losses
+
+### CHIP tool commands
+
+1. Build
+ [chip-tool cli](https://github.com/project-chip/connectedhomeip/blob/master/examples/chip-tool/README.md)
+1. Pair with device
+
+ ```
+ ${CHIP_TOOL_DIR}/chip-tool pairing bypass ${IP_ADDRESS_OF_CHIP_DEVICE} 11097
+ ```
+
+ here:
+
+ - `${IP_ADDRESS_OF_CHIP_DEVICE}` is IPv6 address of CHIP device
+ - **11097** is standart CHIP TCP port
+
+1. Switch on the light:
+
+ ```
+ ${CHIP_TOOL_DIR}/chip-tool onoff on 1
+ ```
+
+ here:
+
+ - **onoff** is name of cluster
+ - **on** command to the cluster
+ - **1** ID of endpoint
+
+1. Switch off the light:
+
+ ```
+ ${CHIP_TOOL_DIR}/chip-tool onoff off 1
+ ```
+
+ here:
+
+ - **onoff** is name of cluster
+ - **off** command to the cluster
+ - **1** ID of endpoint
+
+1. Read the light state:
+
+ ```
+ ${CHIP_TOOL_DIR}/chip-tool onoff read on-off 1
+ ```
+
+ here:
+
+ - **onoff** is name of cluster
+ - **read** command to the cluster
+ - **on-off** attribute to read
+ - **1** ID of endpoint
+
+1. Change brightness of light:
+
+ ```
+ ${CHIP_TOOL_DIR}/chip-tool levelcontrol move-to-level 32 0 0 0 1
+ ```
+
+ here:
+
+ - **levelcontrol** is name of cluster
+ - **move-to-level** command to the cluster
+ - **32** brightness value
+ - **0** transition time
+ - **0** option mask
+ - **0** option override
+ - **1** ID of endpoint
+
+1. Reag brightness level:
+ ```
+ ./chip-tool levelcontrol read current-level 1
+ ```
+ here:
+ - **levelcontrol** is name of cluster
+ - **read** command to the cluster
+ - **current-level** attribute to read
+ - **1** ID of endpoint
diff --git a/examples/lighting-app/telink/include/AppConfig.h b/examples/lighting-app/telink/include/AppConfig.h
new file mode 100644
index 0000000..f23e38c
--- /dev/null
+++ b/examples/lighting-app/telink/include/AppConfig.h
@@ -0,0 +1,31 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+// ---- Lighting Example App Config ----
+#define BUTTON_PORT DT_LABEL(DT_NODELABEL(gpioc))
+
+#define BUTTON_PIN_1 2
+#define BUTTON_PIN_3 3
+#define BUTTON_PIN_4 1
+#define BUTTON_PIN_2 0
+
+#define SYSTEM_STATE_LED_PIN 7
+#define LIGHTING_PWM_DEVICE DT_PWMS_LABEL(DT_ALIAS(pwm_led0))
+#define LIGHTING_PWM_CHANNEL DT_PWMS_CHANNEL(DT_ALIAS(pwm_led0))
diff --git a/examples/lighting-app/telink/include/AppEvent.h b/examples/lighting-app/telink/include/AppEvent.h
new file mode 100644
index 0000000..548d737
--- /dev/null
+++ b/examples/lighting-app/telink/include/AppEvent.h
@@ -0,0 +1,56 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <cstdint>
+
+struct AppEvent;
+typedef void (*EventHandler)(AppEvent *);
+
+struct AppEvent
+{
+ enum AppEventTypes
+ {
+ kEventType_Button = 0,
+ kEventType_Timer,
+ kEventType_Lighting,
+ kEventType_Install,
+ };
+
+ uint16_t Type;
+
+ union
+ {
+ struct
+ {
+ uint8_t Action;
+ } ButtonEvent;
+ struct
+ {
+ void * Context;
+ } TimerEvent;
+ struct
+ {
+ uint8_t Action;
+ int32_t Actor;
+ } LightingEvent;
+ };
+
+ EventHandler Handler;
+};
diff --git a/examples/lighting-app/telink/include/AppTask.h b/examples/lighting-app/telink/include/AppTask.h
new file mode 100644
index 0000000..cf8b642
--- /dev/null
+++ b/examples/lighting-app/telink/include/AppTask.h
@@ -0,0 +1,67 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "AppEvent.h"
+#include "LightingManager.h"
+
+#include <platform/CHIPDeviceLayer.h>
+
+#include <cstdint>
+
+struct k_timer;
+
+class AppTask
+{
+public:
+ int StartApp();
+
+ void PostLightingActionRequest(LightingManager::Action_t aAction);
+ void PostEvent(AppEvent * event);
+ void UpdateClusterState();
+
+private:
+ friend AppTask & GetAppTask(void);
+
+ int Init();
+
+ static void ActionInitiated(LightingManager::Action_t aAction, int32_t aActor);
+ static void ActionCompleted(LightingManager::Action_t aAction, int32_t aActor);
+
+ void DispatchEvent(AppEvent * event);
+
+ static void LightingActionButtonEventHandler(void);
+ static void FactoryResetButtonEventHandler(void);
+ static void StartThreadButtonEventHandler(void);
+
+ static void FactoryResetHandler(AppEvent * aEvent);
+ static void StartThreadHandler(AppEvent * aEvent);
+ static void LightingActionEventHandler(AppEvent * aEvent);
+
+ static void InitButtons(void);
+
+ static void ThreadProvisioningHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);
+
+ static AppTask sAppTask;
+};
+
+inline AppTask & GetAppTask(void)
+{
+ return AppTask::sAppTask;
+}
diff --git a/examples/lighting-app/telink/include/CHIPProjectConfig.h b/examples/lighting-app/telink/include/CHIPProjectConfig.h
new file mode 100644
index 0000000..1e937f0
--- /dev/null
+++ b/examples/lighting-app/telink/include/CHIPProjectConfig.h
@@ -0,0 +1,32 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * Example project configuration file for CHIP.
+ *
+ * This is a place to put application or project-specific overrides
+ * to the default configuration values for general CHIP features.
+ *
+ */
+
+#pragma once
+
+// Use a default pairing code if one hasn't been provisioned in flash.
+#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021
+#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
diff --git a/examples/lighting-app/telink/include/LightingManager.h b/examples/lighting-app/telink/include/LightingManager.h
new file mode 100644
index 0000000..2be688a
--- /dev/null
+++ b/examples/lighting-app/telink/include/LightingManager.h
@@ -0,0 +1,74 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "AppEvent.h"
+
+#include <cstdint>
+#include <drivers/gpio.h>
+
+class LightingManager
+{
+public:
+ enum Action_t : uint8_t
+ {
+ ON_ACTION = 0,
+ OFF_ACTION,
+ LEVEL_ACTION,
+
+ INVALID_ACTION
+ };
+
+ enum State_t : uint8_t
+ {
+ kState_On = 0,
+ kState_Off,
+ };
+
+ using LightingCallback_fn = void (*)(Action_t, int32_t);
+
+ int Init(const char * pwmDeviceName, uint32_t pwmChannel);
+ bool IsTurnedOn() const { return mState == kState_On; }
+ uint8_t GetLevel() const { return mLevel; }
+ bool InitiateAction(Action_t aAction, int32_t aActor, uint8_t size, uint8_t * value);
+ void SetCallbacks(LightingCallback_fn aActionInitiated_CB, LightingCallback_fn aActionCompleted_CB);
+
+private:
+ static constexpr uint8_t kMaxLevel = 255;
+
+ friend LightingManager & LightingMgr();
+ State_t mState;
+ uint8_t mLevel;
+ const device * mPwmDevice;
+ uint32_t mPwmChannel;
+
+ LightingCallback_fn mActionInitiated_CB;
+ LightingCallback_fn mActionCompleted_CB;
+
+ void Set(bool aOn);
+ void SetLevel(uint8_t aLevel);
+ void UpdateLight();
+
+ static LightingManager sLight;
+};
+
+inline LightingManager & LightingMgr(void)
+{
+ return LightingManager::sLight;
+}
diff --git a/examples/lighting-app/telink/prj.conf b/examples/lighting-app/telink/prj.conf
new file mode 100644
index 0000000..9056e68
--- /dev/null
+++ b/examples/lighting-app/telink/prj.conf
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# This sample uses sample-defaults.conf to set options common for all
+# samples. This file should contain only options specific for this sample
+# or overrides of default values.
+
+# enable GPIO
+CONFIG_GPIO=y
+
+# enable PWM
+CONFIG_PWM=y
+
+# Default OpenThread network settings
+CONFIG_OPENTHREAD_PANID=4660
+CONFIG_OPENTHREAD_CHANNEL=15
+CONFIG_OPENTHREAD_NETWORK_NAME="OpenThreadDemo"
+CONFIG_OPENTHREAD_XPANID="11:11:11:11:22:22:22:22"
+CONFIG_OPENTHREAD_JOINER=y
+CONFIG_OPENTHREAD_LOG_LEVEL_DEBG=y
+CONFIG_NET_CONFIG_IEEE802154_DEV_NAME="IEEE802154_b91"
+
+
+# Bluetooth overrides
+CONFIG_BT_DEVICE_NAME="ChipLight"
+
+# Additional configs for debbugging experience.
+CONFIG_THREAD_NAME=y
+
+# CHIP configuration
+CONFIG_CHIP_PROJECT_CONFIG="include/CHIPProjectConfig.h"
+CONFIG_CHIP_OPENTHREAD_CONFIG="../../platform/telink/project_include/OpenThreadConfig.h"
+
+CONFIG_DEBUG=n
\ No newline at end of file
diff --git a/examples/lighting-app/telink/src/AppTask.cpp b/examples/lighting-app/telink/src/AppTask.cpp
new file mode 100644
index 0000000..2ba8d88
--- /dev/null
+++ b/examples/lighting-app/telink/src/AppTask.cpp
@@ -0,0 +1,345 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "AppTask.h"
+
+#include "AppConfig.h"
+#include "AppEvent.h"
+#include "ButtonManager.h"
+#include "LEDWidget.h"
+#include "LightingManager.h"
+#include <app/server/OnboardingCodesUtil.h>
+#include <app/server/Server.h>
+
+#include "ThreadUtil.h"
+
+#include <app/common/gen/attribute-id.h>
+#include <app/common/gen/attribute-type.h>
+#include <app/common/gen/cluster-id.h>
+#include <app/util/attribute-storage.h>
+
+#include <platform/CHIPDeviceLayer.h>
+
+#include <setup_payload/QRCodeSetupPayloadGenerator.h>
+#include <setup_payload/SetupPayload.h>
+#include <support/ErrorStr.h>
+#include <system/SystemClock.h>
+
+#include <logging/log.h>
+#include <zephyr.h>
+
+#include <algorithm>
+
+LOG_MODULE_DECLARE(app);
+
+namespace {
+
+constexpr int kAppEventQueueSize = 10;
+constexpr uint8_t kButtonPushEvent = 1;
+constexpr uint8_t kButtonReleaseEvent = 0;
+
+K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), kAppEventQueueSize, alignof(AppEvent));
+
+LEDWidget sStatusLED;
+
+Button sFactoryResetButton;
+Button sLightingButton;
+Button sThreadStartButton;
+
+bool sIsThreadProvisioned = false;
+bool sIsThreadEnabled = false;
+bool sIsThreadAttached = false;
+bool sHaveBLEConnections = false;
+bool sHaveServiceConnectivity = false;
+
+} // namespace
+
+using namespace ::chip::DeviceLayer;
+
+AppTask AppTask::sAppTask;
+
+int AppTask::Init()
+{
+ int ret;
+
+ // Initialize LEDs
+ LEDWidget::InitGpio();
+
+ sStatusLED.Init(SYSTEM_STATE_LED_PIN);
+
+ InitButtons();
+
+ // Init lighting manager
+ ret = LightingMgr().Init(LIGHTING_PWM_DEVICE, LIGHTING_PWM_CHANNEL);
+ if (ret != 0)
+ {
+ LOG_ERR("Failed to int lighting manager");
+ return ret;
+ }
+
+ LightingMgr().SetCallbacks(ActionInitiated, ActionCompleted);
+
+ // Init ZCL Data Model and start server
+ InitServer();
+ ConfigurationMgr().LogDeviceConfig();
+ PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
+
+ // Setup test pairing
+ ret = AddTestPairing();
+ if (ret != CHIP_NO_ERROR)
+ {
+ LOG_ERR("Failed to add test pairing");
+ return ret;
+ }
+
+ return 0;
+}
+
+int AppTask::StartApp()
+{
+ int ret = Init();
+
+ if (ret)
+ {
+ LOG_ERR("AppTask.Init() failed");
+ return ret;
+ }
+
+ AppEvent event = {};
+
+ while (true)
+ {
+ ret = k_msgq_get(&sAppEventQueue, &event, K_MSEC(10));
+
+ while (!ret)
+ {
+ DispatchEvent(&event);
+ ret = k_msgq_get(&sAppEventQueue, &event, K_NO_WAIT);
+ }
+
+ // Collect connectivity and configuration state from the CHIP stack. Because the
+ // CHIP event loop is being run in a separate task, the stack must be locked
+ // while these values are queried. However we use a non-blocking lock request
+ // (TryLockChipStack()) to avoid blocking other UI activities when the CHIP
+ // task is busy (e.g. with a long crypto operation).
+
+ if (PlatformMgr().TryLockChipStack())
+ {
+ sIsThreadProvisioned = ConnectivityMgr().IsThreadProvisioned();
+ sIsThreadEnabled = ConnectivityMgr().IsThreadEnabled();
+ sIsThreadAttached = ConnectivityMgr().IsThreadAttached();
+ sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0);
+ sHaveServiceConnectivity = ConnectivityMgr().HaveServiceConnectivity();
+ PlatformMgr().UnlockChipStack();
+ }
+
+ if (sHaveServiceConnectivity)
+ {
+ sStatusLED.Set(true);
+ }
+ else if (sIsThreadProvisioned && sIsThreadEnabled)
+ {
+ if (sIsThreadAttached)
+ {
+ sStatusLED.Blink(950, 50);
+ }
+ else
+ {
+ sStatusLED.Blink(100, 100);
+ }
+ }
+ else
+ {
+ sStatusLED.Blink(50, 950);
+ }
+
+ sStatusLED.Animate();
+ }
+}
+
+void AppTask::LightingActionButtonEventHandler(void)
+{
+ AppEvent event;
+
+ event.Type = AppEvent::kEventType_Button;
+ event.ButtonEvent.Action = kButtonPushEvent;
+ event.Handler = LightingActionEventHandler;
+ sAppTask.PostEvent(&event);
+}
+
+void AppTask::LightingActionEventHandler(AppEvent * aEvent)
+{
+ LightingManager::Action_t action = LightingManager::INVALID_ACTION;
+ int32_t actor = 0;
+
+ if (aEvent->Type == AppEvent::kEventType_Lighting)
+ {
+ action = static_cast<LightingManager::Action_t>(aEvent->LightingEvent.Action);
+ actor = aEvent->LightingEvent.Actor;
+ }
+ else if (aEvent->Type == AppEvent::kEventType_Button)
+ {
+ action = LightingMgr().IsTurnedOn() ? LightingManager::OFF_ACTION : LightingManager::ON_ACTION;
+ actor = AppEvent::kEventType_Button;
+ }
+
+ if (action != LightingManager::INVALID_ACTION && !LightingMgr().InitiateAction(action, actor, 0, NULL))
+ LOG_INF("Action is already in progress or active.");
+}
+
+void AppTask::FactoryResetButtonEventHandler(void)
+{
+ AppEvent event;
+
+ event.Type = AppEvent::kEventType_Button;
+ event.ButtonEvent.Action = kButtonPushEvent;
+ event.Handler = FactoryResetHandler;
+ sAppTask.PostEvent(&event);
+}
+
+void AppTask::FactoryResetHandler(AppEvent * aEvent)
+{
+ LOG_INF("Factory Reset triggered.");
+ ConfigurationMgr().InitiateFactoryReset();
+}
+
+void AppTask::StartThreadButtonEventHandler(void)
+{
+ AppEvent event;
+
+ event.Type = AppEvent::kEventType_Button;
+ event.ButtonEvent.Action = kButtonPushEvent;
+ event.Handler = StartThreadHandler;
+ sAppTask.PostEvent(&event);
+}
+
+void AppTask::StartThreadHandler(AppEvent * aEvent)
+{
+ if (!chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned())
+ {
+ StartDefaultThreadNetwork();
+ LOG_INF("Device is not commissioned to a Thread network. Starting with the default configuration.");
+ }
+ else
+ {
+ LOG_INF("Device is commissioned to a Thread network.");
+ }
+}
+
+void AppTask::ActionInitiated(LightingManager::Action_t aAction, int32_t aActor)
+{
+ if (aAction == LightingManager::ON_ACTION)
+ {
+ LOG_INF("Turn On Action has been initiated");
+ }
+ else if (aAction == LightingManager::OFF_ACTION)
+ {
+ LOG_INF("Turn Off Action has been initiated");
+ }
+ else if (aAction == LightingManager::LEVEL_ACTION)
+ {
+ LOG_INF("Level Action has been initiated");
+ }
+}
+
+void AppTask::ActionCompleted(LightingManager::Action_t aAction, int32_t aActor)
+{
+ if (aAction == LightingManager::ON_ACTION)
+ {
+ LOG_INF("Turn On Action has been completed");
+ }
+ else if (aAction == LightingManager::OFF_ACTION)
+ {
+ LOG_INF("Turn Off Action has been completed");
+ }
+ else if (aAction == LightingManager::LEVEL_ACTION)
+ {
+ LOG_INF("Level Action has been completed");
+ }
+
+ if (aActor == AppEvent::kEventType_Button)
+ {
+ sAppTask.UpdateClusterState();
+ }
+}
+
+void AppTask::PostLightingActionRequest(LightingManager::Action_t aAction)
+{
+ AppEvent event;
+ event.Type = AppEvent::kEventType_Lighting;
+ event.LightingEvent.Action = aAction;
+ event.Handler = LightingActionEventHandler;
+ PostEvent(&event);
+}
+
+void AppTask::PostEvent(AppEvent * aEvent)
+{
+ if (k_msgq_put(&sAppEventQueue, aEvent, K_NO_WAIT) != 0)
+ {
+ LOG_INF("Failed to post event to app task event queue");
+ }
+}
+
+void AppTask::DispatchEvent(AppEvent * aEvent)
+{
+ if (aEvent->Handler)
+ {
+ aEvent->Handler(aEvent);
+ }
+ else
+ {
+ LOG_INF("Event received with no handler. Dropping event.");
+ }
+}
+
+void AppTask::UpdateClusterState()
+{
+ uint8_t onoff = LightingMgr().IsTurnedOn();
+
+ // write the new on/off value
+ EmberAfStatus status = emberAfWriteAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, &onoff,
+ ZCL_BOOLEAN_ATTRIBUTE_TYPE);
+ if (status != EMBER_ZCL_STATUS_SUCCESS)
+ {
+ LOG_ERR("Updating on/off cluster failed: %x", status);
+ }
+
+ uint8_t level = LightingMgr().GetLevel();
+
+ status = emberAfWriteAttribute(1, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, &level,
+ ZCL_DATA8_ATTRIBUTE_TYPE);
+
+ if (status != EMBER_ZCL_STATUS_SUCCESS)
+ {
+ LOG_ERR("Updating level cluster failed: %x", status);
+ }
+}
+
+void AppTask::InitButtons(void)
+{
+ const struct device * port = device_get_binding(BUTTON_PORT);
+ assert(port != NULL);
+
+ sFactoryResetButton.Configure(port, BUTTON_PIN_3, BUTTON_PIN_1, FactoryResetButtonEventHandler);
+ sLightingButton.Configure(port, BUTTON_PIN_4, BUTTON_PIN_1, LightingActionButtonEventHandler);
+ sThreadStartButton.Configure(port, BUTTON_PIN_3, BUTTON_PIN_2, StartThreadButtonEventHandler);
+
+ ButtonManagerInst().AddButton(sFactoryResetButton);
+ ButtonManagerInst().AddButton(sLightingButton);
+ ButtonManagerInst().AddButton(sThreadStartButton);
+}
diff --git a/examples/lighting-app/telink/src/LightingManager.cpp b/examples/lighting-app/telink/src/LightingManager.cpp
new file mode 100644
index 0000000..9e76cca
--- /dev/null
+++ b/examples/lighting-app/telink/src/LightingManager.cpp
@@ -0,0 +1,129 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "LightingManager.h"
+
+#include "AppConfig.h"
+
+#include <drivers/pwm.h>
+#include <logging/log.h>
+#include <zephyr.h>
+
+LOG_MODULE_DECLARE(app);
+
+LightingManager LightingManager::sLight;
+
+int LightingManager::Init(const char * pwmDeviceName, uint32_t pwmChannel)
+{
+ // We use a gpioPin instead of a LEDWidget here because we want to use PWM
+ // and other features instead of just on/off.
+
+ mState = kState_On;
+ mLevel = kMaxLevel;
+ mPwmDevice = device_get_binding(pwmDeviceName);
+ mPwmChannel = pwmChannel;
+
+ if (!mPwmDevice)
+ {
+ LOG_ERR("Cannot find PWM device %s", log_strdup(pwmDeviceName));
+ return -ENODEV;
+ }
+
+ Set(false);
+ return 0;
+}
+
+void LightingManager::SetCallbacks(LightingCallback_fn aActionInitiated_CB, LightingCallback_fn aActionCompleted_CB)
+{
+ mActionInitiated_CB = aActionInitiated_CB;
+ mActionCompleted_CB = aActionCompleted_CB;
+}
+
+bool LightingManager::InitiateAction(Action_t aAction, int32_t aActor, uint8_t size, uint8_t * value)
+{
+ bool action_initiated = false;
+ State_t new_state;
+
+ // Initiate On/Off Action only when the previous one is complete.
+ if (mState == kState_Off && aAction == ON_ACTION)
+ {
+ action_initiated = true;
+ new_state = kState_On;
+ }
+ else if (mState == kState_On && aAction == OFF_ACTION)
+ {
+ action_initiated = true;
+ new_state = kState_Off;
+ }
+ else if (aAction == LEVEL_ACTION && *value != mLevel)
+ {
+ action_initiated = true;
+ if (*value == 0)
+ {
+ new_state = kState_Off;
+ }
+ else
+ {
+ new_state = kState_On;
+ }
+ }
+
+ if (action_initiated)
+ {
+ if (mActionInitiated_CB)
+ {
+ mActionInitiated_CB(aAction, aActor);
+ }
+
+ if (aAction == ON_ACTION || aAction == OFF_ACTION)
+ {
+ Set(new_state == kState_On);
+ }
+ else if (aAction == LEVEL_ACTION)
+ {
+ SetLevel(*value);
+ }
+
+ if (mActionCompleted_CB)
+ {
+ mActionCompleted_CB(aAction, aActor);
+ }
+ }
+
+ return action_initiated;
+}
+
+void LightingManager::SetLevel(uint8_t aLevel)
+{
+ LOG_INF("Setting brightness level to %u", aLevel);
+ mLevel = aLevel;
+ UpdateLight();
+}
+
+void LightingManager::Set(bool aOn)
+{
+ mState = aOn ? kState_On : kState_Off;
+ UpdateLight();
+}
+
+void LightingManager::UpdateLight()
+{
+ constexpr uint32_t kPwmWidthUs = 20000u;
+ const uint8_t level = mState == kState_On ? mLevel : 0;
+ pwm_pin_set_usec(mPwmDevice, mPwmChannel, kPwmWidthUs, kPwmWidthUs * level / kMaxLevel, 0);
+}
diff --git a/examples/lighting-app/telink/src/ZclCallbacks.cpp b/examples/lighting-app/telink/src/ZclCallbacks.cpp
new file mode 100644
index 0000000..59fe494
--- /dev/null
+++ b/examples/lighting-app/telink/src/ZclCallbacks.cpp
@@ -0,0 +1,85 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <support/logging/CHIPLogging.h>
+
+#include <app/common/gen/attribute-id.h>
+#include <app/common/gen/cluster-id.h>
+#include <app/common/gen/command-id.h>
+#include <app/util/af-types.h>
+#include <app/util/af.h>
+
+#include "AppTask.h"
+#include "LightingManager.h"
+
+using namespace chip;
+
+void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId, uint8_t mask,
+ uint16_t manufacturerCode, uint8_t type, uint16_t size, uint8_t * value)
+{
+ ChipLogProgress(Zcl, "Cluster callback: %d", clusterId);
+
+ if (clusterId == ZCL_ON_OFF_CLUSTER_ID)
+ {
+ if (attributeId != ZCL_ON_OFF_ATTRIBUTE_ID)
+ {
+ ChipLogProgress(Zcl, "Unknown attribute ID: %d", attributeId);
+ return;
+ }
+
+ LightingMgr().InitiateAction(*value ? LightingManager::ON_ACTION : LightingManager::OFF_ACTION,
+ AppEvent::kEventType_Lighting, size, value);
+ }
+ else if (clusterId == ZCL_LEVEL_CONTROL_CLUSTER_ID)
+ {
+ if (attributeId != ZCL_CURRENT_LEVEL_ATTRIBUTE_ID)
+ {
+ ChipLogProgress(Zcl, "Unknown attribute ID: %d", attributeId);
+ return;
+ }
+
+ ChipLogProgress(Zcl, "Value: %u, length %u", *value, size);
+ if (size == 1)
+ {
+ LightingMgr().InitiateAction(LightingManager::LEVEL_ACTION, AppEvent::kEventType_Lighting, size, value);
+ }
+ else
+ {
+ ChipLogError(Zcl, "wrong length for level: %d", size);
+ }
+ }
+ else
+ {
+ ChipLogProgress(Zcl, "Unknown cluster ID: %d", clusterId);
+ return;
+ }
+}
+
+/** @brief OnOff Cluster Init
+ *
+ * This function is called when a specific cluster is initialized. It gives the
+ * application an opportunity to take care of cluster initialization procedures.
+ * It is called exactly once for each endpoint where cluster is present.
+ *
+ * @param endpoint Ver.: always
+ *
+ */
+void emberAfOnOffClusterInitCallback(EndpointId endpoint)
+{
+ GetAppTask().UpdateClusterState();
+}
diff --git a/examples/lighting-app/telink/src/main.cpp b/examples/lighting-app/telink/src/main.cpp
new file mode 100644
index 0000000..6e061f4
--- /dev/null
+++ b/examples/lighting-app/telink/src/main.cpp
@@ -0,0 +1,81 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "AppTask.h"
+
+#include <platform/CHIPDeviceLayer.h>
+#include <support/CHIPMem.h>
+
+#include <kernel.h>
+
+LOG_MODULE_REGISTER(app);
+
+using namespace ::chip;
+using namespace ::chip::Inet;
+using namespace ::chip::DeviceLayer;
+
+int main(void)
+{
+ int ret = 0;
+
+ k_thread_priority_set(k_current_get(), K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1));
+
+ ret = chip::Platform::MemoryInit();
+ if (ret != CHIP_NO_ERROR)
+ {
+ LOG_ERR("Platform::MemoryInit() failed");
+ goto exit;
+ }
+
+ LOG_INF("Init CHIP stack");
+ ret = PlatformMgr().InitChipStack();
+ if (ret != CHIP_NO_ERROR)
+ {
+ LOG_ERR("PlatformMgr().InitChipStack() failed");
+ goto exit;
+ }
+
+ LOG_INF("Starting CHIP task");
+ ret = PlatformMgr().StartEventLoopTask();
+ if (ret != CHIP_NO_ERROR)
+ {
+ LOG_ERR("PlatformMgr().StartEventLoopTask() failed");
+ goto exit;
+ }
+
+ LOG_INF("Init Thread stack");
+ ret = ThreadStackMgr().InitThreadStack();
+ if (ret != CHIP_NO_ERROR)
+ {
+ LOG_ERR("ThreadStackMgr().InitThreadStack() failed");
+ goto exit;
+ }
+
+ ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
+ if (ret != CHIP_NO_ERROR)
+ {
+ LOG_ERR("ConnectivityMgr().SetThreadDeviceType() failed");
+ goto exit;
+ }
+
+ ret = GetAppTask().StartApp();
+
+exit:
+ LOG_ERR("Exited with code %d", ret);
+ return ret;
+}
diff --git a/examples/lighting-app/telink/third_party/connectedhomeip b/examples/lighting-app/telink/third_party/connectedhomeip
new file mode 120000
index 0000000..c866b86
--- /dev/null
+++ b/examples/lighting-app/telink/third_party/connectedhomeip
@@ -0,0 +1 @@
+../../../..
\ No newline at end of file
diff --git a/examples/platform/telink/project_include/OpenThreadConfig.h b/examples/platform/telink/project_include/OpenThreadConfig.h
new file mode 100644
index 0000000..0ee2d13
--- /dev/null
+++ b/examples/platform/telink/project_include/OpenThreadConfig.h
@@ -0,0 +1,105 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+// Include Zephyr-supplied OpenThread configuration
+
+#include "openthread-core-zephyr-config.h"
+
+// Project-specific settings
+#include "openthread/platform/logging.h"
+
+#undef OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS
+#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 64
+
+// TBD: Investigate the issue with heap allocation
+#undef OPENTHREAD_CONFIG_HEAP_INTERNAL_SIZE
+#define OPENTHREAD_CONFIG_HEAP_INTERNAL_SIZE 10240
+
+#define OPENTHREAD_CONFIG_LOG_OUTPUT OPENTHREAD_CONFIG_LOG_OUTPUT_DEBUG_UART
+
+#undef OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT
+#define OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT 1
+
+#undef OPENTHREAD_CONFIG_LOG_LEVEL
+#define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG
+
+#define OPENTHREAD_CONFIG_ENABLE_DEBUG_UART 1
+
+#undef OPENTHREAD_CONFIG_LOG_API
+#define OPENTHREAD_CONFIG_LOG_API 0
+
+#undef OPENTHREAD_CONFIG_LOG_ARP
+#define OPENTHREAD_CONFIG_LOG_ARP 0
+
+#undef OPENTHREAD_CONFIG_LOG_BB
+#define OPENTHREAD_CONFIG_LOG_BBR 0
+
+#undef OPENTHREAD_CONFIG_LOG_CLI
+#define OPENTHREAD_CONFIG_LOG_CLI 0
+
+#undef OPENTHREAD_CONFIG_LOG_COAP
+#define OPENTHREAD_CONFIG_LOG_COAP 0
+
+#undef OPENTHREAD_CONFIG_LOG_DUA
+#define OPENTHREAD_CONFIG_LOG_DUA 0
+
+#undef OPENTHREAD_CONFIG_LOG_ICMP
+#define OPENTHREAD_CONFIG_LOG_ICMP 0
+
+#undef OPENTHREAD_CONFIG_LOG_IP6
+#define OPENTHREAD_CONFIG_LOG_IP6 0
+
+#undef OPENTHREAD_CONFIG_LOG_MAC
+#define OPENTHREAD_CONFIG_LOG_MAC 0
+
+#undef OPENTHREAD_CONFIG_LOG_MEM
+#define OPENTHREAD_CONFIG_LOG_MEM 0
+
+#undef OPENTHREAD_CONFIG_LOG_MESHCOP
+#define OPENTHREAD_CONFIG_LOG_MESHCOP 0
+
+#undef OPENTHREAD_CONFIG_LOG_MLE
+#define OPENTHREAD_CONFIG_LOG_MLE 0
+
+#undef OPENTHREAD_CONFIG_LOG_MLR
+#define OPENTHREAD_CONFIG_LOG_MLR 0
+
+#undef OPENTHREAD_CONFIG_LOG_NETDATA
+#define OPENTHREAD_CONFIG_LOG_NETDATA 0
+
+#undef OPENTHREAD_CONFIG_LOG_NETDIAG
+#define OPENTHREAD_CONFIG_LOG_NETDIAG 0
+
+#undef OPENTHREAD_CONFIG_LOG_PKT_DUMP
+#define OPENTHREAD_CONFIG_LOG_PKT_DUMP 0
+
+#undef OPENTHREAD_CONFIG_LOG_PLATFORM
+#define OPENTHREAD_CONFIG_LOG_PLATFORM 0
+
+#undef OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL
+#define OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL 0
+
+#undef OPENTHREAD_CONFIG_LOG_PREPEND_REGION
+#define OPENTHREAD_CONFIG_LOG_PREPEND_REGION 0
+
+#undef OPENTHREAD_CONFIG_PLAT_LOG_MACRO_NAME
+#define OPENTHREAD_CONFIG_PLAT_LOG_MACRO_NAME tlOtPlatLog
+
+void tlOtPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char * aFormat, ...);
diff --git a/examples/platform/telink/util/include/ButtonManager.h b/examples/platform/telink/util/include/ButtonManager.h
new file mode 100644
index 0000000..165ac19
--- /dev/null
+++ b/examples/platform/telink/util/include/ButtonManager.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <device.h>
+#include <vector>
+
+#define STATE_HIGH 1
+#define STATE_LOW 0
+
+class Button
+{
+public:
+ void Configure(const struct device * port, gpio_pin_t outPin, gpio_pin_t inPin, void (*callback)(void));
+ void Poll(Button * previous);
+ void SetCallback(void (*callback)(void));
+
+private:
+ int Init(void);
+ int Deinit(void);
+
+ const struct device * mPort;
+ gpio_pin_t mOutPin;
+ gpio_pin_t mInPin;
+ int mPreviousState = STATE_LOW;
+ void (*mCallback)(void) = NULL;
+};
+
+class ButtonManager
+{
+public:
+ void Init(void);
+ void Poll(void);
+ void AddButton(Button & button);
+ void SetCallback(unsigned int index, void (*callback)(void));
+
+private:
+ std::vector<Button> mButtons;
+
+ friend ButtonManager & ButtonManagerInst(void);
+
+ static ButtonManager sInstance;
+};
+
+/**
+ * Returns the KeyManager singleton object.
+ */
+inline ButtonManager & ButtonManagerInst(void)
+{
+ return ButtonManager::sInstance;
+}
diff --git a/examples/platform/telink/util/include/LEDWidget.h b/examples/platform/telink/util/include/LEDWidget.h
new file mode 100644
index 0000000..19aad87
--- /dev/null
+++ b/examples/platform/telink/util/include/LEDWidget.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <cstdint>
+#include <drivers/gpio.h>
+
+class LEDWidget
+{
+public:
+ static void InitGpio();
+ const static struct device * mPort;
+ void Init(gpio_pin_t gpioNum);
+ void Set(bool state);
+ void Invert(void);
+ void Blink(uint32_t changeRateMS);
+ void Blink(uint32_t onTimeMS, uint32_t offTimeMS);
+ void Animate();
+
+private:
+ int64_t mLastChangeTimeMS;
+ uint32_t mBlinkOnTimeMS;
+ uint32_t mBlinkOffTimeMS;
+ gpio_pin_t mGPIONum;
+ bool mState;
+
+ void DoSet(bool state);
+};
diff --git a/examples/platform/telink/util/include/ThreadUtil.h b/examples/platform/telink/util/include/ThreadUtil.h
new file mode 100644
index 0000000..eb6ed1e
--- /dev/null
+++ b/examples/platform/telink/util/include/ThreadUtil.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+void StartDefaultThreadNetwork(void);
diff --git a/examples/platform/telink/util/src/ButtonManager.cpp b/examples/platform/telink/util/src/ButtonManager.cpp
new file mode 100644
index 0000000..3e3aa58
--- /dev/null
+++ b/examples/platform/telink/util/src/ButtonManager.cpp
@@ -0,0 +1,152 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <assert.h>
+#include <device.h>
+#include <drivers/gpio.h>
+#include <kernel.h>
+#include <logging/log.h>
+#include <zephyr.h>
+
+LOG_MODULE_REGISTER(ButtonManager);
+
+#include <ButtonManager.h>
+
+ButtonManager ButtonManager::sInstance;
+
+void Button::Configure(const struct device * port, gpio_pin_t outPin, gpio_pin_t inPin, void (*callback)(void))
+{
+ mPort = port;
+ mOutPin = outPin;
+ mInPin = inPin;
+ mCallback = callback;
+}
+
+int Button::Init(void)
+{
+ int ret = 0;
+
+ ret = gpio_pin_configure(mPort, mOutPin, GPIO_OUTPUT_ACTIVE);
+ if (ret < 0)
+ {
+ LOG_ERR("Configure out pin - fail. Status %d", ret);
+ return ret;
+ }
+
+ ret = gpio_pin_configure(mPort, mInPin, GPIO_INPUT | GPIO_PULL_DOWN);
+ if (ret < 0)
+ {
+ LOG_ERR("Configure in pin - fail. Status %d", ret);
+ return ret;
+ }
+
+ return ret;
+}
+
+int Button::Deinit(void)
+{
+ int ret = 0;
+
+ /* Reconfigure output key pin to input */
+ ret = gpio_pin_configure(mPort, mOutPin, GPIO_INPUT | GPIO_PULL_DOWN);
+ if (ret < 0)
+ {
+ LOG_ERR("Reconfigure out pin - fail. Status %d", ret);
+ return ret;
+ }
+
+ return ret;
+}
+
+void Button::Poll(Button * previous)
+{
+ int ret = 0;
+
+ if (previous != NULL)
+ {
+ ret = previous->Deinit();
+ assert(ret >= 0);
+ }
+
+ ret = Init();
+ assert(ret >= 0);
+
+ ret = gpio_pin_get(mPort, mInPin);
+ assert(ret >= 0);
+
+ if (ret == STATE_HIGH && mPreviousState != STATE_HIGH)
+ {
+ mPreviousState = STATE_HIGH;
+
+ if (mCallback != NULL)
+ {
+ mCallback();
+ }
+ }
+ else if (ret == STATE_LOW)
+ {
+ mPreviousState = STATE_LOW;
+ }
+
+ k_msleep(10);
+}
+
+void Button::SetCallback(void (*callback)(void))
+{
+ mCallback = callback;
+}
+
+void ButtonManager::AddButton(Button & button)
+{
+ mButtons.push_back(button);
+}
+
+void ButtonManager::SetCallback(unsigned int index, void (*callback)(void))
+{
+ if (mButtons.size() <= index)
+ {
+ LOG_ERR("Wrong button index");
+ }
+
+ mButtons[index].SetCallback(callback);
+}
+
+void ButtonManager::Poll(void)
+{
+ static Button * previous = NULL;
+
+ for (unsigned int i = 0; i < mButtons.size(); i++)
+ {
+ mButtons[i].Poll(previous);
+ previous = &mButtons[i];
+ }
+
+ k_msleep(10);
+}
+
+void ButtonEntry(void * param1, void * param2, void * param3)
+{
+ ButtonManager & sInstance = ButtonManagerInst();
+
+ while (true)
+ {
+ sInstance.Poll();
+ }
+}
+
+K_THREAD_DEFINE(buttonThread, 512, ButtonEntry, NULL, NULL, NULL, K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1), 0, 0);
diff --git a/examples/platform/telink/util/src/LEDWidget.cpp b/examples/platform/telink/util/src/LEDWidget.cpp
new file mode 100644
index 0000000..ed9e2b4
--- /dev/null
+++ b/examples/platform/telink/util/src/LEDWidget.cpp
@@ -0,0 +1,90 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "LEDWidget.h"
+
+#include <zephyr.h>
+
+#define LED_PORT DT_LABEL(DT_NODELABEL(gpiob))
+
+const struct device * LEDWidget::mPort = NULL;
+
+void LEDWidget::InitGpio()
+{
+ mPort = device_get_binding(LED_PORT);
+ __ASSERT(mPort != NULL, "Fail to bind with LED port\n");
+}
+
+void LEDWidget::Init(gpio_pin_t gpioNum)
+{
+ mLastChangeTimeMS = 0;
+ mBlinkOnTimeMS = 0;
+ mBlinkOffTimeMS = 0;
+ mGPIONum = gpioNum;
+ mState = false;
+
+ int ret = gpio_pin_configure(mPort, mGPIONum, GPIO_OUTPUT_ACTIVE);
+ __ASSERT(ret >= 0, "GPIO pin %d configure - fail. Status%d\n", mGPIONum, ret);
+
+ Set(false);
+}
+
+void LEDWidget::Invert(void)
+{
+ Set(!mState);
+}
+
+void LEDWidget::Set(bool state)
+{
+ mLastChangeTimeMS = mBlinkOnTimeMS = mBlinkOffTimeMS = 0;
+ DoSet(state);
+}
+
+void LEDWidget::Blink(uint32_t changeRateMS)
+{
+ Blink(changeRateMS, changeRateMS);
+}
+
+void LEDWidget::Blink(uint32_t onTimeMS, uint32_t offTimeMS)
+{
+ mBlinkOnTimeMS = onTimeMS;
+ mBlinkOffTimeMS = offTimeMS;
+ Animate();
+}
+
+void LEDWidget::Animate()
+{
+ if (mBlinkOnTimeMS != 0 && mBlinkOffTimeMS != 0)
+ {
+ int64_t nowMS = k_uptime_get();
+ int64_t stateDurMS = mState ? mBlinkOnTimeMS : mBlinkOffTimeMS;
+
+ if (nowMS > mLastChangeTimeMS + stateDurMS)
+ {
+ DoSet(!mState);
+ mLastChangeTimeMS = nowMS;
+ }
+ }
+}
+
+void LEDWidget::DoSet(bool state)
+{
+ mState = state;
+ int ret = gpio_pin_set(mPort, mGPIONum, state);
+ __ASSERT(ret >= 0, "GPIO pin %d set -fail. Status: %d\n", mGPIONum, ret);
+}
diff --git a/examples/platform/telink/util/src/ThreadUtil.cpp b/examples/platform/telink/util/src/ThreadUtil.cpp
new file mode 100644
index 0000000..0975229
--- /dev/null
+++ b/examples/platform/telink/util/src/ThreadUtil.cpp
@@ -0,0 +1,65 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ThreadUtil.h"
+
+#include <platform/CHIPDeviceLayer.h>
+#include <platform/internal/DeviceNetworkInfo.h>
+#include <support/ThreadOperationalDataset.h>
+
+#include <zephyr.h>
+
+#include <cstring>
+#include <stdio.h>
+#include <stdlib.h>
+
+void StartDefaultThreadNetwork(void)
+{
+ chip::Thread::OperationalDataset dataset{};
+ uint8_t xpanid[8];
+ constexpr uint8_t masterkey[] = {
+ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
+ };
+ constexpr uint8_t meshLocalPrefix[] = { 0xfd, 0x11, 0x11, 0x11, 0x11, 0x22, 0x00, 0x00 };
+
+ net_bytes_from_str(xpanid, sizeof(xpanid), CONFIG_OPENTHREAD_XPANID);
+
+ dataset.SetChannel(CONFIG_OPENTHREAD_CHANNEL);
+ dataset.SetExtendedPanId(xpanid);
+ dataset.SetMasterKey(masterkey);
+ dataset.SetMeshLocalPrefix(meshLocalPrefix);
+ dataset.SetNetworkName(CONFIG_OPENTHREAD_NETWORK_NAME);
+ dataset.SetPanId(CONFIG_OPENTHREAD_PANID);
+
+ chip::DeviceLayer::ThreadStackMgr().SetThreadEnabled(false);
+ chip::DeviceLayer::ThreadStackMgr().SetThreadProvision(dataset.AsByteSpan());
+ chip::DeviceLayer::ThreadStackMgr().SetThreadEnabled(true);
+}
+
+void tlOtPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char * aFormat, ...)
+{
+ va_list args;
+
+ va_start(args, aFormat);
+
+ vprintf(aFormat, args);
+
+ printf("\r\n");
+
+ va_end(args);
+}
diff --git a/scripts/examples/telink_example.sh b/scripts/examples/telink_example.sh
new file mode 100755
index 0000000..4255f65
--- /dev/null
+++ b/scripts/examples/telink_example.sh
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+
+#
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Run bootstrap and activate to set up
+
+APP="$1"
+BOARD="$2"
+
+source "$(dirname "$0")/../../scripts/activate.sh"
+cd "$(dirname "$0")/../../examples"
+shift 2
+
+if [[ ! -f "$APP/telink/CMakeLists.txt" ]]; then
+ echo "Usage: $0 <application>" >&2
+ echo "Applications:" >&2
+ ls */telink/CMakeLists.txt | awk -F/ '{print " "$1}' >&2
+ exit 1
+fi
+
+if [ -z "$BOARD" ]; then
+ echo "No mandatory BOARD argument supplied!"
+ exit 1
+fi
+
+set -x
+[[ -n $ZEPHYR_BASE ]] && source "$ZEPHYR_BASE/zephyr-env.sh"
+
+export ZEPHYR_TOOLCHAIN_VARIANT=cross-compile
+export CROSS_COMPILE="$TELINK_TOOLCHAIN_PATH"/riscv32-elf-
+
+env
+
+west build -b "$BOARD" -d "$APP/telink/build/$BOARD" "$APP/telink" -- "$@"
diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn
index 15c32e5..89f249e 100644
--- a/src/platform/BUILD.gn
+++ b/src/platform/BUILD.gn
@@ -181,6 +181,11 @@
"CHIP_DEVICE_LAYER_TARGET_K32W=1",
"CHIP_DEVICE_LAYER_TARGET=K32W",
]
+ } else if (chip_device_platform == "telink") {
+ defines += [
+ "CHIP_DEVICE_LAYER_TARGET_TELINK=1",
+ "CHIP_DEVICE_LAYER_TARGET=telink",
+ ]
}
}
} else {
@@ -642,6 +647,39 @@
"qpg6100/ThreadStackManagerImpl.h",
]
}
+ } else if (chip_device_platform == "telink") {
+ sources += [
+ "Zephyr/BLEManagerImpl.cpp",
+ "Zephyr/ConfigurationManagerImpl.cpp",
+ "Zephyr/KeyValueStoreManagerImpl.cpp",
+ "Zephyr/Logging.cpp",
+ "Zephyr/PlatformManagerImpl.cpp",
+ "Zephyr/SystemTimeSupport.cpp",
+ "Zephyr/ZephyrConfig.cpp",
+ "Zephyr/ZephyrConfig.h",
+ "telink/BLEManagerImpl.h",
+ "telink/BlePlatformConfig.h",
+ "telink/CHIPDevicePlatformConfig.h",
+ "telink/CHIPDevicePlatformEvent.h",
+ "telink/CHIPPlatformConfig.h",
+ "telink/ConfigurationManagerImpl.h",
+ "telink/ConnectivityManagerImpl.cpp",
+ "telink/ConnectivityManagerImpl.h",
+ "telink/DeviceNetworkProvisioningDelegateImpl.cpp",
+ "telink/DeviceNetworkProvisioningDelegateImpl.h",
+ "telink/InetPlatformConfig.h",
+ "telink/KeyValueStoreManagerImpl.h",
+ "telink/PlatformManagerImpl.h",
+ "telink/SystemPlatformConfig.h",
+ ]
+
+ if (chip_enable_openthread) {
+ sources += [
+ "OpenThread/OpenThreadUtils.cpp",
+ "Zephyr/ThreadStackManagerImpl.cpp",
+ "telink/ThreadStackManagerImpl.h",
+ ]
+ }
}
if (chip_enable_openthread && chip_mdns == "platform" &&
diff --git a/src/platform/device.gni b/src/platform/device.gni
index 336b85a..ca6715a 100644
--- a/src/platform/device.gni
+++ b/src/platform/device.gni
@@ -78,6 +78,8 @@
_chip_device_layer = "qpg6100"
} else if (chip_device_platform == "k32w") {
_chip_device_layer = "K32W"
+} else if (chip_device_platform == "telink") {
+ _chip_device_layer = "telink"
}
if (chip_device_platform != "external") {
@@ -116,5 +118,6 @@
chip_device_platform == "esp32" || chip_device_platform == "external" ||
chip_device_platform == "linux" ||
chip_device_platform == "nrfconnect" ||
- chip_device_platform == "k32w" || chip_device_platform == "qpg6100",
+ chip_device_platform == "k32w" || chip_device_platform == "qpg6100" ||
+ chip_device_platform == "telink",
"Please select a valid value for chip_device_platform")
diff --git a/src/platform/telink/BLEManagerImpl.h b/src/platform/telink/BLEManagerImpl.h
new file mode 100644
index 0000000..48fe558
--- /dev/null
+++ b/src/platform/telink/BLEManagerImpl.h
@@ -0,0 +1,27 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * Provides an implementation of the BLEManager object
+ * for Telink platform, by including Zephyr platform
+ * implementation.
+ */
+
+#pragma once
+
+#include <platform/Zephyr/BLEManagerImpl.h>
diff --git a/src/platform/telink/BlePlatformConfig.h b/src/platform/telink/BlePlatformConfig.h
new file mode 100644
index 0000000..a4dc537
--- /dev/null
+++ b/src/platform/telink/BlePlatformConfig.h
@@ -0,0 +1,36 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * Platform-specific configuration overrides for the CHIP BLE
+ * Layer on Telink platform.
+ *
+ */
+
+#pragma once
+
+// ==================== Platform Adaptations ====================
+
+struct bt_conn;
+#define BLE_CONNECTION_OBJECT bt_conn *
+#define BLE_CONNECTION_UNINITIALIZED nullptr
+#define BLE_MAX_RECEIVE_WINDOW_SIZE 5
+
+// ========== Platform-specific Configuration Overrides =========
+
+/* none so far */
diff --git a/src/platform/telink/CHIPDevicePlatformConfig.h b/src/platform/telink/CHIPDevicePlatformConfig.h
new file mode 100644
index 0000000..84e43f6
--- /dev/null
+++ b/src/platform/telink/CHIPDevicePlatformConfig.h
@@ -0,0 +1,77 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * Platform-specific configuration overrides for the chip Device Layer
+ * on Telink platform.
+ */
+
+#pragma once
+
+#include "autoconf.h"
+
+// ==================== Platform Adaptations ====================
+
+#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0
+#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0
+
+#define CHIP_DEVICE_CONFIG_ENABLE_THREAD CONFIG_NET_L2_OPENTHREAD
+#define CHIP_DEVICE_CONFIG_THREAD_FTD CONFIG_OPENTHREAD_FTD
+
+#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE CONFIG_BT
+
+#define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 0
+
+#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY 2
+#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_PROD_EIDC_KEY 3
+#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY 4
+#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY 5
+
+// ========== Platform-specific Configuration =========
+
+// These are configuration options that are unique to Zephyr platforms.
+// These can be overridden by the application as needed.
+
+// ========== Platform-specific Configuration Overrides =========
+
+#ifndef CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY
+#define CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY (K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1))
+#endif // CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY
+
+#ifndef CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE
+#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE 4096
+#endif // CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE
+
+#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY 0
+#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY 0
+#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL 0
+#define CHIP_DEVICE_CONFIG_LOG_PROVISIONING_HASH 0
+
+#define CHIP_DEVICE_CONFIG_CHIPOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED CONFIG_CHIP_DISABLE_CHIPOBLE_ADVERTISING_WHEN_PROVISIONED
+
+#define CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART 0
+
+#ifndef CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART
+#define CHIP_DEVICE_CONFIG_ENABLE_PAIRING_AUTOSTART 0
+#else
+#define CHIP_DEVICE_CONFIG_ENABLE_PAIRING_AUTOSTART CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART
+#endif // CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART
+
+#ifdef CONFIG_CHIP_ENABLE_RENDEZVOUS_BYPASS
+#define CHIP_BYPASS_RENDEZVOUS CONFIG_CHIP_ENABLE_RENDEZVOUS_BYPASS
+#endif // CONFIG_CHIP_ENABLE_RENDEZVOUS_BYPASS
diff --git a/src/platform/telink/CHIPDevicePlatformEvent.h b/src/platform/telink/CHIPDevicePlatformEvent.h
new file mode 100644
index 0000000..182fd3f
--- /dev/null
+++ b/src/platform/telink/CHIPDevicePlatformEvent.h
@@ -0,0 +1,27 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * Provides platform-specific event types and data for the chip
+ * Device Layer on Telink platform, by including Zephyr
+ * platform definitions.
+ */
+
+#pragma once
+
+#include <platform/Zephyr/CHIPDevicePlatformEvent.h>
diff --git a/src/platform/telink/CHIPPlatformConfig.h b/src/platform/telink/CHIPPlatformConfig.h
new file mode 100644
index 0000000..620fe9e
--- /dev/null
+++ b/src/platform/telink/CHIPPlatformConfig.h
@@ -0,0 +1,107 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * Platform-specific configuration overrides for CHIP on
+ * Telink platform.
+ */
+
+#pragma once
+
+// ==================== General Platform Adaptations ====================
+
+#define ChipDie() abort()
+
+#define CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE const char *
+#define CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH 2
+
+#define CHIP_CONFIG_TIME_ENABLE_CLIENT 1
+#define CHIP_CONFIG_TIME_ENABLE_SERVER 0
+
+// ==================== Security Adaptations ====================
+
+#define CHIP_CONFIG_USE_OPENSSL_ECC 0
+#define CHIP_CONFIG_USE_MICRO_ECC 0
+
+#define CHIP_CONFIG_HASH_IMPLEMENTATION_OPENSSL 0
+#define CHIP_CONFIG_HASH_IMPLEMENTATION_MINCRYPT 1
+#define CHIP_CONFIG_HASH_IMPLEMENTATION_MBEDTLS 0
+#define CHIP_CONFIG_HASH_IMPLEMENTATION_PLATFORM 0
+
+#define CHIP_CONFIG_AES_IMPLEMENTATION_OPENSSL 0
+#define CHIP_CONFIG_AES_IMPLEMENTATION_AESNI 0
+#define CHIP_CONFIG_AES_IMPLEMENTATION_MBEDTLS 1
+#define CHIP_CONFIG_AES_IMPLEMENTATION_PLATFORM 0
+
+#define CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL 0
+#define CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG 1
+#define CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM 0
+
+#define CHIP_CONFIG_ENABLE_PASE_INITIATOR 0
+#define CHIP_CONFIG_ENABLE_PASE_RESPONDER 1
+#define CHIP_CONFIG_ENABLE_CASE_INITIATOR 1
+
+#define CHIP_CONFIG_SUPPORT_PASE_CONFIG0 0
+#define CHIP_CONFIG_SUPPORT_PASE_CONFIG1 0
+#define CHIP_CONFIG_SUPPORT_PASE_CONFIG2 0
+#define CHIP_CONFIG_SUPPORT_PASE_CONFIG3 0
+#define CHIP_CONFIG_SUPPORT_PASE_CONFIG4 1
+
+#define CHIP_CONFIG_ENABLE_KEY_EXPORT_INITIATOR 0
+
+#define CHIP_CONFIG_ENABLE_PROVISIONING_BUNDLE_SUPPORT 0
+
+// ==================== General Configuration Overrides ====================
+
+#ifndef CHIP_CONFIG_MAX_PEER_NODES
+#define CHIP_CONFIG_MAX_PEER_NODES 16
+#endif // CHIP_CONFIG_MAX_PEER_NODES
+
+#ifndef CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS
+#define CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS 16
+#endif // CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS
+
+#ifndef CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS
+#define CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS 8
+#endif // CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS
+
+#ifndef CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT
+#define CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT 6
+#endif // CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT
+
+#ifndef CHIP_LOG_FILTERING
+#define CHIP_LOG_FILTERING 0
+#endif // CHIP_LOG_FILTERING
+
+#ifndef CHIP_CONFIG_BDX_MAX_NUM_TRANSFERS
+#define CHIP_CONFIG_BDX_MAX_NUM_TRANSFERS 1
+#endif // CHIP_CONFIG_BDX_MAX_NUM_TRANSFERS
+
+// ==================== Security Configuration Overrides ====================
+
+#ifndef CHIP_CONFIG_MAX_APPLICATION_GROUPS
+#define CHIP_CONFIG_MAX_APPLICATION_GROUPS 4
+#endif // CHIP_CONFIG_MAX_APPLICATION_GROUPS
+
+#ifndef CHIP_CONFIG_DEBUG_CERT_VALIDATION
+#define CHIP_CONFIG_DEBUG_CERT_VALIDATION 0
+#endif // CHIP_CONFIG_DEBUG_CERT_VALIDATION
+
+#ifndef CHIP_CONFIG_ENABLE_CASE_RESPONDER
+#define CHIP_CONFIG_ENABLE_CASE_RESPONDER 1
+#endif // CHIP_CONFIG_ENABLE_CASE_RESPONDER
diff --git a/src/platform/telink/ConfigurationManagerImpl.h b/src/platform/telink/ConfigurationManagerImpl.h
new file mode 100644
index 0000000..98bfe96
--- /dev/null
+++ b/src/platform/telink/ConfigurationManagerImpl.h
@@ -0,0 +1,27 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * Provides an implementation of the ConfigurationManager object
+ * for Telink, by including Zephyr platform
+ * implementation.
+ */
+
+#pragma once
+
+#include <platform/Zephyr/ConfigurationManagerImpl.h>
diff --git a/src/platform/telink/ConnectivityManagerImpl.cpp b/src/platform/telink/ConnectivityManagerImpl.cpp
new file mode 100644
index 0000000..78ebae1
--- /dev/null
+++ b/src/platform/telink/ConnectivityManagerImpl.cpp
@@ -0,0 +1,61 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include <platform/ConnectivityManager.h>
+#include <platform/internal/BLEManager.h>
+
+#include <support/CodeUtils.h>
+#include <support/logging/CHIPLogging.h>
+
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+#include <platform/internal/GenericConnectivityManagerImpl_BLE.cpp>
+#endif
+
+#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
+#include <platform/internal/GenericConnectivityManagerImpl_Thread.cpp>
+#endif
+
+using namespace ::chip;
+using namespace ::chip::TLV;
+using namespace ::chip::DeviceLayer::Internal;
+
+namespace chip {
+namespace DeviceLayer {
+
+ConnectivityManagerImpl ConnectivityManagerImpl::sInstance;
+
+CHIP_ERROR ConnectivityManagerImpl::_Init()
+{
+#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
+ GenericConnectivityManagerImpl_Thread<ConnectivityManagerImpl>::_Init();
+#endif
+
+ return CHIP_NO_ERROR;
+}
+
+void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
+{
+ // Forward the event to the generic base classes as needed.
+#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
+ GenericConnectivityManagerImpl_Thread<ConnectivityManagerImpl>::_OnPlatformEvent(event);
+#endif
+}
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/telink/ConnectivityManagerImpl.h b/src/platform/telink/ConnectivityManagerImpl.h
new file mode 100644
index 0000000..86d7548
--- /dev/null
+++ b/src/platform/telink/ConnectivityManagerImpl.h
@@ -0,0 +1,121 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <platform/ConnectivityManager.h>
+#include <platform/internal/GenericConnectivityManagerImpl.h>
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+#include <platform/internal/GenericConnectivityManagerImpl_BLE.h>
+#else
+#include <platform/internal/GenericConnectivityManagerImpl_NoBLE.h>
+#endif
+#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
+#include <platform/internal/GenericConnectivityManagerImpl_Thread.h>
+#else
+#include <platform/internal/GenericConnectivityManagerImpl_NoThread.h>
+#endif
+#include <platform/internal/GenericConnectivityManagerImpl_NoWiFi.h>
+
+#include <support/logging/CHIPLogging.h>
+
+namespace chip {
+namespace Inet {
+class IPAddress;
+} // namespace Inet
+} // namespace chip
+
+namespace chip {
+namespace DeviceLayer {
+
+/**
+ * Concrete implementation of the ConnectivityManager singleton object for Zephyr platforms.
+ */
+class ConnectivityManagerImpl final : public ConnectivityManager,
+ public Internal::GenericConnectivityManagerImpl<ConnectivityManagerImpl>,
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+ public Internal::GenericConnectivityManagerImpl_BLE<ConnectivityManagerImpl>,
+#else
+ public Internal::GenericConnectivityManagerImpl_NoBLE<ConnectivityManagerImpl>,
+#endif
+#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
+ public Internal::GenericConnectivityManagerImpl_Thread<ConnectivityManagerImpl>,
+#else
+ public Internal::GenericConnectivityManagerImpl_NoThread<ConnectivityManagerImpl>,
+#endif
+ public Internal::GenericConnectivityManagerImpl_NoWiFi<ConnectivityManagerImpl>
+{
+ // Allow the ConnectivityManager interface class to delegate method calls to
+ // the implementation methods provided by this class.
+ friend class ConnectivityManager;
+
+private:
+ // ===== Members that implement the ConnectivityManager abstract interface.
+
+ bool _HaveIPv4InternetConnectivity(void);
+ bool _HaveIPv6InternetConnectivity(void);
+ bool _HaveServiceConnectivity(void);
+ CHIP_ERROR _Init(void);
+ void _OnPlatformEvent(const ChipDeviceEvent * event);
+
+ // ===== Members for internal use by the following friends.
+
+ friend ConnectivityManager & ConnectivityMgr(void);
+ friend ConnectivityManagerImpl & ConnectivityMgrImpl(void);
+
+ static ConnectivityManagerImpl sInstance;
+};
+
+inline bool ConnectivityManagerImpl::_HaveIPv4InternetConnectivity(void)
+{
+ return false;
+}
+
+inline bool ConnectivityManagerImpl::_HaveIPv6InternetConnectivity(void)
+{
+ return false;
+}
+
+inline bool ConnectivityManagerImpl::_HaveServiceConnectivity(void)
+{
+ return _HaveServiceConnectivityViaThread();
+}
+
+/**
+ * Returns the public interface of the ConnectivityManager singleton object.
+ *
+ * chip applications should use this to access features of the ConnectivityManager object
+ * that are common to all platforms.
+ */
+inline ConnectivityManager & ConnectivityMgr(void)
+{
+ return ConnectivityManagerImpl::sInstance;
+}
+
+/**
+ * Returns the platform-specific implementation of the ConnectivityManager singleton object.
+ *
+ * chip applications can use this to gain access to features of the ConnectivityManager
+ * that are specific to the ESP32 platform.
+ */
+inline ConnectivityManagerImpl & ConnectivityMgrImpl(void)
+{
+ return ConnectivityManagerImpl::sInstance;
+}
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/telink/DeviceNetworkProvisioningDelegateImpl.cpp b/src/platform/telink/DeviceNetworkProvisioningDelegateImpl.cpp
new file mode 100644
index 0000000..dd26ee5
--- /dev/null
+++ b/src/platform/telink/DeviceNetworkProvisioningDelegateImpl.cpp
@@ -0,0 +1,43 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "DeviceNetworkProvisioningDelegateImpl.h"
+
+#if CHIP_ENABLE_OPENTHREAD
+#include <platform/ThreadStackManager.h>
+#endif
+
+namespace chip {
+namespace DeviceLayer {
+
+CHIP_ERROR DeviceNetworkProvisioningDelegateImpl::_ProvisionThreadNetwork(ByteSpan threadData)
+{
+#if CHIP_ENABLE_OPENTHREAD
+ CHIP_ERROR error = CHIP_NO_ERROR;
+
+ SuccessOrExit(error = ThreadStackMgr().SetThreadEnabled(false));
+ SuccessOrExit(error = ThreadStackMgr().SetThreadProvision(threadData));
+ SuccessOrExit(error = ThreadStackMgr().SetThreadEnabled(true));
+exit:
+ return error;
+#else
+ return CHIP_ERROR_NOT_IMPLEMENTED;
+#endif // CHIP_ENABLE_OPENTHREAD
+}
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/telink/DeviceNetworkProvisioningDelegateImpl.h b/src/platform/telink/DeviceNetworkProvisioningDelegateImpl.h
new file mode 100644
index 0000000..54af21c
--- /dev/null
+++ b/src/platform/telink/DeviceNetworkProvisioningDelegateImpl.h
@@ -0,0 +1,43 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <platform/internal/GenericDeviceNetworkProvisioningDelegateImpl.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+namespace Internal {
+
+template <class ImplClass>
+class GenericDeviceNetworkProvisioningDelegateImpl;
+
+} // namespace Internal
+
+class DeviceNetworkProvisioningDelegateImpl final
+ : public Internal::GenericDeviceNetworkProvisioningDelegateImpl<DeviceNetworkProvisioningDelegateImpl>
+{
+ friend class GenericDeviceNetworkProvisioningDelegateImpl<DeviceNetworkProvisioningDelegateImpl>;
+
+private:
+ CHIP_ERROR _ProvisionWiFiNetwork(const char * ssid, const char * passwd) { return CHIP_ERROR_NOT_IMPLEMENTED; }
+ CHIP_ERROR _ProvisionThreadNetwork(ByteSpan threadData);
+};
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/telink/InetPlatformConfig.h b/src/platform/telink/InetPlatformConfig.h
new file mode 100644
index 0000000..b079c47
--- /dev/null
+++ b/src/platform/telink/InetPlatformConfig.h
@@ -0,0 +1,50 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * Platform-specific configuration overrides for the CHIP Inet
+ * Layer on Telink platform.
+ *
+ */
+
+#pragma once
+
+// ==================== Platform Adaptations ====================
+
+#ifndef INET_CONFIG_ENABLE_IPV4
+#ifdef CONFIG_NET_IPV4
+#define INET_CONFIG_ENABLE_IPV4 CONFIG_NET_IPV4
+#else
+#define INET_CONFIG_ENABLE_IPV4 0
+#endif
+#endif // INET_CONFIG_ENABLE_IPV4
+
+// ========== Platform-specific Configuration Overrides =========
+
+#ifndef INET_CONFIG_NUM_TCP_ENDPOINTS
+#define INET_CONFIG_NUM_TCP_ENDPOINTS 4
+#endif // INET_CONFIG_NUM_TCP_ENDPOINTS
+
+#ifndef INET_CONFIG_NUM_UDP_ENDPOINTS
+#define INET_CONFIG_NUM_UDP_ENDPOINTS 4
+#endif // INET_CONFIG_NUM_UDP_ENDPOINTS
+
+// Although Zephyr defines SO_BINDTODEVICE, it's currently unimplemented
+#ifdef HAVE_SO_BINDTODEVICE
+#undef HAVE_SO_BINDTODEVICE
+#endif // HAVE_SO_BINDTODEVICE
diff --git a/src/platform/telink/KeyValueStoreManagerImpl.h b/src/platform/telink/KeyValueStoreManagerImpl.h
new file mode 100644
index 0000000..f60a037
--- /dev/null
+++ b/src/platform/telink/KeyValueStoreManagerImpl.h
@@ -0,0 +1,27 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * Provides an implementation of the KeyValueStoreManager object
+ * for Telink platform, by including Zephyr platform
+ * implementation.
+ */
+
+#pragma once
+
+#include <platform/Zephyr/KeyValueStoreManagerImpl.h>
diff --git a/src/platform/telink/PlatformManagerImpl.h b/src/platform/telink/PlatformManagerImpl.h
new file mode 100644
index 0000000..6d2878f
--- /dev/null
+++ b/src/platform/telink/PlatformManagerImpl.h
@@ -0,0 +1,27 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * Provides an implementation of the PlatformManager object
+ * for Telink platform, by including Zephyr platform
+ * implementation.
+ */
+
+#pragma once
+
+#include <platform/Zephyr/PlatformManagerImpl.h>
diff --git a/src/platform/telink/SystemPlatformConfig.h b/src/platform/telink/SystemPlatformConfig.h
new file mode 100644
index 0000000..25a9fed
--- /dev/null
+++ b/src/platform/telink/SystemPlatformConfig.h
@@ -0,0 +1,54 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * Platform-specific configuration overrides for the CHIP System
+ * Layer on Telink platform.
+ *
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+namespace chip {
+namespace DeviceLayer {
+struct ChipDeviceEvent;
+} // namespace DeviceLayer
+} // namespace chip
+
+// ==================== Platform Adaptations ====================
+
+#define CHIP_SYSTEM_CONFIG_POSIX_LOCKING 1
+#define CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING 0
+#define CHIP_SYSTEM_CONFIG_NO_LOCKING 0
+#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS 1
+#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 0
+
+#ifndef CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS
+#define CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS 0
+#endif // CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS
+
+#define CHIP_SYSTEM_CONFIG_USE_LWIP 0
+#define CHIP_SYSTEM_CONFIG_USE_SOCKETS 1
+
+// ========== Platform-specific Configuration Overrides =========
+
+#ifndef CHIP_SYSTEM_CONFIG_NUM_TIMERS
+#define CHIP_SYSTEM_CONFIG_NUM_TIMERS 16
+#endif // CHIP_SYSTEM_CONFIG_NUM_TIMERS
diff --git a/src/platform/telink/ThreadStackManagerImpl.h b/src/platform/telink/ThreadStackManagerImpl.h
new file mode 100644
index 0000000..95560af
--- /dev/null
+++ b/src/platform/telink/ThreadStackManagerImpl.h
@@ -0,0 +1,27 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * Provides an implementation of the ThreadStackManager object
+ * for Telink platform, by including Zephyr platform
+ * implementation.
+ */
+
+#pragma once
+
+#include <platform/Zephyr/ThreadStackManagerImpl.h>
diff --git a/src/platform/telink/args.gni b/src/platform/telink/args.gni
new file mode 100644
index 0000000..1ff86d0
--- /dev/null
+++ b/src/platform/telink/args.gni
@@ -0,0 +1,17 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+chip_device_platform = "telink"
+
+chip_inet_config_enable_ipv4 = false
diff --git a/src/platform/telink/telink-mbedtls-config.h b/src/platform/telink/telink-mbedtls-config.h
new file mode 100644
index 0000000..7b41880
--- /dev/null
+++ b/src/platform/telink/telink-mbedtls-config.h
@@ -0,0 +1,114 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * Platform-specific configuration for mbedtls *
+ */
+
+#include <sys/cbprintf.h>
+
+#pragma once
+
+#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf
+
+#define MBEDTLS_CIPHER_MODE_CTR
+#define MBEDTLS_SHA512_C
+#define MBEDTLS_ECDH_C
+#define MBEDTLS_SHA1_C
+#define MBEDTLS_HKDF_C
+#define MBEDTLS_CHACHAPOLY_C
+#define MBEDTLS_POLY1305_C
+#define MBEDTLS_CHACHA20_C
+#define MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
+#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
+#define MBEDTLS_AES_C
+#define MBEDTLS_AES_ROM_TABLES
+#define MBEDTLS_ASN1_PARSE_C
+#define MBEDTLS_ASN1_WRITE_C
+#define MBEDTLS_BIGNUM_C
+#define MBEDTLS_CCM_C
+#define MBEDTLS_CIPHER_C
+#define MBEDTLS_CMAC_C
+#define MBEDTLS_CTR_DRBG_C
+#define MBEDTLS_ECJPAKE_C
+#define MBEDTLS_ECP_C
+#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
+#define MBEDTLS_ECP_NIST_OPTIM
+#define MBEDTLS_ENTROPY_C
+#define MBEDTLS_HAVE_ASM
+#define MBEDTLS_HMAC_DRBG_C
+#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
+#define MBEDTLS_MD_C
+#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
+#define MBEDTLS_NO_PLATFORM_ENTROPY
+#define MBEDTLS_PK_C
+#define MBEDTLS_PK_PARSE_C
+#define MBEDTLS_PK_WRITE_C
+#define MBEDTLS_PKCS5_C
+#define MBEDTLS_PLATFORM_C
+#define MBEDTLS_PLATFORM_MEMORY
+#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
+#define MBEDTLS_SHA256_C
+#define MBEDTLS_SHA256_SMALLER
+#define MBEDTLS_SSL_CLI_C
+#define MBEDTLS_SSL_DTLS_ANTI_REPLAY
+#define MBEDTLS_SSL_DTLS_HELLO_VERIFY
+#define MBEDTLS_SSL_EXPORT_KEYS
+#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
+#define MBEDTLS_SSL_PROTO_TLS1_2
+#define MBEDTLS_SSL_PROTO_DTLS
+#define MBEDTLS_SSL_TLS_C
+#define MBEDTLS_SSL_COOKIE_C
+#define MBEDTLS_SSL_SRV_C
+#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
+#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
+#define MBEDTLS_BASE64_C
+#define MBEDTLS_ECDH_C
+#define MBEDTLS_ECDSA_C
+#define MBEDTLS_OID_C
+#define MBEDTLS_PEM_PARSE_C
+#define MBEDTLS_X509_USE_C
+#define MBEDTLS_X509_CRT_PARSE_C
+#define MBEDTLS_X509_CREATE_C
+#define MBEDTLS_X509_CSR_WRITE_C
+#define MBEDTLS_ECDSA_DETERMINISTIC
+
+#if OPENTHREAD_CONFIG_ECDSA_ENABLE
+#define MBEDTLS_BASE64_C
+#define MBEDTLS_ECDH_C
+#define MBEDTLS_ECDSA_C
+#define MBEDTLS_OID_C
+#define MBEDTLS_PEM_PARSE_C
+#endif
+
+#define MBEDTLS_MPI_WINDOW_SIZE 1 /**< Maximum windows size used. */
+#define MBEDTLS_MPI_MAX_SIZE 32 /**< Maximum number of bytes for usable MPIs. */
+#define MBEDTLS_ECP_MAX_BITS 256 /**< Maximum bit size of groups */
+#define MBEDTLS_ECP_WINDOW_SIZE 2 /**< Maximum window size used */
+#define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 /**< Enable fixed-point speed-up */
+#define MBEDTLS_ENTROPY_MAX_SOURCES 1 /**< Maximum number of sources supported */
+
+#if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
+#define MBEDTLS_PLATFORM_STD_CALLOC otPlatCAlloc /**< Default allocator to use, can be undefined */
+#define MBEDTLS_PLATFORM_STD_FREE otPlatFree /**< Default free to use, can be undefined */
+#else
+#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
+#endif
+
+#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
+#define MBEDTLS_DEBUG_C