Skip to content

Commit efb04fb

Browse files
modules: button: channel definition into module header
Button channel definition into dedicated button header. Signed-off-by: Giacomo Dematteis <giacomo.dematteis@nordicsemi.no>
1 parent bea970c commit efb04fb

File tree

11 files changed

+49
-9
lines changed

11 files changed

+49
-9
lines changed

app/src/common/message_channel.c

-8
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@ ZBUS_CHAN_DEFINE(CONFIG_CHAN,
5858
ZBUS_MSG_INIT(0)
5959
);
6060

61-
ZBUS_CHAN_DEFINE(BUTTON_CHAN,
62-
uint8_t,
63-
NULL,
64-
NULL,
65-
ZBUS_OBSERVERS_EMPTY,
66-
ZBUS_MSG_INIT(0)
67-
);
68-
6961
ZBUS_CHAN_DEFINE(TIME_CHAN,
7062
enum time_status,
7163
NULL,

app/src/common/message_channel.h

-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ struct configuration {
247247
#define MSG_TO_CONFIGURATION(_msg) ((const struct configuration *)_msg)
248248

249249
ZBUS_CHAN_DECLARE(
250-
BUTTON_CHAN,
251250
CONFIG_CHAN,
252251
ERROR_CHAN,
253252
FOTA_STATUS_CHAN,

app/src/modules/app/app.c

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "modules_common.h"
1515
#include "message_channel.h"
1616
#include "battery.h"
17+
#include "button.h"
1718

1819
/* Register log module */
1920
LOG_MODULE_REGISTER(app, CONFIG_APP_LOG_LEVEL);

app/src/modules/button/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
#
66

77
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/button.c)
8+
target_include_directories(app PRIVATE .)

app/src/modules/button/button.c

+10
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,20 @@
1212

1313
#include "message_channel.h"
1414
#include "battery.h"
15+
#include "button.h"
1516

1617
/* Register log module */
1718
LOG_MODULE_REGISTER(button, CONFIG_APP_BUTTON_LOG_LEVEL);
1819

20+
/* Define channels provided by this module */
21+
ZBUS_CHAN_DEFINE(BUTTON_CHAN,
22+
uint8_t,
23+
NULL,
24+
NULL,
25+
ZBUS_OBSERVERS_EMPTY,
26+
ZBUS_MSG_INIT(0)
27+
);
28+
1929
/* Button handler called when a user pushes a button */
2030
static void button_handler(uint32_t button_states, uint32_t has_changed)
2131
{

app/src/modules/button/button.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef _BUTTON_H_
8+
#define _BUTTON_H_
9+
10+
#include <zephyr/kernel.h>
11+
#include <zephyr/zbus/zbus.h>
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
/* Channels provided by this module */
18+
ZBUS_CHAN_DECLARE(
19+
BUTTON_CHAN
20+
);
21+
22+
#ifdef __cplusplus
23+
}
24+
#endif
25+
26+
#endif /* _BUTTON_H_ */

app/src/modules/shell/shell.c

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <net/nrf_cloud_defs.h>
2222

2323
#include "message_channel.h"
24+
#include "button.h"
2425

2526
LOG_MODULE_REGISTER(shell, CONFIG_APP_SHELL_LOG_LEVEL);
2627

tests/module/app/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ zephyr_include_directories(../../../app/src/common)
2828
zephyr_include_directories(../../../app/src/modules/cloud)
2929
zephyr_include_directories(${NRF_DIR}/subsys/net/lib/nrf_cloud/include)
3030
zephyr_include_directories(../../../app/src/modules/battery)
31+
zephyr_include_directories(../../../app/src/modules/button)
3132
zephyr_include_directories(${NRF_DIR}/../modules/lib/cjson)
3233

3334
target_link_options(app PRIVATE --whole-archive)

tests/module/app/src/main.c

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ ZBUS_CHAN_DEFINE(BATTERY_CHAN,
2525
ZBUS_OBSERVERS_EMPTY,
2626
ZBUS_MSG_INIT(0)
2727
);
28+
ZBUS_CHAN_DEFINE(BUTTON_CHAN,
29+
struct battery_msg,
30+
NULL,
31+
NULL,
32+
ZBUS_OBSERVERS_EMPTY,
33+
ZBUS_MSG_INIT(0)
34+
);
2835

2936
DEFINE_FFF_GLOBALS;
3037

tests/module/button/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ zephyr_include_directories(${ZEPHYR_BASE}/subsys/testsuite/include)
2323
zephyr_include_directories(../../../app/src/common)
2424
zephyr_include_directories(../../../app/src/modules/cloud)
2525
zephyr_include_directories(../../../app/src/modules/battery)
26+
zephyr_include_directories(../../../app/src/modules/button)
2627

2728
target_link_options(app PRIVATE --whole-archive)
2829
# Options that cannot be passed through Kconfig fragments

tests/module/button/src/main.c

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "message_channel.h"
1313
#include "battery.h"
14+
#include "button.h"
1415

1516
#include <dk_buttons_and_leds.h>
1617
#include <date_time.h>

0 commit comments

Comments
 (0)