Infineon CYW30739 - lighting-app support (#13491)
diff --git a/.github/.wordlist.txt b/.github/.wordlist.txt
index ecb117a..623f75e 100644
--- a/.github/.wordlist.txt
+++ b/.github/.wordlist.txt
@@ -27,6 +27,7 @@
AddOrUpdateThreadNetwork
AddOrUpdateWiFiNetwork
addr
+AddThreadNetwork
adk
adoc
AdvAutonomous
@@ -252,6 +253,7 @@
cvfJ
cxx
CY
+CYW
DAC
DAP
DataFrame
@@ -357,6 +359,7 @@
elock
emberAfExternalAttributeReadCallback
emberAfExternalAttributeWriteCallback
+EnableNetwork
EnableWiFiNetwork
EndpointId
endpointName
diff --git a/.github/workflows/examples-cyw30739.yaml b/.github/workflows/examples-cyw30739.yaml
new file mode 100644
index 0000000..b9cc62b
--- /dev/null
+++ b/.github/workflows/examples-cyw30739.yaml
@@ -0,0 +1,82 @@
+# Copyright (c) 2021 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.
+
+name: Build example - Infineon CYW30739
+
+on:
+ push:
+ pull_request:
+
+concurrency:
+ group: ${{ github.ref }}-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.number) || (github.event_name == 'workflow_dispatch' && github.run_number) || github.sha }}
+ cancel-in-progress: true
+
+jobs:
+ cyw30739:
+ name: CYW30739
+ timeout-minutes: 60
+
+ runs-on: ubuntu-latest
+ if: github.actor != 'restyled-io[bot]'
+
+ container:
+ image: connectedhomeip/chip-build:latest
+ volumes:
+ - "/tmp/bloat_reports:/tmp/bloat_reports"
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+ with:
+ submodules: true
+
+ - name: Set up environment for size reports
+ if: ${{ !env.ACT }}
+ env:
+ GH_CONTEXT: ${{ toJson(github) }}
+ run: scripts/tools/memory/gh_sizes_environment.py "${GH_CONTEXT}"
+
+ - name: Bootstrap
+ timeout-minutes: 25
+ run: scripts/build/gn_bootstrap.sh
+ - name: Uploading bootstrap logs
+ uses: actions/upload-artifact@v2
+ if: ${{ always() }} && ${{ !env.ACT }}
+ with:
+ name: bootstrap-logs
+ path: |
+ .environment/gn_out/.ninja_log
+ .environment/pigweed-venv/*.log
+ - name: Build example CYW30739 Lighting App
+ timeout-minutes: 10
+ run: |
+ ./scripts/run_in_build_env.sh \
+ "./scripts/build/build_examples.py \
+ --target cyw30739-cyw930739m2evb_01-light \
+ build \
+ --copy-artifacts-to out/artifacts \
+ "
+ - name: Get light size stats
+ timeout-minutes: 5
+ run: |
+ .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
+ cyw30739 cyw930739m2evb_01 light \
+ out/artifacts/cyw30739-cyw930739m2evb_01-light/chip-cyw30739-lighting-example.elf \
+ /tmp/bloat_reports/
+ - name: Uploading Size Reports
+ uses: actions/upload-artifact@v2
+ if: ${{ !env.ACT }}
+ with:
+ name: Size,CYW30739-Examples,${{ env.GH_EVENT_PR }},${{ env.GH_EVENT_HASH }},${{ env.GH_EVENT_PARENT }},${{ github.event_name }}
+ path: |
+ /tmp/bloat_reports/
diff --git a/.gitmodules b/.gitmodules
index b8f7b08..6a548e7 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -79,6 +79,10 @@
[submodule "third_party/openthread/ot-efr32"]
path = third_party/openthread/ot-efr32
url = https://github.com/openthread/ot-efr32.git
+[submodule "third_party/openthread/ot-ifx"]
+ path = third_party/openthread/ot-ifx
+ url = https://github.com/Infineon/ot-ifx-release.git
+ branch = cyw30739
[submodule "third_party/mbed-os/repo"]
path = third_party/mbed-os/repo
url = https://github.com/ARMmbed/mbed-os.git
@@ -165,3 +169,15 @@
[submodule "third_party/jsoncpp/repo"]
path = third_party/jsoncpp/repo
url = https://github.com/open-source-parsers/jsoncpp.git
+[submodule "cyw30739_sdk/30739A0"]
+ path = third_party/cyw30739_sdk/repos/30739A0
+ url = https://github.com/Infineon/30739A0.git
+[submodule "cyw30739_sdk/include"]
+ path = third_party/cyw30739_sdk/repos/btsdk-include
+ url = https://github.com/Infineon/btsdk-include.git
+[submodule "cyw30739_sdk/target"]
+ path = third_party/cyw30739_sdk/repos/CYW930739M2EVB-01
+ url = https://github.com/Infineon/TARGET_CYW930739M2EVB-01.git
+[submodule "cyw30739_sdk/tools"]
+ path = third_party/cyw30739_sdk/repos/btsdk-tools
+ url = https://github.com/Infineon/btsdk-tools.git
diff --git a/examples/build_overrides/cyw30739_sdk.gni b/examples/build_overrides/cyw30739_sdk.gni
new file mode 100644
index 0000000..d2c81de
--- /dev/null
+++ b/examples/build_overrides/cyw30739_sdk.gni
@@ -0,0 +1,19 @@
+# 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 CYW30739 SDK.
+ cyw30739_sdk_build_root =
+ "//third_party/connectedhomeip/third_party/cyw30739_sdk"
+}
diff --git a/examples/lighting-app/cyw30739/.gn b/examples/lighting-app/cyw30739/.gn
new file mode 100644
index 0000000..90115e4
--- /dev/null
+++ b/examples/lighting-app/cyw30739/.gn
@@ -0,0 +1,28 @@
+# 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.
+
+import("//build_overrides/build.gni")
+
+# The location of the build configuration file.
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
+
+# CHIP uses angle bracket includes.
+check_system_includes = true
+
+default_args = {
+ target_cpu = "arm"
+ target_os = "cyw30739"
+
+ import("//args.gni")
+}
diff --git a/examples/lighting-app/cyw30739/BUILD.gn b/examples/lighting-app/cyw30739/BUILD.gn
new file mode 100644
index 0000000..8912b05
--- /dev/null
+++ b/examples/lighting-app/cyw30739/BUILD.gn
@@ -0,0 +1,68 @@
+# 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.
+
+import("//build_overrides/build.gni")
+import("//build_overrides/chip.gni")
+import("//build_overrides/cyw30739_sdk.gni")
+
+import("${cyw30739_sdk_build_root}/cyw30739_executable.gni")
+import("${cyw30739_sdk_build_root}/cyw30739_sdk.gni")
+
+cyw30739_project_dir = "${chip_root}/examples/lighting-app/cyw30739"
+
+declare_args() {
+ setupPinCode = 0
+ setupDiscriminator = 0
+}
+
+cyw30739_sdk("sdk") {
+ sources = [ "${cyw30739_project_dir}/include/CHIPProjectConfig.h" ]
+
+ include_dirs = [ "${cyw30739_project_dir}/include" ]
+
+ defines = [
+ "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}",
+ "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${setupDiscriminator}",
+ ]
+}
+
+cyw30739_executable("lighting_app") {
+ output_name = "chip-cyw30739-lighting-example.elf"
+
+ sources = [
+ "src/AppShellCommands.cpp",
+ "src/ButtonHandler.cpp",
+ "src/LightingManager.cpp",
+ "src/ZclCallbacks.cpp",
+ "src/main.cpp",
+ ]
+
+ deps = [
+ ":sdk",
+ "${chip_root}/examples/lighting-app/lighting-common",
+ "${chip_root}/examples/shell/shell_common:shell_common",
+ "${chip_root}/src/lib",
+ "${chip_root}/third_party/openthread/repo:libopenthread-ftd",
+ ]
+
+ include_dirs = [ "include" ]
+}
+
+group("cyw30739") {
+ deps = [ ":lighting_app" ]
+}
+
+group("default") {
+ deps = [ ":cyw30739" ]
+}
diff --git a/examples/lighting-app/cyw30739/README.md b/examples/lighting-app/cyw30739/README.md
new file mode 100644
index 0000000..3d333ee
--- /dev/null
+++ b/examples/lighting-app/cyw30739/README.md
@@ -0,0 +1,104 @@
+# Matter CYW30739 Lighting Example
+
+An example showing the use of Matter on the Infineon CYW30739 platform.
+
+---
+
+## Table of Contents
+
+- [CHIP CYW30739 Lighting Example](#matter-cyw30739-lighting-example)
+ - [Introduction](#introduction)
+ - [Building](#building)
+ - [Flashing the Application](#flashing-the-application)
+ - [Running the Complete Example](#running-the-complete-example)
+
+---
+
+## Introduction
+
+The CYW30739 lighting example provides a baseline demonstration of a Light
+control device, built using Matter and the Infineon Modustoolbox SDK. It can be
+controlled by a Matter controller over Openthread network.
+
+The CYW30739 device can be commissioned over Bluetooth Low Energy where the
+device and the Matter controller will exchange security information with the
+Rendez-vous procedure. Thread Network credentials are then provided to the
+CYW30739 device which will then join the network.
+
+## Building
+
+- Build the example application:
+
+ ```bash
+ $ cd ~/connectedhomeip
+ $ git submodule update --init
+ $ ./scripts/examples/gn_build_example.sh examples/lighting-app/cyw30739 out/lighting-app
+ ```
+
+- To delete generated executable, libraries and object files use:
+
+ ```bash
+ $ cd ~/connectedhomeip
+ $ rm -rf ./out/
+ ```
+
+- OR use GN/Ninja directly
+
+ ```bash
+ $ cd ~/connectedhomeip/examples/lighting-app/cyw30739
+ $ git submodule update --init
+ $ source third_party/connectedhomeip/scripts/activate.sh
+ $ gn gen out/debug
+ $ ninja -C out/debug
+ ```
+
+- To delete generated executable, libraries and object files use:
+
+ ```bash
+ $ cd ~/connectedhomeip/examples/lighting-app/cyw30739
+ $ rm -rf out/
+ ```
+
+## Flashing the Application
+
+### Enter Recovery Mode
+
+Put the CYW30739 in to the recovery mode before running the flash script.
+
+1. Press and hold the `RECOVERY` button on the board.
+2. Press and hold the `RESET` button on the board.
+3. Release the `RESET` button.
+4. After one second, release the `RECOVERY` button.
+
+### Run Flash Script
+
+- On the command line:
+
+ ```bash
+ $ cd ~/connectedhomeip/examples/lighting-app/cyw30739
+ $ python3 out/debug/chip-cyw30739-lighting-example.flash.py
+ ```
+
+## Running the Complete Example
+
+- It is assumed here that you already have an OpenThread border router
+ configured and running. If not see the following guide
+ [Openthread_border_router](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/openthread_border_router_pi.md)
+ for more information on how to setup a border router on a raspberryPi.
+
+- You can provision and control the Chip device using the python controller,
+ Chip tool standalone, Android or iOS app
+
+ [Python Controller](https://github.com/project-chip/connectedhomeip/blob/master/src/controller/python/README.md)
+
+ Here is an example with the Python controller:
+
+ ```bash
+ $ chip-device-ctrl
+ chip-device-ctrl > connect -ble 3840 20202021 1234
+ chip-device-ctrl > zcl NetworkCommissioning AddThreadNetwork 1234 0 0 operationalDataset=hex:0e080000000000000000000300000b35060004001fffe00208dead00beef00cafe0708fddead00beef000005108e11d8ea8ffaa875713699f59e8807e0030a4f70656e5468726561640102c2980410edc641eb63b100b87e90a9980959befc0c0402a0fff8 breadcrumb=0 timeoutMs=1000
+ chip-device-ctrl > zcl NetworkCommissioning EnableNetwork 1234 0 0 networkID=hex:dead00beef00cafe breadcrumb=0 timeoutMs=1000
+ chip-device-ctrl > close-ble
+ chip-device-ctrl > resolve 1234
+ chip-device-ctrl > zcl OnOff Toggle 1234 1 0
+ ```
diff --git a/examples/lighting-app/cyw30739/args.gni b/examples/lighting-app/cyw30739/args.gni
new file mode 100644
index 0000000..149f7d4
--- /dev/null
+++ b/examples/lighting-app/cyw30739/args.gni
@@ -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.
+
+import("//build_overrides/chip.gni")
+import("${chip_root}/src/platform/CYW30739/args.gni")
+
+cyw30739_sdk_target = get_label_info(":sdk", "label_no_toolchain")
diff --git a/examples/lighting-app/cyw30739/build_overrides b/examples/lighting-app/cyw30739/build_overrides
new file mode 120000
index 0000000..e578e73
--- /dev/null
+++ b/examples/lighting-app/cyw30739/build_overrides
@@ -0,0 +1 @@
+../../build_overrides
\ No newline at end of file
diff --git a/examples/lighting-app/cyw30739/include/AppShellCommands.h b/examples/lighting-app/cyw30739/include/AppShellCommands.h
new file mode 100644
index 0000000..575d6c2
--- /dev/null
+++ b/examples/lighting-app/cyw30739/include/AppShellCommands.h
@@ -0,0 +1,22 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * Copyright (c) 2019 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
+
+void RegisterAppShellCommands();
diff --git a/examples/lighting-app/cyw30739/include/ButtonHandler.h b/examples/lighting-app/cyw30739/include/ButtonHandler.h
new file mode 100644
index 0000000..8fbe5ab
--- /dev/null
+++ b/examples/lighting-app/cyw30739/include/ButtonHandler.h
@@ -0,0 +1,28 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * Copyright (c) 2019 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.
+ */
+#include "wiced.h"
+
+typedef enum
+{
+ ON_OFF_BUTTON,
+ APP_MAX_BUTTON,
+} application_button_t;
+#define APP_MAX_BUTTON_DEF 1 // define for preprocessor
+
+wiced_result_t app_button_init(void);
diff --git a/examples/lighting-app/cyw30739/include/CHIPProjectConfig.h b/examples/lighting-app/cyw30739/include/CHIPProjectConfig.h
new file mode 100644
index 0000000..f9a91d3
--- /dev/null
+++ b/examples/lighting-app/cyw30739/include/CHIPProjectConfig.h
@@ -0,0 +1,61 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 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.
+ */
+
+/**
+ * @file
+ * Example project configuration file for CHIP.
+ *
+ * This is a place to put application or project-specific overrides
+ * to the default configuration values for general CHIP features.
+ *
+ */
+
+#pragma once
+
+// -------------------- Device Identification Configuration --------------------
+
+/* The VendorName attribute of the Basic cluster. */
+#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME "Infineon"
+
+/* The VendorID attribute of the Basic cluster. */
+#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0x0009
+
+/* The ProductName attribute of the Basic cluster. */
+#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME "CYW30739 Lighting App"
+
+/* The ProductID attribute of the Basic cluster. */
+#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x154c
+
+/* The HardwareVersionString attribute of the Basic cluster. */
+#define CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING "30739"
+
+/* The HardwareVersion attribute of the Basic cluster. */
+#define CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION 30739
+
+/* The SoftwareVersionString attribute of the Basic cluster. */
+#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING "TE7.5"
+
+/* The SoftwareVersion attribute of the Basic cluster. */
+#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION 0x0705
+
+/* The SerialNumber attribute of the Basic cluster. */
+#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
+
+// -------------------- Test Configuration --------------------
+#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 1
diff --git a/examples/lighting-app/cyw30739/include/LightingManager.h b/examples/lighting-app/cyw30739/include/LightingManager.h
new file mode 100644
index 0000000..0ce5b5c
--- /dev/null
+++ b/examples/lighting-app/cyw30739/include/LightingManager.h
@@ -0,0 +1,75 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * Copyright (c) 2019 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 <lib/core/CHIPError.h>
+
+class LightingManager
+{
+public:
+ enum Action_t
+ {
+ ON_ACTION = 0,
+ OFF_ACTION,
+ LEVEL_ACTION,
+
+ INVALID_ACTION
+ } Action;
+
+ enum State_t
+ {
+ kState_OffInitiated = 0,
+ kState_OffCompleted,
+ kState_OnInitiated,
+ kState_OnCompleted,
+ } State;
+
+ enum Actor_t
+ {
+ ACTOR_ZCL_CMD = 0,
+ ACTOR_APP_CMD,
+ ACTOR_BUTTON,
+ } Actor;
+
+ CHIP_ERROR Init();
+ bool IsLightOn();
+ bool IsActionInProgress();
+ bool InitiateAction(Actor_t aActor, Action_t aAction, uint8_t vallue);
+
+ typedef void (*Callback_fn_initiated)(Actor_t, Action_t, uint8_t);
+ typedef void (*Callback_fn_completed)(Action_t);
+ void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB);
+
+private:
+ void WriteClusterState(uint8_t value);
+ void WriteClusterLevel(uint8_t value);
+
+ friend LightingManager & LightMgr(void);
+ State_t mState;
+
+ Callback_fn_initiated mActionInitiated_CB;
+ Callback_fn_completed mActionCompleted_CB;
+
+ static LightingManager sLight;
+};
+
+inline LightingManager & LightMgr(void)
+{
+ return LightingManager::sLight;
+}
diff --git a/examples/lighting-app/cyw30739/src/AppShellCommands.cpp b/examples/lighting-app/cyw30739/src/AppShellCommands.cpp
new file mode 100644
index 0000000..84f7b74
--- /dev/null
+++ b/examples/lighting-app/cyw30739/src/AppShellCommands.cpp
@@ -0,0 +1,103 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * Copyright (c) 2019 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.
+ */
+
+#include "LightingManager.h"
+#include <lib/shell/commands/Help.h>
+#include <platform/CHIPDeviceLayer.h>
+
+using namespace chip::Shell;
+
+static CHIP_ERROR AppCommandHelpHandler(int argc, char * argv[]);
+static CHIP_ERROR AppCommandLightingHandler(int argc, char * argv[]);
+static CHIP_ERROR AppCommandDispatch(int argc, char * argv[]);
+
+static chip::Shell::Engine sAppSubcommands;
+
+void RegisterAppShellCommands(void)
+{
+ static const shell_command_t sAppSubCommands[] = {
+ {
+ .cmd_func = AppCommandHelpHandler,
+ .cmd_name = "help",
+ .cmd_help = "Usage: app <subcommand>",
+ },
+ {
+ .cmd_func = AppCommandLightingHandler,
+ .cmd_name = "light",
+ .cmd_help = "Usage: app light [on|off|toggle]",
+ },
+ };
+
+ static const shell_command_t sAppCommand = {
+ .cmd_func = AppCommandDispatch,
+ .cmd_name = "app",
+ .cmd_help = "App commands",
+ };
+
+ sAppSubcommands.RegisterCommands(sAppSubCommands, ArraySize(sAppSubCommands));
+
+ Engine::Root().RegisterCommands(&sAppCommand, 1);
+}
+
+CHIP_ERROR AppCommandHelpHandler(int argc, char * argv[])
+{
+ sAppSubcommands.ForEachCommand(PrintCommandHelp, nullptr);
+ return CHIP_NO_ERROR;
+}
+
+CHIP_ERROR AppCommandLightingHandler(int argc, char * argv[])
+{
+ if (argc == 0)
+ {
+ streamer_printf(streamer_get(), "The light is %s\n", LightMgr().IsLightOn() ? "on" : "off");
+ }
+ else if (strcmp(argv[0], "on") == 0)
+ {
+ streamer_printf(streamer_get(), "Turning the light on ...\n");
+ LightMgr().InitiateAction(LightingManager::ACTOR_APP_CMD, LightingManager::ON_ACTION, 0);
+ }
+ else if (strcmp(argv[0], "off") == 0)
+ {
+ streamer_printf(streamer_get(), "Turning the light off ...\n");
+ LightMgr().InitiateAction(LightingManager::ACTOR_APP_CMD, LightingManager::OFF_ACTION, 0);
+ }
+ else if (strcmp(argv[0], "toggle") == 0)
+ {
+ streamer_printf(streamer_get(), "Toggling the light ...\n");
+ if (LightMgr().IsLightOn())
+ LightMgr().InitiateAction(LightingManager::ACTOR_APP_CMD, LightingManager::OFF_ACTION, 0);
+ else
+ LightMgr().InitiateAction(LightingManager::ACTOR_APP_CMD, LightingManager::ON_ACTION, 0);
+ }
+ else
+ {
+ return CHIP_ERROR_INVALID_ARGUMENT;
+ }
+ return CHIP_NO_ERROR;
+}
+
+CHIP_ERROR AppCommandDispatch(int argc, char * argv[])
+{
+ if (argc == 0)
+ {
+ AppCommandHelpHandler(argc, argv);
+ return CHIP_NO_ERROR;
+ }
+ return sAppSubcommands.ExecCommand(argc, argv);
+}
diff --git a/examples/lighting-app/cyw30739/src/ButtonHandler.cpp b/examples/lighting-app/cyw30739/src/ButtonHandler.cpp
new file mode 100644
index 0000000..10c24a4
--- /dev/null
+++ b/examples/lighting-app/cyw30739/src/ButtonHandler.cpp
@@ -0,0 +1,88 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * Copyright (c) 2019 Google LLC.
+ * Copyright 2021, Cypress Semiconductor Corporation (an Infineon company)
+ * 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 <ButtonHandler.h>
+#include <LightingManager.h>
+#include <stdio.h>
+#include <wiced.h>
+#include <wiced_button_manager.h>
+#include <wiced_platform.h>
+
+/******************************************************
+ * Macros
+ ******************************************************/
+void app_button_event_handler(const button_manager_button_t * button, button_manager_event_t event,
+ button_manager_button_state_t state);
+
+static wiced_button_manager_configuration_t app_button_manager_configuration = {
+ .short_hold_duration = 500, /*msec*/
+ .medium_hold_duration = 700,
+ .long_hold_duration = 1500,
+ .very_long_hold_duration = 2500,
+ .debounce_duration = 150, /* typically a click takes around ~150-200 ms */
+ .double_click_interval = 250,
+ .continuous_hold_detect = WICED_TRUE,
+ .event_handler = app_button_event_handler,
+};
+
+/* Static button configuration */
+static wiced_button_configuration_t app_button_configurations[APP_MAX_BUTTON_DEF];
+/* Button objects for the button manager */
+static button_manager_button_t app_buttons[APP_MAX_BUTTON_DEF];
+static button_manager_t app_button_manager;
+
+wiced_result_t app_button_init(void)
+{
+ wiced_result_t result = WICED_ERROR;
+
+ memset(app_button_configurations, 0, (sizeof(wiced_button_configuration_t) * APP_MAX_BUTTON_DEF));
+ memset(app_buttons, 0, (sizeof(button_manager_button_t) * APP_MAX_BUTTON_DEF));
+
+ app_button_configurations[ON_OFF_BUTTON].button = PLATFORM_BUTTON_1;
+ app_button_configurations[ON_OFF_BUTTON].button_event_mask = BUTTON_CLICK_EVENT;
+ app_buttons[ON_OFF_BUTTON].configuration = &app_button_configurations[ON_OFF_BUTTON];
+
+ result = wiced_button_manager_init(&app_button_manager, &app_button_manager_configuration, app_buttons, 1);
+
+ if (result != WICED_SUCCESS)
+ {
+ printf("button_manager_init failed (%d)\n", result);
+ }
+ return result;
+}
+
+void app_button_event_handler(const button_manager_button_t * button_mgr, button_manager_event_t event,
+ button_manager_button_state_t state)
+{
+
+ if (button_mgr[0].configuration->button == PLATFORM_BUTTON_1 && event == BUTTON_CLICK_EVENT && state == BUTTON_STATE_RELEASED)
+ {
+ if (LightMgr().IsLightOn())
+ {
+ printf("Button Toggle:ON -> OFF\n");
+ LightMgr().InitiateAction(LightingManager::ACTOR_BUTTON, LightingManager::OFF_ACTION, 0);
+ }
+ else
+ {
+ printf("Button Toggle:OFF -> ON\n");
+ LightMgr().InitiateAction(LightingManager::ACTOR_BUTTON, LightingManager::ON_ACTION, 0);
+ }
+ }
+}
diff --git a/examples/lighting-app/cyw30739/src/LightingManager.cpp b/examples/lighting-app/cyw30739/src/LightingManager.cpp
new file mode 100644
index 0000000..dc11429
--- /dev/null
+++ b/examples/lighting-app/cyw30739/src/LightingManager.cpp
@@ -0,0 +1,121 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * Copyright (c) 2019 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.
+ */
+
+#include "LightingManager.h"
+#include <app-common/zap-generated/att-storage.h>
+#include <app-common/zap-generated/attribute-id.h>
+#include <app-common/zap-generated/attribute-type.h>
+#include <app-common/zap-generated/attributes/Accessors.h>
+#include <app-common/zap-generated/cluster-id.h>
+#include <app/util/af.h>
+#include <stdio.h>
+
+using namespace chip;
+using namespace chip::app;
+using namespace chip::app::Clusters;
+
+LightingManager LightingManager::sLight;
+
+CHIP_ERROR LightingManager::Init()
+{
+ mState = kState_OffCompleted;
+
+ return CHIP_NO_ERROR;
+}
+
+void LightingManager::SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB)
+{
+ mActionInitiated_CB = aActionInitiated_CB;
+ mActionCompleted_CB = aActionCompleted_CB;
+}
+
+bool LightingManager::IsActionInProgress()
+{
+ return (mState == kState_OffInitiated || mState == kState_OnInitiated);
+}
+
+bool LightingManager::IsLightOn(void)
+{
+ bool on = true;
+ const EmberAfStatus status = OnOff::Attributes::OnOff::Get(1, &on);
+
+ if (status != EMBER_ZCL_STATUS_SUCCESS)
+ {
+ printf("Error ReadServerAttribute 0x%02x\n", status);
+ }
+
+ return on != false;
+}
+
+bool LightingManager::InitiateAction(Actor_t aActor, Action_t aAction, uint8_t value)
+{
+ if (mActionInitiated_CB)
+ {
+ mActionInitiated_CB(aActor, aAction, value);
+ }
+
+ switch (aAction)
+ {
+ case ON_ACTION:
+ mState = kState_OnInitiated;
+ if (aActor != ACTOR_ZCL_CMD)
+ {
+ WriteClusterState(1);
+ }
+ mState = kState_OnCompleted;
+ break;
+ case OFF_ACTION:
+ mState = kState_OffInitiated;
+ if (aActor != ACTOR_ZCL_CMD)
+ {
+ WriteClusterState(0);
+ }
+ mState = kState_OffCompleted;
+ break;
+ default:
+ return false;
+ }
+
+ if (mActionCompleted_CB)
+ {
+ mActionCompleted_CB(aAction);
+ }
+
+ return true;
+}
+
+void LightingManager::WriteClusterState(uint8_t value)
+{
+ const EmberAfStatus status = OnOff::Attributes::OnOff::Set(1, value);
+
+ if (status != EMBER_ZCL_STATUS_SUCCESS)
+ {
+ printf("Error WriteServerAttribute 0x%02x\n", status);
+ }
+}
+
+void LightingManager::WriteClusterLevel(uint8_t value)
+{
+ const EmberAfStatus status = LevelControl::Attributes::CurrentLevel::Set(1, value);
+
+ if (status != EMBER_ZCL_STATUS_SUCCESS)
+ {
+ printf("Error WriteServerAttribute 0x%02x\n", status);
+ }
+}
diff --git a/examples/lighting-app/cyw30739/src/ZclCallbacks.cpp b/examples/lighting-app/cyw30739/src/ZclCallbacks.cpp
new file mode 100644
index 0000000..ce4b512
--- /dev/null
+++ b/examples/lighting-app/cyw30739/src/ZclCallbacks.cpp
@@ -0,0 +1,71 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * Copyright (c) 2019 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.
+ */
+
+#include "LightingManager.h"
+#include <app-common/zap-generated/attributes/Accessors.h>
+#include <platform/CHIPDeviceLayer.h>
+
+using namespace chip;
+using namespace chip::app::Clusters;
+using namespace chip::DeviceLayer;
+
+void emberAfBasicClusterInitCallback(EndpointId endpoint)
+{
+ uint16_t year;
+ uint8_t month;
+ uint8_t dayOfMonth;
+ char cString[16] = "00000000";
+
+ if (ConfigurationMgr().GetManufacturingDate(year, month, dayOfMonth) == CHIP_NO_ERROR)
+ {
+ snprintf(cString, sizeof(cString), "%04u%02u%02u", year, month, dayOfMonth);
+ }
+ Basic::Attributes::ManufacturingDate::Set(endpoint, CharSpan(cString));
+}
+
+void MatterPostAttributeChangeCallback(const app::ConcreteAttributePath & attributePath, uint8_t mask, uint8_t type, uint16_t size,
+ uint8_t * value)
+
+{
+ switch (attributePath.mClusterId)
+ {
+ case OnOff::Id:
+ if (attributePath.mAttributeId == OnOff::Attributes::OnOff::Id)
+ {
+ printf("ZCL OnOff -> %u\n", *value);
+ LightMgr().InitiateAction(LightingManager::ACTOR_ZCL_CMD,
+ (*value == 0) ? LightingManager::OFF_ACTION : LightingManager::ON_ACTION, *value);
+ return;
+ }
+ break;
+ case LevelControl::Id:
+ if (attributePath.mAttributeId == LevelControl::Attributes::CurrentLevel::Id)
+ {
+ printf("ZCL CurrentLevel -> %u\n", *value);
+ LightMgr().InitiateAction(LightingManager::ACTOR_ZCL_CMD, LightingManager::LEVEL_ACTION, *value);
+ return;
+ }
+ break;
+ default:
+ printf("Unhandled cluster ID: 0x%04lx\n", attributePath.mClusterId);
+ return;
+ }
+
+ printf("ERROR clusterId: 0x%04lx, unknown attribute ID: 0x%04lx\n", attributePath.mClusterId, attributePath.mAttributeId);
+}
diff --git a/examples/lighting-app/cyw30739/src/main.cpp b/examples/lighting-app/cyw30739/src/main.cpp
new file mode 100644
index 0000000..3a99588
--- /dev/null
+++ b/examples/lighting-app/cyw30739/src/main.cpp
@@ -0,0 +1,181 @@
+/*
+ *
+ * Copyright (c) 2021 Project CHIP Authors
+ * Copyright (c) 2019 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.
+ */
+#include <AppShellCommands.h>
+#include <ButtonHandler.h>
+#include <ChipShellCollection.h>
+#include <LightingManager.h>
+#include <app/server/Server.h>
+#include <credentials/examples/DeviceAttestationCredsExample.h>
+#include <lib/shell/Engine.h>
+#include <lib/support/CHIPPlatformMemory.h>
+#include <mbedtls/platform.h>
+#include <platform/CHIPDeviceLayer.h>
+#include <protocols/secure_channel/PASESession.h>
+#include <sparcommon.h>
+#include <stdio.h>
+#include <wiced_led_manager.h>
+#include <wiced_memory.h>
+#include <wiced_platform.h>
+
+using namespace ::chip::Credentials;
+using namespace ::chip::DeviceLayer;
+using namespace ::chip::Shell;
+
+static void EventHandler(const ChipDeviceEvent * event, intptr_t arg);
+static void HandleThreadStateChangeEvent(const ChipDeviceEvent * event);
+static void LightManagerCallback(LightingManager::Actor_t actor, LightingManager::Action_t action, uint8_t value);
+
+static wiced_led_config_t chip_lighting_led_config = {
+ .led = PLATFORM_LED_1,
+ .bright = 50,
+};
+
+APPLICATION_START()
+{
+ CHIP_ERROR err;
+ wiced_result_t result;
+
+ printf("\nChipLighting App starting\n");
+
+ mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree);
+
+ err = chip::Platform::MemoryInit();
+ if (err != CHIP_NO_ERROR)
+ {
+ printf("ERROR MemoryInit %ld\n", err.AsInteger());
+ }
+
+ result = app_button_init();
+ if (result != WICED_SUCCESS)
+ {
+ printf("ERROR app_button_init %d\n", result);
+ }
+
+ /* Init. LED Manager. */
+ result = wiced_led_manager_init(&chip_lighting_led_config);
+ if (result != WICED_SUCCESS)
+ printf("wiced_led_manager_init fail (%d)\n", result);
+
+ printf("Initializing CHIP\n");
+ err = PlatformMgr().InitChipStack();
+ if (err != CHIP_NO_ERROR)
+ {
+ printf("ERROR InitChipStack %ld\n", err.AsInteger());
+ }
+
+#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
+ printf("Initializing OpenThread stack\n");
+ err = ThreadStackMgr().InitThreadStack();
+ if (err != CHIP_NO_ERROR)
+ {
+ printf("ERROR InitThreadStack %ld\n", err.AsInteger());
+ }
+#endif
+
+#if CHIP_DEVICE_CONFIG_THREAD_FTD
+ err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router);
+#else // !CHIP_DEVICE_CONFIG_THREAD_FTD
+ err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
+#endif // CHIP_DEVICE_CONFIG_THREAD_FTD
+ if (err != CHIP_NO_ERROR)
+ {
+ printf("ERROR SetThreadDeviceType %ld\n", err.AsInteger());
+ }
+
+ printf("Starting event loop task\n");
+ err = PlatformMgr().StartEventLoopTask();
+ if (err != CHIP_NO_ERROR)
+ {
+ printf("ERROR StartEventLoopTask %ld\n", err.AsInteger());
+ }
+
+#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
+ printf("Starting thread task\n");
+ err = ThreadStackMgr().StartThreadTask();
+ if (err != CHIP_NO_ERROR)
+ {
+ printf("ERROR StartThreadTask %ld\n", err.AsInteger());
+ }
+#endif
+
+ PlatformMgrImpl().AddEventHandler(EventHandler, 0);
+
+ LightMgr().Init();
+ LightMgr().SetCallbacks(LightManagerCallback, NULL);
+
+ /* Start CHIP datamodel server */
+ chip::Server::GetInstance().Init();
+
+ SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
+
+ ConfigurationMgr().LogDeviceConfig();
+
+ const int ret = Engine::Root().Init();
+ if (!chip::ChipError::IsSuccess(ret))
+ {
+ printf("ERROR Shell Init %d\n", ret);
+ }
+ cmd_ping_init();
+ RegisterAppShellCommands();
+ Engine::Root().RunMainLoop();
+
+ assert(!wiced_rtos_check_for_stack_overflow());
+}
+
+void EventHandler(const ChipDeviceEvent * event, intptr_t arg)
+{
+ switch (event->Type)
+ {
+ case DeviceEventType::kThreadStateChange:
+ HandleThreadStateChangeEvent(event);
+ break;
+ default:
+ break;
+ }
+}
+
+void HandleThreadStateChangeEvent(const ChipDeviceEvent * event)
+{
+#if CHIP_BYPASS_RENDEZVOUS
+ if (event->ThreadStateChange.NetDataChanged && !ConnectivityMgr().IsThreadProvisioned())
+ {
+ ThreadStackMgr().JoinerStart();
+ }
+#endif /* CHIP_BYPASS_RENDEZVOUS */
+}
+
+void LightManagerCallback(LightingManager::Actor_t actor, LightingManager::Action_t action, uint8_t level)
+{
+ if (action == LightingManager::ON_ACTION)
+ {
+ printf("Turning light ON\n");
+ wiced_led_manager_enable_led(PLATFORM_LED_1);
+ }
+ else if (action == LightingManager::OFF_ACTION)
+ {
+ printf("Turning light OFF\n");
+ wiced_led_manager_disable_led(PLATFORM_LED_1);
+ }
+ else if (action == LightingManager::LEVEL_ACTION)
+ {
+ printf("Set light level = %d\n", level);
+ chip_lighting_led_config.bright = (uint16_t) level * 100 / 0xfe;
+ wiced_led_manager_reconfig_led(&chip_lighting_led_config);
+ }
+}
diff --git a/examples/lighting-app/cyw30739/static_config.txt b/examples/lighting-app/cyw30739/static_config.txt
new file mode 100644
index 0000000..f256ac9
--- /dev/null
+++ b/examples/lighting-app/cyw30739/static_config.txt
@@ -0,0 +1,21 @@
+# The post-building script uses this file to generate specified static configurations.
+# All '#' prefixed lines are ignored by the script.
+# Each line defines a static configuration by 3 fields separated by commas.
+#
+# The 1st field is a 16-bit ID from 0x2000 to 0x3ffff.
+# All IDs in this file have to be different.
+#
+# The 2nd field is a type to which the script interprets the value according.
+#
+# The 3rd field is a value of the static configuration. The value format depends on what the value type is:
+# - hex: Multiple hexadecimal values separated by commas.
+# - uint32/uint16/uint8/int16/int8: A integer.
+# - eui64: random or btext. If the value is btext, the configuration will be generated from the BT address.
+#
+# ID, type, value
+# EUI64
+0x2000, eui64, random
+# Setup Pin Code
+0x2105, uint32, 20202021
+# Setup Discriminator
+0x2107, uint32, 3840
diff --git a/examples/lighting-app/cyw30739/third_party/connectedhomeip b/examples/lighting-app/cyw30739/third_party/connectedhomeip
new file mode 120000
index 0000000..c866b86
--- /dev/null
+++ b/examples/lighting-app/cyw30739/third_party/connectedhomeip
@@ -0,0 +1 @@
+../../../..
\ No newline at end of file
diff --git a/examples/platform/cyw30739/BUILD.gn b/examples/platform/cyw30739/BUILD.gn
new file mode 100644
index 0000000..8390dd6
--- /dev/null
+++ b/examples/platform/cyw30739/BUILD.gn
@@ -0,0 +1,27 @@
+# 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.
+
+import("//build_overrides/chip.gni")
+
+config("chip_examples_project_config") {
+ include_dirs = [ "project_include" ]
+}
+
+source_set("openthread_core_config_ifx_chip_examples") {
+ sources = [ "project_include/OpenThreadConfig.h" ]
+
+ public_deps = [ "${chip_root}/third_party/openthread/platforms/ifx:openthread_core_config_ifx" ]
+
+ public_configs = [ ":chip_examples_project_config" ]
+}
diff --git a/examples/platform/cyw30739/args.gni b/examples/platform/cyw30739/args.gni
new file mode 100644
index 0000000..4c1695e
--- /dev/null
+++ b/examples/platform/cyw30739/args.gni
@@ -0,0 +1,19 @@
+# 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.
+
+chip_ble_project_config_include = "<CHIPProjectConfig.h>"
+chip_device_project_config_include = "<CHIPProjectConfig.h>"
+chip_project_config_include = "<CHIPProjectConfig.h>"
+chip_inet_project_config_include = "<CHIPProjectConfig.h>"
+chip_system_project_config_include = "<CHIPProjectConfig.h>"
diff --git a/examples/platform/cyw30739/project_include/OpenThreadConfig.h b/examples/platform/cyw30739/project_include/OpenThreadConfig.h
new file mode 100644
index 0000000..eb6006f
--- /dev/null
+++ b/examples/platform/cyw30739/project_include/OpenThreadConfig.h
@@ -0,0 +1,36 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 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.
+ */
+
+/**
+ * @file
+ * Overrides to default OpenThread configuration.
+ *
+ */
+
+#pragma once
+
+#ifndef OPENTHREAD_CONFIG_LOG_LEVEL
+#define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_CRIT
+#endif
+
+#define OPENTHREAD_CONFIG_PLATFORM_ASSERT_MANAGEMENT 1
+#define OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_MAX_HOST_ADDRESSES 4
+#define OPENTHREAD_CONFIG_TCP_ENABLE 0
+
+#include <openthread-core-cyw30739-config.h>
diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py
index 5e729c8..8c5f849 100644
--- a/scripts/build/build/targets.py
+++ b/scripts/build/build/targets.py
@@ -19,6 +19,7 @@
from builders.ameba import AmebaApp, AmebaBoard, AmebaBuilder
from builders.android import AndroidBoard, AndroidApp, AndroidBuilder
+from builders.cyw30739 import Cyw30739Builder, Cyw30739App, Cyw30739Board
from builders.efr32 import Efr32Builder, Efr32App, Efr32Board
from builders.esp32 import Esp32Builder, Esp32Board, Esp32App
from builders.host import HostBuilder, HostApp, HostBoard
@@ -363,6 +364,10 @@
yield target.Extend('lock-low-power-release', app=K32WApp.LOCK, low_power=True, release=True).GlobBlacklist("Only on demand build")
+def Cyw30739Targets():
+ yield Target('cyw30739-cyw930739m2evb_01-light', Cyw30739Builder, board=Cyw30739Board.CYW930739M2EVB_01, app=Cyw30739App.LIGHT)
+
+
ALL = []
target_generators = [
@@ -375,6 +380,7 @@
InfineonTargets(),
AmebaTargets(),
K32WTargets(),
+ Cyw30739Targets(),
]
for generator in target_generators:
diff --git a/scripts/build/builders/cyw30739.py b/scripts/build/builders/cyw30739.py
new file mode 100644
index 0000000..9ba608e
--- /dev/null
+++ b/scripts/build/builders/cyw30739.py
@@ -0,0 +1,68 @@
+# Copyright (c) 2021 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.
+
+import os
+from enum import Enum, auto
+
+from .gn import GnBuilder
+
+
+class Cyw30739App(Enum):
+ LIGHT = auto()
+
+ def ExampleName(self):
+ if self == Cyw30739App.LIGHT:
+ return "lighting-app"
+ else:
+ raise Exception("Unknown app type: %r" % self)
+
+ def AppNamePrefix(self):
+ if self == Cyw30739App.LIGHT:
+ return "chip-cyw30739-lighting-example"
+ else:
+ raise Exception("Unknown app type: %r" % self)
+
+ def BuildRoot(self, root):
+ return os.path.join(root, "examples", self.ExampleName(), "cyw30739")
+
+
+class Cyw30739Board(Enum):
+ CYW930739M2EVB_01 = 1
+
+ def GnArgName(self):
+ if self == Cyw30739Board.CYW930739M2EVB_01:
+ return "CYW930739M2EVB-01"
+ else:
+ raise Exception("Unknown board #: %r" % self)
+
+
+class Cyw30739Builder(GnBuilder):
+ def __init__(
+ self,
+ root,
+ runner,
+ app: Cyw30739App = Cyw30739App.LIGHT,
+ board: Cyw30739Board = Cyw30739Board.CYW930739M2EVB_01,
+ ):
+ super(Cyw30739Builder, self).__init__(
+ root=app.BuildRoot(root), runner=runner)
+ self.app = app
+ self.board = board
+
+ def build_outputs(self):
+ items = {}
+ for extension in ["elf", "elf.map"]:
+ name = "%s.%s" % (self.app.AppNamePrefix(), extension)
+ items[name] = os.path.join(self.output_dir, name)
+ return items
diff --git a/scripts/build/testdata/all_targets_except_host.txt b/scripts/build/testdata/all_targets_except_host.txt
index a698ee4..5b7771d 100644
--- a/scripts/build/testdata/all_targets_except_host.txt
+++ b/scripts/build/testdata/all_targets_except_host.txt
@@ -14,6 +14,7 @@
android-arm64-chip-tvserver
android-x64-chip-tool
android-x86-chip-tool
+cyw30739-cyw930739m2evb_01-light
efr32-brd4161a-light
efr32-brd4161a-light-rpc
efr32-brd4161a-lock
diff --git a/scripts/build/testdata/build_all_except_host.txt b/scripts/build/testdata/build_all_except_host.txt
index 4bcb133..f716cb0 100644
--- a/scripts/build/testdata/build_all_except_host.txt
+++ b/scripts/build/testdata/build_all_except_host.txt
@@ -166,6 +166,9 @@
# Accepting NDK licenses @ tools
bash -c 'yes | TEST_ANDROID_HOME/tools/bin/sdkmanager --licenses >/dev/null'
+# Generating cyw30739-cyw930739m2evb_01-light
+gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/cyw30739 {out}/cyw30739-cyw930739m2evb_01-light
+
# Generating efr32-brd4161a-light
gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/efr32 '--args=efr32_board="BRD4161A"' {out}/efr32-brd4161a-light
@@ -868,6 +871,9 @@
# Building APP android-x86-chip-tool
{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PmatterBuildSrcDir={out}/android-x86-chip-tool -PmatterSdkSourceBuild=false -PbuildDir={out}/android-x86-chip-tool assembleDebug
+# Building cyw30739-cyw930739m2evb_01-light
+ninja -C {out}/cyw30739-cyw930739m2evb_01-light
+
# Building efr32-brd4161a-light
ninja -C {out}/efr32-brd4161a-light
diff --git a/scripts/build/testdata/glob_star_targets_except_host.txt b/scripts/build/testdata/glob_star_targets_except_host.txt
index df7a629..ae829e6 100644
--- a/scripts/build/testdata/glob_star_targets_except_host.txt
+++ b/scripts/build/testdata/glob_star_targets_except_host.txt
@@ -14,6 +14,7 @@
android-arm64-chip-tvserver
android-x64-chip-tool
android-x86-chip-tool
+cyw30739-cyw930739m2evb_01-light
efr32-brd4161a-light
efr32-brd4161a-light-rpc
efr32-brd4161a-lock
diff --git a/scripts/flashing/cyw30739_firmware_utils.py b/scripts/flashing/cyw30739_firmware_utils.py
new file mode 100644
index 0000000..5891320
--- /dev/null
+++ b/scripts/flashing/cyw30739_firmware_utils.py
@@ -0,0 +1,134 @@
+#!/usr/bin/env python3
+# Copyright (c) 2021 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.
+"""Flash an CYW30739 device.
+
+This is layered so that a caller can perform individual operations
+through an `Flasher` instance, or operations according to a command line.
+For `Flasher`, see the class documentation.
+"""
+
+import os
+import sys
+
+import firmware_utils
+
+# Additional options that can be use to configure an `Flasher`
+# object (as dictionary keys) and/or passed as command line options.
+CYW30739_OPTIONS = {
+ # Configuration options define properties used in flashing operations.
+ "configuration": {
+ "direct": {
+ "help": "Set 1 to enable direct load",
+ "default": 0,
+ "argparse": {"action": "store"},
+ },
+ "sdk_scripts_dir": {
+ "help": "The SDK scripts directory",
+ "default": None,
+ "argparse": {"action": "store"},
+ },
+ "sdk_tools_dir": {
+ "help": "The SDK tools directory",
+ "default": None,
+ "argparse": {"action": "store"},
+ },
+ "program": {
+ "help": "The script to program the flash.",
+ "command": [
+ "bash",
+ "--norc",
+ "--noprofile",
+ "{sdk_scripts_dir}/bt_program.bash",
+ "--tools={sdk_tools_dir}",
+ "--scripts={sdk_scripts_dir}",
+ "--elf={application}",
+ "--direct={direct}",
+ (),
+ ],
+ },
+ "port": {
+ "help": "The serial port of device to flash",
+ "default": None,
+ "argparse": {},
+ },
+ },
+}
+
+
+class Flasher(firmware_utils.Flasher):
+ """Manage CYW30739 flashing."""
+
+ def __init__(self, **options):
+ super().__init__(platform="CYW30739", module=__name__, **options)
+ self.define_options(CYW30739_OPTIONS)
+
+ def erase(self):
+ """Not supported"""
+ self.log(0, "Do not support erasing device.")
+ self.err = 1
+ return self
+
+ def verify(self):
+ """Not supported"""
+ self.log(0, "Do not support verifying image.")
+ self.err = 1
+ return self
+
+ def flash(self):
+ """Flash image."""
+
+ arguments = [
+ "--hex={}/{}_download.hex".format(
+ self.option.application.parent, self.option.application.stem
+ ),
+ ]
+ if self.option.port:
+ arguments.append("--uart={port}")
+ if self.option.verbose > 0:
+ arguments.append("--verbose")
+
+ return self.run_tool("program", arguments, name="Flash")
+
+ def reset(self):
+ """Not supported"""
+ self.log(0, "Do not support resetting device.")
+ self.err = 1
+ return self
+
+ def actions(self):
+ """Perform actions on the device according to self.option."""
+ self.log(3, "Options:", self.option)
+
+ if self.option.erase:
+ if self.erase().err:
+ return self
+
+ if self.option.verify_application:
+ if self.verify().err:
+ return self
+
+ if self.option.reset:
+ if self.reset().err:
+ return self
+
+ if self.option.application:
+ if self.flash().err:
+ return self
+
+ return self
+
+
+if __name__ == "__main__":
+ sys.exit(Flasher().flash_command(sys.argv))
diff --git a/scripts/tools/memory/platform/cyw30739.cfg b/scripts/tools/memory/platform/cyw30739.cfg
new file mode 100644
index 0000000..7735934
--- /dev/null
+++ b/scripts/tools/memory/platform/cyw30739.cfg
@@ -0,0 +1,41 @@
+# Copyright (c) 2021 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.
+
+# Memory tools default configuation for Silicon Labs EFR32.
+
+{
+ 'section': {
+ # By default, only these sections will be included
+ # when operating by sections.
+ 'default': [
+ '.app_xip_area',
+ '.text',
+ '.rodata',
+ '.data',
+ '.bss',
+ ]
+ },
+ 'region': {
+ # Regions are sets of sections that can be used for aggregate reports.
+ 'sections': {
+ 'FLASH': [
+ '.app_xip_area',
+ ],
+ 'RAM': [
+ '.data',
+ '.bss',
+ ]
+ }
+ },
+}
diff --git a/src/lib/shell/BUILD.gn b/src/lib/shell/BUILD.gn
index 6f5ff3f..0e4f7d7 100644
--- a/src/lib/shell/BUILD.gn
+++ b/src/lib/shell/BUILD.gn
@@ -58,6 +58,11 @@
"MainLoopDefault.cpp",
"streamer_k32w.cpp",
]
+ } else if (chip_device_platform == "cyw30739") {
+ sources += [
+ "MainLoopCYW30739.cpp",
+ "streamer_cyw30739.cpp",
+ ]
} else if (current_os == "zephyr") {
sources += [
"MainLoopZephyr.cpp",
diff --git a/src/lib/shell/MainLoopCYW30739.cpp b/src/lib/shell/MainLoopCYW30739.cpp
new file mode 100644
index 0000000..7f7044d
--- /dev/null
+++ b/src/lib/shell/MainLoopCYW30739.cpp
@@ -0,0 +1,176 @@
+/*
+ *
+ * Copyright (c) 2021 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.
+ */
+
+#include "streamer.h"
+#include <lib/shell/Engine.h>
+#include <lib/support/CHIPMem.h>
+#include <platform/CHIPDeviceLayer.h>
+
+#include <ctype.h>
+#include <string.h>
+
+using chip::FormatCHIPError;
+using chip::Platform::MemoryAlloc;
+using chip::Platform::MemoryFree;
+using chip::Shell::Engine;
+using chip::Shell::streamer_get;
+
+namespace {
+
+bool IsSeparator(char ch)
+{
+ return (ch == ' ') || (ch == '\t') || (ch == '\r') || (ch == '\n');
+}
+
+bool IsEscape(char ch)
+{
+ return (ch == '\\');
+}
+
+bool IsEscapable(char ch)
+{
+ return IsSeparator(ch) || IsEscape(ch);
+}
+
+int TokenizeLine(char * buffer, char ** tokens, int max_tokens)
+{
+ size_t len = strlen(buffer);
+ int cursor = 0;
+ size_t i = 0;
+
+ // Strip leading spaces
+ while (buffer[i] && buffer[i] == ' ')
+ {
+ i++;
+ }
+
+ if (len <= i)
+ {
+ return 0;
+ }
+
+ // The first token starts at the beginning.
+ tokens[cursor++] = &buffer[i];
+
+ for (; i < len && cursor < max_tokens; i++)
+ {
+ if (IsEscape(buffer[i]) && IsEscapable(buffer[i + 1]))
+ {
+ // include the null terminator: strlen(cmd) = strlen(cmd + 1) + 1
+ memmove(&buffer[i], &buffer[i + 1], strlen(&buffer[i]));
+ }
+ else if (IsSeparator(buffer[i]))
+ {
+ buffer[i] = 0;
+ if (!IsSeparator(buffer[i + 1]))
+ {
+ tokens[cursor++] = &buffer[i + 1];
+ }
+ }
+ }
+
+ tokens[cursor] = nullptr;
+
+ return cursor;
+}
+
+void ProcessShellLine(intptr_t args)
+{
+ int argc;
+ char * argv[CHIP_SHELL_MAX_TOKENS];
+
+ char * line = reinterpret_cast<char *>(args);
+ argc = TokenizeLine(line, argv, CHIP_SHELL_MAX_TOKENS);
+
+ if (argc > 0)
+ {
+ CHIP_ERROR retval = Engine::Root().ExecCommand(argc, argv);
+
+ if (retval != CHIP_NO_ERROR)
+ {
+ char errorStr[160];
+ bool errorStrFound = FormatCHIPError(errorStr, sizeof(errorStr), retval);
+ if (!errorStrFound)
+ {
+ errorStr[0] = 0;
+ }
+ streamer_printf(streamer_get(), "Error %s: %s\r\n", argv[0], errorStr);
+ }
+ else
+ {
+ streamer_printf(streamer_get(), "Done\r\n");
+ }
+ }
+ streamer_printf(streamer_get(), CHIP_SHELL_PROMPT);
+}
+
+} // namespace
+
+namespace chip {
+namespace Shell {
+
+static char sInputBuffer[CHIP_SHELL_MAX_LINE_SIZE];
+static uint16_t sInputLength;
+
+void ProcessInput(intptr_t args)
+{
+ char input[32];
+ const ssize_t read_count = streamer_read(streamer_get(), input, sizeof(input));
+ for (uint8_t i = 0; i < read_count; i++)
+ {
+ switch (input[i])
+ {
+ case '\r':
+ case '\n':
+ streamer_printf(streamer_get(), "\r\n");
+ sInputBuffer[sInputLength] = '\0';
+ ProcessShellLine(reinterpret_cast<intptr_t>(sInputBuffer));
+ sInputLength = 0;
+ break;
+
+ case '\b':
+ case 127:
+ if (sInputLength > 0)
+ {
+ streamer_printf(streamer_get(), "\b \b");
+ sInputBuffer[--sInputLength] = '\0';
+ }
+ break;
+
+ default:
+ if (sInputLength < ArraySize(sInputBuffer) - 1)
+ {
+ sInputBuffer[sInputLength++] = input[i];
+ }
+ if (isprint(static_cast<int>(input[i])) || input[i] == '\t')
+ {
+ streamer_printf(streamer_get(), "%c", input[i]);
+ }
+ break;
+ }
+ }
+}
+
+void Engine::RunMainLoop()
+{
+ sInputLength = 0;
+
+ streamer_printf(streamer_get(), CHIP_SHELL_PROMPT);
+}
+
+} // namespace Shell
+} // namespace chip
diff --git a/src/lib/shell/streamer_cyw30739.cpp b/src/lib/shell/streamer_cyw30739.cpp
new file mode 100644
index 0000000..6c8e5ac
--- /dev/null
+++ b/src/lib/shell/streamer_cyw30739.cpp
@@ -0,0 +1,77 @@
+/*
+ *
+ * Copyright (c) 2021 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.
+ */
+
+#include <lib/core/CHIPSafeCasts.h>
+#include <lib/shell/streamer.h>
+#include <platform/PlatformManager.h>
+#include <wiced_hal_puart.h>
+#include <wiced_platform.h>
+
+namespace chip {
+namespace Shell {
+
+void ProcessInput(intptr_t args);
+
+static int streamer_cyw30739_init(streamer_t * streamer);
+static ssize_t streamer_cyw30739_read(streamer_t * streamer, char * buf, size_t len);
+static ssize_t streamer_cyw30739_write(streamer_t * streamer, const char * buf, size_t len);
+static void streamer_cyw30739_uart_rx_handler(void * arg);
+
+static streamer_t streamer_stdio = {
+ .init_cb = streamer_cyw30739_init,
+ .read_cb = streamer_cyw30739_read,
+ .write_cb = streamer_cyw30739_write,
+};
+
+streamer_t * streamer_get()
+{
+ return &streamer_stdio;
+}
+
+int streamer_cyw30739_init(streamer_t * streamer)
+{
+ wiced_platform_puart_init(streamer_cyw30739_uart_rx_handler);
+ return 0;
+}
+
+ssize_t streamer_cyw30739_read(streamer_t * streamer, char * buf, size_t len)
+{
+ size_t count;
+ for (count = 0; count < len; count++)
+ {
+ if (!wiced_hal_puart_read(Uint8::from_char(buf) + count))
+ break;
+ }
+ wiced_hal_puart_reset_puart_interrupt();
+ return count;
+}
+
+ssize_t streamer_cyw30739_write(streamer_t * streamer, const char * buf, size_t len)
+{
+ wiced_hal_puart_print(const_cast<char *>(buf));
+ return 0;
+}
+
+void streamer_cyw30739_uart_rx_handler(void * arg)
+{
+ DeviceLayer::PlatformMgr().LockChipStack();
+ DeviceLayer::PlatformMgr().ScheduleWork(ProcessInput, 0);
+ DeviceLayer::PlatformMgr().UnlockChipStack();
+}
+
+} // namespace Shell
+} // namespace chip
diff --git a/src/lwip/BUILD.gn b/src/lwip/BUILD.gn
index 6fb03fc..930fe80 100644
--- a/src/lwip/BUILD.gn
+++ b/src/lwip/BUILD.gn
@@ -31,7 +31,8 @@
assert(lwip_platform == "external" || lwip_platform == "standalone" ||
lwip_platform == "cc13x2_26x2" || lwip_platform == "efr32" ||
lwip_platform == "k32w0" || lwip_platform == "qpg" ||
- lwip_platform == "mbed" || lwip_platform == "p6",
+ lwip_platform == "mbed" || lwip_platform == "p6" ||
+ lwip_platform == "cyw30739",
"Unsupported lwIP platform: ${lwip_platform}")
if (lwip_platform != "external") {
@@ -52,6 +53,8 @@
import("//build_overrides/k32w0_sdk.gni")
} else if (lwip_platform == "p6") {
import("//build_overrides/p6.gni")
+} else if (lwip_platform == "cyw30739") {
+ import("//build_overrides/cyw30739_sdk.gni")
}
buildconfig_header("lwip_buildconfig") {
@@ -135,6 +138,7 @@
if (lwip_platform == "standalone") {
public += [ "standalone/arch/sys_arch.h" ]
sources += [ "standalone/sys_arch.c" ]
+ } else if (lwip_platform == "cyw30739") {
} else {
public += [
"${lwip_platform}/lwippools.h",
@@ -152,6 +156,8 @@
public_deps += [ "${chip_root}/src/lib/support" ]
} else if (lwip_platform == "k32w0") {
public_deps += [ "${k32w0_sdk_build_root}:k32w0_sdk" ]
+ } else if (lwip_platform == "cyw30739") {
+ public_deps += [ "${cyw30739_sdk_build_root}:cyw30739_sdk" ]
}
public_configs = [
diff --git a/src/lwip/cyw30739/arch/cc.h b/src/lwip/cyw30739/arch/cc.h
new file mode 100644
index 0000000..3a10bf1
--- /dev/null
+++ b/src/lwip/cyw30739/arch/cc.h
@@ -0,0 +1,23 @@
+/*
+ *
+ * Copyright (c) 2020 Nest Labs, Inc.
+ * All rights reserved.
+ *
+ * This document is the property of Nest. It is considered
+ * confidential and proprietary information.
+ *
+ * This document may not be reproduced or transmitted in any form,
+ * in whole or in part, without the express written permission of
+ * Nest.
+ *
+ * Description:
+ * This file defines processor-architecture- and toolchain-
+ * specific constants and types required for building
+ * LwIP against FreeRTOS.
+ *
+ */
+#pragma once
+
+#include <assert.h>
+
+#define LWIP_PLATFORM_ASSERT(MSG) assert(MSG)
diff --git a/src/lwip/cyw30739/arch/perf.h b/src/lwip/cyw30739/arch/perf.h
new file mode 100644
index 0000000..3799d0c
--- /dev/null
+++ b/src/lwip/cyw30739/arch/perf.h
@@ -0,0 +1,20 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 Nest Labs, Inc.
+ *
+ * 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
diff --git a/src/lwip/cyw30739/lwipopts.h b/src/lwip/cyw30739/lwipopts.h
new file mode 100644
index 0000000..40d3c1c
--- /dev/null
+++ b/src/lwip/cyw30739/lwipopts.h
@@ -0,0 +1,118 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 Nest Labs, Inc.
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * Compile-time configuration for LwIP on CYW30739 platform.
+ */
+#pragma once
+
+/* Make the lwip/errno.h to include the errno.h from the toolchain. */
+#define LWIP_ERRNO_INCLUDE <../include/errno.h>
+
+#if CHIP_HAVE_CONFIG_H
+#include <lwip/lwip_buildconfig.h>
+#endif
+
+/* NO SYS */
+#define NO_SYS 1
+#define LWIP_TIMERS 0
+
+/* Core locking */
+#define SYS_LIGHTWEIGHT_PROT 0
+#define LOCK_TCPIP_CORE()
+#define UNLOCK_TCPIP_CORE()
+
+/* Memory options */
+#define MEM_ALIGNMENT 4
+
+/* Internal Memory Pool Sizes */
+#define MEMP_SEPARATE_POOLS 1
+
+/* ARP options */
+#define LWIP_ARP 0
+
+/* IP options */
+#define LWIP_IPV4 0
+#define IP_REASSEMBLY 0
+#define LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS 1
+
+/* ICMP options */
+
+/* RAW options */
+
+/* DHCP options */
+
+/* AUTOIP options */
+
+/* SNMP MIB2 support */
+
+/* Multicast options */
+
+/* IGMP options */
+
+/* DNS options */
+
+/* UDP options */
+
+/* TCP options */
+#define LWIP_TCP 0
+
+/* Pbuf options */
+#define PBUF_POOL_BUFSIZE 1356
+
+/* Network Interfaces options */
+#define PBUF_POOL_SIZE 8
+
+/* LOOPIF options */
+
+/* Thread options */
+
+/* Sequential layer options */
+#define LWIP_NETCONN 0
+
+/* Socket options */
+#define LWIP_SOCKET 0
+#define LWIP_SOCKET_SET_ERRNO 0
+
+/* Statistics options */
+#define LWIP_STATS 0
+
+/* Checksum options */
+
+/* IPv6 options */
+#define LWIP_IPV6 1
+#define LWIP_IPV6_REASS 0
+#define LWIP_IPV6_ND 0
+#define LWIP_ND6_TCP_REACHABILITY_HINTS 0
+#define LWIP_ND6_LISTEN_RA 0
+#define LWIP_IPV6_ROUTER_SUPPORT 0
+
+/* Hook options */
+
+/* Debugging options */
+#ifndef LWIP_DEBUG
+#define LWIP_DEBUG 0
+#endif
+
+#define INET_DEBUG LWIP_DBG_OFF
+#define MEMP_DEBUG LWIP_DBG_OFF
+#define UDP_DEBUG LWIP_DBG_OFF
+#define IP6_DEBUG LWIP_DBG_OFF
+
+/* Performance tracking options */
diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn
index 741134a..5709d05 100644
--- a/src/platform/BUILD.gn
+++ b/src/platform/BUILD.gn
@@ -217,6 +217,11 @@
"CHIP_DEVICE_LAYER_TARGET=Ameba",
"CHIP_DEVICE_CONFIG_ENABLE_WIFI=${chip_enable_wifi}",
]
+ } else if (chip_device_platform == "cyw30739") {
+ defines += [
+ "CHIP_DEVICE_LAYER_TARGET_CYW30739=1",
+ "CHIP_DEVICE_LAYER_TARGET=CYW30739",
+ ]
}
}
} else {
@@ -345,6 +350,8 @@
_platform_target = "Ameba"
} else if (chip_device_platform == "fake") {
_platform_target = "fake"
+ } else if (chip_device_platform == "cyw30739") {
+ _platform_target = "CYW30739"
} else {
assert(false, "Unknown chip_device_platform: ${chip_device_platform}")
}
diff --git a/src/platform/CYW30739/BLEManagerImpl.cpp b/src/platform/CYW30739/BLEManagerImpl.cpp
new file mode 100644
index 0000000..eabb240
--- /dev/null
+++ b/src/platform/CYW30739/BLEManagerImpl.cpp
@@ -0,0 +1,917 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2020 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.
+ */
+
+/**
+ * @file
+ * Provides an implementation of the BLEManager singleton object
+ * for the P64343W platform.
+ */
+
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+
+#include <ble/CHIPBleServiceData.h>
+#include <lib/support/CodeUtils.h>
+#include <lib/support/logging/CHIPLogging.h>
+#include <platform/internal/BLEManager.h>
+
+#include "cycfg_gatt_db.h"
+#include "wiced_bt_stack.h"
+#include <wiced_bt_ble.h>
+#include <wiced_bt_gatt.h>
+#ifdef BLE_OTA_FW_UPGRADE
+#include <wiced_bt_ota_firmware_upgrade.h>
+#endif
+#include "wiced_platform_bt_cfg.h"
+
+using namespace ::chip;
+using namespace ::chip::Ble;
+
+namespace chip {
+namespace DeviceLayer {
+namespace Internal {
+
+namespace {
+
+const ChipBleUUID chipUUID_CHIPoBLEChar_RX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F,
+ 0x9D, 0x11 } };
+
+const ChipBleUUID ChipUUID_CHIPoBLEChar_TX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F,
+ 0x9D, 0x12 } };
+
+} // unnamed namespace
+
+BLEManagerImpl BLEManagerImpl::sInstance;
+
+wiced_bt_gatt_status_t app_gatts_callback(wiced_bt_gatt_evt_t event, wiced_bt_gatt_event_data_t * p_data);
+
+CHIP_ERROR BLEManagerImpl::_Init()
+{
+ CHIP_ERROR err;
+
+ // Initialize the CHIP BleLayer.
+ err = BleLayer::Init(this, this, &DeviceLayer::SystemLayer());
+ SuccessOrExit(err);
+
+ mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled;
+ if (CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART)
+ {
+ mFlags.Set(Flags::kFlag_AdvertisingEnabled, true);
+ }
+ else
+ {
+ mFlags.Set(Flags::kFlag_AdvertisingEnabled, false);
+ }
+ mNumCons = 0;
+ memset(mCons, 0, sizeof(mCons));
+ memset(mDeviceName, 0, sizeof(mDeviceName));
+
+ // Register with stack to receive GATT callback
+ wiced_bt_gatt_register(app_gatts_callback);
+
+ // Inform the stack to use this app GATT database
+ wiced_bt_gatt_db_init(gatt_database, gatt_database_len);
+
+ ChipLogProgress(DeviceLayer, "BLEManagerImpl::Init() complete");
+
+ PlatformMgr().ScheduleWork(DriveBLEState, 0);
+
+exit:
+ return err;
+}
+
+CHIP_ERROR BLEManagerImpl::_SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val)
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+
+ VerifyOrExit(val != ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, err = CHIP_ERROR_INVALID_ARGUMENT);
+ VerifyOrExit(mServiceMode != ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
+
+ if (val != mServiceMode)
+ {
+ mServiceMode = val;
+ PlatformMgr().ScheduleWork(DriveBLEState, 0);
+ }
+
+exit:
+ return err;
+}
+
+bool BLEManagerImpl::_IsAdvertisingEnabled(void)
+{
+ return mFlags.Has(Flags::kFlag_AdvertisingEnabled);
+}
+
+CHIP_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val)
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+
+ VerifyOrExit(mServiceMode != ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
+
+ if (mFlags.Has(Flags::kFlag_AdvertisingEnabled) != val)
+ {
+ mFlags.Set(Flags::kFlag_AdvertisingEnabled, val);
+ PlatformMgr().ScheduleWork(DriveBLEState, 0);
+ }
+
+exit:
+ return err;
+}
+
+/*
+ * TODO
+ */
+CHIP_ERROR BLEManagerImpl::_SetAdvertisingMode(BLEAdvertisingMode mode)
+{
+ (void) (mode);
+
+ return CHIP_ERROR_NOT_IMPLEMENTED;
+}
+
+#if 0
+CHIP_ERROR BLEManagerImpl::_SetFastAdvertisingEnabled(bool val)
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+
+ VerifyOrExit(mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
+
+ if (GetFlag(mFlags, kFlag_FastAdvertisingEnabled) != val)
+ {
+ SetFlag(mFlags, kFlag_FastAdvertisingEnabled, val);
+ PlatformMgr().ScheduleWork(DriveBLEState, 0);
+ }
+
+exit:
+ return err;
+}
+#endif
+
+CHIP_ERROR BLEManagerImpl::_GetDeviceName(char * buf, size_t bufSize)
+{
+ if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_NotSupported)
+ {
+ return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
+ }
+ if (strlen(mDeviceName) >= bufSize)
+ {
+ return CHIP_ERROR_BUFFER_TOO_SMALL;
+ }
+ strcpy(buf, mDeviceName);
+ ChipLogProgress(DeviceLayer, "Getting device name to : \"%s\"", mDeviceName);
+ return CHIP_NO_ERROR;
+}
+
+CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * deviceName)
+{
+ if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_NotSupported)
+ {
+ return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
+ }
+ if (deviceName != NULL && deviceName[0] != 0)
+ {
+ if (strlen(deviceName) >= kMaxDeviceNameLength)
+ {
+ return CHIP_ERROR_INVALID_ARGUMENT;
+ }
+ memset(mDeviceName, 0, kMaxDeviceNameLength);
+ strncpy(mDeviceName, deviceName, strlen(deviceName));
+ mFlags.Set(Flags::kFlag_DeviceNameSet, true);
+ ChipLogProgress(DeviceLayer, "Setting device name to : \"%s\"", deviceName);
+ }
+ else
+ {
+ wiced_platform_bt_cfg_settings.device_name[0] = 0;
+ mDeviceName[0] = 0;
+ mFlags.Set(Flags::kFlag_DeviceNameSet, false);
+ }
+
+ return CHIP_NO_ERROR;
+}
+
+uint16_t BLEManagerImpl::_NumConnections(void)
+{
+ return mNumCons;
+}
+
+void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
+{
+ switch (event->Type)
+ {
+ case DeviceEventType::kCHIPoBLESubscribe:
+ HandleSubscribeReceived(event->CHIPoBLESubscribe.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_TX);
+ {
+ ChipDeviceEvent _event;
+ _event.Type = DeviceEventType::kCHIPoBLEConnectionEstablished;
+ PlatformMgr().PostEventOrDie(&_event);
+ }
+ break;
+
+ case DeviceEventType::kCHIPoBLEUnsubscribe:
+ HandleUnsubscribeReceived(event->CHIPoBLEUnsubscribe.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_TX);
+ break;
+
+ case DeviceEventType::kCHIPoBLEWriteReceived:
+ ChipLogProgress(DeviceLayer, "_OnPlatformEvent kCHIPoBLEWriteReceived");
+ HandleWriteReceived(event->CHIPoBLEWriteReceived.ConId, &CHIP_BLE_SVC_ID, &chipUUID_CHIPoBLEChar_RX,
+ PacketBufferHandle::Adopt(event->CHIPoBLEWriteReceived.Data));
+ break;
+
+ case DeviceEventType::kCHIPoBLEIndicateConfirm:
+ HandleIndicationConfirmation(event->CHIPoBLEIndicateConfirm.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_TX);
+ break;
+
+ case DeviceEventType::kCHIPoBLEConnectionError:
+ HandleConnectionError(event->CHIPoBLEConnectionError.ConId, event->CHIPoBLEConnectionError.Reason);
+ break;
+
+ case DeviceEventType::kFabricMembershipChange:
+ case DeviceEventType::kServiceProvisioningChange:
+ case DeviceEventType::kAccountPairingChange:
+
+ // If CHIPOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED is enabled, and there is a change to the
+ // device's provisioning state, then automatically disable CHIPoBLE advertising if the device
+ // is now fully provisioned.
+#if CHIP_DEVICE_CONFIG_CHIPOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED
+ if (ConfigurationMgr().IsFullyProvisioned())
+ {
+ ClearFlag(mFlags, kFlag_AdvertisingEnabled);
+ ChipLogProgress(DeviceLayer, "CHIPoBLE advertising disabled because device is fully provisioned");
+ }
+#endif // CHIP_DEVICE_CONFIG_CHIPOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED
+
+ // Force the advertising state to be refreshed to reflect new provisioning state.
+ mFlags.Set(Flags::kFlag_AdvertisingRefreshNeeded, true);
+
+ DriveBLEState();
+ break;
+
+ default:
+ break;
+ }
+}
+
+bool BLEManagerImpl::SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId)
+{
+ ChipLogProgress(DeviceLayer, "BLEManagerImpl::SubscribeCharacteristic() not supported");
+ return false;
+}
+
+bool BLEManagerImpl::UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId)
+{
+ ChipLogProgress(DeviceLayer, "BLEManagerImpl::UnsubscribeCharacteristic() not supported");
+ return false;
+}
+
+bool BLEManagerImpl::CloseConnection(BLE_CONNECTION_OBJECT conId)
+{
+ ChipLogProgress(DeviceLayer, "Closing BLE GATT connection (con %u)", conId);
+
+ // Initiate a GAP disconnect.
+ wiced_bt_gatt_status_t gatt_err = wiced_bt_gatt_disconnect((uint16_t) conId);
+ if (gatt_err != WICED_BT_GATT_SUCCESS)
+ {
+ ChipLogError(DeviceLayer, "wiced_bt_gatt_disconnect() failed: %d", gatt_err);
+ }
+
+ return (gatt_err == WICED_BT_GATT_SUCCESS);
+}
+
+uint16_t BLEManagerImpl::GetMTU(BLE_CONNECTION_OBJECT conId) const
+{
+ CHIPoBLEConState * p_conn;
+
+ /* Check if target connection state exists. */
+ p_conn = BLEManagerImpl::sInstance.GetConnectionState(conId);
+
+ if (!p_conn)
+ {
+ return wiced_platform_bt_cfg_settings.gatt_cfg.max_mtu_size;
+ }
+ else
+ {
+ return p_conn->Mtu;
+ }
+}
+
+bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId,
+ PacketBufferHandle data)
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+ uint16_t dataLen = data->DataLength();
+ wiced_bt_gatt_status_t gatt_err = WICED_BT_GATT_SUCCESS;
+ CHIPoBLEConState * conState = GetConnectionState(conId);
+
+ VerifyOrExit(conState != NULL, err = CHIP_ERROR_INVALID_ARGUMENT);
+
+ ChipLogDetail(DeviceLayer, "Sending indication for CHIPoBLE TX characteristic (con %u, len %u)", conId, dataLen);
+
+ // Send a indication for the CHIPoBLE TX characteristic to the client containing the supplied data.
+ gatt_err = wiced_bt_gatt_send_indication((uint16_t) conId, HDLC_CHIP_SERVICE_CHAR_C2_VALUE, dataLen, data->Start());
+
+exit:
+ if (gatt_err != WICED_BT_GATT_SUCCESS)
+ {
+ ChipLogError(DeviceLayer, "BLEManagerImpl::SendIndication() failed: %d", gatt_err);
+ return false;
+ }
+ return err == CHIP_NO_ERROR;
+}
+
+bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId,
+ PacketBufferHandle data)
+
+{
+ ChipLogError(DeviceLayer, "BLEManagerImpl::SendWriteRequest() not supported");
+ return false;
+}
+
+bool BLEManagerImpl::SendReadRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId,
+ PacketBufferHandle data)
+{
+ ChipLogError(DeviceLayer, "BLEManagerImpl::SendReadRequest() not supported");
+ return false;
+}
+
+bool BLEManagerImpl::SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext,
+ const ChipBleUUID * svcId, const ChipBleUUID * charId)
+{
+ ChipLogError(DeviceLayer, "BLEManagerImpl::SendReadResponse() not supported");
+ return false;
+}
+
+void BLEManagerImpl::NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId) {}
+
+void BLEManagerImpl::DriveBLEState(void)
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+
+ // Perform any initialization actions that must occur after the CHIP task is running.
+ if (!mFlags.Has(Flags::kFlag_AsyncInitCompleted))
+ {
+ mFlags.Set(Flags::kFlag_AsyncInitCompleted, true);
+
+ // If CHIP_DEVICE_CONFIG_CHIPOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED is enabled,
+ // disable CHIPoBLE advertising if the device is fully provisioned.
+#if CHIP_DEVICE_CONFIG_CHIPOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED
+ if (ConfigurationMgr().IsFullyProvisioned())
+ {
+ ClearFlag(mFlags, kFlag_AdvertisingEnabled);
+ ChipLogProgress(DeviceLayer, "CHIPoBLE advertising disabled because device is fully provisioned");
+ }
+#endif // CHIP_DEVICE_CONFIG_CHIPOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED
+ }
+
+ // If the application has enabled CHIPoBLE and BLE advertising...
+ if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_Enabled &&
+ mFlags.Has(Flags::kFlag_AdvertisingEnabled)
+#if CHIP_DEVICE_CONFIG_CHIPOBLE_SINGLE_CONNECTION
+ // and no connections are active...
+ && (mNumCons == 0)
+#endif
+ )
+ {
+ // Start/re-start SoftDevice advertising if not already advertising, or if the
+ // advertising state of the SoftDevice needs to be refreshed.
+ if (!mFlags.Has(Flags::kFlag_Advertising) || mFlags.Has(Flags::kFlag_AdvertisingRefreshNeeded))
+ {
+ ChipLogProgress(DeviceLayer, "CHIPoBLE advertising started");
+
+ mFlags.Set(Flags::kFlag_Advertising, true);
+ mFlags.Set(Flags::kFlag_AdvertisingRefreshNeeded, false);
+
+ SetAdvertisingData();
+
+ wiced_bt_start_advertisements(BTM_BLE_ADVERT_UNDIRECTED_HIGH, BLE_ADDR_PUBLIC, NULL);
+
+ // Post a CHIPoBLEAdvertisingChange(Started) event.
+ {
+ ChipDeviceEvent advChange;
+ advChange.Type = DeviceEventType::kCHIPoBLEAdvertisingChange;
+ advChange.CHIPoBLEAdvertisingChange.Result = kActivity_Started;
+ PlatformMgr().PostEventOrDie(&advChange);
+ }
+ }
+ }
+
+ // Otherwise, stop advertising if currently active.
+ else
+ {
+ if (mFlags.Has(Flags::kFlag_Advertising))
+ {
+ mFlags.Set(Flags::kFlag_Advertising, false);
+
+ ChipLogProgress(DeviceLayer, "CHIPoBLE stop advertising");
+ wiced_bt_start_advertisements(BTM_BLE_ADVERT_OFF, BLE_ADDR_PUBLIC, NULL);
+ }
+ }
+
+ // exit:
+ if (err != CHIP_NO_ERROR)
+ {
+ ChipLogError(DeviceLayer, "Disabling CHIPoBLE service due to error: %s", ErrorStr(err));
+ mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Disabled;
+ }
+}
+
+/*
+ * This function searches through the GATT DB to point to the attribute
+ * corresponding to the given handle
+ */
+gatt_db_lookup_table_t * BLEManagerImpl::GetGattAttr(uint16_t handle)
+{
+ /* Search for the given handle in the GATT DB and return the pointer to the
+ correct attribute */
+ uint8_t array_index = 0;
+
+ for (array_index = 0; array_index < app_gatt_db_ext_attr_tbl_size; array_index++)
+ {
+ if (app_gatt_db_ext_attr_tbl[array_index].handle == handle)
+ {
+ return (&app_gatt_db_ext_attr_tbl[array_index]);
+ }
+ }
+ return NULL;
+}
+
+/*
+ * Currently there is no reason to pass Read Req to CHIP. Only process request for
+ * attributes in the GATT DB attribute table
+ */
+wiced_bt_gatt_status_t BLEManagerImpl::HandleGattServiceRead(uint16_t conn_id, wiced_bt_gatt_read_t * p_read_data)
+{
+ gatt_db_lookup_table_t * puAttribute;
+ int attr_len_to_copy;
+
+#ifdef BLE_OTA_FW_UPGRADE
+ if (wiced_ota_fw_upgrade_is_gatt_handle(p_read_data->handle))
+ {
+ return wiced_ota_fw_upgrade_read_handler(conn_id, p_read_data);
+ }
+#endif
+
+ /* Get the right address for the handle in Gatt DB */
+ if (NULL == (puAttribute = GetGattAttr(p_read_data->handle)))
+ {
+ ChipLogError(DeviceLayer, "Read handle attribute not found. Handle:0x%X\n", p_read_data->handle);
+ return WICED_BT_GATT_INVALID_HANDLE;
+ }
+
+ attr_len_to_copy = puAttribute->cur_len;
+
+ ChipLogProgress(DeviceLayer, "GATT Read handler: conn_id:%04x handle:%04x len:%d", conn_id, p_read_data->handle,
+ attr_len_to_copy);
+
+ /* If the incoming offset is greater than the current length in the GATT DB
+ then the data cannot be read back*/
+ if (p_read_data->offset >= puAttribute->cur_len)
+ {
+ attr_len_to_copy = 0;
+ }
+
+ /* Calculate the number of bytes and the position of the data and copy it to
+ the given pointer */
+ if (attr_len_to_copy != 0)
+ {
+ uint8_t * from;
+ int size_to_copy = attr_len_to_copy - p_read_data->offset;
+
+ if (size_to_copy > *p_read_data->p_val_len)
+ {
+ size_to_copy = *p_read_data->p_val_len;
+ }
+
+ from = ((uint8_t *) puAttribute->p_data) + p_read_data->offset;
+ *p_read_data->p_val_len = size_to_copy;
+
+ memcpy(p_read_data->p_val, from, size_to_copy);
+ }
+ return WICED_BT_GATT_SUCCESS;
+}
+
+/*
+ * If Attribute is for CHIP, pass it through. Otherwise process request for
+ * attributes in the GATT DB attribute table.
+ */
+wiced_bt_gatt_status_t BLEManagerImpl::HandleGattServiceWrite(uint16_t conn_id, wiced_bt_gatt_write_t * p_data)
+{
+ wiced_bt_gatt_status_t result = WICED_BT_GATT_SUCCESS;
+ gatt_db_lookup_table_t * puAttribute;
+ const uint16_t valLen = p_data->val_len;
+
+#ifdef BLE_OTA_FW_UPGRADE
+ if (wiced_ota_fw_upgrade_is_gatt_handle(p_data->handle))
+ {
+ return wiced_ota_fw_upgrade_write_handler(conn_id, p_data);
+ }
+#endif
+
+ // special handling for CHIP RX path
+ if (p_data->handle == HDLC_CHIP_SERVICE_CHAR_C1_VALUE)
+ {
+ System::PacketBufferHandle buf;
+
+ buf = System::PacketBufferHandle::NewWithData(p_data->p_val, valLen, 0, 0);
+ if (!buf.IsNull())
+ {
+
+ ChipLogDetail(DeviceLayer, "Write received for CHIPoBLE RX characteristic con %04x len %d", conn_id, valLen);
+
+ // Post an event to the CHIP queue to deliver the data into the CHIP stack.
+ {
+ ChipDeviceEvent event;
+ event.Type = DeviceEventType::kCHIPoBLEWriteReceived;
+ event.CHIPoBLEWriteReceived.ConId = conn_id;
+ event.CHIPoBLEWriteReceived.Data = std::move(buf).UnsafeRelease();
+ PlatformMgr().PostEventOrDie(&event);
+ }
+ }
+ else
+ {
+ ChipLogError(DeviceLayer, "BLEManagerImpl: Out of buffers during CHIPoBLE RX");
+ }
+ }
+ else
+ {
+ ChipLogDetail(DeviceLayer, "Write received for CHIPoBLE RX characteristic con:%04x handle:%04x len:%d", conn_id,
+ p_data->handle, valLen);
+
+ /* Get the right address for the handle in Gatt DB */
+ if (NULL == (puAttribute = GetGattAttr(p_data->handle)))
+ {
+ ChipLogError(DeviceLayer, "BLEManagerImpl: Write wrong handle:%04x", p_data->handle);
+ return WICED_BT_GATT_INVALID_HANDLE;
+ }
+ puAttribute->cur_len = valLen > puAttribute->max_len ? puAttribute->max_len : valLen;
+ memcpy(puAttribute->p_data, p_data->p_val, puAttribute->cur_len);
+
+ // Post an event to the Chip queue to process either a CHIPoBLE Subscribe or Unsubscribe based on
+ // whether the client is enabling or disabling indications.
+ if (p_data->handle == HDLD_CHIP_SERVICE_RX_CLIENT_CHAR_CONFIG)
+ {
+ ChipDeviceEvent event;
+ event.Type = (app_chip_service_char_tx_client_char_config[0] != 0) ? DeviceEventType::kCHIPoBLESubscribe
+ : DeviceEventType::kCHIPoBLEUnsubscribe;
+ event.CHIPoBLESubscribe.ConId = conn_id;
+ PlatformMgr().PostEventOrDie(&event);
+ }
+
+ ChipLogProgress(DeviceLayer, "CHIPoBLE %s received",
+ app_chip_service_char_tx_client_char_config[0] != 0 ? "subscribe" : "unsubscribe");
+ }
+ return result;
+}
+
+/*
+ * Process MTU request received from the GATT client
+ */
+wiced_bt_gatt_status_t BLEManagerImpl::HandleGattServiceMtuReq(wiced_bt_gatt_attribute_request_t * p_data,
+ CHIPoBLEConState * p_conn)
+{
+ p_data->data.mtu = p_conn->Mtu;
+
+ return WICED_BT_GATT_SUCCESS;
+}
+
+/*
+ * Process GATT Indication Confirm from the client
+ */
+wiced_bt_gatt_status_t BLEManagerImpl::HandleGattServiceIndCfm(uint16_t conn_id, uint16_t handle)
+{
+ ChipLogDetail(DeviceLayer, "GATT Ind Cfm received con:%04x handle:%d", conn_id, handle);
+
+ if (handle == HDLC_CHIP_SERVICE_CHAR_C2_VALUE)
+ {
+ ChipDeviceEvent event;
+ event.Type = DeviceEventType::kCHIPoBLEIndicateConfirm;
+ event.CHIPoBLEIndicateConfirm.ConId = conn_id;
+ PlatformMgr().PostEventOrDie(&event);
+ }
+#ifdef BLE_OTA_FW_UPGRADE
+ else if (wiced_ota_fw_upgrade_is_gatt_handle(handle))
+ {
+ return wiced_ota_fw_upgrade_indication_cfm_handler(conn_id, handle);
+ }
+#endif
+ return WICED_BT_GATT_SUCCESS;
+}
+
+/*
+ * Process GATT attribute requests
+ */
+wiced_bt_gatt_status_t BLEManagerImpl::HandleGattServiceRequestEvent(wiced_bt_gatt_attribute_request_t * p_request,
+ CHIPoBLEConState * p_conn)
+{
+ wiced_bt_gatt_status_t result = WICED_BT_GATT_INVALID_PDU;
+
+ switch (p_request->request_type)
+ {
+ case GATTS_REQ_TYPE_READ:
+ result = HandleGattServiceRead(p_request->conn_id, &(p_request->data.read_req));
+ break;
+
+ case GATTS_REQ_TYPE_WRITE:
+ result = HandleGattServiceWrite(p_request->conn_id, &(p_request->data.write_req));
+ break;
+
+ case GATTS_REQ_TYPE_MTU:
+ result = HandleGattServiceMtuReq(p_request, p_conn);
+ break;
+
+ case GATTS_REQ_TYPE_CONF:
+ result = HandleGattServiceIndCfm(p_request->conn_id, p_request->data.handle);
+ break;
+
+ default:
+ break;
+ }
+
+ return result;
+}
+
+/*
+ * Handle GATT connection events from the stack
+ */
+wiced_bt_gatt_status_t BLEManagerImpl::HandleGattConnectEvent(wiced_bt_gatt_connection_status_t * p_conn_status,
+ CHIPoBLEConState * p_conn)
+{
+#ifdef BLE_OTA_FW_UPGRADE
+ wiced_ota_fw_upgrade_connection_status_event(p_conn_status);
+#endif
+
+ if (p_conn_status->connected)
+ {
+ /* Device got connected */
+ p_conn->connected = true;
+ ChipLogProgress(DeviceLayer, "BLE GATT connection up (con %u)", p_conn_status->conn_id);
+ }
+ else /* Device got disconnected */
+ {
+ ChipDeviceEvent event;
+ event.Type = DeviceEventType::kCHIPoBLEConnectionError;
+ event.CHIPoBLEConnectionError.ConId = p_conn_status->conn_id;
+
+ switch (p_conn_status->reason)
+ {
+ case GATT_CONN_TERMINATE_PEER_USER:
+ event.CHIPoBLEConnectionError.Reason = BLE_ERROR_REMOTE_DEVICE_DISCONNECTED;
+ break;
+
+ case GATT_CONN_TERMINATE_LOCAL_HOST:
+ event.CHIPoBLEConnectionError.Reason = BLE_ERROR_APP_CLOSED_CONNECTION;
+ break;
+
+ default:
+ event.CHIPoBLEConnectionError.Reason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT;
+ break;
+ }
+
+ ChipLogProgress(DeviceLayer, "BLE GATT connection closed (con %u, reason %u)", p_conn_status->conn_id,
+ p_conn_status->reason);
+
+ PlatformMgr().PostEventOrDie(&event);
+
+ // Arrange to re-enable connectable advertising in case it was disabled due to the
+ // maximum connection limit being reached.
+ mFlags.Set(Flags::kFlag_Advertising, false);
+ PlatformMgr().ScheduleWork(DriveBLEState, 0);
+
+ ReleaseConnectionState(p_conn->ConId);
+ }
+ return WICED_BT_GATT_SUCCESS;
+}
+
+/*
+ * Process GATT requests. Callback is received in the BT stack thread context.
+ *
+ */
+wiced_bt_gatt_status_t app_gatts_callback(wiced_bt_gatt_evt_t event, wiced_bt_gatt_event_data_t * p_data)
+{
+ uint16_t conn_id;
+ BLEManagerImpl::CHIPoBLEConState * p_conn;
+
+ /* Check parameter. */
+ if (!p_data)
+ {
+ return WICED_BT_GATT_ILLEGAL_PARAMETER;
+ }
+
+ /* Check if target connection state exists. */
+ switch (event)
+ {
+ case GATT_CONNECTION_STATUS_EVT:
+ conn_id = p_data->connection_status.conn_id;
+ break;
+
+ case GATT_OPERATION_CPLT_EVT:
+ conn_id = p_data->operation_complete.conn_id;
+ break;
+
+ case GATT_DISCOVERY_RESULT_EVT:
+ conn_id = p_data->discovery_result.conn_id;
+ break;
+
+ case GATT_DISCOVERY_CPLT_EVT:
+ conn_id = p_data->discovery_complete.conn_id;
+ break;
+
+ case GATT_ATTRIBUTE_REQUEST_EVT:
+ conn_id = p_data->attribute_request.conn_id;
+ break;
+
+ case GATT_CONGESTION_EVT:
+ conn_id = p_data->congestion.conn_id;
+ break;
+
+ default:
+ return WICED_BT_GATT_ILLEGAL_PARAMETER;
+ }
+
+ p_conn = BLEManagerImpl::sInstance.GetConnectionState(conn_id);
+
+ /* Allocate connection state if no exist. */
+ if (!p_conn)
+ {
+ p_conn = BLEManagerImpl::sInstance.AllocConnectionState(conn_id);
+
+ if (!p_conn)
+ {
+ return WICED_BT_GATT_INSUF_RESOURCE;
+ }
+ }
+
+ switch (event)
+ {
+ case GATT_CONNECTION_STATUS_EVT:
+ return BLEManagerImpl::sInstance.HandleGattConnectEvent(&p_data->connection_status, p_conn);
+
+ case GATT_ATTRIBUTE_REQUEST_EVT:
+ return BLEManagerImpl::sInstance.HandleGattServiceRequestEvent(&p_data->attribute_request, p_conn);
+
+ default:
+ break;
+ }
+
+ return WICED_BT_GATT_ILLEGAL_PARAMETER;
+}
+
+void BLEManagerImpl::SetAdvertisingData(void)
+{
+ CHIP_ERROR err;
+ wiced_bt_ble_advert_elem_t adv_elem[4];
+ uint8_t num_elem = 0;
+ uint8_t flag = BTM_BLE_GENERAL_DISCOVERABLE_FLAG | BTM_BLE_BREDR_NOT_SUPPORTED;
+ uint8_t chip_service_uuid[2] = { BIT16_TO_8(__UUID16_CHIPoBLEService) };
+ ChipBLEDeviceIdentificationInfo mDeviceIdInfo;
+ uint16_t deviceDiscriminator = 0;
+ uint8_t localDeviceNameLen;
+ uint8_t service_data[9];
+ uint8_t * p = service_data;
+ uint8_t * rpa = wiced_btm_get_private_bda();
+
+ // Initialize the CHIP BLE Device Identification Information block that will be sent as payload
+ // within the BLE service advertisement data.
+ err = ConfigurationMgr().GetBLEDeviceIdentificationInfo(mDeviceIdInfo);
+ SuccessOrExit(err);
+
+ // Verify device name was not already set
+ if (!sInstance.mFlags.Has(Flags::kFlag_DeviceNameSet))
+ {
+ /* Default device name is CHIP-<DISCRIMINATOR> */
+ deviceDiscriminator = mDeviceIdInfo.GetDeviceDiscriminator();
+
+ memset(sInstance.mDeviceName, 0, kMaxDeviceNameLength);
+ snprintf(sInstance.mDeviceName, kMaxDeviceNameLength, "%s%04u", CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX,
+ deviceDiscriminator);
+ localDeviceNameLen = strlen(sInstance.mDeviceName);
+
+ memset((void *) app_gap_device_name, 0, sizeof(app_gap_device_name));
+ strncpy((char *) app_gap_device_name, sInstance.mDeviceName, sizeof(app_gap_device_name) - 1);
+ app_gatt_db_ext_attr_tbl[0].cur_len = app_gatt_db_ext_attr_tbl[0].max_len < strlen(sInstance.mDeviceName)
+ ? app_gatt_db_ext_attr_tbl[0].max_len
+ : strlen(sInstance.mDeviceName);
+
+ ChipLogProgress(DeviceLayer, "SetAdvertisingData: device name set: %s", sInstance.mDeviceName);
+ }
+ else
+ {
+ localDeviceNameLen = strlen(sInstance.mDeviceName);
+ }
+
+ ChipLogProgress(DeviceLayer, "SetAdvertisingData: RPA: %02X%02X%02X%02X%02X%02X", rpa[0], rpa[1], rpa[2], rpa[3], rpa[4],
+ rpa[5]);
+
+ /* First element is the advertisement flags */
+ adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_FLAG;
+ adv_elem[num_elem].len = sizeof(uint8_t);
+ adv_elem[num_elem].p_data = &flag;
+ num_elem++;
+
+ /* Second element is the service data for CHIP service */
+ adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_SERVICE_DATA;
+ adv_elem[num_elem].len = sizeof(service_data);
+ adv_elem[num_elem].p_data = service_data;
+ num_elem++;
+ UINT8_TO_STREAM(p, chip_service_uuid[0]);
+ UINT8_TO_STREAM(p, chip_service_uuid[1]);
+ UINT8_TO_STREAM(p, 0); // CHIP BLE Opcode == 0x00 (Uncommissioned)
+ UINT16_TO_STREAM(p, deviceDiscriminator);
+ UINT8_TO_STREAM(p, mDeviceIdInfo.DeviceVendorId[0]);
+ UINT8_TO_STREAM(p, mDeviceIdInfo.DeviceVendorId[1]);
+ UINT8_TO_STREAM(p, mDeviceIdInfo.DeviceProductId[0]);
+ UINT8_TO_STREAM(p, mDeviceIdInfo.DeviceProductId[1]);
+
+ adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_NAME_COMPLETE;
+ adv_elem[num_elem].len = localDeviceNameLen;
+ adv_elem[num_elem].p_data = (uint8_t *) sInstance.mDeviceName;
+ num_elem++;
+
+ wiced_bt_ble_set_raw_advertisement_data(num_elem, adv_elem);
+
+ /* Configure Scan Response data */
+ num_elem = 0;
+ adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_NAME_COMPLETE;
+ adv_elem[num_elem].len = localDeviceNameLen;
+ adv_elem[num_elem].p_data = (uint8_t *) sInstance.mDeviceName;
+ num_elem++;
+
+ wiced_bt_ble_set_raw_scan_response_data(num_elem, adv_elem);
+
+exit:
+ ChipLogProgress(DeviceLayer, "BLEManagerImpl::SetAdvertisingData err:%ld", err.AsInteger());
+}
+
+BLEManagerImpl::CHIPoBLEConState * BLEManagerImpl::AllocConnectionState(uint16_t conId)
+{
+ for (uint16_t i = 0; i < kMaxConnections; i++)
+ {
+ if (mCons[i].connected == false)
+ {
+ mCons[i].ConId = conId;
+ mCons[i].Mtu = wiced_platform_bt_cfg_settings.gatt_cfg.max_mtu_size;
+ mCons[i].connected = false;
+
+ mNumCons++;
+
+ return &mCons[i];
+ }
+ }
+ ChipLogError(DeviceLayer, "Failed to allocate CHIPoBLEConState");
+ return NULL;
+}
+
+BLEManagerImpl::CHIPoBLEConState * BLEManagerImpl::GetConnectionState(uint16_t conId)
+{
+ for (uint16_t i = 0; i < kMaxConnections; i++)
+ {
+ if (mCons[i].ConId == conId)
+ {
+ return &mCons[i];
+ }
+ }
+ ChipLogError(DeviceLayer, "Failed to find CHIPoBLEConState");
+ return NULL;
+}
+
+bool BLEManagerImpl::ReleaseConnectionState(uint16_t conId)
+{
+ for (uint16_t i = 0; i < kMaxConnections; i++)
+ {
+ if (mCons[i].ConId == conId)
+ {
+ memset(&mCons[i], 0, sizeof(CHIPoBLEConState));
+ mNumCons--;
+ return true;
+ }
+ }
+ ChipLogError(DeviceLayer, "Failed to delete CHIPoBLEConState");
+ return false;
+}
+
+void BLEManagerImpl::DriveBLEState(intptr_t arg)
+{
+ sInstance.DriveBLEState();
+}
+
+} // namespace Internal
+} // namespace DeviceLayer
+} // namespace chip
+
+#endif
diff --git a/src/platform/CYW30739/BLEManagerImpl.h b/src/platform/CYW30739/BLEManagerImpl.h
new file mode 100644
index 0000000..9aedc3a
--- /dev/null
+++ b/src/platform/CYW30739/BLEManagerImpl.h
@@ -0,0 +1,180 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2018 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.
+ */
+
+/**
+ * @file
+ * Provides an implementation of the BLEManager singleton object
+ * for the P64343W platform.
+ */
+
+#pragma once
+
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+
+#include "cycfg_gatt_db.h"
+#include <wiced_bt_ble.h>
+#include <wiced_bt_gatt.h>
+#include <wiced_bt_stack.h>
+
+namespace chip {
+namespace DeviceLayer {
+namespace Internal {
+
+/**
+ * Concrete implementation of the NetworkProvisioningServer singleton object for the P64343W platform.
+ */
+class BLEManagerImpl final : public BLEManager,
+ private Ble::BleLayer,
+ private Ble::BlePlatformDelegate,
+ private Ble::BleApplicationDelegate
+{
+ // Allow the BLEManager interface class to delegate method calls to
+ // the implementation methods provided by this class.
+ friend BLEManager;
+
+ // ===== Members that implement the BLEManager internal interface.
+
+ CHIP_ERROR _Init(void);
+ CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; }
+ CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void);
+ CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
+ bool _IsAdvertisingEnabled(void);
+ CHIP_ERROR _SetAdvertisingEnabled(bool val);
+ bool _IsFastAdvertisingEnabled(void);
+#if 0
+ CHIP_ERROR _SetFastAdvertisingEnabled(bool val);
+#endif
+ bool _IsAdvertising(void);
+ CHIP_ERROR _SetAdvertisingMode(BLEAdvertisingMode mode);
+ CHIP_ERROR _GetDeviceName(char * buf, size_t bufSize);
+ CHIP_ERROR _SetDeviceName(const char * deviceName);
+ uint16_t _NumConnections(void);
+ void _OnPlatformEvent(const ChipDeviceEvent * event);
+ ::chip::Ble::BleLayer * _GetBleLayer(void);
+
+ // ===== Members that implement virtual methods on BlePlatformDelegate.
+
+ bool SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId,
+ const Ble::ChipBleUUID * charId) override;
+ bool UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId,
+ const Ble::ChipBleUUID * charId) override;
+ bool CloseConnection(BLE_CONNECTION_OBJECT conId) override;
+ uint16_t GetMTU(BLE_CONNECTION_OBJECT conId) const override;
+ bool SendIndication(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId,
+ System::PacketBufferHandle data) override;
+ bool SendWriteRequest(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId,
+ System::PacketBufferHandle data) override;
+ bool SendReadRequest(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId,
+ System::PacketBufferHandle data) override;
+ bool SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext, const Ble::ChipBleUUID * svcId,
+ const Ble::ChipBleUUID * charId) override;
+
+ // ===== Members that implement virtual methods on BleApplicationDelegate.
+
+ void NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId) override;
+
+ // ===== Members for internal use by the following friends.
+
+ friend BLEManager & BLEMgr(void);
+ friend BLEManagerImpl & BLEMgrImpl(void);
+
+public:
+ static BLEManagerImpl sInstance;
+
+ // ===== Private members reserved for use by this class only.
+ enum class Flags : uint16_t
+ {
+ kFlag_AsyncInitCompleted = 0x0001, /**< One-time asynchronous initialization actions have been performed. */
+ kFlag_AdvertisingEnabled = 0x0002, /**< The application has enabled CHIPoBLE advertising. */
+ kFlag_FastAdvertisingEnabled = 0x0004, /**< The application has enabled fast advertising. */
+ kFlag_Advertising = 0x0008, /**< The system is currently CHIPoBLE advertising. */
+ kFlag_AdvertisingRefreshNeeded =
+ 0x0010, /**< The advertising state/configuration has changed, but the SoftDevice has yet to be updated. */
+ kFlag_DeviceNameSet = 0x0020,
+ };
+
+ enum
+ {
+ kMaxConnections = BLE_LAYER_NUM_BLE_ENDPOINTS,
+ };
+
+ struct CHIPoBLEConState
+ {
+ // System::PacketBuffer * PendingIndBuf;
+ uint16_t ConId;
+ uint16_t Mtu;
+ bool connected;
+ };
+
+ CHIPoBLEConState mCons[kMaxConnections];
+ uint16_t mNumCons;
+ CHIPoBLEServiceMode mServiceMode;
+ BitFlags<Flags> mFlags;
+ char mDeviceName[kMaxDeviceNameLength];
+
+ void DriveBLEState(void);
+ void SetAdvertisingData(void);
+
+ wiced_bt_gatt_status_t HandleGattConnectEvent(wiced_bt_gatt_connection_status_t * p_conn_status, CHIPoBLEConState * p_conn);
+ wiced_bt_gatt_status_t HandleGattServiceRead(uint16_t conn_id, wiced_bt_gatt_read_t * p_read_data);
+ wiced_bt_gatt_status_t HandleGattServiceWrite(uint16_t conn_id, wiced_bt_gatt_write_t * p_data);
+ wiced_bt_gatt_status_t HandleGattServiceMtuReq(wiced_bt_gatt_attribute_request_t * p_data, CHIPoBLEConState * p_conn);
+ wiced_bt_gatt_status_t HandleGattServiceIndCfm(uint16_t conn_id, uint16_t handle);
+ wiced_bt_gatt_status_t HandleGattServiceRequestEvent(wiced_bt_gatt_attribute_request_t * p_request, CHIPoBLEConState * p_conn);
+
+ CHIPoBLEConState * AllocConnectionState(uint16_t conId);
+ CHIPoBLEConState * GetConnectionState(uint16_t conId);
+ bool ReleaseConnectionState(uint16_t conId);
+ gatt_db_lookup_table_t * GetGattAttr(uint16_t handle);
+
+ static void DriveBLEState(intptr_t arg);
+};
+
+/**
+ * Returns a reference to the public interface of the BLEManager singleton object.
+ *
+ * Internal components should use this to access features of the BLEManager object
+ * that are common to all platforms.
+ */
+inline BLEManager & BLEMgr(void)
+{
+ return BLEManagerImpl::sInstance;
+}
+
+/**
+ * Returns the platform-specific implementation of the BLEManager singleton object.
+ *
+ * Internal components can use this to gain access to features of the BLEManager
+ * that are specific to the P64343W platform.
+ */
+inline BLEManagerImpl & BLEMgrImpl(void)
+{
+ return BLEManagerImpl::sInstance;
+}
+
+inline Ble::BleLayer * BLEManagerImpl::_GetBleLayer()
+{
+ return this;
+}
+
+} // namespace Internal
+} // namespace DeviceLayer
+} // namespace chip
+
+#endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
diff --git a/src/platform/CYW30739/BUILD.gn b/src/platform/CYW30739/BUILD.gn
new file mode 100644
index 0000000..b09c70c
--- /dev/null
+++ b/src/platform/CYW30739/BUILD.gn
@@ -0,0 +1,81 @@
+# Copyright (c) 2021 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.
+
+import("//build_overrides/chip.gni")
+
+import("${chip_root}/src/platform/device.gni")
+
+assert(chip_device_platform == "cyw30739")
+
+if (chip_enable_openthread) {
+ import("//build_overrides/openthread.gni")
+}
+
+static_library("CYW30739") {
+ sources = [
+ "../SingletonConfigurationManager.cpp",
+ "BLEManagerImpl.cpp",
+ "BLEManagerImpl.h",
+ "BlePlatformConfig.h",
+ "CHIPDevicePlatformConfig.h",
+ "CHIPDevicePlatformEvent.h",
+ "CHIPPlatformConfig.h",
+ "CYW30739Config.cpp",
+ "CYW30739Config.h",
+ "ConfigurationManagerImpl.cpp",
+ "ConfigurationManagerImpl.h",
+ "ConnectivityManagerImpl.cpp",
+ "ConnectivityManagerImpl.h",
+ "DeviceNetworkProvisioningDelegateImpl.cpp",
+ "DeviceNetworkProvisioningDelegateImpl.h",
+ "DiagnosticDataProviderImpl.cpp",
+ "DiagnosticDataProviderImpl.h",
+ "InetPlatformConfig.h",
+ "KeyValueStoreManagerImpl.cpp",
+ "KeyValueStoreManagerImpl.h",
+ "Logging.cpp",
+ "PlatformManagerImpl.cpp",
+ "PlatformManagerImpl.h",
+ "SystemPlatformConfig.h",
+ "SystemTimeSupport.cpp",
+ "cycfg_gatt_db.c",
+ "cycfg_gatt_db.h",
+ "cyw30739-chip-mbedtls-config.h",
+ "wiced_button_manager.c",
+ "wiced_led_manager.c",
+ ]
+
+ deps = [ "${chip_root}/src/crypto" ]
+
+ public_deps = [ "${chip_root}/src/platform:platform_base" ]
+
+ if (chip_enable_openthread) {
+ sources += [
+ "../OpenThread/OpenThreadUtils.cpp",
+ "ThreadStackManagerImpl.cpp",
+ "ThreadStackManagerImpl.h",
+ ]
+
+ deps += [
+ "${chip_root}/third_party/openthread/platforms:libopenthread-platform",
+ "${openthread_root}/src/core:libopenthread_core_headers",
+ ]
+
+ if (chip_mdns == "platform") {
+ sources += [ "../OpenThread/DnssdImpl.cpp" ]
+
+ deps += [ "${chip_root}/src/lib/dnssd:platform_header" ]
+ }
+ }
+}
diff --git a/src/platform/CYW30739/BlePlatformConfig.h b/src/platform/CYW30739/BlePlatformConfig.h
new file mode 100644
index 0000000..cdf8d9a
--- /dev/null
+++ b/src/platform/CYW30739/BlePlatformConfig.h
@@ -0,0 +1,34 @@
+/*
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * Platform-specific configuration overrides for the CHIP BLE
+ * Layer on CYW20739B2 platform.
+ *
+ */
+
+#pragma once
+
+// ==================== Platform Adaptations ====================
+
+#define BLE_CONNECTION_OBJECT uint16_t
+#define BLE_CONNECTION_UNINITIALIZED ((uint16_t) 0xffff)
+
+// ========== Platform-specific Configuration Overrides =========
+
+/* none so far */
diff --git a/src/platform/CYW30739/CHIPDevicePlatformConfig.h b/src/platform/CYW30739/CHIPDevicePlatformConfig.h
new file mode 100644
index 0000000..f19d20c
--- /dev/null
+++ b/src/platform/CYW30739/CHIPDevicePlatformConfig.h
@@ -0,0 +1,72 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019-2020 Google LLC.
+ * Copyright (c) 2018 Nest Labs, Inc.
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * Defines compile-time configuration overrides for the chip Device Layer.
+ */
+
+#pragma once
+
+// -------------------- General Configuration --------------------
+#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE 0x00001300
+#define CHIP_DEVICE_CONFIG_LOG_PROVISIONING_HASH 0
+
+// -------------------- WiFi Station Configuration --------------------
+
+// -------------------- WiFi AP Configuration --------------------
+#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0
+#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0
+
+// -------------------- BLE/CHIPoBLE Configuration --------------------
+#ifndef CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1
+#endif
+#define CHIP_DEVICE_CONFIG_CHIPOBLE_SINGLE_CONNECTION 1
+#define CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART 1
+#define CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL 60 // 60*0.625ms=37.5ms
+#define CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL 600 // 600*0.625ms=375
+
+// -------------------- Time Sync Configuration --------------------
+
+// -------------------- Service Provisioning Configuration --------------------
+
+// -------------------- Just-In-Time Provisioning Configuration --------------------
+
+// -------------------- Service Discovery Configuration -----------------------
+#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT 1
+
+// -------------------- Thread Configuration --------------------
+#ifndef CHIP_DEVICE_CONFIG_ENABLE_THREAD
+#define CHIP_DEVICE_CONFIG_ENABLE_THREAD 1
+#define CHIP_DEVICE_CONFIG_THREAD_FTD 1
+#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE 0x00001000
+#define CHIP_DEVICE_CONFIG_THREAD_SRP_MAX_SERVICES 5
+#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT 1
+#endif
+
+// -------------------- Trait Manager Configuration --------------------
+
+// -------------------- Network Telemetry Configuration --------------------
+
+// -------------------- Event Logging Configuration --------------------
+#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE 256
+#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE 256
+
+// -------------------- Software Update Manager Configuration --------------------
diff --git a/src/platform/CYW30739/CHIPDevicePlatformEvent.h b/src/platform/CYW30739/CHIPDevicePlatformEvent.h
new file mode 100644
index 0000000..519bfd7
--- /dev/null
+++ b/src/platform/CYW30739/CHIPDevicePlatformEvent.h
@@ -0,0 +1,44 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 Nest Labs, Inc.
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * Defines platform-specific event types and data for the Chip
+ * Device Layer on the platform.
+ */
+
+#pragma once
+
+#include <platform/CHIPDeviceEvent.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+/**
+ * Represents platform-specific event information for the platforms.
+ */
+struct ChipDevicePlatformEvent final
+{
+ union
+ {
+ /* None currently defined */
+ };
+};
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/CYW30739/CHIPPlatformConfig.h b/src/platform/CYW30739/CHIPPlatformConfig.h
new file mode 100644
index 0000000..2b3f197
--- /dev/null
+++ b/src/platform/CYW30739/CHIPPlatformConfig.h
@@ -0,0 +1,31 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 Google LLC.
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * Platform-specific configuration overrides for CHIP.
+ */
+
+#pragma once
+
+#define CHIP_CONFIG_PERSISTED_STORAGE_MAX_VALUE_LENGTH 2048
+#define CHIP_CONFIG_MAX_DEVICE_ADMINS 4
+#define CHIP_CONFIG_UNAUTHENTICATED_CONNECTION_POOL_SIZE 10
+#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1
+#define CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING 1
+#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_COMMISSIONABLE_DISCOVERY 1
diff --git a/src/platform/CYW30739/CYW30739Config.cpp b/src/platform/CYW30739/CYW30739Config.cpp
new file mode 100644
index 0000000..cd845cd
--- /dev/null
+++ b/src/platform/CYW30739/CYW30739Config.cpp
@@ -0,0 +1,130 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 Nest Labs, Inc.
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * Utilities for accessing persisted device configuration.
+ */
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include <platform/CYW30739/CYW30739Config.h>
+#include <platform_nvram.h>
+
+namespace chip {
+namespace DeviceLayer {
+namespace Internal {
+
+CHIP_ERROR CYW30739Config::Init()
+{
+ return CHIP_NO_ERROR;
+}
+
+template <typename T>
+CHIP_ERROR CYW30739Config::ReadConfigValue(Key key, T & val)
+{
+ wiced_result_t result;
+ uint16_t read_count = wiced_hal_read_nvram(PLATFORM_NVRAM_VSID_MATTER_BASE + key, sizeof(val), (uint8_t *) &val, &result);
+ if (result != WICED_SUCCESS || read_count != sizeof(val))
+ {
+ read_count = wiced_hal_read_nvram_static(PLATFORM_NVRAM_SSID_MATTER_BASE + key, sizeof(val), &val, &result);
+ }
+ if (result == WICED_SUCCESS && read_count == sizeof(val))
+ return CHIP_NO_ERROR;
+ else
+ return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
+}
+
+CHIP_ERROR CYW30739Config::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen)
+{
+ return ReadConfigValueBin(key, reinterpret_cast<uint8_t *>(buf), bufSize, outLen);
+}
+
+CHIP_ERROR CYW30739Config::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen)
+{
+ wiced_result_t result;
+ uint16_t read_count = wiced_hal_read_nvram(PLATFORM_NVRAM_VSID_MATTER_BASE + key, bufSize, (uint8_t *) buf, &result);
+ if (result != WICED_SUCCESS)
+ {
+ read_count = wiced_hal_read_nvram_static(PLATFORM_NVRAM_SSID_MATTER_BASE + key, bufSize, buf, &result);
+ }
+ if (result == WICED_SUCCESS)
+ {
+ outLen = read_count;
+ return CHIP_NO_ERROR;
+ }
+ else
+ return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
+}
+
+template CHIP_ERROR CYW30739Config::ReadConfigValue(Key key, bool & val);
+template CHIP_ERROR CYW30739Config::ReadConfigValue(Key key, uint32_t & val);
+template CHIP_ERROR CYW30739Config::ReadConfigValue(Key key, uint64_t & val);
+
+CHIP_ERROR CYW30739Config::WriteConfigValue(Key key, uint32_t val)
+{
+ wiced_result_t result;
+ uint16_t write_count = wiced_hal_write_nvram(PLATFORM_NVRAM_VSID_MATTER_BASE + key, sizeof(val), (uint8_t *) &val, &result);
+ if (result == WICED_SUCCESS && write_count == sizeof(val))
+ return CHIP_NO_ERROR;
+ else
+ return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
+}
+
+CHIP_ERROR CYW30739Config::WriteConfigValueStr(Key key, const char * str)
+{
+ return WriteConfigValueStr(key, str, (str != NULL) ? strlen(str) : 0);
+}
+
+CHIP_ERROR CYW30739Config::WriteConfigValueStr(Key key, const char * str, size_t strLen)
+{
+ return WriteConfigValueBin(key, reinterpret_cast<const uint8_t *>(str), strLen);
+}
+
+CHIP_ERROR CYW30739Config::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen)
+{
+ wiced_result_t result;
+ wiced_hal_write_nvram(PLATFORM_NVRAM_VSID_MATTER_BASE + key, dataLen, (uint8_t *) data, &result);
+ if (result == WICED_SUCCESS)
+ return CHIP_NO_ERROR;
+ else
+ return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
+}
+
+bool CYW30739Config::ConfigValueExists(Key key)
+{
+ wiced_result_t result;
+ wiced_hal_read_nvram(PLATFORM_NVRAM_VSID_MATTER_BASE + key, 0, NULL, &result);
+ if (result != WICED_SUCCESS)
+ wiced_hal_read_nvram_static(PLATFORM_NVRAM_SSID_MATTER_BASE + key, 0, NULL, &result);
+ return result == WICED_SUCCESS;
+}
+
+CHIP_ERROR CYW30739Config::FactoryResetConfig(void)
+{
+ wiced_result_t result;
+ for (Key key = kConfigKey_Base; key <= kConfigKey_Max; key++)
+ wiced_hal_delete_nvram(PLATFORM_NVRAM_VSID_MATTER_BASE + key, &result);
+ return CHIP_NO_ERROR;
+}
+
+void CYW30739Config::RunConfigUnitTest(void) {}
+
+} // namespace Internal
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/CYW30739/CYW30739Config.h b/src/platform/CYW30739/CYW30739Config.h
new file mode 100644
index 0000000..11fd35b
--- /dev/null
+++ b/src/platform/CYW30739/CYW30739Config.h
@@ -0,0 +1,94 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019-2020 Google LLC.
+ * Copyright (c) 2018 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.
+ */
+
+/**
+ * @file
+ * Utilities for accessing persisted device configuration on
+ * CYW30739 platforms.
+ */
+
+#pragma once
+
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+namespace chip {
+namespace DeviceLayer {
+namespace Internal {
+
+/**
+ * Provides functions and definitions for accessing device configuration information.
+ */
+class CYW30739Config
+{
+public:
+ using Key = uint32_t;
+
+ // Key definitions for well-known keys.
+ // Factory config keys
+ static constexpr Key kConfigKey_SerialNum = 0;
+ static constexpr Key kConfigKey_MfrDeviceId = 1;
+ static constexpr Key kConfigKey_MfrDeviceCert = 2;
+ static constexpr Key kConfigKey_MfrDevicePrivateKey = 3;
+ static constexpr Key kConfigKey_ManufacturingDate = 4;
+ static constexpr Key kConfigKey_SetupPinCode = 5;
+ static constexpr Key kConfigKey_MfrDeviceICACerts = 6;
+ static constexpr Key kConfigKey_SetupDiscriminator = 7;
+ // CHIP Config Keys
+ static constexpr Key kConfigKey_FabricId = 8;
+ static constexpr Key kConfigKey_ServiceConfig = 9;
+ static constexpr Key kConfigKey_PairedAccountId = 10;
+ static constexpr Key kConfigKey_ServiceId = 11;
+ static constexpr Key kConfigKey_FabricSecret = 12;
+ static constexpr Key kConfigKey_LastUsedEpochKeyId = 13;
+ static constexpr Key kConfigKey_FailSafeArmed = 14;
+ static constexpr Key kConfigKey_GroupKey = 15;
+ static constexpr Key kConfigKey_HardwareVersion = 16;
+ static constexpr Key kConfigKey_RegulatoryLocation = 17;
+ static constexpr Key kConfigKey_CountryCode = 18;
+ static constexpr Key kConfigKey_ActiveLocale = 19;
+ static constexpr Key kConfigKey_HourFormat = 20;
+ static constexpr Key kConfigKey_CalendarType = 21;
+ static constexpr Key kConfigKey_Breadcrumb = 22;
+
+ // Set key id limits for each group.
+ static constexpr Key kConfigKey_Base = kConfigKey_SerialNum;
+ static constexpr Key kConfigKey_Max = kConfigKey_Breadcrumb;
+
+ static CHIP_ERROR Init(void);
+
+ // Config value accessors.
+ template <typename T>
+ static CHIP_ERROR ReadConfigValue(Key key, T & val);
+
+ static CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen);
+ static CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen);
+ static CHIP_ERROR WriteConfigValue(Key key, uint32_t val);
+ static CHIP_ERROR WriteConfigValueStr(Key key, const char * str);
+ static CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen);
+ static CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen);
+ static CHIP_ERROR ClearConfigValue(Key key);
+ static bool ConfigValueExists(Key key);
+ static CHIP_ERROR FactoryResetConfig(void);
+ static void RunConfigUnitTest(void);
+};
+
+} // namespace Internal
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/CYW30739/ConfigurationManagerImpl.cpp b/src/platform/CYW30739/ConfigurationManagerImpl.cpp
new file mode 100644
index 0000000..891ec57
--- /dev/null
+++ b/src/platform/CYW30739/ConfigurationManagerImpl.cpp
@@ -0,0 +1,169 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 Nest Labs, Inc.
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * Provides the implementation of the Device Layer ConfigurationManager object
+ * for CYW30739 platform.
+ */
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include <platform/internal/GenericConfigurationManagerImpl.cpp>
+
+#include <platform/CYW30739/CYW30739Config.h>
+#include <platform/ConfigurationManager.h>
+
+#include <hal/wiced_hal_wdog.h>
+#include <platform/KeyValueStoreManager.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+using namespace ::chip::DeviceLayer::Internal;
+
+ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance()
+{
+ static ConfigurationManagerImpl sInstance;
+ return sInstance;
+}
+
+CHIP_ERROR ConfigurationManagerImpl::Init()
+{
+ CHIP_ERROR err;
+
+ // Initialize the generic implementation base class.
+ err = Internal::GenericConfigurationManagerImpl<CYW30739Config>::Init();
+ SuccessOrExit(err);
+
+exit:
+ return err;
+}
+
+bool ConfigurationManagerImpl::CanFactoryReset(void)
+{
+ return true;
+}
+
+void ConfigurationManagerImpl::InitiateFactoryReset(void)
+{
+ PlatformMgr().ScheduleWork(DoFactoryReset);
+}
+
+CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value)
+{
+ const size_t keyLength = strnlen(key, CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH + 1);
+ VerifyOrReturnError(keyLength <= CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH, CHIP_ERROR_INVALID_STRING_LENGTH);
+
+ return PersistedStorage::KeyValueStoreMgr().Get(key, &value, sizeof(value));
+}
+
+CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value)
+{
+ const size_t keyLength = strnlen(key, CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH + 1);
+ VerifyOrReturnError(keyLength <= CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH, CHIP_ERROR_INVALID_STRING_LENGTH);
+
+ return PersistedStorage::KeyValueStoreMgr().Put(key, &value, sizeof(value));
+}
+
+CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val)
+{
+ return CYW30739Config::ReadConfigValue(key, val);
+}
+
+CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val)
+{
+ return CYW30739Config::ReadConfigValue(key, val);
+}
+
+CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val)
+{
+ return CYW30739Config::ReadConfigValue(key, val);
+}
+
+CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen)
+{
+ return CYW30739Config::ReadConfigValueStr(key, buf, bufSize, outLen);
+}
+
+CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen)
+{
+ return CYW30739Config::ReadConfigValueBin(key, buf, bufSize, outLen);
+}
+
+CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val)
+{
+ return CYW30739Config::WriteConfigValue(key, val);
+}
+
+CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val)
+{
+ return CYW30739Config::WriteConfigValue(key, val);
+}
+
+CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val)
+{
+ return CYW30739Config::WriteConfigValue(key, val);
+}
+
+CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str)
+{
+ return CYW30739Config::WriteConfigValueStr(key, str);
+}
+
+CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen)
+{
+ return CYW30739Config::WriteConfigValueStr(key, str, strLen);
+}
+
+CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen)
+{
+ return CYW30739Config::WriteConfigValueBin(key, data, dataLen);
+}
+
+void ConfigurationManagerImpl::RunConfigUnitTest(void)
+{
+ CYW30739Config::RunConfigUnitTest();
+}
+
+void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
+{
+ CHIP_ERROR err;
+
+ ChipLogProgress(DeviceLayer, "Performing factory reset");
+
+ err = CYW30739Config::FactoryResetConfig();
+ if (err != CHIP_NO_ERROR)
+ {
+ ChipLogError(DeviceLayer, "FactoryResetConfig() failed: %s", ErrorStr(err));
+ }
+
+#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
+
+ ChipLogProgress(DeviceLayer, "Clearing Thread provision");
+ ThreadStackMgr().ErasePersistentInfo();
+
+#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD
+
+ // Restart the system.
+ ChipLogProgress(DeviceLayer, "System restarting");
+ wiced_hal_wdog_reset_system();
+}
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/CYW30739/ConfigurationManagerImpl.h b/src/platform/CYW30739/ConfigurationManagerImpl.h
new file mode 100644
index 0000000..021fde3
--- /dev/null
+++ b/src/platform/CYW30739/ConfigurationManagerImpl.h
@@ -0,0 +1,74 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 Nest Labs, Inc.
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * Provides an implementation of the ConfigurationManager object
+ * for CYW30739 platform.
+ */
+
+#pragma once
+
+#include <platform/internal/GenericConfigurationManagerImpl.h>
+
+#include "CYW30739Config.h"
+
+namespace chip {
+namespace DeviceLayer {
+
+/**
+ * Concrete implementation of the ConfigurationManager singleton object for the CYW30739 platform.
+ */
+class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl<Internal::CYW30739Config>
+{
+public:
+ // This returns an instance of this class.
+ static ConfigurationManagerImpl & GetDefaultInstance();
+
+private:
+ // ===== Members that implement the ConfigurationManager public interface.
+
+ CHIP_ERROR Init(void) override;
+ bool CanFactoryReset(void) override;
+ void InitiateFactoryReset(void) override;
+ CHIP_ERROR ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) override;
+ CHIP_ERROR WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) override;
+
+ // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>.
+
+ // ===== Members that implement the GenericConfigurationManagerImpl protected interface.
+ CHIP_ERROR ReadConfigValue(Key key, bool & val) override;
+ CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override;
+ CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override;
+ CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override;
+ CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override;
+ CHIP_ERROR WriteConfigValue(Key key, bool val) override;
+ CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override;
+ CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override;
+ CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override;
+ CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override;
+ CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override;
+ void RunConfigUnitTest(void) override;
+
+ // ===== Private members reserved for use by this class only.
+
+ static void DoFactoryReset(intptr_t arg);
+};
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/CYW30739/ConnectivityManagerImpl.cpp b/src/platform/CYW30739/ConnectivityManagerImpl.cpp
new file mode 100644
index 0000000..7d8852c
--- /dev/null
+++ b/src/platform/CYW30739/ConnectivityManagerImpl.cpp
@@ -0,0 +1,57 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 Nest Labs, Inc.
+ *
+ * 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.
+ */
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include <platform/ConnectivityManager.h>
+
+#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
+#include <platform/internal/GenericConnectivityManagerImpl_Thread.cpp>
+#endif
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+#include <platform/internal/GenericConnectivityManagerImpl_BLE.cpp>
+#endif
+
+namespace chip {
+namespace DeviceLayer {
+
+ConnectivityManagerImpl ConnectivityManagerImpl::sInstance;
+
+CHIP_ERROR ConnectivityManagerImpl::_Init()
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+
+ // Initialize the generic base classes that require it.
+#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
+ GenericConnectivityManagerImpl_Thread<ConnectivityManagerImpl>::_Init();
+#endif
+ SuccessOrExit(err);
+
+exit:
+ return err;
+}
+
+void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
+{
+#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
+ GenericConnectivityManagerImpl_Thread<ConnectivityManagerImpl>::_OnPlatformEvent(event);
+#endif
+}
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/CYW30739/ConnectivityManagerImpl.h b/src/platform/CYW30739/ConnectivityManagerImpl.h
new file mode 100644
index 0000000..3fc89d7
--- /dev/null
+++ b/src/platform/CYW30739/ConnectivityManagerImpl.h
@@ -0,0 +1,97 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 Nest Labs, Inc.
+ *
+ * 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 <platform/ConnectivityManager.h>
+#include <platform/internal/GenericConnectivityManagerImpl.h>
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+#include <platform/internal/GenericConnectivityManagerImpl_BLE.h>
+#else
+#include <platform/internal/GenericConnectivityManagerImpl_NoBLE.h>
+#endif
+#include <platform/internal/GenericConnectivityManagerImpl_NoWiFi.h>
+#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
+#include <platform/internal/GenericConnectivityManagerImpl_Thread.h>
+#else
+#include <platform/internal/GenericConnectivityManagerImpl_NoThread.h>
+#endif
+
+namespace chip {
+namespace DeviceLayer {
+
+/**
+ * Concrete implementation of the ConnectivityManager singleton object for the platforms.
+ */
+class ConnectivityManagerImpl final : public ConnectivityManager,
+ public Internal::GenericConnectivityManagerImpl<ConnectivityManagerImpl>,
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+ public Internal::GenericConnectivityManagerImpl_BLE<ConnectivityManagerImpl>,
+#else
+ public Internal::GenericConnectivityManagerImpl_NoBLE<ConnectivityManagerImpl>,
+#endif
+ public Internal::GenericConnectivityManagerImpl_NoWiFi<ConnectivityManagerImpl>,
+#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
+ public Internal::GenericConnectivityManagerImpl_Thread<ConnectivityManagerImpl>
+#else
+ public Internal::GenericConnectivityManagerImpl_NoThread<ConnectivityManagerImpl>
+#endif
+{
+ // Allow the ConnectivityManager interface class to delegate method calls to
+ // the implementation methods provided by this class.
+ friend class ConnectivityManager;
+
+private:
+ // ===== Members that implement the ConnectivityManager abstract interface.
+
+ bool _HaveServiceConnectivity(void);
+ CHIP_ERROR _Init(void);
+ void _OnPlatformEvent(const ChipDeviceEvent * event);
+
+ // ===== Members for internal use by the following friends.
+
+ friend ConnectivityManager & ConnectivityMgr(void);
+ friend ConnectivityManagerImpl & ConnectivityMgrImpl(void);
+
+ static ConnectivityManagerImpl sInstance;
+};
+
+/**
+ * Returns the public interface of the ConnectivityManager singleton object.
+ *
+ * Chip applications should use this to access features of the ConnectivityManager object
+ * that are common to all platforms.
+ */
+inline ConnectivityManager & ConnectivityMgr(void)
+{
+ return ConnectivityManagerImpl::sInstance;
+}
+
+/**
+ * Returns the platform-specific implementation of the ConnectivityManager singleton object.
+ *
+ * Chip applications can use this to gain access to features of the ConnectivityManager
+ * that are specific to the ESP32 platform.
+ */
+inline ConnectivityManagerImpl & ConnectivityMgrImpl(void)
+{
+ return ConnectivityManagerImpl::sInstance;
+}
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/CYW30739/DeviceNetworkProvisioningDelegateImpl.cpp b/src/platform/CYW30739/DeviceNetworkProvisioningDelegateImpl.cpp
new file mode 100644
index 0000000..57d9a29
--- /dev/null
+++ b/src/platform/CYW30739/DeviceNetworkProvisioningDelegateImpl.cpp
@@ -0,0 +1,39 @@
+/*
+ *
+ * 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.
+ */
+
+#include "DeviceNetworkProvisioningDelegateImpl.h"
+
+namespace chip {
+namespace DeviceLayer {
+
+CHIP_ERROR DeviceNetworkProvisioningDelegateImpl::_ProvisionThreadNetwork(ByteSpan threadData)
+{
+#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
+ CHIP_ERROR error = CHIP_NO_ERROR;
+
+ SuccessOrExit(error = ThreadStackMgr().SetThreadEnabled(false));
+ SuccessOrExit(error = ThreadStackMgr().SetThreadProvision(threadData));
+ SuccessOrExit(error = ThreadStackMgr().SetThreadEnabled(true));
+exit:
+ return error;
+#else
+ return CHIP_ERROR_NOT_IMPLEMENTED;
+#endif /* CHIP_DEVICE_CONFIG_ENABLE_THREAD */
+}
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/CYW30739/DeviceNetworkProvisioningDelegateImpl.h b/src/platform/CYW30739/DeviceNetworkProvisioningDelegateImpl.h
new file mode 100644
index 0000000..e799358
--- /dev/null
+++ b/src/platform/CYW30739/DeviceNetworkProvisioningDelegateImpl.h
@@ -0,0 +1,43 @@
+/*
+ *
+ * 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.
+ */
+
+#pragma once
+
+#include <platform/internal/GenericDeviceNetworkProvisioningDelegateImpl.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+namespace Internal {
+
+template <class ImplClass>
+class GenericDeviceNetworkProvisioningDelegateImpl;
+
+} // namespace Internal
+
+class DeviceNetworkProvisioningDelegateImpl final
+ : public Internal::GenericDeviceNetworkProvisioningDelegateImpl<DeviceNetworkProvisioningDelegateImpl>
+{
+ friend class GenericDeviceNetworkProvisioningDelegateImpl<DeviceNetworkProvisioningDelegateImpl>;
+
+private:
+ CHIP_ERROR _ProvisionWiFiNetwork(const char * ssid, const char * passwd) { return CHIP_ERROR_NOT_IMPLEMENTED; }
+ CHIP_ERROR _ProvisionThreadNetwork(ByteSpan threadData);
+};
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/CYW30739/DiagnosticDataProviderImpl.cpp b/src/platform/CYW30739/DiagnosticDataProviderImpl.cpp
new file mode 100644
index 0000000..7360320
--- /dev/null
+++ b/src/platform/CYW30739/DiagnosticDataProviderImpl.cpp
@@ -0,0 +1,69 @@
+/*
+ *
+ * Copyright (c) 2021 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.
+ */
+
+/**
+ * @file
+ * Provides an implementation of the DiagnosticDataProvider object
+ * for CYW30739 platform.
+ */
+
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include <platform/CYW30739/DiagnosticDataProviderImpl.h>
+#include <platform/DiagnosticDataProvider.h>
+
+#include <hal/wiced_memory.h>
+#include <malloc.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+DiagnosticDataProviderImpl & DiagnosticDataProviderImpl::GetDefaultInstance()
+{
+ static DiagnosticDataProviderImpl sInstance;
+ return sInstance;
+}
+
+CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapFree(uint64_t & currentHeapFree)
+{
+ const struct mallinfo mallocInfo = mallinfo();
+
+ currentHeapFree = wiced_memory_get_free_bytes() + mallocInfo.fordblks;
+
+ return CHIP_NO_ERROR;
+}
+
+CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapUsed(uint64_t & currentHeapUsed)
+{
+ const struct mallinfo mallocInfo = mallinfo();
+
+ currentHeapUsed = mallocInfo.uordblks;
+
+ return CHIP_NO_ERROR;
+}
+
+CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark)
+{
+ const struct mallinfo mallocInfo = mallinfo();
+
+ currentHeapHighWatermark = mallocInfo.arena;
+
+ return CHIP_NO_ERROR;
+}
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/CYW30739/DiagnosticDataProviderImpl.h b/src/platform/CYW30739/DiagnosticDataProviderImpl.h
new file mode 100644
index 0000000..6505cf5
--- /dev/null
+++ b/src/platform/CYW30739/DiagnosticDataProviderImpl.h
@@ -0,0 +1,48 @@
+/*
+ *
+ * Copyright (c) 2021 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.
+ */
+
+/**
+ * @file
+ * Provides an implementation of the DiagnosticDataProvider object.
+ */
+
+#pragma once
+
+#include <memory>
+
+#include <platform/DiagnosticDataProvider.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+/**
+ * Concrete implementation of the PlatformManager singleton object for Linux platforms.
+ */
+class DiagnosticDataProviderImpl : public DiagnosticDataProvider
+{
+public:
+ static DiagnosticDataProviderImpl & GetDefaultInstance();
+
+ // ===== Methods that implement the PlatformManager abstract interface.
+
+ CHIP_ERROR GetCurrentHeapFree(uint64_t & currentHeapFree) override;
+ CHIP_ERROR GetCurrentHeapUsed(uint64_t & currentHeapUsed) override;
+ CHIP_ERROR GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark) override;
+};
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/CYW30739/InetPlatformConfig.h b/src/platform/CYW30739/InetPlatformConfig.h
new file mode 100644
index 0000000..f73534e
--- /dev/null
+++ b/src/platform/CYW30739/InetPlatformConfig.h
@@ -0,0 +1,27 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 Google LLC.
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * Platform-specific configuration overrides for the CHIP Inet Layer.
+ */
+
+#pragma once
+
+#define INET_CONFIG_NUM_TCP_ENDPOINTS 4
+#define INET_CONFIG_NUM_UDP_ENDPOINTS 4
diff --git a/src/platform/CYW30739/KeyValueStoreManagerImpl.cpp b/src/platform/CYW30739/KeyValueStoreManagerImpl.cpp
new file mode 100644
index 0000000..439865f
--- /dev/null
+++ b/src/platform/CYW30739/KeyValueStoreManagerImpl.cpp
@@ -0,0 +1,205 @@
+/*
+ *
+ * Copyright (c) 2021 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.
+ */
+
+/**
+ * @file
+ * Platform-specific key value storage implementation
+ */
+
+#include <platform/KeyValueStoreManager.h>
+
+#include <lib/support/CodeUtils.h>
+#include <platform_nvram.h>
+#include <string.h>
+
+namespace chip {
+namespace DeviceLayer {
+namespace PersistedStorage {
+
+KeyValueStoreManagerImpl KeyValueStoreManagerImpl::sInstance;
+
+CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size,
+ size_t offset_bytes)
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+ KeyEntryStorage * keyEntryStorage = NULL;
+ uint16_t nvramID = 0;
+ wiced_result_t result;
+ uint16_t byte_count;
+
+ VerifyOrReturnError(offset_bytes == 0, CHIP_ERROR_NOT_IMPLEMENTED);
+
+ const size_t keyLength = strnlen(key, CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH);
+ VerifyOrExit(keyLength != 0 && keyLength <= CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH &&
+ value_size <= CHIP_CONFIG_PERSISTED_STORAGE_MAX_VALUE_LENGTH,
+ err = CHIP_ERROR_INVALID_ARGUMENT);
+
+ keyEntryStorage = new KeyEntryStorage();
+ VerifyOrExit(keyEntryStorage != NULL, ChipLogError(DeviceLayer, "%s new KeyEntryStorage", __func__);
+ err = CHIP_ERROR_NO_MEMORY;);
+
+ SuccessOrExit(err = keyEntryStorage->FindKeyNvramID(nvramID, key));
+
+ byte_count = wiced_hal_read_nvram(nvramID, value_size, (uint8_t *) value, &result);
+ VerifyOrExit(result == WICED_SUCCESS, ChipLogError(DeviceLayer, "%s wiced_hal_read_nvram %u", __func__, result);
+ err = CHIP_ERROR_INTEGRITY_CHECK_FAILED;);
+
+ if (read_bytes_size != NULL)
+ {
+ *read_bytes_size = byte_count;
+ }
+
+exit:
+ delete keyEntryStorage;
+
+ return err;
+}
+
+CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size)
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+ KeyEntryStorage * keyEntryStorage = NULL;
+ uint16_t nvramID = 0;
+ wiced_result_t result;
+ uint16_t byte_count;
+
+ const size_t keyLength = strnlen(key, CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH + 1);
+ VerifyOrExit(keyLength != 0 && keyLength <= CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH &&
+ value_size <= CHIP_CONFIG_PERSISTED_STORAGE_MAX_VALUE_LENGTH,
+ err = CHIP_ERROR_INVALID_ARGUMENT);
+
+ keyEntryStorage = new KeyEntryStorage();
+ VerifyOrExit(keyEntryStorage != NULL, ChipLogError(DeviceLayer, "%s new KeyEntryStorage", __func__);
+ err = CHIP_ERROR_NO_MEMORY;);
+
+ err = keyEntryStorage->AllocateEntry(nvramID, key, keyLength);
+ VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(DeviceLayer, "%s AllocateEntry %s", __func__, ErrorStr(err)));
+
+ byte_count = wiced_hal_write_nvram(nvramID, value_size, (uint8_t *) value, &result);
+ VerifyOrExit(byte_count == value_size && result == WICED_SUCCESS,
+ ChipLogError(DeviceLayer, "%s wiced_hal_write_nvram %u", __func__, result);
+ keyEntryStorage->ReleaseEntry(key); err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;);
+
+exit:
+ delete keyEntryStorage;
+
+ return err;
+}
+
+CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key)
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+ KeyEntryStorage * keyEntryStorage = NULL;
+ uint16_t nvramID = 0;
+
+ const size_t keyLength = strnlen(key, CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH);
+ VerifyOrExit(keyLength != 0 && keyLength <= CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH, err = CHIP_ERROR_INVALID_ARGUMENT);
+
+ keyEntryStorage = new KeyEntryStorage();
+ VerifyOrExit(keyEntryStorage != NULL, ChipLogError(DeviceLayer, "%s new KeyEntryStorage", __func__);
+ err = CHIP_ERROR_NO_MEMORY;);
+
+ SuccessOrExit(err = keyEntryStorage->FindKeyNvramID(nvramID, key));
+
+ keyEntryStorage->ReleaseEntry(key);
+
+exit:
+ delete keyEntryStorage;
+
+ return err;
+}
+
+bool KeyValueStoreManagerImpl::KeyEntry::IsMatchKey(const char * key)
+{
+ return mIsValid && strncmp(mKey, key, sizeof(mKey)) == 0;
+}
+
+KeyValueStoreManagerImpl::KeyEntryStorage::KeyEntryStorage(void) : mIsDirty(false)
+{
+ wiced_result_t result;
+ const uint16_t byte_count =
+ wiced_hal_read_nvram(PLATFORM_NVRAM_ID_ENTRY_INFO_STRING, sizeof(mKeyEntries), (uint8_t *) mKeyEntries, &result);
+ if (byte_count != sizeof(mKeyEntries) || result != WICED_SUCCESS)
+ {
+ memset(mKeyEntries, 0, sizeof(mKeyEntries));
+ }
+}
+
+KeyValueStoreManagerImpl::KeyEntryStorage::~KeyEntryStorage(void)
+{
+ if (mIsDirty)
+ {
+ wiced_result_t result;
+ const uint16_t byte_count =
+ wiced_hal_write_nvram(PLATFORM_NVRAM_ID_ENTRY_INFO_STRING, sizeof(mKeyEntries), (uint8_t *) mKeyEntries, &result);
+ if (byte_count != sizeof(mKeyEntries) || result != WICED_SUCCESS)
+ {
+ ChipLogError(DeviceLayer, "%s wiced_hal_write_nvram %u", __func__, result);
+ }
+ }
+}
+
+CHIP_ERROR KeyValueStoreManagerImpl::KeyEntryStorage::AllocateEntry(uint16_t & nvramID, const char * key, size_t keyLength)
+{
+ ReturnErrorCodeIf(keyLength == 0 || keyLength > sizeof(mKeyEntries[0].mKey), CHIP_ERROR_INVALID_ARGUMENT);
+ ReturnErrorCodeIf(FindKeyNvramID(nvramID, key) == CHIP_NO_ERROR, CHIP_NO_ERROR);
+
+ for (uint8_t i = 0; i < ArraySize(mKeyEntries); i++)
+ {
+ if (!mKeyEntries[i].mIsValid)
+ {
+ mKeyEntries[i].mIsValid = true;
+ memcpy(mKeyEntries[i].mKey, key, keyLength);
+ mIsDirty = true;
+ nvramID = PLATFORM_NVRAM_ID_ENTRY_DATA_STRING + i;
+ return CHIP_NO_ERROR;
+ }
+ }
+
+ return CHIP_ERROR_NO_MEMORY;
+}
+
+void KeyValueStoreManagerImpl::KeyEntryStorage::ReleaseEntry(const char * key)
+{
+ for (uint8_t i = 0; i < ArraySize(mKeyEntries); i++)
+ {
+ if (mKeyEntries[i].IsMatchKey(key))
+ {
+ mKeyEntries[i].mIsValid = false;
+ mIsDirty = true;
+ break;
+ }
+ }
+}
+
+CHIP_ERROR KeyValueStoreManagerImpl::KeyEntryStorage::FindKeyNvramID(uint16_t & nvramID, const char * key)
+{
+ for (uint8_t i = 0; i < ArraySize(mKeyEntries); i++)
+ {
+ if (mKeyEntries[i].IsMatchKey(key))
+ {
+ nvramID = PLATFORM_NVRAM_ID_ENTRY_DATA_STRING + i;
+ return CHIP_NO_ERROR;
+ }
+ }
+ return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND;
+}
+
+} // namespace PersistedStorage
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/CYW30739/KeyValueStoreManagerImpl.h b/src/platform/CYW30739/KeyValueStoreManagerImpl.h
new file mode 100644
index 0000000..6cc0fbe
--- /dev/null
+++ b/src/platform/CYW30739/KeyValueStoreManagerImpl.h
@@ -0,0 +1,107 @@
+/*
+ *
+ * Copyright (c) 2021 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.
+ */
+
+/**
+ * @file
+ * Platform-specific key value storage implementation.
+ */
+
+#pragma once
+
+#include <inet/InetConfig.h>
+
+namespace chip {
+namespace DeviceLayer {
+namespace PersistedStorage {
+
+class KeyValueStoreManagerImpl final : public KeyValueStoreManager
+{
+ // Allow the KeyValueStoreManager interface class to delegate method calls to
+ // the implementation methods provided by this class.
+ friend class KeyValueStoreManager;
+
+public:
+ // NOTE: Currently this platform does not support partial and offset reads
+ // these will return CHIP_ERROR_NOT_IMPLEMENTED.
+ CHIP_ERROR _Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size = nullptr, size_t offset = 0);
+
+ CHIP_ERROR _Delete(const char * key);
+
+ CHIP_ERROR _Put(const char * key, const void * value, size_t value_size);
+
+private:
+ static constexpr uint8_t mMaxEntryCount = 1 + /* For the global message counter */
+ 1 + /* For the admin key count */
+ CHIP_CONFIG_MAX_DEVICE_ADMINS + 1 + /* For the session key count */
+ CHIP_CONFIG_MAX_SESSION_KEYS;
+
+ struct KeyEntry
+ {
+ bool mIsValid;
+ char mKey[CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH];
+
+ bool IsMatchKey(const char * key);
+ };
+
+ class KeyEntryStorage
+ {
+ public:
+ KeyEntryStorage(void);
+ ~KeyEntryStorage(void);
+
+ CHIP_ERROR AllocateEntry(uint16_t & nvramID, const char * key, size_t keyLength);
+ void ReleaseEntry(const char * key);
+ CHIP_ERROR FindKeyNvramID(uint16_t & nvramID, const char * key);
+
+ private:
+ KeyEntry mKeyEntries[mMaxEntryCount];
+ bool mIsDirty;
+ };
+
+ // ===== Members for internal use by the following friends.
+ friend KeyValueStoreManager & KeyValueStoreMgr();
+ friend KeyValueStoreManagerImpl & KeyValueStoreMgrImpl();
+
+ static KeyValueStoreManagerImpl sInstance;
+};
+
+/**
+ * Returns the public interface of the KeyValueStoreManager singleton object.
+ *
+ * Chip applications should use this to access features of the KeyValueStoreManager object
+ * that are common to all platforms.
+ */
+inline KeyValueStoreManager & KeyValueStoreMgr(void)
+{
+ return KeyValueStoreManagerImpl::sInstance;
+}
+
+/**
+ * Returns the platform-specific implementation of the KeyValueStoreManager singleton object.
+ *
+ * Chip applications can use this to gain access to features of the KeyValueStoreManager
+ * that are specific to the ESP32 platform.
+ */
+inline KeyValueStoreManagerImpl & KeyValueStoreMgrImpl(void)
+{
+ return KeyValueStoreManagerImpl::sInstance;
+}
+
+} // namespace PersistedStorage
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/CYW30739/Logging.cpp b/src/platform/CYW30739/Logging.cpp
new file mode 100644
index 0000000..9826665
--- /dev/null
+++ b/src/platform/CYW30739/Logging.cpp
@@ -0,0 +1,37 @@
+/* See Project CHIP LICENSE file for licensing information. */
+
+#include <assert.h>
+#include <lib/support/logging/Constants.h>
+#include <platform/logging/LogV.h>
+#include <stdio.h>
+#include <wiced_rtos.h>
+
+namespace chip {
+namespace Logging {
+namespace Platform {
+
+void LogV(const char * module, uint8_t category, const char * msg, va_list v)
+{
+ switch (category)
+ {
+ case chip::Logging::LogCategory::kLogCategory_Error:
+ printf("Error");
+ break;
+ case chip::Logging::LogCategory::kLogCategory_Progress:
+ printf("InfoP");
+ break;
+ case chip::Logging::LogCategory::kLogCategory_Detail:
+ printf("InfoD");
+ break;
+ }
+
+ static char buffer[256];
+ vsnprintf(buffer, sizeof(buffer), msg, v);
+ printf(" CHIP:%s: %s\n", module, buffer);
+
+ assert(!wiced_rtos_check_for_stack_overflow());
+}
+
+} // namespace Platform
+} // namespace Logging
+} // namespace chip
diff --git a/src/platform/CYW30739/PlatformManagerImpl.cpp b/src/platform/CYW30739/PlatformManagerImpl.cpp
new file mode 100644
index 0000000..3b097fa
--- /dev/null
+++ b/src/platform/CYW30739/PlatformManagerImpl.cpp
@@ -0,0 +1,251 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 Nest Labs, Inc.
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * Provides an implementation of the PlatformManager object.
+ */
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include <platform/CYW30739/DiagnosticDataProviderImpl.h>
+#include <platform/PlatformManager.h>
+#include <platform/internal/GenericPlatformManagerImpl.cpp>
+
+#include <crypto/CHIPCryptoPAL.h>
+#include <hal/wiced_memory.h>
+#include <wiced_platform.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+PlatformManagerImpl PlatformManagerImpl::sInstance;
+
+CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+ wiced_result_t result;
+
+ // Initialize the configuration system.
+ err = Internal::CYW30739Config::Init();
+ SuccessOrExit(err);
+
+ SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());
+ SetDiagnosticDataProvider(&DiagnosticDataProviderImpl::GetDefaultInstance());
+
+ /* Initialize LwIP. */
+ lwip_init();
+
+ /* Create the thread object. */
+ mThread = wiced_rtos_create_thread();
+ VerifyOrExit(mThread != nullptr, err = CHIP_ERROR_NO_MEMORY);
+
+ /* Initialize the event flags. */
+ mEventFlags = wiced_rtos_create_event_flags();
+ VerifyOrExit(mEventFlags != nullptr, err = CHIP_ERROR_NO_MEMORY);
+
+ result = wiced_rtos_init_event_flags(mEventFlags);
+ VerifyOrExit(result == WICED_SUCCESS, err = CHIP_ERROR_NO_MEMORY);
+ /* Initialize the event queue. */
+ mEventQueue = wiced_rtos_create_queue();
+ VerifyOrExit(mEventQueue != nullptr, err = CHIP_ERROR_NO_MEMORY);
+
+ result = wiced_rtos_init_queue(mEventQueue, "EventQueue", sizeof(ChipDeviceEvent), CHIP_DEVICE_CONFIG_MAX_EVENT_QUEUE_SIZE);
+ VerifyOrExit(result == WICED_SUCCESS, err = CHIP_ERROR_NO_MEMORY);
+
+ /* Initialize the timer. */
+ result = wiced_init_timer(&mTimer, TimerCallback, 0, WICED_MILLI_SECONDS_TIMER);
+ VerifyOrExit(result == WICED_SUCCESS, err = CHIP_ERROR_INTERNAL);
+
+ /* Initialize the mutex. */
+ mMutex = wiced_rtos_create_mutex();
+ VerifyOrExit(mMutex != nullptr, err = CHIP_ERROR_NO_MEMORY);
+
+ result = wiced_rtos_init_mutex(mMutex);
+ VerifyOrExit(result == WICED_SUCCESS, err = CHIP_ERROR_INTERNAL);
+
+ ReturnErrorOnFailure(chip::Crypto::add_entropy_source(GetEntropy, NULL, 16));
+
+ ReturnErrorOnFailure(GenericPlatformManagerImpl<ImplClass>::_InitChipStack());
+
+exit:
+ return err;
+}
+
+void PlatformManagerImpl::_RunEventLoop(void)
+{
+ ChipLogDetail(DeviceLayer, "Free RAM sizes: %lu\n", wiced_memory_get_free_bytes());
+
+ while (true)
+ {
+ uint32_t flags_set = 0;
+ const wiced_result_t result = wiced_rtos_wait_for_event_flags(mEventFlags, 0xffffffff, &flags_set, WICED_TRUE,
+ WAIT_FOR_ANY_EVENT, WICED_WAIT_FOREVER);
+ if (result != WICED_SUCCESS)
+ {
+ ChipLogError(DeviceLayer, "wiced_rtos_wait_for_event_flags 0x%08x", result);
+ continue;
+ }
+
+ if (flags_set & kTimerEventFlag)
+ {
+ HandleTimerEvent();
+ }
+
+ if (flags_set & kPostEventFlag)
+ {
+ HandlePostEvent();
+ }
+ }
+}
+
+CHIP_ERROR PlatformManagerImpl::_StartEventLoopTask(void)
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+ wiced_result_t result;
+
+ result = wiced_rtos_init_thread(mThread, CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY, CHIP_DEVICE_CONFIG_CHIP_TASK_NAME,
+ EventLoopTaskMain, CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE, this);
+ VerifyOrExit(result == WICED_SUCCESS, err = CHIP_ERROR_NO_MEMORY);
+
+exit:
+ return err;
+}
+
+void PlatformManagerImpl::_LockChipStack(void)
+{
+ const wiced_result_t result = wiced_rtos_lock_mutex(mMutex);
+ VerifyOrReturn(result == WICED_SUCCESS, ChipLogError(DeviceLayer, "%s %x", __func__, result));
+}
+
+void PlatformManagerImpl::_UnlockChipStack(void)
+{
+ const wiced_result_t result = wiced_rtos_unlock_mutex(mMutex);
+ VerifyOrReturn(result == WICED_SUCCESS || result == WICED_NOT_OWNED, ChipLogError(DeviceLayer, "%s %x", __func__, result));
+}
+
+CHIP_ERROR PlatformManagerImpl::_PostEvent(const ChipDeviceEvent * event)
+{
+ const wiced_result_t result = wiced_rtos_push_to_queue(mEventQueue, const_cast<ChipDeviceEvent *>(event), WICED_NO_WAIT);
+ if (WICED_SUCCESS != result)
+ {
+ ChipLogError(DeviceLayer, "wiced_rtos_push_to_queue %u", result);
+ return CHIP_ERROR_INTERNAL;
+ }
+
+ SetEventFlags(kPostEventFlag);
+
+ return CHIP_NO_ERROR;
+}
+
+CHIP_ERROR PlatformManagerImpl::_StartChipTimer(System::Clock::Timeout durationMS)
+{
+ if (durationMS.count() == 0)
+ {
+ TimerCallback(0);
+ }
+ else
+ {
+ const wiced_result_t result = wiced_start_timer(&mTimer, durationMS.count());
+ if (WICED_SUCCESS != result)
+ {
+ ChipLogError(DeviceLayer, "wiced_start_timer 0x%02x", result);
+ return CHIP_ERROR_INTERNAL;
+ }
+ }
+ return CHIP_NO_ERROR;
+}
+
+CHIP_ERROR PlatformManagerImpl::_Shutdown()
+{
+ return CHIP_NO_ERROR;
+}
+
+void PlatformManagerImpl::SetEventFlags(uint32_t flags)
+{
+ assert(!wiced_rtos_check_for_stack_overflow());
+
+ if (wiced_rtos_set_event_flags(mEventFlags, flags) != WICED_SUCCESS)
+ {
+ ChipLogError(DeviceLayer, "%s wiced_rtos_set_event_flags %08lx", __func__, flags);
+ }
+}
+
+void PlatformManagerImpl::HandleTimerEvent(void)
+{
+ const CHIP_ERROR err = static_cast<System::LayerImplLwIP &>(DeviceLayer::SystemLayer()).HandlePlatformTimer();
+ if (err != CHIP_NO_ERROR)
+ {
+ ChipLogError(DeviceLayer, "HandlePlatformTimer %ld", err.AsInteger());
+ }
+}
+
+void PlatformManagerImpl::HandlePostEvent(void)
+{
+ wiced_result_t result;
+ ChipDeviceEvent event;
+
+ /* Check the event queue. */
+ if (wiced_rtos_is_queue_empty(mEventQueue))
+ {
+ return;
+ }
+
+ /* Pop one event from the event queue. */
+ result = wiced_rtos_pop_from_queue(mEventQueue, &event, WICED_WAIT_FOREVER);
+
+ if (WICED_SUCCESS != result)
+ {
+ ChipLogError(DeviceLayer, "wiced_rtos_pop_from_queue %u", result);
+ return;
+ }
+
+ /* Process this event. */
+ DispatchEvent(&event);
+
+ /* Set another application thread event if the event queue is not empty. */
+ if (!wiced_rtos_is_queue_empty(mEventQueue))
+ {
+ SetEventFlags(kPostEventFlag);
+ }
+}
+
+void PlatformManagerImpl::EventLoopTaskMain(uint32_t arg)
+{
+ ChipLogDetail(DeviceLayer, "CHIP task running");
+ reinterpret_cast<PlatformManagerImpl *>(arg)->RunEventLoop();
+}
+
+void PlatformManagerImpl::TimerCallback(WICED_TIMER_PARAM_TYPE params)
+{
+ PlatformMgrImpl().SetEventFlags(kTimerEventFlag);
+}
+
+int PlatformManagerImpl::GetEntropy(void * data, unsigned char * output, size_t len, size_t * olen)
+{
+ const wiced_result_t result = wiced_platform_entropy_get(output, static_cast<uint16_t>(len));
+ if (result != WICED_SUCCESS)
+ {
+ return -1;
+ }
+ *olen = len;
+ return 0;
+}
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/CYW30739/PlatformManagerImpl.h b/src/platform/CYW30739/PlatformManagerImpl.h
new file mode 100644
index 0000000..9b0523d
--- /dev/null
+++ b/src/platform/CYW30739/PlatformManagerImpl.h
@@ -0,0 +1,103 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 Nest Labs, Inc.
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * Provides an implementation of the PlatformManager object.
+ * for the platform.
+ */
+
+#pragma once
+
+#include <hal/wiced_timer.h>
+#include <platform/internal/GenericPlatformManagerImpl.h>
+#include <wiced_rtos.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+/**
+ * Concrete implementation of the PlatformManager singleton object for the platform.
+ */
+class PlatformManagerImpl final : public PlatformManager, public Internal::GenericPlatformManagerImpl<PlatformManagerImpl>
+{
+ // Allow the PlatformManager interface class to delegate method calls to
+ // the implementation methods provided by this class.
+ friend PlatformManager;
+
+private:
+ // ===== Methods that implement the PlatformManager abstract interface.
+
+ CHIP_ERROR _InitChipStack(void);
+ void _RunEventLoop(void);
+ CHIP_ERROR _StartEventLoopTask(void);
+ CHIP_ERROR _StopEventLoopTask(void);
+ void _LockChipStack(void);
+ bool _TryLockChipStack(void);
+ void _UnlockChipStack(void);
+ CHIP_ERROR _PostEvent(const ChipDeviceEvent * event);
+ CHIP_ERROR _StartChipTimer(System::Clock::Timeout durationMS);
+ CHIP_ERROR _Shutdown(void);
+
+ void SetEventFlags(uint32_t flags);
+ void HandleTimerEvent(void);
+ void HandlePostEvent(void);
+
+ // ===== Members for internal use by the following friends.
+
+ friend PlatformManager & PlatformMgr(void);
+ friend PlatformManagerImpl & PlatformMgrImpl(void);
+
+ wiced_thread_t * mThread;
+ wiced_event_flags_t * mEventFlags;
+ wiced_queue_t * mEventQueue;
+ wiced_timer_t mTimer;
+ wiced_mutex_t * mMutex;
+
+ static void EventLoopTaskMain(uint32_t arg);
+ static void TimerCallback(WICED_TIMER_PARAM_TYPE params);
+ static int GetEntropy(void * data, unsigned char * output, size_t len, size_t * olen);
+ static PlatformManagerImpl sInstance;
+ static constexpr uint32_t kTimerEventFlag = 1 << 0;
+ static constexpr uint32_t kPostEventFlag = 1 << 1;
+};
+
+/**
+ * Returns the public interface of the PlatformManager singleton object.
+ *
+ * Chip applications should use this to access features of the PlatformManager object
+ * that are common to all platforms.
+ */
+inline PlatformManager & PlatformMgr(void)
+{
+ return PlatformManagerImpl::sInstance;
+}
+
+/**
+ * Returns the platform-specific implementation of the PlatformManager singleton object.
+ *
+ * Chip applications can use this to gain access to features of the PlatformManager
+ * that are specific to the ESP32 platform.
+ */
+inline PlatformManagerImpl & PlatformMgrImpl(void)
+{
+ return PlatformManagerImpl::sInstance;
+}
+
+} // namespace DeviceLayer
+} // namespace chip
diff --git a/src/platform/CYW30739/SystemPlatformConfig.h b/src/platform/CYW30739/SystemPlatformConfig.h
new file mode 100644
index 0000000..0da60ba
--- /dev/null
+++ b/src/platform/CYW30739/SystemPlatformConfig.h
@@ -0,0 +1,31 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 Google LLC.
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * Platform-specific configuration overrides for the CHIP system layer.
+ *
+ */
+
+#pragma once
+
+// ==================== Platform Adaptations ====================
+#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1
+#define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent *
+
+// ========== Platform-specific Configuration Overrides =========
diff --git a/src/platform/CYW30739/SystemTimeSupport.cpp b/src/platform/CYW30739/SystemTimeSupport.cpp
new file mode 100644
index 0000000..5eaf8a3
--- /dev/null
+++ b/src/platform/CYW30739/SystemTimeSupport.cpp
@@ -0,0 +1,66 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2018 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.
+ */
+
+/**
+ * @file
+ * Provides implementations of the CHIP System Layer platform
+ * time/clock functions.
+ */
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include <internal/clock_timer.h>
+#include <lib/support/TimeUtils.h>
+
+namespace chip {
+namespace System {
+namespace Clock {
+
+namespace Internal {
+ClockImpl gClockImpl;
+} // namespace Internal
+
+Clock::Microseconds64 ClockImpl::GetMonotonicMicroseconds64(void)
+{
+ return Clock::Microseconds64(clock_SystemTimeMicroseconds64());
+}
+
+Clock::Milliseconds64 ClockImpl::GetMonotonicMilliseconds64(void)
+{
+ return Clock::Milliseconds64(clock_SystemTimeMicroseconds64() / 1000);
+}
+
+CHIP_ERROR ClockImpl::GetClock_RealTime(Clock::Microseconds64 & aCurTime)
+{
+ return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
+}
+
+CHIP_ERROR ClockImpl::GetClock_RealTimeMS(Clock::Milliseconds64 & aCurTime)
+{
+ return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
+}
+
+CHIP_ERROR ClockImpl::SetClock_RealTime(Clock::Microseconds64 aNewCurTime)
+{
+ return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
+}
+
+} // namespace Clock
+} // namespace System
+} // namespace chip
diff --git a/src/platform/CYW30739/ThreadStackManagerImpl.cpp b/src/platform/CYW30739/ThreadStackManagerImpl.cpp
new file mode 100644
index 0000000..f8d8a76
--- /dev/null
+++ b/src/platform/CYW30739/ThreadStackManagerImpl.cpp
@@ -0,0 +1,108 @@
+/*
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * Provides an implementation of the ThreadStackManager object.
+ *
+ */
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp>
+
+#include <lwip/ip.h>
+#include <openthread-system.h>
+#include <wiced_platform.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+using namespace ::chip::DeviceLayer::Internal;
+
+ThreadStackManagerImpl ThreadStackManagerImpl::sInstance;
+
+CHIP_ERROR ThreadStackManagerImpl::_InitThreadStack()
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+ wiced_result_t result;
+
+ mThread = wiced_rtos_create_thread();
+ VerifyOrExit(mThread != nullptr, err = CHIP_ERROR_NO_MEMORY);
+
+ mMutex = wiced_rtos_create_mutex();
+ VerifyOrExit(mMutex != nullptr, err = CHIP_ERROR_NO_MEMORY);
+
+ result = wiced_rtos_init_mutex(mMutex);
+ VerifyOrExit(result == WICED_SUCCESS, err = CHIP_ERROR_INTERNAL);
+ otSysInit(0, NULL);
+
+ err = GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>::DoInit(NULL);
+
+exit:
+ return err;
+}
+
+CHIP_ERROR ThreadStackManagerImpl::_StartThreadTask()
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+ wiced_result_t result;
+
+ result = wiced_rtos_init_thread(mThread, CHIP_DEVICE_CONFIG_THREAD_TASK_PRIORITY, CHIP_DEVICE_CONFIG_THREAD_TASK_NAME,
+ ThreadTaskMain, CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE, this);
+ VerifyOrExit(result == WICED_SUCCESS, err = CHIP_ERROR_NO_MEMORY);
+
+exit:
+ return err;
+}
+
+void ThreadStackManagerImpl::_LockThreadStack()
+{
+ const wiced_result_t result = wiced_rtos_lock_mutex(mMutex);
+ VerifyOrReturn(result == WICED_SUCCESS, ChipLogError(DeviceLayer, "%s %x", __func__, result));
+}
+
+void ThreadStackManagerImpl::_UnlockThreadStack()
+{
+ const wiced_result_t result = wiced_rtos_unlock_mutex(mMutex);
+ VerifyOrReturn(result == WICED_SUCCESS || result == WICED_NOT_OWNED, ChipLogError(DeviceLayer, "%s %x", __func__, result));
+}
+
+void ThreadStackManagerImpl::ThreadTaskMain(void)
+{
+ while (true)
+ {
+ LockThreadStack();
+ ProcessThreadActivity();
+ UnlockThreadStack();
+ }
+}
+
+void ThreadStackManagerImpl::ThreadTaskMain(uint32_t arg)
+{
+ ChipLogDetail(DeviceLayer, "Thread task running");
+ reinterpret_cast<ThreadStackManagerImpl *>(arg)->ThreadTaskMain();
+}
+
+} // namespace DeviceLayer
+} // namespace chip
+
+/* A wrapper for the GenericThreadStackManagerImpl_OpenThread_LwIP implementation. */
+err_t tcpip_input(struct pbuf * p, struct netif * inp)
+{
+ return ip_input(p, inp);
+}
diff --git a/src/platform/CYW30739/ThreadStackManagerImpl.h b/src/platform/CYW30739/ThreadStackManagerImpl.h
new file mode 100644
index 0000000..a8068ed
--- /dev/null
+++ b/src/platform/CYW30739/ThreadStackManagerImpl.h
@@ -0,0 +1,102 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2019 Nest Labs, Inc.
+ *
+ * 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.
+ */
+
+/**
+ * @file
+ * Provides an implementation of the ThreadStackManager object
+ * for the platforms using the OpenThread stack.
+ */
+
+#pragma once
+
+#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.h>
+#include <wiced_rtos.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+/**
+ * Concrete implementation of the ThreadStackManager singleton object for the platform.
+ */
+class ThreadStackManagerImpl final : public ThreadStackManager,
+ public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>
+{
+ // Allow the ThreadStackManager interface class to delegate method calls to
+ // the implementation methods provided by this class.
+ friend class ThreadStackManager;
+
+public:
+ // ===== Methods that implement the ThreadStackManager abstract interface.
+ CHIP_ERROR _InitThreadStack();
+
+protected:
+ // ===== Methods that implement the ThreadStackManager abstract interface.
+
+ CHIP_ERROR _StartThreadTask();
+ void _LockThreadStack();
+ bool _TryLockThreadStack();
+ void _UnlockThreadStack();
+
+ // ===== Methods that override the GenericThreadStackManagerImpl_OpenThread abstract interface.
+
+ void _OnCHIPoBLEAdvertisingStart();
+ void _OnCHIPoBLEAdvertisingStop();
+
+private:
+ // ===== Members for internal use by the following friends.
+
+ friend ThreadStackManager & ::chip::DeviceLayer::ThreadStackMgr(void);
+ friend ThreadStackManagerImpl & ::chip::DeviceLayer::ThreadStackMgrImpl(void);
+
+ wiced_thread_t * mThread;
+ wiced_mutex_t * mMutex;
+ static ThreadStackManagerImpl sInstance;
+
+ // ===== Private members for use by this class only.
+
+ void ThreadTaskMain(void);
+
+ static void ThreadTaskMain(uint32_t arg);
+};
+
+/**
+ * Returns the public interface of the ThreadStackManager singleton object.
+ *
+ * Chip applications should use this to access features of the ThreadStackManager object
+ * that are common to all platforms.
+ */
+inline ThreadStackManager & ThreadStackMgr(void)
+{
+ return ThreadStackManagerImpl::sInstance;
+}
+
+/**
+ * Returns the platform-specific implementation of the ThreadStackManager singleton object.
+ *
+ * Chip applications can use this to gain access to features of the ThreadStackManager
+ * that are specific to the platforms.
+ */
+inline ThreadStackManagerImpl & ThreadStackMgrImpl(void)
+{
+ return ThreadStackManagerImpl::sInstance;
+}
+
+} // namespace DeviceLayer
+} // namespace chip
+
+err_t tcpip_input(struct pbuf * p, struct netif * inp);
diff --git a/src/platform/CYW30739/args.gni b/src/platform/CYW30739/args.gni
new file mode 100644
index 0000000..a49440e
--- /dev/null
+++ b/src/platform/CYW30739/args.gni
@@ -0,0 +1,66 @@
+# Copyright (c) 2021 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.
+
+import("//build_overrides/build.gni")
+import("//build_overrides/chip.gni")
+import("//build_overrides/cyw30739_sdk.gni")
+import("//build_overrides/pigweed.gni")
+
+import("${chip_root}/examples/platform/cyw30739/args.gni")
+
+custom_toolchain = "${build_root}/toolchain/arm_gcc"
+
+arm_platform_config = "${cyw30739_sdk_build_root}/cyw30739_arm.gni"
+
+chip_target_style = "embedded"
+chip_crypto = "mbedtls"
+
+chip_device_platform = "cyw30739"
+chip_mdns = "platform"
+
+chip_enable_openthread = true
+
+lwip_platform = "cyw30739"
+
+chip_inet_config_enable_ipv4 = false
+chip_inet_config_enable_dns_resolver = false
+chip_inet_config_enable_tcp_endpoint = false
+chip_inet_config_enable_raw_endpoint = false
+
+chip_system_config_locking = "none"
+chip_system_config_use_lwip = true
+chip_system_config_use_sockets = false
+
+is_debug = false
+default_configs_optimize = [ "$dir_pw_build:optimize_size" ]
+
+chip_build_tests = false
+
+mbedtls_target = "${cyw30739_sdk_build_root}:mbedtls"
+openthread_external_mbedtls = mbedtls_target
+
+openthread_project_core_config_file = "OpenThreadConfig.h"
+openthread_core_config_deps = [ "${chip_root}/examples/platform/cyw30739:openthread_core_config_ifx_chip_examples" ]
+
+openthread_external_platform =
+ "${chip_root}/third_party/openthread/platforms/ifx:libopenthread-ifx"
+
+openthread_enable_core_config_args = true
+openthread_config_dhcp6_client_enable = true
+openthread_config_dns_client_enable = true
+openthread_config_ecdsa_enable = true
+openthread_config_ip6_slaac_enable = true
+openthread_config_joiner_enable = true
+openthread_config_log_output = "platform_defined"
+openthread_config_srp_client_enable = true
diff --git a/src/platform/CYW30739/cycfg_gatt_db.c b/src/platform/CYW30739/cycfg_gatt_db.c
new file mode 100644
index 0000000..7e24da9
--- /dev/null
+++ b/src/platform/CYW30739/cycfg_gatt_db.c
@@ -0,0 +1,128 @@
+/***************************************************************************/ /**
+ * File Name: cycfg_gatt_db.c
+ * Version: 2.1
+ *
+ * Description:
+ * BLE device's GATT database and device
+ *configuration.
+ *
+ ********************************************************************************
+ * Copyright 2020 Cypress Semiconductor Corporation
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 "cycfg_gatt_db.h"
+#include "wiced_bt_gatt.h"
+#include "wiced_bt_uuid.h"
+#ifdef BLE_OTA_FW_UPGRADE
+#include <wiced_bt_ota_firmware_upgrade.h>
+#endif
+
+/*************************************************************************************
+ * GATT server definitions
+ *************************************************************************************/
+
+const uint8_t gatt_database[] = {
+ /* Primary Service: Generic Access */
+ PRIMARY_SERVICE_UUID16(HDLS_GAP, __UUID_SERVICE_GENERIC_ACCESS),
+
+ /* Characteristic: Device Name */
+ CHARACTERISTIC_UUID16(HDLC_GAP_DEVICE_NAME, HDLC_GAP_DEVICE_NAME_VALUE, __UUID_CHARACTERISTIC_DEVICE_NAME,
+ LEGATTDB_CHAR_PROP_READ, LEGATTDB_PERM_READABLE),
+
+ /* Characteristic: Appearance */
+ CHARACTERISTIC_UUID16(HDLC_GAP_APPEARANCE, HDLC_GAP_APPEARANCE_VALUE, __UUID_CHARACTERISTIC_APPEARANCE, LEGATTDB_CHAR_PROP_READ,
+ LEGATTDB_PERM_READABLE),
+
+ /* Primary Service: Generic Attribute */
+ PRIMARY_SERVICE_UUID16(HDLS_GATT, __UUID_SERVICE_GENERIC_ATTRIBUTE),
+
+ /* Primary Service: Custom Service */
+ PRIMARY_SERVICE_UUID16(HDLS_CHIP_SERVICE, __UUID16_CHIPoBLEService),
+
+ /* Characteristic: C1 */
+ CHARACTERISTIC_UUID128_WRITABLE(HDLC_CHIP_SERVICE_CHAR_C1, HDLC_CHIP_SERVICE_CHAR_C1_VALUE, __UUID128_CHIPoBLEChar_C1,
+ LEGATTDB_CHAR_PROP_WRITE,
+ LEGATTDB_PERM_VARIABLE_LENGTH | LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITE_REQ),
+ /* Characteristic: C2 */
+ CHARACTERISTIC_UUID128_WRITABLE(HDLC_CHIP_SERVICE_CHAR_C2, HDLC_CHIP_SERVICE_CHAR_C2_VALUE, __UUID128_CHIPoBLEChar_C2,
+ LEGATTDB_CHAR_PROP_READ | LEGATTDB_CHAR_PROP_NOTIFY,
+ LEGATTDB_PERM_RELIABLE_WRITE | LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITABLE),
+
+ /* Descriptor: Client Characteristic Configuration */
+ CHAR_DESCRIPTOR_UUID16_WRITABLE(HDLD_CHIP_SERVICE_RX_CLIENT_CHAR_CONFIG, __UUID_DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION,
+ LEGATTDB_PERM_AUTH_READABLE | LEGATTDB_PERM_WRITE_REQ),
+
+#ifdef BLE_OTA_FW_UPGRADE
+ /* WICED Upgrade Service. */
+ PRIMARY_SERVICE_UUID128(HANDLE_OTA_FW_UPGRADE_SERVICE, UUID_OTA_FW_UPGRADE_SERVICE),
+
+ /* characteristic Control Point */
+ CHARACTERISTIC_UUID128_WRITABLE(HANDLE_OTA_FW_UPGRADE_CHARACTERISTIC_CONTROL_POINT, HANDLE_OTA_FW_UPGRADE_CONTROL_POINT,
+ UUID_OTA_FW_UPGRADE_CHARACTERISTIC_CONTROL_POINT,
+ LEGATTDB_CHAR_PROP_WRITE | LEGATTDB_CHAR_PROP_NOTIFY | LEGATTDB_CHAR_PROP_INDICATE,
+ LEGATTDB_PERM_VARIABLE_LENGTH | LEGATTDB_PERM_WRITE_REQ),
+
+ /* client characteristic configuration descriptor */
+ CHAR_DESCRIPTOR_UUID16_WRITABLE(HANDLE_OTA_FW_UPGRADE_CLIENT_CONFIGURATION_DESCRIPTOR,
+ UUID_DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION,
+ LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITE_REQ),
+
+ /* characteristic Data. */
+ CHARACTERISTIC_UUID128_WRITABLE(HANDLE_OTA_FW_UPGRADE_CHARACTERISTIC_DATA, HANDLE_OTA_FW_UPGRADE_DATA,
+ UUID_OTA_FW_UPGRADE_CHARACTERISTIC_DATA, LEGATTDB_CHAR_PROP_WRITE,
+ LEGATTDB_PERM_VARIABLE_LENGTH | LEGATTDB_PERM_WRITE_REQ | LEGATTDB_PERM_RELIABLE_WRITE),
+#endif /* BLE_OTA_FW_UPGRADE */
+};
+
+/* Length of the GATT database */
+const uint16_t gatt_database_len = sizeof(gatt_database);
+
+/*************************************************************************************
+ * GATT Initial Value Arrays
+ ************************************************************************************/
+
+uint8_t app_gap_device_name[kMaxDeviceNameLength] = { 'I', 'F', 'X', ' ', 'C', 'H', 'I', 'P' };
+uint8_t app_gap_appearance[] = {
+ 0x00,
+ 0x00,
+};
+uint8_t app_chip_service_char_tx_client_char_config[] = {
+ 0x00,
+ 0x00,
+};
+
+/************************************************************************************
+ * GATT Lookup Table
+ ************************************************************************************/
+
+gatt_db_lookup_table_t app_gatt_db_ext_attr_tbl[] = {
+ /* { attribute handle, maxlen, curlen, attribute data } */
+ { HDLC_GAP_DEVICE_NAME_VALUE, sizeof(app_gap_device_name), sizeof(app_gap_device_name), app_gap_device_name },
+ { HDLC_GAP_APPEARANCE_VALUE, sizeof(app_gap_appearance), sizeof(app_gap_appearance), app_gap_appearance },
+ { HDLD_CHIP_SERVICE_RX_CLIENT_CHAR_CONFIG, sizeof(app_chip_service_char_tx_client_char_config),
+ sizeof(app_chip_service_char_tx_client_char_config), app_chip_service_char_tx_client_char_config },
+};
+
+/* Number of Lookup Table entries */
+const uint16_t app_gatt_db_ext_attr_tbl_size = (sizeof(app_gatt_db_ext_attr_tbl) / sizeof(gatt_db_lookup_table_t));
+
+/* Number of GATT initial value arrays entries */
+const uint16_t app_gap_device_name_len = (sizeof(app_gap_device_name));
+const uint16_t app_gap_appearance_len = (sizeof(app_gap_appearance));
+const uint16_t app_chip_service_char_tx_client_char_config_len = (sizeof(app_chip_service_char_tx_client_char_config));
diff --git a/src/platform/CYW30739/cycfg_gatt_db.h b/src/platform/CYW30739/cycfg_gatt_db.h
new file mode 100644
index 0000000..a525696
--- /dev/null
+++ b/src/platform/CYW30739/cycfg_gatt_db.h
@@ -0,0 +1,95 @@
+/***************************************************************************/
+/**
+ * File Name: cycfg_gatt_db.h
+ * Version: 2.1
+ *
+ * Description:
+ * Definitions for constants used in the device's GATT
+ *database and function prototypes. This file should
+ *not be modified. It was automatically generated by
+ * Bluetooth Configurator 2.1.0.2188
+ *
+ ********************************************************************************
+ * Copyright 2020 Cypress Semiconductor Corporation
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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.
+ *******************************************************************************/
+
+#if !defined(CYCFG_GATT_DB_H)
+#define CYCFG_GATT_DB_H
+
+#include "stdint.h"
+
+#define __UUID_SERVICE_GENERIC_ACCESS 0x1800
+#define __UUID_CHARACTERISTIC_DEVICE_NAME 0x2A00
+#define __UUID_CHARACTERISTIC_APPEARANCE 0x2A01
+#define __UUID_SERVICE_GENERIC_ATTRIBUTE 0x1801
+#define __UUID16_CHIPoBLEService 0xFFF6
+#define __UUID128_CHIPoBLEChar_C1 0x11, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18
+#define __UUID128_CHIPoBLEChar_C2 0x12, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18
+#define __UUID_DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION 0x2902
+
+/* Service Generic Access */
+#define HDLS_GAP 0x01
+/* Characteristic Device Name */
+#define HDLC_GAP_DEVICE_NAME 0x02
+#define HDLC_GAP_DEVICE_NAME_VALUE 0x03
+/* Characteristic Appearance */
+#define HDLC_GAP_APPEARANCE 0x04
+#define HDLC_GAP_APPEARANCE_VALUE 0x05
+
+/* Service Generic Attribute */
+#define HDLS_GATT 0x06
+
+/* Service CHIP Service */
+#define HDLS_CHIP_SERVICE 0x07
+
+/* Characteristic CHIP C1 */
+#define HDLC_CHIP_SERVICE_CHAR_C1 0x08
+#define HDLC_CHIP_SERVICE_CHAR_C1_VALUE 0x09
+
+/* Characteristic CHIP C2 */
+#define HDLC_CHIP_SERVICE_CHAR_C2 0x0A
+#define HDLC_CHIP_SERVICE_CHAR_C2_VALUE 0x0B
+
+/* Descriptor Client Characteristic Configuration */
+#define HDLD_CHIP_SERVICE_RX_CLIENT_CHAR_CONFIG 0x0C
+
+/* External Lookup Table Entry */
+typedef struct
+{
+ uint16_t handle;
+ uint16_t max_len;
+ uint16_t cur_len;
+ uint8_t * p_data;
+} gatt_db_lookup_table_t;
+
+#define kMaxDeviceNameLength 32
+
+/* External definitions */
+extern const uint8_t gatt_database[];
+extern const uint16_t gatt_database_len;
+extern gatt_db_lookup_table_t app_gatt_db_ext_attr_tbl[];
+extern const uint16_t app_gatt_db_ext_attr_tbl_size;
+extern uint8_t app_gap_device_name[kMaxDeviceNameLength];
+extern const uint16_t app_gap_device_name_len;
+extern uint8_t app_gap_appearance[];
+extern const uint16_t app_gap_appearance_len;
+extern uint8_t app_chip_service_char_tx_client_char_config[];
+extern const uint16_t app_chip_service_char_tx_client_char_config_len;
+
+#endif /* CYCFG_GATT_DB_H */
diff --git a/src/platform/CYW30739/cyw30739-chip-mbedtls-config.h b/src/platform/CYW30739/cyw30739-chip-mbedtls-config.h
new file mode 100644
index 0000000..0a7a749
--- /dev/null
+++ b/src/platform/CYW30739/cyw30739-chip-mbedtls-config.h
@@ -0,0 +1,202 @@
+/*
+ *
+ * Copyright (c) 2021 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.
+ */
+
+#pragma once
+
+/**
+ * \def MBEDTLS_AES_ALT
+ *
+ * MBEDTLS__MODULE_NAME__ALT: Uncomment a macro to let mbed TLS use your
+ * alternate core implementation of a symmetric crypto, an arithmetic or hash
+ * module (e.g. platform specific assembly optimized implementations). Keep
+ * in mind that the function prototypes should remain the same.
+ *
+ * This replaces the whole module. If you only want to replace one of the
+ * functions, use one of the MBEDTLS__FUNCTION_NAME__ALT flags.
+ *
+ * Example: In case you uncomment MBEDTLS_AES_ALT, mbed TLS will no longer
+ * provide the "struct mbedtls_aes_context" definition and omit the base
+ * function declarations and implementations. "aes_alt.h" will be included from
+ * "aes.h" to include the new function definitions.
+ *
+ * Uncomment a macro to enable alternate implementation of the corresponding
+ * module.
+ *
+ * \warning MD2, MD4, MD5, ARC4, DES and SHA-1 are considered weak and their
+ * use constitutes a security risk. If possible, we recommend
+ * avoiding dependencies on them, and considering stronger message
+ * digests and ciphers instead.
+ *
+ */
+//#define MBEDTLS_AES_ALT
+//#define MBEDTLS_ARC4_ALT
+//#define MBEDTLS_ARIA_ALT
+//#define MBEDTLS_BLOWFISH_ALT
+//#define MBEDTLS_CAMELLIA_ALT
+//#define MBEDTLS_CCM_ALT
+//#define MBEDTLS_CHACHA20_ALT
+//#define MBEDTLS_CHACHAPOLY_ALT
+//#define MBEDTLS_CMAC_ALT
+//#define MBEDTLS_DES_ALT
+//#define MBEDTLS_DHM_ALT
+//#define MBEDTLS_ECJPAKE_ALT
+//#define MBEDTLS_GCM_ALT
+//#define MBEDTLS_NIST_KW_ALT
+//#define MBEDTLS_MD2_ALT
+//#define MBEDTLS_MD4_ALT
+//#define MBEDTLS_MD5_ALT
+//#define MBEDTLS_POLY1305_ALT
+//#define MBEDTLS_RIPEMD160_ALT
+//#define MBEDTLS_RSA_ALT
+//#define MBEDTLS_SHA1_ALT
+//#define MBEDTLS_SHA256_ALT
+//#define MBEDTLS_SHA512_ALT
+//#define MBEDTLS_XTEA_ALT
+
+/**
+ * \def MBEDTLS_ERROR_STRERROR_DUMMY
+ *
+ * Enable a dummy error function to make use of mbedtls_strerror() in
+ * third party libraries easier when MBEDTLS_ERROR_C is disabled
+ * (no effect when MBEDTLS_ERROR_C is enabled).
+ *
+ * You can safely disable this if MBEDTLS_ERROR_C is enabled, or if you're
+ * not using mbedtls_strerror() or error_strerror() in your application.
+ *
+ * Disable if you run into name conflicts and want to really remove the
+ * mbedtls_strerror()
+ */
+#define MBEDTLS_ERROR_STRERROR_DUMMY
+
+/**
+ * \def MBEDTLS_BASE64_C
+ *
+ * Enable the Base64 module.
+ *
+ * Module: library/base64.c
+ * Caller: library/pem.c
+ *
+ * This module is required for PEM support (required by X.509).
+ */
+#define MBEDTLS_BASE64_C
+
+/**
+ * \def MBEDTLS_HKDF_C
+ *
+ * Enable the HKDF algorithm (RFC 5869).
+ *
+ * Module: library/hkdf.c
+ * Caller:
+ *
+ * Requires: MBEDTLS_MD_C
+ *
+ * This module adds support for the Hashed Message Authentication Code
+ * (HMAC)-based key derivation function (HKDF).
+ */
+#define MBEDTLS_HKDF_C
+
+/**
+ * \def MBEDTLS_OID_C
+ *
+ * Enable the OID database.
+ *
+ * Module: library/oid.c
+ * Caller: library/asn1write.c
+ * library/pkcs5.c
+ * library/pkparse.c
+ * library/pkwrite.c
+ * library/rsa.c
+ * library/x509.c
+ * library/x509_create.c
+ * library/x509_crl.c
+ * library/x509_crt.c
+ * library/x509_csr.c
+ * library/x509write_crt.c
+ * library/x509write_csr.c
+ *
+ * This modules translates between OIDs and internal values.
+ */
+#define MBEDTLS_OID_C
+
+/**
+ * \def MBEDTLS_PEM_WRITE_C
+ *
+ * Enable PEM encoding / writing.
+ *
+ * Module: library/pem.c
+ * Caller: library/pkwrite.c
+ * library/x509write_crt.c
+ * library/x509write_csr.c
+ *
+ * Requires: MBEDTLS_BASE64_C
+ *
+ * This modules adds support for encoding / writing PEM files.
+ */
+#define MBEDTLS_PEM_WRITE_C
+
+/**
+ * \def MBEDTLS_PK_WRITE_C
+ *
+ * Enable the generic public (asymetric) key writer.
+ *
+ * Module: library/pkwrite.c
+ * Caller: library/x509write.c
+ *
+ * Requires: MBEDTLS_PK_C
+ *
+ * Uncomment to enable generic public key write functions.
+ */
+#define MBEDTLS_PK_WRITE_C
+
+/**
+ * \def MBEDTLS_PKCS5_C
+ *
+ * Enable PKCS#5 functions.
+ *
+ * Module: library/pkcs5.c
+ *
+ * Requires: MBEDTLS_MD_C
+ *
+ * This module adds support for the PKCS#5 functions.
+ */
+#define MBEDTLS_PKCS5_C
+
+/**
+ * \def MBEDTLS_X509_CREATE_C
+ *
+ * Enable X.509 core for creating certificates.
+ *
+ * Module: library/x509_create.c
+ *
+ * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_OID_C, MBEDTLS_PK_WRITE_C
+ *
+ * This module is the basis for creating X.509 certificates and CSRs.
+ */
+#define MBEDTLS_X509_CREATE_C
+
+/**
+ * \def MBEDTLS_X509_CSR_WRITE_C
+ *
+ * Enable creating X.509 Certificate Signing Requests (CSR).
+ *
+ * Module: library/x509_csr_write.c
+ *
+ * Requires: MBEDTLS_X509_CREATE_C
+ *
+ * This module is required for X.509 certificate request writing.
+ */
+#define MBEDTLS_X509_CSR_WRITE_C
diff --git a/src/platform/CYW30739/wiced_button_manager.c b/src/platform/CYW30739/wiced_button_manager.c
new file mode 100644
index 0000000..9309b5a
--- /dev/null
+++ b/src/platform/CYW30739/wiced_button_manager.c
@@ -0,0 +1,691 @@
+/*
+ * Copyright 2016-2021, Cypress Semiconductor Corporation (an Infineon company) or
+ * an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+ *
+ * This software, including source code, documentation and related
+ * materials ("Software") is owned by Cypress Semiconductor Corporation
+ * or one of its affiliates ("Cypress") and is protected by and subject to
+ * worldwide patent protection (United States and foreign),
+ * United States copyright laws and international treaty provisions.
+ * Therefore, you may use this Software only as provided in the license
+ * agreement accompanying the software package from which you
+ * obtained this Software ("EULA").
+ * If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
+ * non-transferable license to copy, modify, and compile the Software
+ * source code solely for use in connection with Cypress's
+ * integrated circuit products. Any reproduction, modification, translation,
+ * compilation, or representation of this Software except as specified
+ * above is prohibited without the express written permission of Cypress.
+ *
+ * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
+ * reserves the right to make changes to the Software without notice. Cypress
+ * does not assume any liability arising out of the application or use of the
+ * Software or any product or circuit described in the Software. Cypress does
+ * not authorize its products for use in any products where a malfunction or
+ * failure of the Cypress product may reasonably be expected to result in
+ * significant property damage, injury or death ("High Risk Product"). By
+ * including Cypress's product in a High Risk Product, the manufacturer
+ * of such system or application assumes all risk of such use and in doing
+ * so agrees to indemnify Cypress against all liability.
+ */
+/** @file
+ *
+ * Button manager implements generic interface for button events and button type configurations.
+ * It exposes interface to configure platform button events (like click,long press) with user configurable timing.
+ */
+#include "wiced_button_manager.h"
+#include "clock_timer.h"
+#include "platform_button.h"
+#include "string.h"
+#include "wiced_bt_trace.h"
+#ifdef CYW55572
+#include "wiced_memory.h"
+#include "wiced_misc_rtos_utils.h"
+#endif
+
+/******************************************************
+ * Macros
+ ******************************************************/
+
+#define BUTTON_TIMER_TIMEOUT (100) /*msec*/
+
+/******************************************************
+ * Constants
+ ******************************************************/
+
+/******************************************************
+ * Enumerations
+ ******************************************************/
+
+/******************************************************
+ * Type Definitions
+ ******************************************************/
+#if BTSTACK_VER >= 0x03000001
+#define TIMER_PARAM_TYPE WICED_TIMER_PARAM_TYPE
+#endif
+
+#ifdef CYW55572
+#define BUTTON_EVENT_QUEUE_DEPTH 16
+#endif
+
+/******************************************************
+ * Structures
+ ******************************************************/
+#ifdef CYW55572
+typedef struct
+{
+ button_manager_button_t * p_button;
+ button_manager_event_t event;
+} button_event_defer_to_mpaf_t;
+#endif
+
+/******************************************************
+ * Function Declarations
+ ******************************************************/
+static void button_state_change_callback(platform_button_t id, wiced_bool_t new_state);
+static wiced_result_t button_pressed_event_handler(void * arg);
+static wiced_result_t button_released_event_handler(void * arg);
+static wiced_result_t deferred_button_timer_handler(void * arg);
+
+static wiced_bool_t button_check_event_mask(button_manager_button_t * button, uint16_t new_event);
+static void button_check_for_double_click(button_manager_button_t * button, button_manager_event_t * new_event);
+static button_manager_event_t button_deduce_duration_event(button_manager_button_t * button, uint32_t current_interval);
+static button_manager_button_t * get_button(platform_button_t id);
+#ifdef CYW55572
+static void button_event_defer_to_mpaf(void * arg);
+#endif
+
+/******************************************************
+ * Variables Definitions
+ ******************************************************/
+static button_manager_t * button_manager;
+#ifdef CYW55572
+static wiced_mutex_t * p_mutex_button_event;
+static wiced_bt_buffer_q_t button_event_queue;
+static wiced_bt_pool_t * p_button_event_pool = NULL;
+#endif
+
+/******************************************************
+ * Function Definitions
+ ******************************************************/
+
+/*
+ * button_long_press_detect_timeout_handler
+ *
+ * Timeout handler for button long press detect timer.
+ *
+ * The execution duration of this utility is defined in BUTTON_TIMER_TIMEOUT.
+ */
+static void button_long_press_detect_timeout_handler(TIMER_PARAM_TYPE arg)
+{
+ button_manager_button_t * p_button = (button_manager_button_t *) arg;
+
+ /* Check if button is under debouncing state. */
+ if (p_button->debouncing)
+ {
+ return;
+ }
+
+ /* Get current button state. */
+ p_button->current_state = (button_manager_button_state_t) platform_button_get_value(p_button->configuration->button);
+
+ if (p_button->current_state != BUTTON_STATE_HELD)
+ {
+ WICED_BT_TRACE("Err: Button %d is already released\n", p_button->configuration->button);
+
+ if (wiced_is_timer_in_use(&p_button->long_press_timer))
+ {
+ wiced_stop_timer(&p_button->long_press_timer);
+ }
+
+ return;
+ }
+ /* Get current timestatmp. */
+ p_button->timer_timestamp = clock_SystemTimeMicroseconds64();
+
+ deferred_button_timer_handler((void *) p_button);
+}
+
+/*
+ * button_debounce_timeout_handler
+ *
+ * Timeout handler for button debounce timer.
+ */
+static void button_debounce_timeout_handler(TIMER_PARAM_TYPE arg)
+{
+ button_manager_button_t * p_button = (button_manager_button_t *) arg;
+ wiced_result_t result;
+
+ // WICED_BT_TRACE("button_debounce_timeout_handler (%d, %d)\n", p_button->configuration->button, p_button->debounce_counter);
+
+ if (p_button->debounce_counter > 0)
+ {
+ /* Reset the button debounce counter. */
+ p_button->debounce_counter = 0;
+
+ button_pressed_event_handler((void *) p_button);
+ }
+ else
+ {
+ if (wiced_is_timer_in_use(&p_button->long_press_timer))
+ {
+ wiced_stop_timer(&p_button->long_press_timer);
+ }
+ }
+
+ /* Reset the button debounce state. */
+ p_button->debouncing = WICED_FALSE;
+}
+
+/**
+ * The application should call this function to Initialize the Button Manager
+ */
+wiced_result_t __attribute__((weak))
+wiced_button_manager_init(button_manager_t * manager, const wiced_button_manager_configuration_t * configuration,
+ button_manager_button_t * buttons, uint32_t number_of_buttons)
+{
+ uint32_t a;
+
+ memset(manager, 0, sizeof(*manager));
+
+ manager->configuration = configuration;
+ manager->buttons = buttons;
+ manager->number_of_buttons = number_of_buttons;
+
+ button_manager = manager;
+
+ for (a = 0; a < number_of_buttons; a++)
+ {
+ platform_button_init(buttons[a].configuration->button);
+ platform_button_enable(buttons[a].configuration->button);
+ buttons[a].current_state = BUTTON_STATE_RELEASED;
+ buttons[a].repeat = 0;
+ buttons[a].debounce_counter = 0;
+ buttons[a].debouncing = WICED_FALSE;
+ }
+
+ platform_button_register_state_change_callback(button_state_change_callback);
+
+ /* Initialize the timers used for detecting the long press event. */
+ for (a = 0; a < number_of_buttons; a++)
+ {
+ wiced_init_timer(&buttons[a].long_press_timer, button_long_press_detect_timeout_handler, (TIMER_PARAM_TYPE) &buttons[a],
+ WICED_MILLI_SECONDS_PERIODIC_TIMER);
+ }
+
+ /* Initialize the timers used for de-bounce. */
+ for (a = 0; a < number_of_buttons; a++)
+ {
+ wiced_init_timer(&buttons[a].debounce_timer, button_debounce_timeout_handler, (TIMER_PARAM_TYPE) &buttons[a],
+ WICED_MILLI_SECONDS_TIMER);
+ }
+
+#ifdef CYW55572
+ p_button_event_pool =
+ wiced_bt_create_pool("Button Event", sizeof(button_event_defer_to_mpaf_t), BUTTON_EVENT_QUEUE_DEPTH, NULL);
+
+ if (!p_button_event_pool)
+ {
+ WICED_BT_TRACE("%s: Fail to create pool.\n", __FUNCTION__);
+ return WICED_ERROR;
+ }
+
+ wiced_bt_init_q(&button_event_queue, NULL);
+ p_mutex_button_event = wiced_rtos_create_mutex();
+ if (p_mutex_button_event == NULL)
+ {
+ WICED_BT_TRACE("%s: Fail to create mutex.\n", __FUNCTION__);
+ return WICED_ERROR;
+ }
+
+ if (wiced_rtos_init_mutex(p_mutex_button_event) != WICED_SUCCESS)
+ {
+ WICED_BT_TRACE("%s: Fail to init. mutex.\n", __FUNCTION__);
+ return WICED_ERROR;
+ }
+#endif
+
+ return WICED_SUCCESS;
+}
+
+/**
+ * The application should call this function to de-Initialize the Button Manager
+ *
+ * @param manager : Pointer to button manager to de-initialize.
+ * @return : result.
+ */
+wiced_result_t wiced_button_manager_deinit(button_manager_t * manager)
+{
+ uint32_t a;
+ for (a = 0; a < manager->number_of_buttons; a++)
+ {
+ platform_button_disable(manager->buttons[a].configuration->button);
+ platform_button_deinit(manager->buttons[a].configuration->button);
+ }
+
+ for (a = 0; a < manager->number_of_buttons; a++)
+ {
+ if (WICED_TRUE == wiced_is_timer_in_use(&manager->buttons[a].debounce_timer))
+ {
+ wiced_stop_timer(&manager->buttons[a].debounce_timer);
+ }
+
+ wiced_deinit_timer(&manager->buttons[a].debounce_timer);
+
+ if (WICED_TRUE == wiced_is_timer_in_use(&manager->buttons[a].long_press_timer))
+ {
+ wiced_stop_timer(&manager->buttons[a].long_press_timer);
+ }
+
+ wiced_deinit_timer(&manager->buttons[a].long_press_timer);
+ }
+
+ button_manager = NULL;
+ return WICED_SUCCESS;
+}
+
+/**
+ * Deferred Handler initiated from timer handler
+ *
+ * @param arg : Arguments passed by the timer framework to timer handler
+ * @return : result
+ */
+static wiced_result_t deferred_button_timer_handler(void * arg)
+{
+ button_manager_button_t * p_button = (button_manager_button_t *) arg;
+ uint64_t duration; // us
+ button_manager_event_t new_held_event = 0;
+
+ /* Check current button state. */
+ if (p_button->current_state == BUTTON_STATE_RELEASED)
+ {
+ return WICED_SUCCESS;
+ }
+
+ /* Calculate the time difference. */
+ duration = p_button->timer_timestamp - p_button->pressed_timestamp; // us
+ duration = duration / 1000; // ms
+
+ /* deduce the event depending on the duration */
+ new_held_event = button_deduce_duration_event(p_button, (uint32_t) duration);
+
+ /*
+ * timers should be mainly interested in duration-specific events;
+ * let release_handler only report Click events to the application
+ */
+ if (new_held_event == BUTTON_CLICK_EVENT)
+ {
+ return WICED_SUCCESS;
+ }
+
+ if (button_check_event_mask(p_button, new_held_event))
+ {
+ if (p_button->last_sent_event != BUTTON_HOLDING_EVENT)
+ {
+ if (p_button->last_sent_event != new_held_event)
+ {
+ button_manager->configuration->event_handler(p_button, new_held_event, p_button->current_state);
+ p_button->last_sent_event = new_held_event;
+ }
+ }
+ else
+ {
+ button_manager->configuration->event_handler(p_button, new_held_event, p_button->current_state);
+ p_button->last_sent_event = new_held_event;
+ }
+ }
+
+ return WICED_SUCCESS;
+}
+
+static void button_state_change_callback_pressed(button_manager_button_t * p_button)
+{
+ /* Check if the button is under de-bounce state. */
+ if (p_button->debouncing)
+ { // under de-bounce state
+ p_button->debounce_counter++;
+ }
+ else
+ {
+ /* ignore pressed event for already pressed button*/
+ if (p_button->current_state == BUTTON_STATE_HELD)
+ {
+ return;
+ }
+
+ /* Get current timestamp for pressed event. */
+ p_button->pressed_timestamp = clock_SystemTimeMicroseconds64();
+
+ /* Start the button debounce timer. */
+ wiced_start_timer(&p_button->debounce_timer, (uint32_t) button_manager->configuration->debounce_duration);
+
+ /* Start the long pressed event detect timer. */
+ wiced_start_timer(&p_button->long_press_timer, BUTTON_TIMER_TIMEOUT);
+
+ /* Update information. */
+ p_button->debouncing = WICED_TRUE;
+ p_button->debounce_counter = 1;
+ }
+}
+
+static void button_state_change_callback_released(button_manager_button_t * p_button)
+{
+ wiced_result_t result;
+
+ /* Check if the button is under de-bounce state. */
+ if (p_button->debouncing)
+ { // under de-bounce state
+ p_button->debounce_counter--;
+ }
+ else
+ {
+ /* ignore released event for already released button */
+ if (p_button->current_state == BUTTON_STATE_RELEASED)
+ {
+ return;
+ }
+
+ /* Get current timestamp for release event. */
+ p_button->released_timestamp = clock_SystemTimeMicroseconds64();
+
+ /* Stop the long pressed event detect timer. */
+ if (wiced_is_timer_in_use(&p_button->long_press_timer))
+ {
+ wiced_stop_timer(&p_button->long_press_timer);
+ }
+
+ button_released_event_handler((void *) p_button);
+ }
+}
+
+/**
+ * Call back received when button state is changed.
+ *
+ * @param id : id of the button.
+ * @param new_state : new state of the button.
+ * @return void : no return value is expected.
+ */
+static void button_state_change_callback(platform_button_t id, wiced_bool_t new_state)
+{
+ button_manager_button_t * button = get_button(id);
+
+#if 0
+ WICED_BT_TRACE("button_state_change_callback (button %d %s, %s, %d, %d)\n",
+ id,
+ button->current_state == BUTTON_STATE_HELD ? "H" : "R",
+ button->debouncing ? "D" : "-",
+ new_state,
+ button->debounce_counter);
+#endif
+
+ /* Check module state.*/
+ if (button == NULL || button_manager == NULL)
+ {
+ WICED_BT_TRACE("button manager not initialized\n");
+ return;
+ }
+
+ if (new_state == WICED_TRUE)
+ {
+ button_state_change_callback_pressed(button);
+ }
+ else
+ {
+ button_state_change_callback_released(button);
+ }
+}
+
+/**
+ * Event handler for button press event.
+ *
+ * @param arg : Arguments passed by the event manager
+ * @return void : No return value expected.
+ */
+static wiced_result_t button_pressed_event_handler(void * arg)
+{
+ button_manager_button_t * button = (button_manager_button_t *) arg;
+
+ if (button->current_state == BUTTON_STATE_HELD)
+ {
+ return WICED_SUCCESS;
+ }
+
+ /** Button is pressed; update the state so that timer-handlers know it */
+ button->current_state = BUTTON_STATE_HELD;
+
+ return WICED_SUCCESS;
+}
+
+/**
+ * Event handler for button release event.
+ *
+ * @param arg : Arguments passed by the event manager
+ * @return void : No return value expected.
+ */
+
+static wiced_result_t button_released_event_handler(void * arg)
+{
+ button_manager_button_t * button = (button_manager_button_t *) arg;
+ button_manager_event_t new_release_event = 0;
+ uint64_t duration; // us
+
+ if (button->current_state == BUTTON_STATE_RELEASED)
+ {
+ return WICED_SUCCESS;
+ }
+
+ button->current_state = BUTTON_STATE_RELEASED;
+
+ /* Calculate the time difference. */
+ duration = button->released_timestamp - button->pressed_timestamp; // us
+ duration = duration / 1000; // ms
+
+ /** If release event comes before debounce duration, ignore it */
+ if (duration <= button_manager->configuration->debounce_duration)
+ {
+ return WICED_SUCCESS;
+ }
+
+ /** deduce the event depending on the duration */
+ new_release_event = button_deduce_duration_event(button, (uint32_t) duration);
+
+ /** Check if this Release is from 2nd click of a double-click event */
+ button_check_for_double_click(button, &new_release_event);
+
+ /**
+ * As the new state is Release and application has asked for this kind of event,
+ * send it irrespective of whether timer-handler
+ * had sent it previously
+ */
+ if (button_check_event_mask(button, new_release_event))
+ {
+#ifndef CYW55572
+ button_manager->configuration->event_handler(button, new_release_event, button->current_state);
+#else
+ /*
+ * Button released event is handled by another thread, it needs defer to mpaf thread.
+ * Deferred_button_timer_handler(long press) is handled by timer which is in mpaf thread,
+ * it does not need defer.
+ */
+ wiced_result_t result;
+
+ wiced_rtos_lock_mutex(p_mutex_button_event);
+ button_event_defer_to_mpaf_t * p_data = (button_event_defer_to_mpaf_t *) wiced_bt_get_buffer_from_pool(p_button_event_pool);
+
+ if (!p_data)
+ {
+ wiced_rtos_unlock_mutex(p_mutex_button_event);
+ WICED_BT_TRACE("Err: release event_handler no memory \n");
+ goto DEFER_MPAF_ERROR;
+ }
+
+ p_data->p_button = button;
+ p_data->event = new_release_event;
+ wiced_bt_enqueue(&button_event_queue, (wiced_bt_buffer_t *) p_data);
+ wiced_rtos_unlock_mutex(p_mutex_button_event);
+ result = wiced_rtos_defer_execution(WICED_RTOS_DEFER_TO_MPAF_THREAD, &button_event_defer_to_mpaf, NULL);
+
+ if (result != WICED_SUCCESS)
+ {
+ wiced_rtos_lock_mutex(p_mutex_button_event);
+ button_event_defer_to_mpaf_t * p_buf = (button_event_defer_to_mpaf_t *) wiced_bt_dequeue(&button_event_queue);
+ wiced_bt_free_buffer(p_buf);
+ wiced_rtos_unlock_mutex(p_mutex_button_event);
+ WICED_BT_TRACE("Err: release event_handler wiced_rtos_defer_execution (%d)\n", result);
+ goto DEFER_MPAF_ERROR;
+ }
+#endif
+ }
+
+#ifdef CYW55572
+DEFER_MPAF_ERROR:
+#endif
+
+ /** reset the button's last-sent so that a new press/held after this release is handled properly */
+ button->last_sent_event = 0;
+
+ return WICED_SUCCESS;
+}
+
+/**
+ * Checks if the event is a double click event.
+ *
+ * @param button : button information.
+ * @param new_event : new event generated for the button.
+ * @return void : no return value is expected.
+ */
+static void button_check_for_double_click(button_manager_button_t * button, button_manager_event_t * new_event)
+{
+ if (!button_check_event_mask(button, BUTTON_DOUBLE_CLICK_EVENT) || *new_event != BUTTON_CLICK_EVENT)
+ {
+ return;
+ }
+ /** figure out the time-difference in two-releases */
+ if ((button->released_timestamp - button->last_released_timestamp) <= button_manager->configuration->double_click_interval)
+ {
+ /** morph it as DOUBLE_CLICK */
+ *new_event = BUTTON_DOUBLE_CLICK_EVENT;
+ }
+
+ button->last_released_timestamp = button->released_timestamp;
+
+ return;
+}
+
+/**
+ * Checks the event mask for the button
+ *
+ * @param button : button information.
+ * @param new_event : new event generated for the button.
+ * @return wiced_bool_t : returns true/false based on the new event.
+ */
+static wiced_bool_t button_check_event_mask(button_manager_button_t * button, uint16_t new_event)
+{
+ if (!button)
+ {
+ return WICED_FALSE;
+ }
+
+ return ((new_event & button->configuration->button_event_mask) ? WICED_TRUE : WICED_FALSE);
+}
+
+/**
+ * Checks duration of the event
+ *
+ * @param button : the button that been triggered
+ * @param current_interval : current time interval
+ * @return button_manager_event_t : returns button manager event.
+ */
+
+static button_manager_event_t button_deduce_duration_event(button_manager_button_t * button, uint32_t current_interval)
+{
+ button_manager_event_t new_event = 0;
+ uint32_t target_hold_interval;
+
+ if (current_interval <= button_manager->configuration->debounce_duration)
+ {
+ return (button_manager_event_t) 0;
+ }
+ else if (current_interval > button_manager->configuration->debounce_duration &&
+ current_interval <= button_manager->configuration->short_hold_duration)
+ {
+ return BUTTON_CLICK_EVENT;
+ }
+ else if (current_interval > button_manager->configuration->short_hold_duration &&
+ current_interval <= button_manager->configuration->medium_hold_duration)
+ {
+ return BUTTON_SHORT_DURATION_EVENT;
+ }
+ else if (current_interval > button_manager->configuration->medium_hold_duration &&
+ current_interval <= button_manager->configuration->long_hold_duration)
+ {
+ return BUTTON_MEDIUM_DURATION_EVENT;
+ }
+ else if (current_interval > button_manager->configuration->long_hold_duration &&
+ current_interval <= button_manager->configuration->very_long_hold_duration)
+ {
+ button->repeat = 0;
+ return BUTTON_LONG_DURATION_EVENT;
+ }
+ else
+ { // current_interval > button_manager->configuration->very_long_hold_duration
+ if (button_manager->configuration->continuous_hold_detect == WICED_FALSE)
+ {
+ return BUTTON_VERY_LONG_DURATION_EVENT;
+ }
+ else
+ {
+ target_hold_interval = (button->repeat + 2) * button_manager->configuration->long_hold_duration;
+
+ if (current_interval > target_hold_interval)
+ {
+ button->repeat++;
+
+ return BUTTON_HOLDING_EVENT;
+ }
+ else
+ {
+ return (button_manager_event_t) 0;
+ }
+ }
+ }
+}
+
+/**
+ * returns button based on the button id
+ *
+ * @param id : id of the buttonl
+ * @return button_manager_button_t : returns button.
+ */
+
+static button_manager_button_t * get_button(platform_button_t id)
+{
+ uint8_t a;
+
+ for (a = 0; a < button_manager->number_of_buttons; a++)
+ {
+ if (button_manager->buttons[a].configuration->button == id)
+ {
+ return &button_manager->buttons[a];
+ }
+ }
+
+ return NULL;
+}
+
+#ifdef CYW55572
+static void button_event_defer_to_mpaf(void * arg)
+{
+ button_event_defer_to_mpaf_t button_event_buf;
+
+ wiced_rtos_lock_mutex(p_mutex_button_event);
+ button_event_defer_to_mpaf_t * p_buf = (button_event_defer_to_mpaf_t *) wiced_bt_dequeue(&button_event_queue);
+ memcpy(&button_event_buf, p_buf, sizeof(button_event_defer_to_mpaf_t));
+ wiced_bt_free_buffer(p_buf);
+ wiced_rtos_unlock_mutex(p_mutex_button_event);
+ button_manager->configuration->event_handler(button_event_buf.p_button, button_event_buf.event,
+ button_event_buf.p_button->current_state);
+}
+#endif
diff --git a/src/platform/CYW30739/wiced_led_manager.c b/src/platform/CYW30739/wiced_led_manager.c
new file mode 100644
index 0000000..7761c92
--- /dev/null
+++ b/src/platform/CYW30739/wiced_led_manager.c
@@ -0,0 +1,305 @@
+/*
+ * Copyright 2016-2021, Cypress Semiconductor Corporation (an Infineon company) or
+ * an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+ *
+ * This software, including source code, documentation and related
+ * materials ("Software") is owned by Cypress Semiconductor Corporation
+ * or one of its affiliates ("Cypress") and is protected by and subject to
+ * worldwide patent protection (United States and foreign),
+ * United States copyright laws and international treaty provisions.
+ * Therefore, you may use this Software only as provided in the license
+ * agreement accompanying the software package from which you
+ * obtained this Software ("EULA").
+ * If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
+ * non-transferable license to copy, modify, and compile the Software
+ * source code solely for use in connection with Cypress's
+ * integrated circuit products. Any reproduction, modification, translation,
+ * compilation, or representation of this Software except as specified
+ * above is prohibited without the express written permission of Cypress.
+ *
+ * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
+ * reserves the right to make changes to the Software without notice. Cypress
+ * does not assume any liability arising out of the application or use of the
+ * Software or any product or circuit described in the Software. Cypress does
+ * not authorize its products for use in any products where a malfunction or
+ * failure of the Cypress product may reasonably be expected to result in
+ * significant property damage, injury or death ("High Risk Product"). By
+ * including Cypress's product in a High Risk Product, the manufacturer
+ * of such system or application assumes all risk of such use and in doing
+ * so agrees to indemnify Cypress against all liability.
+ */
+/** @file
+ *
+ * This file provides implementation for the LED Manager library interface.
+ * LED Manager library provides API's to enable/disable, blink and set brightness of a LED.
+ */
+
+#include "wiced_led_manager.h"
+#include "platform_led.h"
+#include "wiced_bt_dev.h"
+#include "wiced_bt_trace.h"
+#include "wiced_hal_gpio.h"
+#include "wiced_platform.h"
+#include "wiced_rtos.h"
+#include "wiced_timer.h"
+/******************************************************
+ * Macros
+ ******************************************************/
+#define LED_FREQ (60) /*Hz*/
+
+/******************************************************
+ * Constants
+ ******************************************************/
+
+/******************************************************
+ * Enumerations
+ ******************************************************/
+
+/******************************************************
+ * Type Definitions
+ ******************************************************/
+extern platform_led_config_t platform_led_config[PLATFORM_LED_MAX];
+/******************************************************
+ * Structures
+ ******************************************************/
+
+/**
+ * @brief timer structure for LED manager
+ *
+ */
+typedef struct
+{
+ wiced_led_t led;
+ wiced_bool_t led_state;
+ uint32_t on_period;
+ uint32_t off_period;
+ wiced_timer_t timer;
+ wiced_bool_t is_init;
+} led_manager_timer;
+
+/**
+ * @brief LED timer
+ *
+ */
+static led_manager_timer led_timer[PLATFORM_LED_MAX] = { 0 };
+
+/******************************************************
+ * Function Declarations
+ ******************************************************/
+void led_timer_function(uint32_t arg);
+
+/**
+ * Function to Initialize the LED Manager
+ *
+ * @param config : Configuration for the LED.
+ * @return : result.
+ */
+wiced_result_t wiced_led_manager_init(wiced_led_config_t * config)
+{
+ uint32_t i;
+ uint16_t bright;
+ // WICED_BT_TRACE("%s <<\n",__func__);
+ if (config == NULL)
+ return WICED_ERROR;
+
+ if (config->led >= PLATFORM_LED_MAX)
+ {
+ WICED_BT_TRACE("Invalid LED for platform\n");
+ return WICED_ERROR;
+ }
+
+ /* check whether initialized */
+ if (led_timer[config->led].is_init)
+ {
+ WICED_BT_TRACE("Error: Init LED(%d) multiple times\n", config->led);
+ return WICED_ERROR;
+ }
+
+ bright = config->bright;
+
+ if (bright > 99)
+ {
+ bright = 99;
+ }
+
+ if (WICED_SUCCESS != platform_led_init(&platform_led_config[config->led], LED_FREQ, bright))
+ return WICED_ERROR;
+
+ led_timer[config->led].led = config->led;
+
+ /* initialize timer */
+ wiced_init_timer(&led_timer[config->led].timer, &led_timer_function, (uint32_t) config->led,
+ WICED_MILLI_SECONDS_PERIODIC_TIMER);
+
+ led_timer[config->led].is_init = WICED_TRUE;
+
+ return WICED_SUCCESS;
+}
+
+/**
+ * Function to de-initialize the LED Manager
+ *
+ * @param void : No arguments.
+ * @return : result.
+ */
+wiced_result_t wiced_led_manager_deinit()
+{
+ uint32_t i;
+ /*if any led active we stop all of them*/
+ for (i = 0; i < PLATFORM_LED_MAX; i++)
+ platform_led_deinit(&platform_led_config[i]);
+
+ /* deinit timer */
+ for (i = 0; i < PLATFORM_LED_MAX; i++)
+ {
+ if (led_timer[i].is_init)
+ {
+ wiced_deinit_timer(&led_timer[i].timer);
+ led_timer[i].is_init = WICED_FALSE;
+ }
+ }
+
+ return WICED_SUCCESS;
+}
+
+/**
+ * Enables the selected LED
+ *
+ * @param led : LED to be enabled.
+ * @return : result.
+ */
+wiced_result_t wiced_led_manager_enable_led(wiced_led_t led)
+{
+ wiced_result_t result;
+ if (led >= PLATFORM_LED_MAX)
+ {
+ WICED_BT_TRACE("Invalid LED for platform\n");
+ return WICED_ERROR;
+ }
+
+ result = platform_led_start(&platform_led_config[led]);
+
+ return result;
+}
+
+/**
+ * Disables the selected LED
+ *
+ * @param led : LED to be disabled.
+ * @return : result.
+ */
+wiced_result_t wiced_led_manager_disable_led(wiced_led_t led)
+{
+ wiced_result_t result;
+ if (led >= PLATFORM_LED_MAX)
+ {
+ WICED_BT_TRACE("Invalid LED for platform\n");
+ return WICED_ERROR;
+ }
+ if (wiced_is_timer_in_use(&led_timer[led].timer))
+ {
+ wiced_stop_timer(&led_timer[led].timer);
+ // wiced_deinit_timer(&led_timer[led].timer);
+ }
+
+ result = platform_led_stop(&platform_led_config[led]);
+
+ return result;
+}
+
+/**
+ * Reconfigures the LED
+ *
+ * @param config : Configuration for the LED.
+ * @return : result.
+ */
+wiced_result_t wiced_led_manager_reconfig_led(wiced_led_config_t * config)
+{
+ uint16_t bright;
+
+ if (config == NULL)
+ return WICED_ERROR;
+
+ if (config->led >= PLATFORM_LED_MAX)
+ {
+ WICED_BT_TRACE("Invalid LED for platform\n");
+ return WICED_ERROR;
+ }
+
+ bright = config->bright;
+
+ if (bright > 99)
+ {
+ bright = 99;
+ }
+
+ return platform_led_reinit(&platform_led_config[config->led], LED_FREQ, bright);
+}
+
+/**
+ * LED timer handler
+ *
+ * @param arg : arguments passed to the handler.
+ * @return : no return value expected.
+ */
+void led_timer_function(uint32_t arg)
+{
+ if (led_timer[arg].led_state == WICED_TRUE)
+ {
+ // WICED_BT_TRACE("Timer led %d stop\n",led_timer[arg].led);
+ platform_led_stop(&platform_led_config[led_timer[arg].led]);
+ led_timer[arg].led_state = WICED_FALSE;
+ }
+ else
+ {
+ platform_led_start(&platform_led_config[led_timer[arg].led]);
+ // WICED_BT_TRACE("Timer led %d start\n",led_timer[arg].led);
+ led_timer[arg].led_state = WICED_TRUE;
+ }
+
+ wiced_stop_timer(&led_timer[arg].timer);
+ wiced_start_timer(&led_timer[arg].timer,
+ led_timer[arg].led_state == WICED_TRUE ? led_timer[arg].on_period : led_timer[arg].off_period);
+}
+
+/**
+ * Function called to blink a LED
+ *
+ * @param led : LED to be blinked.
+ * @param on_period : on period (ms)
+ * @param off_period : off period (ms)
+ * @return : result.
+ */
+
+wiced_result_t wiced_led_manager_blink_led(wiced_led_t led, uint32_t on_period, uint32_t off_period)
+{
+ // WICED_BT_TRACE("%s <<\n",__func__);
+ if (led >= PLATFORM_LED_MAX)
+ {
+ WICED_BT_TRACE("Invalid LED for platform\n");
+ return WICED_ERROR;
+ }
+
+ if (led_timer[led].is_init == WICED_FALSE)
+ {
+ WICED_BT_TRACE("LED(%d) un-init\n", led);
+ return WICED_ERROR;
+ }
+
+ led_timer[led].on_period = on_period;
+ led_timer[led].off_period = off_period;
+
+ if (WICED_SUCCESS != wiced_led_manager_enable_led(led))
+ {
+ WICED_BT_TRACE("LED enable failed\n");
+ return WICED_ERROR;
+ }
+
+ led_timer[led].led_state = WICED_TRUE;
+ wiced_start_timer(&led_timer[led].timer, on_period);
+ // WICED_BT_TRACE("timer started\n");
+
+ return WICED_SUCCESS;
+}
diff --git a/src/platform/device.gni b/src/platform/device.gni
index ff9ce0b..87b4c05 100755
--- a/src/platform/device.gni
+++ b/src/platform/device.gni
@@ -16,7 +16,7 @@
import("${chip_root}/src/ble/ble.gni")
declare_args() {
- # Device platform layer: cc13x2_26x2, darwin, efr32, esp32, external, freertos, linux, nrfconnect, k32w0, qpg, tizen, none.
+ # Device platform layer: cc13x2_26x2, darwin, efr32, esp32, external, freertos, linux, nrfconnect, k32w0, qpg, tizen, cyw30739, none.
chip_device_platform = "auto"
chip_platform_target = ""
@@ -114,6 +114,8 @@
_chip_device_layer = "android"
} else if (chip_device_platform == "ameba") {
_chip_device_layer = "Ameba"
+} else if (chip_device_platform == "cyw30739") {
+ _chip_device_layer = "CYW30739"
}
if (chip_device_platform != "external") {
@@ -156,5 +158,5 @@
chip_device_platform == "k32w0" || chip_device_platform == "qpg" ||
chip_device_platform == "telink" || chip_device_platform == "mbed" ||
chip_device_platform == "p6" || chip_device_platform == "android" ||
- chip_device_platform == "ameba",
+ chip_device_platform == "ameba" || chip_device_platform == "cyw30739",
"Please select a valid value for chip_device_platform")
diff --git a/third_party/cyw30739_sdk/BUILD.gn b/third_party/cyw30739_sdk/BUILD.gn
new file mode 100644
index 0000000..288d013
--- /dev/null
+++ b/third_party/cyw30739_sdk/BUILD.gn
@@ -0,0 +1,45 @@
+# 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.
+
+import("//build_overrides/chip.gni")
+import("//build_overrides/mbedtls.gni")
+import("//build_overrides/openthread.gni")
+
+import("${mbedtls_root}/mbedtls.gni")
+
+declare_args() {
+ # Build target to use for CYW30739 SDK. Use this to set global SDK defines.
+ cyw30739_sdk_target = ""
+}
+
+assert(cyw30739_sdk_target != "", "cyw30739_sdk_target must be specified")
+
+group("cyw30739_sdk") {
+ public_deps = [ cyw30739_sdk_target ]
+}
+
+config("mbedtls_cyw30739_config") {
+ defines = [
+ "MBEDTLS_CONFIG_FILE=<third_party/openthread/repo/third_party/mbedtls/mbedtls-config.h>",
+ "MBEDTLS_USER_CONFIG_FILE=<src/platform/CYW30739/cyw30739-chip-mbedtls-config.h>",
+ ]
+
+ include_dirs = [ chip_root ]
+}
+
+mbedtls_target("mbedtls") {
+ public_configs = [ ":mbedtls_cyw30739_config" ]
+
+ public_deps = [ "${openthread_root}/src/core:libopenthread_core_headers" ]
+}
diff --git a/third_party/cyw30739_sdk/bsp_design_modus/cycfg_notices.h b/third_party/cyw30739_sdk/bsp_design_modus/cycfg_notices.h
new file mode 100644
index 0000000..3d64d12
--- /dev/null
+++ b/third_party/cyw30739_sdk/bsp_design_modus/cycfg_notices.h
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * File Name: cycfg_notices.h
+ *
+ * Description:
+ * Contains warnings and errors that occurred while generating code for the
+ * design.
+ * This file was automatically generated and should not be modified.
+ * Tools Package 2.4.0.5880
+ * 20739B2 CSP
+ * personalities 1.0.0.31
+ * udd 3.0.0.1454
+ *
+ ********************************************************************************
+ * Copyright 2021 Cypress Semiconductor Corporation (an Infineon company) or
+ * an affiliate of Cypress Semiconductor Corporation.
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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.
+ ********************************************************************************/
+
+#if !defined(CYCFG_NOTICES_H)
+#define CYCFG_NOTICES_H
+
+#ifdef CY_SUPPORTS_DEVICE_VALIDATION
+#ifndef LBCA1KU1WA
+#error \
+ "Unexpected target MCU; expected LBCA1KU1WA. There may be an inconsistency between the *.modus file and the makefile target configuration device sets."
+#endif
+#endif
+
+#endif /* CYCFG_NOTICES_H */
diff --git a/third_party/cyw30739_sdk/bsp_design_modus/cycfg_pins.c b/third_party/cyw30739_sdk/bsp_design_modus/cycfg_pins.c
new file mode 100644
index 0000000..0742299
--- /dev/null
+++ b/third_party/cyw30739_sdk/bsp_design_modus/cycfg_pins.c
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * File Name: cycfg_pins.c
+ *
+ * Description:
+ * Pin configuration
+ * This file was automatically generated and should not be modified.
+ * Tools Package 2.4.0.5880
+ * 20739B2 CSP
+ * personalities 1.0.0.31
+ * udd 3.0.0.1454
+ *
+ ********************************************************************************
+ * Copyright 2021 Cypress Semiconductor Corporation (an Infineon company) or
+ * an affiliate of Cypress Semiconductor Corporation.
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 "cycfg_pins.h"
+
+#define BUTTON_USER_config \
+ { \
+ .gpio = (wiced_bt_gpio_numbers_t *) &platform_gpio_pins[PLATFORM_GPIO_0].gpio_pin, \
+ .config = GPIO_INPUT_ENABLE | GPIO_PULL_UP, .default_state = GPIO_PIN_OUTPUT_HIGH, \
+ .button_pressed_value = GPIO_PIN_OUTPUT_LOW, \
+ }
+#define GPIO2_config \
+ { \
+ .gpio = (wiced_bt_gpio_numbers_t *) &platform_gpio_pins[PLATFORM_GPIO_5].gpio_pin, \
+ .config = GPIO_OUTPUT_ENABLE | GPIO_INPUT_DISABLE, .default_state = GPIO_PIN_OUTPUT_LOW, \
+ }
+#define RX_PU_config \
+ { \
+ .gpio = (wiced_bt_gpio_numbers_t *) &platform_gpio_pins[PLATFORM_GPIO_6].gpio_pin, \
+ .config = GPIO_OUTPUT_ENABLE | GPIO_INPUT_DISABLE, .default_state = GPIO_PIN_OUTPUT_LOW, \
+ }
+#define GPIO3_config \
+ { \
+ .gpio = (wiced_bt_gpio_numbers_t *) &platform_gpio_pins[PLATFORM_GPIO_7].gpio_pin, \
+ .config = GPIO_INPUT_ENABLE | GPIO_PULL_UP_DOWN_NONE, .default_state = GPIO_PIN_OUTPUT_LOW, \
+ }
+#define TX_PU_config \
+ { \
+ .gpio = (wiced_bt_gpio_numbers_t *) &platform_gpio_pins[PLATFORM_GPIO_8].gpio_pin, \
+ .config = GPIO_OUTPUT_ENABLE | GPIO_INPUT_DISABLE, .default_state = GPIO_PIN_OUTPUT_HIGH, \
+ }
+#define GPIO4_config \
+ { \
+ .gpio = (wiced_bt_gpio_numbers_t *) &platform_gpio_pins[PLATFORM_GPIO_9].gpio_pin, \
+ .config = GPIO_INPUT_ENABLE | GPIO_PULL_UP_DOWN_NONE, .default_state = GPIO_PIN_OUTPUT_LOW, \
+ }
+#define GPIO5_config \
+ { \
+ .gpio = (wiced_bt_gpio_numbers_t *) &platform_gpio_pins[PLATFORM_GPIO_10].gpio_pin, \
+ .config = GPIO_INPUT_ENABLE | GPIO_PULL_UP_DOWN_NONE, .default_state = GPIO_PIN_OUTPUT_LOW, \
+ }
+#define DEBUG_UART_TXD_config \
+ { \
+ .gpio = (wiced_bt_gpio_numbers_t *) &platform_gpio_pins[PLATFORM_GPIO_12].gpio_pin, \
+ .config = GPIO_INPUT_ENABLE | GPIO_PULL_UP_DOWN_NONE, .default_state = GPIO_PIN_OUTPUT_LOW, \
+ }
+#define LED1_config \
+ { \
+ .gpio = (wiced_bt_gpio_numbers_t *) &platform_gpio_pins[PLATFORM_GPIO_13].gpio_pin, \
+ .config = GPIO_OUTPUT_ENABLE | GPIO_PULL_UP, .default_state = GPIO_PIN_OUTPUT_HIGH, \
+ }
+#define LED2_config \
+ { \
+ .gpio = (wiced_bt_gpio_numbers_t *) &platform_gpio_pins[PLATFORM_GPIO_14].gpio_pin, \
+ .config = GPIO_OUTPUT_ENABLE | GPIO_PULL_UP, .default_state = GPIO_PIN_OUTPUT_HIGH, \
+ }
+#define GPIO1_config \
+ { \
+ .gpio = (wiced_bt_gpio_numbers_t *) &platform_gpio_pins[PLATFORM_GPIO_3].gpio_pin, \
+ .config = GPIO_INPUT_ENABLE | GPIO_PULL_UP_DOWN_NONE, .default_state = GPIO_PIN_OUTPUT_LOW, \
+ }
+
+const wiced_platform_gpio_t platform_gpio_pins[] = {
+ [PLATFORM_GPIO_0] = { WICED_P00, WICED_GPIO },
+ [PLATFORM_GPIO_1] = { WICED_P04, pwm_0_pwm_0_TRIGGER_IN },
+ [PLATFORM_GPIO_2] = { WICED_P06, uart_1_rxd_0_TRIGGER_IN },
+ [PLATFORM_GPIO_3] = { WICED_P07, WICED_GPIO },
+ [PLATFORM_GPIO_4] = { WICED_P10, uart_1_txd_0_TRIGGER_IN },
+ [PLATFORM_GPIO_5] = { WICED_P16, WICED_GPIO },
+ [PLATFORM_GPIO_6] = { WICED_P17, WICED_GPIO },
+ [PLATFORM_GPIO_7] = { WICED_P25, WICED_GPIO },
+ [PLATFORM_GPIO_8] = { WICED_P26, WICED_GPIO },
+ [PLATFORM_GPIO_9] = { WICED_P28, WICED_GPIO },
+ [PLATFORM_GPIO_10] = { WICED_P29, WICED_GPIO },
+ [PLATFORM_GPIO_11] = { WICED_P30, WICED_GPIO },
+ [PLATFORM_GPIO_12] = { WICED_P33, WICED_GPIO },
+ [PLATFORM_GPIO_13] = { WICED_P34, WICED_GPIO },
+ [PLATFORM_GPIO_14] = { WICED_P38, WICED_GPIO },
+};
+const size_t platform_gpio_pin_count = (sizeof(platform_gpio_pins) / sizeof(wiced_platform_gpio_t));
+const wiced_platform_led_config_t platform_led[] = {
+ [WICED_PLATFORM_LED_1] = LED1_config,
+ [WICED_PLATFORM_LED_2] = LED2_config,
+};
+const size_t led_count = (sizeof(platform_led) / sizeof(wiced_platform_led_config_t));
+const wiced_platform_button_config_t platform_button[] = {
+ [WICED_PLATFORM_BUTTON_1] = BUTTON_USER_config,
+};
+const size_t button_count = (sizeof(platform_button) / sizeof(wiced_platform_button_config_t));
+const wiced_platform_gpio_config_t platform_gpio[] = {
+ [WICED_PLATFORM_GPIO_1] = GPIO1_config, [WICED_PLATFORM_GPIO_2] = GPIO2_config, [WICED_PLATFORM_GPIO_7] = RX_PU_config,
+ [WICED_PLATFORM_GPIO_3] = GPIO3_config, [WICED_PLATFORM_GPIO_6] = TX_PU_config, [WICED_PLATFORM_GPIO_4] = GPIO4_config,
+ [WICED_PLATFORM_GPIO_5] = GPIO5_config, [WICED_PLATFORM_GPIO_8] = DEBUG_UART_TXD_config,
+};
+const size_t gpio_count = (sizeof(platform_gpio) / sizeof(wiced_platform_gpio_config_t));
diff --git a/third_party/cyw30739_sdk/bsp_design_modus/cycfg_pins.h b/third_party/cyw30739_sdk/bsp_design_modus/cycfg_pins.h
new file mode 100644
index 0000000..de4b9f3
--- /dev/null
+++ b/third_party/cyw30739_sdk/bsp_design_modus/cycfg_pins.h
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * File Name: cycfg_pins.h
+ *
+ * Description:
+ * Pin configuration
+ * This file was automatically generated and should not be modified.
+ * Tools Package 2.4.0.5880
+ * 20739B2 CSP
+ * personalities 1.0.0.31
+ * udd 3.0.0.1454
+ *
+ ********************************************************************************
+ * Copyright 2021 Cypress Semiconductor Corporation (an Infineon company) or
+ * an affiliate of Cypress Semiconductor Corporation.
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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.
+ ********************************************************************************/
+
+#if !defined(CYCFG_PINS_H)
+#define CYCFG_PINS_H
+
+#include "cycfg_notices.h"
+#include "cycfg_routing.h"
+#include "wiced_platform.h"
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#define bluetooth_0_ENABLED 1U
+#define ioss_0_ENABLED 1U
+#define WICED_GET_PIN_FOR_LED(idx) (*(platform_led[(idx)].gpio))
+#define WICED_GET_PIN_FOR_BUTTON(idx) (*(platform_button[(idx)].gpio))
+#define WICED_GET_PIN_FOR_IO(idx) (*(platform_gpio[(idx)].gpio))
+#define BUTTON_USER_ENABLED 1U
+#define BUTTON_USER WICED_P00
+#define PUART_TXD_ENABLED 1U
+#define PUART_TXD WICED_P10
+#define GPIO2_ENABLED 1U
+#define GPIO2 WICED_P16
+#define RX_PU_ENABLED 1U
+#define RX_PU WICED_P17
+#define GPIO3_ENABLED 1U
+#define GPIO3 WICED_P25
+#define TX_PU_ENABLED 1U
+#define TX_PU WICED_P26
+#define GPIO4_ENABLED 1U
+#define GPIO4 WICED_P28
+#define GPIO5_ENABLED 1U
+#define GPIO5 WICED_P29
+#define ioss_0_pin_30_ENABLED 1U
+#define ioss_0_pin_30 WICED_P30
+#define DEBUG_UART_TXD_ENABLED 1U
+#define DEBUG_UART_TXD WICED_P33
+#define LED1_ENABLED 1U
+#define LED1 WICED_P34
+#define LED2_ENABLED 1U
+#define LED2 WICED_P38
+#define PWM0_ENABLED 1U
+#define PWM0 WICED_P04
+#define PUART_RXD_ENABLED 1U
+#define PUART_RXD WICED_P06
+#define GPIO1_ENABLED 1U
+#define GPIO1 WICED_P07
+#define pwm_0_ENABLED 1U
+#define uart_1_ENABLED 1U
+
+extern const wiced_platform_gpio_t platform_gpio_pins[];
+extern const size_t platform_gpio_pin_count;
+extern const wiced_platform_led_config_t platform_led[];
+extern const size_t led_count;
+extern const wiced_platform_button_config_t platform_button[];
+extern const size_t button_count;
+extern const wiced_platform_gpio_config_t platform_gpio[];
+extern const size_t gpio_count;
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* CYCFG_PINS_H */
diff --git a/third_party/cyw30739_sdk/bsp_design_modus/cycfg_routing.h b/third_party/cyw30739_sdk/bsp_design_modus/cycfg_routing.h
new file mode 100644
index 0000000..47e1e82
--- /dev/null
+++ b/third_party/cyw30739_sdk/bsp_design_modus/cycfg_routing.h
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * File Name: cycfg_routing.h
+ *
+ * Description:
+ * Establishes all necessary connections between hardware elements.
+ * This file was automatically generated and should not be modified.
+ * Tools Package 2.4.0.5880
+ * 20739B2 CSP
+ * personalities 1.0.0.31
+ * udd 3.0.0.1454
+ *
+ ********************************************************************************
+ * Copyright 2021 Cypress Semiconductor Corporation (an Infineon company) or
+ * an affiliate of Cypress Semiconductor Corporation.
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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.
+ ********************************************************************************/
+
+#if !defined(CYCFG_ROUTING_H)
+#define CYCFG_ROUTING_H
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#include "cycfg_notices.h"
+static inline void init_cycfg_routing(void) {}
+#define init_cycfg_connectivity() init_cycfg_routing()
+#define ioss_0_pin_4_AUX UNKNOWN
+#define ioss_0_pin_6_AUX UNKNOWN
+#define ioss_0_pin_10_AUX UNKNOWN
+
+#define pwm_0_pwm_0_TRIGGER_IN WICED_PWM0
+#define uart_1_rxd_0_TRIGGER_IN WICED_UART_2_RXD
+#define uart_1_txd_0_TRIGGER_IN WICED_UART_2_TXD
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* CYCFG_ROUTING_H */
diff --git a/third_party/cyw30739_sdk/btp_reader.py b/third_party/cyw30739_sdk/btp_reader.py
new file mode 100644
index 0000000..4a1de71
--- /dev/null
+++ b/third_party/cyw30739_sdk/btp_reader.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+
+import json
+import sys
+
+
+def main():
+ btp_file = sys.argv[1]
+
+ items = {}
+ with open(btp_file) as btp:
+ for line in btp:
+ item = line.strip().split("=")
+ if len(item) == 2:
+ key = item[0].strip()
+ value = item[1].strip()
+ items[key] = value
+
+ items["XIP_DS_OFFSET"] = "0x0001e000"
+ items["XIP_LEN"] = "0x{:08x}".format(
+ int(items["ConfigDS2Location"], 16)
+ - int(items["ConfigDSLocation"], 16)
+ - int(items["XIP_DS_OFFSET"], 16)
+ )
+
+ print(json.dumps(items))
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/third_party/cyw30739_sdk/cyw30739_arm.gni b/third_party/cyw30739_sdk/cyw30739_arm.gni
new file mode 100644
index 0000000..44b76f7
--- /dev/null
+++ b/third_party/cyw30739_sdk/cyw30739_arm.gni
@@ -0,0 +1,17 @@
+# 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.
+
+arm_cpu = "cortex-m4"
+arm_float_abi = "hard"
+arm_fpu = "fpv4-sp-d16"
diff --git a/third_party/cyw30739_sdk/cyw30739_executable.gni b/third_party/cyw30739_sdk/cyw30739_executable.gni
new file mode 100644
index 0000000..ca2e92f
--- /dev/null
+++ b/third_party/cyw30739_sdk/cyw30739_executable.gni
@@ -0,0 +1,81 @@
+# 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.
+
+import("//build_overrides/build.gni")
+import("//build_overrides/chip.gni")
+import("//build_overrides/cyw30739_sdk.gni")
+
+import("${build_root}/toolchain/flashable_executable.gni")
+import("${cyw30739_sdk_build_root}/cyw30739_sdk.gni")
+
+template("cyw30739_executable") {
+ if (!defined(invoker.output_dir)) {
+ invoker.output_dir = root_out_dir
+ }
+
+ output_base_name = get_path_info(invoker.output_name, "name")
+ ldscript_file = "${root_build_dir}/${output_base_name}.ld"
+ flashable_target = "${target_name}.flashable"
+
+ cyw30739_sdk_pre_build("${target_name}.pre_build") {
+ }
+
+ cyw30739_sdk_post_build("${target_name}.post_build") {
+ executable_target = ":${flashable_target}.executable"
+ }
+
+ group(target_name) {
+ deps = [
+ ":${flashable_target}",
+ ":${target_name}.post_build",
+ ]
+ }
+
+ # Copy flashing dependencies to the output directory so that the output
+ # is collectively self-contained; this allows flashing to work reliably
+ # even if the build and flashing steps take place on different machines
+ # or in different containers.
+
+ flashing_runtime_target = target_name + ".flashing_runtime"
+ flashing_script_inputs = [
+ "${chip_root}/scripts/flashing/cyw30739_firmware_utils.py",
+ "${chip_root}/scripts/flashing/firmware_utils.py",
+ ]
+ copy(flashing_runtime_target) {
+ sources = flashing_script_inputs
+ outputs = [ "${root_out_dir}/{{source_file_part}}" ]
+ }
+
+ flashing_script_generator =
+ "${chip_root}/scripts/flashing/gen_flashing_script.py"
+ flashing_script_name = output_base_name + ".flash.py"
+ flashing_options = [
+ "cyw30739",
+ "--sdk-scripts-dir",
+ rebase_path(invoker.cyw30739_sdk_scripts_dir),
+ "--sdk-tools-dir",
+ rebase_path(invoker.cyw30739_sdk_tools_dir),
+ ]
+
+ flashable_executable(flashable_target) {
+ forward_variables_from(invoker, "*")
+ data_deps = [ ":${flashing_runtime_target}" ]
+
+ deps += [ ":${target_name}.pre_build" ]
+
+ inputs = [ ldscript_file ]
+
+ ldflags = [ "-T" + rebase_path(ldscript_file, root_build_dir) ]
+ }
+}
diff --git a/third_party/cyw30739_sdk/cyw30739_sdk.gni b/third_party/cyw30739_sdk/cyw30739_sdk.gni
new file mode 100644
index 0000000..c041b95
--- /dev/null
+++ b/third_party/cyw30739_sdk/cyw30739_sdk.gni
@@ -0,0 +1,281 @@
+# 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.
+
+import("//build_overrides/build.gni")
+import("//build_overrides/cyw30739_sdk.gni")
+
+declare_args() {
+ # Location of the CYW30739 SDK.
+ cyw30739_sdk_root = "${cyw30739_sdk_build_root}/repos"
+ cyw30739_sdk_verbose = false
+}
+
+assert(cyw30739_sdk_root != "", "cyw30739_sdk_root must be specified")
+
+cyw30739_sdk_bsp_design_modus_dir =
+ "${cyw30739_sdk_build_root}/bsp_design_modus"
+cyw30739_sdk_baselib_dir = "${cyw30739_sdk_root}/30739A0/COMPONENT_30739A0"
+cyw30739_sdk_board_dir = "${cyw30739_sdk_root}/CYW930739M2EVB-01"
+cyw30739_sdk_include_dir = "${cyw30739_sdk_root}/btsdk-include"
+cyw30739_sdk_patch_dir =
+ "${cyw30739_sdk_baselib_dir}/internal/30739A0/patches_CYW930739M2EVB_01"
+cyw30739_sdk_platform_dir = "${cyw30739_sdk_baselib_dir}/platforms"
+cyw30739_sdk_scripts_dir = "${cyw30739_sdk_baselib_dir}/make/scripts"
+cyw30739_sdk_btp_file = "${cyw30739_sdk_platform_dir}/flash.btp"
+cyw30739_sdk_patch_sym_file = "${cyw30739_sdk_patch_dir}/patch.sym"
+
+cyw30739_sdk_tools_dir = "${cyw30739_sdk_root}/btsdk-tools/"
+if (host_os == "linux") {
+ cyw30739_sdk_tools_dir += "Linux64"
+} else if (host_os == "mac") {
+ cyw30739_sdk_tools_dir += "OSX"
+} else if (host_os == "win") {
+ cyw30739_sdk_tools_dir += "Windows"
+}
+
+template("cyw30739_sdk_script") {
+ action(target_name) {
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "script_file_name",
+ "sources",
+ "outputs",
+ ])
+
+ script_file = "${cyw30739_sdk_scripts_dir}/${script_file_name}"
+
+ script = "${build_root}/gn_run_binary.py"
+
+ inputs = [ script_file ]
+
+ args = [
+ "bash",
+ "--norc",
+ "--noprofile",
+ rebase_path(script_file, root_build_dir),
+ "--scripts=" + rebase_path(cyw30739_sdk_scripts_dir, root_build_dir),
+ ]
+ if (defined(invoker.args)) {
+ args += invoker.args
+ }
+ if (cyw30739_sdk_verbose) {
+ args += [ "--verbose" ]
+ }
+ }
+}
+
+# Defines a CYW30739 SDK build target.
+#
+# Parameters:
+# cyw30739_sdk_root - The location of the erf32 SDK.
+# sources - The sources files to build.
+template("cyw30739_sdk") {
+ if (defined(invoker.cyw30739_sdk_root)) {
+ cyw30739_sdk_root = invoker.cyw30739_sdk_root
+ }
+
+ assert(cyw30739_sdk_root != "", "cyw30739_sdk_root must be specified")
+
+ config("${target_name}_config") {
+ include_dirs = []
+ defines = []
+ libs = []
+
+ if (is_debug) {
+ enable_debug = 1
+ } else {
+ enable_debug = 0
+ }
+
+ if (defined(invoker.include_dirs)) {
+ include_dirs += invoker.include_dirs
+ }
+
+ if (defined(invoker.defines)) {
+ defines += invoker.defines
+ }
+
+ include_dirs += [
+ "${cyw30739_sdk_baselib_dir}/WICED/common",
+ "${cyw30739_sdk_baselib_dir}/include",
+ "${cyw30739_sdk_baselib_dir}/include/hal",
+ "${cyw30739_sdk_baselib_dir}/include/internal",
+ "${cyw30739_sdk_baselib_dir}/include/stack",
+ "${cyw30739_sdk_baselib_dir}/platforms",
+ "${cyw30739_sdk_board_dir}",
+ "${cyw30739_sdk_build_root}/include",
+ "${cyw30739_sdk_include_dir}",
+ ]
+
+ defines += [
+ "CHIP_HAVE_CONFIG_H=1",
+ "CY_PLATFORM_SWDCK=WICED_P05",
+ "CY_PLATFORM_SWDIO=WICED_P03",
+ "ENABLE_DEBUG=${enable_debug}",
+ "SPAR_CRT_SETUP=spar_crt_setup",
+ ]
+
+ cflags = [ "--specs=nano.specs" ]
+ if (is_debug) {
+ cflags += [ "-Wno-unused" ]
+ }
+
+ ldflags = [
+ "--specs=nano.specs",
+ "-Wl,--entry=spar_crt_setup",
+ "-Wl,--just-symbols=" +
+ rebase_path(cyw30739_sdk_patch_sym_file, root_build_dir),
+ "-nostartfiles",
+ ]
+ }
+
+ cyw30739_sdk_script("${target_name}_gen_lib_installer") {
+ script_file_name = "bt_gen_lib_installer.bash"
+
+ lib_installer_file = "${root_gen_dir}/lib_installer.c"
+
+ args = [ "--out=" + rebase_path(lib_installer_file, root_build_dir) ]
+
+ outputs = [ lib_installer_file ]
+ }
+
+ source_set(target_name) {
+ sources = [
+ "${cyw30739_sdk_baselib_dir}/WICED/common/spar_setup.c",
+ "${cyw30739_sdk_baselib_dir}/platforms/platform_entropy.c",
+ "${cyw30739_sdk_baselib_dir}/platforms/platform_nvram.h",
+ "${cyw30739_sdk_baselib_dir}/platforms/platform_retarget_lock.h",
+ "${cyw30739_sdk_baselib_dir}/platforms/platform_stdio.c",
+ "${cyw30739_sdk_baselib_dir}/platforms/wiced_platform.c",
+ "${cyw30739_sdk_baselib_dir}/platforms/wiced_platform_bt_cfg.c",
+ "${cyw30739_sdk_baselib_dir}/platforms/wiced_platform_bt_cfg.h",
+ "${cyw30739_sdk_baselib_dir}/platforms/wiced_platform_memory.c",
+ "${cyw30739_sdk_baselib_dir}/platforms/wiced_platform_os.c",
+ "${cyw30739_sdk_board_dir}/gpio_button.c",
+ "${cyw30739_sdk_board_dir}/gpio_button.h",
+ "${cyw30739_sdk_board_dir}/platform.c",
+ "${cyw30739_sdk_board_dir}/platform_button.c",
+ "${cyw30739_sdk_board_dir}/wiced_platform.h",
+ "${cyw30739_sdk_board_dir}/wiced_platform_memory.h",
+ "${cyw30739_sdk_board_dir}/wiced_platform_os.h",
+ "${cyw30739_sdk_bsp_design_modus_dir}/cycfg_notices.h",
+ "${cyw30739_sdk_bsp_design_modus_dir}/cycfg_pins.c",
+ "${cyw30739_sdk_bsp_design_modus_dir}/cycfg_pins.h",
+ "${cyw30739_sdk_bsp_design_modus_dir}/cycfg_routing.h",
+ "${cyw30739_sdk_build_root}/src/platform_retarget_lock.c",
+ ]
+
+ sources += get_target_outputs(":${target_name}_gen_lib_installer")
+
+ if (defined(invoker.sources)) {
+ sources += invoker.sources
+ }
+
+ public_configs = [ ":${target_name}_config" ]
+
+ deps = [ ":${target_name}_gen_lib_installer" ]
+ }
+}
+
+template("cyw30739_sdk_pre_build") {
+ cyw30739_sdk_script(target_name) {
+ script_file_name = "bt_pre_build.bash"
+
+ btp = exec_script("${cyw30739_sdk_build_root}/btp_reader.py",
+ [ rebase_path(cyw30739_sdk_btp_file, root_build_dir) ],
+ "json")
+
+ linker_defines = [
+ "FLASH0_BEGIN_ADDR=" + btp.DLConfigSSLocation,
+ "FLASH0_LENGTH=0x00100000",
+ "XIP_DS_OFFSET=" + btp.XIP_DS_OFFSET,
+ "XIP_LEN=" + btp.XIP_LEN,
+ "SRAM_BEGIN_ADDR=0x00200000",
+ "SRAM_LENGTH=0x00070000",
+ "AON_AREA_END=0x00284000",
+ "ISTATIC_BEGIN=0x500C00",
+ "ISTATIC_LEN=0x400",
+ "NUM_PATCH_ENTRIES=256",
+ "BTP=" + rebase_path(cyw30739_sdk_btp_file, root_build_dir),
+ ]
+
+ args = [
+ "--defs=" + string_join(" ", linker_defines),
+ "--ld=" + rebase_path(invoker.ldscript_file, root_build_dir),
+ "--patch=" + rebase_path(cyw30739_sdk_patch_sym_file, root_build_dir),
+ ]
+
+ sources = [ cyw30739_sdk_btp_file ]
+
+ outputs = [ invoker.ldscript_file ]
+ }
+}
+
+template("cyw30739_sdk_post_build") {
+ copy("${target_name}_static_config") {
+ sources = [ "static_config.txt" ]
+ outputs = [ "${root_out_dir}/{{source_file_part}}" ]
+ }
+
+ cyw30739_sdk_script(target_name) {
+ script_file_name = "bt_post_build.bash"
+
+ cgs_list = [
+ "${cyw30739_sdk_patch_dir}/patch.cgs",
+ "${cyw30739_sdk_platform_dir}/platform.cgs",
+ "${cyw30739_sdk_platform_dir}/platform_xip.cgs",
+ ]
+
+ args = [
+ "--cross=arm-none-eabi-",
+ "--tools=" + rebase_path(cyw30739_sdk_tools_dir, root_build_dir),
+ "--builddir=" + rebase_path(root_out_dir, root_build_dir),
+ "--elfname=${invoker.output_base_name}.elf",
+ "--appname=${invoker.output_base_name}",
+ "--appver=0x00000000",
+ "--hdf=" + rebase_path(
+ "${cyw30739_sdk_baselib_dir}/internal/30739A0/configdef30739A0.hdf",
+ root_build_dir),
+ "--entry=spar_crt_setup.entry",
+ "--cgslist=" + string_join(" ", rebase_path(cgs_list, root_build_dir)),
+ "--cgsargs=-O DLConfigBD_ADDRBase:default",
+ "--btp=" + rebase_path(cyw30739_sdk_btp_file, root_build_dir),
+ "--id=" + rebase_path("${cyw30739_sdk_platform_dir}/IDFILE.txt",
+ root_build_dir),
+ "--overridebaudfile=" +
+ rebase_path("${cyw30739_sdk_platform_dir}/BAUDRATEFILE.txt",
+ root_build_dir),
+ "--chip=30739A0",
+ "--minidriver=" +
+ rebase_path("${cyw30739_sdk_platform_dir}/minidriver.hex",
+ root_build_dir),
+ "--clflags=-NOHCIRESET",
+ "--extras=static_config_XIP_",
+ ]
+
+ sources = [
+ "${root_out_dir}/static_config.txt",
+ cyw30739_sdk_btp_file,
+ ]
+ sources += cgs_list
+
+ outputs = [ "${root_out_dir}/${invoker.output_base_name}_download.hex" ]
+
+ deps = [
+ ":${target_name}_static_config",
+ invoker.executable_target,
+ ]
+ }
+}
diff --git a/third_party/cyw30739_sdk/include/auto_flags.h b/third_party/cyw30739_sdk/include/auto_flags.h
new file mode 100644
index 0000000..6e09909
--- /dev/null
+++ b/third_party/cyw30739_sdk/include/auto_flags.h
@@ -0,0 +1,7 @@
+#pragma once
+
+#define ALWAYS_ON_MEMORY_SUPPORT 1
+#define CPU_CM4 1
+#define DYNAMIC_MEMORY_NUM_POOLS 4
+#define MICRO_BCS 1
+#define TOOLCHAIN_wiced 1
diff --git a/third_party/cyw30739_sdk/include/wiced_button_manager.h b/third_party/cyw30739_sdk/include/wiced_button_manager.h
new file mode 100644
index 0000000..6162dc9
--- /dev/null
+++ b/third_party/cyw30739_sdk/include/wiced_button_manager.h
@@ -0,0 +1,234 @@
+/*
+ * Copyright 2016-2021, Cypress Semiconductor Corporation (an Infineon company) or
+ * an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+ *
+ * This software, including source code, documentation and related
+ * materials ("Software") is owned by Cypress Semiconductor Corporation
+ * or one of its affiliates ("Cypress") and is protected by and subject to
+ * worldwide patent protection (United States and foreign),
+ * United States copyright laws and international treaty provisions.
+ * Therefore, you may use this Software only as provided in the license
+ * agreement accompanying the software package from which you
+ * obtained this Software ("EULA").
+ * If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
+ * non-transferable license to copy, modify, and compile the Software
+ * source code solely for use in connection with Cypress's
+ * integrated circuit products. Any reproduction, modification, translation,
+ * compilation, or representation of this Software except as specified
+ * above is prohibited without the express written permission of Cypress.
+ *
+ * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
+ * reserves the right to make changes to the Software without notice. Cypress
+ * does not assume any liability arising out of the application or use of the
+ * Software or any product or circuit described in the Software. Cypress does
+ * not authorize its products for use in any products where a malfunction or
+ * failure of the Cypress product may reasonably be expected to result in
+ * significant property damage, injury or death ("High Risk Product"). By
+ * including Cypress's product in a High Risk Product, the manufacturer
+ * of such system or application assumes all risk of such use and in doing
+ * so agrees to indemnify Cypress against all liability.
+ */
+/** @file
+ *
+ * Button manager defines generic interface for button events and button type configurations.
+ * It exposes interface to configure platform button events (like click,long press) with user configurable timing.
+ */
+#pragma once
+
+#include "platform_button.h"
+#include "wiced.h"
+#include "wiced_rtos.h"
+#include "wiced_timer.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************
+ * Macros
+ ******************************************************/
+
+/******************************************************
+ * Constants
+ ******************************************************/
+
+/******************************************************
+ * Enumerations
+ ******************************************************/
+
+/**
+ * @brief Button Manager events.
+ *
+ */
+typedef enum
+{
+ BUTTON_CLICK_EVENT = (1 << 0), /**< A click is a combination of press and release button events. Typically ~ < 200 ms. */
+ BUTTON_SHORT_DURATION_EVENT = (1 << 1), /**< Short duration click event */
+ BUTTON_MEDIUM_DURATION_EVENT = (1 << 2), /**< Medium duration click event */
+ BUTTON_LONG_DURATION_EVENT = (1 << 3), /**< Long duration click event */
+ BUTTON_VERY_LONG_DURATION_EVENT = (1 << 4), /**< Very long duration click event */
+ BUTTON_DOUBLE_CLICK_EVENT =
+ (1 << 5), /**< A double click is a combination of two single clicks with some delay between them */
+ BUTTON_HOLDING_EVENT = (1 << 6), /**< Button is holding over at least two long duration. */
+} button_manager_event_t;
+
+/**
+ * @brief Button states.
+ *
+ */
+typedef enum
+{
+ BUTTON_STATE_HELD = (0), /**< Button state held */
+ BUTTON_STATE_RELEASED = (1), /**< Button state released */
+} button_manager_button_state_t;
+
+/******************************************************
+ * Type Definitions
+ ******************************************************/
+
+/**
+ * @brief Worker thread structure.
+ *
+ */
+typedef struct
+{
+ wiced_thread_t * thread; /**< Button event thread */
+ wiced_queue_t * event_queue; /**< Button event queue */
+} button_worker_thread_t;
+
+/**
+ * @brief Button Event Message.
+ *
+ */
+typedef struct
+{
+ event_handler_t function; /**< Button event handler function */
+ void * arg; /**< Button event message arguments to be passed */
+} button_event_message_t;
+/******************************************************
+ * Structures
+ ******************************************************/
+
+/**
+ * @brief Button configuration.
+ *
+ */
+typedef struct
+{
+ platform_button_t button; /**< Logical Button-ids which map to physical buttons on the board */
+ uint16_t button_event_mask; /**< Button event mask */
+ uint32_t application_event; /**< Application event */
+} wiced_button_configuration_t;
+
+/**
+ * @brief Button Information.
+ *
+ */
+typedef struct
+{
+ const wiced_button_configuration_t * configuration; /**< Button configuration */
+ button_manager_button_state_t current_state; /**< Button current state */
+ button_manager_event_t last_sent_event; /**< Button last sent event */
+ uint64_t pressed_timestamp; /**< Button pressed time stamp (us) */
+ uint64_t released_timestamp; /**< Button released time stamp (us) */
+ uint32_t last_released_timestamp; /**< Button last released time stamp */
+ wiced_bool_t check_for_double_click; /**< Button double click event or not */
+ uint32_t repeat; /**< Button holding counter */
+ int32_t debounce_counter; /**< Button debounce counter */
+ wiced_timer_t debounce_timer; /**< Button debounce timer */
+ wiced_bool_t debouncing; /**< Button debounce state indication */
+ wiced_timer_t long_press_timer; /**< Button long press detection timer */
+ uint64_t timer_timestamp; /**< Button event time stamp (us) */
+} button_manager_button_t;
+
+/**
+ * Button event handler
+ *
+ * @param button Which button in the list has been pressed/released/held
+ * @param event What exact event the button is generating.
+ * @param state What exact state the button is in.
+ *
+ * @return void Library should not care whether app handled the button-events correctly or not.
+ *
+ */
+typedef void (*wiced_button_event_handler_t)(const button_manager_button_t * button, button_manager_event_t event,
+ button_manager_button_state_t state);
+
+/**
+ * @brief Button manager Configuration.
+ *
+ */
+typedef struct
+{
+ uint16_t short_hold_duration; /**< held for short duration (ms) */
+ uint16_t medium_hold_duration; /**< held for medium duration (ms) */
+ uint16_t long_hold_duration; /**< held for long duration (ms) */
+ uint16_t very_long_hold_duration; /**< held for very long duration (ms) */
+ uint16_t debounce_duration; /**< duration taken to de-bounce (ms) */
+ uint16_t double_click_interval; /**< Time interval between two RELEASE events */
+ wiced_bool_t continuous_hold_detect; /**< Flag to enable button holding detection.\n
+ If this is set to true, the BUTTON_VERY_LONG_DURATION_EVENT is disabled
+ and a BUTTON_HOLDING_EVENT will be triggered if a button is pressed over
+ twice the long_hold_duration.\n
+ The BUTTON_HOLDING_EVENT will continuous be sent every long_hold_duration
+ after the first BUTTON_HOLDING_EVENT event been sent. */
+ wiced_button_event_handler_t event_handler;
+} wiced_button_manager_configuration_t;
+
+/**
+ * @brief Button Manager structure.
+ *
+ */
+typedef struct
+{
+ const wiced_button_manager_configuration_t * configuration; /**< Button manager configuration */
+ button_manager_button_t * buttons; /**< Button information */
+ uint32_t number_of_buttons; /**< Number of buttons */
+ wiced_button_event_handler_t button_callback; /**< Button event handler */
+} button_manager_t;
+
+/**
+ * Button's state change call back
+ *
+ * @param id Id of the button
+ * @param new_state What exact new state the button is going to.
+ *
+ * @return void Library should not care whether app handled the button-events correctly or not.
+ */
+
+typedef void (*wiced_button_state_change_callback_t)(platform_button_t id, wiced_bool_t new_state);
+
+/******************************************************
+ * Global Variables
+ ******************************************************/
+
+/******************************************************
+ * Function Declarations
+ ******************************************************/
+
+/**
+ * The application should call this function to Initialize the Button Manager
+ *
+ * @param manager : pointer to button manager.
+ * @param configuration : Configuration for the button.
+ * @param buttons : Button information.
+ * @param number_of_buttons : Number of buttons.
+ * @return : result.
+ */
+extern wiced_result_t wiced_button_manager_init(button_manager_t * manager,
+ const wiced_button_manager_configuration_t * configuration,
+ button_manager_button_t * buttons, uint32_t number_of_buttons);
+
+/**
+ * The application should call this function to de-Initialize the Button Manager
+ *
+ * @param manager : Pointer to button manager to de-initialize.
+ * @return : result.
+ */
+extern wiced_result_t wiced_button_manager_deinit(button_manager_t * manager);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
diff --git a/third_party/cyw30739_sdk/include/wiced_led_manager.h b/third_party/cyw30739_sdk/include/wiced_led_manager.h
new file mode 100644
index 0000000..c23f367
--- /dev/null
+++ b/third_party/cyw30739_sdk/include/wiced_led_manager.h
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2016-2021, Cypress Semiconductor Corporation (an Infineon company) or
+ * an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+ *
+ * This software, including source code, documentation and related
+ * materials ("Software") is owned by Cypress Semiconductor Corporation
+ * or one of its affiliates ("Cypress") and is protected by and subject to
+ * worldwide patent protection (United States and foreign),
+ * United States copyright laws and international treaty provisions.
+ * Therefore, you may use this Software only as provided in the license
+ * agreement accompanying the software package from which you
+ * obtained this Software ("EULA").
+ * If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
+ * non-transferable license to copy, modify, and compile the Software
+ * source code solely for use in connection with Cypress's
+ * integrated circuit products. Any reproduction, modification, translation,
+ * compilation, or representation of this Software except as specified
+ * above is prohibited without the express written permission of Cypress.
+ *
+ * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
+ * reserves the right to make changes to the Software without notice. Cypress
+ * does not assume any liability arising out of the application or use of the
+ * Software or any product or circuit described in the Software. Cypress does
+ * not authorize its products for use in any products where a malfunction or
+ * failure of the Cypress product may reasonably be expected to result in
+ * significant property damage, injury or death ("High Risk Product"). By
+ * including Cypress's product in a High Risk Product, the manufacturer
+ * of such system or application assumes all risk of such use and in doing
+ * so agrees to indemnify Cypress against all liability.
+ */
+/** @file
+ *
+ * This file provides definitions of the LED Manager library interface.
+ * LED Manager library provides API's to enable/disable, blink and set brightness of a LED.
+ */
+#pragma once
+
+#include "platform_led.h"
+#include "wiced.h"
+#include "wiced_rtos.h"
+#include "wiced_timer.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************
+ * Macros
+ ******************************************************/
+
+/******************************************************
+ * Constants
+ ******************************************************/
+
+/******************************************************
+ * Enumerations
+ ******************************************************/
+
+/**
+ * @brief Logical LED-id's which map to physical LED's on the board
+ *
+ */
+typedef platform_led_t wiced_led_t;
+
+/**
+ * @brief LED configuration
+ *
+ */
+typedef struct
+{
+ wiced_led_t led; /**< LED id */
+ uint16_t bright; /**< in % from 1 to 100 */
+} wiced_led_config_t;
+/******************************************************
+ * Global Variables
+ ******************************************************/
+
+/******************************************************
+ * Function Declarations
+ ******************************************************/
+
+/**
+ * Function to Initialize the LED Manager
+ *
+ * @param config : Configuration for the LED.
+ * @return : result.
+ */
+extern wiced_result_t wiced_led_manager_init(wiced_led_config_t * config);
+
+/**
+ * Function to de-initialize the LED Manager
+ *
+ * @param void : No arguments.
+ * @return : result.
+ */
+extern wiced_result_t wiced_led_manager_deinit(void);
+
+/**
+ * Enables the selected LED
+ *
+ * @param led : LED to be enabled.
+ * @return : result.
+ */
+extern wiced_result_t wiced_led_manager_enable_led(wiced_led_t led);
+
+/**
+ * Disables the selected LED
+ *
+ * @param led : LED to be disabled.
+ * @return : result.
+ */
+extern wiced_result_t wiced_led_manager_disable_led(wiced_led_t led);
+
+/**
+ * Reconfigures the LED
+ *
+ * @param config : Configuration for the LED.
+ * @return : result.
+ */
+extern wiced_result_t wiced_led_manager_reconfig_led(wiced_led_config_t * config);
+
+/**
+ * Function called to blink a LED
+ *
+ * @param led : LED to be blinked.
+ * @param on_period : on period (ms)
+ * @param off_period : off period (ms)
+ * @return : result.
+ */
+wiced_result_t wiced_led_manager_blink_led(wiced_led_t led, uint32_t on_period, uint32_t off_period);
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
diff --git a/third_party/cyw30739_sdk/repos/30739A0 b/third_party/cyw30739_sdk/repos/30739A0
new file mode 160000
index 0000000..c50b1e7
--- /dev/null
+++ b/third_party/cyw30739_sdk/repos/30739A0
@@ -0,0 +1 @@
+Subproject commit c50b1e77f78d7a52f3677bae8cdb58dd1880a9fe
diff --git a/third_party/cyw30739_sdk/repos/CYW930739M2EVB-01 b/third_party/cyw30739_sdk/repos/CYW930739M2EVB-01
new file mode 160000
index 0000000..92ec887
--- /dev/null
+++ b/third_party/cyw30739_sdk/repos/CYW930739M2EVB-01
@@ -0,0 +1 @@
+Subproject commit 92ec8873d34162c9ce5aab23bb7b0275d8e21806
diff --git a/third_party/cyw30739_sdk/repos/btsdk-include b/third_party/cyw30739_sdk/repos/btsdk-include
new file mode 160000
index 0000000..b1eb9b3
--- /dev/null
+++ b/third_party/cyw30739_sdk/repos/btsdk-include
@@ -0,0 +1 @@
+Subproject commit b1eb9b39f3ef86211164c4d9825bee6316ac76c6
diff --git a/third_party/cyw30739_sdk/repos/btsdk-tools b/third_party/cyw30739_sdk/repos/btsdk-tools
new file mode 160000
index 0000000..9743681
--- /dev/null
+++ b/third_party/cyw30739_sdk/repos/btsdk-tools
@@ -0,0 +1 @@
+Subproject commit 9743681eed4d3f16a291bff6f8aee65349d1241b
diff --git a/third_party/cyw30739_sdk/src/platform_retarget_lock.c b/third_party/cyw30739_sdk/src/platform_retarget_lock.c
new file mode 100644
index 0000000..2de5160
--- /dev/null
+++ b/third_party/cyw30739_sdk/src/platform_retarget_lock.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2016-2021, Cypress Semiconductor Corporation (an Infineon company) or
+ * an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+ *
+ * This software, including source code, documentation and related
+ * materials ("Software") is owned by Cypress Semiconductor Corporation
+ * or one of its affiliates ("Cypress") and is protected by and subject to
+ * worldwide patent protection (United States and foreign),
+ * United States copyright laws and international treaty provisions.
+ * Therefore, you may use this Software only as provided in the license
+ * agreement accompanying the software package from which you
+ * obtained this Software ("EULA").
+ * If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
+ * non-transferable license to copy, modify, and compile the Software
+ * source code solely for use in connection with Cypress's
+ * integrated circuit products. Any reproduction, modification, translation,
+ * compilation, or representation of this Software except as specified
+ * above is prohibited without the express written permission of Cypress.
+ *
+ * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
+ * reserves the right to make changes to the Software without notice. Cypress
+ * does not assume any liability arising out of the application or use of the
+ * Software or any product or circuit described in the Software. Cypress does
+ * not authorize its products for use in any products where a malfunction or
+ * failure of the Cypress product may reasonably be expected to result in
+ * significant property damage, injury or death ("High Risk Product"). By
+ * including Cypress's product in a High Risk Product, the manufacturer
+ * of such system or application assumes all risk of such use and in doing
+ * so agrees to indemnify Cypress against all liability.
+ */
+
+#include <sys/lock.h>
+#include <wiced_rtos.h>
+
+typedef struct __lock
+{
+ wiced_mutex_t * mutex;
+} lock_t;
+
+static void lock_init_recursive(lock_t * lock);
+
+lock_t __lock___sinit_recursive_mutex;
+lock_t __lock___sfp_recursive_mutex;
+lock_t __lock___atexit_recursive_mutex;
+lock_t __lock___malloc_recursive_mutex;
+lock_t __lock___env_recursive_mutex;
+lock_t __lock___tz_mutex;
+
+void platform_retarget_lock_init(void)
+{
+ lock_init_recursive(&__lock___sinit_recursive_mutex);
+ lock_init_recursive(&__lock___sfp_recursive_mutex);
+ lock_init_recursive(&__lock___malloc_recursive_mutex);
+}
+
+void __retarget_lock_init_recursive(lock_t ** lock) {}
+
+void __retarget_lock_close_recursive(lock_t * lock) {}
+
+void __retarget_lock_acquire(lock_t * lock) {}
+
+void __retarget_lock_acquire_recursive(lock_t * lock)
+{
+ if (lock != NULL && lock->mutex != NULL)
+ {
+ wiced_rtos_lock_mutex(lock->mutex);
+ }
+}
+
+void __retarget_lock_release(lock_t * lock) {}
+
+void __retarget_lock_release_recursive(lock_t * lock)
+{
+ if (lock != NULL && lock->mutex != NULL)
+ {
+ wiced_rtos_unlock_mutex(lock->mutex);
+ }
+}
+
+void lock_init_recursive(lock_t * lock)
+{
+ lock->mutex = wiced_rtos_create_mutex();
+ if (lock->mutex != NULL)
+ {
+ wiced_rtos_init_mutex(lock->mutex);
+ }
+}
diff --git a/third_party/openthread/ot-ifx b/third_party/openthread/ot-ifx
new file mode 160000
index 0000000..da52256
--- /dev/null
+++ b/third_party/openthread/ot-ifx
@@ -0,0 +1 @@
+Subproject commit da522560fbff49f6b27bfef2139e898018c5f0f4
diff --git a/third_party/openthread/platforms/ifx/BUILD.gn b/third_party/openthread/platforms/ifx/BUILD.gn
new file mode 100644
index 0000000..ce9f1e1
--- /dev/null
+++ b/third_party/openthread/platforms/ifx/BUILD.gn
@@ -0,0 +1,53 @@
+# 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.
+
+import("//build_overrides/chip.gni")
+import("//build_overrides/cyw30739_sdk.gni")
+import("//build_overrides/openthread.gni")
+
+openthread_ifx_root = "${chip_root}/third_party/openthread/ot-ifx"
+openthread_ifx_mcu = "cyw30739"
+
+config("openthread_ifx_config") {
+ include_dirs = [ "${openthread_ifx_root}/src/${openthread_ifx_mcu}" ]
+}
+
+source_set("openthread_core_config_ifx") {
+ sources = [ "${openthread_ifx_root}/src/${openthread_ifx_mcu}/openthread-core-cyw30739-config.h" ]
+
+ public_deps = [ "${cyw30739_sdk_build_root}:cyw30739_sdk" ]
+
+ public_configs = [ ":openthread_ifx_config" ]
+}
+
+source_set("libopenthread-ifx") {
+ sources = [
+ "${openthread_ifx_root}/src/${openthread_ifx_mcu}/alarm.c",
+ "${openthread_ifx_root}/src/${openthread_ifx_mcu}/entropy.c",
+ "${openthread_ifx_root}/src/${openthread_ifx_mcu}/logging.c",
+ "${openthread_ifx_root}/src/${openthread_ifx_mcu}/misc.c",
+ "${openthread_ifx_root}/src/${openthread_ifx_mcu}/radio.c",
+ "${openthread_ifx_root}/src/${openthread_ifx_mcu}/settings.c",
+ "${openthread_ifx_root}/src/${openthread_ifx_mcu}/system.c",
+ ]
+
+ defines = [ "CHIP_HAVE_CONFIG_H=1" ]
+
+ public_deps = [
+ ":openthread_core_config_ifx",
+ "${openthread_root}/src/core:libopenthread_core_headers",
+ "..:libopenthread-platform",
+ "..:libopenthread-platform-utils",
+ ]
+}