Skip to content

Commit

Permalink
[K32W0][THREADIP-3665] Improve shell application (#11194)
Browse files Browse the repository at this point in the history
* [K32W0][THREADIP-3665] Improve shell application

Shell application lacked a method for commissioning it to a Thread/Matter network:
* add commissioning support;
* run the shell functionality in a dedicated task.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

* Restyled by clang-format

* Restyled by gn

* [K32W] DIsable ot cli for the moment

Otherwise, the app won't fit into RAM0.

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

* Restyled by clang-format

* [K32W0] Fix variable type

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

* [K32W0] Disable low power build for the shell app

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Mar 22, 2022
1 parent 415fcc9 commit f20ed82
Show file tree
Hide file tree
Showing 11 changed files with 654 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/examples-k32w.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
timeout-minutes: 5
run: |
scripts/examples/k32w_example.sh \
examples/shell/nxp/k32w/k32w0 out/shell_app_debug
examples/shell/nxp/k32w/k32w0 out/shell_app_debug no_low_power
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
k32w k32w061+debug shell \
out/shell_app_debug/chip-k32w061-shell-example \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct AppEvent
kEventType_Install,
};

uint16_t Type;
AppEventTypes Type;

union
{
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/nxp/k32w/k32w0/main/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct AppEvent
#endif
};

uint16_t Type;
AppEventTypes Type;

union
{
Expand Down
11 changes: 8 additions & 3 deletions examples/shell/nxp/k32w/k32w0/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ k32w0_sdk("sdk") {
"main/include",
"main",
"include",
"${k32w0_platform_dir}/app/project_include",
"${k32w0_platform_dir}/app/support",
"${k32w0_platform_dir}/util/include",
]
Expand All @@ -54,16 +55,20 @@ k32w0_sdk("sdk") {
k32w0_executable("shell_app") {
output_name = "chip-k32w061-shell-example"

sources = [ "main/main.cpp" ]
sources = [
"${k32w0_platform_dir}/util/LEDWidget.cpp",
"${k32w0_platform_dir}/util/include/LEDWidget.h",
"main/AppTask.cpp",
"main/main.cpp",
]

deps = [
":sdk",
"${chip_root}/examples/lock-app/lock-common",
"${chip_root}/examples/shell/shell_common:shell_common",
"${chip_root}/src/lib",
"${chip_root}/third_party/mbedtls:mbedtls",
"${chip_root}/third_party/simw-top-mini:se05x",
"${k32w0_platform_dir}/app/support:freertos_mbedtls_utils",
"${openthread_root}:libopenthread-ftd",
]

cflags = [ "-Wconversion" ]
Expand Down
55 changes: 55 additions & 0 deletions examples/shell/nxp/k32w/k32w0/include/AppEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
*
* Copyright (c) 2021 Nest Labs, Inc.
* 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

struct AppEvent;
typedef void (*EventHandler)(AppEvent *);

struct AppEvent
{
enum AppEventTypes
{
kEventType_Button = 0,
kEventType_Timer,
kEventType_TurnOn,
kEventType_Install,
};

AppEventTypes Type;

union
{
struct
{
uint8_t PinNo;
uint8_t Action;
} ButtonEvent;
struct
{
void * Context;
} TimerEvent;
struct
{
uint8_t Action;
int32_t Actor;
} LightEvent;
};

EventHandler Handler;
};
88 changes: 88 additions & 0 deletions examples/shell/nxp/k32w/k32w0/include/AppTask.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
*
* Copyright (c) 2021 Google LLC.
* 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 <stdbool.h>
#include <stdint.h>

#include "AppEvent.h"

#include <platform/CHIPDeviceLayer.h>

#include "FreeRTOS.h"
#include "timers.h"

// Application-defined error codes in the CHIP_ERROR space.
#define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01)
#define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02)
#define APP_ERROR_UNHANDLED_EVENT CHIP_APPLICATION_ERROR(0x03)
#define APP_ERROR_CREATE_TIMER_FAILED CHIP_APPLICATION_ERROR(0x04)
#define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05)
#define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06)

class AppTask
{
public:
CHIP_ERROR StartAppTask();
static void AppTaskMain(void * pvParameter);
void PostEvent(const AppEvent * event);

private:
friend AppTask & GetAppTask(void);

CHIP_ERROR Init();

void CancelTimer(void);

void DispatchEvent(AppEvent * event);

static void FunctionTimerEventHandler(AppEvent * aEvent);
static void KBD_Callback(uint8_t events);
static void HandleKeyboard(void);
static void BleHandler(AppEvent * aEvent);
static void ResetActionEventHandler(AppEvent * aEvent);
static void InstallEventHandler(AppEvent * aEvent);

static void ButtonEventHandler(uint8_t pin_no, uint8_t button_action);
static void TimerEventHandler(TimerHandle_t xTimer);

static void ThreadProvisioningHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);

static void ThreadStart();
void StartTimer(uint32_t aTimeoutInMs);

enum Function_t
{
kFunction_NoneSelected = 0,
kFunction_SoftwareUpdate = 0,
kFunction_FactoryReset,

kFunction_Invalid
} Function;

Function_t mFunction = kFunction_NoneSelected;
bool mResetTimerActive = false;

static AppTask sAppTask;
};

inline AppTask & GetAppTask(void)
{
return AppTask::sAppTask;
}
25 changes: 23 additions & 2 deletions examples/shell/nxp/k32w/k32w0/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
*
* Enable support for CHIP-over-BLE (CHIPOBLE).
*/
#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0
#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1

/**
* CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC
Expand Down Expand Up @@ -176,10 +176,31 @@
*/
#define CHIP_DEVICE_CONFIG_BLE_ADVERTISING_TIMEOUT (15 * 60 * 1000)

/**
* CONFIG_CHIP_NFC_COMMISSIONING, CHIP_DEVICE_CONFIG_ENABLE_NFC
*
* Set these defines to 1 if NFC Commissioning is needed
*/
#define CONFIG_CHIP_NFC_COMMISSIONING 0

#define CHIP_DEVICE_CONFIG_ENABLE_NFC 0

/**
* CHIP_DEVICE_CONFIG_THREAD_FTD
*
* Shell Demo Application is a Thread SED (Sleepy End Device)
*/
#define CHIP_DEVICE_CONFIG_THREAD_FTD 0

/**
* @def CHIP_CONFIG_MAX_DEVICE_ADMINS
*
* @brief
* Maximum number of administrators that can provision the device. Each admin
* can provision the device with their unique operational credentials and manage
* their access control lists.
*/
#define CHIP_CONFIG_MAX_DEVICE_ADMINS 2 // 1 fabrics + 1 for rotation slack

/**
* CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE
*
Expand Down
Loading

0 comments on commit f20ed82

Please sign in to comment.