From 18a201cd183fb36dac7c841ee37d6b70fdb6853d Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 3 Dec 2025 12:40:39 +0530 Subject: [PATCH] components/esp_matter: add closure_control cluster in esp_matter --- .../data_model/esp_matter_attribute.cpp | 42 +++++ .../data_model/esp_matter_attribute.h | 12 ++ .../data_model/esp_matter_cluster.cpp | 83 ++++++++++ .../data_model/esp_matter_cluster.h | 10 ++ .../data_model/esp_matter_command.cpp | 23 +++ .../data_model/esp_matter_command.h | 8 + .../esp_matter_delegate_callbacks.cpp | 11 ++ .../esp_matter_delegate_callbacks.h | 1 + .../data_model/esp_matter_event.cpp | 25 +++ .../esp_matter/data_model/esp_matter_event.h | 9 + .../data_model/esp_matter_feature.cpp | 154 ++++++++++++++++++ .../data_model/esp_matter_feature.h | 60 +++++++ .../private/esp_matter_cluster_revisions.h | 4 + 13 files changed, 442 insertions(+) diff --git a/components/esp_matter/data_model/esp_matter_attribute.cpp b/components/esp_matter/data_model/esp_matter_attribute.cpp index 2e5377349..93b507f15 100644 --- a/components/esp_matter/data_model/esp_matter_attribute.cpp +++ b/components/esp_matter/data_model/esp_matter_attribute.cpp @@ -4945,5 +4945,47 @@ attribute_t *create_enabled(cluster_t *cluster, bool value) } /* chime */ +namespace closure_control { +namespace attribute { +attribute_t *create_countdown_time(cluster_t *cluster, nullable value) +{ + return esp_matter::attribute::create(cluster, ClosureControl::Attributes::CountdownTime::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint32(value)); +} + +attribute_t *create_main_state(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, ClosureControl::Attributes::MainState::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_enum8(value)); +} + +attribute_t *create_current_error_list(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, ClosureControl::Attributes::CurrentErrorList::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_array(value, length, count)); +} + +attribute_t *create_overall_current_state(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, ClosureControl::Attributes::OverallCurrentState::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_array(value, length, count)); +} + +attribute_t *create_overall_target_state(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, ClosureControl::Attributes::OverallTargetState::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_array(value, length, count)); +} + +attribute_t *create_latch_control_modes(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, ClosureControl::Attributes::LatchControlModes::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_bitmap8(value)); +} + +} /* attribute */ + +} /* closure_control */ + } /* 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 1ea668ad7..8aa4d2186 100644 --- a/components/esp_matter/data_model/esp_matter_attribute.h +++ b/components/esp_matter/data_model/esp_matter_attribute.h @@ -1279,5 +1279,17 @@ attribute_t *create_enabled(cluster_t *cluster, bool value); } /* attribute */ } /* chime */ +namespace closure_control { +namespace attribute { + +attribute_t *create_countdown_time(cluster_t *cluster, nullable value); +attribute_t *create_main_state(cluster_t *cluster, uint8_t value); +attribute_t *create_current_error_list(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count); +attribute_t *create_overall_current_state(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count); +attribute_t *create_overall_target_state(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count); +attribute_t *create_latch_control_modes(cluster_t *cluster, uint8_t value); +} /* attribute */ +} /* closure_control */ + } /* 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 d81b09be2..5d5e1b6de 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.cpp +++ b/components/esp_matter/data_model/esp_matter_cluster.cpp @@ -4081,5 +4081,88 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } /* chime */ +namespace closure_control { +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, ClosureControl::Id, flags); + VerifyOrReturnValue(cluster, NULL, ESP_LOGE(TAG, "Could not create cluster. cluster_id: 0x%08" PRIX32, ClosureControl::Id)); + if (flags & CLUSTER_FLAG_SERVER) { + if (config->delegate != nullptr) { + static const auto delegate_init_cb = ClosureControlDelegateInitCB; + set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate); + } + static const auto plugin_server_init_cb = CALL_ONCE(MatterClosureControlPluginServerInitCallback); + 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_main_state(cluster, 0); + attribute::create_current_error_list(cluster, NULL, 0, 0); + attribute::create_overall_current_state(cluster, NULL, 0, 0); + attribute::create_overall_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)); + if (has(feature::ventilation::get_id())) { + VerifyOrReturnValue(feature::ventilation::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster)); + } + if (has(feature::pedestrian::get_id())) { + VerifyOrReturnValue(feature::pedestrian::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster)); + } + if (has(feature::calibration::get_id())) { + VerifyOrReturnValue(feature::calibration::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)); + } + if (has(feature::manually_operable::get_id())) { + VerifyOrReturnValue(feature::manually_operable::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster)); + } + if (has(feature::instantaneous::get_id())) { + VerifyOrReturnValue(feature::instantaneous::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster)); + } + if (has(feature::speed::get_id())) { + if (has(feature::positioning::get_id()) && !has(feature::instantaneous::get_id())) { + VerifyOrReturnValue(feature::speed::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster)); + } + } + if (has(feature::protection::get_id())) { + VerifyOrReturnValue(feature::protection::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster)); + } + + command::create_move_to(cluster); + if (!has(feature::instantaneous::get_id())) { + command::create_stop(cluster); + } + + /* Events */ + event::create_operational_error(cluster); + event::create_secure_state_changed(cluster); + if (!has(feature::instantaneous::get_id())) { + event::create_movement_completed(cluster); + } + } + + if (flags & CLUSTER_FLAG_CLIENT) { + create_default_binding_cluster(endpoint); + } + return cluster; +} + +} /* closure_control */ + } /* 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 a80808eac..bd05d46d1 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.h +++ b/components/esp_matter/data_model/esp_matter_cluster.h @@ -1007,5 +1007,15 @@ typedef struct config { cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); } /* chime */ +namespace closure_control { +typedef struct config { + void *delegate; + uint32_t feature_flags; + config() : delegate(nullptr), feature_flags(0) {} +} config_t; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); +} /* closure_control */ + } /* 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 d12472b08..36be7c808 100644 --- a/components/esp_matter/data_model/esp_matter_command.cpp +++ b/components/esp_matter/data_model/esp_matter_command.cpp @@ -3013,5 +3013,28 @@ command_t *create_play_chime_sound(cluster_t *cluster) } /* command */ } /* chime */ +namespace closure_control { +namespace command { +command_t *create_stop(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, ClosureControl::Commands::Stop::Id, + COMMAND_FLAG_ACCEPTED, NULL); +} + +command_t *create_move_to(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, ClosureControl::Commands::MoveTo::Id, + COMMAND_FLAG_ACCEPTED, NULL); +} + +command_t *create_calibrate(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, ClosureControl::Commands::Calibrate::Id, + COMMAND_FLAG_ACCEPTED, NULL); +} + +} /* command */ +} /* closure_control */ + } /* 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 65378cec6..2b6c1d618 100644 --- a/components/esp_matter/data_model/esp_matter_command.h +++ b/components/esp_matter/data_model/esp_matter_command.h @@ -552,5 +552,13 @@ command_t *create_play_chime_sound(cluster_t *cluster); } /* command */ } /* chime */ +namespace closure_control { +namespace command { +command_t *create_stop(cluster_t *cluster); +command_t *create_move_to(cluster_t *cluster); +command_t *create_calibrate(cluster_t *cluster); +} /* command */ +} /* closure_control */ + } /* 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 82de0bde9..c08b4fadd 100644 --- a/components/esp_matter/data_model/esp_matter_delegate_callbacks.cpp +++ b/components/esp_matter/data_model/esp_matter_delegate_callbacks.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include using namespace chip::app::Clusters; @@ -548,6 +549,16 @@ void ChimeDelegateInitCB(void *delegate, uint16_t endpoint_id) chime_server->Init(); } +void ClosureControlDelegateInitCB(void *delegate, uint16_t endpoint_id) +{ + VerifyOrReturn(delegate != nullptr); + ClosureControl::DelegateBase *closure_control_delegate = static_cast(delegate); + ClosureControl::MatterContext *matter_context = new ClosureControl::MatterContext(endpoint_id); + ClosureControl::ClusterLogic *cluster_logic = new ClosureControl::ClusterLogic(*closure_control_delegate, *matter_context); + ClosureControl::Interface *server_interface = new ClosureControl::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 cda62ecc3..5a6b3c816 100644 --- a/components/esp_matter/data_model/esp_matter_delegate_callbacks.h +++ b/components/esp_matter/data_model/esp_matter_delegate_callbacks.h @@ -56,6 +56,7 @@ void ThermostatDelegateInitCB(void *delegate, uint16_t endpoint_id); void OtaSoftwareUpdateProviderDelegateInitCB(void *delegate, uint16_t endpoint_id); void DiagnosticLogsDelegateInitCB(void *delegate, uint16_t endpoint_id); void ChimeDelegateInitCB(void *delegate, uint16_t endpoint_id); +void ClosureControlDelegateInitCB(void *delegate, uint16_t endpoint_id); } // namespace delegate_cb } // namespace cluster diff --git a/components/esp_matter/data_model/esp_matter_event.cpp b/components/esp_matter/data_model/esp_matter_event.cpp index 687fe3d72..91805bd77 100644 --- a/components/esp_matter/data_model/esp_matter_event.cpp +++ b/components/esp_matter/data_model/esp_matter_event.cpp @@ -842,5 +842,30 @@ event_t *create_occupancy_changed(cluster_t *cluster) } // namespace event } // namespace occupancy_sensing +namespace closure_control { +namespace event { +event_t *create_operational_error(cluster_t *cluster) +{ + return esp_matter::event::create(cluster, ClosureControl::Events::OperationalError::Id); +} + +event_t *create_movement_completed(cluster_t *cluster) +{ + return esp_matter::event::create(cluster, ClosureControl::Events::MovementCompleted::Id); +} + +event_t *create_engage_state_changed(cluster_t *cluster) +{ + return esp_matter::event::create(cluster, ClosureControl::Events::EngageStateChanged::Id); +} + +event_t *create_secure_state_changed(cluster_t *cluster) +{ + return esp_matter::event::create(cluster, ClosureControl::Events::SecureStateChanged::Id); +} + +} // namespace event +} // namespace closure_control + } // namespace cluster } // namespace esp_matter diff --git a/components/esp_matter/data_model/esp_matter_event.h b/components/esp_matter/data_model/esp_matter_event.h index fe4a25116..17a742a1d 100644 --- a/components/esp_matter/data_model/esp_matter_event.h +++ b/components/esp_matter/data_model/esp_matter_event.h @@ -263,5 +263,14 @@ event_t *create_occupancy_changed(cluster_t *cluster); } // namespace event } // namespace occupancy_sensing +namespace closure_control { +namespace event { +event_t *create_operational_error(cluster_t *cluster); +event_t *create_movement_completed(cluster_t *cluster); +event_t *create_engage_state_changed(cluster_t *cluster); +event_t *create_secure_state_changed(cluster_t *cluster); +} // namespace event +} // namespace closure_control + } // namespace cluster } // namespace esp_matter diff --git a/components/esp_matter/data_model/esp_matter_feature.cpp b/components/esp_matter/data_model/esp_matter_feature.cpp index 6a57514d0..f9badc447 100644 --- a/components/esp_matter/data_model/esp_matter_feature.cpp +++ b/components/esp_matter/data_model/esp_matter_feature.cpp @@ -4212,5 +4212,159 @@ namespace webrtc_transport_requestor { }/*webrtc_transport_requestor*/ +namespace closure_control { +namespace feature { +namespace positioning { + +uint32_t get_id() +{ + return static_cast(ClosureControl::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()); + return ESP_OK; +} + +} /* positioning */ + +namespace motion_latching { + +uint32_t get_id() +{ + return static_cast(ClosureControl::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 managed internally */ + attribute::create_latch_control_modes(cluster, 0); + return ESP_OK; +} + +} /* motion_latching */ + +namespace instantaneous { + +uint32_t get_id() +{ + return static_cast(ClosureControl::Feature::kInstantaneous); +} + +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; +} + +} /* instantaneous */ + +namespace speed { + +uint32_t get_id() +{ + return static_cast(ClosureControl::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 ventilation { + +uint32_t get_id() +{ + return static_cast(ClosureControl::Feature::kVentilation); +} + +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; +} + +} /* ventilation */ + +namespace pedestrian { + +uint32_t get_id() +{ + return static_cast(ClosureControl::Feature::kPedestrian); +} + +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; +} + +} /* pedestrian */ + +namespace calibration { + +uint32_t get_id() +{ + return static_cast(ClosureControl::Feature::kCalibration); +} + +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()); + command::create_calibrate(cluster); + return ESP_OK; +} + +} /* calibration */ + +namespace protection { + +uint32_t get_id() +{ + return static_cast(ClosureControl::Feature::kProtection); +} + +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; +} + +} /* protection */ + +namespace manually_operable { + +uint32_t get_id() +{ + return static_cast(ClosureControl::Feature::kManuallyOperable); +} + +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()); + // Events + event::create_engage_state_changed(cluster); + return ESP_OK; +} + +} /* manually_operable */ + +} /* feature */ +} /* closure_control */ + } /* 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 8d8ab8b1d..8acd1907b 100644 --- a/components/esp_matter/data_model/esp_matter_feature.h +++ b/components/esp_matter/data_model/esp_matter_feature.h @@ -1892,5 +1892,65 @@ namespace webrtc_transport_requestor { }/*webrtc_transport_requestor*/ +namespace closure_control { +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 instantaneous { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* instantaneous */ + +namespace speed { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* speed */ + +namespace ventilation { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* ventilation */ + +namespace pedestrian { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* pedestrian */ + +namespace calibration { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* calibration */ + +namespace protection { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* protection */ + +namespace manually_operable { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* manually_operable */ + +} /* feature */ +} /* closure_control */ + } /* 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 71aaea772..c09f910f4 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 @@ -383,6 +383,10 @@ namespace chime { constexpr uint16_t cluster_revision = 1; } // namespace chime +namespace closure_control { +constexpr uint16_t cluster_revision = 1; +} // namespace closure_control + } // namespace cluster } // namespace esp_matter