Skip to content

Commit 0ff8f19

Browse files
s07641069restyled-commitsUR6LAL
authored
[Telink] Add chef app example (project-chip#28701)
* Restyled by autopep8 * [Telink] add telink support to chef.py * [Telink] addtelink platform compatibility with chef example * [Telink] remove README * Restyled by whitespace * Restyled by clang-format * Restyled by autopep8 * [Telink] fix code style --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: UR6LAL <ur6lal@gmail.com>
1 parent a6dae2c commit 0ff8f19

File tree

8 files changed

+581
-4
lines changed

8 files changed

+581
-4
lines changed

examples/chef/chef.py

+36-4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def load_config() -> None:
6464
config["esp32"] = dict()
6565
config["silabs-thread"] = dict()
6666
config["ameba"] = dict()
67+
config["telink"] = dict()
6768
configFile = f"{_CHEF_SCRIPT_PATH}/config.yaml"
6869
if (os.path.exists(configFile)):
6970
configStream = open(configFile, 'r')
@@ -88,6 +89,8 @@ def load_config() -> None:
8889
config["ameba"]["MATTER_SDK"] = None
8990
config["ameba"]["MODEL"] = 'D'
9091
config["ameba"]["TTY"] = None
92+
config["telink"]["ZEPHYR_BASE"] = os.environ.get('ZEPHYR_BASE')
93+
config["telink"]["TTY"] = None
9194

9295
flush_print(yaml.dump(config))
9396
yaml.dump(config, configStream)
@@ -275,6 +278,7 @@ def main() -> int:
275278
linux
276279
silabs-thread
277280
ameba
281+
telink
278282
279283
Device Types:
280284
{deviceTypes}
@@ -312,7 +316,7 @@ def main() -> int:
312316
dest="build_target",
313317
help="specifies target platform. See info below for currently supported target platforms",
314318
choices=['nrfconnect', 'esp32',
315-
'linux', 'silabs-thread', 'ameba'],
319+
'linux', 'silabs-thread', 'ameba', 'telink'],
316320
metavar="TARGET",
317321
default="linux")
318322
parser.add_option("-r", "--rpc",
@@ -514,6 +518,16 @@ def main() -> int:
514518
if (config['ameba']['MODEL'] != 'D' and config['ameba']['MODEL'] != 'Z2'):
515519
flush_print("Ameba Model is not recognized, please input D or Z2")
516520
exit(1)
521+
elif options.build_target == "telink":
522+
if config['telink']['ZEPHYR_BASE'] is None:
523+
flush_print(
524+
'Path for Telink SDK was not found. Make sure Telink_SDK is set on your config.yaml file')
525+
exit(1)
526+
shell.run_cmd("export ZEPHYR_TOOLCHAIN_VARIANT=zephyr")
527+
shell.run_cmd(
528+
f"export ZEPHYR_BASE={config['telink']['ZEPHYR_BASE']}")
529+
shell.run_cmd(
530+
f'source {config["telink"]["ZEPHYR_BASE"]}/zephyr-env.sh')
517531
else:
518532
flush_print(f"Target {options.build_target} not supported")
519533

@@ -536,7 +550,8 @@ def main() -> int:
536550
flush_print("Linux toolchain update not supported. Skipping")
537551
elif options.build_target == "Ameba":
538552
flush_print("Ameba toolchain update not supported. Skipping")
539-
553+
elif options.build_target == "telink":
554+
flush_print("Telink toolchain update not supported. Skipping")
540555
#
541556
# Clean environment
542557
#
@@ -606,6 +621,8 @@ def main() -> int:
606621
flush_print("Menuconfig not available on Linux target. Skipping")
607622
elif options.build_target == "Ameba":
608623
flush_print("Menuconfig not available on Ameba target. Skipping")
624+
elif options.build_target == "telink":
625+
flush_print("Menuconfig not available on Telink target. Skipping")
609626

610627
#
611628
# Build
@@ -639,7 +656,7 @@ def main() -> int:
639656

640657
shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}")
641658

642-
if (options.build_target == "esp32") or (options.build_target == "nrfconnect") or (options.build_target == "ameba"):
659+
if options.build_target in "esp32 nrfconnect ameba telink".split():
643660
with open("project_include.cmake", "w") as f:
644661
f.write(textwrap.dedent(f"""\
645662
set(CONFIG_DEVICE_VENDOR_ID {options.vid})
@@ -725,6 +742,14 @@ def main() -> int:
725742
shell.run_cmd("make clean")
726743
shell.run_cmd("make chef")
727744
shell.run_cmd("make is")
745+
elif options.build_target == "telink":
746+
shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}/telink")
747+
telink_build_cmds = ["west build"]
748+
if options.do_clean:
749+
telink_build_cmds.append("-p always")
750+
if options.do_rpc:
751+
telink_build_cmds.append("-- -DOVERLAY_CONFIG=rpc.overlay")
752+
shell.run_cmd(" ".join(telink_build_cmds))
728753

729754
elif options.build_target == "linux":
730755
shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}/linux")
@@ -900,7 +925,14 @@ def main() -> int:
900925
shell.run_cmd(f"screen {config['ameba']['TTY']} 115200")
901926
else:
902927
flush_print("Ameba Z2 image has not been flashed yet")
903-
928+
elif options.build_target == "telink":
929+
if config['telink']['TTY'] is None:
930+
flush_print(
931+
'The path for the serial enumeration for telink is not set. '
932+
'Make sure telink.TTY is set on your config.yaml file')
933+
exit(1)
934+
shell.run_cmd("killall screen")
935+
shell.run_cmd(f"screen {config['telink']['TTY']} 115200")
904936
#
905937
# RPC Console
906938
#

examples/chef/telink/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build/
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* @file
21+
* Example project configuration file for CHIP.
22+
*
23+
* This is a place to put application or project-specific overrides
24+
* to the default configuration values for general CHIP features.
25+
*
26+
*/
27+
28+
#pragma once
29+
30+
// Use a default pairing code if one hasn't been provisioned in flash.
31+
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021
32+
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
33+
34+
/**
35+
* CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE
36+
*
37+
* Reduce packet buffer pool size to 8 (default 15) to reduce ram consumption
38+
*/
39+
#define CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE 8
40+
41+
// Enable support functions for parsing command-line arguments
42+
#define CHIP_CONFIG_ENABLE_ARG_PARSER 1
43+
44+
#define CHIP_DEVICE_CONFIG_DISABLE_SHELL_PING 1

examples/chef/telink/CMakeLists.txt

+232
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
#
2+
# Copyright (c) 2023 Project CHIP Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
cmake_minimum_required(VERSION 3.13.1)
17+
18+
set(BOARD tlsr9518adk80d)
19+
20+
get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connectedhomeip REALPATH)
21+
get_filename_component(TELINK_COMMON ${CHIP_ROOT}/examples/platform/telink REALPATH)
22+
get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH)
23+
get_filename_component(CHEF ${CMAKE_CURRENT_SOURCE_DIR}/../ REALPATH)
24+
25+
include(${CHEF}/project_include.cmake)
26+
27+
get_filename_component(GEN_DIR ${CHEF}/out/${SAMPLE_NAME}/zap-generated REALPATH)
28+
29+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD}.overlay")
30+
set(LOCAL_DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD}.overlay")
31+
else()
32+
unset(LOCAL_DTC_OVERLAY_FILE)
33+
endif()
34+
35+
if(EXISTS "${CHIP_ROOT}/src/platform/telink/${BOARD}.overlay")
36+
set(GLOBAL_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BOARD}.overlay")
37+
else()
38+
unset(GLOBAL_DTC_OVERLAY_FILE)
39+
endif()
40+
41+
if(DTC_OVERLAY_FILE)
42+
set(DTC_OVERLAY_FILE
43+
"${DTC_OVERLAY_FILE} ${GLOBAL_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE}"
44+
CACHE STRING "" FORCE
45+
)
46+
else()
47+
set(DTC_OVERLAY_FILE ${GLOBAL_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE})
48+
endif()
49+
50+
set(CONF_FILE ${CHIP_ROOT}/config/telink/app/zephyr.conf prj.conf)
51+
52+
# Load NCS/Zephyr build system
53+
list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/telink/chip-module)
54+
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
55+
56+
project(chip-telink-chef-example)
57+
58+
include(${CHIP_ROOT}/config/telink/app/enable-gnu-std.cmake)
59+
include(${CHIP_ROOT}/src/app/chip_data_model.cmake)
60+
61+
target_compile_options(app PRIVATE -fpermissive)
62+
63+
target_include_directories(app PRIVATE
64+
${CMAKE_CURRENT_SOURCE_DIR}
65+
${GEN_DIR}/app-common
66+
${GEN_DIR}
67+
${CHEF}
68+
${GEN_DIR}/../
69+
${CHIP_ROOT}/src
70+
${CHEF}/shell_common/include
71+
${TELINK_COMMON}/common/include
72+
${TELINK_COMMON}/util/include
73+
)
74+
75+
if (CONFIG_CHIP_LIB_SHELL)
76+
target_sources(app PRIVATE
77+
${CHEF}/shell_common/globals.cpp
78+
${CHEF}/shell_common/cmd_misc.cpp
79+
${CHEF}/shell_common/cmd_otcli.cpp
80+
)
81+
82+
target_include_directories(app PRIVATE
83+
${CHEF}/shell_common/include
84+
)
85+
endif()
86+
87+
add_definitions(
88+
"-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib/address_resolve/AddressResolve_DefaultImpl.h>"
89+
)
90+
91+
target_sources(app PRIVATE
92+
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
93+
${CHEF}/common/stubs.cpp
94+
)
95+
96+
message(STATUS ${CHEF}/devices/${SAMPLE_NAME}.zap)
97+
98+
chip_configure_data_model(app
99+
INCLUDE_SERVER
100+
ZAP_FILE ${CHEF}/devices/${SAMPLE_NAME}.zap
101+
)
102+
103+
104+
if(CONFIG_CHIP_OTA_REQUESTOR)
105+
target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp)
106+
endif()
107+
108+
if (CONFIG_CHIP_PW_RPC)
109+
110+
# Make all targets created below depend on zephyr_interface to inherit MCU-related compilation flags
111+
link_libraries($<BUILD_INTERFACE:zephyr_interface>)
112+
113+
set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo")
114+
include(${PIGWEED_ROOT}/pw_build/pigweed.cmake)
115+
include(${PIGWEED_ROOT}/pw_protobuf_compiler/proto.cmake)
116+
117+
include($ENV{PW_ROOT}/pw_assert/backend.cmake)
118+
include($ENV{PW_ROOT}/pw_log/backend.cmake)
119+
include($ENV{PW_ROOT}/pw_sys_io/backend.cmake)
120+
121+
pw_set_module_config(pw_rpc_CONFIG pw_rpc.disable_global_mutex_config)
122+
pw_set_backend(pw_log pw_log_basic)
123+
pw_set_backend(pw_assert.check pw_assert_log.check_backend)
124+
pw_set_backend(pw_assert.assert pw_assert.assert_compatibility_backend)
125+
pw_set_backend(pw_sys_io pw_sys_io.telink)
126+
127+
set(dir_pw_third_party_nanopb "${CHIP_ROOT}/third_party/nanopb/repo" CACHE STRING "" FORCE)
128+
129+
add_subdirectory(third_party/connectedhomeip/third_party/pigweed/repo)
130+
add_subdirectory(third_party/connectedhomeip/third_party/nanopb/repo)
131+
add_subdirectory(third_party/connectedhomeip/examples/platform/telink/pw_sys_io)
132+
133+
pw_proto_library(attributes_service
134+
SOURCES
135+
${CHIP_ROOT}/examples/common/pigweed/protos/attributes_service.proto
136+
INPUTS
137+
${CHIP_ROOT}/examples/common/pigweed/protos/attributes_service.options
138+
PREFIX
139+
attributes_service
140+
STRIP_PREFIX
141+
${CHIP_ROOT}/examples/common/pigweed/protos
142+
DEPS
143+
pw_protobuf.common_proto
144+
)
145+
146+
pw_proto_library(descriptor_service
147+
SOURCES
148+
${CHIP_ROOT}/examples/common/pigweed/protos/descriptor_service.proto
149+
PREFIX
150+
descriptor_service
151+
STRIP_PREFIX
152+
${CHIP_ROOT}/examples/common/pigweed/protos
153+
DEPS
154+
pw_protobuf.common_proto
155+
)
156+
157+
pw_proto_library(device_service
158+
SOURCES
159+
${CHIP_ROOT}/examples/common/pigweed/protos/device_service.proto
160+
INPUTS
161+
${CHIP_ROOT}/examples/common/pigweed/protos/device_service.options
162+
PREFIX
163+
device_service
164+
STRIP_PREFIX
165+
${CHIP_ROOT}/examples/common/pigweed/protos
166+
DEPS
167+
pw_protobuf.common_proto
168+
)
169+
170+
pw_proto_library(ot_cli_service
171+
SOURCES
172+
${CHIP_ROOT}/examples/common/pigweed/protos/ot_cli_service.proto
173+
INPUTS
174+
${CHIP_ROOT}/examples/common/pigweed/protos/ot_cli_service.options
175+
STRIP_PREFIX
176+
${CHIP_ROOT}/examples/common/pigweed/protos
177+
PREFIX
178+
ot_cli_service
179+
DEPS
180+
pw_protobuf.common_proto
181+
)
182+
183+
pw_proto_library(thread_service
184+
SOURCES
185+
${CHIP_ROOT}/examples/common/pigweed/protos/thread_service.proto
186+
INPUTS
187+
${CHIP_ROOT}/examples/common/pigweed/protos/thread_service.options
188+
STRIP_PREFIX
189+
${CHIP_ROOT}/examples/common/pigweed/protos
190+
PREFIX
191+
thread_service
192+
DEPS
193+
pw_protobuf.common_proto
194+
)
195+
196+
target_sources(app PRIVATE
197+
../../common/pigweed/RpcService.cpp
198+
../../common/pigweed/telink/PigweedLoggerMutex.cpp
199+
${TELINK_COMMON}/Rpc.cpp
200+
${TELINK_COMMON}/util/src/PigweedLogger.cpp
201+
)
202+
203+
target_include_directories(app PRIVATE
204+
${PIGWEED_ROOT}/pw_sys_io/public
205+
${CHIP_ROOT}/src/lib/support
206+
${CHIP_ROOT}/src/system
207+
${TELINK_COMMON}
208+
../../common
209+
../../common/pigweed
210+
../../common/pigweed/telink)
211+
212+
target_compile_options(app PRIVATE
213+
"-DPW_RPC_ATTRIBUTE_SERVICE=1"
214+
"-DPW_RPC_DESCRIPTOR_SERVICE=1"
215+
"-DPW_RPC_DEVICE_SERVICE=1"
216+
"-DPW_RPC_THREAD_SERVICE=1"
217+
)
218+
219+
target_link_libraries(app PRIVATE
220+
attributes_service.nanopb_rpc
221+
descriptor_service.nanopb_rpc
222+
device_service.nanopb_rpc
223+
thread_service.nanopb_rpc
224+
pw_checksum
225+
pw_hdlc
226+
pw_hdlc.pw_rpc
227+
pw_log
228+
pw_rpc.server
229+
pw_sys_io
230+
)
231+
232+
endif(CONFIG_CHIP_PW_RPC)

0 commit comments

Comments
 (0)