Skip to content

Commit b708336

Browse files
samples: matter: Switch Identify Cluster to code-driven
Replaced ZAP-driven Identify Cluster usage by the code-driven implementation. This change is done to be aligned with Matter 1.5. Signed-off-by: Arkadiusz Balys <[email protected]>
1 parent 270cebc commit b708336

File tree

27 files changed

+390
-406
lines changed

27 files changed

+390
-406
lines changed

applications/matter_bridge/src/app_task.cpp

Lines changed: 8 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "board/board.h"
1818
#include "bridge_manager.h"
1919
#include "bridge_storage_manager.h"
20+
#include "clusters/identify.h"
2021

2122
#ifdef CONFIG_BRIDGED_DEVICE_BT
2223
#include "ble_connectivity_manager.h"
@@ -25,7 +26,6 @@
2526
#include <app-common/zap-generated/attributes/Accessors.h>
2627
#include <app-common/zap-generated/ids/Attributes.h>
2728
#include <app-common/zap-generated/ids/Clusters.h>
28-
#include <app/clusters/identify-server/identify-server.h>
2929
#include <setup_payload/OnboardingCodesUtil.h>
3030

3131
#ifdef CONFIG_BRIDGED_DEVICE_BT
@@ -47,14 +47,13 @@ namespace
4747
{
4848

4949
constexpr EndpointId kBridgeEndpointId = 1;
50-
constexpr uint16_t kTriggerEffectTimeout = 5000;
51-
constexpr uint16_t kTriggerEffectFinishTimeout = 1000;
5250

53-
k_timer sTriggerEffectTimer;
54-
bool sIsTriggerEffectActive;
55-
56-
Identify sIdentify = { kBridgeEndpointId, AppTask::IdentifyStartHandler, AppTask::IdentifyStopHandler,
57-
Clusters::Identify::IdentifyTypeEnum::kVisibleIndicator, AppTask::TriggerIdentifyEffectHandler };
51+
#ifndef CONFIG_BRIDGE_SMART_PLUG_SUPPORT
52+
/* Trigger effect is enabled for the bridge device */
53+
Nrf::Matter::IdentifyCluster sIdentifyCluster(kBridgeEndpointId, true);
54+
#else
55+
Nrf::Matter::IdentifyCluster sIdentifyCluster(kBridgeEndpointId);
56+
#endif
5857

5958
#ifdef CONFIG_BRIDGED_DEVICE_BT
6059
const bt_uuid *sUuidLbs = BT_UUID_LBS;
@@ -115,67 +114,6 @@ void AppFactoryResetHandler(const ChipDeviceEvent *event, intptr_t /* unused */)
115114

116115
} /* namespace */
117116

118-
void AppTask::IdentifyStartHandler(Identify *)
119-
{
120-
Nrf::PostTask(
121-
[] { Nrf::GetBoard().GetLED(Nrf::DeviceLeds::LED2).Blink(Nrf::LedConsts::kIdentifyBlinkRate_ms); });
122-
}
123-
124-
void AppTask::IdentifyStopHandler(Identify *)
125-
{
126-
Nrf::PostTask([] {
127-
Nrf::GetBoard().GetLED(Nrf::DeviceLeds::LED2).Set(false);
128-
});
129-
}
130-
131-
void AppTask::TriggerEffectTimerTimeoutCallback(k_timer *timer)
132-
{
133-
LOG_INF("Identify effect completed");
134-
135-
sIsTriggerEffectActive = false;
136-
137-
Nrf::GetBoard().GetLED(Nrf::DeviceLeds::LED2).Set(false);
138-
139-
}
140-
141-
void AppTask::TriggerIdentifyEffectHandler(Identify *identify)
142-
{
143-
switch (identify->mCurrentEffectIdentifier) {
144-
/* Just handle all effects in the same way. */
145-
case Clusters::Identify::EffectIdentifierEnum::kBlink:
146-
case Clusters::Identify::EffectIdentifierEnum::kBreathe:
147-
case Clusters::Identify::EffectIdentifierEnum::kOkay:
148-
case Clusters::Identify::EffectIdentifierEnum::kChannelChange:
149-
LOG_INF("Identify effect identifier changed to %d",
150-
static_cast<uint8_t>(identify->mCurrentEffectIdentifier));
151-
152-
sIsTriggerEffectActive = false;
153-
154-
k_timer_stop(&sTriggerEffectTimer);
155-
k_timer_start(&sTriggerEffectTimer, K_MSEC(kTriggerEffectTimeout), K_NO_WAIT);
156-
157-
Nrf::GetBoard().GetLED(Nrf::DeviceLeds::LED2).Blink(Nrf::LedConsts::kIdentifyBlinkRate_ms);
158-
break;
159-
case Clusters::Identify::EffectIdentifierEnum::kFinishEffect:
160-
LOG_INF("Identify effect finish triggered");
161-
k_timer_stop(&sTriggerEffectTimer);
162-
k_timer_start(&sTriggerEffectTimer, K_MSEC(kTriggerEffectFinishTimeout), K_NO_WAIT);
163-
break;
164-
case Clusters::Identify::EffectIdentifierEnum::kStopEffect:
165-
if (sIsTriggerEffectActive) {
166-
sIsTriggerEffectActive = false;
167-
168-
k_timer_stop(&sTriggerEffectTimer);
169-
170-
Nrf::GetBoard().GetLED(Nrf::DeviceLeds::LED2).Set(false);
171-
}
172-
break;
173-
default:
174-
LOG_ERR("Received invalid effect identifier.");
175-
break;
176-
}
177-
}
178-
179117
CHIP_ERROR AppTask::RestoreBridgedDevices()
180118
{
181119
uint8_t count;
@@ -289,8 +227,7 @@ CHIP_ERROR AppTask::Init()
289227
ReturnErrorOnFailure(Nrf::Matter::RegisterEventHandler(AppFactoryResetHandler, 0));
290228
#endif
291229

292-
/* Initialize trigger effect timer */
293-
k_timer_init(&sTriggerEffectTimer, &AppTask::TriggerEffectTimerTimeoutCallback, nullptr);
230+
ReturnErrorOnFailure(sIdentifyCluster.Init());
294231

295232
return Nrf::Matter::StartServer();
296233
}

applications/matter_weather_station/src/app_task.cpp

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
#include "app/task_executor.h"
1414
#include "board/board.h"
1515
#include "board/led_widget.h"
16+
#include "clusters/identify.h"
1617

1718
#ifdef CONFIG_MCUMGR_TRANSPORT_BT
1819
#include "dfu/smp/dfu_over_smp.h"
1920
#endif
2021

2122
#include <app-common/zap-generated/attributes/Accessors.h>
2223
#include <app-common/zap-generated/cluster-objects.h>
24+
#include <app/DefaultTimerDelegate.h>
2325
#include <app/server/Server.h>
2426
#include <setup_payload/OnboardingCodesUtil.h>
2527

@@ -76,13 +78,45 @@ k_timer sIdentifyTimer;
7678

7779
const device *sBme688SensorDev = DEVICE_DT_GET_ONE(bosch_bme680);
7880

79-
/* Add identify for all endpoints */
80-
Identify sIdentifyTemperature = { chip::EndpointId{ kTemperatureMeasurementEndpointId }, AppTask::OnIdentifyStart,
81-
AppTask::OnIdentifyStop, Clusters::Identify::IdentifyTypeEnum::kAudibleBeep };
82-
Identify sIdentifyHumidity = { chip::EndpointId{ kHumidityMeasurementEndpointId }, AppTask::OnIdentifyStart,
83-
AppTask::OnIdentifyStop, Clusters::Identify::IdentifyTypeEnum::kAudibleBeep };
84-
Identify sIdentifyPressure = { chip::EndpointId{ kPressureMeasurementEndpointId }, AppTask::OnIdentifyStart,
85-
AppTask::OnIdentifyStop, Clusters::Identify::IdentifyTypeEnum::kAudibleBeep };
81+
class IdentifyDelegateImplWeatherStation : public chip::app::Clusters::IdentifyDelegate {
82+
public:
83+
void OnIdentifyStart(chip::app::Clusters::IdentifyCluster &cluster) override
84+
{
85+
Nrf::PostTask([] {
86+
Nrf::GetBoard().GetLED(Nrf::DeviceLeds::LED2).Blink(Nrf::LedConsts::kIdentifyBlinkRate_ms);
87+
k_timer_start(&sIdentifyTimer, K_MSEC(kIdentifyTimerIntervalMs),
88+
K_MSEC(kIdentifyTimerIntervalMs));
89+
BuzzerSetState(true);
90+
});
91+
}
92+
93+
void OnIdentifyStop(chip::app::Clusters::IdentifyCluster &cluster) override
94+
{
95+
Nrf::PostTask([] {
96+
Nrf::GetBoard().GetLED(Nrf::DeviceLeds::LED2).Set(false);
97+
k_timer_stop(&sIdentifyTimer);
98+
BuzzerSetState(false);
99+
});
100+
}
101+
102+
void OnTriggerEffect(chip::app::Clusters::IdentifyCluster &cluster) override
103+
{
104+
Nrf::PostTask([] { BuzzerToggleState(); });
105+
}
106+
107+
bool IsTriggerEffectEnabled() const override { return true; }
108+
};
109+
110+
IdentifyDelegateImplWeatherStation sIdentifyDelegateImplWeatherStation;
111+
DefaultTimerDelegate sTimerDelegate;
112+
113+
Nrf::Matter::IdentifyCluster sIdentifyTemperature(kTemperatureMeasurementEndpointId,
114+
sIdentifyDelegateImplWeatherStation, sTimerDelegate,
115+
Clusters::Identify::IdentifyTypeEnum::kAudibleBeep);
116+
Nrf::Matter::IdentifyCluster sIdentifyHumidity(kHumidityMeasurementEndpointId, sIdentifyDelegateImplWeatherStation,
117+
sTimerDelegate, Clusters::Identify::IdentifyTypeEnum::kAudibleBeep);
118+
Nrf::Matter::IdentifyCluster sIdentifyPressure(kPressureMeasurementEndpointId, sIdentifyDelegateImplWeatherStation,
119+
sTimerDelegate, Clusters::Identify::IdentifyTypeEnum::kAudibleBeep);
86120

87121
} /* namespace */
88122

@@ -91,19 +125,6 @@ void AppTask::MeasurementsTimerHandler()
91125
Instance().UpdateClustersState();
92126
}
93127

94-
void AppTask::OnIdentifyStart(Identify *)
95-
{
96-
Nrf::PostTask(
97-
[] { Nrf::GetBoard().GetLED(Nrf::DeviceLeds::LED2).Blink(Nrf::LedConsts::kIdentifyBlinkRate_ms); });
98-
k_timer_start(&sIdentifyTimer, K_MSEC(kIdentifyTimerIntervalMs), K_MSEC(kIdentifyTimerIntervalMs));
99-
}
100-
101-
void AppTask::OnIdentifyStop(Identify *)
102-
{
103-
k_timer_stop(&sIdentifyTimer);
104-
BuzzerSetState(false);
105-
}
106-
107128
void AppTask::IdentifyTimerHandler()
108129
{
109130
BuzzerToggleState();
@@ -383,6 +404,10 @@ CHIP_ERROR AppTask::Init()
383404
return chip::System::MapErrorZephyr(ret);
384405
}
385406

407+
ReturnErrorOnFailure(sIdentifyTemperature.Init());
408+
ReturnErrorOnFailure(sIdentifyHumidity.Init());
409+
ReturnErrorOnFailure(sIdentifyPressure.Init());
410+
386411
/* Initialize timers */
387412
k_timer_init(
388413
&sMeasurementsTimer, [](k_timer *) { Nrf::PostTask([] { MeasurementsTimerHandler(); }); }, nullptr);

applications/matter_weather_station/src/app_task.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "board/led_widget.h"
1010

11-
#include <app/clusters/identify-server/identify-server.h>
1211
#include <platform/CHIPDeviceLayer.h>
1312

1413
class AppTask {
@@ -22,8 +21,6 @@ class AppTask {
2221
CHIP_ERROR StartApp();
2322

2423
void UpdateClustersState();
25-
static void OnIdentifyStart(Identify *);
26-
static void OnIdentifyStop(Identify *);
2724
static void UpdateLedState();
2825

2926
private:

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ Matter bridge
330330
To fix this, you need to disable storing the Wi-Fi firmware patch in external memory.
331331
See the :ref:`migration guide <migration_3.2_required>` for more information.
332332
* By moving code from :file:`samples/matter/common/src/bridge` to :file:`applications/matter_bridge/src/core` and :file:`applications/matter_bridge/src/ble` directories.
333+
* The Identify cluster implementation in the application to use the code-driven approach instead of the zap-driven approach.
333334

334335
nRF5340 Audio
335336
-------------
@@ -423,7 +424,7 @@ nRF Machine Learning (Edge Impulse)
423424
Thingy:53: Matter weather station
424425
---------------------------------
425426

426-
|no_changes_yet_note|
427+
* Updated the application to use the code-driven approach for the Identify cluster implementation instead of the zap-driven approach.
427428

428429
Samples
429430
=======
@@ -743,6 +744,7 @@ Matter samples
743744
See the :ref:`migration guide <migration_3.2_required>` for more information.
744745
* All Matter samples that support low-power mode to use the :ref:`lib_ram_pwrdn` feature with the nRF54LM20 DK.
745746
This change resulted in decreasing the sleep current consumption by more than two uA.
747+
* All Matter samples to use the code-driven approach for the Identify cluster implementation instead of the zap-driven approach.
746748

747749
* :ref:`matter_lock_sample` sample:
748750

samples/matter/closure/src/app_task.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
#include "board/board.h"
1212
#include "closure_control_endpoint.h"
1313
#include "closure_manager.h"
14+
#include "clusters/identify.h"
15+
1416
#include "lib/core/CHIPError.h"
1517
#include "lib/support/CodeUtils.h"
16-
1718
#include <app-common/zap-generated/ids/Attributes.h>
1819
#include <app-common/zap-generated/ids/Clusters.h>
1920
#include <app/data-model/Nullable.h>
@@ -29,7 +30,15 @@ using namespace ::chip::app;
2930
using namespace ::chip::DeviceLayer;
3031
using namespace chip::app::Clusters::Descriptor;
3132

32-
static const struct pwm_dt_spec sPhysicalIndicatorPwmDevice = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led1));
33+
namespace
34+
{
35+
const struct pwm_dt_spec sPhysicalIndicatorPwmDevice = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led1));
36+
37+
constexpr chip::EndpointId kClosureEndpoint = 1;
38+
39+
/* TODO: Add a custom identify delegate to handle the custom identify stop behavior according to the closure state */
40+
Nrf::Matter::IdentifyCluster sIdentifyCluster(kClosureEndpoint);
41+
} // namespace
3342

3443
AppTask::AppTask() : mPhysicalDevice(&sPhysicalIndicatorPwmDevice), mClosureManager(mPhysicalDevice, kClosureEndpoint)
3544
{
@@ -48,6 +57,8 @@ CHIP_ERROR AppTask::Init()
4857

4958
ReturnErrorOnFailure(Nrf::Matter::StartServer());
5059

60+
ReturnErrorOnFailure(sIdentifyCluster.Init());
61+
5162
ReturnErrorOnFailure(mClosureManager.Init());
5263
return CHIP_NO_ERROR;
5364
}

samples/matter/closure/src/app_task.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#include "closure_manager.h"
88
#include "garage_door_impl.h"
99

10-
static constexpr chip::EndpointId kClosureEndpoint = 1;
11-
1210
class AppTask {
1311
public:
1412
AppTask();

samples/matter/common/src/board/board.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ bool Board::Init(button_handler_t buttonHandler, LedStateHandler ledStateHandler
6868
.cb = Nrf::Matter::Certification::ButtonHandler,
6969
};
7070
dk_button_handler_add(&handler);
71+
72+
Nrf::Matter::Certification::Init();
7173
}
7274
#endif
7375

samples/matter/common/src/board/board_consts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace Nrf
2525

2626
namespace LedConsts
2727
{
28+
constexpr uint32_t kTriggerEffectStart_ms = 5000;
29+
constexpr uint32_t kTriggerEffectFinish_ms = 1000;
2830
constexpr uint32_t kBlinkRate_ms{ 500 };
2931
constexpr uint32_t kIdentifyBlinkRate_ms{ 500 };
3032
namespace StatusLed

0 commit comments

Comments
 (0)