diff --git a/examples/chef/chef.py b/examples/chef/chef.py index 184df5e5c10428..3783596b04a1f2 100755 --- a/examples/chef/chef.py +++ b/examples/chef/chef.py @@ -771,7 +771,7 @@ def main() -> int: shell.run_cmd("make is") elif options.build_target == "telink": shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}/telink") - telink_build_cmds = ["west build"] + telink_build_cmds = ["west build -b tlsr9518adk80d"] if options.do_clean: telink_build_cmds.append("-p always") if options.do_rpc: diff --git a/examples/chef/telink/CMakeLists.txt b/examples/chef/telink/CMakeLists.txt index d52ce7446f12ed..7722f26a11d96e 100755 --- a/examples/chef/telink/CMakeLists.txt +++ b/examples/chef/telink/CMakeLists.txt @@ -15,8 +15,6 @@ # cmake_minimum_required(VERSION 3.13.1) -set(BOARD tlsr9518adk80d) - get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connectedhomeip REALPATH) get_filename_component(TELINK_COMMON ${CHIP_ROOT}/examples/platform/telink REALPATH) get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH) @@ -76,8 +74,10 @@ target_include_directories(app PRIVATE ${GEN_DIR}/../ ${CHIP_ROOT}/src ${CHEF}/shell_common/include + ${CHEF}/telink/include ${TELINK_COMMON}/common/include ${TELINK_COMMON}/util/include + ${TELINK_COMMON}/app/include ) if (CONFIG_CHIP_LIB_SHELL) @@ -97,7 +97,12 @@ add_definitions( ) target_sources(app PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp + src/AppTask.cpp + ${TELINK_COMMON}/common/src/mainCommon.cpp + ${TELINK_COMMON}/common/src/AppTaskCommon.cpp + ${TELINK_COMMON}/util/src/PWMDevice.cpp + ${TELINK_COMMON}/util/src/ButtonManager.cpp + ${TELINK_COMMON}/util/src/ThreadUtil.cpp ${CHEF}/common/stubs.cpp ) diff --git a/examples/chef/telink/include/AppConfig.h b/examples/chef/telink/include/AppConfig.h new file mode 100644 index 00000000000000..e5c7b0417ef160 --- /dev/null +++ b/examples/chef/telink/include/AppConfig.h @@ -0,0 +1,28 @@ +/* + * + * Copyright (c) 2023 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 + +// ---- Chef Example App Config ---- + +#define APP_USE_EXAMPLE_START_BUTTON 0 +#define APP_USE_BLE_START_BUTTON 1 +#define APP_USE_THREAD_START_BUTTON 1 +#define APP_SET_DEVICE_INFO_PROVIDER 1 +#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0 +#define APP_USE_IDENTIFY_PWM 0 diff --git a/examples/chef/telink/include/AppTask.h b/examples/chef/telink/include/AppTask.h new file mode 100644 index 00000000000000..3b91e9a3733786 --- /dev/null +++ b/examples/chef/telink/include/AppTask.h @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2023 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 "AppTaskCommon.h" + +class AppTask : public AppTaskCommon +{ +public: +private: + friend AppTask & GetAppTask(void); + friend class AppTaskCommon; + + CHIP_ERROR Init(void); + + static AppTask sAppTask; +}; + +inline AppTask & GetAppTask(void) +{ + return AppTask::sAppTask; +} diff --git a/examples/chef/telink/main.cpp b/examples/chef/telink/main.cpp deleted file mode 100644 index 088dd22a481063..00000000000000 --- a/examples/chef/telink/main.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * - * Copyright (c) 2023 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 - -#include - -#include "platform/CHIPDeviceLayer.h" -#include - -#include -#include - -#include -#include - -#if CONFIG_ENABLE_CHIP_SHELL || CONFIG_CHIP_LIB_SHELL -#include -#endif - -#ifdef CONFIG_ENABLE_PW_RPC -#include "Rpc.h" -#endif - -LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL); - -using namespace chip; -using namespace chip::Shell; -using namespace chip::DeviceLayer; - -int main() -{ - CHIP_ERROR err = CHIP_NO_ERROR; - -#ifdef CONFIG_ENABLE_PW_RPC - rpc::Init(); -#endif - err = chip::Platform::MemoryInit(); - if (err != CHIP_NO_ERROR) - { - ChipLogError(AppServer, "Platform::MemoryInit() failed"); - return 1; - } - err = PlatformMgr().InitChipStack(); - if (err != CHIP_NO_ERROR) - { - ChipLogError(AppServer, "PlatformMgr().InitChipStack() failed"); - return 1; - } - - // Network connectivity -#if CHIP_DEVICE_CONFIG_ENABLE_WPA - ConnectivityManagerImpl().StartWiFiManagement(); -#endif - -#if defined(CHIP_ENABLE_OPENTHREAD) - err = ThreadStackMgr().InitThreadStack(); - if (err != CHIP_NO_ERROR) - { - ChipLogError(AppServer, "ThreadStackMgr().InitThreadStack() failed"); - return 1; - } - -#if defined(CONFIG_CHIP_THREAD_DEVICE_ROLE_ROUTER) - err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router); -#elif defined(CONFIG_CHIP_THREAD_DEVICE_ROLE_END_DEVICE) - err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice); -#elif defined(CONFIG_CHIP_THREAD_DEVICE_ROLE_SLEEPY_END_DEVICE) - err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice); -#else -#error THREAD_DEVICE_ROLE not selected -#endif - if (err != CHIP_NO_ERROR) - { - ChipLogError(AppServer, "ConnectivityMgr().SetThreadDeviceType() failed"); - return 1; - } -#endif - - // Device Attestation & Onboarding codes - chip::Credentials::SetDeviceAttestationCredentialsProvider(chip::Credentials::Examples::GetExampleDACProvider()); -#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY - chip::app::DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(kExtDiscoveryTimeoutSecs); -#endif /* CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY */ - - // Start IM server - static chip::CommonCaseDeviceServerInitParams initParams; - (void) initParams.InitializeStaticResourcesBeforeServerInit(); - err = chip::Server::GetInstance().Init(initParams); - if (err != CHIP_NO_ERROR) - { - return 1; - } - - chip::DeviceLayer::ConfigurationMgr().LogDeviceConfig(); - - err = chip::DeviceLayer::PlatformMgr().StartEventLoopTask(); - if (err != CHIP_NO_ERROR) - { - ChipLogError(AppServer, "PlatformMgr().StartEventLoopTask() failed"); - } - - // When SoftAP support becomes available, it should be added here. -#if CONFIG_NETWORK_LAYER_BLE - PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE)); -#else - PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kOnNetwork)); -#endif /* CONFIG_NETWORK_LAYER_BLE */ - - // Starts commissioning window automatically. Starts BLE advertising when BLE enabled - if (chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() != CHIP_NO_ERROR) - { - ChipLogError(AppServer, "OpenBasicCommissioningWindow() failed"); - } - -#if CONFIG_CHIP_LIB_SHELL - int rc = Engine::Root().Init(); - if (rc != 0) - { - ChipLogError(AppServer, "Streamer initialization failed: %d", rc); - return 1; - } - - cmd_misc_init(); - cmd_otcli_init(); -#endif - -#if CHIP_SHELL_ENABLE_CMD_SERVER - cmd_app_server_init(); -#endif - -#if CONFIG_CHIP_LIB_SHELL - Engine::Root().RunMainLoop(); -#endif - - return 0; -} diff --git a/examples/chef/telink/prj.conf b/examples/chef/telink/prj.conf index b5986b7d07a5bc..9b99b6a3fcc40c 100755 --- a/examples/chef/telink/prj.conf +++ b/examples/chef/telink/prj.conf @@ -55,3 +55,5 @@ CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE=n # Enable Power Management CONFIG_PM=n + +CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED=n diff --git a/examples/chef/telink/src/AppTask.cpp b/examples/chef/telink/src/AppTask.cpp new file mode 100644 index 00000000000000..a9683f0d8c3610 --- /dev/null +++ b/examples/chef/telink/src/AppTask.cpp @@ -0,0 +1,51 @@ +/* + * + * Copyright (c) 2023 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 + +LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL); + +AppTask AppTask::sAppTask; + +CHIP_ERROR AppTask::Init(void) +{ + InitCommonParts(); + +#if CONFIG_CHIP_LIB_SHELL + int rc = Engine::Root().Init(); + if (rc != 0) + { + ChipLogError(AppServer, "Streamer initialization failed: %d", rc); + return 1; + } + + cmd_misc_init(); + cmd_otcli_init(); +#endif + +#if CHIP_SHELL_ENABLE_CMD_SERVER + cmd_app_server_init(); +#endif + +#if CONFIG_CHIP_LIB_SHELL + Engine::Root().RunMainLoop(); +#endif + + return CHIP_NO_ERROR; +} diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 41899c8a1f9c73..0731410dfe07da 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -351,9 +351,11 @@ void AppTaskCommon::ButtonEventHandler(ButtonId_t btnId, bool btnPressed) switch (btnId) { +#if APP_USE_EXAMPLE_START_BUTTON case kButtonId_ExampleAction: ExampleActionButtonEventHandler(); break; +#endif case kButtonId_FactoryReset: FactoryResetButtonEventHandler(); break;