From 716d1eadf556bcb4ddc0926b90a701800840b3f1 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 3 Dec 2025 12:24:07 +0530 Subject: [PATCH] components/esp_matter: add chime cluster in esp_matter --- .../data_model/esp_matter_attribute.cpp | 24 ++++++++++++ .../data_model/esp_matter_attribute.h | 9 +++++ .../data_model/esp_matter_cluster.cpp | 39 +++++++++++++++++++ .../data_model/esp_matter_cluster.h | 9 +++++ .../data_model/esp_matter_command.cpp | 11 ++++++ .../data_model/esp_matter_command.h | 6 +++ .../esp_matter_delegate_callbacks.cpp | 10 ++++- .../esp_matter_delegate_callbacks.h | 1 + .../private/esp_matter_cluster_revisions.h | 4 ++ 9 files changed, 112 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 dbca14b61..2e5377349 100644 --- a/components/esp_matter/data_model/esp_matter_attribute.cpp +++ b/components/esp_matter/data_model/esp_matter_attribute.cpp @@ -4921,5 +4921,29 @@ attribute_t *create_current_sessions(cluster_t *cluster, uint8_t *value, uint16_ }/*webrtc transport requestor*/ +namespace chime { +namespace attribute { +attribute_t *create_installed_chime_sounds(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, Chime::Attributes::InstalledChimeSounds::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_array(value, length, count)); +} + +attribute_t *create_selected_chime(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, Chime::Attributes::SelectedChime::Id, + ATTRIBUTE_FLAG_WRITABLE | ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NONVOLATILE, esp_matter_uint8(value)); +} + +attribute_t *create_enabled(cluster_t *cluster, bool value) +{ + return esp_matter::attribute::create(cluster, Chime::Attributes::Enabled::Id, + ATTRIBUTE_FLAG_WRITABLE | ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NONVOLATILE, esp_matter_bool(value)); +} + +} /* attribute */ + +} /* chime */ + } /* 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 25c6562de..1ea668ad7 100644 --- a/components/esp_matter/data_model/esp_matter_attribute.h +++ b/components/esp_matter/data_model/esp_matter_attribute.h @@ -1270,5 +1270,14 @@ attribute_t *create_current_sessions(cluster_t *cluster, uint8_t * value, uint16 } /* attribute */ }/*webrtc transport requestor*/ +namespace chime { +namespace attribute { + +attribute_t *create_installed_chime_sounds(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count); +attribute_t *create_selected_chime(cluster_t *cluster, uint8_t value); +attribute_t *create_enabled(cluster_t *cluster, bool value); +} /* attribute */ +} /* chime */ + } /* 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 4422dae96..d81b09be2 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.cpp +++ b/components/esp_matter/data_model/esp_matter_cluster.cpp @@ -4042,5 +4042,44 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) // // ToDo // } /* audio_output */ +namespace chime { +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, Chime::Id, flags); + VerifyOrReturnValue(cluster, NULL, ESP_LOGE(TAG, "Could not create cluster. cluster_id: 0x%08" PRIX32, Chime::Id)); + if (flags & CLUSTER_FLAG_SERVER) { + if (config->delegate != nullptr) { + static const auto delegate_init_cb = ChimeDelegateInitCB; + set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate); + } + static const auto plugin_server_init_cb = CALL_ONCE(MatterChimePluginServerInitCallback); + set_plugin_server_init_callback(cluster, plugin_server_init_cb); + add_function_list(cluster, function_list, function_flags); + + /* Attributes managed internally */ + global::attribute::create_feature_map(cluster, 0); + attribute::create_installed_chime_sounds(cluster, NULL, 0, 0); + attribute::create_selected_chime(cluster, 0); + attribute::create_enabled(cluster, false); + + /* Attributes not managed internally */ + global::attribute::create_cluster_revision(cluster, cluster_revision); + + command::create_play_chime_sound(cluster); + + } + + if (flags & CLUSTER_FLAG_CLIENT) { + create_default_binding_cluster(endpoint); + } + return cluster; +} + +} /* chime */ + } /* 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 50bc42dfa..a80808eac 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.h +++ b/components/esp_matter/data_model/esp_matter_cluster.h @@ -998,5 +998,14 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); }/*webrtc transport requestor*/ +namespace chime { +typedef struct config { + void *delegate; + config() : delegate(nullptr) {} +} config_t; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); +} /* chime */ + } /* 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 7254f1001..d12472b08 100644 --- a/components/esp_matter/data_model/esp_matter_command.cpp +++ b/components/esp_matter/data_model/esp_matter_command.cpp @@ -3002,5 +3002,16 @@ namespace webrtc_transport_requestor { }/*webrtc_transport_requestor*/ +namespace chime { +namespace command { +command_t *create_play_chime_sound(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, Chime::Commands::PlayChimeSound::Id, + COMMAND_FLAG_ACCEPTED, NULL); +} + +} /* command */ +} /* chime */ + } /* 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 11dd9c4f6..65378cec6 100644 --- a/components/esp_matter/data_model/esp_matter_command.h +++ b/components/esp_matter/data_model/esp_matter_command.h @@ -546,5 +546,11 @@ command_t *create_end(cluster_t *cluster); }/*webrtc transport requestor*/ +namespace chime { +namespace command { +command_t *create_play_chime_sound(cluster_t *cluster); +} /* command */ +} /* chime */ + } /* 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 a323f1408..82de0bde9 100644 --- a/components/esp_matter/data_model/esp_matter_delegate_callbacks.cpp +++ b/components/esp_matter/data_model/esp_matter_delegate_callbacks.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include using namespace chip::app::Clusters; @@ -539,7 +540,14 @@ void DiagnosticLogsDelegateInitCB(void *delegate, uint16_t endpoint_id) DiagnosticLogs::DiagnosticLogsServer::Instance().SetDiagnosticLogsProviderDelegate(endpoint_id, diagnostic_logs_delegate); } -} // namespace delegate_cb +void ChimeDelegateInitCB(void *delegate, uint16_t endpoint_id) +{ + VerifyOrReturn(delegate != nullptr); + ChimeDelegate *chime_delegate = static_cast(delegate); + ChimeServer *chime_server = new ChimeServer(endpoint_id, *chime_delegate); + chime_server->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 1aced6b06..cda62ecc3 100644 --- a/components/esp_matter/data_model/esp_matter_delegate_callbacks.h +++ b/components/esp_matter/data_model/esp_matter_delegate_callbacks.h @@ -55,6 +55,7 @@ void ActionsDelegateInitCB(void *delegate, uint16_t endpoint_id); 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); } // namespace delegate_cb } // namespace cluster 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 15c676679..71aaea772 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 @@ -379,6 +379,10 @@ namespace webrtc_transport_requestor { constexpr uint16_t cluster_revision = 1; } // namespace webrtc_transport_requestor +namespace chime { +constexpr uint16_t cluster_revision = 1; +} // namespace chime + } // namespace cluster } // namespace esp_matter