Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle Add Lock app example for infineon P6 board #8274

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
# Set this to true to enable efr32 builds by default.
enable_efr32_builds = false

# Set this to true to enable p6 builds by default.
enable_p6_builds = false

# Set this to true to enable Qorvo qpg builds by default.
enable_qpg_builds = false

Expand Down Expand Up @@ -216,6 +219,9 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
# Build the efr32 lock app example.
enable_efr32_lock_app_build = enable_efr32_builds

# Build the p6 lock app example.
enable_p6_lock_app_build = enable_p6_builds

# Build the qpgxxxx lock app example.
enable_qpg_lock_app_build = enable_qpg_builds && !is_debug

Expand Down Expand Up @@ -335,6 +341,12 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
}
}

if (enable_p6_lock_app_build) {
group("p6_lock_app") {
deps = [ "${chip_root}/examples/lock-app/p6(${chip_root}/config/p6/toolchain:p6_lock_app)" ]
}
}

if (enable_qpg_lock_app_build) {
group("qpg_lock_app") {
deps = [ "${chip_root}/examples/lock-app/qpg(${chip_root}/config/qpg/toolchain:qpg_lock_app)" ]
Expand Down Expand Up @@ -420,6 +432,9 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
if (enable_efr32_window_app_build) {
deps += [ ":efr32_window_app" ]
}
if (enable_p6_lock_app_build) {
deps += [ ":p6_lock_app" ]
}
if (enable_k32w_lighting_app_build) {
deps += [ ":k32w_lighting_app" ]
}
Expand Down
18 changes: 18 additions & 0 deletions build_overrides/p6.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

declare_args() {
# Root directory for p6 SDK build files.
p6_sdk_build_root = "//third_party/p6"
}
26 changes: 26 additions & 0 deletions config/p6/toolchain/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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_root}/toolchain/arm_gcc/arm_toolchain.gni")

arm_toolchain("p6_lock_app") {
toolchain_args = {
current_os = "freertos"
import("${chip_root}/examples/lock-app/p6/args.gni")
treat_warnings_as_errors = false
}
}
28 changes: 28 additions & 0 deletions examples/lock-app/p6/.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 = "freertos"

import("//args.gni")
}
110 changes: 110 additions & 0 deletions examples/lock-app/p6/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# 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/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/lock-app/p6"
examples_plat_dir = "${chip_root}/examples/platform/p6"

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

p6_sdk_sources("lock_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",
"CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}",
]

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

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

#public_configs += ["${chip_root}/third_party/p6:project_configs"]
}

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

public_deps = [
":lock_app_sdk_sources",
"${chip_root}/examples/common/QRCode",
"${chip_root}/examples/lock-app/lock-common",
"${chip_root}/src/lib",
"${chip_root}/src/setup_payload",
"${chip_root}/third_party/openthread/platforms:libopenthread-platform",
"${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils",
"${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd",
"${chip_root}/third_party/openthread/repo:libopenthread-ftd",
]

include_dirs += [
"include",
"${chip_root}/src/app/util",
"${chip_root}/src/app/server",
"${examples_plat_dir}",
"${p6_project_dir}/include",
]

sources = [
"${examples_plat_dir}/LEDWidget.cpp",
"${examples_plat_dir}/Service.cpp",
"${examples_plat_dir}/init_p6Platform.cpp",
"${p6_project_dir}/include/CHIPProjectConfig.h",
"src/AppTask.cpp",
"src/BoltLockManager.cpp",
"src/ButtonHandler.cpp",
"src/ZclCallbacks.cpp",
"src/main.cpp",
]

output_dir = root_out_dir

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

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

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

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

<hr>

- [Matter P6 Lock Example](#chip-p6-lock-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 lock example provides a demonstration of a door lock control device,
built using Matter and the Infineon Modustoolbox SDK. It can be controlled by a
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

- Download
[Modustoolbox Software](https://www.cypress.com/products/modustoolbox)
- 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:

$ cd ~/connectedhomeip
$ ./gn_build.sh enable_p6_builds=true

- 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/debug/p6_lock_app/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 12345678 1234

Parameters:
1. Discriminator: 3840
2. Setup-pin-code: 12345678
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_LOCK_BUTTON` in `include/AppConfig.h`.
Press `USER_BTN1` on the board to toggle between lock and unlock states. The
Lock/Unlock status of door can be observed with 'LED9' on the board. This
LED is configured with `LOCK_STATE_LED` in `include/AppConfig.h`.
Loading