Skip to content

Commit 1197b62

Browse files
feat: Add support LCD timeouts for ICD applications.
1 parent 3ef28b2 commit 1197b62

File tree

3 files changed

+76
-12
lines changed

3 files changed

+76
-12
lines changed

examples/platform/silabs/BaseApplication.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ void BaseApplication::UpdateDisplay()
561561
#ifdef DISPLAY_ENABLED
562562
UpdateLCDStatusScreen();
563563
slLCD.CycleScreens();
564-
#endif
564+
#endif // DISPLAY_ENABLED
565565
}
566566

567567
void BaseApplication::CancelFunctionTimer()

examples/platform/silabs/display/lcd.cpp

+57-11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
#include "sl_board_control.h"
3737

38+
#include <lib/support/logging/CHIPLogging.h>
39+
3840
#define LCD_SIZE 128
3941
#define QR_CODE_VERSION 4
4042
#define QR_CODE_MODULE_SIZE 3
@@ -214,18 +216,29 @@ void SilabsLCD::SetScreen(Screen_e screen)
214216
{
215217
return;
216218
}
217-
219+
#ifdef SL_ENABLE_ICD_LCD
220+
TurnOn();
221+
#endif // SL_ENABLE_ICD_LCD
218222
switch (screen)
219223
{
220224
case DemoScreen:
221225
WriteDemoUI();
226+
#ifdef SL_ENABLE_ICD_LCD
227+
TurnOff(kActivityLCDTimeout);
228+
#endif // SL_ENABLE_ICD_LCD
222229
break;
223230
case StatusScreen:
224231
WriteStatus();
232+
#ifdef SL_ENABLE_ICD_LCD
233+
TurnOff(kActivityLCDTimeout);
234+
#endif // SL_ENABLE_ICD_LCD
225235
break;
226236
#ifdef QR_CODE_ENABLED
227237
case QRCodeScreen:
228238
WriteQRCode();
239+
#ifdef SL_ENABLE_ICD_LCD
240+
TurnOff(kQRCodeScreenTimeout);
241+
#endif // SL_ENABLE_ICD_LCD
229242
break;
230243
#endif
231244
default:
@@ -259,27 +272,60 @@ void SilabsLCD::SetStatus(DisplayStatus_t & status)
259272

260273
CHIP_ERROR SilabsLCD::TurnOn(void)
261274
{
262-
CHIP_ERROR err = CHIP_NO_ERROR;
263-
EMSTATUS status;
275+
sl_status_t status = SL_STATUS_OK;
264276
#if (SLI_SI91X_MCU_INTERFACE)
265-
sl_memlcd_display_enable();
277+
status = sl_memlcd_power_on(sl_memlcd_get(), true);
266278
#else
267279
status = sl_board_enable_display();
280+
#endif // SLI_SI91X_MCU_INTERFACE
268281
if (status != SL_STATUS_OK)
269282
{
270-
SILABS_LOG("Board Display enable fail %d", status);
271-
err = CHIP_ERROR_INTERNAL;
283+
ChipLogError(DeviceLayer, "sl_board_enable_display failed: %ld", status);
284+
return CHIP_ERROR_INTERNAL;
272285
}
273-
#endif // SLI_SI91X_MCU_INTERFACE
274-
return err;
286+
return CHIP_NO_ERROR;
275287
}
276288

277289
CHIP_ERROR SilabsLCD::TurnOff(void)
278290
{
279-
CHIP_ERROR err = CHIP_NO_ERROR;
280-
Clear();
281-
sl_board_disable_display();
291+
sl_status_t status = SL_STATUS_OK;
292+
status = SilabsLCD::Clear();
293+
if (status != SL_STATUS_OK)
294+
{
295+
ChipLogError(DeviceLayer, "LCD clear failed: %ld", status);
296+
return CHIP_ERROR_INTERNAL;
297+
}
298+
#if (SLI_SI91X_MCU_INTERFACE)
299+
status = sl_memlcd_power_on(sl_memlcd_get(), false);
300+
#else
301+
status = sl_board_disable_display();
302+
#endif // SLI_SI91X_MCU_INTERFACE
303+
if (status != SL_STATUS_OK)
304+
{
305+
ChipLogError(DeviceLayer, "sl_board_disable_display failed: %ld", status);
306+
return CHIP_ERROR_INTERNAL;
307+
}
308+
ChipLogDetail(DeviceLayer, "SilabsLCD::TurnOff completed");
309+
return CHIP_NO_ERROR;
310+
}
311+
312+
#ifdef SL_ENABLE_ICD_LCD
313+
CHIP_ERROR SilabsLCD::TurnOff(uint32_t delayInMs)
314+
{
315+
ChipLogDetail(DeviceLayer, "start LCD timeout timer");
316+
sl_sleeptimer_restart_timer(&lcdTimerHandle, sl_sleeptimer_ms_to_tick(delayInMs), LcdTimeoutCallback, this, 0,
317+
SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG);
318+
return CHIP_NO_ERROR;
319+
}
320+
321+
void SilabsLCD::LcdTimeoutCallback(sl_sleeptimer_timer_handle_t * handle, void * data)
322+
{
323+
// Perform the desired task when the timer expires
324+
(void) handle;
325+
SilabsLCD * sLCD = reinterpret_cast<SilabsLCD *>(data);
326+
sLCD->TurnOff();
282327
}
328+
#endif // SL_ENABLE_ICD_LCD
283329

284330
#ifdef QR_CODE_ENABLED
285331
void SilabsLCD::WriteQRCode()

examples/platform/silabs/display/lcd.h

+18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
#endif // QR_CODE_ENABLED
2727

2828
#include "demo-ui.h"
29+
#ifdef SL_ENABLE_ICD_LCD
30+
#include <sl_sleeptimer.h>
31+
#endif // SL_ENABLE_ICD_LCD
32+
33+
#include <lib/core/CHIPError.h>
2934
#include <platform/internal/DeviceNetworkInfo.h>
3035

3136
class SilabsLCD
@@ -58,6 +63,12 @@ class SilabsLCD
5863
ICDMode_e icdMode = NotICD;
5964
} DisplayStatus_t;
6065

66+
#ifdef SL_ENABLE_ICD_LCD
67+
static const uint32_t kDefaultLCDTimeout = 3000;
68+
const uint32_t kActivityLCDTimeout = 5000;
69+
const uint32_t kQRCodeScreenTimeout = 10000;
70+
#endif // SL_ENABLE_ICD_LCD
71+
6172
typedef void (*customUICB)(GLIB_Context_t * context);
6273
CHIP_ERROR Init(uint8_t * name = nullptr, bool initialState = false);
6374
void * Context();
@@ -75,6 +86,9 @@ class SilabsLCD
7586

7687
CHIP_ERROR TurnOn(void);
7788
CHIP_ERROR TurnOff(void);
89+
#ifdef SL_ENABLE_ICD_LCD
90+
CHIP_ERROR TurnOff(uint32_t delayInMs);
91+
#endif // SL_ENABLE_ICD_LCD
7892

7993
#ifdef QR_CODE_ENABLED
8094
void SetQRCode(uint8_t * str, uint32_t size);
@@ -108,4 +122,8 @@ class SilabsLCD
108122

109123
DisplayStatus_t mStatus;
110124
uint8_t mCurrentScreen = DemoScreen;
125+
#ifdef SL_ENABLE_ICD_LCD
126+
sl_sleeptimer_timer_handle_t lcdTimerHandle;
127+
static void LcdTimeoutCallback(sl_sleeptimer_timer_handle_t * handle, void * data);
128+
#endif // SL_ENABLE_ICD_LCD
111129
};

0 commit comments

Comments
 (0)