Skip to content

Commit 5319505

Browse files
s07641069dima-horbenko-telinkrestyled-commits
authored andcommitted
[Telink] Use common main & apptask for chef app (#29995)
* [Telink][Chef] Add common file structure for Chef app Signed-off-by: Dima Horbenko <dima.horbenko@telink-semi.com> * Clean-up code Signed-off-by: Dima Horbenko <dima.horbenko@telink-semi.com> * Restyled by clang-format * Add board to build command Signed-off-by: Dima Horbenko <dima.horbenko@telink-semi.com> * Fix build issue Signed-off-by: Dima Horbenko <dima.horbenko@telink-semi.com> --------- Signed-off-by: Dima Horbenko <dima.horbenko@telink-semi.com> Co-authored-by: Dima Horbenko <dima.horbenko@telink-semi.com> Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Dima Horbenko <138576027+dima-horbenko-telink@users.noreply.github.com>
1 parent 6ed5e44 commit 5319505

File tree

8 files changed

+130
-156
lines changed

8 files changed

+130
-156
lines changed

examples/chef/chef.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ def main() -> int:
771771
shell.run_cmd("make is")
772772
elif options.build_target == "telink":
773773
shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}/telink")
774-
telink_build_cmds = ["west build"]
774+
telink_build_cmds = ["west build -b tlsr9518adk80d"]
775775
if options.do_clean:
776776
telink_build_cmds.append("-p always")
777777
if options.do_rpc:

examples/chef/telink/CMakeLists.txt

+8-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#
1616
cmake_minimum_required(VERSION 3.13.1)
1717

18-
set(BOARD tlsr9518adk80d)
19-
2018
get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connectedhomeip REALPATH)
2119
get_filename_component(TELINK_COMMON ${CHIP_ROOT}/examples/platform/telink REALPATH)
2220
get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH)
@@ -76,8 +74,10 @@ target_include_directories(app PRIVATE
7674
${GEN_DIR}/../
7775
${CHIP_ROOT}/src
7876
${CHEF}/shell_common/include
77+
${CHEF}/telink/include
7978
${TELINK_COMMON}/common/include
8079
${TELINK_COMMON}/util/include
80+
${TELINK_COMMON}/app/include
8181
)
8282

8383
if (CONFIG_CHIP_LIB_SHELL)
@@ -97,7 +97,12 @@ add_definitions(
9797
)
9898

9999
target_sources(app PRIVATE
100-
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
100+
src/AppTask.cpp
101+
${TELINK_COMMON}/common/src/mainCommon.cpp
102+
${TELINK_COMMON}/common/src/AppTaskCommon.cpp
103+
${TELINK_COMMON}/util/src/PWMDevice.cpp
104+
${TELINK_COMMON}/util/src/ButtonManager.cpp
105+
${TELINK_COMMON}/util/src/ThreadUtil.cpp
101106
${CHEF}/common/stubs.cpp
102107
)
103108

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 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+
#pragma once
20+
21+
// ---- Chef Example App Config ----
22+
23+
#define APP_USE_EXAMPLE_START_BUTTON 0
24+
#define APP_USE_BLE_START_BUTTON 1
25+
#define APP_USE_THREAD_START_BUTTON 1
26+
#define APP_SET_DEVICE_INFO_PROVIDER 1
27+
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0
28+
#define APP_USE_IDENTIFY_PWM 0
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 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+
#pragma once
20+
21+
#include "AppTaskCommon.h"
22+
23+
class AppTask : public AppTaskCommon
24+
{
25+
public:
26+
private:
27+
friend AppTask & GetAppTask(void);
28+
friend class AppTaskCommon;
29+
30+
CHIP_ERROR Init(void);
31+
32+
static AppTask sAppTask;
33+
};
34+
35+
inline AppTask & GetAppTask(void)
36+
{
37+
return AppTask::sAppTask;
38+
}

examples/chef/telink/main.cpp

-152
This file was deleted.

examples/chef/telink/prj.conf

+2
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,5 @@ CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE=n
5555

5656
# Enable Power Management
5757
CONFIG_PM=n
58+
59+
CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED=n

examples/chef/telink/src/AppTask.cpp

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 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 "AppTask.h"
20+
#include <app/server/Server.h>
21+
22+
LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL);
23+
24+
AppTask AppTask::sAppTask;
25+
26+
CHIP_ERROR AppTask::Init(void)
27+
{
28+
InitCommonParts();
29+
30+
#if CONFIG_CHIP_LIB_SHELL
31+
int rc = Engine::Root().Init();
32+
if (rc != 0)
33+
{
34+
ChipLogError(AppServer, "Streamer initialization failed: %d", rc);
35+
return 1;
36+
}
37+
38+
cmd_misc_init();
39+
cmd_otcli_init();
40+
#endif
41+
42+
#if CHIP_SHELL_ENABLE_CMD_SERVER
43+
cmd_app_server_init();
44+
#endif
45+
46+
#if CONFIG_CHIP_LIB_SHELL
47+
Engine::Root().RunMainLoop();
48+
#endif
49+
50+
return CHIP_NO_ERROR;
51+
}

examples/platform/telink/common/src/AppTaskCommon.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,11 @@ void AppTaskCommon::ButtonEventHandler(ButtonId_t btnId, bool btnPressed)
351351

352352
switch (btnId)
353353
{
354+
#if APP_USE_EXAMPLE_START_BUTTON
354355
case kButtonId_ExampleAction:
355356
ExampleActionButtonEventHandler();
356357
break;
358+
#endif
357359
case kButtonId_FactoryReset:
358360
FactoryResetButtonEventHandler();
359361
break;

0 commit comments

Comments
 (0)