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

[SL-UP] Adding app event for the LCD update #368

Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
addressing review comments
chirag-silabs committed Mar 25, 2025
commit 111beae27f9073fcc5cf935d469ef1d29ebad48d
2 changes: 1 addition & 1 deletion .github/workflows/silabs-common-build.yaml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: ghcr.io/project-chip/chip-build-efr32:115
image: ghcr.io/project-chip/chip-build-efr32:95

strategy:
matrix:
6 changes: 6 additions & 0 deletions examples/lighting-app/silabs/include/AppEvent.h
Original file line number Diff line number Diff line change
@@ -41,6 +41,12 @@ struct AppEvent
{
uint8_t Action;
} ButtonEvent;
#ifdef DISPLAY_ENABLED
struct
{
void * screen;
} LCDEvent;
#endif
struct
{
void * Context;
18 changes: 11 additions & 7 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
@@ -252,8 +252,9 @@ void BaseApplicationDelegate::OnCommissioningWindowClosed()
slLCD.GetScreen(screen);
VerifyOrReturn(screen == SilabsLCD::Screen_e::QRCodeScreen);
AppEvent event;
event.Type = AppEvent::kEventType_LCD;
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
event.Type = AppEvent::kEventType_LCD;
event.LCDEvent.screen = reinterpret_cast<void *>(static_cast<uintptr_t>(SilabsLCD::Screen_e::DemoScreen));
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
BaseApplication::PostEvent(&event);
#endif // QR_CODE_ENABLED
#endif // DISPLAY_ENABLED
@@ -625,8 +626,9 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
}

AppEvent event;
event.Type = AppEvent::kEventType_LCD;
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
event.Type = AppEvent::kEventType_LCD;
event.LCDEvent.screen = reinterpret_cast<void *>(static_cast<uintptr_t>(SilabsLCD::Screen_e::CycleScreen));
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
PostEvent(&event);
}
}
@@ -635,7 +637,8 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
void BaseApplication::UpdateDisplayHandler(AppEvent * aEvent)
{
VerifyOrReturn(aEvent->Type == AppEvent::kEventType_LCD);
AppTask::GetAppTask().UpdateDisplay();
SilabsLCD::Screen_e screen = static_cast<SilabsLCD::Screen_e>(reinterpret_cast<uintptr_t>(aEvent->LCDEvent.screen));
(screen == SilabsLCD::Screen_e::CycleScreen) ? AppTask::GetAppTask().UpdateDisplay() : AppTask::GetLCD().SetScreen(screen);
}

void BaseApplication::UpdateDisplay()
@@ -942,8 +945,9 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t)
if (screen == SilabsLCD::Screen_e::StatusScreen)
{
AppEvent event;
event.Type = AppEvent::kEventType_LCD;
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
event.Type = AppEvent::kEventType_LCD;
event.LCDEvent.screen = reinterpret_cast<void *>(static_cast<uintptr_t>(SilabsLCD::Screen_e::StatusScreen));
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
PostEvent(&event);
}
#endif // DISPLAY_ENABLED
1 change: 1 addition & 0 deletions examples/platform/silabs/display/lcd.h
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ class SilabsLCD
QRCodeScreen,
#endif
InvalidScreen,
CycleScreen,
} Screen_e;

typedef enum icdMode
4 changes: 3 additions & 1 deletion src/platform/silabs/wifi/BUILD.gn
Original file line number Diff line number Diff line change
@@ -139,7 +139,9 @@ source_set("wifi-platform") {
"${silabs_platform_dir}/wifi/SiWx/WifiInterface.cpp",
"${silabs_platform_dir}/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp",
"${silabs_platform_dir}/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h",
"${wifi_sdk_root}/components/service/network_manager/src/sl_net_for_lwip.c",

# Wi-Fi Config - Using the file sdk support until the wiseconnect file is fixed
"${matter_support_root}/sdk-copies/components/service/network_manager/src/sl_net_for_lwip.c",
]

public_deps += [ "${lwip_root}:lwip" ]
114 changes: 91 additions & 23 deletions src/platform/silabs/wifi/SiWx/WifiInterface.cpp
Original file line number Diff line number Diff line change
@@ -100,11 +100,16 @@ bool ps_requirement_added = false;
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

bool hasNotifiedWifiConnectivity = false;
bool hasNotifiedIPV6 = false;
#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4)
bool hasNotifiedIPV4 = false;
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */

wfx_wifi_scan_ext_t temp_reset;

osSemaphoreId_t sScanCompleteSemaphore;
osSemaphoreId_t sScanInProgressSemaphore;
osTimerId_t sDHCPTimer;
osMessageQueueId_t sWifiEventQueue = nullptr;

sl_net_wifi_lwip_context_t wifi_client_context;
@@ -203,6 +208,27 @@ constexpr uint8_t kWfxQueueSize = 10;
// TODO: Figure out why we actually need this, we are already handling failure and retries somewhere else.
constexpr uint16_t kWifiScanTimeoutTicks = 10000;

void DHCPTimerEventHandler(void * arg)
{
WifiEvent event = WifiEvent::kStationDhcpPoll;
sl_matter_wifi_post_event(event);
}

void CancelDHCPTimer(void)
{
VerifyOrReturn(osTimerIsRunning(sDHCPTimer), ChipLogDetail(DeviceLayer, "CancelDHCPTimer: timer not running"));
VerifyOrReturn(osTimerStop(sDHCPTimer) == osOK, ChipLogError(DeviceLayer, "CancelDHCPTimer: failed to stop timer"));
}

void StartDHCPTimer(uint32_t timeout)
{
// Cancel timer if already started
CancelDHCPTimer();

VerifyOrReturn(osTimerStart(sDHCPTimer, pdMS_TO_TICKS(timeout)) == osOK,
ChipLogError(DeviceLayer, "StartDHCPTimer: failed to start timer"));
}

sl_status_t sl_wifi_siwx917_init(void)
{
sl_status_t status = SL_STATUS_OK;
@@ -331,10 +357,7 @@ sl_status_t SetWifiConfigurations()
VerifyOrReturnError(status == SL_STATUS_OK, status,
ChipLogError(DeviceLayer, "sl_wifi_set_listen_interval failed: 0x%lx", status));

// This is be triggered on the disconnect use case, providing the amount of TA tries
// Setting the TA retry to 1 and giving the control to the M4 for improved power efficiency
// When max_retry_attempts is set to 0, TA will retry indefinitely.
sl_wifi_advanced_client_configuration_t client_config = { .max_retry_attempts = 1 };
sl_wifi_advanced_client_configuration_t client_config = { .max_retry_attempts = 5 };
status = sl_wifi_set_advanced_client_configuration(SL_WIFI_CLIENT_INTERFACE, &client_config);
VerifyOrReturnError(status == SL_STATUS_OK, status,
ChipLogError(DeviceLayer, "sl_wifi_set_advanced_client_configuration failed: 0x%lx", status));
@@ -491,6 +514,11 @@ sl_status_t sl_matter_wifi_platform_init(void)
sWifiEventQueue = osMessageQueueNew(kWfxQueueSize, sizeof(WifiEvent), nullptr);
VerifyOrReturnError(sWifiEventQueue != nullptr, SL_STATUS_ALLOCATION_FAILED);

// Create timer for DHCP polling
// TODO: Use LWIP timer instead of creating a new one here
sDHCPTimer = osTimerNew(DHCPTimerEventHandler, osTimerPeriodic, nullptr, nullptr);
VerifyOrReturnError(sDHCPTimer != nullptr, SL_STATUS_ALLOCATION_FAILED);

return status;
}

@@ -634,29 +662,53 @@ sl_status_t bg_scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_

/// NotifyConnectivity
/// @brief Notify the application about the connectivity status if it has not been notified yet.
/// Helper function for HandleDHCPPolling.
void NotifyConnectivity(void)
{
VerifyOrReturn(!hasNotifiedWifiConnectivity);
wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac);
hasNotifiedWifiConnectivity = true;
}

/// NotifySuccessfulConnection
/// @brief Processing function responsible for notifying the upper layers of a succesful connection attempt.
void NotifySuccessfulConnection(void)
void HandleDHCPPolling(void)
{
WifiEvent event;

// TODO: Notify the application that the interface is not set up or Chipdie here because we are in an unkonwn state
struct netif * sta_netif = &wifi_client_context.netif;
VerifyOrReturn(sta_netif != nullptr, ChipLogError(DeviceLayer, "HandleDHCPPolling: failed to get STA netif"));

#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4)
wfx_dhcp_got_ipv4((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr);
uint8_t dhcp_state = dhcpclient_poll(sta_netif);
if (dhcp_state == DHCP_ADDRESS_ASSIGNED && !hasNotifiedIPV4)
{
wfx_dhcp_got_ipv4((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr);
hasNotifiedIPV4 = true;
event = WifiEvent::kStationDhcpDone;
sl_matter_wifi_post_event(event);
NotifyConnectivity();
}
else if (dhcp_state == DHCP_OFF)
{
wfx_ip_changed_notify(IP_STATUS_FAIL);
hasNotifiedIPV4 = false;
}
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
char addrStr[chip::Inet::IPAddress::kMaxStringLength] = { 0 };
VerifyOrReturn(ip6addr_ntoa_r(netif_ip6_addr(sta_netif, 0), addrStr, sizeof(addrStr)) != nullptr);
ChipLogProgress(DeviceLayer, "SLAAC OK: linklocal addr: %s", addrStr);
wfx_ipv6_notify(GET_IPV6_SUCCESS);
NotifyConnectivity();
/* Checks if the assigned IPv6 address is preferred by evaluating
* the first block of IPv6 address ( block 0)
*/
if ((ip6_addr_ispreferred(netif_ip6_addr_state(sta_netif, 0))) && !hasNotifiedIPV6)
{
char addrStr[chip::Inet::IPAddress::kMaxStringLength] = { 0 };
VerifyOrReturn(ip6addr_ntoa_r(netif_ip6_addr(sta_netif, 0), addrStr, sizeof(addrStr)) != nullptr);
ChipLogProgress(DeviceLayer, "SLAAC OK: linklocal addr: %s", addrStr);
wfx_ipv6_notify(GET_IPV6_SUCCESS);
hasNotifiedIPV6 = true;
event = WifiEvent::kStationDhcpDone;
sl_matter_wifi_post_event(event);
NotifyConnectivity();
}
}

void sl_matter_wifi_post_event(WifiEvent event)
{
sl_status_t status = osMessageQueuePut(sWifiEventQueue, &event, 0, 0);
@@ -668,14 +720,19 @@ void sl_matter_wifi_post_event(WifiEvent event)
// Chipdie, etc.
}
}
/// ResetConnectivityNotificationFlags
/// ResetDHCPNotificationFlags
/// @brief Reset the flags that are used to notify the application about DHCP connectivity
/// and emits a WifiEvent::kConnectionComplete event to trigger DHCP polling checks. Helper function for ProcessEvent.
void ResetConnectivityNotificationFlags(void)
/// and emits a WifiEvent::kStationDoDhcp event to trigger DHCP polling checks. Helper function for ProcessEvent.
void ResetDHCPNotificationFlags(void)
{

#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4)
hasNotifiedIPV4 = false;
#endif // CHIP_DEVICE_CONFIG_ENABLE_IPV4
hasNotifiedIPV6 = false;
hasNotifiedWifiConnectivity = false;

WifiEvent event = WifiEvent::kConnectionComplete;
WifiEvent event = WifiEvent::kStationDoDhcp;
sl_matter_wifi_post_event(event);
}

@@ -687,7 +744,7 @@ void ProcessEvent(WifiEvent event)
case WifiEvent::kStationConnect:
ChipLogDetail(DeviceLayer, "WifiEvent::kStationConnect");
wfx_rsi.dev_state.Set(WifiState::kStationConnected);
ResetConnectivityNotificationFlags();
ResetDHCPNotificationFlags();
break;

case WifiEvent::kStationDisconnect: {
@@ -700,7 +757,7 @@ void ProcessEvent(WifiEvent event)
.Clear(WifiState::kStationDhcpDone);

/* TODO: Implement disconnect notify */
ResetConnectivityNotificationFlags();
ResetDHCPNotificationFlags();
#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4)
wfx_ip_changed_notify(0); // for IPV4
wfx_ip_changed_notify(IP_STATUS_FAIL);
@@ -777,9 +834,20 @@ void ProcessEvent(WifiEvent event)
JoinWifiNetwork();
break;

case WifiEvent::kConnectionComplete:
ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kConnectionComplete");
NotifySuccessfulConnection();
case WifiEvent::kStationDoDhcp:
ChipLogDetail(DeviceLayer, "WifiEvent::kStationDoDhcp");
StartDHCPTimer(WFX_RSI_DHCP_POLL_INTERVAL);
break;

case WifiEvent::kStationDhcpDone:
ChipLogDetail(DeviceLayer, "WifiEvent::kStationDhcpDone");
CancelDHCPTimer();
break;

case WifiEvent::kStationDhcpPoll:
ChipLogDetail(DeviceLayer, "WifiEvent::kStationDhcpPoll");
HandleDHCPPolling();
break;

default:
break;
18 changes: 9 additions & 9 deletions src/platform/silabs/wifi/WifiInterfaceAbstraction.h
Original file line number Diff line number Diff line change
@@ -87,15 +87,15 @@ enum class WifiState : uint16_t

enum class WifiEvent : uint8_t
{
kStationConnect = 0,
kStationDisconnect = 1,
kAPStart = 2,
kAPStop = 3,
kScan = 4, /* This is used as scan result and start */
kStationStartJoin = 5,
kConnectionComplete = 6,
kStationDhcpDone = 7,
kStationDhcpPoll = 8
kStationConnect = 0,
kStationDisconnect = 1,
kAPStart = 2,
kAPStop = 3,
kScan = 4, /* This is used as scan result and start */
kStationStartJoin = 5,
kStationDoDhcp = 6,
kStationDhcpDone = 7,
kStationDhcpPoll = 8
};

typedef enum
6 changes: 3 additions & 3 deletions src/platform/silabs/wifi/rs911x/WifiInterface.cpp
Original file line number Diff line number Diff line change
@@ -606,7 +606,7 @@ void HandleDHCPPolling(void)

/** ResetDHCPNotificationFlags
* @brief Reset the flags that are used to notify the application about DHCP connectivity
* and emits a WifiEvent::kConnectionComplete event to trigger DHCP polling checks. Helper function for ProcessEvent.
* and emits a WifiEvent::kStationDoDhcp event to trigger DHCP polling checks. Helper function for ProcessEvent.
*/
void ResetDHCPNotificationFlags(void)
{
@@ -618,7 +618,7 @@ void ResetDHCPNotificationFlags(void)
hasNotifiedIPV6 = false;
hasNotifiedWifiConnectivity = false;

outEvent = WifiEvent::kConnectionComplete;
outEvent = WifiEvent::kStationDoDhcp;
sl_matter_wifi_post_event(outEvent);
}

@@ -752,7 +752,7 @@ void ProcessEvent(WifiEvent event)
sl_wifi_platform_join_network();
}
break;
case WifiEvent::kConnectionComplete: {
case WifiEvent::kStationDoDhcp: {
StartDHCPTimer(WFX_RSI_DHCP_POLL_INTERVAL);
}
break;
4 changes: 3 additions & 1 deletion src/platform/silabs/wifi/rs911x/rs9117.gni
Original file line number Diff line number Diff line change
@@ -44,6 +44,9 @@ rs9117_src_sapi = [
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/ncp_interface/spi/sl_si91x_spi.c",
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/ncp_interface/sl_si91x_ncp_driver.c",

# Wi-Fi Config - Using the file sdk support until the wiseconnect file is fixed
"${matter_support_root}/sdk-copies/components/service/network_manager/src/sl_net_for_lwip.c",

# wifi component
"${wifi_sdk_root}/components/protocol/wifi/src/sl_wifi_basic_credentials.c",
"${wifi_sdk_root}/components/protocol/wifi/src/sl_wifi_callback_framework.c",
@@ -52,7 +55,6 @@ rs9117_src_sapi = [
# basic_network_manager component
"${wifi_sdk_root}/components/service/network_manager/src/sl_net_credentials.c",
"${wifi_sdk_root}/components/service/network_manager/src/sl_net_basic_profiles.c",
"${wifi_sdk_root}/components/service/network_manager/src/sl_net_for_lwip.c",

# si91x_basic_buffers component
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/memory/malloc_buffers.c",