Skip to content

Commit 84efd49

Browse files
[Silabs] Adds fix for BTN low power mode for SiWx917 SoC and power manager (project-chip#35808)
* Decouple UART power requirement handler * Adds refactored BTN handler based on power manager * Fixed incorrect API * Adds changes for interrupt * Replace use of RSI_xx APIs with sl_si91x_xx APIs * Refactor button event handling and UART power requirement handler * Adds comments based on the coding standards Reduce into inline functions * Renaming sl_btn0 -> btn0 * Adds changes to optimize code * Adds CPP define in header * Update function comments * Replace with more readable condition * Updates document to add BTN0 screen cycle action (project-chip#323) * Restyled by prettier-markdown * Adds compilation fix for EFR32 boards * Addressing comments --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 380ddd6 commit 84efd49

File tree

16 files changed

+117
-24
lines changed

16 files changed

+117
-24
lines changed

examples/air-quality-sensor-app/silabs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ combination with JLinkRTTClient as follows:
257257
- _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode
258258
for 30 seconds. The device will then switch to a slower interval advertisement.
259259
After 15 minutes, the advertisement stops.
260+
Additionally, it will cycle through the QR code, application status screen and device status screen, respectively.
260261

261262
- _Pressed and hold for 6 s_ : Initiates the factory reset of the device.
262263
Releasing the button within the 6-second window cancels the factory reset

examples/dishwasher-app/silabs/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ An example showing the use of Matter on the Silicon Labs EFR32 MG24 boards.
1010
- [Flashing the Application](#flashing-the-application)
1111
- [Viewing Logging Output](#viewing-logging-output)
1212
- [Running the Complete Example](#running-the-complete-example)
13+
- [Commissioning](#commissioning)
1314

1415
<hr>
1516

@@ -211,6 +212,7 @@ combination with JLinkRTTClient as follows:
211212
- _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode
212213
for 30 seconds. The device will then switch to a slower interval advertisement.
213214
After 15 minutes, the advertisement stops.
215+
Additionally, it will cycle through the QR code, application status screen and device status screen, respectively.
214216

215217
- _Pressed and hold for 6 s_ : Initiates the factory reset of the device.
216218
Releasing the button within the 6-second window cancels the factory reset

examples/energy-management-app/silabs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ combination with JLinkRTTClient as follows:
257257
- _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode
258258
for 30 seconds. The device will then switch to a slower interval advertisement.
259259
After 15 minutes, the advertisement stops.
260+
Additionally, it will cycle through the QR code, application status screen and device status screen, respectively.
260261

261262
- _Pressed and hold for 6 s_ : Initiates the factory reset of the device.
262263
Releasing the button within the 6-second window cancels the factory reset

examples/light-switch-app/silabs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ combination with JLinkRTTClient as follows:
263263
- _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode
264264
for 30 seconds. The device will then switch to a slower interval advertisement.
265265
After 15 minutes, the advertisement stops.
266+
Additionally, it will cycle through the QR code, application status screen and device status screen, respectively.
266267

267268
- _Pressed and hold for 6 s_ : Initiates the factory reset of the device.
268269
Releasing the button within the 6-second window cancels the factory reset

examples/lighting-app/silabs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ combination with JLinkRTTClient as follows:
245245
- _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode
246246
for 30 seconds. The device will then switch to a slower interval advertisement.
247247
After 15 minutes, the advertisement stops.
248+
Additionally, it will cycle through the QR code, application status screen and device status screen, respectively.
248249

249250
- _Pressed and hold for 6 s_ : Initiates the factory reset of the device.
250251
Releasing the button within the 6-second window cancels the factory reset

examples/lit-icd-app/silabs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ combination with JLinkRTTClient as follows:
250250
- _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode
251251
for 30 seconds. The device will then switch to a slower interval advertisement.
252252
After 15 minutes, the advertisement stops.
253+
Additionally, it will cycle through the QR code, application status screen and device status screen, respectively.
253254

254255
- _Pressed and hold for 6 s_ : Initiates the factory reset of the device.
255256
Releasing the button within the 6-second window cancels the factory reset

examples/lock-app/silabs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ combination with JLinkRTTClient as follows:
277277
- _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode
278278
for 30 seconds. The device will then switch to a slower interval advertisement.
279279
After 15 minutes, the advertisement stops.
280+
Additionally, it will cycle through the QR code, application status screen and device status screen, respectively.
280281

281282
- _Pressed and hold for 6 s_ : Initiates the factory reset of the device.
282283
Releasing the button within the 6-second window cancels the factory reset

examples/platform/silabs/MatterConfig.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#endif
4242

4343
#if defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1
44+
#include "SiWxPlatformInterface.h"
4445
#include "WifiInterfaceAbstraction.h"
4546
#endif // SLI_SI91X_MCU_INTERFACE
4647

@@ -328,6 +329,7 @@ CHIP_ERROR SilabsMatterConfig::InitWiFi(void)
328329
extern "C" void vApplicationIdleHook(void)
329330
{
330331
#if (SLI_SI91X_MCU_INTERFACE && CHIP_CONFIG_ENABLE_ICD_SERVER)
331-
sl_si91x_invoke_btn_press_event();
332+
SiWxPlatformInterface::sl_si91x_btn_event_handler();
333+
SiWxPlatformInterface::sl_si91x_uart_power_requirement_handler();
332334
#endif
333335
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#include <app/icd/server/ICDServerConfig.h>
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
#if CHIP_CONFIG_ENABLE_ICD_SERVER
26+
#if SLI_SI91X_MCU_INTERFACE
27+
#include "sl_si91x_button.h"
28+
#include "sl_si91x_button_pin_config.h"
29+
#include "sl_si91x_driver_gpio.h"
30+
/**
31+
* @brief invoked when button press event is received when in sleep
32+
* @param[in] pin_intr GPIO pin interrupt number.
33+
* @return none.
34+
* @note this is a callback from the Wiseconnect SDK
35+
*/
36+
void gpio_uulp_pin_interrupt_callback(uint32_t pin_intr);
37+
#endif // SLI_SI91X_MCU_INTERFACE
38+
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
39+
#ifdef __cplusplus
40+
}
41+
#endif
42+
43+
namespace chip {
44+
namespace DeviceLayer {
45+
namespace Silabs {
46+
namespace SiWxPlatformInterface {
47+
48+
#if CHIP_CONFIG_ENABLE_ICD_SERVER
49+
#if SLI_SI91X_MCU_INTERFACE
50+
/**
51+
* @brief Required to invoke button press event during sleep as falling edge is not detected
52+
* @param[in] none.
53+
* @note flow is GPIO wakeup due to BTN0 press -> check button state in idle task required as the GPIO interrupt is not
54+
* detected during sleep for BUTTON RELEASED
55+
*/
56+
inline void sl_si91x_btn_event_handler()
57+
{
58+
sl_button_on_change(SL_BUTTON_BTN0_NUMBER,
59+
(sl_si91x_gpio_get_uulp_npss_pin(SL_BUTTON_BTN0_PIN) == LOW) ? BUTTON_PRESSED : BUTTON_RELEASED);
60+
}
61+
62+
/**
63+
* @brief Required to enable MATTER shell UART with ICD feature flag
64+
* @param[in] none.
65+
* @note this requires hardware jumping of the GPIO PINs to work with the baseboard.
66+
*/
67+
void sl_si91x_uart_power_requirement_handler();
68+
#endif // SLI_SI91X_MCU_INTERFACE
69+
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
70+
} // namespace SiWxPlatformInterface
71+
} // namespace Silabs
72+
} // namespace DeviceLayer
73+
} // namespace chip

examples/platform/silabs/SiWx917/SiWxWifiInterface.cpp

+19-12
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ extern "C" {
7474
#endif
7575

7676
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI91X_MCU_INTERFACE
77+
#include "SiWxPlatformInterface.h"
78+
7779
#include "rsi_rom_power_save.h"
78-
#include "sl_si91x_button_pin_config.h"
80+
#include "sl_gpio_board.h"
81+
#include "sl_si91x_driver_gpio.h"
7982
#include "sl_si91x_power_manager.h"
8083
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI91X_MCU_INTERFACE
8184

@@ -522,23 +525,27 @@ int32_t sl_wifi_platform_disconnect(void)
522525

523526
#if CHIP_CONFIG_ENABLE_ICD_SERVER
524527
#if SLI_SI91X_MCU_INTERFACE
525-
// Required to invoke button press event during sleep as falling edge is not detected
526-
void sl_si91x_invoke_btn_press_event(void)
528+
void gpio_uulp_pin_interrupt_callback(uint32_t pin_intr)
527529
{
528-
// TODO: should be removed once we are getting the press interrupt for button 0 with sleep
529-
if (!RSI_NPSSGPIO_GetPin(SL_BUTTON_BTN0_PIN) && !btn0_pressed)
530-
{
531-
sl_button_on_change(SL_BUTTON_BTN0_NUMBER, 1 /* Button Pressed */);
532-
btn0_pressed = true;
533-
}
534-
if (RSI_NPSSGPIO_GetPin(SL_BUTTON_BTN0_PIN))
530+
// UULP_GPIO_2 is used to detect the button 0 press
531+
VerifyOrReturn(pin_intr == RTE_UULP_GPIO_2_PIN, ChipLogError(DeviceLayer, "invalid pin interrupt: %ld", pin_intr));
532+
sl_status_t status = SL_STATUS_OK;
533+
uint8_t pin_intr_status = sl_si91x_gpio_get_uulp_npss_pin(pin_intr);
534+
if (pin_intr_status == LOW)
535535
{
536-
btn0_pressed = false;
536+
// BTN_0 is pressed
537+
// NOTE: the GPIO is masked since the interrupt is invoked before scheduler is started, thus this is required to hand over
538+
// control to scheduler, the PIN is unmasked in the power manager flow before going to sleep
539+
status = sl_si91x_gpio_driver_mask_uulp_npss_interrupt(BIT(pin_intr));
540+
VerifyOrReturn(status == SL_STATUS_OK, ChipLogError(DeviceLayer, "failed to mask interrupt: %ld", status));
537541
}
542+
}
538543

544+
void chip::DeviceLayer::Silabs::SiWxPlatformInterface::sl_si91x_uart_power_requirement_handler(void)
545+
{
539546
#ifdef ENABLE_CHIP_SHELL
540547
// Checking the UULP PIN 1 status to reinit the UART and not allow the device to go to sleep
541-
if (RSI_NPSSGPIO_GetPin(RTE_UULP_GPIO_1_PIN))
548+
if (sl_si91x_gpio_get_uulp_npss_pin(RTE_UULP_GPIO_1_PIN))
542549
{
543550
if (!ps_requirement_added)
544551
{

examples/platform/silabs/wifi/WifiInterfaceAbstraction.h

-3
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ extern "C" {
105105
sl_status_t sl_matter_wifi_platform_init(void);
106106

107107
#if CHIP_CONFIG_ENABLE_ICD_SERVER
108-
#if SLI_SI91X_MCU_INTERFACE
109-
void sl_si91x_invoke_btn_press_event();
110-
#endif // SLI_SI91X_MCU_INTERFACE
111108
#if SLI_SI917
112109
int32_t wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state);
113110
#else

examples/pump-app/silabs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ combination with JLinkRTTClient as follows:
242242
- _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode
243243
for 30 seconds. The device will then switch to a slower interval advertisement.
244244
After 15 minutes, the advertisement stops.
245+
Additionally, it will cycle through the QR code, application status screen and device status screen, respectively.
245246

246247
- _Pressed and hold for 6 s_ : Initiates the factory reset of the device.
247248
Releasing the button within the 6-second window cancels the factory reset

examples/smoke-co-alarm-app/silabs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ combination with JLinkRTTClient as follows:
260260
- _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode
261261
for 30 seconds. The device will then switch to a slower interval advertisement.
262262
After 15 minutes, the advertisement stops.
263+
Additionally, it will cycle through the QR code, application status screen and device status screen, respectively.
263264

264265
- _Pressed and hold for 6 s_ : Initiates the factory reset of the device.
265266
Releasing the button within the 6-second window cancels the factory reset

examples/thermostat/silabs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ combination with JLinkRTTClient as follows:
251251
- _Press and Release_ : Start, or restart, BLE advertisement in fast mode. It will advertise in this mode
252252
for 30 seconds. The device will then switch to a slower interval advertisement.
253253
After 15 minutes, the advertisement stops.
254+
Additionally, it will cycle through the QR code, application status screen and device status screen, respectively.
254255

255256
- _Pressed and hold for 6 s_ : Initiates the factory reset of the device.
256257
Releasing the button within the 6-second window cancels the factory reset

src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,21 @@ void sl_button_on_change(uint8_t btn, uint8_t btnAction)
159159
// Currently the btn0 is pull-up resistor due to which is sends a release event on every wakeup
160160
if (btn == SL_BUTTON_BTN0_NUMBER)
161161
{
162-
if (btnAction == BUTTON_PRESSED)
162+
// if the btn was not pressed and only a release event came, ignore it
163+
// if the btn was already pressed and another press event came, ignore it
164+
// essentially, if both of them are in the same state then ignore it.
165+
VerifyOrReturn(btnAction != btn0_pressed);
166+
167+
if ((btnAction == BUTTON_PRESSED) && (btn0_pressed == false))
163168
{
164169
btn0_pressed = true;
165170
}
166-
else if ((btnAction == BUTTON_RELEASED) && (btn0_pressed == false))
167-
{
168-
// if the btn was not pressed and only a release event came, ignore it
169-
return;
170-
}
171171
else if ((btnAction == BUTTON_RELEASED) && (btn0_pressed == true))
172172
{
173173
btn0_pressed = false;
174174
}
175175
}
176-
#endif /* SL_ICD_ENABLED */
176+
#endif // SL_ICD_ENABLED
177177
if (Silabs::GetPlatform().mButtonCallback == nullptr)
178178
{
179179
return;

third_party/silabs/SiWx917_sdk.gni

+4-1
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,12 @@ template("siwx917_sdk") {
321321
"SL_ACTIVE_MODE_DURATION_MS=${sl_active_mode_duration_ms}",
322322
"SL_IDLE_MODE_DURATION_S=${sl_idle_mode_duration_s}",
323323
"SL_ICD_SUPPORTED_CLIENTS_PER_FABRIC=${sl_icd_supported_clients_per_fabric}",
324-
"SL_SI91X_NPSS_GPIO_BTN_HANDLER=1",
325324
"SL_SI91X_POWER_MANAGER_UC_AVAILABLE=1",
326325
"SL_SI91X_TICKLESS_MODE=1",
326+
327+
# Enable Wakeup source for ICD
328+
"SL_ENABLE_GPIO_WAKEUP_SOURCE=1",
329+
"ENABLE_NPSS_GPIO_2=1",
327330
]
328331
}
329332

0 commit comments

Comments
 (0)