Skip to content

Commit 193a009

Browse files
committed
subsys: add Kconfig for BLE while Zigbee and button switch
Make CHIPoBLE during the Zigbee phase, user button switching, and hold time independently configurable. Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
1 parent 23b2fb2 commit 193a009

7 files changed

Lines changed: 99 additions & 21 deletions

File tree

include/zigbee/matter_coexistence.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ struct zigbee_matter_coexistence_callbacks {
4343
*/
4444
int (*zigbee_start)(void);
4545

46-
/** Hook run on the Zigbee worker thread once the Matter board has
47-
* finished initialisation (first CHIPoBLE advertising-started event).
46+
/** Hook run on the Zigbee worker thread once Matter is ready for the
47+
* Zigbee phase (CHIPoBLE advertising started when
48+
* @kconfig{CONFIG_ZIGBEE_MATTER_COEXISTENCE_CHIP_BLE_WHILE_ZIGBEE},
49+
* otherwise after the sample calls
50+
* @ref zigbee_matter_coexistence_signal_matter_board_init).
4851
* Typically used to register a chained Zigbee button handler with
4952
* the DK buttons library after @c dk_buttons_init() has completed.
5053
* May be NULL.
@@ -69,6 +72,16 @@ struct zigbee_matter_coexistence_callbacks {
6972
*/
7073
int zigbee_matter_coexistence_run(const struct zigbee_matter_coexistence_callbacks *cb);
7174

75+
/** @brief Notify the coexistence runtime that Matter board init is complete.
76+
*
77+
* Call from the Matter worker thread after @c Nrf::Matter::StartServer()
78+
* returns successfully when
79+
* @kconfig{CONFIG_ZIGBEE_MATTER_COEXISTENCE_CHIP_BLE_WHILE_ZIGBEE} is
80+
* disabled. Unblocks the Zigbee worker so it can chain button handlers and
81+
* start the Zigbee stack.
82+
*/
83+
void zigbee_matter_coexistence_signal_matter_board_init(void);
84+
7285
/** @brief Process button events for user-triggered protocol switching.
7386
*
7487
* Detects a long press on @p switch_button and requests a protocol switch

samples/light_bulb/src/app_task_matter.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
#include <app/server/Server.h>
2323
#include <setup_payload/OnboardingCodesUtil.h>
2424

25+
#if defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE) && \
26+
!defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE_CHIP_BLE_WHILE_ZIGBEE)
27+
#include <zigbee/matter_coexistence.h>
28+
#endif
29+
2530
#include <zephyr/logging/log.h>
2631

2732
LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL);
@@ -213,7 +218,14 @@ CHIP_ERROR AppTask::Init() {
213218

214219
ReturnErrorOnFailure(sIdentifyCluster.Init());
215220

216-
return Nrf::Matter::StartServer();
221+
ReturnErrorOnFailure(Nrf::Matter::StartServer());
222+
223+
#if defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE) && \
224+
!defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE_CHIP_BLE_WHILE_ZIGBEE)
225+
zigbee_matter_coexistence_signal_matter_board_init();
226+
#endif
227+
228+
return CHIP_NO_ERROR;
217229
}
218230

219231
CHIP_ERROR AppTask::StartApp() {

samples/light_bulb/src/app_task_zigbee.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <zephyr/drivers/pwm.h>
2222
#include <zephyr/kernel.h>
2323
#include <zephyr/logging/log.h>
24+
#include <zephyr/sys/util.h>
2425
#ifdef CONFIG_ZIGBEE_SCENES
2526
#include <zephyr/settings/settings.h>
2627
#endif

samples/light_switch/src/app_task.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
#include <setup_payload/OnboardingCodesUtil.h>
1717

18+
#if defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE) && \
19+
!defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE_CHIP_BLE_WHILE_ZIGBEE)
20+
#include <zigbee/matter_coexistence.h>
21+
#endif
22+
1823
#include <zephyr/logging/log.h>
1924

2025
LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL);
@@ -157,7 +162,14 @@ CHIP_ERROR AppTask::Init()
157162

158163
ReturnErrorOnFailure(sIdentifyCluster.Init());
159164

160-
return Nrf::Matter::StartServer();
165+
ReturnErrorOnFailure(Nrf::Matter::StartServer());
166+
167+
#if defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE) && \
168+
!defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE_CHIP_BLE_WHILE_ZIGBEE)
169+
zigbee_matter_coexistence_signal_matter_board_init();
170+
#endif
171+
172+
return CHIP_NO_ERROR;
161173
}
162174

163175
CHIP_ERROR AppTask::StartApp()

samples/light_switch/src/app_task_zigbee.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <zigbee/matter_coexistence.h>
1717

1818
#include <zephyr/kernel.h>
19+
#include <zephyr/sys/util.h>
1920
#include <zephyr/device.h>
2021
#include <zephyr/logging/log.h>
2122
#include <dk_buttons_and_leds.h>

subsys/lib/zigbee_matter_coexistence/Kconfig

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
menuconfig ZIGBEE_MATTER_COEXISTENCE
88
bool "Matter + Zigbee coexistence runtime for combined applications"
99
depends on CHIP && SETTINGS && ZIGBEE_ADD_ON
10-
depends on BT && CHIP_ENABLE_PAIRING_AUTOSTART
10+
depends on BT
1111
depends on CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT
1212
select ZIGBEE_MATTER_PROTOCOL_STATE
1313
default y
@@ -18,15 +18,51 @@ menuconfig ZIGBEE_MATTER_COEXISTENCE
1818
commissioning, and updates the persistent protocol state across
1919
reboots and factory resets.
2020

21-
Requires Matter BLE commissioning: the Zigbee worker waits for
22-
Matter to start BLE advertising so the buttons library is ready
23-
before the sample chains its Zigbee button handler onto it.
24-
25-
On last-fabric removal the device reboots and the
26-
Zigbee-first boot path restores Zigbee operation.
21+
On last-fabric removal the device reboots and the Zigbee-first boot
22+
path restores Zigbee operation (unless configured otherwise).
2723

2824
if ZIGBEE_MATTER_COEXISTENCE
2925

26+
config ZIGBEE_MATTER_COEXISTENCE_CHIP_BLE_WHILE_ZIGBEE
27+
bool "Allow CHIPoBLE commissioning while Zigbee is active"
28+
default y
29+
depends on CHIP_ENABLE_PAIRING_AUTOSTART
30+
help
31+
When enabled, Matter may start BLE commissioning advertising while
32+
the Zigbee stack owns the 802.15.4 radio. The Zigbee worker waits
33+
for the first CHIPoBLE advertising-started event before chaining
34+
sample button handlers and starting Zigbee.
35+
36+
Requires CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART in the application.
37+
38+
When disabled, the sample must call
39+
zigbee_matter_coexistence_signal_matter_board_init() after Matter
40+
server init completes.
41+
The Zigbee worker then proceeds without waiting for Thread
42+
or DNS-SD. Set CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART=n if Matter
43+
commissioning over BLE is not needed until after a protocol switch.
44+
45+
config ZIGBEE_MATTER_COEXISTENCE_BUTTON_SWITCH
46+
bool "Enable user protocol switch on button long press"
47+
default y
48+
help
49+
When enabled, samples may call
50+
zigbee_matter_coexistence_process_switch_button() to switch between
51+
Zigbee and Matter using a long button press.
52+
53+
When disabled, protocol changes rely on Matter commissioning events
54+
and factory reset only.
55+
56+
config ZIGBEE_MATTER_COEXISTENCE_SWITCH_BUTTON_PRESS_TIME_SECONDS
57+
int "Protocol-switch button hold time (seconds)"
58+
depends on ZIGBEE_MATTER_COEXISTENCE_BUTTON_SWITCH
59+
range 1 30
60+
default 5
61+
help
62+
Hold time required when pressing the protocol-switch button.
63+
When the timer expires, the coexistence runtime attempts to switch
64+
to the other protocol unless pairing or commissioning is in progress.
65+
3066
config ZIGBEE_MATTER_COEXISTENCE_ZIGBEE_THREAD_STACK_SIZE
3167
int "Zigbee worker thread stack size (bytes)"
3268
default 2048
@@ -43,15 +79,6 @@ config ZIGBEE_MATTER_COEXISTENCE_MATTER_THREAD_PRIORITY
4379
int "Matter worker thread priority"
4480
default 3
4581

46-
config ZIGBEE_MATTER_COEXISTENCE_SWITCH_BUTTON_PRESS_TIME_SECONDS
47-
int "Protocol-switch button hold time (seconds)"
48-
range 1 30
49-
default 5
50-
help
51-
Hold time required when pressing the protocol-switch button.
52-
When the timer expires, the coexistence runtime attempts to switch
53-
to the other protocol unless pairing or commissioning is in progress.
54-
5582
module = ZIGBEE_MATTER_COEXISTENCE
5683
module-str = Matter/Zigbee coexistence
5784
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"

subsys/lib/zigbee_matter_coexistence/coexistence.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ atomic_t g_switch_press_active = ATOMIC_INIT(0);
3737
void switch_to_thread_radio(void);
3838
void switch_to_zigbee_radio(void);
3939

40+
void matter_board_init_signal(void)
41+
{
42+
k_sem_give(&matter_init_done_sem);
43+
}
44+
4045
void protocol_switch_work_handler(struct k_work *work)
4146
{
4247
ARG_UNUSED(work);
@@ -140,12 +145,14 @@ void matter_event_handler(const chip::DeviceLayer::ChipDeviceEvent *event, intpt
140145
ARG_UNUSED(arg);
141146

142147
switch (event->Type) {
148+
#ifdef CONFIG_ZIGBEE_MATTER_COEXISTENCE_CHIP_BLE_WHILE_ZIGBEE
143149
case chip::DeviceLayer::DeviceEventType::kCHIPoBLEAdvertisingChange:
144150
if (event->CHIPoBLEAdvertisingChange.Result ==
145151
chip::DeviceLayer::kActivity_Started) {
146-
k_sem_give(&matter_init_done_sem);
152+
matter_board_init_signal();
147153
}
148154
break;
155+
#endif /* CONFIG_ZIGBEE_MATTER_COEXISTENCE_CHIP_BLE_WHILE_ZIGBEE */
149156
case chip::DeviceLayer::DeviceEventType::kSecureSessionEstablished:
150157
if (protocol_state_get() == PROTOCOL_ZIGBEE &&
151158
!chip::DeviceLayer::ThreadStackMgr().IsThreadAttached()) {
@@ -182,6 +189,11 @@ void matter_event_handler(const chip::DeviceLayer::ChipDeviceEvent *event, intpt
182189

183190
} /* namespace */
184191

192+
extern "C" void zigbee_matter_coexistence_signal_matter_board_init(void)
193+
{
194+
matter_board_init_signal();
195+
}
196+
185197
extern "C" int zigbee_matter_coexistence_run(const struct zigbee_matter_coexistence_callbacks *cb)
186198
{
187199
__ASSERT(cb != NULL, "Null callback table");

0 commit comments

Comments
 (0)