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

[Silabs] Adds LCD timeouts for ICD applications #34703

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion examples/lock-app/silabs/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ CHIP_ERROR AppTask::Init()
GetLCD().ShowQRCode(true);
}
#endif // QR_CODE_ENABLED
#endif
#endif // DISPLAY_ENABLED

chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateClusterState, reinterpret_cast<intptr_t>(nullptr));

Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ void BaseApplication::UpdateDisplay()
#ifdef DISPLAY_ENABLED
UpdateLCDStatusScreen();
slLCD.CycleScreens();
#endif
#endif // DISPLAY_ENABLED
}

void BaseApplication::CancelFunctionTimer()
Expand Down
91 changes: 87 additions & 4 deletions examples/platform/silabs/display/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

#include "sl_board_control.h"

#include <lib/support/logging/CHIPLogging.h>

#define LCD_SIZE 128
#define QR_CODE_VERSION 4
#define QR_CODE_MODULE_SIZE 3
Expand Down Expand Up @@ -75,7 +77,7 @@ CHIP_ERROR SilabsLCD::Init(uint8_t * name, bool initialState)
SILABS_LOG("Board Display enable fail %d", status);
err = CHIP_ERROR_INTERNAL;
}
#endif
#endif // SLI_SI91X_MCU_INTERFACE

/* Initialize the DMD module for the DISPLAY device driver. */
status = DMD_init(0);
Expand Down Expand Up @@ -126,7 +128,30 @@ int SilabsLCD::DrawPixel(void * pContext, int32_t x, int32_t y)

int SilabsLCD::Update(void)
{
return updateDisplay();
int status = 0;
#ifdef SL_ENABLE_ICD_LCD
Copy link
Member

Choose a reason for hiding this comment

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

I don't see where this is defined But I'd also suggest a more specific name to what it enables.
SL_MATTER_TIMED_SCREEN_DISPLAY

SilabsLCD::TurnOn();
#endif // SL_ENABLE_ICD_LCD
status = updateDisplay();
#ifdef SL_ENABLE_ICD_LCD
switch (mCurrentScreen)
{
case DemoScreen:
SilabsLCD::TurnOff(kActivityLCDTimeout);
break;
case StatusScreen:
SilabsLCD::TurnOff(kActivityLCDTimeout);
break;
#ifdef QR_CODE_ENABLED
case QRCodeScreen:
SilabsLCD::TurnOff(kQRCodeScreenTimeout);
break;
#endif // QR_CODE_ENABLED
default:
break;
}
#endif // SL_ENABLE_ICD_LCD
return status;
Comment on lines +131 to +154
Copy link
Member

Choose a reason for hiding this comment

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

use #if rather than #ifdef and make sure the define always exist (1/0)
Also to limit the use of #if and simplify the code I suggest making one function that will turn on the screen and start the timer to turn it off and only use 1 Timeout value for all screen activities.

Suggested change
int status = 0;
#ifdef SL_ENABLE_ICD_LCD
SilabsLCD::TurnOn();
#endif // SL_ENABLE_ICD_LCD
status = updateDisplay();
#ifdef SL_ENABLE_ICD_LCD
switch (mCurrentScreen)
{
case DemoScreen:
SilabsLCD::TurnOff(kActivityLCDTimeout);
break;
case StatusScreen:
SilabsLCD::TurnOff(kActivityLCDTimeout);
break;
#ifdef QR_CODE_ENABLED
case QRCodeScreen:
SilabsLCD::TurnOff(kQRCodeScreenTimeout);
break;
#endif // QR_CODE_ENABLED
default:
break;
}
#endif // SL_ENABLE_ICD_LCD
return status;
#if SL_MATTER_TIMED_SCREEN_DISPLAY
SilabsLCD::TimedScreenDisplay(kActivityLCDTimeout);
#endif
return updateDisplay();

}

void SilabsLCD::WriteDemoUI(bool state)
Expand All @@ -151,6 +176,7 @@ void SilabsLCD::WriteDemoUI()
demoUIClearMainScreen(mName);
demoUIDisplayApp(dState.mainState);
}
SilabsLCD::Update();
}

void SilabsLCD::WriteStatus()
Expand Down Expand Up @@ -195,7 +221,7 @@ void SilabsLCD::WriteStatus()
GLIB_drawStringOnLine(&glibContext, str, lineNb++, GLIB_ALIGN_LEFT, 0, 0, true);
}

updateDisplay();
SilabsLCD::Update();
}

void SilabsLCD::SetCustomUI(customUICB cb)
Expand All @@ -214,7 +240,6 @@ void SilabsLCD::SetScreen(Screen_e screen)
{
return;
}

switch (screen)
{
case DemoScreen:
Expand Down Expand Up @@ -257,6 +282,64 @@ void SilabsLCD::SetStatus(DisplayStatus_t & status)
mStatus = status;
}

CHIP_ERROR SilabsLCD::TurnOn(void)
{
sl_status_t status = SL_STATUS_OK;
#if (SLI_SI91X_MCU_INTERFACE)
sl_memlcd_display_enable();
sl_memlcd_power_on(sl_memlcd_get(), true);
sl_memlcd_clear(sl_memlcd_get());
#else
status = sl_board_enable_display();
#endif // SLI_SI91X_MCU_INTERFACE
if (status != SL_STATUS_OK)
{
ChipLogError(DeviceLayer, "sl_board_enable_display failed: %ld", status);
return CHIP_ERROR_INTERNAL;
}
return CHIP_NO_ERROR;
}

CHIP_ERROR SilabsLCD::TurnOff(void)
{
sl_status_t status = SL_STATUS_OK;
status = SilabsLCD::Clear();
if (status != SL_STATUS_OK)
{
ChipLogError(DeviceLayer, "SilabsLCD::Clear failed: %ld", status);
return CHIP_ERROR_INTERNAL;
}
#if (SLI_SI91X_MCU_INTERFACE)
sl_memlcd_power_on(sl_memlcd_get(), false);
sl_memlcd_display_disable();
#else
status = sl_board_disable_display();
#endif // SLI_SI91X_MCU_INTERFACE
if (status != SL_STATUS_OK)
{
ChipLogError(DeviceLayer, "sl_board_disable_display failed: %ld", status);
return CHIP_ERROR_INTERNAL;
}
return CHIP_NO_ERROR;
}

#ifdef SL_ENABLE_ICD_LCD
CHIP_ERROR SilabsLCD::TurnOff(uint32_t delayInMs)
{
sl_sleeptimer_restart_timer(&lcdTimerHandle, sl_sleeptimer_ms_to_tick(delayInMs), LcdTimeoutCallback, this, 0,
SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG);
return CHIP_NO_ERROR;
}
Comment on lines +326 to +332
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#ifdef SL_ENABLE_ICD_LCD
CHIP_ERROR SilabsLCD::TurnOff(uint32_t delayInMs)
{
sl_sleeptimer_restart_timer(&lcdTimerHandle, sl_sleeptimer_ms_to_tick(delayInMs), LcdTimeoutCallback, this, 0,
SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG);
return CHIP_NO_ERROR;
}
#if SL_MATTER_TIMED_SCREEN_DISPLAY
void SilabsLCD::TimedScreenDisplay(uint32_t screenDisplayDurationMs);
{
TurnOn();
sl_sleeptimer_restart_timer(&lcdTimerHandle, sl_sleeptimer_ms_to_tick(screenDisplayDurationMs), LcdTimeoutCallback, this, 0,
SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG);
}


void SilabsLCD::LcdTimeoutCallback(sl_sleeptimer_timer_handle_t * handle, void * data)
{
// Perform the desired task when the timer expires
(void) handle;
SilabsLCD * sLCD = reinterpret_cast<SilabsLCD *>(data);
sLCD->TurnOff();
}
#endif // SL_ENABLE_ICD_LCD

#ifdef QR_CODE_ENABLED
void SilabsLCD::WriteQRCode()
{
Expand Down
26 changes: 24 additions & 2 deletions examples/platform/silabs/display/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
#endif // QR_CODE_ENABLED

#include "demo-ui.h"
#ifdef SL_ENABLE_ICD_LCD
#include <sl_sleeptimer.h>
#endif // SL_ENABLE_ICD_LCD

#include <lib/core/CHIPError.h>
#include <platform/internal/DeviceNetworkInfo.h>

class SilabsLCD
Expand Down Expand Up @@ -58,6 +63,12 @@ class SilabsLCD
ICDMode_e icdMode = NotICD;
} DisplayStatus_t;

#ifdef SL_ENABLE_ICD_LCD
static const uint32_t kDefaultLCDTimeout = 3000;
static const uint32_t kActivityLCDTimeout = 5000;
static const uint32_t kQRCodeScreenTimeout = 10000;
#endif // SL_ENABLE_ICD_LCD

typedef void (*customUICB)(GLIB_Context_t * context);
CHIP_ERROR Init(uint8_t * name = nullptr, bool initialState = false);
void * Context();
Expand All @@ -74,6 +85,12 @@ class SilabsLCD
void SetStatus(DisplayStatus_t & status);
void WriteStatus();

CHIP_ERROR TurnOn(void);
CHIP_ERROR TurnOff(void);
#ifdef SL_ENABLE_ICD_LCD
CHIP_ERROR TurnOff(uint32_t delayInMs);
#endif // SL_ENABLE_ICD_LCD

#ifdef QR_CODE_ENABLED
void SetQRCode(uint8_t * str, uint32_t size);
void ShowQRCode(bool show);
Expand All @@ -95,13 +112,18 @@ class SilabsLCD
GLIB_Context_t glibContext;

#ifdef SL_DEMO_NAME
uint8_t mName[] = SL_DEMO_NAME
uint8_t mName[] = SL_DEMO_NAME;
#else
uint8_t mName[APP_NAME_MAX_LENGTH + 1];
#endif
customUICB customUI = nullptr;
customUICB customUI = nullptr;
DemoState_t dState;

DisplayStatus_t mStatus;
uint8_t mCurrentScreen = DemoScreen;

#ifdef SL_ENABLE_ICD_LCD
sl_sleeptimer_timer_handle_t lcdTimerHandle;
Copy link
Member

Choose a reason for hiding this comment

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

what is the advantage of using the sleepTimer vs a cmsisosTimer or a ScheduleWork?

static void LcdTimeoutCallback(sl_sleeptimer_timer_handle_t * handle, void * data);
#endif // SL_ENABLE_ICD_LCD
};
Loading