Skip to content

Commit 74cba6d

Browse files
marius-alex-tacheandrei-menzopolrestyled-commits
authored
[NXP] Add lock app example (#35536)
* [nxp][examples][platform] Add cluster-handling functions & remove RestoreState * Add virtual cluster-handling functions that must be implemented per application based on cluster configuration. * Remove RestoreState as it may read attributes from cluster before the enpoints are initialized. Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][examples][common] Implement cluster-handling functions Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][platform][mcxw71_k32w1] Add ResetInIdle functions Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][platform][common][legacy] Add SetRebootDelaySec function Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][platform][mcxw71_k32w1] Platform changes * Add __wrap__calloc_r * Use ProcessSetStateClusterHandler in ButtonManager Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp] Add initial lock app common files Signed-off-by: marius-alex-tache <marius.tache@nxp.com> * [nxp][examples][common][lock-app] LockApp changes needed for KW/MCX * Add cluster-handling functions * Put OnSubscriptionRequested override under define * Call RestoreState in PostAttributeChangeCallback * Call RestoreState in DoorLockClusterInitCallback * Add FSL_OSA_MAIN_FUNC_ENABLE main_task * Update lock-app/nxp/zap/lock-app zap files * Include stdint Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][examples][k32w1] Remove cluster attribute and endpoint defines Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][examples][mcxw71] Remove cluster attribute and endpoint defines Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][platform][common][icd] Do not change publisher-selected maximum interval Our code from OnSubscriptionRequested sets the publisher-selected maximum interval to kSubscriptionMaxIntervalPublisherLimit to 60 mins which is not spec compliant, it should be set to `Idle Mode Duration` as done in the default implementation from src/app/ReadHandler.cpp. Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][examples][k32w1] Add LockApp examples Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][examples][mcxw71] Add LockApp examples Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp] Add support for lock app Signed-off-by: marius-alex-tache <marius.tache@nxp.com> * Restyled by whitespace * Restyled by clang-format * Restyled by gn * Restyled by prettier-markdown * [nxp] Fix lock app mcxw71 readme files Signed-off-by: marius-alex-tache <marius.tache@nxp.com> * Restyled by prettier-markdown * [nxp] Fix a typo for lighting app readme Signed-off-by: marius-alex-tache <marius.tache@nxp.com> * [nxp] Add common lock app readme file Signed-off-by: marius-alex-tache <marius.tache@nxp.com> * Restyled by prettier-markdown * [nxp][mcxw71] Fix lock app naming Signed-off-by: marius-alex-tache <marius.tache@nxp.com> * [nxp] Fix lock app zap files Signed-off-by: marius-alex-tache <marius.tache@nxp.com> --------- Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> Signed-off-by: marius-alex-tache <marius.tache@nxp.com> Co-authored-by: Andrei Menzopol <andrei.menzopol@nxp.com> Co-authored-by: Restyled.io <commits@restyled.io>
1 parent d60a126 commit 74cba6d

File tree

48 files changed

+4371
-264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4371
-264
lines changed

.github/workflows/examples-nxp.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ jobs:
120120
./scripts/build/build_examples.py \
121121
--target nxp-k32w1-freertos-lighting \
122122
--target nxp-k32w1-freertos-contact-sensor-low-power \
123+
--target nxp-k32w1-freertos-lock-app \
123124
build \
124125
--copy-artifacts-to out/artifacts \
125126
"
@@ -135,6 +136,12 @@ jobs:
135136
nxp k32w1+release contact \
136137
out/artifacts/nxp-k32w1-freertos-contact-sensor-low-power/chip-k32w1-contact-example.elf \
137138
/tmp/bloat_reports/
139+
- name: Get lock app size stats
140+
run: |
141+
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
142+
nxp k32w1+release lock \
143+
out/artifacts/nxp-k32w1-freertos-lock-app/chip-k32w1-lock-example.elf \
144+
/tmp/bloat_reports/
138145
- name: Uploading Size Reports
139146
uses: ./.github/actions/upload-size-reports
140147
if: ${{ !env.ACT }}
@@ -174,6 +181,7 @@ jobs:
174181
./scripts/build/build_examples.py \
175182
--target nxp-mcxw71-freertos-lighting \
176183
--target nxp-mcxw71-freertos-contact-sensor-low-power \
184+
--target nxp-mcxw71-freertos-lock-app \
177185
build \
178186
--copy-artifacts-to out/artifacts \
179187
"
@@ -189,6 +197,12 @@ jobs:
189197
nxp mcxw71+release contact \
190198
out/artifacts/nxp-mcxw71-freertos-contact-sensor-low-power/chip-mcxw71-contact-example.elf \
191199
/tmp/bloat_reports/
200+
- name: Get lock app size stats
201+
run: |
202+
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
203+
nxp mcxw71+release lock \
204+
out/artifacts/nxp-mcxw71-freertos-lock-app/chip-mcxw71-lock-example.elf \
205+
/tmp/bloat_reports/
192206
- name: Uploading Size Reports
193207
uses: ./.github/actions/upload-size-reports
194208
if: ${{ !env.ACT }}

examples/contact-sensor-app/nxp/common/AppTask.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@
2222
#include "PWR_Interface.h"
2323
#endif
2424

25+
#include <app-common/zap-generated/attributes/Accessors.h>
2526
#include <platform/CHIPDeviceLayer.h>
2627

28+
#ifndef APP_DEVICE_TYPE_ENDPOINT
29+
#define APP_DEVICE_TYPE_ENDPOINT 1
30+
#endif
31+
32+
using namespace chip::app::Clusters;
33+
2734
void ContactSensorApp::AppTask::PreInitMatterStack()
2835
{
2936
ChipLogProgress(DeviceLayer, "Welcome to NXP Contact Sensor Demo App");
@@ -47,6 +54,24 @@ ContactSensorApp::AppTask & ContactSensorApp::AppTask::GetDefaultInstance()
4754
return sAppTask;
4855
}
4956

57+
bool ContactSensorApp::AppTask::CheckStateClusterHandler(void)
58+
{
59+
bool val = false;
60+
BooleanState::Attributes::StateValue::Get(APP_DEVICE_TYPE_ENDPOINT, &val);
61+
return val;
62+
}
63+
64+
CHIP_ERROR ContactSensorApp::AppTask::ProcessSetStateClusterHandler(void)
65+
{
66+
bool val = false;
67+
BooleanState::Attributes::StateValue::Get(APP_DEVICE_TYPE_ENDPOINT, &val);
68+
auto status = BooleanState::Attributes::StateValue::Set(APP_DEVICE_TYPE_ENDPOINT, (bool) !val);
69+
70+
VerifyOrReturnError(status == chip::Protocols::InteractionModel::Status::Success, CHIP_ERROR_WRITE_FAILED);
71+
72+
return CHIP_NO_ERROR;
73+
}
74+
5075
chip::NXP::App::AppTaskBase & chip::NXP::App::GetAppTask()
5176
{
5277
return ContactSensorApp::AppTask::GetDefaultInstance();

examples/contact-sensor-app/nxp/common/include/AppTask.h

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ namespace ContactSensorApp {
2828
class AppTask : public chip::NXP::App::AppTaskFreeRTOS
2929
{
3030
public:
31+
// AppTaskBase virtual methods
32+
bool CheckStateClusterHandler(void) override;
33+
CHIP_ERROR ProcessSetStateClusterHandler(void) override;
34+
3135
// AppTaskFreeRTOS virtual methods
3236
void PreInitMatterStack() override;
3337
#if CONFIG_LOW_POWER

examples/contact-sensor-app/nxp/k32w1/include/config/AppConfig.h

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#pragma once
1919

2020
/* ---- App Config ---- */
21-
#define APP_DEVICE_TYPE_ENDPOINT 1
22-
#define APP_CLUSTER_ATTRIBUTE chip::app::Clusters::BooleanState::Attributes::StateValue
2321

2422
/* ---- Button Manager Config ---- */
2523
#define BUTTON_MANAGER_FACTORY_RESET_TIMEOUT_MS 6000

examples/contact-sensor-app/nxp/mcxw71/include/config/AppConfig.h

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#pragma once
1919

2020
/* ---- App Config ---- */
21-
#define APP_DEVICE_TYPE_ENDPOINT 1
22-
#define APP_CLUSTER_ATTRIBUTE chip::app::Clusters::BooleanState::Attributes::StateValue
2321

2422
/* ---- Button Manager Config ---- */
2523
#define BUTTON_MANAGER_FACTORY_RESET_TIMEOUT_MS 6000

examples/lighting-app/nxp/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ where `device` can be one of the [Supported devices](#supported-devices).
119119
120120
The application uses an NXP specific data model file:
121121
122-
| path | description |
123-
| ----------------------------- | --------------------------------------- |
124-
| `zap-lit/lighting-on-off.zap` | Data model for On/Off Light device type |
122+
| path | description |
123+
| ------------------------- | --------------------------------------- |
124+
| `zap/lighting-on-off.zap` | Data model for On/Off Light device type |
125125
126126
The data model can be changed by simply replacing the gn `deps` statement
127127
corresponding to data model target.

examples/lighting-app/nxp/common/AppTask.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@
1818

1919
#include "AppTask.h"
2020

21+
#include <app-common/zap-generated/attributes/Accessors.h>
2122
#include <platform/CHIPDeviceLayer.h>
2223

24+
#ifndef APP_DEVICE_TYPE_ENDPOINT
25+
#define APP_DEVICE_TYPE_ENDPOINT 1
26+
#endif
27+
28+
using namespace chip::app::Clusters;
29+
2330
void LightingApp::AppTask::PreInitMatterStack()
2431
{
2532
ChipLogProgress(DeviceLayer, "Welcome to NXP Lighting Demo App");
@@ -31,6 +38,24 @@ LightingApp::AppTask & LightingApp::AppTask::GetDefaultInstance()
3138
return sAppTask;
3239
}
3340

41+
bool LightingApp::AppTask::CheckStateClusterHandler(void)
42+
{
43+
bool val = false;
44+
OnOff::Attributes::OnOff::Get(APP_DEVICE_TYPE_ENDPOINT, &val);
45+
return val;
46+
}
47+
48+
CHIP_ERROR LightingApp::AppTask::ProcessSetStateClusterHandler(void)
49+
{
50+
bool val = false;
51+
OnOff::Attributes::OnOff::Get(APP_DEVICE_TYPE_ENDPOINT, &val);
52+
auto status = OnOff::Attributes::OnOff::Set(APP_DEVICE_TYPE_ENDPOINT, (bool) !val);
53+
54+
VerifyOrReturnError(status == chip::Protocols::InteractionModel::Status::Success, CHIP_ERROR_WRITE_FAILED);
55+
56+
return CHIP_NO_ERROR;
57+
}
58+
3459
chip::NXP::App::AppTaskBase & chip::NXP::App::GetAppTask()
3560
{
3661
return LightingApp::AppTask::GetDefaultInstance();

examples/lighting-app/nxp/common/include/AppTask.h

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ namespace LightingApp {
2828
class AppTask : public chip::NXP::App::AppTaskFreeRTOS
2929
{
3030
public:
31+
// AppTaskBase virtual methods
32+
bool CheckStateClusterHandler(void) override;
33+
CHIP_ERROR ProcessSetStateClusterHandler(void) override;
34+
3135
// AppTaskFreeRTOS virtual methods
3236
void PreInitMatterStack() override;
3337

examples/lighting-app/nxp/k32w1/include/config/AppConfig.h

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#pragma once
1919

2020
/* ---- App Config ---- */
21-
#define APP_DEVICE_TYPE_ENDPOINT 1
22-
#define APP_CLUSTER_ATTRIBUTE chip::app::Clusters::OnOff::Attributes::OnOff
2321

2422
/* ---- Button Manager Config ---- */
2523
#define BUTTON_MANAGER_FACTORY_RESET_TIMEOUT_MS 6000

examples/lighting-app/nxp/mcxw71/include/config/AppConfig.h

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#pragma once
1919

2020
/* ---- App Config ---- */
21-
#define APP_DEVICE_TYPE_ENDPOINT 1
22-
#define APP_CLUSTER_ATTRIBUTE chip::app::Clusters::OnOff::Attributes::OnOff
2321

2422
/* ---- Button Manager Config ---- */
2523
#define BUTTON_MANAGER_FACTORY_RESET_TIMEOUT_MS 6000

examples/lock-app/nxp/README.md

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Matter NXP Door Lock Example Application
2+
3+
This reference application implements an Door Lock device type. It uses board
4+
buttons or `matter-cli` for user input and LEDs for state feedback. You can use
5+
this example as a reference for creating your own application.
6+
7+
The example is based on:
8+
9+
- [Matter](https://github.com/project-chip/connectedhomeip)
10+
- [NXP github SDK](https://github.com/nxp-mcuxpresso/mcux-sdk)
11+
12+
- [Matter NXP Door Lock Example Application](#matter-nxp-door-lock-example-application)
13+
- [Supported devices](#supported-devices)
14+
- [Introduction](#introduction)
15+
- [Device UI](#device-ui)
16+
- [Prerequisites for building](#prerequisites-for-building)
17+
- [Building](#building)
18+
- [Data model](#data-model)
19+
- [Manufacturing data](#manufacturing-data)
20+
- [Flashing and debugging](#flashing-and-debugging)
21+
22+
## Supported devices
23+
24+
- [k32w1](k32w1/README.md)
25+
- [mcxw71](mcxw71/README.md)
26+
27+
## Introduction
28+
29+
The application showcases a door lock device that communicates with clients over
30+
a low-power, 802.15.4 Thread network.
31+
32+
It can be commissioned into an existing Matter network using a controller such
33+
as `chip-tool`.
34+
35+
This example implements a `User-Intent Commissioning Flow`, meaning the user has
36+
to press a button in order for the device to be ready for commissioning. The
37+
initial commissioning is done through `ble-thread` pairing method.
38+
39+
The Thread network dataset will be transferred on the device using a secure
40+
session over Bluetooth LE. In order to start the commissioning process, the user
41+
must enable BLE advertising on the device manually. To pair successfully, the
42+
commissioner must know the commissioning information corresponding to the
43+
device: setup passcode and discriminator. This data is usually encoded within a
44+
QR code or printed to the UART console.
45+
46+
## Device UI
47+
48+
The example application provides a simple UI that depicts the state of the
49+
device and offers basic user control. This UI is implemented via the
50+
general-purpose LEDs and buttons built in the evaluation boards. Please see each
51+
supported device readme file for details.
52+
53+
## Prerequisites for building
54+
55+
In order to build the example, it is recommended to use a Linux distribution.
56+
Please visit the supported Operating Systems list in
57+
[BUILDING.md](../../../docs/guides/BUILDING.md#prerequisites).
58+
59+
- Make sure that below prerequisites are correctly installed (as described in
60+
[BUILDING.md](../../../docs/guides/BUILDING.md#prerequisites))
61+
62+
```
63+
sudo apt-get install git gcc g++ pkg-config libssl-dev libdbus-1-dev libglib2.0-dev libavahi-client-dev ninja-build python3-venv python3-dev python3-pip unzip libgirepository1.0-dev libcairo2-dev libreadline-dev
64+
```
65+
66+
- Step 1: checkout NXP specific submodules only
67+
68+
```
69+
user@ubuntu:~/Desktop/git/connectedhomeip$ scripts/checkout_submodules.py --shallow --platform nxp --recursive
70+
```
71+
72+
- Step 2: activate local environment
73+
74+
```
75+
user@ubuntu:~/Desktop/git/connectedhomeip$ source scripts/activate.sh
76+
```
77+
78+
If the script says the environment is out of date, you can update it by
79+
running the following command:
80+
81+
```
82+
user@ubuntu:~/Desktop/git/connectedhomeip$ source scripts/bootstrap.sh
83+
```
84+
85+
- Step 3: Init NXP SDK(s)
86+
87+
```
88+
user@ubuntu:~/Desktop/git/connectedhomeip$ third_party/nxp/nxp_matter_support/scripts/update_nxp_sdk.py --platform common
89+
```
90+
91+
Note: By default, `update_nxp_sdk.py` will try to initialize all NXP SDKs.
92+
Please run the script with arg `--help` to view all available options.
93+
94+
## Building
95+
96+
There are two options for building this reference app:
97+
98+
- Using `build_examples.py` framework.
99+
- Manually generating `ninja` files using `gn`.
100+
101+
For manual generation and building, please see the specific readme file for your
102+
device.
103+
104+
A list of all available contact sensor targets can be viewed in the following
105+
table:
106+
107+
| target name | description |
108+
| ---------------------------- | ---------------- |
109+
| nxp-device-freertos-lock-app | Default lock app |
110+
111+
where `device` can be one of the [Supported devices](#supported-devices).
112+
113+
### Data model
114+
115+
The application uses an NXP specific data model file:
116+
117+
| path | description |
118+
| ------------------ | ------------------------------------ |
119+
| `zap/lock-app.zap` | Data model for Door Lock device type |
120+
121+
The data model can be changed by simply replacing the gn `deps` statement
122+
corresponding to data model target.
123+
124+
### Manufacturing data
125+
126+
Use `chip_with_factory_data=1` in the gn build command to enable factory data.
127+
128+
For a full guide on manufacturing flow, please see
129+
[Guide for writing manufacturing data on NXP devices](../../../docs/guides/nxp/nxp_manufacturing_flow.md).
130+
131+
## Flashing and debugging
132+
133+
Please see the device specific readme file.

0 commit comments

Comments
 (0)