Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions include/zigbee/matter_coexistence.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
* and calling @ref zigbee_matter_coexistence_run from @c main().
*/

#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -40,13 +43,17 @@ struct zigbee_matter_coexistence_callbacks {
*/
int (*zigbee_start)(void);

/** Hook run on the Zigbee worker thread once the Matter board has
* finished initialisation (first CHIPoBLE advertising-started event).
/** Hook run on the Zigbee worker thread once Matter is ready for the
* Zigbee phase (CHIPoBLE advertising started when
* @kconfig{CONFIG_ZIGBEE_MATTER_COEXISTENCE_CHIP_BLE_WHILE_ZIGBEE},
* otherwise after the sample calls
* @ref zigbee_matter_coexistence_signal_matter_board_init).
* Typically used to register a chained Zigbee button handler with
* the DK buttons library after @c dk_buttons_init() has completed.
* May be NULL.
*/
void (*post_matter_board_init)(void);

};

/** @brief Start the coexistence runtime.
Expand All @@ -65,6 +72,31 @@ struct zigbee_matter_coexistence_callbacks {
*/
int zigbee_matter_coexistence_run(const struct zigbee_matter_coexistence_callbacks *cb);

/** @brief Notify the coexistence runtime that Matter board init is complete.
*
* Call from the Matter worker thread after @c Nrf::Matter::StartServer()
* returns successfully when
* @kconfig{CONFIG_ZIGBEE_MATTER_COEXISTENCE_CHIP_BLE_WHILE_ZIGBEE} is
* disabled. Unblocks the Zigbee worker so it can chain button handlers and
* start the Zigbee stack.
*/
void zigbee_matter_coexistence_signal_matter_board_init(void);

/** @brief Process button events for user-triggered protocol switching.
*
* Detects a long press on @p switch_button and requests a protocol switch
* when @kconfig_ZIGBEE_MATTER_COEXISTENCE_SWITCH_BUTTON_PRESS_TIME_SECONDS
* expires.
Comment on lines +87 to +89
*
* Call this before other sample-specific button checks.
*
* @param button_state Current button state bitmask.
* @param has_changed Button-change bitmask from DK callback.
* @param switch_button Bitmask of the switch button (one DK button).
*/
void zigbee_matter_coexistence_process_switch_button(uint32_t button_state, uint32_t has_changed,
uint32_t switch_button);

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 5 additions & 4 deletions include/zigbee/matter_protocol_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
* @brief Persistent "which protocol is active" state for samples that host
* both Matter and Zigbee on the same 802.15.4 radio.
*
* The application boots on Zigbee by default. 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.
* 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>
Expand Down
21 changes: 19 additions & 2 deletions include/zigbee/zigbee_app_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <stdint.h>
#include <stdbool.h>

#include <zboss_api.h>

/** @file zigbee_app_utils.h
*
* @defgroup zigbee_app_utils Zigbee application utilities library.
Expand All @@ -27,6 +25,8 @@
extern "C" {
#endif

#include <zboss_api.h>

/**@brief Function for setting the Erase persistent storage,
* depending on the erase pin.
*
Expand All @@ -40,6 +40,23 @@ extern "C" {
*/
void zigbee_erase_persistent_storage(zb_bool_t erase);

/** @brief Whether a Zigbee network join/commissioning procedure is active.
*
* True only while top-level BDB commissioning (initialization, steering,
* formation, Touchlink, or Trust Center rejoin) is running on the radio.
* False when the device is idle and not joined, including between automatic
* rejoin attempts.
*/
bool zigbee_network_join_commissioning_active(void);

/** @brief Mark Zigbee network join/commissioning as active or idle.
*
* Samples should set this to true before starting Touchlink or other
* application-triggered commissioning not covered by the default signal
* handler.
*/
void zigbee_network_join_commissioning_set_active(bool active);

/**@brief Function for converting an input buffer to a hex string.
*
* @param[out] out Pointer to the output buffer.
Expand Down
1 change: 1 addition & 0 deletions samples/light_bulb/prj_matter_fota.conf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ CONFIG_DK_LIBRARY=y
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

CONFIG_ZBOSS_OSIF_LOG_LEVEL_INF=y
CONFIG_ZIGBEE_MATTER_COEXISTENCE_LOG_LEVEL_INF=y

#######################
# Zigbee FOTA Configuration
Expand Down
14 changes: 13 additions & 1 deletion samples/light_bulb/src/app_task_matter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#include <app/server/Server.h>
#include <setup_payload/OnboardingCodesUtil.h>

#if defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE) && \
!defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE_CHIP_BLE_WHILE_ZIGBEE)
#include <zigbee/matter_coexistence.h>
#endif

#include <zephyr/logging/log.h>

LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL);
Expand Down Expand Up @@ -213,7 +218,14 @@ CHIP_ERROR AppTask::Init() {

ReturnErrorOnFailure(sIdentifyCluster.Init());

return Nrf::Matter::StartServer();
ReturnErrorOnFailure(Nrf::Matter::StartServer());

#if defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE) && \
!defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE_CHIP_BLE_WHILE_ZIGBEE)
zigbee_matter_coexistence_signal_matter_board_init();
#endif

return CHIP_NO_ERROR;
}

CHIP_ERROR AppTask::StartApp() {
Expand Down
10 changes: 10 additions & 0 deletions samples/light_bulb/src/app_task_zigbee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "app_task_zigbee.h"

#ifdef CONFIG_ZIGBEE_MATTER_COEXISTENCE
#include <zigbee/matter_coexistence.h>
#include <zigbee/matter_protocol_state.h>
#endif

Expand All @@ -20,6 +21,7 @@
#include <zephyr/drivers/pwm.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/sys/util.h>
#ifdef CONFIG_ZIGBEE_SCENES
#include <zephyr/settings/settings.h>
#endif
Expand Down Expand Up @@ -91,6 +93,9 @@ extern "C" {
/* Button used to enter the Bulb into the Identify mode. */
#define IDENTIFY_MODE_BUTTON DK_BTN4_MSK

/* Long-press Button 3 to switch active protocol in combined builds. */
#define PROTOCOL_SWITCH_BUTTON DK_BTN3_MSK

/* Use onboard led4 to act as a light bulb.
* The app.overlay file has this at node label "pwm_led3" in /pwmleds.
*/
Expand Down Expand Up @@ -213,6 +218,11 @@ static void start_identifying(zb_bufid_t bufid) {
*/
static void zb_button_handler_impl(uint32_t button_state, uint32_t has_changed) {
#ifdef CONFIG_ZIGBEE_MATTER_COEXISTENCE
#ifdef CONFIG_ZIGBEE_MATTER_COEXISTENCE_BUTTON_SWITCH
(void)zigbee_matter_coexistence_process_switch_button(
button_state, has_changed, PROTOCOL_SWITCH_BUTTON);
#endif

if (!protocol_is_zigbee_active()) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions samples/light_switch/prj_matter_fota.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ CONFIG_DK_LIBRARY=y
CONFIG_RAM_POWER_DOWN_LIBRARY=y

CONFIG_ZBOSS_OSIF_LOG_LEVEL_INF=y
CONFIG_ZIGBEE_MATTER_COEXISTENCE_LOG_LEVEL_INF=y

#######################
# Matter Configuration
Expand Down
14 changes: 13 additions & 1 deletion samples/light_switch/src/app_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

#include <setup_payload/OnboardingCodesUtil.h>

#if defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE) && \
!defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE_CHIP_BLE_WHILE_ZIGBEE)
#include <zigbee/matter_coexistence.h>
#endif

#include <zephyr/logging/log.h>

LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL);
Expand Down Expand Up @@ -157,7 +162,14 @@ CHIP_ERROR AppTask::Init()

ReturnErrorOnFailure(sIdentifyCluster.Init());

return Nrf::Matter::StartServer();
ReturnErrorOnFailure(Nrf::Matter::StartServer());

#if defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE) && \
!defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE_CHIP_BLE_WHILE_ZIGBEE)
zigbee_matter_coexistence_signal_matter_board_init();
#endif

return CHIP_NO_ERROR;
}

CHIP_ERROR AppTask::StartApp()
Expand Down
19 changes: 18 additions & 1 deletion samples/light_switch/src/app_task_zigbee.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
#include "app_task_zigbee.h"

#include <zigbee/matter_protocol_state.h>
#include <zigbee/matter_coexistence.h>

#include <zephyr/kernel.h>
#include <zephyr/sys/util.h>
#include <zephyr/device.h>
#include <zephyr/logging/log.h>
#include <dk_buttons_and_leds.h>
Expand Down Expand Up @@ -96,6 +98,9 @@
/* Button to start Factory Reset */
#define FACTORY_RESET_BUTTON DK_BTN4_MSK

/* Long-press Button 3 to switch active protocol in combined builds. */
#define PROTOCOL_SWITCH_BUTTON DK_BTN3_MSK

/* Button used to enter the Identify mode. */
#define IDENTIFY_MODE_BUTTON DK_BTN4_MSK

Expand Down Expand Up @@ -258,6 +263,7 @@ static void light_switch_touchlink_initiator_start_cb(zb_bufid_t bufid)
ZVUNUSED(bufid);

LOG_INF("Starting Touchlink initiator");
zigbee_network_join_commissioning_set_active(true);
zigbee_touchlink_initiator_prepare_scan_channels();
if (!bdb_start_top_level_commissioning(ZB_BDB_TOUCHLINK_COMMISSIONING)) {
LOG_WRN("Touchlink commissioning rejected (already in progress?)");
Expand All @@ -277,6 +283,11 @@ static void zb_button_handler_impl(uint32_t button_state, uint32_t has_changed)
zb_ret_t zb_err_code;

#ifdef CONFIG_ZIGBEE_MATTER_COEXISTENCE
#ifdef CONFIG_ZIGBEE_MATTER_COEXISTENCE_BUTTON_SWITCH
(void)zigbee_matter_coexistence_process_switch_button(button_state, has_changed,
PROTOCOL_SWITCH_BUTTON);
#endif

if (!protocol_is_zigbee_active()) {
return;
}
Expand All @@ -287,7 +298,7 @@ static void zb_button_handler_impl(uint32_t button_state, uint32_t has_changed)

check_factory_reset_button(button_state, has_changed);

#if defined(CONFIG_ZIGBEE_TOUCHLINK_INITIATOR)
#if defined(CONFIG_ZIGBEE_TOUCHLINK_INITIATOR) && !defined(CONFIG_ZIGBEE_MATTER_COEXISTENCE)
if ((has_changed & BUTTON_TOUCHLINK) && (button_state & BUTTON_TOUCHLINK)) {
ZB_SCHEDULE_APP_CALLBACK(light_switch_touchlink_initiator_start_cb, 0);
return;
Expand Down Expand Up @@ -548,6 +559,12 @@ static void find_light_bulb_cb(zb_bufid_t bufid)
*/
static void find_light_bulb_alarm(struct k_timer *timer)
{
#ifdef CONFIG_ZIGBEE_MATTER_COEXISTENCE
if (!protocol_is_zigbee_active()) {
return;
}
#endif

ZB_ERROR_CHECK(zb_buf_get_out_delayed(find_light_bulb));
}

Expand Down
Loading
Loading