From 82e9188dc27e71a6e9d23b98e5501d90f24fbb63 Mon Sep 17 00:00:00 2001 From: mahesh Date: Mon, 1 Dec 2025 13:41:03 +0530 Subject: [PATCH] components/esp_matter: add closure_dimension cluster in esp_matter --- .../data_model/esp_matter_attribute.cpp | 78 +++++++++ .../data_model/esp_matter_attribute.h | 18 +++ .../data_model/esp_matter_cluster.cpp | 80 ++++++++- .../data_model/esp_matter_cluster.h | 10 ++ .../data_model/esp_matter_command.cpp | 17 ++ .../data_model/esp_matter_command.h | 7 + .../esp_matter_delegate_callbacks.cpp | 12 ++ .../esp_matter_delegate_callbacks.h | 1 + .../data_model/esp_matter_feature.cpp | 152 ++++++++++++++++++ .../data_model/esp_matter_feature.h | 54 +++++++ .../private/esp_matter_cluster_revisions.h | 4 + 11 files changed, 432 insertions(+), 1 deletion(-) diff --git a/components/esp_matter/data_model/esp_matter_attribute.cpp b/components/esp_matter/data_model/esp_matter_attribute.cpp index 93b507f15..c67f222d7 100644 --- a/components/esp_matter/data_model/esp_matter_attribute.cpp +++ b/components/esp_matter/data_model/esp_matter_attribute.cpp @@ -4987,5 +4987,83 @@ attribute_t *create_latch_control_modes(cluster_t *cluster, uint8_t value) } /* closure_control */ +namespace closure_dimension { +namespace attribute { +attribute_t *create_current_state(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::CurrentState::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_array(value, length, count)); +} + +attribute_t *create_target_state(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::TargetState::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_array(value, length, count)); +} + +attribute_t *create_resolution(cluster_t *cluster, uint16_t value) +{ + return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::Resolution::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_uint16(value)); +} + +attribute_t *create_step_value(cluster_t *cluster, uint16_t value) +{ + return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::StepValue::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_uint16(value)); +} + +attribute_t *create_unit(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::Unit::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_enum8(value)); +} + +attribute_t *create_unit_range(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::UnitRange::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_array(value, length, count)); +} + +attribute_t *create_limit_range(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::LimitRange::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_array(value, length, count)); +} + +attribute_t *create_translation_direction(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::TranslationDirection::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_enum8(value)); +} + +attribute_t *create_rotation_axis(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::RotationAxis::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_enum8(value)); +} + +attribute_t *create_overflow(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::Overflow::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_enum8(value)); +} + +attribute_t *create_modulation_type(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::ModulationType::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_enum8(value)); +} + +attribute_t *create_latch_control_modes(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, ClosureDimension::Attributes::LatchControlModes::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_bitmap8(value)); +} + +} /* attribute */ + +} /* closure_dimension */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_attribute.h b/components/esp_matter/data_model/esp_matter_attribute.h index 8aa4d2186..a71e0ac47 100644 --- a/components/esp_matter/data_model/esp_matter_attribute.h +++ b/components/esp_matter/data_model/esp_matter_attribute.h @@ -1291,5 +1291,23 @@ attribute_t *create_latch_control_modes(cluster_t *cluster, uint8_t value); } /* attribute */ } /* closure_control */ +namespace closure_dimension { +namespace attribute { + +attribute_t *create_current_state(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count); +attribute_t *create_target_state(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count); +attribute_t *create_resolution(cluster_t *cluster, uint16_t value); +attribute_t *create_step_value(cluster_t *cluster, uint16_t value); +attribute_t *create_unit(cluster_t *cluster, uint8_t value); +attribute_t *create_unit_range(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count); +attribute_t *create_limit_range(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count); +attribute_t *create_translation_direction(cluster_t *cluster, uint8_t value); +attribute_t *create_rotation_axis(cluster_t *cluster, uint8_t value); +attribute_t *create_overflow(cluster_t *cluster, uint8_t value); +attribute_t *create_modulation_type(cluster_t *cluster, uint8_t value); +attribute_t *create_latch_control_modes(cluster_t *cluster, uint8_t value); +} /* attribute */ +} /* closure_dimension */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_cluster.cpp b/components/esp_matter/data_model/esp_matter_cluster.cpp index 5d5e1b6de..df050082f 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.cpp +++ b/components/esp_matter/data_model/esp_matter_cluster.cpp @@ -58,9 +58,10 @@ enum class feature_policy { k_exact_one = 0, // O.a k_at_least_one = 1, // 0.a+ + k_at_most_one = 2, // 0.a- }; -const char feature_policy_strs[2][16] = {"Exactly one", "At least one"}; +const char feature_policy_strs[3][16] = {"Exactly one", "At least one", "At most one"}; bool validate_features(uint32_t feature_flag, feature_policy policy, const char *feature_name, std::initializer_list features) @@ -81,6 +82,9 @@ bool validate_features(uint32_t feature_flag, feature_policy policy, case feature_policy::k_at_least_one: result = count >= 1; break; + case feature_policy::k_at_most_one: + result = count <= 1; + break; } if (!result) { @@ -99,6 +103,10 @@ bool validate_features(uint32_t feature_flag, feature_policy policy, do { if (!validate_features(config->feature_flags, feature_policy::k_at_least_one, name, {__VA_ARGS__})) \ return ABORT_CLUSTER_CREATE(cluster); } while(0) +#define VALIDATE_FEATURES_AT_MOST_ONE(name, ...) \ + do { if (!validate_features(config->feature_flags, feature_policy::k_at_most_one, name, {__VA_ARGS__})) \ + return ABORT_CLUSTER_CREATE(cluster); } while(0) + } // anonymous namespace namespace esp_matter { @@ -4164,5 +4172,75 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } /* closure_control */ +namespace closure_dimension { +const function_generic_t *function_list = NULL; + +const int function_flags = CLUSTER_FLAG_NONE; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) +{ + cluster_t *cluster = esp_matter::cluster::create(endpoint, ClosureDimension::Id, flags); + VerifyOrReturnValue(cluster, NULL, ESP_LOGE(TAG, "Could not create cluster. cluster_id: 0x%08" PRIX32, ClosureDimension::Id)); + if (flags & CLUSTER_FLAG_SERVER) { + if (config->delegate != nullptr) { + static const auto delegate_init_cb = ClosureDimensionDelegateInitCB; + set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate); + } + static const auto plugin_server_init_cb = CALL_ONCE(MatterClosureDimensionPluginServerInitCallback); + set_plugin_server_init_callback(cluster, plugin_server_init_cb); + add_function_list(cluster, function_list, function_flags); + + VerifyOrReturnValue(config != NULL, ABORT_CLUSTER_CREATE(cluster)); + /* Attributes managed internally */ + global::attribute::create_feature_map(cluster, config->feature_flags); + attribute::create_current_state(cluster, NULL, 0, 0); + attribute::create_target_state(cluster, NULL, 0, 0); + + /* Attributes not managed internally */ + global::attribute::create_cluster_revision(cluster, cluster_revision); + + // check against O.a+ feature conformance + VALIDATE_FEATURES_AT_LEAST_ONE("Positioning,MotionLatching", + feature::positioning::get_id(), feature::motion_latching::get_id()); + if (has(feature::positioning::get_id())) { + VerifyOrReturnValue(feature::positioning::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster)); + + VALIDATE_FEATURES_AT_MOST_ONE("Translation, Rotation, Modulation", + feature::translation::get_id(), feature::rotation::get_id(), feature::modulation::get_id()); + if (has(feature::translation::get_id())) { + VerifyOrReturnValue(feature::translation::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster)); + } + if (has(feature::rotation::get_id())) { + VerifyOrReturnValue(feature::rotation::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster)); + } + if (has(feature::modulation::get_id())) { + VerifyOrReturnValue(feature::modulation::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster)); + } + if (has(feature::speed::get_id())) { + VerifyOrReturnValue(feature::speed::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster)); + } + if (has(feature::unit::get_id())) { + VerifyOrReturnValue(feature::unit::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster)); + } + if (has(feature::limitation::get_id())) { + VerifyOrReturnValue(feature::limitation::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster)); + } + } + if (has(feature::motion_latching::get_id())) { + VerifyOrReturnValue(feature::motion_latching::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster)); + } + + command::create_set_target(cluster); + + } + + if (flags & CLUSTER_FLAG_CLIENT) { + create_default_binding_cluster(endpoint); + } + return cluster; +} + +} /* closure_dimension */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_cluster.h b/components/esp_matter/data_model/esp_matter_cluster.h index bd05d46d1..9e78c8890 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.h +++ b/components/esp_matter/data_model/esp_matter_cluster.h @@ -1017,5 +1017,15 @@ typedef struct config { cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); } /* closure_control */ +namespace closure_dimension { +typedef struct config { + void *delegate; + uint32_t feature_flags = 0; + config() : delegate(nullptr), feature_flags(0) {} +} config_t; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); +} /* closure_dimension */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_command.cpp b/components/esp_matter/data_model/esp_matter_command.cpp index 36be7c808..2a0fc8130 100644 --- a/components/esp_matter/data_model/esp_matter_command.cpp +++ b/components/esp_matter/data_model/esp_matter_command.cpp @@ -3036,5 +3036,22 @@ command_t *create_calibrate(cluster_t *cluster) } /* command */ } /* closure_control */ +namespace closure_dimension { +namespace command { +command_t *create_set_target(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, ClosureDimension::Commands::SetTarget::Id, + COMMAND_FLAG_ACCEPTED, NULL); +} + +command_t *create_step(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, ClosureDimension::Commands::Step::Id, + COMMAND_FLAG_ACCEPTED, NULL); +} + +} /* command */ +} /* closure_dimension */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_command.h b/components/esp_matter/data_model/esp_matter_command.h index 2b6c1d618..3dc0fa3e6 100644 --- a/components/esp_matter/data_model/esp_matter_command.h +++ b/components/esp_matter/data_model/esp_matter_command.h @@ -560,5 +560,12 @@ command_t *create_calibrate(cluster_t *cluster); } /* command */ } /* closure_control */ +namespace closure_dimension { +namespace command { +command_t *create_set_target(cluster_t *cluster); +command_t *create_step(cluster_t *cluster); +} /* command */ +} /* closure_dimension */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_delegate_callbacks.cpp b/components/esp_matter/data_model/esp_matter_delegate_callbacks.cpp index c08b4fadd..f01f5cbe0 100644 --- a/components/esp_matter/data_model/esp_matter_delegate_callbacks.cpp +++ b/components/esp_matter/data_model/esp_matter_delegate_callbacks.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include using namespace chip::app::Clusters; @@ -559,6 +560,17 @@ void ClosureControlDelegateInitCB(void *delegate, uint16_t endpoint_id) server_interface->Init(); } + +void ClosureDimensionDelegateInitCB(void *delegate, uint16_t endpoint_id) +{ + VerifyOrReturn(delegate != nullptr); + ClosureDimension::DelegateBase *closure_dimension_delegate = static_cast(delegate); + ClosureDimension::MatterContext *matter_context = new ClosureDimension::MatterContext(endpoint_id); + ClosureDimension::ClusterLogic *cluster_logic = new ClosureDimension::ClusterLogic(*closure_dimension_delegate, *matter_context); + ClosureDimension::Interface *server_interface = new ClosureDimension::Interface(endpoint_id, *cluster_logic); + server_interface->Init(); +} + } // namespace delegate_cb } // namespace cluster } // namespace esp_matter diff --git a/components/esp_matter/data_model/esp_matter_delegate_callbacks.h b/components/esp_matter/data_model/esp_matter_delegate_callbacks.h index 5a6b3c816..3b303cfb2 100644 --- a/components/esp_matter/data_model/esp_matter_delegate_callbacks.h +++ b/components/esp_matter/data_model/esp_matter_delegate_callbacks.h @@ -57,6 +57,7 @@ void OtaSoftwareUpdateProviderDelegateInitCB(void *delegate, uint16_t endpoint_i void DiagnosticLogsDelegateInitCB(void *delegate, uint16_t endpoint_id); void ChimeDelegateInitCB(void *delegate, uint16_t endpoint_id); void ClosureControlDelegateInitCB(void *delegate, uint16_t endpoint_id); +void ClosureDimensionDelegateInitCB(void *delegate, uint16_t endpoint_id); } // namespace delegate_cb } // namespace cluster diff --git a/components/esp_matter/data_model/esp_matter_feature.cpp b/components/esp_matter/data_model/esp_matter_feature.cpp index f9badc447..b62d9e0a1 100644 --- a/components/esp_matter/data_model/esp_matter_feature.cpp +++ b/components/esp_matter/data_model/esp_matter_feature.cpp @@ -4366,5 +4366,157 @@ esp_err_t add(cluster_t *cluster) } /* feature */ } /* closure_control */ +namespace closure_dimension { +namespace feature { +namespace positioning { + +uint32_t get_id() +{ + return static_cast(ClosureDimension::Feature::kPositioning); +} + +esp_err_t add(cluster_t *cluster) +{ + VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL")); + update_feature_map(cluster, get_id()); + // Attributes + attribute::create_resolution(cluster, 0); + attribute::create_step_value(cluster, 0); + // Commands + command::create_step(cluster); + return ESP_OK; +} + +} /* positioning */ + +namespace motion_latching { + +uint32_t get_id() +{ + return static_cast(ClosureDimension::Feature::kMotionLatching); +} + +esp_err_t add(cluster_t *cluster) +{ + VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL")); + update_feature_map(cluster, get_id()); + // Attributes + attribute::create_latch_control_modes(cluster, 0); + return ESP_OK; +} + +} /* motion_latching */ + +namespace unit { + +uint32_t get_id() +{ + return static_cast(ClosureDimension::Feature::kUnit); +} + +esp_err_t add(cluster_t *cluster) +{ + VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL")); + update_feature_map(cluster, get_id()); + // Attributes + attribute::create_unit(cluster, 0); + attribute::create_unit_range(cluster, NULL, 0, 0); + return ESP_OK; +} + +} /* unit */ + +namespace limitation { + +uint32_t get_id() +{ + return static_cast(ClosureDimension::Feature::kLimitation); +} + +esp_err_t add(cluster_t *cluster) +{ + VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL")); + update_feature_map(cluster, get_id()); + // Attributes + attribute::create_limit_range(cluster, NULL, 0, 0); + return ESP_OK; +} + +} /* limitation */ + +namespace speed { + +uint32_t get_id() +{ + return static_cast(ClosureDimension::Feature::kSpeed); +} + +esp_err_t add(cluster_t *cluster) +{ + VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL")); + update_feature_map(cluster, get_id()); + return ESP_OK; +} + +} /* speed */ + +namespace translation { + +uint32_t get_id() +{ + return static_cast(ClosureDimension::Feature::kTranslation); +} + +esp_err_t add(cluster_t *cluster) +{ + VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL")); + update_feature_map(cluster, get_id()); + // Attributes + attribute::create_translation_direction(cluster, 0); + return ESP_OK; +} + +} /* translation */ + +namespace rotation { + +uint32_t get_id() +{ + return static_cast(ClosureDimension::Feature::kRotation); +} + +esp_err_t add(cluster_t *cluster) +{ + VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL")); + update_feature_map(cluster, get_id()); + // Attributes + attribute::create_rotation_axis(cluster, 0); + attribute::create_overflow(cluster, 0); + return ESP_OK; +} + +} /* rotation */ + +namespace modulation { + +uint32_t get_id() +{ + return static_cast(ClosureDimension::Feature::kModulation); +} + +esp_err_t add(cluster_t *cluster) +{ + VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL")); + update_feature_map(cluster, get_id()); + // Attributes + attribute::create_modulation_type(cluster, 0); + return ESP_OK; +} + +} /* modulation */ + +} /* feature */ +} /* closure_dimension */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_feature.h b/components/esp_matter/data_model/esp_matter_feature.h index 8acd1907b..69d5d6c22 100644 --- a/components/esp_matter/data_model/esp_matter_feature.h +++ b/components/esp_matter/data_model/esp_matter_feature.h @@ -1952,5 +1952,59 @@ esp_err_t add(cluster_t *cluster); } /* feature */ } /* closure_control */ +namespace closure_dimension { +namespace feature { + +namespace positioning { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* positioning */ + +namespace motion_latching { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* motion_latching */ + +namespace unit { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* unit */ + +namespace limitation { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* limitation */ + +namespace speed { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* speed */ + +namespace translation { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* translation */ + +namespace rotation { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* rotation */ + +namespace modulation { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* modulation */ + +} /* feature */ +} /* closure_dimension */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h b/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h index c09f910f4..87c51a96e 100644 --- a/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h +++ b/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h @@ -387,6 +387,10 @@ namespace closure_control { constexpr uint16_t cluster_revision = 1; } // namespace closure_control +namespace closure_dimension { +constexpr uint16_t cluster_revision = 1; +} // namespace closure_dimension + } // namespace cluster } // namespace esp_matter