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

[K32W] Add functionality to run lock-app and lighting-app without OM15082 Expansion board #6813

Merged
merged 4 commits into from
May 14, 2021
Merged
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
19 changes: 16 additions & 3 deletions examples/lighting-app/k32w/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ states are depicted:
light bulb is on; when not lit, the light bulb is off.

**Button SW2** can be used to reset the device to a default state. Pressing and
holding Button SW3 for 6 seconds initiates a factory reset. After an initial
holding Button SW2 for 6 seconds initiates a factory reset. After an initial
period of 3 seconds, LED2 D2 and D3 will flash in unison to signal the pending
reset. Holding the button past 6 seconds will cause the device to reset its
persistent configuration and initiate a reboot. The reset action can be
Expand All @@ -130,6 +130,15 @@ enabling Bluetooth LE advertising for a predefined period of time. Also, pushing
this button starts the NFC emulation by writing the onboarding information in
the NTAG.

### No expansion board

In case the **OM15082** Expansion board is not attached to the DK6 board, the
functionality of LED D2 and LED D3 is taken over by LED DS2, respectively LED
DS3, which can be found on the DK6 board.

Also, by long pressing the **USERINTERFACE** button, the factory reset action
will be initiated.

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

## Building
Expand All @@ -150,15 +159,19 @@ distribution (the demo-application was compiled on Ubuntu 20.04).
user@ubuntu:~/Desktop/git/connectedhomeip$ export K32W061_SDK_ROOT=/home/user/Desktop/SDK_2.6.3_K32W061DK6/
user@ubuntu:~/Desktop/git/connectedhomeip$ ./third_party/k32w_sdk/sdk_fixes/patch_k32w_sdk.sh
user@ubuntu:~/Desktop/git/connectedhomeip$ source ./scripts/activate.sh
user@ubuntu:~/Desktop/git/connectedhomeip/third_party/openthread/repo$ cd examples/lighting-app/k32w/
user@ubuntu:~/Desktop/git/connectedhomeip/examples/lighting-app/k32w$ gn gen out/debug --args="k32w_sdk_root=\"${K32W061_SDK_ROOT}\" is_debug=true"
user@ubuntu:~/Desktop/git/connectedhomeip$ cd examples/lighting-app/k32w/
user@ubuntu:~/Desktop/git/connectedhomeip/examples/lighting-app/k32w$ gn gen out/debug --args="k32w_sdk_root=\"${K32W061_SDK_ROOT}\" chip_with_OM15082=1 is_debug=true"
user@ubuntu:~/Desktop/git/connectedhomeip/examples/lightin-app/k32w$ ninja -C out/debug
user@ubuntu:~/Desktop/git/connectedhomeip/examples/lighting-app/k32w$ $K32W061_SDK_ROOT/tools/imagetool/sign_images.sh out/debug/
```

Note that "patch_k32w_sdk.sh" script must be run for patching the K32W061 SDK
2.6.3.

Also, in case the OM15082 Expansion Board is not attached to the DK6 board, the
build argument (chip_with_OM15082) inside the gn build instruction should be set
to zero. The argument chip_with_OM15082 is set to zero by default.

In case signing errors are encountered when running the "sign_images.sh" script
install the recommanded packages (python version > 3, pip3, pycrypto,
pycryptodome):
Expand Down
Binary file modified examples/lighting-app/k32w/data.bin
Binary file not shown.
18 changes: 17 additions & 1 deletion examples/lighting-app/k32w/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ void AppTask::ButtonEventHandler(uint8_t pin_no, uint8_t button_action)
else if (pin_no == BLE_BUTTON)
{
button_event.Handler = BleHandler;
#if !(defined OM15082)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this not be using defined(OM15082) instead of (defined OM15082) ? I find the bracketing a bit odd ... gcc defined docs seem to only describe the brackets after the keyword.

Is this a style that is valid?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested it and it does work ... but feels unusual. Are there docs on why it works?

Copy link

@Ursescu Ursescu May 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @andy31415, that syntax is basically the one described from GCC standard defined OM15082 wrapped around parenthesis. Check out the reference link under examples and also the godbolt that I've baked.

if (button_action == RESET_BUTTON_PUSH)
{
button_event.Handler = ResetActionEventHandler;
}
#endif
}

sAppTask.PostEvent(&button_event);
Expand Down Expand Up @@ -271,8 +277,13 @@ void AppTask::HandleKeyboard(void)
switch (keyEvent)
{
case gKBD_EventPB1_c:
#if (defined OM15082)
ButtonEventHandler(RESET_BUTTON, RESET_BUTTON_PUSH);
break;
#else
ButtonEventHandler(BLE_BUTTON, BLE_BUTTON_PUSH);
break;
#endif
case gKBD_EventPB2_c:
ButtonEventHandler(LIGHT_BUTTON, LIGHT_BUTTON_PUSH);
break;
Expand All @@ -282,6 +293,11 @@ void AppTask::HandleKeyboard(void)
case gKBD_EventPB4_c:
ButtonEventHandler(BLE_BUTTON, BLE_BUTTON_PUSH);
break;
#if !(defined OM15082)
case gKBD_EventLongPB1_c:
ButtonEventHandler(BLE_BUTTON, RESET_BUTTON_PUSH);
break;
#endif
default:
break;
}
Expand Down Expand Up @@ -310,7 +326,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)

void AppTask::ResetActionEventHandler(AppEvent * aEvent)
{
if (aEvent->ButtonEvent.PinNo != RESET_BUTTON)
if (aEvent->ButtonEvent.PinNo != RESET_BUTTON && aEvent->ButtonEvent.PinNo != BLE_BUTTON)
return;

if (sAppTask.mResetTimerActive)
Expand Down
17 changes: 15 additions & 2 deletions examples/lock-app/k32w/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ unlocked). The LED will flash whenever the simulated bolt is in motion from one
position to another.

**Button SW2** can be used to reset the device to a default state. Pressing and
holding Button SW3 for 6 seconds initiates a factory reset. After an initial
holding Button SW2 for 6 seconds initiates a factory reset. After an initial
period of 3 seconds, LED2 D2 and D3 will flash in unison to signal the pending
reset. Holding the button past 6 seconds will cause the device to reset its
persistent configuration and initiate a reboot. The reset action can be
Expand All @@ -133,6 +133,15 @@ enabling Bluetooth LE advertising for a predefined period of time. Also, pushing
this button starts the NFC emulation by writing the onboarding information in
the NTAG.

### No expansion board

In case the **OM15082** Expansion board is not attached to the DK6 board, the
functionality of LED D2 and LED D3 is taken over by LED DS2, respectively LED
DS3, which can be found on the DK6 board.

Also, by long pressing the **USERINTERFACE** button, the factory reset action
will be initiated.

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

## Building
Expand All @@ -154,14 +163,18 @@ user@ubuntu:~/Desktop/git/connectedhomeip$ export K32W061_SDK_ROOT=/home/user/De
user@ubuntu:~/Desktop/git/connectedhomeip$ ./third_party/k32w_sdk/sdk_fixes/patch_k32w_sdk.sh
user@ubuntu:~/Desktop/git/connectedhomeip$ source ./scripts/activate.sh
user@ubuntu:~/Desktop/git/connectedhomeip$ cd examples/lock-app/k32w/
user@ubuntu:~/Desktop/git/connectedhomeip/examples/lock-app/k32w$ gn gen out/debug --args="k32w_sdk_root=\"${K32W061_SDK_ROOT}\" is_debug=true"
user@ubuntu:~/Desktop/git/connectedhomeip/examples/lock-app/k32w$ gn gen out/debug --args="k32w_sdk_root=\"${K32W061_SDK_ROOT}\" chip_with_OM15082=1 is_debug=true"
user@ubuntu:~/Desktop/git/connectedhomeip/examples/lock-app/k32w$ ninja -C out/debug
user@ubuntu:~/Desktop/git/connectedhomeip/examples/lock-app/k32w$ $K32W061_SDK_ROOT/tools/imagetool/sign_images.sh out/debug/
```

Note that "patch_k32w_sdk.sh" script must be run for patching the K32W061 SDK
2.6.3.

Also, in case the OM15082 Expansion Board is not attached to the DK6 board, the
build argument (chip_with_OM15082) inside the gn build instruction should be set
to zero. The argument chip_with_OM15082 is set to zero by default.

In case signing errors are encountered when running the "sign_images.sh" script
install the recommanded packages (python version > 3, pip3, pycrypto,
pycryptodome):
Expand Down
20 changes: 18 additions & 2 deletions examples/lock-app/k32w/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,14 @@ void AppTask::ButtonEventHandler(uint8_t pin_no, uint8_t button_action)
else if (pin_no == BLE_BUTTON)
{
button_event.Handler = BleHandler;
}

#if !(defined OM15082)
if (button_action == RESET_BUTTON_PUSH)
{
button_event.Handler = ResetActionEventHandler;
}
#endif
}
sAppTask.PostEvent(&button_event);
}

Expand Down Expand Up @@ -275,8 +281,13 @@ void AppTask::HandleKeyboard(void)
switch (keyEvent)
{
case gKBD_EventPB1_c:
#if (defined OM15082)
ButtonEventHandler(RESET_BUTTON, RESET_BUTTON_PUSH);
break;
#else
ButtonEventHandler(BLE_BUTTON, BLE_BUTTON_PUSH);
break;
#endif
case gKBD_EventPB2_c:
ButtonEventHandler(LOCK_BUTTON, LOCK_BUTTON_PUSH);
break;
Expand All @@ -286,6 +297,11 @@ void AppTask::HandleKeyboard(void)
case gKBD_EventPB4_c:
ButtonEventHandler(BLE_BUTTON, BLE_BUTTON_PUSH);
break;
#if !(defined OM15082)
case gKBD_EventLongPB1_c:
ButtonEventHandler(BLE_BUTTON, RESET_BUTTON_PUSH);
break;
#endif
default:
break;
}
Expand Down Expand Up @@ -314,7 +330,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)

void AppTask::ResetActionEventHandler(AppEvent * aEvent)
{
if (aEvent->ButtonEvent.PinNo != RESET_BUTTON)
if (aEvent->ButtonEvent.PinNo != RESET_BUTTON && aEvent->ButtonEvent.PinNo != BLE_BUTTON)
return;

if (sAppTask.mResetTimerActive)
Expand Down
11 changes: 9 additions & 2 deletions third_party/k32w_sdk/k32w_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import("${chip_root}/src/crypto/crypto.gni")
declare_args() {
# Location of the k32w SDK.
k32w_sdk_root = getenv("K32W_SDK_ROOT")
chip_with_OM15082 = 0
}

assert(k32w_sdk_root != "", "k32w_sdk_root must be specified")
Expand Down Expand Up @@ -127,8 +128,6 @@ template("k32w_sdk") {
"gPdmNbSegments=32",
"configFRTOS_MEMORY_SCHEME=4",
"osCustomStartup=1",
"OM15082=1",
"gKBD_KeysCount_c=4",
"gLEDsOnTargetBoardCnt_c=2",
"gLED_InvertedMode_d=1",
"ENABLE_RAM_VECTOR_TABLE=1",
Expand Down Expand Up @@ -163,6 +162,14 @@ template("k32w_sdk") {
} else {
defines += [ "gMainThreadStackSize_c=6024" ]
}
if (chip_with_OM15082 == 1) {
defines += [
"gKBD_KeysCount_c=4",
"OM15082=1",
]
} else {
defines += [ "gKBD_KeysCount_c=1" ]
}

if (defined(invoker.defines)) {
defines += invoker.defines
Expand Down