From 6772bbb10d1995f3ee9ffa6bb7124ed114b5af38 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Wed, 21 Jun 2023 17:48:03 +0300 Subject: [PATCH] [Telink] Add RPC for ligt-switch app (#27381) --- .../light-switch-app/telink/CMakeLists.txt | 154 ++++++++++++++++++ examples/light-switch-app/telink/rpc.overlay | 47 ++++++ .../lighting-app/telink/include/AppTask.h | 18 -- examples/lighting-app/telink/src/AppTask.cpp | 26 --- .../telink/common/include/AppTaskCommon.h | 19 +++ .../telink/common/src/AppTaskCommon.cpp | 26 +++ 6 files changed, 246 insertions(+), 44 deletions(-) create mode 100644 examples/light-switch-app/telink/rpc.overlay diff --git a/examples/light-switch-app/telink/CMakeLists.txt b/examples/light-switch-app/telink/CMakeLists.txt index c7339e9f81b623..18a5f83ac1ebbf 100755 --- a/examples/light-switch-app/telink/CMakeLists.txt +++ b/examples/light-switch-app/telink/CMakeLists.txt @@ -86,3 +86,157 @@ chip_configure_data_model(app if(CONFIG_CHIP_OTA_REQUESTOR) target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) endif() + +# Fix for unused swap parameter in: zephyr/include/zephyr/arch/riscv/irq.h:70 +add_compile_options(-Wno-error=unused-parameter) + +if (CONFIG_CHIP_PW_RPC) + +# Make all targets created below depend on zephyr_interface to inherit MCU-related compilation flags +link_libraries($) + +set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo") +include(${PIGWEED_ROOT}/pw_build/pigweed.cmake) +include(${PIGWEED_ROOT}/pw_protobuf_compiler/proto.cmake) + +include($ENV{PW_ROOT}/pw_assert/backend.cmake) +include($ENV{PW_ROOT}/pw_log/backend.cmake) +include($ENV{PW_ROOT}/pw_sys_io/backend.cmake) + +pw_set_module_config(pw_rpc_CONFIG pw_rpc.disable_global_mutex_config) +pw_set_backend(pw_log pw_log_basic) +pw_set_backend(pw_assert.check pw_assert_log.check_backend) +pw_set_backend(pw_assert.assert pw_assert.assert_compatibility_backend) +pw_set_backend(pw_sys_io pw_sys_io.telink) + +set(dir_pw_third_party_nanopb "${CHIP_ROOT}/third_party/nanopb/repo" CACHE STRING "" FORCE) + +add_subdirectory(third_party/connectedhomeip/third_party/pigweed/repo) +add_subdirectory(third_party/connectedhomeip/third_party/nanopb/repo) +add_subdirectory(third_party/connectedhomeip/examples/platform/telink/pw_sys_io) + +pw_proto_library(attributes_service + SOURCES + ${CHIP_ROOT}/examples/common/pigweed/protos/attributes_service.proto + INPUTS + ${CHIP_ROOT}/examples/common/pigweed/protos/attributes_service.options + PREFIX + attributes_service + STRIP_PREFIX + ${CHIP_ROOT}/examples/common/pigweed/protos + DEPS + pw_protobuf.common_proto +) + +pw_proto_library(button_service + SOURCES + ${CHIP_ROOT}/examples/common/pigweed/protos/button_service.proto + PREFIX + button_service + STRIP_PREFIX + ${CHIP_ROOT}/examples/common/pigweed/protos + DEPS + pw_protobuf.common_proto +) + +pw_proto_library(descriptor_service + SOURCES + ${CHIP_ROOT}/examples/common/pigweed/protos/descriptor_service.proto + PREFIX + descriptor_service + STRIP_PREFIX + ${CHIP_ROOT}/examples/common/pigweed/protos + DEPS + pw_protobuf.common_proto +) + +pw_proto_library(device_service + SOURCES + ${CHIP_ROOT}/examples/common/pigweed/protos/device_service.proto + INPUTS + ${CHIP_ROOT}/examples/common/pigweed/protos/device_service.options + PREFIX + device_service + STRIP_PREFIX + ${CHIP_ROOT}/examples/common/pigweed/protos + DEPS + pw_protobuf.common_proto +) + +pw_proto_library(lighting_service + SOURCES + ${CHIP_ROOT}/examples/common/pigweed/protos/lighting_service.proto + STRIP_PREFIX + ${CHIP_ROOT}/examples/common/pigweed/protos + PREFIX + lighting_service + DEPS + pw_protobuf.common_proto +) + +pw_proto_library(ot_cli_service + SOURCES + ${CHIP_ROOT}/examples/common/pigweed/protos/ot_cli_service.proto + INPUTS + ${CHIP_ROOT}/examples/common/pigweed/protos/ot_cli_service.options + STRIP_PREFIX + ${CHIP_ROOT}/examples/common/pigweed/protos + PREFIX + ot_cli_service + DEPS + pw_protobuf.common_proto +) + +pw_proto_library(thread_service + SOURCES + ${CHIP_ROOT}/examples/common/pigweed/protos/thread_service.proto + INPUTS + ${CHIP_ROOT}/examples/common/pigweed/protos/thread_service.options + STRIP_PREFIX + ${CHIP_ROOT}/examples/common/pigweed/protos + PREFIX + thread_service + DEPS + pw_protobuf.common_proto +) + +target_sources(app PRIVATE + ../../common/pigweed/RpcService.cpp + ../../common/pigweed/telink/PigweedLoggerMutex.cpp + ${TELINK_COMMON}/Rpc.cpp + ${TELINK_COMMON}/util/src/PigweedLogger.cpp +) + +target_include_directories(app PRIVATE + ${PIGWEED_ROOT}/pw_sys_io/public + ${CHIP_ROOT}/src/lib/support + ${CHIP_ROOT}/src/system + ${TELINK_COMMON} + ../../common + ../../common/pigweed + ../../common/pigweed/telink) + +target_compile_options(app PRIVATE + "-DPW_RPC_ATTRIBUTE_SERVICE=1" + "-DPW_RPC_BUTTON_SERVICE=1" + "-DPW_RPC_DESCRIPTOR_SERVICE=1" + "-DPW_RPC_DEVICE_SERVICE=1" + "-DPW_RPC_LIGHTING_SERVICE=1" + "-DPW_RPC_THREAD_SERVICE=1") + +target_link_libraries(app PRIVATE + attributes_service.nanopb_rpc + button_service.nanopb_rpc + descriptor_service.nanopb_rpc + device_service.nanopb_rpc + lighting_service.nanopb_rpc + thread_service.nanopb_rpc + pw_checksum + pw_hdlc + pw_hdlc.pw_rpc + pw_log + pw_rpc.server + pw_sys_io +) + +endif(CONFIG_CHIP_PW_RPC) diff --git a/examples/light-switch-app/telink/rpc.overlay b/examples/light-switch-app/telink/rpc.overlay new file mode 100644 index 00000000000000..017c76b54c4e24 --- /dev/null +++ b/examples/light-switch-app/telink/rpc.overlay @@ -0,0 +1,47 @@ +# +# Copyright (c) 2023 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 file should be used as a configuration overlay to build Pigweed RPCs to +# light-switch-app. + +# Enable Pigweed RPC +CONFIG_CHIP_PW_RPC=y + +# Add support for C++17 to build Pigweed components +CONFIG_STD_CPP14=n +CONFIG_STD_CPP17=y + +# Add support for Zephyr console component to use it for Pigweed console purposes +CONFIG_CONSOLE_SUBSYS=y +CONFIG_CONSOLE_GETCHAR=y +CONFIG_CONSOLE_PUTCHAR_BUFSIZE=256 + +# Disable features which may interfere with Pigweed HDLC transport +CONFIG_SHELL=n +CONFIG_OPENTHREAD_SHELL=n +CONFIG_BOOT_BANNER=n + +# Configure Zephyr logger with defaults backends disabled as the app provides its own, +# based on Pigweed HDLC. +CONFIG_LOG=y +CONFIG_LOG_MODE_MINIMAL=n +CONFIG_LOG_MODE_IMMEDIATE=y +CONFIG_LOG_BACKEND_UART=n +CONFIG_LOG_BACKEND_RTT=n +CONFIG_LOG_OUTPUT=y + +# Increase zephyr tty rx buffer +CONFIG_CONSOLE_GETCHAR_BUFSIZE=128 diff --git a/examples/lighting-app/telink/include/AppTask.h b/examples/lighting-app/telink/include/AppTask.h index 7157b5a9d3601d..f1085763e74086 100644 --- a/examples/lighting-app/telink/include/AppTask.h +++ b/examples/lighting-app/telink/include/AppTask.h @@ -20,10 +20,6 @@ #include "AppTaskCommon.h" -#ifdef CONFIG_CHIP_PW_RPC -#include "Rpc.h" -#endif - class AppTask : public AppTaskCommon { public: @@ -31,21 +27,7 @@ class AppTask : public AppTaskCommon void UpdateClusterState(void); PWMDevice & GetPWMDevice(void) { return mPwmRgbBlueLed; } -#ifdef CONFIG_CHIP_PW_RPC - enum ButtonId_t - { - kButtonId_LightingAction = 1, - kButtonId_FactoryReset, - kButtonId_StartThread, - kButtonId_StartBleAdv - } ButtonId; -#endif - private: -#ifdef CONFIG_CHIP_PW_RPC - friend class chip::rpc::TelinkButton; - static void ButtonEventHandler(ButtonId_t btnId, bool btnPressed); -#endif friend AppTask & GetAppTask(void); friend class AppTaskCommon; diff --git a/examples/lighting-app/telink/src/AppTask.cpp b/examples/lighting-app/telink/src/AppTask.cpp index 6bee2963f81696..f875086b9d59c7 100644 --- a/examples/lighting-app/telink/src/AppTask.cpp +++ b/examples/lighting-app/telink/src/AppTask.cpp @@ -127,32 +127,6 @@ void AppTask::LightingActionEventHandler(AppEvent * aEvent) } } -#ifdef CONFIG_CHIP_PW_RPC -void AppTask::ButtonEventHandler(ButtonId_t btnId, bool btnPressed) -{ - if (!btnPressed) - { - return; - } - - switch (btnId) - { - case kButtonId_LightingAction: - ExampleActionButtonEventHandler(); - break; - case kButtonId_FactoryReset: - FactoryResetButtonEventHandler(); - break; - case kButtonId_StartThread: - StartThreadButtonEventHandler(); - break; - case kButtonId_StartBleAdv: - StartBleAdvButtonEventHandler(); - break; - } -} -#endif - void AppTask::ActionInitiated(PWMDevice::Action_t aAction, int32_t aActor) { if (aAction == PWMDevice::ON_ACTION) diff --git a/examples/platform/telink/common/include/AppTaskCommon.h b/examples/platform/telink/common/include/AppTaskCommon.h index 97b87f0d3e300d..fe1c400b22c448 100644 --- a/examples/platform/telink/common/include/AppTaskCommon.h +++ b/examples/platform/telink/common/include/AppTaskCommon.h @@ -39,6 +39,10 @@ #include #endif +#ifdef CONFIG_CHIP_PW_RPC +#include "Rpc.h" +#endif + #include #include @@ -64,6 +68,16 @@ class AppTaskCommon static void IdentifyEffectHandler(Clusters::Identify::EffectIdentifierEnum aEffect); +#ifdef CONFIG_CHIP_PW_RPC + enum ButtonId_t + { + kButtonId_ExampleAction = 1, + kButtonId_FactoryReset, + kButtonId_StartThread, + kButtonId_StartBleAdv + } ButtonId; +#endif + protected: CHIP_ERROR InitCommonParts(void); @@ -110,4 +124,9 @@ class AppTaskCommon #if CONFIG_CHIP_FACTORY_DATA chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; #endif + +#ifdef CONFIG_CHIP_PW_RPC + friend class chip::rpc::TelinkButton; + static void ButtonEventHandler(ButtonId_t btnId, bool btnPressed); +#endif }; diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index aa9b38bb7fdeb4..263f094b440ab4 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -342,6 +342,32 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void) return CHIP_NO_ERROR; } +#ifdef CONFIG_CHIP_PW_RPC +void AppTaskCommon::ButtonEventHandler(ButtonId_t btnId, bool btnPressed) +{ + if (!btnPressed) + { + return; + } + + switch (btnId) + { + case kButtonId_ExampleAction: + ExampleActionButtonEventHandler(); + break; + case kButtonId_FactoryReset: + FactoryResetButtonEventHandler(); + break; + case kButtonId_StartThread: + StartThreadButtonEventHandler(); + break; + case kButtonId_StartBleAdv: + StartBleAdvButtonEventHandler(); + break; + } +} +#endif + void AppTaskCommon::InitButtons(void) { #if CONFIG_CHIP_BUTTON_MANAGER_IRQ_MODE