Skip to content

Commit

Permalink
[Infineon] Add an example of light switch app for CYW30739. (#26029)
Browse files Browse the repository at this point in the history
* [Infineon] Add an example of light switch app for CYW30739.

* Add CYW30739 light switch app example codes.
* Add the arg enable_sleepy_device to enable sleepy end device.

* Fix CI for "Build on Linux (coverage)".
  • Loading branch information
hsusid authored and pull[bot] committed Mar 15, 2024
1 parent 526713b commit 6af6f24
Show file tree
Hide file tree
Showing 32 changed files with 2,193 additions and 19 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/examples-infineon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ jobs:
"./scripts/build/build_examples.py \
--target cyw30739-cyw930739m2evb_01-light \
--target cyw30739-cyw930739m2evb_01-lock \
--target cyw30739-cyw930739m2evb_01-ota-requestor-no-progress-logging \
--target cyw30739-cyw930739m2evb_01-ota-requestor \
--target cyw30739-cyw930739m2evb_01-switch \
build \
--copy-artifacts-to out/artifacts \
"
Expand All @@ -163,8 +164,15 @@ jobs:
timeout-minutes: 5
run: |
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
cyw30739 cyw930739m2evb_01 ota-requestor-no-progress-logging \
out/artifacts/cyw30739-cyw930739m2evb_01-ota-requestor-no-progress-logging/chip-cyw30739-ota-requestor-example.elf \
cyw30739 cyw930739m2evb_01 ota-requestor \
out/artifacts/cyw30739-cyw930739m2evb_01-ota-requestor/chip-cyw30739-ota-requestor-example.elf \
/tmp/bloat_reports/
- name: Get switch size stats
timeout-minutes: 5
run: |
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
cyw30739 cyw930739m2evb_01 switch \
out/artifacts/cyw30739-cyw930739m2evb_01-switch/chip-cyw30739-light-switch-example.elf \
/tmp/bloat_reports/
- name: Uploading Size Reports
uses: actions/upload-artifact@v3
Expand Down
28 changes: 28 additions & 0 deletions examples/light-switch-app/infineon/cyw30739/.gn
Original file line number Diff line number Diff line change
@@ -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")
}
82 changes: 82 additions & 0 deletions examples/light-switch-app/infineon/cyw30739/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 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/light-switch-app/infineon/cyw30739"
examples_plat_dir = "${chip_root}/examples/platform/infineon/cyw30739"

declare_args() {
setupPinCode = 20202021
setupDiscriminator = 3840
}

cyw30739_sdk("sdk") {
sources = [ "${cyw30739_project_dir}/include/CHIPProjectConfig.h" ]

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

defines = [
"CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}",
"CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${setupDiscriminator}",
]
}

cyw30739_executable("light_switch_app") {
output_name = "chip-cyw30739-light-switch-example.elf"

sources = [
"src/AppShellCommands.cpp",
"src/BindingHandler.cpp",
"src/ButtonHandler.cpp",
"src/LightSwitch.cpp",
"src/LightingManager.cpp",
"src/ZclCallbacks.cpp",
"src/main.cpp",
]

deps = [
":sdk",
"${chip_root}/examples/light-switch-app/light-switch-common",
"${chip_root}/examples/providers:device_info_provider",
"${chip_root}/examples/shell/shell_common:shell_common",
"${chip_root}/src/lib",
]

include_dirs = [ "include" ]

if (chip_enable_ota_requestor) {
sources += [
"${examples_plat_dir}/OTAConfig.cpp",
"${examples_plat_dir}/OTAConfig.h",
]
}
}

group("cyw30739") {
deps = [ ":light_switch_app" ]
}

group("default") {
deps = [ ":cyw30739" ]
}
216 changes: 216 additions & 0 deletions examples/light-switch-app/infineon/cyw30739/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
# Matter CYW30739 Light Switch Example

An example showing the use of Matter on the Infineon CYW30739 platform.

---

## Table of Contents

- [Matter CYW30739 Light Switch Example](#matter-cyw30739-light-switch-example)
- [Table of Contents](#table-of-contents)
- [Introduction](#introduction)
- [Building](#building)
- [Building Options](#building-options)
- [DAC / DAC Key / PAI Certificate / Certificate Declaration](#dac--dac-key--pai-certificate--certificate-declaration)
- [Flashing the Application](#flashing-the-application)
- [Enter Recovery Mode](#enter-recovery-mode)
- [Run Flash Script](#run-flash-script)
- [Running the Complete Example](#running-the-complete-example)

## Introduction

The CYW30739 light switch example provides a baseline demonstration of a on-off
light switch 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. Target Thread Network information including the active
dataset and CASE credentials are then provided.

## Building

- Build the example application:

```bash
$ cd ~/connectedhomeip
$ git submodule update --init
$ ./scripts/examples/gn_build_example.sh examples/light-switch-app/infineon/cyw30739 out/light-switch-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/light-switch-app/infineon/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/light-switch-app/infineon/cyw30739
$ rm -rf out/
```

## Building Options

### DAC / DAC Key / PAI Certificate / Certificate Declaration

Infineon CYW30739 examples use test certifications, keys, and CD by default. For
a production build, manufacturers can provision certifications, keys, and CD by
the following arguments:

- `matter_dac`, `matter_dac_key`, `matter_pai`, `matter_cd`

```bash
$ ./scripts/examples/gn_build_example.sh examples/light-switch-app/infineon/cyw30739 out/light-switch-app \
'matter_dac="/path/to/dac.der"' \
'matter_dac_key="/path/to/dac_key.der"' \
'matter_pai="/path/to/pai.der"' \
'matter_cd="/path/to/cd.der"'
```

## 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/light-switch-app/infineon/cyw30739
$ python3 out/debug/chip-cyw30739-light-switch-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.

- For this example to work, it is necessary to have a second CYW30739 device
running the lighting app example commissioned on the same OpenThread network

- If the CYW30739 device is running the light switch example, then

**Push USER Button** - Sends a Toggle command to bound light app.

**LED1** - Indicates the current button state.

**_OnOff Cluster_** - As following commands are app shell commands.

- 'switch local on' : Lights On LED1 of light-switch device
- 'switch local off' : Lights Off LED1 of light-switch device
- 'switch local toggle' : Makes Toggle LED1 of light-switch device

- 'switch onoff on' : Sends unicast On command to bound device
- 'switch onoff off' : Sends unicast Off command to bound device
- 'switch onoff toggle' : Sends unicast Toggle command to bound device

- 'switch groups onoff on' : Sends On group command to bound group
- 'switch groups onoff off' : Sends On group command to bound group
- 'switch groups onoff toggle' : Sends On group command to bound group

- Here is an example with the CHIPTool for unicast commands only:

```bash
chip-tool pairing ble-thread 1 hex:<operationalDataset> 20202021 3840
chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [<chip-tool-node-id>], "targets": null}, {"fabricIndex": 1, "privilege": 3, "authMode": 2, "subjects": [<light-switch-node-id>], "targets": [{"cluster": 6, "endpoint": 1, "deviceType": null}]}]' <lighting-node-id> 0
chip-tool binding write binding '[{"fabricIndex": 1, "node": <lighting-node-id>, "endpoint": 1, "cluster": 6}]' <light-switch-node-id> 1
```

Example: After pairing successfully [lighting-node-id : 1,
light-switch-node-id : 2]

```bash
chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null}, {"fabricIndex": 1,
"privilege": 3, "authMode": 2, "subjects": [2], "targets": [{"cluster": 6, "endpoint": 1, "deviceType": null}]}]' 1 0
chip-tool binding write binding '[{"fabricIndex": 1, "node": 1, "endpoint": 1, "cluster": 6}]' 2 1
```

- Here is an example with the CHIPTool for groups commands only:

Pairing the device

```bash
chip-tool pairing ble-thread 1 hex:<operationalDataset> 20202021 3840
```

You can use a series of commands after pairing successfully. Here is a
lighting device (node 1) and a light-switch device (node 2) for connection
demonstration.

```bash
chip-tool groupkeymanagement key-set-write '{"groupKeySetID": 417, "groupKeySecurityPolicy": 0, "epochKey0":"a0a1a2a3a4a5a6a7a8a9aaabacadaeaf", "epochStartTime0": 1110000,"epochKey1":"b0b1b2b3b4b5b6b7b8b9babbbcbdbebf", "epochStartTime1":1110001,"epochKey2":"c0c1c2c3c4c5c6c7c8c9cacbcccdcecf", "epochStartTime2": 1110002 }' 1 0
chip-tool groupkeymanagement write group-key-map '[{"groupId": 257, "groupKeySetID": 417, "fabricIndex": 1}]' 1 0
chip-tool groups add-group 257 demo 1 1
chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": null, "targets": null}, {"fabricIndex": 1, "privilege": 3, "authMode": 3, "subjects": [257], "targets": null}]' 1 0
chip-tool groupkeymanagement key-set-write '{"groupKeySetID": 417, "groupKeySecurityPolicy": 0, "epochKey0":"a0a1a2a3a4a5a6a7a8a9aaabacadaeaf", "epochStartTime0": 1110000,"epochKey1":"b0b1b2b3b4b5b6b7b8b9babbbcbdbebf", "epochStartTime1":1110001,"epochKey2":"c0c1c2c3c4c5c6c7c8c9cacbcccdcecf", "epochStartTime2": 1110002 }' 2 0
chip-tool groupkeymanagement write group-key-map '[{"groupId": 257, "groupKeySetID": 417, "fabricIndex": 1}]' 2 0
chip-tool groups add-group 257 demo 2 1
chip-tool binding write binding '[{"fabricIndex": 1, "group": 257}]' 2 1
```

Or you can use TestGroupDemoConfig after pairing successfully

```bash
chip-tool tests TestGroupDemoConfig --nodeId <light-switch-node-id>
chip-tool tests TestGroupDemoConfig --nodeId <lighting-node-id>
chip-tool binding write binding '[{"fabricIndex": 1, "group": 257}]' <light-switch-node-id> 1
```

Example: After pairing successfully [lighting-node-id : 1,
light-switch-node-id : 2]

```bash
chip-tool tests TestGroupDemoConfig --nodeId 2
chip-tool tests TestGroupDemoConfig --nodeId 1
chip-tool binding write binding '[{"fabricIndex": 1, "group": 257}]' 2 1
```

To run the example with unicast and groups commands, run the group
configuration commands and replace the last one with binding this command

```bash
chip-tool binding write binding '[{"fabricIndex": 1, "group": 257},{"fabricIndex": 1, "node": <lighting-node-id>, "endpoint": 1, "cluster":6} ]' <light-switch-node-id> 1
```

To acquire the chip-tool node id, read the acl table right after
commissioning

```bash
chip-tool accesscontrol read acl <nodeid> 0
```
29 changes: 29 additions & 0 deletions examples/light-switch-app/infineon/cyw30739/args.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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}/config/standalone/args.gni")
import("${chip_root}/src/platform/Infineon/CYW30739/args.gni")

cyw30739_sdk_target = get_label_info(":sdk", "label_no_toolchain")

chip_openthread_ftd = false
enable_sleepy_device = true

chip_enable_ota_requestor = true

chip_error_logging = false
chip_progress_logging = false
chip_detail_logging = false
chip_automation_logging = false
Loading

0 comments on commit 6af6f24

Please sign in to comment.