Skip to content

Commit 6e035c8

Browse files
authored
[Ameba] Support Pigweed-app (project-chip#12979)
* [Ameba]Support Pigweed-app and RPC * [Ameba] Update scripts/build for pigweed app * [Ameba] Fix restyled errors * [Ameba] Update README.md file * Fix spellcheck * Restyled
1 parent f9ce4be commit 6e035c8

26 files changed

+1048
-3
lines changed

.github/.wordlist.txt

+1
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ TransportMgrBase
996996
TrustedRootCertificates
997997
TSG
998998
tsv
999+
TTL
9991000
tty
10001001
ttyACM
10011002
ttyACMx

config/ameba/args.gni

+1
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ custom_toolchain = "//third_party/connectedhomeip/config/ameba/toolchain:ameba"
3636

3737
pw_build_PIP_CONSTRAINTS =
3838
[ "//third_party/connectedhomeip/scripts/constraints.txt" ]
39+
cpp_standard = "c++17"

config/ameba/chip.cmake

+13-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ list(
4141
-Wno-deprecated-declarations
4242
-Wno-unused-parameter
4343
-Wno-format
44+
-Wno-stringop-truncation
45+
-std=c++17
4446
)
4547

4648
list(
@@ -98,6 +100,15 @@ string(APPEND CHIP_GN_ARGS "ameba_cc = \"arm-none-eabi-gcc\"\n")
98100
string(APPEND CHIP_GN_ARGS "ameba_cxx = \"arm-none-eabi-c++\"\n")
99101
string(APPEND CHIP_GN_ARGS "ameba_cpu = \"ameba\"\n")
100102

103+
# Build RPC
104+
#string(APPEND CHIP_GN_ARGS "remove_default_configs = [\"//third_party/connectedhomeip/third_party/pigweed/repo/pw_build:cpp17\"]\n")
105+
string(APPEND CHIP_GN_ARGS "chip_build_pw_rpc_lib = true\n")
106+
string(APPEND CHIP_GN_ARGS "pw_log_BACKEND = \"//third_party/connectedhomeip/third_party/pigweed/repo/pw_log_basic\"\n")
107+
string(APPEND CHIP_GN_ARGS "pw_assert_BACKEND = \"//third_party/connectedhomeip/third_party/pigweed/repo/pw_assert_log\"\n")
108+
string(APPEND CHIP_GN_ARGS "pw_sys_io_BACKEND = \"//third_party/connectedhomeip/examples/platform/ameba/pw_sys_io:pw_sys_io_ameba\"\n")
109+
string(APPEND CHIP_GN_ARGS "dir_pw_third_party_nanopb = \"//third_party/connectedhomeip/third_party/nanopb/repo\"\n")
110+
string(APPEND CHIP_GN_ARGS "pw_build_LINK_DEPS = [\"//third_party/connectedhomeip/third_party/pigweed/repo/pw_assert:impl\", \"//third_party/connectedhomeip/third_party/pigweed/repo/pw_log:impl\"]\n")
111+
101112
file(GENERATE OUTPUT ${CHIP_OUTPUT}/args.gn CONTENT ${CHIP_GN_ARGS})
102113

103114
ExternalProject_Add(
@@ -106,9 +117,9 @@ ExternalProject_Add(
106117
SOURCE_DIR ${CHIP_ROOT}
107118
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}
108119
CONFIGURE_COMMAND gn --root=${CHIP_ROOT}/config/ameba gen --check --fail-on-unused-args ${CHIP_OUTPUT}
109-
BUILD_COMMAND ninja -C ${CHIP_OUTPUT}
120+
BUILD_COMMAND ninja -C ${CHIP_OUTPUT} :ameba
110121
INSTALL_COMMAND ""
111-
BUILD_BYPRODUCTS -lCHIP
122+
BUILD_BYPRODUCTS -lCHIP -lPwRpc
112123
CONFIGURE_ALWAYS TRUE
113124
BUILD_ALWAYS TRUE
114125
USES_TERMINAL_CONFIGURE TRUE

config/ameba/lib/pw_rpc/BUILD.gn

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (c) 2021 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/chip.gni")
16+
import("//build_overrides/pigweed.gni")
17+
import("$dir_pw_build/target_types.gni")
18+
19+
static_library("pw_rpc") {
20+
output_name = "libPwRpc"
21+
22+
public_configs = [ "${dir_pigweed}/pw_hdlc:default_config" ]
23+
deps = [
24+
"$dir_pw_rpc:server",
25+
"$dir_pw_rpc/nanopb:echo_service",
26+
"${chip_root}/examples/platform/ameba/pw_sys_io:pw_sys_io_ameba",
27+
"${dir_pigweed}/pw_hdlc:pw_rpc",
28+
dir_pw_assert,
29+
dir_pw_hdlc,
30+
dir_pw_log,
31+
]
32+
33+
deps += pw_build_LINK_DEPS
34+
35+
output_dir = "${root_out_dir}/lib"
36+
37+
complete_static_lib = true
38+
}

examples/all-clusters-app/ameba/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ control.
1313
- [BLE mode](#ble-mode)
1414
- [IP mode](#ip-mode)
1515
- [Cluster control](#cluster-control)
16+
- [Running RPC Console](#running-rpc-console)
1617

1718
---
1819

@@ -113,3 +114,31 @@ to be On or Off.
113114
[Python Controller](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/python_chip_controller_building.md#step-8-control-application-zcl-clusters)
114115

115116
$ chip-device-ctrl > zcl OnOff Toggle 1234 1 0
117+
118+
## Running RPC Console
119+
120+
- Connect a USB-TTL Adapter as shown below
121+
122+
Ameba USB-TTL
123+
A19 TX
124+
A18 RX
125+
GND GND
126+
127+
- Build the
128+
[chip-rpc console](https://github.com/project-chip/connectedhomeip/tree/master/examples/common/pigweed/rpc_console)
129+
130+
- As part of building the example with RPCs enabled the chip_rpc python
131+
interactive console is installed into your venv. The python wheel files are
132+
also created in the output folder: out/debug/chip_rpc_console_wheels. To
133+
install the wheel files without rebuilding:
134+
135+
$ pip3 install out/debug/chip_rpc_console_wheels/*.whl
136+
137+
- Launch the chip-rpc console after inputting `ATS$` command
138+
139+
$ python3 -m chip_rpc.console --device /dev/tty<port connected to USB-TTL adapter> -b 115200
140+
141+
- Get and Set lighting directly using the RPC console
142+
143+
rpcs.chip.rpc.Lighting.Get()
144+
rpcs.chip.rpc.Lighting.Set(on=True, level=128, color=protos.chip.rpc.LightingColor(hue=5, saturation=5))

examples/all-clusters-app/ameba/chip_main.cmake

+157-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,110 @@ set(dir "${sdk_root}/component/common/api")
88
set(chip_main chip_main)
99
set(list_chip_main_sources chip_main_sources)
1010

11+
if (matter_enable_rpc)
12+
set(pigweed_dir "${chip_dir}/third_party/pigweed/repo")
13+
14+
include(${pigweed_dir}/pw_build/pigweed.cmake)
15+
include(${pigweed_dir}/pw_protobuf_compiler/proto.cmake)
16+
17+
set(dir_pw_third_party_nanopb "${chip_dir}/third_party/nanopb/repo" CACHE STRING "" FORCE)
18+
19+
pw_set_backend(pw_log pw_log_basic)
20+
pw_set_backend(pw_assert pw_assert_log)
21+
pw_set_backend(pw_sys_io pw_sys_io.ameba)
22+
pw_set_backend(pw_trace pw_trace_tokenized)
23+
24+
add_subdirectory(${chip_dir}/third_party/pigweed/repo ${chip_dir}/examples/all-clusters-app/ameba/out/pigweed)
25+
add_subdirectory(${chip_dir}/third_party/nanopb/repo ${chip_dir}/examples/all-clusters-app/ameba/out/nanopb)
26+
add_subdirectory(${chip_dir}/examples/platform/ameba/pw_sys_io ${chip_dir}/examples/all-clusters-app/ameba/out/pw_sys_io)
27+
28+
pw_proto_library(attributes_service
29+
SOURCES
30+
${chip_dir}/examples/common/pigweed/protos/attributes_service.proto
31+
INPUTS
32+
${chip_dir}/examples/common/pigweed/protos/attributes_service.options
33+
PREFIX
34+
attributes_service
35+
STRIP_PREFIX
36+
${chip_dir}/examples/common/pigweed/protos
37+
DEPS
38+
pw_protobuf.common_protos
39+
)
40+
41+
pw_proto_library(button_service
42+
SOURCES
43+
${chip_dir}/examples/common/pigweed/protos/button_service.proto
44+
PREFIX
45+
button_service
46+
STRIP_PREFIX
47+
${chip_dir}/examples/common/pigweed/protos
48+
DEPS
49+
pw_protobuf.common_protos
50+
)
51+
52+
pw_proto_library(device_service
53+
SOURCES
54+
${chip_dir}/examples/common/pigweed/protos/device_service.proto
55+
INPUTS
56+
${chip_dir}/examples/common/pigweed/protos/device_service.options
57+
PREFIX
58+
device_service
59+
STRIP_PREFIX
60+
${chip_dir}/examples/common/pigweed/protos
61+
DEPS
62+
pw_protobuf.common_protos
63+
)
64+
65+
pw_proto_library(lighting_service
66+
SOURCES
67+
${chip_dir}/examples/common/pigweed/protos/lighting_service.proto
68+
PREFIX
69+
lighting_service
70+
STRIP_PREFIX
71+
${chip_dir}/examples/common/pigweed/protos
72+
DEPS
73+
pw_protobuf.common_protos
74+
)
75+
76+
pw_proto_library(locking_service
77+
SOURCES
78+
${chip_dir}/examples/common/pigweed/protos/locking_service.proto
79+
PREFIX
80+
locking_service
81+
STRIP_PREFIX
82+
${chip_dir}/examples/common/pigweed/protos
83+
DEPS
84+
pw_protobuf.common_protos
85+
)
86+
87+
pw_proto_library(wifi_service
88+
SOURCES
89+
${chip_dir}/examples/ipv6only-app/common/wifi_service/wifi_service.proto
90+
INPUTS
91+
${chip_dir}/examples/ipv6only-app/common/wifi_service/wifi_service.options
92+
PREFIX
93+
wifi_service
94+
DEPS
95+
pw_protobuf.common_protos
96+
STRIP_PREFIX
97+
${chip_dir}/examples/ipv6only-app/common/wifi_service
98+
)
99+
100+
endif(matter_enable_rpc)
101+
11102
include(${prj_root}/GCC-RELEASE/project_hp/asdk/includepath.cmake)
12103

104+
if (matter_enable_rpc)
105+
list(
106+
APPEND ${list_chip_main_sources}
107+
#rpc
108+
${chip_dir}/examples/platform/ameba/PigweedLogger.cpp
109+
${chip_dir}/examples/platform/ameba/Rpc.cpp
110+
${chip_dir}/examples/common/pigweed/RpcService.cpp
111+
${chip_dir}/examples/common/pigweed/ameba/PigweedLoggerMutex.cpp
112+
)
113+
endif (matter_enable_rpc)
114+
13115
list(
14116
APPEND ${list_chip_main_sources}
15117

@@ -40,10 +142,26 @@ chip_configure_data_model(chip_main
40142
ZAP_FILE ${matter_example_path}/../all-clusters-common/all-clusters-app.zap
41143
)
42144

145+
if (matter_enable_rpc)
43146
target_include_directories(
44147
${chip_main}
45148
PUBLIC
46-
${inc_path}
149+
#rpc
150+
${chip_dir}/examples/platform/ameba
151+
${chip_dir}/examples/platform/ameba/pw_sys_io/public
152+
${chip_dir}/examples/common
153+
${chip_dir}/examples/common/pigweed
154+
${chip_dir}/examples/common/pigweed/ameba
155+
${chip_dir}/src
156+
${chip_dir}/src/lib/support
157+
${pigweed_dir}/pw_rpc/nanopb/public
158+
)
159+
endif (matter_enable_rpc)
160+
161+
target_include_directories(
162+
${chip_main}
163+
PUBLIC
164+
${inc_path}
47165
${chip_dir}/zzz_generated/all-clusters-app
48166
${chip_dir}/zzz_generated/all-clusters-app/zap-generated
49167
${chip_dir}/zzz_generated/app-common
@@ -63,6 +181,30 @@ target_include_directories(
63181
${chip_dir}/third_party/nlunit-test/repo/src
64182
)
65183

184+
if (matter_enable_rpc)
185+
target_link_libraries(${chip_main} PUBLIC
186+
attributes_service.nanopb_rpc
187+
button_service.nanopb_rpc
188+
device_service.nanopb_rpc
189+
lighting_service.nanopb_rpc
190+
locking_service.nanopb_rpc
191+
wifi_service.nanopb_rpc
192+
pw_checksum
193+
pw_hdlc
194+
pw_log
195+
pw_rpc.server
196+
pw_trace_tokenized
197+
pw_trace_tokenized.trace_buffer
198+
pw_trace_tokenized.rpc_service
199+
pw_trace_tokenized.protos.nanopb_rpc
200+
PwRpc
201+
)
202+
203+
link_directories(
204+
${chip_dir_output}/lib
205+
)
206+
endif (matter_enable_rpc)
207+
66208
list(
67209
APPEND chip_main_flags
68210

@@ -74,6 +216,19 @@ list(
74216
-DMBEDTLS_CONFIG_FILE=<mbedtls_config.h>
75217
)
76218

219+
if (matter_enable_rpc)
220+
list(
221+
APPEND chip_main_flags
222+
223+
-DPW_RPC_ATTRIBUTE_SERVICE=1
224+
-DPW_RPC_BUTTON_SERVICE=1
225+
-DPW_RPC_DEVICE_SERVICE=1
226+
-DPW_RPC_LIGHTING_SERVICE=1
227+
-DPW_RPC_LOCKING_SERVICE=1
228+
-DCONFIG_ENABLE_PW_RPC=1
229+
)
230+
endif (matter_enable_rpc)
231+
77232
list(
78233
APPEND chip_main_cpp_flags
79234

@@ -91,3 +246,4 @@ add_custom_command(
91246
POST_BUILD
92247
COMMAND cp lib${chip_main}.a ${CMAKE_CURRENT_SOURCE_DIR}/lib/application
93248
)
249+

examples/all-clusters-app/ameba/main/chipinterface.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
3737
#include <support/CHIPMem.h>
3838

39+
#if CONFIG_ENABLE_PW_RPC
40+
#include "Rpc.h"
41+
#endif
42+
3943
extern "C" {
4044
void * __dso_handle = 0;
4145
}
@@ -190,6 +194,10 @@ extern "C" void ChipTest(void)
190194
ChipLogProgress(DeviceLayer, "All Clusters Demo!");
191195
CHIP_ERROR err = CHIP_NO_ERROR;
192196

197+
#if CONFIG_ENABLE_PW_RPC
198+
chip::rpc::Init();
199+
#endif
200+
193201
initPref();
194202

195203
CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
*
3+
* Copyright (c) 2021 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+
#include "PigweedLoggerMutex.h"
20+
21+
namespace chip {
22+
namespace rpc {
23+
24+
PigweedLoggerMutex logger_mutex;
25+
26+
} // namespace rpc
27+
} // namespace chip

0 commit comments

Comments
 (0)