Skip to content

Commit

Permalink
[Ameba] Support Pigweed-app (#12979)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
pankore authored Dec 22, 2021
1 parent f9ce4be commit 6e035c8
Show file tree
Hide file tree
Showing 26 changed files with 1,048 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ TransportMgrBase
TrustedRootCertificates
TSG
tsv
TTL
tty
ttyACM
ttyACMx
Expand Down
1 change: 1 addition & 0 deletions config/ameba/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ custom_toolchain = "//third_party/connectedhomeip/config/ameba/toolchain:ameba"

pw_build_PIP_CONSTRAINTS =
[ "//third_party/connectedhomeip/scripts/constraints.txt" ]
cpp_standard = "c++17"
15 changes: 13 additions & 2 deletions config/ameba/chip.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ list(
-Wno-deprecated-declarations
-Wno-unused-parameter
-Wno-format
-Wno-stringop-truncation
-std=c++17
)

list(
Expand Down Expand Up @@ -98,6 +100,15 @@ string(APPEND CHIP_GN_ARGS "ameba_cc = \"arm-none-eabi-gcc\"\n")
string(APPEND CHIP_GN_ARGS "ameba_cxx = \"arm-none-eabi-c++\"\n")
string(APPEND CHIP_GN_ARGS "ameba_cpu = \"ameba\"\n")

# Build RPC
#string(APPEND CHIP_GN_ARGS "remove_default_configs = [\"//third_party/connectedhomeip/third_party/pigweed/repo/pw_build:cpp17\"]\n")
string(APPEND CHIP_GN_ARGS "chip_build_pw_rpc_lib = true\n")
string(APPEND CHIP_GN_ARGS "pw_log_BACKEND = \"//third_party/connectedhomeip/third_party/pigweed/repo/pw_log_basic\"\n")
string(APPEND CHIP_GN_ARGS "pw_assert_BACKEND = \"//third_party/connectedhomeip/third_party/pigweed/repo/pw_assert_log\"\n")
string(APPEND CHIP_GN_ARGS "pw_sys_io_BACKEND = \"//third_party/connectedhomeip/examples/platform/ameba/pw_sys_io:pw_sys_io_ameba\"\n")
string(APPEND CHIP_GN_ARGS "dir_pw_third_party_nanopb = \"//third_party/connectedhomeip/third_party/nanopb/repo\"\n")
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")

file(GENERATE OUTPUT ${CHIP_OUTPUT}/args.gn CONTENT ${CHIP_GN_ARGS})

ExternalProject_Add(
Expand All @@ -106,9 +117,9 @@ ExternalProject_Add(
SOURCE_DIR ${CHIP_ROOT}
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}
CONFIGURE_COMMAND gn --root=${CHIP_ROOT}/config/ameba gen --check --fail-on-unused-args ${CHIP_OUTPUT}
BUILD_COMMAND ninja -C ${CHIP_OUTPUT}
BUILD_COMMAND ninja -C ${CHIP_OUTPUT} :ameba
INSTALL_COMMAND ""
BUILD_BYPRODUCTS -lCHIP
BUILD_BYPRODUCTS -lCHIP -lPwRpc
CONFIGURE_ALWAYS TRUE
BUILD_ALWAYS TRUE
USES_TERMINAL_CONFIGURE TRUE
Expand Down
38 changes: 38 additions & 0 deletions config/ameba/lib/pw_rpc/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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")
import("//build_overrides/pigweed.gni")
import("$dir_pw_build/target_types.gni")

static_library("pw_rpc") {
output_name = "libPwRpc"

public_configs = [ "${dir_pigweed}/pw_hdlc:default_config" ]
deps = [
"$dir_pw_rpc:server",
"$dir_pw_rpc/nanopb:echo_service",
"${chip_root}/examples/platform/ameba/pw_sys_io:pw_sys_io_ameba",
"${dir_pigweed}/pw_hdlc:pw_rpc",
dir_pw_assert,
dir_pw_hdlc,
dir_pw_log,
]

deps += pw_build_LINK_DEPS

output_dir = "${root_out_dir}/lib"

complete_static_lib = true
}
29 changes: 29 additions & 0 deletions examples/all-clusters-app/ameba/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ control.
- [BLE mode](#ble-mode)
- [IP mode](#ip-mode)
- [Cluster control](#cluster-control)
- [Running RPC Console](#running-rpc-console)

---

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

$ chip-device-ctrl > zcl OnOff Toggle 1234 1 0

## Running RPC Console

- Connect a USB-TTL Adapter as shown below

Ameba USB-TTL
A19 TX
A18 RX
GND GND

- Build the
[chip-rpc console](https://github.com/project-chip/connectedhomeip/tree/master/examples/common/pigweed/rpc_console)

- As part of building the example with RPCs enabled the chip_rpc python
interactive console is installed into your venv. The python wheel files are
also created in the output folder: out/debug/chip_rpc_console_wheels. To
install the wheel files without rebuilding:

$ pip3 install out/debug/chip_rpc_console_wheels/*.whl

- Launch the chip-rpc console after inputting `ATS$` command

$ python3 -m chip_rpc.console --device /dev/tty<port connected to USB-TTL adapter> -b 115200

- Get and Set lighting directly using the RPC console

rpcs.chip.rpc.Lighting.Get()
rpcs.chip.rpc.Lighting.Set(on=True, level=128, color=protos.chip.rpc.LightingColor(hue=5, saturation=5))
158 changes: 157 additions & 1 deletion examples/all-clusters-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,110 @@ set(dir "${sdk_root}/component/common/api")
set(chip_main chip_main)
set(list_chip_main_sources chip_main_sources)

if (matter_enable_rpc)
set(pigweed_dir "${chip_dir}/third_party/pigweed/repo")

include(${pigweed_dir}/pw_build/pigweed.cmake)
include(${pigweed_dir}/pw_protobuf_compiler/proto.cmake)

set(dir_pw_third_party_nanopb "${chip_dir}/third_party/nanopb/repo" CACHE STRING "" FORCE)

pw_set_backend(pw_log pw_log_basic)
pw_set_backend(pw_assert pw_assert_log)
pw_set_backend(pw_sys_io pw_sys_io.ameba)
pw_set_backend(pw_trace pw_trace_tokenized)

add_subdirectory(${chip_dir}/third_party/pigweed/repo ${chip_dir}/examples/all-clusters-app/ameba/out/pigweed)
add_subdirectory(${chip_dir}/third_party/nanopb/repo ${chip_dir}/examples/all-clusters-app/ameba/out/nanopb)
add_subdirectory(${chip_dir}/examples/platform/ameba/pw_sys_io ${chip_dir}/examples/all-clusters-app/ameba/out/pw_sys_io)

pw_proto_library(attributes_service
SOURCES
${chip_dir}/examples/common/pigweed/protos/attributes_service.proto
INPUTS
${chip_dir}/examples/common/pigweed/protos/attributes_service.options
PREFIX
attributes_service
STRIP_PREFIX
${chip_dir}/examples/common/pigweed/protos
DEPS
pw_protobuf.common_protos
)

pw_proto_library(button_service
SOURCES
${chip_dir}/examples/common/pigweed/protos/button_service.proto
PREFIX
button_service
STRIP_PREFIX
${chip_dir}/examples/common/pigweed/protos
DEPS
pw_protobuf.common_protos
)

pw_proto_library(device_service
SOURCES
${chip_dir}/examples/common/pigweed/protos/device_service.proto
INPUTS
${chip_dir}/examples/common/pigweed/protos/device_service.options
PREFIX
device_service
STRIP_PREFIX
${chip_dir}/examples/common/pigweed/protos
DEPS
pw_protobuf.common_protos
)

pw_proto_library(lighting_service
SOURCES
${chip_dir}/examples/common/pigweed/protos/lighting_service.proto
PREFIX
lighting_service
STRIP_PREFIX
${chip_dir}/examples/common/pigweed/protos
DEPS
pw_protobuf.common_protos
)

pw_proto_library(locking_service
SOURCES
${chip_dir}/examples/common/pigweed/protos/locking_service.proto
PREFIX
locking_service
STRIP_PREFIX
${chip_dir}/examples/common/pigweed/protos
DEPS
pw_protobuf.common_protos
)

pw_proto_library(wifi_service
SOURCES
${chip_dir}/examples/ipv6only-app/common/wifi_service/wifi_service.proto
INPUTS
${chip_dir}/examples/ipv6only-app/common/wifi_service/wifi_service.options
PREFIX
wifi_service
DEPS
pw_protobuf.common_protos
STRIP_PREFIX
${chip_dir}/examples/ipv6only-app/common/wifi_service
)

endif(matter_enable_rpc)

include(${prj_root}/GCC-RELEASE/project_hp/asdk/includepath.cmake)

if (matter_enable_rpc)
list(
APPEND ${list_chip_main_sources}
#rpc
${chip_dir}/examples/platform/ameba/PigweedLogger.cpp
${chip_dir}/examples/platform/ameba/Rpc.cpp
${chip_dir}/examples/common/pigweed/RpcService.cpp
${chip_dir}/examples/common/pigweed/ameba/PigweedLoggerMutex.cpp
)
endif (matter_enable_rpc)

list(
APPEND ${list_chip_main_sources}

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

if (matter_enable_rpc)
target_include_directories(
${chip_main}
PUBLIC
${inc_path}
#rpc
${chip_dir}/examples/platform/ameba
${chip_dir}/examples/platform/ameba/pw_sys_io/public
${chip_dir}/examples/common
${chip_dir}/examples/common/pigweed
${chip_dir}/examples/common/pigweed/ameba
${chip_dir}/src
${chip_dir}/src/lib/support
${pigweed_dir}/pw_rpc/nanopb/public
)
endif (matter_enable_rpc)

target_include_directories(
${chip_main}
PUBLIC
${inc_path}
${chip_dir}/zzz_generated/all-clusters-app
${chip_dir}/zzz_generated/all-clusters-app/zap-generated
${chip_dir}/zzz_generated/app-common
Expand All @@ -63,6 +181,30 @@ target_include_directories(
${chip_dir}/third_party/nlunit-test/repo/src
)

if (matter_enable_rpc)
target_link_libraries(${chip_main} PUBLIC
attributes_service.nanopb_rpc
button_service.nanopb_rpc
device_service.nanopb_rpc
lighting_service.nanopb_rpc
locking_service.nanopb_rpc
wifi_service.nanopb_rpc
pw_checksum
pw_hdlc
pw_log
pw_rpc.server
pw_trace_tokenized
pw_trace_tokenized.trace_buffer
pw_trace_tokenized.rpc_service
pw_trace_tokenized.protos.nanopb_rpc
PwRpc
)

link_directories(
${chip_dir_output}/lib
)
endif (matter_enable_rpc)

list(
APPEND chip_main_flags

Expand All @@ -74,6 +216,19 @@ list(
-DMBEDTLS_CONFIG_FILE=<mbedtls_config.h>
)

if (matter_enable_rpc)
list(
APPEND chip_main_flags

-DPW_RPC_ATTRIBUTE_SERVICE=1
-DPW_RPC_BUTTON_SERVICE=1
-DPW_RPC_DEVICE_SERVICE=1
-DPW_RPC_LIGHTING_SERVICE=1
-DPW_RPC_LOCKING_SERVICE=1
-DCONFIG_ENABLE_PW_RPC=1
)
endif (matter_enable_rpc)

list(
APPEND chip_main_cpp_flags

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

8 changes: 8 additions & 0 deletions examples/all-clusters-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <support/CHIPMem.h>

#if CONFIG_ENABLE_PW_RPC
#include "Rpc.h"
#endif

extern "C" {
void * __dso_handle = 0;
}
Expand Down Expand Up @@ -190,6 +194,10 @@ extern "C" void ChipTest(void)
ChipLogProgress(DeviceLayer, "All Clusters Demo!");
CHIP_ERROR err = CHIP_NO_ERROR;

#if CONFIG_ENABLE_PW_RPC
chip::rpc::Init();
#endif

initPref();

CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance();
Expand Down
27 changes: 27 additions & 0 deletions examples/common/pigweed/ameba/PigweedLoggerMutex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
*
* 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 "PigweedLoggerMutex.h"

namespace chip {
namespace rpc {

PigweedLoggerMutex logger_mutex;

} // namespace rpc
} // namespace chip
Loading

0 comments on commit 6e035c8

Please sign in to comment.