Skip to content

Commit 23b2fb2

Browse files
committed
subsys: add Kconfig for default boot protocol
Let combined builds choose Zigbee or Matter as the initial protocol when no persisted settings entry exists yet. Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
1 parent 16fae6c commit 23b2fb2

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

include/zigbee/matter_protocol_state.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
* @brief Persistent "which protocol is active" state for samples that host
1515
* both Matter and Zigbee on the same 802.15.4 radio.
1616
*
17-
* The application boots on Zigbee by default. Once Matter commissioning
18-
* completes, the state flips to Matter and is persisted so that subsequent
19-
* reboots resume Matter directly (and Zigbee stack initialization is skipped).
20-
* A factory reset resets the state back to Zigbee.
17+
* The default protocol on first boot is selected by Kconfig (see
18+
* @kconfig{CONFIG_ZIGBEE_MATTER_PROTOCOL_STATE_DEFAULT_PROTOCOL}). Once Matter
19+
* commissioning completes, the state flips to Matter and is persisted so that
20+
* subsequent reboots resume Matter directly (and Zigbee stack initialization
21+
* is skipped). A factory reset resets the state back to Zigbee.
2122
*/
2223

2324
#include <stdbool.h>

subsys/lib/zigbee_matter_protocol_state/Kconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,28 @@ menuconfig ZIGBEE_MATTER_PROTOCOL_STATE
1515

1616
if ZIGBEE_MATTER_PROTOCOL_STATE
1717

18+
choice ZIGBEE_MATTER_PROTOCOL_STATE_DEFAULT_PROTOCOL
19+
prompt "Default protocol on first boot"
20+
default ZIGBEE_MATTER_PROTOCOL_STATE_DEFAULT_ZIGBEE
21+
help
22+
Applied when no protocol state has been stored yet (factory-fresh
23+
device or after the settings entry was erased). Subsequent boots use
24+
the persisted value.
25+
26+
config ZIGBEE_MATTER_PROTOCOL_STATE_DEFAULT_ZIGBEE
27+
bool "Zigbee"
28+
help
29+
Start on Zigbee: bring up the Zigbee stack and hand the 802.15.4
30+
radio to ZBOSS unless a previous run already persisted Matter.
31+
32+
config ZIGBEE_MATTER_PROTOCOL_STATE_DEFAULT_MATTER
33+
bool "Matter"
34+
help
35+
Start on Matter: skip Zigbee stack start and hand the 802.15.4 radio
36+
to OpenThread unless a previous run already persisted Zigbee.
37+
38+
endchoice
39+
1840
module = ZIGBEE_MATTER_PROTOCOL_STATE
1941
module-str = Matter/Zigbee protocol state
2042
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"

subsys/lib/zigbee_matter_protocol_state/matter_protocol_state.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ LOG_MODULE_REGISTER(matter_protocol_state, CONFIG_ZIGBEE_MATTER_PROTOCOL_STATE_L
1919

2020
static atomic_t active_protocol = ATOMIC_INIT(PROTOCOL_ZIGBEE);
2121
static atomic_t state_initialized = ATOMIC_INIT(0);
22+
static bool protocol_loaded_from_settings;
2223
static K_MUTEX_DEFINE(init_mutex);
2324

2425
static int protocol_state_load_direct_cb(const char *key, size_t len,
@@ -51,6 +52,7 @@ static int protocol_state_load_direct_cb(const char *key, size_t len,
5152
return 0;
5253
}
5354

55+
protocol_loaded_from_settings = true;
5456
atomic_set(&active_protocol, (atomic_val_t)value);
5557
return 0;
5658
}
@@ -79,6 +81,14 @@ int protocol_state_init(void)
7981
(void)settings_load_subtree_direct(ZIGBEE_SETTINGS_SUBSYS_NAME,
8082
protocol_state_load_direct_cb, NULL);
8183

84+
if (!protocol_loaded_from_settings) {
85+
#if IS_ENABLED(CONFIG_ZIGBEE_MATTER_PROTOCOL_STATE_DEFAULT_MATTER)
86+
atomic_set(&active_protocol, PROTOCOL_MATTER);
87+
#else
88+
atomic_set(&active_protocol, PROTOCOL_ZIGBEE);
89+
#endif
90+
}
91+
8292
atomic_set(&state_initialized, 1);
8393

8494
LOG_INF("Boot protocol: %s",

0 commit comments

Comments
 (0)