Skip to content

Commit

Permalink
[NXP] Add lock app example (#35536)
Browse files Browse the repository at this point in the history
* [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>
  • Loading branch information
3 people authored Sep 13, 2024
1 parent d60a126 commit 74cba6d
Show file tree
Hide file tree
Showing 48 changed files with 4,371 additions and 264 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/examples-nxp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ jobs:
./scripts/build/build_examples.py \
--target nxp-k32w1-freertos-lighting \
--target nxp-k32w1-freertos-contact-sensor-low-power \
--target nxp-k32w1-freertos-lock-app \
build \
--copy-artifacts-to out/artifacts \
"
Expand All @@ -135,6 +136,12 @@ jobs:
nxp k32w1+release contact \
out/artifacts/nxp-k32w1-freertos-contact-sensor-low-power/chip-k32w1-contact-example.elf \
/tmp/bloat_reports/
- name: Get lock app size stats
run: |
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
nxp k32w1+release lock \
out/artifacts/nxp-k32w1-freertos-lock-app/chip-k32w1-lock-example.elf \
/tmp/bloat_reports/
- name: Uploading Size Reports
uses: ./.github/actions/upload-size-reports
if: ${{ !env.ACT }}
Expand Down Expand Up @@ -174,6 +181,7 @@ jobs:
./scripts/build/build_examples.py \
--target nxp-mcxw71-freertos-lighting \
--target nxp-mcxw71-freertos-contact-sensor-low-power \
--target nxp-mcxw71-freertos-lock-app \
build \
--copy-artifacts-to out/artifacts \
"
Expand All @@ -189,6 +197,12 @@ jobs:
nxp mcxw71+release contact \
out/artifacts/nxp-mcxw71-freertos-contact-sensor-low-power/chip-mcxw71-contact-example.elf \
/tmp/bloat_reports/
- name: Get lock app size stats
run: |
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
nxp mcxw71+release lock \
out/artifacts/nxp-mcxw71-freertos-lock-app/chip-mcxw71-lock-example.elf \
/tmp/bloat_reports/
- name: Uploading Size Reports
uses: ./.github/actions/upload-size-reports
if: ${{ !env.ACT }}
Expand Down
25 changes: 25 additions & 0 deletions examples/contact-sensor-app/nxp/common/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@
#include "PWR_Interface.h"
#endif

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

#ifndef APP_DEVICE_TYPE_ENDPOINT
#define APP_DEVICE_TYPE_ENDPOINT 1
#endif

using namespace chip::app::Clusters;

void ContactSensorApp::AppTask::PreInitMatterStack()
{
ChipLogProgress(DeviceLayer, "Welcome to NXP Contact Sensor Demo App");
Expand All @@ -47,6 +54,24 @@ ContactSensorApp::AppTask & ContactSensorApp::AppTask::GetDefaultInstance()
return sAppTask;
}

bool ContactSensorApp::AppTask::CheckStateClusterHandler(void)
{
bool val = false;
BooleanState::Attributes::StateValue::Get(APP_DEVICE_TYPE_ENDPOINT, &val);
return val;
}

CHIP_ERROR ContactSensorApp::AppTask::ProcessSetStateClusterHandler(void)
{
bool val = false;
BooleanState::Attributes::StateValue::Get(APP_DEVICE_TYPE_ENDPOINT, &val);
auto status = BooleanState::Attributes::StateValue::Set(APP_DEVICE_TYPE_ENDPOINT, (bool) !val);

VerifyOrReturnError(status == chip::Protocols::InteractionModel::Status::Success, CHIP_ERROR_WRITE_FAILED);

return CHIP_NO_ERROR;
}

chip::NXP::App::AppTaskBase & chip::NXP::App::GetAppTask()
{
return ContactSensorApp::AppTask::GetDefaultInstance();
Expand Down
4 changes: 4 additions & 0 deletions examples/contact-sensor-app/nxp/common/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ namespace ContactSensorApp {
class AppTask : public chip::NXP::App::AppTaskFreeRTOS
{
public:
// AppTaskBase virtual methods
bool CheckStateClusterHandler(void) override;
CHIP_ERROR ProcessSetStateClusterHandler(void) override;

// AppTaskFreeRTOS virtual methods
void PreInitMatterStack() override;
#if CONFIG_LOW_POWER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#pragma once

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

/* ---- Button Manager Config ---- */
#define BUTTON_MANAGER_FACTORY_RESET_TIMEOUT_MS 6000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#pragma once

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

/* ---- Button Manager Config ---- */
#define BUTTON_MANAGER_FACTORY_RESET_TIMEOUT_MS 6000
Expand Down
6 changes: 3 additions & 3 deletions examples/lighting-app/nxp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ where `device` can be one of the [Supported devices](#supported-devices).
The application uses an NXP specific data model file:
| path | description |
| ----------------------------- | --------------------------------------- |
| `zap-lit/lighting-on-off.zap` | Data model for On/Off Light device type |
| path | description |
| ------------------------- | --------------------------------------- |
| `zap/lighting-on-off.zap` | Data model for On/Off Light device type |
The data model can be changed by simply replacing the gn `deps` statement
corresponding to data model target.
Expand Down
25 changes: 25 additions & 0 deletions examples/lighting-app/nxp/common/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@

#include "AppTask.h"

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

#ifndef APP_DEVICE_TYPE_ENDPOINT
#define APP_DEVICE_TYPE_ENDPOINT 1
#endif

using namespace chip::app::Clusters;

void LightingApp::AppTask::PreInitMatterStack()
{
ChipLogProgress(DeviceLayer, "Welcome to NXP Lighting Demo App");
Expand All @@ -31,6 +38,24 @@ LightingApp::AppTask & LightingApp::AppTask::GetDefaultInstance()
return sAppTask;
}

bool LightingApp::AppTask::CheckStateClusterHandler(void)
{
bool val = false;
OnOff::Attributes::OnOff::Get(APP_DEVICE_TYPE_ENDPOINT, &val);
return val;
}

CHIP_ERROR LightingApp::AppTask::ProcessSetStateClusterHandler(void)
{
bool val = false;
OnOff::Attributes::OnOff::Get(APP_DEVICE_TYPE_ENDPOINT, &val);
auto status = OnOff::Attributes::OnOff::Set(APP_DEVICE_TYPE_ENDPOINT, (bool) !val);

VerifyOrReturnError(status == chip::Protocols::InteractionModel::Status::Success, CHIP_ERROR_WRITE_FAILED);

return CHIP_NO_ERROR;
}

chip::NXP::App::AppTaskBase & chip::NXP::App::GetAppTask()
{
return LightingApp::AppTask::GetDefaultInstance();
Expand Down
4 changes: 4 additions & 0 deletions examples/lighting-app/nxp/common/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ namespace LightingApp {
class AppTask : public chip::NXP::App::AppTaskFreeRTOS
{
public:
// AppTaskBase virtual methods
bool CheckStateClusterHandler(void) override;
CHIP_ERROR ProcessSetStateClusterHandler(void) override;

// AppTaskFreeRTOS virtual methods
void PreInitMatterStack() override;

Expand Down
2 changes: 0 additions & 2 deletions examples/lighting-app/nxp/k32w1/include/config/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#pragma once

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

/* ---- Button Manager Config ---- */
#define BUTTON_MANAGER_FACTORY_RESET_TIMEOUT_MS 6000
Expand Down
2 changes: 0 additions & 2 deletions examples/lighting-app/nxp/mcxw71/include/config/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#pragma once

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

/* ---- Button Manager Config ---- */
#define BUTTON_MANAGER_FACTORY_RESET_TIMEOUT_MS 6000
Expand Down
133 changes: 133 additions & 0 deletions examples/lock-app/nxp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Matter NXP Door Lock Example Application

This reference application implements an Door Lock device type. It uses board
buttons or `matter-cli` for user input and LEDs for state feedback. You can use
this example as a reference for creating your own application.

The example is based on:

- [Matter](https://github.com/project-chip/connectedhomeip)
- [NXP github SDK](https://github.com/nxp-mcuxpresso/mcux-sdk)

- [Matter NXP Door Lock Example Application](#matter-nxp-door-lock-example-application)
- [Supported devices](#supported-devices)
- [Introduction](#introduction)
- [Device UI](#device-ui)
- [Prerequisites for building](#prerequisites-for-building)
- [Building](#building)
- [Data model](#data-model)
- [Manufacturing data](#manufacturing-data)
- [Flashing and debugging](#flashing-and-debugging)

## Supported devices

- [k32w1](k32w1/README.md)
- [mcxw71](mcxw71/README.md)

## Introduction

The application showcases a door lock device that communicates with clients over
a low-power, 802.15.4 Thread network.

It can be commissioned into an existing Matter network using a controller such
as `chip-tool`.

This example implements a `User-Intent Commissioning Flow`, meaning the user has
to press a button in order for the device to be ready for commissioning. The
initial commissioning is done through `ble-thread` pairing method.

The Thread network dataset will be transferred on the device using a secure
session over Bluetooth LE. In order to start the commissioning process, the user
must enable BLE advertising on the device manually. To pair successfully, the
commissioner must know the commissioning information corresponding to the
device: setup passcode and discriminator. This data is usually encoded within a
QR code or printed to the UART console.

## Device UI

The example application provides a simple UI that depicts the state of the
device and offers basic user control. This UI is implemented via the
general-purpose LEDs and buttons built in the evaluation boards. Please see each
supported device readme file for details.

## Prerequisites for building

In order to build the example, it is recommended to use a Linux distribution.
Please visit the supported Operating Systems list in
[BUILDING.md](../../../docs/guides/BUILDING.md#prerequisites).

- Make sure that below prerequisites are correctly installed (as described in
[BUILDING.md](../../../docs/guides/BUILDING.md#prerequisites))

```
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
```

- Step 1: checkout NXP specific submodules only

```
user@ubuntu:~/Desktop/git/connectedhomeip$ scripts/checkout_submodules.py --shallow --platform nxp --recursive
```
- Step 2: activate local environment
```
user@ubuntu:~/Desktop/git/connectedhomeip$ source scripts/activate.sh
```
If the script says the environment is out of date, you can update it by
running the following command:
```
user@ubuntu:~/Desktop/git/connectedhomeip$ source scripts/bootstrap.sh
```
- Step 3: Init NXP SDK(s)
```
user@ubuntu:~/Desktop/git/connectedhomeip$ third_party/nxp/nxp_matter_support/scripts/update_nxp_sdk.py --platform common
```
Note: By default, `update_nxp_sdk.py` will try to initialize all NXP SDKs.
Please run the script with arg `--help` to view all available options.
## Building
There are two options for building this reference app:
- Using `build_examples.py` framework.
- Manually generating `ninja` files using `gn`.
For manual generation and building, please see the specific readme file for your
device.
A list of all available contact sensor targets can be viewed in the following
table:
| target name | description |
| ---------------------------- | ---------------- |
| nxp-device-freertos-lock-app | Default lock app |
where `device` can be one of the [Supported devices](#supported-devices).
### Data model
The application uses an NXP specific data model file:
| path | description |
| ------------------ | ------------------------------------ |
| `zap/lock-app.zap` | Data model for Door Lock device type |
The data model can be changed by simply replacing the gn `deps` statement
corresponding to data model target.
### Manufacturing data
Use `chip_with_factory_data=1` in the gn build command to enable factory data.
For a full guide on manufacturing flow, please see
[Guide for writing manufacturing data on NXP devices](../../../docs/guides/nxp/nxp_manufacturing_flow.md).
## Flashing and debugging
Please see the device specific readme file.
Loading

0 comments on commit 74cba6d

Please sign in to comment.