Skip to content

Commit

Permalink
Pull request #317: Cherry pick/9a41c9c3d97 (Thermostat app)
Browse files Browse the repository at this point in the history
Merge in WMN_TOOLS/matter from cherry-pick/9a41c9c3d97 to silabs_1.0

Squashed commit of the following:

commit a3d26430db3e4f5b7dc360625c96af0eccdc9005
Author: Junior Martinez <[email protected]>
Date:   Wed Nov 23 10:24:41 2022 -0500

    update the zap file for this branch versions, add missing header in efr32_sdk.gni on this branch

commit 7c1b1657bec71351344afcaf14e8a06b43bcb8c0
Author: Junior Martinez <[email protected]>
Date:   Tue Nov 22 17:02:22 2022 -0500

    regen zap config to match the zap version of this branch

commit e5b46dc0f3a45008e77ee43dc7411e29930a98cd
Author: jmartinez-silabs <[email protected]>
Date:   Tue Nov 15 02:20:57 2022 +0100

    [Silabs] Update the efr32 Thermostat app (project-chip#23408)

    * Update the efr32 Thermostat app, Use the temperature sensor when available, add a LCD UI for thermostat

    * Address PR comments, Cleanup rebase and regen
  • Loading branch information
jmartinez-silabs authored and rerasool committed Nov 23, 2022
1 parent 0c033e7 commit ecabcd8
Show file tree
Hide file tree
Showing 25 changed files with 1,430 additions and 153 deletions.
49 changes: 49 additions & 0 deletions examples/platform/efr32/TemperatureSensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2019 Google LLC.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "TemperatureSensor.h"

#ifdef __cplusplus
extern "C" {
#endif
// This is a C implementation. Need the ifdef __cplusplus else we get linking issues
#include "sl_sensor_rht.h"

#ifdef __cplusplus
}
#endif

namespace TemperatureSensor {
constexpr uint16_t kSensorTemperatureOffset = 800;

sl_status_t Init()
{
return sl_sensor_rht_init();
}

sl_status_t GetTemp(uint32_t * relativeHumidity, int16_t * temperature)
{
// Sensor resolution 0.001 C
// DataModel resolution 0.01 C
int32_t temp;
sl_status_t status = sl_sensor_rht_get(relativeHumidity, &temp);
*temperature = static_cast<int16_t>(temp / 10) - kSensorTemperatureOffset;
return status;
}
}; // namespace TemperatureSensor
28 changes: 28 additions & 0 deletions examples/platform/efr32/TemperatureSensor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2019 Google LLC.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "sl_status.h"
#include <stdint.h>

namespace TemperatureSensor {
sl_status_t Init();
sl_status_t GetTemp(uint32_t * relativeHumidity, int16_t * temperature);
}; // namespace TemperatureSensor
16 changes: 14 additions & 2 deletions examples/platform/efr32/display/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,20 @@ void SilabsLCD::WriteDemoUI(bool state)
void SilabsLCD::WriteDemoUI()
{
Clear();
demoUIClearMainScreen(mName);
demoUIDisplayApp(dState.mainState);
if (customUI != nullptr)
{
customUI(&glibContext);
}
else
{
demoUIClearMainScreen(mName);
demoUIDisplayApp(dState.mainState);
}
}

void SilabsLCD::SetCustomUI(customUICB cb)
{
customUI = cb;
}

#ifdef QR_CODE_ENABLED
Expand Down
7 changes: 5 additions & 2 deletions examples/platform/efr32/display/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ class SilabsLCD
{

public:
typedef void (*customUICB)(GLIB_Context_t * context);
CHIP_ERROR Init(uint8_t * name = nullptr, bool initialState = false);
void * Context();
int Clear(void);
int DrawPixel(void * pContext, int32_t x, int32_t y);
int Update(void);
void WriteDemoUI(bool state);
void SetCustomUI(customUICB cb);

#ifdef QR_CODE_ENABLED
void SetQRCode(uint8_t * str, uint32_t size);
void ShowQRCode(bool show, bool forceRefresh = false);
Expand Down Expand Up @@ -66,6 +69,6 @@ class SilabsLCD
#else
uint8_t mName[APP_NAME_MAX_LENGTH + 1];
#endif

DemoState_t dState;
customUICB customUI = nullptr;
DemoState_t dState;
};
34 changes: 34 additions & 0 deletions examples/thermostat/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ assert(current_os == "freertos")

efr32_project_dir = "${chip_root}/examples/thermostat/efr32"
examples_plat_dir = "${chip_root}/examples/platform/efr32"
efr32_sdk_root = "${chip_root}/third_party/silabs/gecko_sdk"

declare_args() {
# Dump memory usage at link time.
Expand All @@ -59,6 +60,10 @@ declare_args() {

# Argument to Disable IPv4 for wifi(rs911)
chip_enable_wifi_ipv4 = false

# Enable the temperature sensor
# Some boards do not have a temperature sensor
use_temp_sensor = silabs_board != "BRD2703A" && silabs_board != "BRD4319A"
}

declare_args() {
Expand Down Expand Up @@ -133,6 +138,7 @@ efr32_sdk("sdk") {
"${efr32_project_dir}/include",
"${examples_plat_dir}",
"${chip_root}/src/lib",
"${efr32_sdk_root}/app/common/util/app_assert",
]

defines = [
Expand Down Expand Up @@ -172,6 +178,18 @@ efr32_sdk("sdk") {
defines += [ "SL_WFX_CONFIG_SCAN" ]
}
}
if (use_temp_sensor) {
include_dirs += [
"${efr32_sdk_root}/platform/driver/i2cspm/inc",
"${efr32_sdk_root}/app/bluetooth/common/sensor_rht",
"${efr32_sdk_root}/app/bluetooth/common/sensor_rht/config",
"${efr32_sdk_root}/hardware/driver/si70xx/inc",
"${efr32_sdk_root}/app/bluetooth/common/sensor_select",
"${efr32_sdk_root}/platform/common/config",
]

defines += [ "USE_TEMP_SENSOR" ]
}
}

efr32_executable("thermostat_app") {
Expand All @@ -186,6 +204,8 @@ efr32_executable("thermostat_app") {
"${examples_plat_dir}/init_efrPlatform.cpp",
"${examples_plat_dir}/matter_config.cpp",
"src/AppTask.cpp",
"src/SensorManager.cpp",
"src/TemperatureManager.cpp",
"src/ZclCallbacks.cpp",
"src/main.cpp",
]
Expand All @@ -194,6 +214,19 @@ efr32_executable("thermostat_app") {
sources += [ "${examples_plat_dir}/LEDWidget.cpp" ]
}

if (use_temp_sensor) {
sources += [
"${efr32_sdk_root}/app/bluetooth/common/sensor_rht/sl_sensor_rht.c",
"${efr32_sdk_root}/app/bluetooth/common/sensor_select/sl_sensor_select.c",
"${efr32_sdk_root}/hardware/driver/si70xx/src/sl_si70xx.c",
"${efr32_sdk_root}/platform/common/src/sl_status.c",
"${efr32_sdk_root}/platform/driver/i2cspm/src/sl_i2cspm.c",
"${efr32_sdk_root}/platform/emlib/src/em_i2c.c",
"${examples_plat_dir}/TemperatureSensor.cpp",
"${sdk_support_root}/matter/efr32/${silabs_family}/${silabs_board}/autogen/sl_i2cspm_init.c",
]
}

if (chip_enable_pw_rpc || chip_build_libshell || enable_openthread_cli ||
use_wf200 || use_rs911x) {
sources += [ "${examples_plat_dir}/uart.cpp" ]
Expand Down Expand Up @@ -268,6 +301,7 @@ efr32_executable("thermostat_app") {
sources += [
"${examples_plat_dir}/display/demo-ui.c",
"${examples_plat_dir}/display/lcd.cpp",
"src/ThermostatUI.cpp",
]
include_dirs += [ "${examples_plat_dir}/display" ]
defines += [
Expand Down
6 changes: 0 additions & 6 deletions examples/thermostat/efr32/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ struct AppEvent
{
kEventType_Button = 0,
kEventType_Timer,
kEventType_Light,
kEventType_Install,
};

Expand All @@ -44,11 +43,6 @@ struct AppEvent
{
void * Context;
} TimerEvent;
struct
{
uint8_t Action;
int32_t Actor;
} LightEvent;
};

EventHandler Handler;
Expand Down
17 changes: 11 additions & 6 deletions examples/thermostat/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@
#include <stdbool.h>
#include <stdint.h>

#ifdef DISPLAY_ENABLED
#include "ThermostatUI.h"
#endif

#include "AppEvent.h"
#include "BaseApplication.h"
#include "FreeRTOS.h"
#include "SensorManager.h"
#include "TemperatureManager.h"
#include "sl_simple_button_instances.h"
#include "timers.h" // provides FreeRTOS timer support
#include <app/clusters/identify-server/identify-server.h>
Expand Down Expand Up @@ -69,6 +75,11 @@ class AppTask : public BaseApplication

CHIP_ERROR StartAppTask();

/**
* @brief Request an update of the Thermostat LCD UI
*/
void UpdateThermoStatUI();

/**
* @brief Event handler when a button is pressed
* Function posts an event for button processing
Expand Down Expand Up @@ -112,11 +123,5 @@ class AppTask : public BaseApplication
*/
static void ButtonHandler(AppEvent * aEvent);

/**
* @brief PB1 Button event processing function
* Function triggers a thermostat action sent to the CHIP task
*
* @param aEvent button event being processed
*/
static void ThermostatActionEventHandler(AppEvent * aEvent);
};
2 changes: 1 addition & 1 deletion examples/thermostat/efr32/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
*
* 0x8005: example lighting app
*/
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x8004
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x800E

/**
* CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION
Expand Down
48 changes: 48 additions & 0 deletions examples/thermostat/efr32/include/SensorManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
*
* Copyright (c) 2019 Google LLC.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <stdbool.h>
#include <stdint.h>

#include "AppEvent.h"

#include "FreeRTOS.h"
#include "timers.h" // provides FreeRTOS timer support
#include <app-common/zap-generated/attributes/Accessors.h>
#include <lib/core/CHIPError.h>

class SensorManager
{
public:
CHIP_ERROR Init();

private:
friend SensorManager & SensorMgr();

// Reads new generated sensor value, stores it, and updates local temperature attribute
static void SensorTimerEventHandler(TimerHandle_t xTimer);

static SensorManager sSensorManager;
};

inline SensorManager & SensorMgr()
{
return SensorManager::sSensorManager;
}
69 changes: 69 additions & 0 deletions examples/thermostat/efr32/include/TemperatureManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
*
* Copyright (c) 2019 Google LLC.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <stdbool.h>
#include <stdint.h>

#include "AppEvent.h"

#include "FreeRTOS.h"
#include "timers.h" // provides FreeRTOS timer support
#include <app-common/zap-generated/attributes/Accessors.h>

#include <lib/core/CHIPError.h>

using namespace chip;

// AppCluster Spec Table 85.
enum ThermMode
{
OFF = 0,
AUTO,
NOT_USED,
COOL,
HEAT,
};

class TemperatureManager
{
public:
CHIP_ERROR Init();
void AttributeChangeHandler(EndpointId endpointId, AttributeId attributeId, uint8_t * value, uint16_t size);
uint8_t GetMode();
int8_t GetCurrentTemp();
int8_t GetHeatingSetPoint();
int8_t GetCoolingSetPoint();

private:
friend TemperatureManager & TempMgr();

int8_t mCurrentTempCelsius;
int8_t mCoolingCelsiusSetPoint;
int8_t mHeatingCelsiusSetPoint;
uint8_t mThermMode;

int8_t ConvertToPrintableTemp(int16_t temperature);
static TemperatureManager sTempMgr;
};

inline TemperatureManager & TempMgr()
{
return TemperatureManager::sTempMgr;
}
Loading

0 comments on commit ecabcd8

Please sign in to comment.