From a8d5ae825640d456f6c7278df47fdc7817ad88c8 Mon Sep 17 00:00:00 2001 From: Gatien Chapon Date: Thu, 7 Nov 2024 15:54:31 +0100 Subject: [PATCH] Revert "[nxp fromtree] [Silabs] Refactor Sensor code (#35979) (#35992)" This reverts commit cf6395725a4fe2d8245feca2eb2576fda0bcf474. Signed-off-by: Gatien Chapon --- examples/platform/silabs/Si70xxSensor.cpp | 67 ------------------- examples/platform/silabs/Si70xxSensor.h | 48 ------------- examples/platform/silabs/SiWx917/BUILD.gn | 7 -- .../platform/silabs/TemperatureSensor.cpp | 62 +++++++++++++++++ examples/platform/silabs/TemperatureSensor.h | 28 ++++++++ examples/platform/silabs/display/demo-ui.c | 1 + examples/platform/silabs/display/lcd.h | 3 +- examples/platform/silabs/efr32/BUILD.gn | 7 -- examples/thermostat/silabs/BUILD.gn | 28 ++++++++ .../thermostat/silabs/src/SensorManager.cpp | 42 ++++++------ third_party/silabs/efr32_sdk.gni | 27 -------- third_party/silabs/matter_support | 2 +- third_party/silabs/silabs_board.gni | 15 ----- 13 files changed, 141 insertions(+), 196 deletions(-) delete mode 100644 examples/platform/silabs/Si70xxSensor.cpp delete mode 100644 examples/platform/silabs/Si70xxSensor.h create mode 100644 examples/platform/silabs/TemperatureSensor.cpp create mode 100644 examples/platform/silabs/TemperatureSensor.h diff --git a/examples/platform/silabs/Si70xxSensor.cpp b/examples/platform/silabs/Si70xxSensor.cpp deleted file mode 100644 index 0b03ca040f1f69..00000000000000 --- a/examples/platform/silabs/Si70xxSensor.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * 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 "sl_board_control.h" -#include "sl_i2cspm_instances.h" -#include "sl_si70xx.h" -#include -#include - -namespace { - -constexpr uint16_t kSensorTemperatureOffset = 475; -bool initialized = false; - -} // namespace - -namespace Si70xxSensor { - -sl_status_t Init() -{ - sl_status_t status = SL_STATUS_OK; - - status = sl_board_enable_sensor(SL_BOARD_SENSOR_RHT); - VerifyOrReturnError(status == SL_STATUS_OK, status); - - status = sl_si70xx_init(sl_i2cspm_sensor, SI7021_ADDR); - VerifyOrReturnError(status == SL_STATUS_OK, status); - - initialized = true; - return status; -} - -sl_status_t GetSensorData(uint16_t & relativeHumidity, int16_t & temperature) -{ - VerifyOrReturnError(initialized, SL_STATUS_NOT_INITIALIZED); - - sl_status_t status = SL_STATUS_OK; - int32_t tempTemperature = 0; - uint32_t tempHumidity = 0; - - status = sl_si70xx_measure_rh_and_temp(sl_i2cspm_sensor, SI7021_ADDR, &tempHumidity, &tempTemperature); - VerifyOrReturnError(status == SL_STATUS_OK, status); - - // Sensor precision is milliX. We need to reduce to change the precision to centiX to fit with the cluster attributes presicion. - temperature = static_cast(tempTemperature / 10) - kSensorTemperatureOffset; - relativeHumidity = static_cast(tempHumidity / 10); - - return status; -} - -}; // namespace Si70xxSensor diff --git a/examples/platform/silabs/Si70xxSensor.h b/examples/platform/silabs/Si70xxSensor.h deleted file mode 100644 index 8dc31a8dafd5ca..00000000000000 --- a/examples/platform/silabs/Si70xxSensor.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * - * 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 - -namespace Si70xxSensor { - -/** - * @brief Initialises the Si70xx Sensor. - * - * @return sl_status_t SL_STATUS_OK if there were no errors occured during initialisation. - * Error if an underlying platform error occured - */ -sl_status_t Init(); - -/** - * @brief Reads Humidity and temperature values from the Si70xx sensor. - * The init function must be called before calling the GetSensorData. - * - * @param[out] relativeHumidity Relative humidity percentage in centi-pourcentage (1000 == 10.00%) - * @param[out] temperature Ambiant temperature in centi-celsium (1000 == 10.00C) - * - * @return sl_status_t SL_STATUS_OK if there were no errors occured during initialisation. - * SL_STATUS_NOT_INITIALIZED if the sensor was not initialised - * Error if an underlying platform error occured - */ -sl_status_t GetSensorData(uint16_t & relativeHumidity, int16_t & temperature); - -}; // namespace Si70xxSensor diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn index cf7b7aedbf1cfa..156fb38e4916fc 100644 --- a/examples/platform/silabs/SiWx917/BUILD.gn +++ b/examples/platform/silabs/SiWx917/BUILD.gn @@ -252,13 +252,6 @@ source_set("siwx917-common") { public_deps += [ ":test-event-trigger" ] } - if (sl_enable_si70xx_sensor) { - sources += [ - "${silabs_common_plat_dir}/Si70xxSensor.cpp", - "${silabs_common_plat_dir}/Si70xxSensor.h", - ] - } - if (app_data_model != "") { public_deps += [ app_data_model ] } diff --git a/examples/platform/silabs/TemperatureSensor.cpp b/examples/platform/silabs/TemperatureSensor.cpp new file mode 100644 index 00000000000000..d7e13e19932526 --- /dev/null +++ b/examples/platform/silabs/TemperatureSensor.cpp @@ -0,0 +1,62 @@ +/* + * + * 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" + +#include "sl_board_control.h" +#include "sl_i2cspm_instances.h" +#include "sl_si70xx.h" + +namespace TemperatureSensor { +constexpr uint16_t kSensorTemperatureOffset = 800; +static bool initialized = false; + +sl_status_t Init() +{ + sl_status_t status; + sl_i2cspm_t * rht_sensor = sl_i2cspm_sensor; + (void) sl_board_enable_sensor(SL_BOARD_SENSOR_RHT); + + status = sl_si70xx_init(rht_sensor, SI7021_ADDR); + initialized = (SL_STATUS_OK == status); + return status; +} + +sl_status_t GetTemp(uint32_t * relativeHumidity, int16_t * temperature) +{ + if (!initialized) + { + return SL_STATUS_NOT_INITIALIZED; + } + + // Sensor resolution 0.001 C + // DataModel resolution 0.01 C + sl_status_t status; + sl_i2cspm_t * rht_sensor = sl_i2cspm_sensor; + int32_t temp = 0; + status = sl_si70xx_measure_rh_and_temp(rht_sensor, SI7021_ADDR, relativeHumidity, &temp); + + if (temperature != nullptr) + { + *temperature = static_cast(temp / 10) - kSensorTemperatureOffset; + } + + return status; +} +}; // namespace TemperatureSensor diff --git a/examples/platform/silabs/TemperatureSensor.h b/examples/platform/silabs/TemperatureSensor.h new file mode 100644 index 00000000000000..116287e9a37155 --- /dev/null +++ b/examples/platform/silabs/TemperatureSensor.h @@ -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 + +namespace TemperatureSensor { +sl_status_t Init(); +sl_status_t GetTemp(uint32_t * relativeHumidity, int16_t * temperature); +}; // namespace TemperatureSensor diff --git a/examples/platform/silabs/display/demo-ui.c b/examples/platform/silabs/display/demo-ui.c index d909cb1f885172..e0fe37ec9cb09b 100644 --- a/examples/platform/silabs/display/demo-ui.c +++ b/examples/platform/silabs/display/demo-ui.c @@ -167,5 +167,6 @@ void demoUIClearMainScreen(uint8_t * name) { GLIB_clear(&glibContext); demoUIDisplayHeader((char *) name); + demoUIDisplayApp(false); demoUIDisplayProtocols(); } diff --git a/examples/platform/silabs/display/lcd.h b/examples/platform/silabs/display/lcd.h index 61fa816743f644..b62664c9b47346 100644 --- a/examples/platform/silabs/display/lcd.h +++ b/examples/platform/silabs/display/lcd.h @@ -65,7 +65,6 @@ class SilabsLCD int DrawPixel(void * pContext, int32_t x, int32_t y); int Update(void); void WriteDemoUI(bool state); - void WriteDemoUI(); void SetCustomUI(customUICB cb); void GetScreen(Screen_e & screen); @@ -86,6 +85,8 @@ class SilabsLCD bool protocol1 = false; /* data */ } DemoState_t; + void WriteDemoUI(); + #ifdef QR_CODE_ENABLED void WriteQRCode(); void LCDFillRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h); diff --git a/examples/platform/silabs/efr32/BUILD.gn b/examples/platform/silabs/efr32/BUILD.gn index f5c79a22524812..91cd2c1a0a58d6 100644 --- a/examples/platform/silabs/efr32/BUILD.gn +++ b/examples/platform/silabs/efr32/BUILD.gn @@ -308,13 +308,6 @@ source_set("efr32-common") { public_deps += [ ":test-event-trigger" ] } - if (sl_enable_si70xx_sensor) { - sources += [ - "${silabs_common_plat_dir}/Si70xxSensor.cpp", - "${silabs_common_plat_dir}/Si70xxSensor.h", - ] - } - if (app_data_model != "") { public_deps += [ app_data_model ] } diff --git a/examples/thermostat/silabs/BUILD.gn b/examples/thermostat/silabs/BUILD.gn index f51ee14825d27e..75b2f75c15c863 100644 --- a/examples/thermostat/silabs/BUILD.gn +++ b/examples/thermostat/silabs/BUILD.gn @@ -47,6 +47,10 @@ import("${examples_common_plat_dir}/args.gni") declare_args() { # Dump memory usage at link time. chip_print_memory_usage = false + + # Enable the temperature sensor + # Some boards do not have a temperature sensor + use_temp_sensor = false } if (wifi_soc) { @@ -108,6 +112,19 @@ if (wifi_soc) { "PW_RPC_ENABLED", ] } + + 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" ] + } } } @@ -124,6 +141,17 @@ silabs_executable("thermostat_app") { "src/ZclCallbacks.cpp", ] + if (use_temp_sensor) { + sources += [ + "${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_common_plat_dir}/TemperatureSensor.cpp", + "${sdk_support_root}/matter/efr32/${silabs_family}/${silabs_board}/autogen/sl_i2cspm_init.c", + ] + } + if (!disable_lcd) { sources += [ "src/ThermostatUI.cpp" ] } diff --git a/examples/thermostat/silabs/src/SensorManager.cpp b/examples/thermostat/silabs/src/SensorManager.cpp index 3522e9f5a30d1d..abecd899d5370f 100644 --- a/examples/thermostat/silabs/src/SensorManager.cpp +++ b/examples/thermostat/silabs/src/SensorManager.cpp @@ -26,15 +26,14 @@ #include "AppEvent.h" #include "AppTask.h" -#if defined(SL_MATTER_USE_SI70XX_SENSOR) && SL_MATTER_USE_SI70XX_SENSOR -#include "Si70xxSensor.h" -#endif // defined(SL_MATTER_USE_SI70XX_SENSOR) && SL_MATTER_USE_SI70XX_SENSOR +#ifdef USE_TEMP_SENSOR +#include "TemperatureSensor.h" +#endif /********************************************************** * Defines and Constants *********************************************************/ using namespace chip; -using namespace chip::app; using namespace ::chip::DeviceLayer; constexpr EndpointId kThermostatEndpoint = 1; @@ -46,10 +45,10 @@ constexpr uint16_t kMinTemperatureDelta = 50; // 0.5 degree Celcius *********************************************************/ SensorManager SensorManager::sSensorManager; -#if !(defined(SL_MATTER_USE_SI70XX_SENSOR) && (SL_MATTER_USE_SI70XX_SENSOR)) +#ifndef USE_TEMP_SENSOR constexpr uint16_t kSimulatedReadingFrequency = (60000 / kSensorTImerPeriodMs); // Change Simulated number at each minutes static int16_t mSimulatedTemp[] = { 2300, 2400, 2800, 2550, 2200, 2125, 2100, 2600, 1800, 2700 }; -#endif // !(defined(SL_MATTER_USE_SI70XX_SENSOR) && (SL_MATTER_USE_SI70XX_SENSOR)) +#endif CHIP_ERROR SensorManager::Init() { @@ -62,13 +61,13 @@ CHIP_ERROR SensorManager::Init() return APP_ERROR_CREATE_TIMER_FAILED; } -#if defined(SL_MATTER_USE_SI70XX_SENSOR) && SL_MATTER_USE_SI70XX_SENSOR - if (SL_STATUS_OK != Si70xxSensor::Init()) +#ifdef USE_TEMP_SENSOR + if (SL_STATUS_OK != TemperatureSensor::Init()) { SILABS_LOG("Failed to Init Sensor"); return CHIP_ERROR_INTERNAL; } -#endif // defined(SL_MATTER_USE_SI70XX_SENSOR) && SL_MATTER_USE_SI70XX_SENSOR +#endif // Update Temp immediatly at bootup SensorTimerEventHandler(nullptr); @@ -82,20 +81,19 @@ void SensorManager::SensorTimerEventHandler(void * arg) int16_t temperature = 0; static int16_t lastTemperature = 0; -#if defined(SL_MATTER_USE_SI70XX_SENSOR) && SL_MATTER_USE_SI70XX_SENSOR +#ifdef USE_TEMP_SENSOR int32_t tempSum = 0; - uint16_t humidity = 0; + uint32_t humidity = 0; for (uint8_t i = 0; i < 100; i++) { - if (SL_STATUS_OK != Si70xxSensor::GetSensorData(humidity, temperature)) + if (SL_STATUS_OK != TemperatureSensor::GetTemp(&humidity, &temperature)) { SILABS_LOG("Failed to read Temperature !!!"); } tempSum += temperature; } temperature = static_cast(tempSum / 100); - #else static uint8_t nbOfRepetition = 0; static uint8_t simulatedIndex = 0; @@ -111,20 +109,18 @@ void SensorManager::SensorTimerEventHandler(void * arg) simulatedIndex++; nbOfRepetition = 0; } -#endif // defined(SL_MATTER_USE_SI70XX_SENSOR) && SL_MATTER_USE_SI70XX_SENSOR +#endif // USE_TEMP_SENSOR SILABS_LOG("Sensor Temp is : %d", temperature); - MarkAttributeDirty reportState = MarkAttributeDirty::kNo; if ((temperature >= (lastTemperature + kMinTemperatureDelta)) || temperature <= (lastTemperature - kMinTemperatureDelta)) { - reportState = MarkAttributeDirty::kIfChanged; - } + lastTemperature = temperature; + PlatformMgr().LockChipStack(); + // The SensorMagager shouldn't be aware of the Endpoint ID TODO Fix this. + // TODO Per Spec we should also apply the Offset stored in the same cluster before saving the temp - lastTemperature = temperature; - PlatformMgr().LockChipStack(); - // The SensorMagager shouldn't be aware of the Endpoint ID TODO Fix this. - // TODO Per Spec we should also apply the Offset stored in the same cluster before saving the temp - app::Clusters::Thermostat::Attributes::LocalTemperature::Set(kThermostatEndpoint, temperature, reportState); - PlatformMgr().UnlockChipStack(); + app::Clusters::Thermostat::Attributes::LocalTemperature::Set(kThermostatEndpoint, temperature); + PlatformMgr().UnlockChipStack(); + } } diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index 146077372f4cc6..470c812505f966 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -415,17 +415,6 @@ template("efr32_sdk") { _include_dirs += [ "${chip_root}/third_party/silabs/mqtt/stack" ] } - if (sl_enable_si70xx_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", - ] - } - # Note that we're setting the mbedTLS and PSA configuration files through a # define. This means the build system by default does not pick up changes in # the content of these, only when changing the filename itself. @@ -683,12 +672,6 @@ template("efr32_sdk") { defines += [ "CHIP_CONFIG_SYNCHRONOUS_REPORTS_ENABLED=1" ] } - if (sl_enable_si70xx_sensor) { - defines += [ "SL_MATTER_USE_SI70XX_SENSOR=1" ] - } else { - defines += [ "SL_MATTER_USE_SI70XX_SENSOR=0" ] - } - cflags = [] foreach(include_dir, _include_dirs) { cflags += [ "-isystem" + rebase_path(include_dir, root_build_dir) ] @@ -1085,16 +1068,6 @@ template("efr32_sdk") { ] } - if (sl_enable_si70xx_sensor) { - sources += [ - "${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", - "${sdk_support_root}/matter/efr32/${silabs_family}/${silabs_board}/autogen/sl_i2cspm_init.c", - ] - } - public_deps = [ ":efr32_mbedtls_config", "${segger_rtt_root}:segger_rtt", diff --git a/third_party/silabs/matter_support b/third_party/silabs/matter_support index 841d43db7e8687..c3e993cea4aad3 160000 --- a/third_party/silabs/matter_support +++ b/third_party/silabs/matter_support @@ -1 +1 @@ -Subproject commit 841d43db7e86877636cd73b5244da4c34d38d544 +Subproject commit c3e993cea4aad32adc178fe487afb66822f0b42d diff --git a/third_party/silabs/silabs_board.gni b/third_party/silabs/silabs_board.gni index 03b2ea7cb67cb5..213417976d3318 100644 --- a/third_party/silabs/silabs_board.gni +++ b/third_party/silabs/silabs_board.gni @@ -53,9 +53,6 @@ declare_args() { # Self-provision enabled use_provision_channel = false - - # Temperature Sensor support - sl_enable_si70xx_sensor = false } declare_args() { @@ -78,9 +75,6 @@ if (silabs_board == "BRD4338A" || silabs_board == "BRD2605A") { silabs_mcu = "SiWG917M111MGTBA" wifi_soc = true - assert(!sl_enable_si70xx_sensor, - "${silabs_board} does not support the si90xx sensor!") - # EFR32 MG24 series ---------- } else if (silabs_board == "BRD4186A" || silabs_board == "BRD4187A") { variant = string_replace(silabs_board, "A", "C") @@ -110,9 +104,6 @@ if (silabs_board == "BRD4338A" || silabs_board == "BRD2605A") { show_qr_code = false disable_lcd = true - assert(!sl_enable_si70xx_sensor, - "${silabs_board} does not support the si90xx sensor!") - # EFR32 MG24 Modules series ---------- } else if (silabs_board == "BRD4316A") { silabs_family = "mgm24" @@ -137,9 +128,6 @@ if (silabs_board == "BRD4338A" || silabs_board == "BRD2605A") { use_external_flash = false show_qr_code = false disable_lcd = true - - assert(!sl_enable_si70xx_sensor, - "${silabs_board} does not support the si90xx sensor!") } else if (silabs_board == "BRD2704A") { silabs_family = "mgm24" silabs_mcu = "MGM240PB32VNA" @@ -149,9 +137,6 @@ if (silabs_board == "BRD4338A" || silabs_board == "BRD2605A") { use_external_flash = false show_qr_code = false disable_lcd = true - - assert(!sl_enable_si70xx_sensor, - "${silabs_board} does not support the si90xx sensor!") } else if (silabs_board == "BRD4318A") { silabs_family = "mgm24" silabs_mcu = "MGM240SD22VNA"