Skip to content

Commit

Permalink
[NXP][k32w1] Rework reference apps (#34926)
Browse files Browse the repository at this point in the history
* [NXP][platform][common] Update pw RPC flag in streamer_nxp

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit 4ae033a1bddd5d914e862791c111eebca41a62e8)

* [NXP][examples][common] Fix binding issue due to generated Zap flag renaming

Signed-off-by: Martin Girardot <martin.girardot@nxp.com>
(cherry picked from commit b50b382478138ad02103e55194b0145b1e61e841)

* [NXP][examples][common] make-pretty update

(cherry picked from commit efc51cc65471f4f5f667947ef18a4656e1d29578)

* [NXP][examples][common] Fix contact-sensor-app always returning empty diagnostic logs

The LogProvider class method GetSizeForIntent() was always returning
zero as log size due to an incorrect evaluation of the result of the
SyncGetValue() call.

GetSizeForIntent() is evaluating the size of the diagnostic log by
trying to read the key using a zero length buffer. This action will
return the size of the key in storage, but it will also yield a
CHIP_ERROR_BUFFER_TOO_SMALL error code. GetSizeForIntent() however
was not expecting this error code and it was returning zero in all
situations when the status returned by SyncGetValue() was anything
else but CHIP_NO_ERROR.

The function was updated to take into account that, under these
circumstances, the SyncGetValue() function always returns
CHIP_ERROR_BUFFER_TOO_SMALL.

Signed-off-by: Marian Chereji <marian.chereji@nxp.com>
Reviewed-by: Doru-Cristian Gucea <doru-cristian.gucea@nxp.com>
(cherry picked from commit dd3b3b784318f73cf6f0390f79d1fdf0160169d3)

* [NXP][examples][common] Call init using the base class reference

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit b7a0a0a4d88bd5d03b70f36b34c2475b614bd296)

* [NXP][examples][common] Update app task common code

New task base API:
- PostEventsProcessedAction - this will be called in the main loop,
after all events have been processed. An example of concrete action
is to animate some LEDs.
- PrintOnboardingInfo - the default implementation remains the same.
It can be overwritten by the concrete application task class.
- AppMatter_DisallowDeviceToSleep/AppMatter_AllowDeviceToSleep -
An application that uses low power mode should overwrite the API to
implement the allow/disallow entering low power mechanism.
Before taking the OT mutex, the device is disallowed to enter low power.
The device is allowed to enter low power after the OT mutex is released.

Other changes:
- The app event queue handle should be static such that the concrete
application task can initialize it during Start() call.
- The ticksToWait passed to xQueueReceived is used to specify
the maximum amount of time the task should block waiting for an event.
This can be modified according to the application needs, e.g. is needed
by an application that has LED animation.
- PostEvent should take into account ISR context when populating the event queue.
- PostEvent becomes a static method.
- Thread device type is specified by the following flag: CONFIG_THREAD_DEVICE_TYPE
This is set by default to kThreadDeviceType_Router.

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit d88e78ea6c973eb736915110bb227ad3515eec98)

* [NXP][examples][common] Add additional common components

- Add led widget component
- Add diagnostic logs component - chip::NXP::App::DiagnosticLogsDemo::DisplayUsage
should be implemeneted to showcase how the diagnostic logs provider should be used.
- Add low power component - chip::NXP::App::LowPower::Init should be implemented
according to the application needs. A default example is implemented, which registers
an empty enter/exit low power callback.
- Add operational keystore component - the API contains two functions:
	- GetInstance - should return the address of a concrete operational keystore class
	- Init - can be used to register a persistent storage delegate in case the concrete
	  class is using persistent storage (which will be our case)
- Add user interface feedback component - this component defines an abstract interface
that can be implemented by applications in order to provide some kind of feedback to the user
in certain conditions: logging, LED animations, etc. Add example of lighting manager, which
uses LED animation for user feedback.
- Add clusters component - add an API for identify related callbacks. Add implementation for
common MatterPostAttributeChangeCallback, which delegates the work to the device manager component.
- Add RPC component - this is a simple Init API that can be used to initialize PW RPC related
components, such as UART.

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit 46a1d3d673b9cae14d33c749e3741727449e6ff9)

* [NXP][examples][common] Add missing header in Identify

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit 3abfee2c6eea327ae931a150733ac83639d157d5)

* [NXP][examples][common] Add multi-image OTA requestor initiator

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit 5848e4d4e2d384c4bfe41714bd41e25c4b1ba1e8)

* [NXP][examples][common] Update pw RPC implementation

Update AppRpc API by adding two new methods used by the common
RPC implementation:
- ButtonHandler
- Reboot

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit 5e40934145825c61444e43e479ed7ac5c26605a4)

* [NXP][examples][common] Small updates to common app code

- Add call to feedback manager init.
- Remove PostEventsProcessedAction. Call FeedbackMgr().DisplayInLoop()
directly in the main loop.
- Move PostEvent in AppTaskBase interface and make it virtual.
- Add demo of diagnostic logs usage.
- Update PrintOnboardingInfo to take into account user action requried
commissioning flow.
- Remove usage of deprecated sFunction from Lighting manager.
- Add LowPower::Init call.
- If FSL_OSA_TASK_ENABLE is used, then call AppTaskMain inside Start, instead
of creating the app task.
- Add PrintCurrentVersion API to print the software version string and software
version.
- Enclose DeviceInfoProviderImpl usage based on CONFIG_DEVICE_INFO_PROVIDER_IMPL
- Add diagnostic logs cluster init under the corresponding flag.

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit 1619c92380275dc0466f9cf9dc9e818671406b06)

* [NXP][examples][common] Make Animate pure virtual

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit eaf3789fc2d1e562fe030acc758e5f322b5f02d3)

* [NXP][examples][common] Add pw RPC init

RPC_TASK_STACK_SIZE and RPC_TASK_PRIORITY can now be defined
in the build system to override the default values.

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit 7962d612b14502dc3f514c5c3d39891b086cfd63)

* [NXP][examples][common] Allow platforms to redefine the path to the FactoryDataProvider.h that needs to be included

Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com>
(cherry picked from commit 097cd999c4767572f8cc55fac18f93ac3cb5d50c)

* [NXP][examples][common] Add TestEventTriggerDelegate

 * TestEventTriggerDelegate is now used at Server Initialization
   to add the ICDManager instance as Handler

Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
(cherry picked from commit edce1dc967130589e74cdd9c8289719171141178)

* [NXP][examples][common] Minor updates for some components

The KVS wear stats are stored in the user diagnostic log key hence only
initialize this key if the KVS wear stats are not enabled.

Signed-off-by: Marian Chereji <marian.chereji@nxp.com>

[nxp noup][examples][common] Remove UpdateState API

The interface can be simplified by calling RestoreState
instead of UpdateState when needed. This implies that the
caller must update the cluster attribute by itself.

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

[nxp noup][examples][common] Rename LightingManager to LedManager

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

* [NXP][examples][common] Add initial version of lighting app

- Copy lighting app sources to common folder
- Add device callbacks
- Use common OTA support
- Use common app factory data
- Use led widgets for lighting app
- Use common app task and button management
- Decouple lighting manager from app task
- Update LED status function
- Update lighting manager related flags
	Flags:
	- LIGHTING_MANAGER_ENABLE_DIMMABLE_LED to enable dimmable LED feature
	- LIGHTING_MANAGER_ENABLE_STATUS_LED to enable status LED usage
	These flags can be overwritten in AppConfig.h.
- Make lighting manager more configurable
- Create button manager
	The ButtonManager class should define the buttons callbacks and
	all callback delegates.

	Moved AppMatterButton_registerButtons implementation inside the
	button manager source file.
- Update lighting manager interface
- Replace lighting manager calls with feedback manager
	LightingManager now implements the UserFeedbackInterface abstract class and the
	dimmable feature was moved to a new class: LightingManagerDimmable.
- Move identify code in a separate file
- Remove deprecated #include statements from all files.
- Add commissioning complete state
	A boolean static member is added to AppTask. It is set when the
	kCommissioningComplete event is received. It should be used by
	other components if they need a way to check the state of the device.
- Add button action to switch to ICD active mode
- Add support for BooleanState in device callbacks
- Add diagnostic logs usage demo
- Enclose feedback manager calls in CONFIG_ENABLE_FEEDBACK flag
	This flag should be defined whenever the application must provide
	some kind of user interface feedback, such as LED animation.
	In case of low power, this flag will not be defined.
- Remove unused features (e.g. diagnostic logs)
- Overwrite event queue and ticks to wait
- Call PlatformMgrImpl API for PreInitMatterStack actions
- Replace PW_RPC_ENABLED with CONFIG_ENABLE_PW_RPC

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit bed6655227d44900279cbd0ef547771da9143895)

* [NXP][examples][common] Add initial version of contact sensor

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit 637580aa6c63048ae1a956807c284165c2af17ed)

* [NXP][openthread][k32w1] Update mbedtls target

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit 3c84b1fd3987958bc0dcf49a283c281e48b400f8)

* [NXP][platform][k32w] OTA/FactoryData changes

 * Add FactoryDataDriver interface which handles factory data update
   functionality and factory data ram backup operations;
   must be implemented for each platform
 * Make FactoryDataProvider global instances
 * Move Restore mechanism and plain-text SignWithDacKey in
   common FactoryDataProvider
 * Adapt Validate and SearchForId to use factory data config
   which stores size, start, payload
 * Move OTAFactoryDataProcessor in common folder
 * Adapt to be generic and use FactoryDataDriver functions instead

Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
(cherry picked from commit 3a81c2367013c2a2ed08ecbbeac89ce15943998e)

* [NXP][platform][k32w1] SDK 2.15 platform updates

 * remove RNG_SetPseudoRandomNoSeed call to accomodate new RNG API changes.
 * add SDK root, SDK release, and SDK 2.15 gn arguments. They will be used
   to differentiate between SDK versions (2.12 vs 2.15) and release
   status (repo vs packages).

Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>

[nxp noup][platform][k32w] Small fixes for k32w platform code

 * correct typos
 * remove executable access permissions
 * remove unused files
 * change openthread_root to ot-nxp/openthread-k32w1
 * use nxp_mbedtls gn target

Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
(cherry picked from commit 1905c1cea645506f8a88e514c2eacecea81ac385)

* [NXP][platform][k32w1] Add "chip_key_storage" solution selector and littlefs support

Updated the K32W1 platform build files by adding the "chip_key_storage"
selector which will help developers select an implementation option
for the key storage between "littlefs" and "fwk_nvm".

Signed-off-by: Marian Chereji <marian.chereji@nxp.com>

[nxp noup][k32w1] Temporarily disable OpenThread settings save-on-idle when using LittleFS key storage

When using LittleFS key storage, the OpenThread settings save-on-idle
feature requires additional support in the application idle task,
which is not yet available. In order for the OT settings saving to
work at this stage and in this configuration, the save-on-idle
feature must be disabled until the required idle task support will be
implemented.

Signed-off-by: Marian Chereji <marian.chereji@nxp.com>

[nxp noup][platform][k32w1] Fix minimum data chunk size required when programming the flash memory

According to the specifications, the internal flash memory of the
K32W1 platform supports programming chunks of memory which are 128
bytes long (instead of 256).

Signed-off-by: Marian Chereji <marian.chereji@nxp.com>

[nxp noup][platform][k32w1] Increase LittleFS cache size to 1K to suppress frequent data synchronizations

A small cache size forces LittleFS to perform frequent data
synchronizations with the storage (flash memory) and this consumes a
number of data blocks which are not available in the K32W1 Matter
applications. To reduce the fast consumption of flash memory data
blocks, the LittleFS cache size was increased to 1KB.

Signed-off-by: Marian Chereji <marian.chereji@nxp.com>
(cherry picked from commit 753f7d7390661bd5dbd29cc9cfa7d3a4e4728ba2)

* [NXP][platform][k32w1] Add Zephyr NVS based key storage build option

Added a new build option (chip_key_storage="nvs") which allows the
developers to use the Zephyr NVS file system as a key storage
solution.

Signed-off-by: Marian Chereji <marian.chereji@nxp.com>
(cherry picked from commit 1d42e48d8f50f6e9999b49025ea3d71545e89a3d)

* [NXP][examples][k32w1] App updates

 * the sdk root was moved to platform args.
 * update readme files
 * Add CONNECTIVITY_MANAGER_THREAD_DEVICE_TYPE define.
 * Set define accordingly based on FTD/MTD configuration.
 * Solve issue when lighting-app is MTD but device type is set to
   Router because it was hardcoded.
 * Remove deprecated files
 * Move some headers in examples/platform for common usage

Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
(cherry picked from commit c2b626df132e058ce674df0ee20965b3029c462d)

* [NXP][examples][k32w1] Update ZclCallbacks after transition to common code

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

* [NXP][k32w1] Remove k32w parent folder

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

* [NXP][platform][k32w1] Add FactoryDataDriver implementation

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

* [NXP][platform][k32w] Remove k32w/common

This folder was moved to nxp/common/legacy area.

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit 755081c71bde287e2d065e5fd9b1a0922c3b341a)

* [NXP][scripts] Minor updates for NXP related scripts

Add HWParams APP FactoryData support

 * Add proper format for HWParameters app factory data section
 * Put changes under new argument

Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>

[nxp noup][scripts][common] Fix Crc16 attribute when using latest version

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

[nxp noup][scripts] Update structure k32w1 path

All k32w1 folders were moved under nxp, removing the k32w parent.

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

[nxp noup][scripts][ota] Update paths after k32w transition

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit 4963ce98725b74e94f498f959d46edf4933fa56c)

* [NXP][platform][common] Add nxp_factory_data, nxp_ota gn targets

The application can use these targets to integrate the default, platform-specific
NXP factory data provider and OTA implementation. Each platform should define an
"nxp_factory_data" and "nxp_ota" source sets.

Usage:
deps += [ "${chip_root}/src/platform/nxp:nxp_factory_data" ]
deps += [ "${chip_root}/src/platform/nxp:nxp_ota" ]

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
(cherry picked from commit 4869c4a97134692fe87a59b9b69d33f836d9b2e9)

* [NXP][platform][common] Create NXPConfigNVS.cpp file, remove NXPConfig BLE dependencies

Signed-off-by: Martin Girardot <martin.girardot@nxp.com>
(cherry picked from commit 50e14e4a1b9f8561126310e19ebbaf72ca7bbdbe)

* [NXP] revert mcxw71 headers

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

* [NXP][k32w1] Add default logging target

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

* [NXP][k32w1] Update paths to reference nxp_matter_support

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

* [NXP] Bump nxp_matter_support

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

* Restyled by whitespace

* Restyled by clang-format

* Restyled by gn

* Restyled by prettier-markdown

* Restyled by autopep8

* Restyled by isort

* [NXP][k32w1] Fix gn import order

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

* [NXP][k32w1] Fix wrong README reference

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

* [NXP][k32w1] Update workflow docker image

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

* [NXP][rw61x] Adding nxp_ota and nxp_factory_data as they are now mandatory

Signed-off-by: Gatien Chapon <gatien.chapon@nxp.com>

* [NXP][platform][common] Fix build warning

(cherry picked from commit 72b1cbaaf36fe6cf2af57a8c7ad3cc457b45c713)

* Restyled by gn

* [NXP][platform] Remove deprecated files

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

* [NXP][workflow] Create separate jobs for k32w0/k32w1

k32w0 builds use chip-build-k32w Docker image, but k32w1 builds
use chip-build-nxp Docker image.

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

* [NXP][k32w0] Adding nxp_ota and nxp_factory_data as they are now mandatory

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

* [NXP][scripts] Fix script issue when there is no --args

Signed-off-by: Martin Girardot <martin.girardot@nxp.com>

* [NXP][k32w1] Disable SMU2

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>

---------

Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
Signed-off-by: Gatien Chapon <gatien.chapon@nxp.com>
Signed-off-by: Martin Girardot <martin.girardot@nxp.com>
Co-authored-by: Martin Girardot <martin.girardot@nxp.com>
Co-authored-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com>
Co-authored-by: Marian Chereji <marian.chereji@nxp.com>
Co-authored-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: Gatien Chapon <gatien.chapon@nxp.com>
Co-authored-by: Yassine El Aissaoui <yassine.elaissaoui@nxp.com>
  • Loading branch information
8 people authored and pull[bot] committed Sep 30, 2024
1 parent bcf59d0 commit 4225108
Show file tree
Hide file tree
Showing 183 changed files with 4,708 additions and 7,959 deletions.
64 changes: 54 additions & 10 deletions .github/workflows/examples-nxp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ env:
CHIP_NO_LOG_TIMESTAMPS: true

jobs:
k32w:
name: K32W
k32w0:
name: K32W0

env:
BUILD_TYPE: gn_k32w
Expand All @@ -39,7 +39,7 @@ jobs:
if: github.actor != 'restyled-io[bot]'

container:
image: ghcr.io/project-chip/chip-build-k32w:66
image: ghcr.io/project-chip/chip-build-k32w:71
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"
steps:
Expand All @@ -66,8 +66,6 @@ jobs:
--target nxp-k32w0-freertos-contact-sensor \
--target nxp-k32w0-freertos-contact-sensor-low-power \
--target nxp-k32w0-freertos-contact-sensor-low-power-factory \
--target nxp-k32w1-freertos-lighting \
--target nxp-k32w1-freertos-contact-sensor-low-power \
build \
--copy-artifacts-to out/artifacts \
"
Expand All @@ -77,16 +75,62 @@ jobs:
nxp k32w0+release light \
out/artifacts/nxp-k32w0-freertos-lighting/chip-k32w0x-light-example.elf \
/tmp/bloat_reports/
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
nxp k32w1+release light \
out/artifacts/nxp-k32w1-freertos-lighting/chip-k32w1-light-example.elf \
/tmp/bloat_reports/
- name: Get contact sensor size stats
run: |
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
nxp k32w0+release contact \
out/artifacts/nxp-k32w0-freertos-contact-sensor-low-power/chip-k32w0x-contact-example.elf \
/tmp/bloat_reports/
- name: Uploading Size Reports
uses: ./.github/actions/upload-size-reports
if: ${{ !env.ACT }}
with:
platform-name: K32W0
k32w1:
name: K32W1

env:
BUILD_TYPE: gn_k32w

runs-on: ubuntu-latest
if: github.actor != 'restyled-io[bot]'

container:
image: ghcr.io/project-chip/chip-build-nxp:71
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout submodules & Bootstrap
uses: ./.github/actions/checkout-submodules-and-bootstrap
with:
platform: nxp
extra-submodule-parameters: --recursive

- name: Set up environment for size reports
uses: ./.github/actions/setup-size-reports
if: ${{ !env.ACT }}
with:
gh-context: ${{ toJson(github) }}

- name: Build examples
run: |
scripts/run_in_build_env.sh "\
./scripts/build/build_examples.py \
--target nxp-k32w1-freertos-lighting \
--target nxp-k32w1-freertos-contact-sensor-low-power \
build \
--copy-artifacts-to out/artifacts \
"
- name: Get lighting app size stats
run: |
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
nxp k32w1+release light \
out/artifacts/nxp-k32w1-freertos-lighting/chip-k32w1-light-example.elf \
/tmp/bloat_reports/
- name: Get contact sensor size stats
run: |
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
nxp k32w1+release contact \
out/artifacts/nxp-k32w1-freertos-contact-sensor-low-power/chip-k32w1-contact-example.elf \
Expand All @@ -95,7 +139,7 @@ jobs:
uses: ./.github/actions/upload-size-reports
if: ${{ !env.ACT }}
with:
platform-name: K32W
platform-name: K32W1
rw61x:
name: RW61X

Expand Down
53 changes: 53 additions & 0 deletions examples/contact-sensor-app/nxp/common/AppTask.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "AppTask.h"

#if CONFIG_LOW_POWER
#include "PWR_Interface.h"
#endif

#include <platform/CHIPDeviceLayer.h>

void ContactSensorApp::AppTask::PreInitMatterStack()
{
ChipLogProgress(DeviceLayer, "Welcome to NXP Contact Sensor Demo App");
}

#if CONFIG_LOW_POWER
void ContactSensorApp::AppTask::AppMatter_DisallowDeviceToSleep()
{
PWR_DisallowDeviceToSleep();
}

void ContactSensorApp::AppTask::AppMatter_AllowDeviceToSleep()
{
PWR_AllowDeviceToSleep();
}
#endif

ContactSensorApp::AppTask & ContactSensorApp::AppTask::GetDefaultInstance()
{
static ContactSensorApp::AppTask sAppTask;
return sAppTask;
}

chip::NXP::App::AppTaskBase & chip::NXP::App::GetAppTask()
{
return ContactSensorApp::AppTask::GetDefaultInstance();
}
69 changes: 69 additions & 0 deletions examples/contact-sensor-app/nxp/common/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <lib/support/logging/CHIPLogging.h>

#include "DeviceCallbacks.h"
#if CONFIG_ENABLE_FEEDBACK
#include "UserInterfaceFeedback.h"
#endif

#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/EventLogging.h>

using namespace ::chip;
using namespace ::chip::app::Clusters;

void logBooleanStateEvent(bool state)
{
chip::EventNumber eventNumber;
chip::app::Clusters::BooleanState::Events::StateChange::Type event{ state };
if (CHIP_NO_ERROR != chip::app::LogEvent(event, 1, eventNumber))
{
ChipLogProgress(Zcl, "booleanstate: failed to reacord state-change event");
}
}

void ContactSensorApp::DeviceCallbacks::PostAttributeChangeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
chip::AttributeId attributeId, uint8_t type, uint16_t size,
uint8_t * value)
{
if (clusterId == BooleanState::Id)
{
if (attributeId != BooleanState::Attributes::StateValue::Id)
{
ChipLogProgress(Zcl, "Unknown attribute ID: " ChipLogFormatMEI, ChipLogValueMEI(attributeId));
return;
}
#if CONFIG_ENABLE_FEEDBACK
FeedbackMgr().RestoreState();
#endif
logBooleanStateEvent(static_cast<bool>(*value));
}
else
{
ChipLogProgress(Zcl, "Unknown attribute ID: " ChipLogFormatMEI, ChipLogValueMEI(attributeId));
}
}

chip::DeviceManager::CHIPDeviceManagerCallbacks & chip::NXP::App::GetDeviceCallbacks()
{
static ContactSensorApp::DeviceCallbacks sDeviceCallbacks;
return sDeviceCallbacks;
}
38 changes: 38 additions & 0 deletions examples/contact-sensor-app/nxp/common/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <app-common/zap-generated/cluster-objects.h>
#include <lib/support/logging/CHIPLogging.h>

#if CONFIG_ENABLE_FEEDBACK
#include "UserInterfaceFeedback.h"
#endif

/** @brief BooleanState Cluster Init
*
* This function is called when a specific cluster is initialized. It gives the
* application an opportunity to take care of cluster initialization procedures.
* It is called exactly once for each endpoint where cluster is present.
*/
void emberAfBooleanStateClusterInitCallback(chip::EndpointId endpoint)
{
ChipLogProgress(Zcl, "emberAfBooleanStateClusterInitCallback\n");
#if CONFIG_ENABLE_FEEDBACK
FeedbackMgr().RestoreState();
#endif
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,16 +16,12 @@
* limitations under the License.
*/

#include "DefaultTestEventTriggerDelegate.h"
#pragma once

#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>
struct AppEvent;
typedef void (*EventHandler)(const AppEvent &);

namespace chip {

bool DefaultTestEventTriggerDelegate::DoesEnableKeyMatch(const ByteSpan & enableKey) const
struct AppEvent
{
return !mEnableKey.empty() && mEnableKey.data_equal(enableKey);
}

} // namespace chip
EventHandler Handler;
};
50 changes: 50 additions & 0 deletions examples/contact-sensor-app/nxp/common/include/AppTask.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "AppConfig.h"
#include "AppTaskFreeRTOS.h"

#include <platform/CHIPDeviceLayer.h>

namespace ContactSensorApp {

class AppTask : public chip::NXP::App::AppTaskFreeRTOS
{
public:
// AppTaskFreeRTOS virtual methods
void PreInitMatterStack() override;
#if CONFIG_LOW_POWER
void AppMatter_DisallowDeviceToSleep() override;
void AppMatter_AllowDeviceToSleep() override;
#endif

// This returns an instance of this class.
static AppTask & GetDefaultInstance();
};

} // namespace ContactSensorApp

/**
* Returns the application-specific implementation of the AppTaskBase object.
*
* Applications can use this to gain access to features of the AppTaskBase
* that are specific to the selected application.
*/
chip::NXP::App::AppTaskBase & GetAppTask();
Loading

0 comments on commit 4225108

Please sign in to comment.