Skip to content

Commit

Permalink
Support lighting app, Diagnostics Clusters for Infineon P6 (#12189)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenCY authored and pull[bot] committed Apr 6, 2023
1 parent 292bdc9 commit 6438484
Show file tree
Hide file tree
Showing 41 changed files with 2,785 additions and 10 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/examples-infineon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ concurrency:
jobs:
infineon:
name: Infineon examples building
timeout-minutes: 30
timeout-minutes: 60

runs-on: ubuntu-latest
if: github.actor != 'restyled-io[bot]'
Expand Down Expand Up @@ -72,7 +72,14 @@ jobs:
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
p6 default all-clusters-app \
out/infineon-p6-all-clusters/chip-p6-clusters-example.out
- name: Build lighting-app example
timeout-minutes: 10
run: |
scripts/run_in_build_env.sh \
"scripts/build/build_examples.py --no-log-timestamps --target 'infineon-p6-light' build"
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
p6 default light-app \
out/infineon-p6-light/chip-p6-lighting-example.out
- name: Uploading Size Reports
uses: actions/upload-artifact@v2
if: ${{ !env.ACT }}
Expand Down
1 change: 1 addition & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
"esp32-m5stack-all-clusters-rpc-ipv6only",
"infineon-p6-all-clusters",
"infineon-p6-lock",
"infineon-p6-light",
"linux-arm64-all-clusters",
"linux-arm64-all-clusters-ipv6only",
"linux-arm64-chip-tool",
Expand Down
9 changes: 8 additions & 1 deletion examples/all-clusters-app/p6/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ int main(void)
// Init Chip memory management before the stack
chip::Platform::MemoryInit();

CHIP_ERROR ret = PlatformMgr().InitChipStack();
CHIP_ERROR ret = chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();
if (ret != CHIP_NO_ERROR)
{
P6_LOG("PersistedStorage::KeyValueStoreMgrImpl().Init() failed");
appError(ret);
}

ret = PlatformMgr().InitChipStack();
if (ret != CHIP_NO_ERROR)
{
P6_LOG("PlatformMgr().InitChipStack() failed");
Expand Down
28 changes: 28 additions & 0 deletions examples/lighting-app/p6/.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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")

# 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 = "freertos"

import("//args.gni")
}
109 changes: 109 additions & 0 deletions examples/lighting-app/p6/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# 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/p6.gni")

import("${build_root}/config/defaults.gni")
import("${p6_sdk_build_root}/p6_executable.gni")
import("${p6_sdk_build_root}/p6_sdk.gni")

assert(current_os == "freertos")

p6_project_dir = "${chip_root}/examples/lighting-app/p6"
examples_plat_dir = "${chip_root}/examples/platform/p6"

declare_args() {
# Dump memory usage at link time.
chip_print_memory_usage = false

# PIN code for PASE session establishment.
setup_pin_code = 20202021

# Monitor & log memory usage at runtime.
enable_heap_monitoring = false
}

p6_sdk_sources("lighting_app_sdk_sources") {
include_dirs = [
"${chip_root}/src/platform/P6",
"${p6_project_dir}/include",
"${examples_plat_dir}",
]

defines = [
"BOARD_ID=${p6_board}",
"P6_LOG_ENABLED=1",
"CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setup_pin_code}",
]

sources = [ "${p6_project_dir}/include/CHIPProjectConfig.h" ]

public_configs = [ "${chip_root}/third_party/p6:p6_sdk_config" ]
}

p6_executable("lighting_app") {
include_dirs = []
defines = []
output_name = "chip-p6-lighting-example.out"

sources = [
"${examples_plat_dir}/LEDWidget.cpp",
"${examples_plat_dir}/init_p6Platform.cpp",
"src/AppTask.cpp",
"src/ButtonHandler.cpp",
"src/LightingManager.cpp",
"src/ZclCallbacks.cpp",
"src/main.cpp",
]

deps = [
":lighting_app_sdk_sources",
"${chip_root}/examples/common/QRCode",
"${chip_root}/examples/lighting-app/lighting-common",
"${chip_root}/src/lib",
"${chip_root}/src/setup_payload",
]

include_dirs += [
"include",
"${examples_plat_dir}",
"${p6_project_dir}/include",
]

defines = []

if (enable_heap_monitoring) {
sources += [ "${examples_plat_dir}/MemMonitoring.cpp" ]
defines += [ "HEAP_MONITORING" ]
}

if (chip_print_memory_usage) {
ldflags += [
"-Wl,--print-memory-usage",
"-fstack-usage",
]
}

output_dir = root_out_dir
}

group("p6") {
deps = [ ":lighting_app" ]
}

group("default") {
deps = [ ":p6" ]
}
156 changes: 156 additions & 0 deletions examples/lighting-app/p6/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#CHIP P6 Lighting Example

An example showing the use of Matter on the Infineon CY8CKIT-062S2-43012 board.

<hr>

- [Matter P6 Lighting Example](#chip-p6-Lighting-example)
- [Introduction](#introduction)
- [Building](#building)
- [Flashing the Application](#flashing-the-application)
- [Commissioning and cluster control](#commissioning-and-cluster-control)
- [Setting up Python Controller](#setting-up-python-controller)
- [Commissioning over BLE](#commissioning-over-ble)
- [Notes](#notes)
- [Cluster control](#cluster-control)

<hr>

<a name="intro"></a>

## Introduction

The P6 lighting example provides a baseline demonstration of a Light control
device, built using Matter and the Infineon Modustoolbox SDK. It can be
controlled by Matter controller over Wi-Fi network.

The P6 device can be commissioned over Bluetooth Low Energy where the device and
the Matter controller will exchange security information with the Rendezvous
procedure. Wi-Fi Network credentials are then provided to the P6 device which
will then join the network.

<a name="building"></a>

## Building

- [Modustoolbox Software](https://www.cypress.com/products/modustoolbox)

Refer to `integrations/docker/images/chip-build-infineon/Dockerfile` or
`scripts/examples/gn_p6_example.sh` for downloading the Software and related
tools.

- Install some additional tools (likely already present for Matter
developers): \$ sudo apt install gcc g++ clang ninja-build python
python3-venv libssl-dev libavahi-client-dev libglib2.0-dev git cmake
python3-pip

- Supported hardware:
[CY8CKIT-062S2-43012](https://www.cypress.com/CY8CKIT-062S2-43012)

* Build the example application:

$ ./scripts/examples/gn_p6_example.sh ./examples/lighting-app/p6 out/lighting_app_p6

- To delete generated executable, libraries and object files use:

$ cd ~/connectedhomeip
$ rm -rf out/

<a name="flashing"></a>

## Flashing the Application

- Put CY8CKIT-062S2-43012 board on KitProg3 CMSIS-DAP Mode by pressing the
`MODE SELECT` button. `KITPROG3 STATUS` LED is ON confirms board is in
proper mode.

- On the command line:

$ cd ~/connectedhomeip
$ python3 out/lighting_app_p6/chip-p6-lock-example.flash.py

<a name="Commissioning and cluster control"></a>

## Commissioning and cluster control

Commissioning can be carried out using BLE.

<a name="Setting up Python Controller"></a>

### Setting up Python Controller

Once P6 is up and running, we need to set up a device controller on Raspberry Pi
4 to perform commissioning and cluster control.

- Set up python controller.

$ cd {path-to-connectedhomeip}
$ ./scripts/build_python.sh -m platform

- Execute the controller.

$ source ./out/python_env/bin/activate
$ chip-device-ctrl

<a name="Commissioning over BLE"></a>

### Commissioning over BLE

- Establish the secure session over BLE.

- chip-device-ctrl > ble-scan
- chip-device-ctrl > connect -ble 3840 20202021 1234

Parameters:
1. Discriminator: 3840
2. Setup-pin-code: 20202021
3. Node ID: Optional.
If not passed in this command, then it is auto-generated by the controller and
displayed in the output of connect.
The same value should be used in the next commands.
We have chosen a random node ID which is 1234.

- Add credentials of the Wi-Fi network you want the P6 to connect to, using
the `AddWiFiNetwork` command and then enable the P6 to connect to it using
`EnableWiFiNetwork` command. In this example, we have used `WIFI_SSID` and
`WIFI_PASSWORD` as the SSID and passphrase respectively.

- chip-device-ctrl > zcl NetworkCommissioning AddWiFiNetwork 1234 0 0 ssid=str:WIFI_SSID credentials=str:WIFI_PASSWORD breadcrumb=0 timeoutMs=1000

- chip-device-ctrl > zcl NetworkCommissioning EnableNetwork 1234 0 0 networkID=str:WIFI_SSID breadcrumb=0 timeoutMs=1000

- Close the BLE connection to P6, as it is not required hereafter.

- chip-device-ctrl > close-ble

- Resolve DNS-SD name and update address of the node in the device controller.

- chip-device-ctrl > resolve 0 1234

<a name="Notes"></a>

#### Notes

Raspberry Pi 4 BLE connection issues can be avoided by running the following
commands. These power cycle the BlueTooth hardware and disable BR/EDR mode.

$ sudo btmgmt -i hci0 power off
$ sudo btmgmt -i hci0 bredr off
$ sudo btmgmt -i hci0 power on

<a name="Cluster control"></a>

### Cluster control

- After successful commissioning, use the OnOff cluster command to toggle
device between On or Off states.

`chip-device-ctrl > zcl OnOff Off 1234 1 0`

`chip-device-ctrl > zcl OnOff On 1234 1 0`

- Cluster OnOff can also be done using the `USER_BTN1` button on the board.
This button is configured with `APP_LIGHT_BUTTON` in `include/AppConfig.h`.
Press `USER_BTN1` on the board to toggle between Light ON and OFF states.
Light ON and OFF can be observed with 'LED9' on the board. This LED is
configured with `LIGHT_STATE_LED` in `include/AppConfig.h`.
20 changes: 20 additions & 0 deletions examples/lighting-app/p6/args.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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("//build_overrides/pigweed.gni")
import("${chip_root}/src/platform/P6/args.gni")

p6_target_project =
get_label_info(":lighting_app_sdk_sources", "label_no_toolchain")
1 change: 1 addition & 0 deletions examples/lighting-app/p6/build_overrides
Loading

0 comments on commit 6438484

Please sign in to comment.