Skip to content

Commit

Permalink
Merge remote-tracking branch 'jharrow/Add_WaterHeater_to_EFR32' into …
Browse files Browse the repository at this point in the history
…fix/silabs_evse
  • Loading branch information
mkardous-silabs committed Sep 20, 2024
2 parents caa42db + f7cb5a9 commit 05be810
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 20 deletions.
33 changes: 33 additions & 0 deletions examples/energy-management-app/silabs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ import("${examples_common_plat_dir}/args.gni")
declare_args() {
# Dump memory usage at link time.
chip_print_memory_usage = false

# Enable test event triggers by default: Disable these in production devices
sl_enable_energy_evse_trigger = true
sl_enable_energy_reporting_trigger = true
sl_enable_water_heater_management_trigger = true
sl_enable_device_energy_management_trigger = true

# Device Energy Management feature support - only one of these can be true
# or both can be disabled if forecasting is not supported
sl_dem_support_power_forecast_reporting = true
sl_dem_support_state_forecast_reporting = false

# Only one of these examples should be enabled
sl_enable_example_evse_device = true
sl_enable_example_water_heater_device = false
}

if (slc_generate) {
Expand Down Expand Up @@ -105,6 +120,7 @@ if (wifi_soc) {
"${chip_root}/examples/energy-management-app/energy-management-common/device-energy-management/include",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/include",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-reporting/include",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/include",
]

if (use_wf200) {
Expand Down Expand Up @@ -134,6 +150,17 @@ silabs_executable("energy-management-app") {
include_dirs = [ "include" ]
defines = []

defines += [
"SL_MATTER_CONFIG_ENABLE_ENERGY_EVSE_TRIGGER=${sl_enable_energy_evse_trigger}",
"SL_MATTER_CONFIG_ENABLE_ENERGY_REPORTING_TRIGGER=${sl_enable_energy_reporting_trigger}",
"SL_MATTER_CONFIG_ENABLE_WATER_HEATER_MANAGEMENT_TRIGGER=${sl_enable_water_heater_management_trigger}",
"SL_MATTER_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER=${sl_enable_device_energy_management_trigger}",
"SL_MATTER_CONFIG_DEM_SUPPORT_POWER_FORECAST_REPORTING=${sl_dem_support_power_forecast_reporting}",
"SL_MATTER_CONFIG_DEM_SUPPORT_STATE_FORECAST_REPORTING=${sl_dem_support_state_forecast_reporting}",
"SL_MATTER_CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE=${sl_enable_example_evse_device}",
"SL_CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE=${sl_enable_example_water_heater_device}",
]

if (silabs_board == "BRD2704A") {
defines += [ "SL_STATUS_LED=0" ]
}
Expand All @@ -156,6 +183,12 @@ silabs_executable("energy-management-app") {
"${chip_root}/examples/energy-management-app/energy-management-common/energy-reporting/src/EnergyReportingEventTriggers.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-reporting/src/FakeReadings.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-reporting/src/PowerTopologyDelegate.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WaterHeaterMain.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmDelegateImpl.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmInstance.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmMain.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmManufacturer.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/water-heater-mode.cpp",
"${examples_common_plat_dir}/main.cpp",
"src/AppTask.cpp",
]
Expand Down
26 changes: 21 additions & 5 deletions examples/energy-management-app/silabs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ An example showing the use of CHIP on the Silicon Labs EFR32 MG12 and MG24.
## Introduction

The EFR32 Energy Management example provides a baseline demonstration of a EVSE
device, built using Matter and the Silicon Labs gecko SDK. It can be controlled
by a Chip controller over an Openthread or Wifi network..
or Water Heater device, built using Matter and the Silicon Labs gecko SDK. It
can be controlled by a Chip controller over an Openthread or Wifi network.

The EFR32 device can be commissioned over Bluetooth Low Energy where the device
and the Chip controller will exchange security information with the Rendez-vous
Expand All @@ -45,9 +45,9 @@ If the LCD is enabled, the LCD on the Silabs WSTK shows a QR Code containing the
needed commissioning information for the BLE connection and starting the
Rendez-vous procedure.

The EVSE example is intended to serve both as a means to explore the workings of
Matter as well as a template for creating real products based on the Silicon
Labs platform.
The EVSE and Water Heater examples are intended to serve both as a means to
explore the workings of Matter Energy Management as well as a template for
creating real products based on the Silicon Labs platform.

## Building

Expand Down Expand Up @@ -99,9 +99,25 @@ Labs platform.
$ git submodule update --init
$ source third_party/connectedhomeip/scripts/activate.sh
$ export SILABS_BOARD=BRD4187C

To build the EVSE example

$ gn gen out/debug
$ ninja -C out/debug

To build the Water Heater example you can change the args to gn gen (see
BUILD.gn for arg options)

$ gn gen out/debug --args='chip_enable_example_evse_device=false chip_enable_example_water_heater_device=true'
$ ninja -C out/debug

To change Device Energy Management feature support (e.g. Power forecast or
State forecast reporting), you can change the args to gn gen (see BUILD.gn
for arg options)

$ gn gen out/debug --args='chip_dem_support_state_forecast_reporting=true chip_dem_support_power_forecast_reporting=false'
$ ninja -C out/debug

- To delete generated executable, libraries and object files use:

$ cd ~/connectedhomeip/examples/energy-management-app/silabs
Expand Down
4 changes: 2 additions & 2 deletions examples/energy-management-app/silabs/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include "AppEvent.h"
#include "BaseApplication.h"
#include "EnergyEvseManager.h"

#include "FreeRTOS.h"
#include "timers.h" // provides FreeRTOS timer support
#include <ble/BLEEndPoint.h>
Expand Down Expand Up @@ -80,7 +80,7 @@ class AppTask : public BaseApplication

private:
static AppTask sAppTask;
static void EvseActionEventHandler(AppEvent * aEvent);
static void EnergyManagementActionEventHandler(AppEvent * aEvent);

static void UpdateClusterState(intptr_t context);

Expand Down
106 changes: 93 additions & 13 deletions examples/energy-management-app/silabs/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
#include "AppConfig.h"
#include "AppEvent.h"
#include "LEDWidget.h"
#if SL_MATTER_CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE
#include <EnergyEvseMain.h>
#endif
#if SL_CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE
#include <WaterHeaterMain.h>
#endif
#include <app-common/zap-generated/cluster-enums.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Attributes.h>
Expand All @@ -45,10 +50,21 @@

#ifdef SL_MATTER_TEST_EVENT_TRIGGER_ENABLED
#include <app/TestEventTriggerDelegate.h>
#include <app/clusters/device-energy-management-server/DeviceEnergyManagementTestEventTriggerHandler.h>
#include <app/clusters/electrical-energy-measurement-server/EnergyReportingTestEventTriggerHandler.h>

#if SL_MATTER_CONFIG_ENABLE_ENERGY_EVSE_TRIGGER
#include <app/clusters/energy-evse-server/EnergyEvseTestEventTriggerHandler.h>
#endif
#if SL_MATTER_CONFIG_ENABLE_ENERGY_REPORTING_TRIGGER
#include <app/clusters/electrical-energy-measurement-server/EnergyReportingTestEventTriggerHandler.h>
#endif
#if SL_MATTER_CONFIG_ENABLE_WATER_HEATER_MANAGEMENT_TRIGGER
#include <app/clusters/water-heater-management-server/WaterHeaterManagementTestEventTriggerHandler.h>
#endif
#if SL_MATTER_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER
#include <app/clusters/device-energy-management-server/DeviceEnergyManagementTestEventTriggerHandler.h>
#endif

#endif // SL_MATTER_TEST_EVENT_TRIGGER_ENABLED

#if (defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT) || defined(SIWX_917))
#define EVSE_LED 1
Expand All @@ -60,14 +76,15 @@
#define APP_EVSE_SWITCH 1

namespace {
LEDWidget sEvseLED;
LEDWidget sEnergyManagementLED;
}

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::DeviceEnergyManagement;
using namespace chip::app::Clusters::DeviceEnergyManagement::Attributes;
using namespace chip::app::Clusters::WaterHeaterManagement;
using namespace ::chip::DeviceLayer;
using namespace ::chip::DeviceLayer::Silabs;
using namespace ::chip::DeviceLayer::Internal;
Expand All @@ -85,9 +102,21 @@ namespace Clusters {
namespace DeviceEnergyManagement {

// Keep track of the parsed featureMap option
#if (SL_MATTER_CONFIG_DEM_SUPPORT_POWER_FORECAST_REPORTING) && (SL_MATTER_CONFIG_DEM_SUPPORT_STATE_FORECAST_REPORTING)
#error Cannot define SL_MATTER_CONFIG_DEM_SUPPORT_POWER_FORECAST_REPORTING and SL_MATTER_CONFIG_DEM_SUPPORT_STATE_FORECAST_REPORTING
#endif

#if SL_MATTER_CONFIG_DEM_SUPPORT_POWER_FORECAST_REPORTING
static chip::BitMask<Feature> sFeatureMap(Feature::kPowerAdjustment, Feature::kPowerForecastReporting,
Feature::kStateForecastReporting, Feature::kStartTimeAdjustment, Feature::kPausable,
Feature::kForecastAdjustment, Feature::kConstraintBasedAdjustment);
Feature::kStartTimeAdjustment, Feature::kPausable, Feature::kForecastAdjustment,
Feature::kConstraintBasedAdjustment);
#elif SL_MATTER_CONFIG_DEM_SUPPORT_STATE_FORECAST_REPORTING
static chip::BitMask<Feature> sFeatureMap(Feature::kPowerAdjustment, Feature::kStateForecastReporting,
Feature::kStartTimeAdjustment, Feature::kPausable, Feature::kForecastAdjustment,
Feature::kConstraintBasedAdjustment);
#else
static chip::BitMask<Feature> sFeatureMap(Feature::kPowerAdjustment);
#endif

chip::BitMask<Feature> GetFeatureMapFromCmdLine()
{
Expand All @@ -104,14 +133,33 @@ AppTask AppTask::sAppTask;
void ApplicationInit()
{
chip::DeviceLayer::PlatformMgr().LockChipStack();
SILABS_LOG("==================================================");
#if SL_MATTER_CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE
SILABS_LOG("energy-management-example EVSE starting. featureMap 0x%08lx", DeviceEnergyManagement::sFeatureMap.Raw());

EvseApplicationInit();
sEvseLED.Init(EVSE_LED);
#endif // CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE

#if SL_CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE
SILABS_LOG("energy-management-example WaterHeater starting. featureMap 0x%08lx", DeviceEnergyManagement::sFeatureMap.Raw());

FullWhmApplicationInit();
#endif // CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE
SILABS_LOG("==================================================");

sEnergyManagementLED.Init(EVSE_LED);
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
}
void ApplicationShutdown()
{
chip::DeviceLayer::PlatformMgr().LockChipStack();
#if SL_MATTER_CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE
EvseApplicationShutdown();
#endif // CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE

#if SL_CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE
FullWhmApplicationShutdown();
#endif // CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
}

Expand All @@ -121,7 +169,11 @@ CHIP_ERROR AppTask::Init()
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);

#ifdef DISPLAY_ENABLED
GetLCD().Init((uint8_t *) "energy-management-App");
#if SL_MATTER_CONFIG_ENABLE_EXAMPLE_EVSE_DEVICE
GetLCD().Init((uint8_t *) "energy-management-App (EVSE)");
#elif SL_CONFIG_ENABLE_EXAMPLE_WATER_HEATER_DEVICE
GetLCD().Init((uint8_t *) "energy-management-App (WaterHeater)");
#endif
#endif

err = BaseApplication::Init();
Expand All @@ -134,14 +186,42 @@ CHIP_ERROR AppTask::Init()
ApplicationInit();

#ifdef SL_MATTER_TEST_EVENT_TRIGGER_ENABLED
if (Server::GetInstance().GetTestEventTriggerDelegate() != nullptr)
TestEventTriggerDelegate * pTestEventDelegate = Server::GetInstance().GetTestEventTriggerDelegate();

#if SL_MATTER_CONFIG_ENABLE_ENERGY_EVSE_TRIGGER
static EnergyEvseTestEventTriggerHandler sEnergyEvseTestEventTriggerHandler;
if (pTestEventDelegate != nullptr)
{
Server::GetInstance().GetTestEventTriggerDelegate()->AddHandler(&sEnergyEvseTestEventTriggerHandler);
Server::GetInstance().GetTestEventTriggerDelegate()->AddHandler(&sEnergyReportingTestEventTriggerHandler);
Server::GetInstance().GetTestEventTriggerDelegate()->AddHandler(&sDeviceEnergyManagementTestEventTriggerHandler);
VerifyOrDie(pTestEventDelegate->AddHandler(&sEnergyEvseTestEventTriggerHandler) == CHIP_NO_ERROR);
}
#endif

#if SL_MATTER_CONFIG_ENABLE_ENERGY_REPORTING_TRIGGER
static EnergyReportingTestEventTriggerHandler sEnergyReportingTestEventTriggerHandler;
if (pTestEventDelegate != nullptr)
{
VerifyOrDie(pTestEventDelegate->AddHandler(&sEnergyReportingTestEventTriggerHandler) == CHIP_NO_ERROR);
}

#endif
#if SL_MATTER_CONFIG_ENABLE_WATER_HEATER_MANAGEMENT_TRIGGER
static WaterHeaterManagementTestEventTriggerHandler sWaterHeaterManagementTestEventTriggerHandler;

if (pTestEventDelegate != nullptr)
{
VerifyOrDie(pTestEventDelegate->AddHandler(&sWaterHeaterManagementTestEventTriggerHandler) == CHIP_NO_ERROR);
}
#endif
#if SL_MATTER_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER
static DeviceEnergyManagementTestEventTriggerHandler sDeviceEnergyManagementTestEventTriggerHandler;
if (pTestEventDelegate != nullptr)
{
VerifyOrDie(pTestEventDelegate->AddHandler(&sDeviceEnergyManagementTestEventTriggerHandler) == CHIP_NO_ERROR);
}
#endif

#endif // SL_MATTER_TEST_EVENT_TRIGGER_ENABLED

// Update the LCD with the Stored value. Show QR Code if not provisioned
#ifdef DISPLAY_ENABLED
GetLCD().WriteDemoUI(LightMgr().IsLightOn());
Expand Down Expand Up @@ -190,7 +270,7 @@ void AppTask::AppTaskMain(void * pvParameter)
}
}

void AppTask::EvseActionEventHandler(AppEvent * aEvent)
void AppTask::EnergyManagementActionEventHandler(AppEvent * aEvent)
{
bool initiated = false;
int32_t actor;
Expand Down Expand Up @@ -223,7 +303,7 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)

if (button == APP_EVSE_SWITCH && btnAction == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonPressed))
{
button_event.Handler = EvseActionEventHandler;
button_event.Handler = EnergyManagementActionEventHandler;
AppTask::GetAppTask().PostEvent(&button_event);
}
else if (button == APP_FUNCTION_BUTTON)
Expand Down

0 comments on commit 05be810

Please sign in to comment.