Skip to content

Commit

Permalink
[NXP] Adding Matter support for RW61x platform
Browse files Browse the repository at this point in the history
  • Loading branch information
dinabenamar committed Sep 7, 2023
1 parent ba45f9c commit d575057
Show file tree
Hide file tree
Showing 141 changed files with 52,700 additions and 2 deletions.
18 changes: 18 additions & 0 deletions build_overrides/nxp_sdk.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2020 Project CHIP Authors
#
# 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.

declare_args() {
# Root directory for NXP SDKs.
nxp_sdk_build_root = "//third_party/nxp"
}
33 changes: 33 additions & 0 deletions examples/all-clusters-app/nxp/common/main/AppAssert.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
* Copyright 2023 NXP
* 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 "fsl_debug_console.h"
#include <platform/CHIPDeviceLayer.h>

/*
* Assert function implemented in the application layer.
* This implementation would produce a reset.
* But it could be extended with specific application contrains/requirements.
*/
void __assert_func(const char *file, int line, const char *func, const char *failedExpr)
{
PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" function name \"%s\" \n", failedExpr, file, line, func);
chip::DeviceLayer::PlatformMgrImpl().Reset();
while(1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* Copyright 2023 NXP
* 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 "AppFactoryData.h"

#include <platform/CommissionableDataProvider.h>
#include <platform/DeviceInstanceInfoProvider.h>
#include <credentials/DeviceAttestationCredsProvider.h>

#if CONFIG_CHIP_PLAT_LOAD_REAL_FACTORY_DATA
#include "FactoryDataProvider.h"
/*
* Test key used to encrypt factory data before storing it to the flash.
*/
static const uint8_t aes128TestKey[] __attribute__((aligned)) = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
#else
#include <credentials/examples/DeviceAttestationCredsExample.h>
#endif

using namespace chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceLayer;

/**
* Allows to register Matter factory data before initializing the Matter stack
* Empty content here nothing particular to do.
*/
CHIP_ERROR AppFactoryData_PreMatterStackInit(void)
{
return CHIP_NO_ERROR;
}

/**
* Allows to register Matter factory data before initializing the Matter stack
* Load factory data.
*
* In this example we assume that the matter factory dataset is encrypted.
* This example demonstrates the usage of AES ecb with a software key.
*/
CHIP_ERROR AppFactoryData_PostMatterStackInit(void)
{
CHIP_ERROR err = CHIP_NO_ERROR;
#if CONFIG_CHIP_PLAT_LOAD_REAL_FACTORY_DATA
FactoryDataPrvdImpl().SetEncryptionMode(FactoryDataProvider::encrypt_ecb);
FactoryDataPrvdImpl().SetAes128Key(&aes128TestKey[0]);

err = FactoryDataPrvdImpl().Init();
if (err == CHIP_NO_ERROR)
{
SetDeviceInstanceInfoProvider(&FactoryDataPrvd());
SetDeviceAttestationCredentialsProvider(&FactoryDataPrvd());
SetCommissionableDataProvider(&FactoryDataPrvd());
}
#else
// Initialize device attestation with example one (only for debug purpose)
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
#endif
return err;
}
26 changes: 26 additions & 0 deletions examples/all-clusters-app/nxp/common/main/AppMatterButtonEmpty.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
* Copyright 2023 NXP
* 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 "AppMatterButton.h"

CHIP_ERROR AppMatterButton_registerButtons(void)
{
/* Empty content could be re-defined in a dedicated platform AppMatterButton_registerButtons function */
return CHIP_NO_ERROR;
}
138 changes: 138 additions & 0 deletions examples/all-clusters-app/nxp/common/main/AppMatterCli.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
* Copyright 2023 NXP
* 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 "AppMatterCli.h"
#include <cstring>
#include <platform/CHIPDeviceLayer.h>
#include "AppTask.h"
#include <app/server/Server.h>

#ifdef ENABLE_CHIP_SHELL
#include <lib/shell/Engine.h>
#include <ChipShellCollection.h>
#include "task.h"

#define MATTER_CLI_TASK_SIZE ((configSTACK_DEPTH_TYPE)2048 / sizeof(portSTACK_TYPE))
#define MATTER_CLI_LOG(message) (streamer_printf(streamer_get(), message))

using namespace chip::Shell;
TaskHandle_t AppMatterCliTaskHandle;
static bool isShellInitialized = false;
#else
#define MATTER_CLI_LOG(...)
#endif /* ENABLE_CHIP_SHELL */

void AppMatterCliTask(void * args)
{
#ifdef ENABLE_CHIP_SHELL
Engine::Root().RunMainLoop();
#endif /* ENABLE_CHIP_SHELL */
}

/* Application Matter CLI commands */

CHIP_ERROR commissioningManager(int argc, char * argv[])
{
CHIP_ERROR error = CHIP_NO_ERROR;
if (strncmp(argv[0], "on", 2) == 0)
{
GetAppTask().StartCommissioningHandler();
}
else if (strncmp(argv[0], "off", 3) == 0)
{
GetAppTask().StopCommissioningHandler();
}
else
{
MATTER_CLI_LOG("wrong args should be either \"mattercommissioning on\" or \"mattercommissioning off\"" );
error = CHIP_ERROR_INVALID_ARGUMENT;
}
return error;
}

CHIP_ERROR cliFactoryReset(int argc, char * argv[])
{
GetAppTask().FactoryResetHandler();
return CHIP_NO_ERROR;
}

CHIP_ERROR cliReset(int argc, char * argv[])
{
/*
Shutdown device before reboot,
this emits the ShutDown event, handles the server shutting down,
and stores in flash the total-operational-hours value.
*/
chip::DeviceLayer::PlatformMgr().Shutdown();
chip::DeviceLayer::PlatformMgrImpl().ScheduleResetInIdle();
return CHIP_NO_ERROR;
}


CHIP_ERROR AppMatterCli_RegisterCommands(void)
{
#ifdef ENABLE_CHIP_SHELL
if (!isShellInitialized)
{
int error = Engine::Root().Init();
if (error != 0)
{
ChipLogError(Shell, "Streamer initialization failed: %d", error);
return CHIP_ERROR_INTERNAL;
}

/* Register common shell commands */
cmd_misc_init();
cmd_otcli_init();
#if CHIP_SHELL_ENABLE_CMD_SERVER
cmd_app_server_init();
#endif /* CHIP_SHELL_ENABLE_CMD_SERVER */

/* Register application commands */
static const shell_command_t kCommands[] = {
{
.cmd_func = commissioningManager,
.cmd_name = "mattercommissioning",
.cmd_help = "Open/close the commissioning window. Usage : mattercommissioning [on|off]",
},
{
.cmd_func = cliFactoryReset,
.cmd_name = "matterfactoryreset",
.cmd_help = "Perform a factory reset on the device",
},
{
.cmd_func = cliReset,
.cmd_name = "matterreset",
.cmd_help = "Reset the device",
},
};

Engine::Root().RegisterCommands(kCommands, sizeof(kCommands) / sizeof(kCommands[0]));

if (xTaskCreate(&AppMatterCliTask, "AppMatterCli_task", MATTER_CLI_TASK_SIZE, NULL, 1, &AppMatterCliTaskHandle) != pdPASS)
{
ChipLogError(Shell, "Failed to start Matter CLI task");
return CHIP_ERROR_INTERNAL;
}
isShellInitialized = true;
}
#endif /* ENABLE_CHIP_SHELL */

return CHIP_NO_ERROR;
}
Loading

0 comments on commit d575057

Please sign in to comment.