Skip to content

Commit

Permalink
[K32W] Add functionality to run lock-app and lighting-app without OM1…
Browse files Browse the repository at this point in the history
…5082 Expansion board (#6813)

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

LED D2 and LED D3 functionality are redirected to LED DS2 and LED DS3
on the DK6 board if OM15082 is not attached.

Also the factory reset action can be done by long pressing the
USERINTERFACE button on DK6 board.

If the OM15082 Expansion Board is attached to the DK6 board, then
chip_with_OM15082 should be set to 1 in the gn build instruction.
By default chip_with_OM15082 is zero.

Signed-off-by: PetruSicoe <[email protected]>

* Restyled by clang-format

* Restyled by gn

* Restyled by prettier-markdown

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jul 3, 2021
1 parent c957348 commit 1195959
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 10 deletions.
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)
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 @@ -21,6 +21,7 @@ import("${chip_root}/src/platform/K32W/args.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 @@ -128,8 +129,6 @@ template("k32w_sdk") {
"gPdmNbSegments=63",
"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 @@ -172,6 +171,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

0 comments on commit 1195959

Please sign in to comment.