Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Telink] Add all clusters app & clusters minimal app (project-chip#23383
Browse files Browse the repository at this point in the history
)

* [Telink] Add all-cluster-minimal-app & all-cluster-app

* [Telink] update md files &  set Teilink Light as FTD

* [Telink] Restyled

* [Telink] Add targets

* [Telink] Fix pair cmd example

* [Telink] restyled

* [Telink] Add new apps for target linux

* [Telink] Add note reg set up a valid Network Commissioning cluster;
Remove ThreadStartButton from minimal app.
s07641069 committed Nov 4, 2022
1 parent fe40470 commit 4ccafe7
Showing 35 changed files with 1,908 additions and 31 deletions.
33 changes: 21 additions & 12 deletions .github/workflows/examples-telink.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020 Project CHIP Authors
# Copyright (c) 2022 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.
@@ -54,37 +54,46 @@ jobs:
GH_CONTEXT: ${{ toJson(github) }}
run: scripts/tools/memory/gh_sizes_environment.py "${GH_CONTEXT}"

- name: Build example Telink Lighting App
- name: Build example Telink All Clusters App
run: |
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py --no-log-timestamps --target 'telink-tlsr9518adk80d-light' build"
"./scripts/build/build_examples.py --no-log-timestamps --target 'telink-tlsr9518adk80d-all-clusters' build"
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
telink tlsr9518adk80d all-clusters-app \
out/telink-tlsr9518adk80d-all-clusters/zephyr/zephyr.elf \
/tmp/bloat_reports/
- name: Build example Telink Light Switch App
- name: Build example Telink All Clusters Minimal App
run: |
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py --no-log-timestamps --target 'telink-tlsr9518adk80d-light-switch' build"
"./scripts/build/build_examples.py --no-log-timestamps --target 'telink-tlsr9518adk80d-all-clusters-minimal' build"
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
telink tlsr9518adk80d all-clusters-minimal-app \
out/telink-tlsr9518adk80d-all-clusters-minimal/zephyr/zephyr.elf \
/tmp/bloat_reports/
- name: Build example Telink OTA Requestor App
- name: Build example Telink Lighting App
run: |
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py --no-log-timestamps --target 'telink-tlsr9518adk80d-ota-requestor' build"
- name: Get Lighting size stats
run: |
"./scripts/build/build_examples.py --no-log-timestamps --target 'telink-tlsr9518adk80d-light' build"
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
telink tlsr9518adk80d lighting-app \
out/telink-tlsr9518adk80d-light/zephyr/zephyr.elf \
/tmp/bloat_reports/
- name: Get Light Switch size stats
- name: Build example Telink Light Switch App
run: |
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py --no-log-timestamps --target 'telink-tlsr9518adk80d-light-switch' build"
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
telink tlsr9518adk80d light-switch-app \
out/telink-tlsr9518adk80d-light-switch/zephyr/zephyr.elf \
/tmp/bloat_reports/
- name: Get OTA Requestor size stats
- name: Build example Telink OTA Requestor App
run: |
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py --no-log-timestamps --target 'telink-tlsr9518adk80d-ota-requestor' build"
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
telink tlsr9518adk80d ota-requestor-app \
out/telink-tlsr9518adk80d-ota-requestor/zephyr/zephyr.elf \
2 changes: 2 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -441,6 +441,8 @@
"nrf-nrf5340-pump-controller",
"nrf-nrf5340-shell",
"qpg-qpg6100-lock",
"telink-tlsr9518adk80d-all-clusters",
"telink-tlsr9518adk80d-all-clusters-minimal",
"telink-tlsr9518adk80d-light",
"telink-tlsr9518adk80d-light-switch",
"telink-tlsr9518adk80d-ota-requestor",
1 change: 1 addition & 0 deletions examples/all-clusters-app/telink/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build/
71 changes: 71 additions & 0 deletions examples/all-clusters-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#
# Copyright (c) 2022 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.
#
cmake_minimum_required(VERSION 3.13.1)

set(BOARD tlsr9518adk80d)

get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connectedhomeip REALPATH)
get_filename_component(NLIO_ROOT ${CHIP_ROOT}/third_party/nlio/repo/include REALPATH)
get_filename_component(TELINK_COMMON ${CHIP_ROOT}/examples/platform/telink REALPATH)
get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH)
get_filename_component(ALL_CLUSTERS_COMMON_DIR ${CHIP_ROOT}/examples/all-clusters-app/all-clusters-common REALPATH)

set(CONF_FILE ${CHIP_ROOT}/config/telink/app/zephyr.conf prj.conf)

# Load NCS/Zephyr build system
list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/telink/chip-module)
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})

project(chip-telink-all-clusters-app-example)

include(${CHIP_ROOT}/config/telink/app/enable-gnu-std.cmake)
include(${CHIP_ROOT}/src/app/chip_data_model.cmake)

target_compile_options(app PRIVATE -fpermissive)

target_include_directories(app PRIVATE
include
${ALL_CLUSTERS_COMMON_DIR}/include
${GEN_DIR}/app-common
${GEN_DIR}/all-clusters-app
${NLIO_ROOT}
${TELINK_COMMON}/util/include)

add_definitions(
"-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib/address_resolve/AddressResolve_DefaultImpl.h>"
)

target_sources(app PRIVATE
src/AppTask.cpp
src/main.cpp
src/ZclDoorLockCallbacks.cpp
${ALL_CLUSTERS_COMMON_DIR}/src/static-supported-modes-manager.cpp
${ALL_CLUSTERS_COMMON_DIR}/src/bridged-actions-stub.cpp
${ALL_CLUSTERS_COMMON_DIR}/src/binding-handler.cpp
${GEN_DIR}/all-clusters-app/zap-generated/callback-stub.cpp
${GEN_DIR}/all-clusters-app/zap-generated/IMClusterCommandHandler.cpp
${TELINK_COMMON}/util/src/LEDWidget.cpp
${TELINK_COMMON}/util/src/ButtonManager.cpp
${TELINK_COMMON}/util/src/ThreadUtil.cpp)

chip_configure_data_model(app
INCLUDE_SERVER
ZAP_FILE ${ALL_CLUSTERS_COMMON_DIR}/all-clusters-app.zap
)

if(CONFIG_CHIP_OTA_REQUESTOR)
target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp)
endif()
159 changes: 159 additions & 0 deletions examples/all-clusters-app/telink/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# Matter Telink All Clusters Example Application

The Telink All Clusters Example Application implements various ZCL clusters
populated on three endpoints. You can use this example as a reference for
creating your own application.

![Telink B91 EVK](http://wiki.telink-semi.cn/wiki/assets/Hardware/B91_Generic_Starter_Kit_Hardware_Guide/connection_chart.png)

## Build and flash

1. Pull docker image from repository:

```bash
$ docker pull connectedhomeip/chip-build-telink:latest
```

1. Run docker container:

```bash
$ docker run -it --rm -v ${CHIP_BASE}:/root/chip -v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule "c 189:* rmw" connectedhomeip/chip-build-telink:latest
```

here `${CHIP_BASE}` is directory which contains CHIP repo files **!!!Pay
attention that OUTPUT_DIR should contains ABSOLUTE path to output dir**

1. Activate the build environment:

```bash
$ source ./scripts/activate.sh
```

1. In the example dir run:

```bash
$ west build
```

1. Flash binary:

```
$ west flash --erase
```

## Usage

### UART

To get output from device, connect UART to following pins:

| Name | Pin |
| :--: | :---------------------------- |
| RX | PB3 (pin 17 of J34 connector) |
| TX | PB2 (pin 16 of J34 connector) |
| GND | GND |

### Buttons

The following buttons are available on **tlsr9518adk80d** board:

| Name | Function | Description |
| :------- | :--------------------- | :----------------------------------------------------------------------------------------------------- |
| Button 1 | Factory reset | Perform factory reset to forget currently commissioned Thread network and back to uncommissioned state |
| Button 2 | Not used | Not used |
| Button 3 | Thread start | Commission thread with static credentials and enables the Thread on device |
| Button 4 | Open commission window | The button is opening commissioning window to perform commissioning over BLE |

### LEDs

**Red** LED indicates current state of Thread network. It ables to be in
following states:

| State | Description |
| :-------------------------- | :--------------------------------------------------------------------------- |
| Blinks with short pulses | Device is not commissioned to Thread, Thread is disabled |
| Blinls with frequent pulses | Device is commissioned, Thread enabled. Device trying to JOIN thread network |
| Blinks with whde pulses | Device commissioned and joined to thread network as CHILD |

### CHIP tool commands

1. Build
[chip-tool cli](https://github.com/project-chip/connectedhomeip/blob/master/examples/chip-tool/README.md)

2. Pair with device

```
${CHIP_TOOL_DIR}/chip-tool pairing ble-thread ${NODE_ID} hex:${DATASET} ${PIN_CODE} ${DISCRIMINATOR}
```

Example:

```
./chip-tool pairing ble-thread 1234 hex:0e080000000000010000000300000f35060004001fffe0020811111111222222220708fd61f77bd3df233e051000112233445566778899aabbccddeeff030e4f70656e54687265616444656d6f010212340410445f2b5ca6f2a93a55ce570a70efeecb0c0402a0fff8 20202021 3840
```

### OTA with Linux OTA Provider

OTA feature enabled by default only for ota-requestor-app example. To enable OTA
feature for another Telink example:

- set CONFIG_CHIP_OTA_REQUESTOR=y in corresponding "prj.conf" configuration
file.

After build application with enabled OTA feature, use next binary files:

- zephyr.bin - main binary to flash PCB (Use 2MB PCB).
- zephyr-ota.bin - binary for OTA Provider

All binaries has the same SW version. To test OTA “zephyr-ota.bin” should have
higher SW version than base SW. Set CONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2 in
corresponding “prj.conf” configuration file.

Usage of OTA:

- Build the [Linux OTA Provider](../../ota-provider-app/linux)

```
./scripts/examples/gn_build_example.sh examples/ota-provider-app/linux out/ota-provider-app chip_config_network_layer_ble=false
```

- Run the Linux OTA Provider with OTA image.

```
./chip-ota-provider-app -f zephyr-ota.bin
```

- Provision the Linux OTA Provider using chip-tool

```
./chip-tool pairing onnetwork ${OTA_PROVIDER_NODE_ID} 20202021
```

here:

- \${OTA_PROVIDER_NODE_ID} is the node id of Linux OTA Provider

- Configure the ACL of the ota-provider-app to allow access

```
./chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null}, {"fabricIndex": 1, "privilege": 3, "authMode": 2, "subjects": null, "targets": null}]' ${OTA_PROVIDER_NODE_ID} 0
```

here:

- \${OTA_PROVIDER_NODE_ID} is the node id of Linux OTA Provider

- Use the chip-tool to announce the ota-provider-app to start the OTA process

```
./chip-tool otasoftwareupdaterequestor announce-ota-provider ${OTA_PROVIDER_NODE_ID} 0 0 0 ${DEVICE_NODE_ID} 0
```

here:

- \${OTA_PROVIDER_NODE_ID} is the node id of Linux OTA Provider
- \${DEVICE_NODE_ID} is the node id of paired device

Once the transfer is complete, OTA requestor sends ApplyUpdateRequest command to
OTA provider for applying the image. Device will restart on successful
application of OTA image.
34 changes: 34 additions & 0 deletions examples/all-clusters-app/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
*
* Copyright (c) 2022 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.
*/

#pragma once

// ---- All Clusters Application example config ----

// Buttons config
#define BUTTON_PORT DEVICE_DT_GET(DT_NODELABEL(gpioc))

#define BUTTON_PIN_1 2
#define BUTTON_PIN_3 3
#define BUTTON_PIN_4 1
#define BUTTON_PIN_2 0

// LEDs config
// System led config
#define SYSTEM_STATE_LED_PORT DEVICE_DT_GET(DT_NODELABEL(gpiob))
#define SYSTEM_STATE_LED_PIN 7
44 changes: 44 additions & 0 deletions examples/all-clusters-app/telink/include/AppEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
*
* Copyright (c) 2022 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.
*/

#pragma once

#include <cstdint>

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

struct AppEvent
{
enum AppEventTypes
{
kEventType_Button = 0,
};

uint16_t Type;

union
{
struct
{
uint8_t Action;
} ButtonEvent;
};

EventHandler Handler;
};
Loading

0 comments on commit 4ccafe7

Please sign in to comment.