-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathmatter_protocol_state.h
More file actions
87 lines (74 loc) · 2.28 KB
/
matter_protocol_state.h
File metadata and controls
87 lines (74 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright (c) 2026 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#ifndef ZIGBEE_MATTER_PROTOCOL_STATE_H_
#define ZIGBEE_MATTER_PROTOCOL_STATE_H_
/** @file
* @defgroup zigbee_matter_protocol_state Combined Matter + Zigbee protocol state
* @{
*
* @brief Persistent "which protocol is active" state for samples that host
* both Matter and Zigbee on the same 802.15.4 radio.
*
* The default protocol on first boot is selected by Kconfig (see
* @kconfig{CONFIG_ZIGBEE_MATTER_PROTOCOL_STATE_DEFAULT_PROTOCOL}). Once Matter
* commissioning completes, the state flips to Matter and is persisted so that
* subsequent reboots resume Matter directly (and Zigbee stack initialization
* is skipped). A factory reset resets the state back to Zigbee.
*/
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
PROTOCOL_ZIGBEE,
PROTOCOL_MATTER
} active_protocol_t;
/**
* @brief Load the persisted protocol state from non-volatile storage.
*
* Must be called once before the protocol dispatch logic runs. Safe to call
* from multiple contexts; internal state is guarded and the underlying
* settings subsystem is initialized at most once.
*
* @retval 0 on success (state loaded or default applied)
* @retval <0 negative errno on unrecoverable storage failure
*/
int protocol_state_init(void);
/**
* @brief Get the currently active protocol.
* @return PROTOCOL_ZIGBEE or PROTOCOL_MATTER
*/
active_protocol_t protocol_state_get(void);
/**
* @brief Set and persist the active protocol.
*
* Updates the in-RAM state and writes it to non-volatile storage so that the
* application resumes with the same protocol after a reboot.
*
* @param protocol The protocol to activate.
*/
void protocol_state_set(active_protocol_t protocol);
/**
* @brief Check if Zigbee is the active protocol.
* @return true if Zigbee is active, false otherwise.
*/
static inline bool protocol_is_zigbee_active(void)
{
return protocol_state_get() == PROTOCOL_ZIGBEE;
}
/**
* @brief Check if Matter is the active protocol.
* @return true if Matter is active, false otherwise.
*/
static inline bool protocol_is_matter_active(void)
{
return protocol_state_get() == PROTOCOL_MATTER;
}
#ifdef __cplusplus
}
#endif
/** @} */
#endif /* ZIGBEE_MATTER_PROTOCOL_STATE_H_ */