Skip to content

Commit

Permalink
[Telink] Use common main & apptask for chef app (#29995)
Browse files Browse the repository at this point in the history
* [Telink][Chef] Add common file structure for Chef app

Signed-off-by: Dima Horbenko <[email protected]>

* Clean-up code

Signed-off-by: Dima Horbenko <[email protected]>

* Restyled by clang-format

* Add board to build command

Signed-off-by: Dima Horbenko <[email protected]>

* Fix build issue

Signed-off-by: Dima Horbenko <[email protected]>

---------

Signed-off-by: Dima Horbenko <[email protected]>
Co-authored-by: Dima Horbenko <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Dima Horbenko <[email protected]>
  • Loading branch information
4 people authored and pull[bot] committed Feb 5, 2024
1 parent 87cd1e1 commit af39cfe
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 156 deletions.
2 changes: 1 addition & 1 deletion examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions examples/chef/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
)

Expand Down
28 changes: 28 additions & 0 deletions examples/chef/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions examples/chef/telink/include/AppTask.h
Original file line number Diff line number Diff line change
@@ -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;
}
152 changes: 0 additions & 152 deletions examples/chef/telink/main.cpp

This file was deleted.

2 changes: 2 additions & 0 deletions examples/chef/telink/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE=n

# Enable Power Management
CONFIG_PM=n

CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED=n
51 changes: 51 additions & 0 deletions examples/chef/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
@@ -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 <app/server/Server.h>

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;
}
2 changes: 2 additions & 0 deletions examples/platform/telink/common/src/AppTaskCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit af39cfe

Please sign in to comment.