From 39ba730422ca4b571664e97cea491ffd583747fc Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 20 Feb 2023 09:32:19 -0500 Subject: [PATCH] Move defines not dependent on ZAP config out of endpoint_config.zapt. (#25163) --- .../app-templates/endpoint_config.h | 32 ++---------------- .../app-templates/endpoint_config.h | 32 ++---------------- src/app/util/attribute-storage.cpp | 18 ++++++++-- src/app/util/endpoint-config-defines.h | 33 +++++++++++++++++++ .../templates/app/endpoint_config.zapt | 21 ++---------- .../zap-generated/endpoint_config.h | 32 ++---------------- 6 files changed, 57 insertions(+), 111 deletions(-) create mode 100644 src/app/util/endpoint-config-defines.h diff --git a/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/endpoint_config.h b/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/endpoint_config.h index d1adcab280db5b..53abe1bd9e8aa7 100644 --- a/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/endpoint_config.h +++ b/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/endpoint_config.h @@ -20,6 +20,7 @@ // Prevent multiple inclusion #pragma once +#include #include // Default values for the attributes longer than a pointer, @@ -267,24 +268,6 @@ #define GENERATED_DEFAULTS_COUNT (32) -#define ZAP_TYPE(type) ZCL_##type##_ATTRIBUTE_TYPE -#define ZAP_LONG_DEFAULTS_INDEX(index) \ - { \ - &generatedDefaults[index] \ - } -#define ZAP_MIN_MAX_DEFAULTS_INDEX(index) \ - { \ - &minMaxDefaults[index] \ - } -#define ZAP_EMPTY_DEFAULT() \ - { \ - (uint32_t) 0 \ - } -#define ZAP_SIMPLE_DEFAULT(x) \ - { \ - (uint32_t) x \ - } - // This is an array of EmberAfAttributeMinMaxValue structures. #define GENERATED_MIN_MAX_DEFAULT_COUNT 47 #define GENERATED_MIN_MAX_DEFAULTS \ @@ -370,7 +353,6 @@ } /* StartUpOnOff */ \ } -#define ZAP_ATTRIBUTE_MASK(mask) ATTRIBUTE_MASK_##mask // This is an array of EmberAfAttributeMetadata structures. #define GENERATED_ATTRIBUTE_COUNT 718 #define GENERATED_ATTRIBUTES \ @@ -1486,11 +1468,6 @@ { ZAP_EMPTY_DEFAULT(), 0x0000FFFD, 2, ZAP_TYPE(INT16U), ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE) }, /* ClusterRevision */ \ } -// This is an array of EmberAfCluster structures. -#define ZAP_ATTRIBUTE_INDEX(index) (&generatedAttributes[index]) - -#define ZAP_GENERATED_COMMANDS_INDEX(index) (&generatedCommands[index]) - // clang-format off #define GENERATED_EVENT_COUNT 23 #define GENERATED_EVENTS { \ @@ -1539,8 +1516,6 @@ // clang-format on -#define ZAP_GENERATED_EVENTS_INDEX(index) (&generatedEvents[index]) - // Cluster function static arrays #define GENERATED_FUNCTION_ARRAYS \ const EmberAfGenericClusterFunction chipFuncArrayIdentifyServer[] = { \ @@ -1948,9 +1923,8 @@ // clang-format on -#define ZAP_CLUSTER_MASK(mask) CLUSTER_MASK_##mask +// This is an array of EmberAfCluster structures. #define GENERATED_CLUSTER_COUNT 78 - // clang-format off #define GENERATED_CLUSTERS { \ { \ @@ -2971,8 +2945,6 @@ // clang-format on -#define ZAP_CLUSTER_INDEX(index) (&generatedClusters[index]) - #define ZAP_FIXED_ENDPOINT_DATA_VERSION_COUNT 77 // This is an array of EmberAfEndpointType structures. diff --git a/scripts/tools/zap/tests/outputs/lighting-app/app-templates/endpoint_config.h b/scripts/tools/zap/tests/outputs/lighting-app/app-templates/endpoint_config.h index 4dbb215dd7731e..f70a3c5efe82e8 100644 --- a/scripts/tools/zap/tests/outputs/lighting-app/app-templates/endpoint_config.h +++ b/scripts/tools/zap/tests/outputs/lighting-app/app-templates/endpoint_config.h @@ -20,6 +20,7 @@ // Prevent multiple inclusion #pragma once +#include #include // Default values for the attributes longer than a pointer, @@ -59,24 +60,6 @@ #define GENERATED_DEFAULTS_COUNT (2) -#define ZAP_TYPE(type) ZCL_##type##_ATTRIBUTE_TYPE -#define ZAP_LONG_DEFAULTS_INDEX(index) \ - { \ - &generatedDefaults[index] \ - } -#define ZAP_MIN_MAX_DEFAULTS_INDEX(index) \ - { \ - &minMaxDefaults[index] \ - } -#define ZAP_EMPTY_DEFAULT() \ - { \ - (uint32_t) 0 \ - } -#define ZAP_SIMPLE_DEFAULT(x) \ - { \ - (uint32_t) x \ - } - // This is an array of EmberAfAttributeMinMaxValue structures. #define GENERATED_MIN_MAX_DEFAULT_COUNT 4 #define GENERATED_MIN_MAX_DEFAULTS \ @@ -97,7 +80,6 @@ } /* StartUpColorTemperatureMireds */ \ } -#define ZAP_ATTRIBUTE_MASK(mask) ATTRIBUTE_MASK_##mask // This is an array of EmberAfAttributeMetadata structures. #define GENERATED_ATTRIBUTE_COUNT 271 #define GENERATED_ATTRIBUTES \ @@ -543,11 +525,6 @@ { ZAP_SIMPLE_DEFAULT(3), 0x0000FFFD, 2, ZAP_TYPE(INT16U), 0 }, /* ClusterRevision */ \ } -// This is an array of EmberAfCluster structures. -#define ZAP_ATTRIBUTE_INDEX(index) (&generatedAttributes[index]) - -#define ZAP_GENERATED_COMMANDS_INDEX(index) (&generatedCommands[index]) - // clang-format off #define GENERATED_EVENT_COUNT 15 #define GENERATED_EVENTS { \ @@ -580,8 +557,6 @@ // clang-format on -#define ZAP_GENERATED_EVENTS_INDEX(index) (&generatedEvents[index]) - // Cluster function static arrays #define GENERATED_FUNCTION_ARRAYS \ const EmberAfGenericClusterFunction chipFuncArrayGroupsServer[] = { \ @@ -788,9 +763,8 @@ // clang-format on -#define ZAP_CLUSTER_MASK(mask) CLUSTER_MASK_##mask +// This is an array of EmberAfCluster structures. #define GENERATED_CLUSTER_COUNT 29 - // clang-format off #define GENERATED_CLUSTERS { \ { \ @@ -1174,8 +1148,6 @@ // clang-format on -#define ZAP_CLUSTER_INDEX(index) (&generatedClusters[index]) - #define ZAP_FIXED_ENDPOINT_DATA_VERSION_COUNT 28 // This is an array of EmberAfEndpointType structures. diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index b7217184f6d7fe..5254d2138b9f31 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -70,10 +70,18 @@ uint16_t emberEndpointCount = 0; // we need this data block for the defaults #if (defined(GENERATED_DEFAULTS) && GENERATED_DEFAULTS_COUNT) constexpr const uint8_t generatedDefaults[] = GENERATED_DEFAULTS; +#define ZAP_LONG_DEFAULTS_INDEX(index) \ + { \ + &generatedDefaults[index] \ + } #endif // GENERATED_DEFAULTS #if (defined(GENERATED_MIN_MAX_DEFAULTS) && GENERATED_MIN_MAX_DEFAULT_COUNT) constexpr const EmberAfAttributeMinMaxValue minMaxDefaults[] = GENERATED_MIN_MAX_DEFAULTS; +#define ZAP_MIN_MAX_DEFAULTS_INDEX(index) \ + { \ + &minMaxDefaults[index] \ + } #endif // GENERATED_MIN_MAX_DEFAULTS #ifdef GENERATED_FUNCTION_ARRAYS @@ -82,14 +90,20 @@ GENERATED_FUNCTION_ARRAYS #ifdef GENERATED_COMMANDS constexpr const chip::CommandId generatedCommands[] = GENERATED_COMMANDS; +#define ZAP_GENERATED_COMMANDS_INDEX(index) (&generatedCommands[index]) #endif // GENERATED_COMMANDS #if (defined(GENERATED_EVENTS) && (GENERATED_EVENT_COUNT > 0)) constexpr const chip::EventId generatedEvents[] = GENERATED_EVENTS; +#define ZAP_GENERATED_EVENTS_INDEX(index) (&generatedEvents[index]) #endif // GENERATED_EVENTS -constexpr const EmberAfAttributeMetadata generatedAttributes[] = GENERATED_ATTRIBUTES; -constexpr const EmberAfCluster generatedClusters[] = GENERATED_CLUSTERS; +constexpr const EmberAfAttributeMetadata generatedAttributes[] = GENERATED_ATTRIBUTES; +#define ZAP_ATTRIBUTE_INDEX(index) (&generatedAttributes[index]) + +constexpr const EmberAfCluster generatedClusters[] = GENERATED_CLUSTERS; +#define ZAP_CLUSTER_INDEX(index) (&generatedClusters[index]) + constexpr const EmberAfEndpointType generatedEmberAfEndpointTypes[] = GENERATED_ENDPOINT_TYPES; constexpr const EmberAfDeviceType fixedDeviceTypeList[] = FIXED_DEVICE_TYPES; diff --git a/src/app/util/endpoint-config-defines.h b/src/app/util/endpoint-config-defines.h new file mode 100644 index 00000000000000..2a54c5d58106f6 --- /dev/null +++ b/src/app/util/endpoint-config-defines.h @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2023 Project CHIP Authors + * + * 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 + +/** + * Defines used by endpoint_config.h that may be useful when manually creating + * endpoint configurations (e.g. for dynamic endpoints). + */ +#define ZAP_TYPE(type) ZCL_##type##_ATTRIBUTE_TYPE +#define ZAP_EMPTY_DEFAULT() \ + { \ + (uint32_t) 0 \ + } +#define ZAP_SIMPLE_DEFAULT(x) \ + { \ + (uint32_t) x \ + } +#define ZAP_ATTRIBUTE_MASK(mask) ATTRIBUTE_MASK_##mask +#define ZAP_CLUSTER_MASK(mask) CLUSTER_MASK_##mask diff --git a/src/app/zap-templates/templates/app/endpoint_config.zapt b/src/app/zap-templates/templates/app/endpoint_config.zapt index 92574b71fa912e..78fff827dca22f 100644 --- a/src/app/zap-templates/templates/app/endpoint_config.zapt +++ b/src/app/zap-templates/templates/app/endpoint_config.zapt @@ -4,6 +4,7 @@ #pragma once #include +#include {{#endpoint_config allowUnknownStorageOption="false" spaceForDefaultValue=4}} @@ -19,33 +20,19 @@ #define GENERATED_DEFAULTS_COUNT ({{endpoint_attribute_long_defaults_count}}) -#define ZAP_TYPE(type) ZCL_ ## type ## _ATTRIBUTE_TYPE -#define ZAP_LONG_DEFAULTS_INDEX(index) { &generatedDefaults[index] } -#define ZAP_MIN_MAX_DEFAULTS_INDEX(index) { &minMaxDefaults[index] } -#define ZAP_EMPTY_DEFAULT() {(uint32_t) 0} -#define ZAP_SIMPLE_DEFAULT(x) {(uint32_t) x} - // This is an array of EmberAfAttributeMinMaxValue structures. #define GENERATED_MIN_MAX_DEFAULT_COUNT {{endpoint_attribute_min_max_count}} #define GENERATED_MIN_MAX_DEFAULTS {{endpoint_attribute_min_max_list}} -#define ZAP_ATTRIBUTE_MASK(mask) ATTRIBUTE_MASK_ ## mask // This is an array of EmberAfAttributeMetadata structures. #define GENERATED_ATTRIBUTE_COUNT {{endpoint_attribute_count}} #define GENERATED_ATTRIBUTES {{ endpoint_attribute_list }} -// This is an array of EmberAfCluster structures. -#define ZAP_ATTRIBUTE_INDEX(index) (&generatedAttributes[index]) - -#define ZAP_GENERATED_COMMANDS_INDEX(index) (&generatedCommands[index]) - // clang-format off #define GENERATED_EVENT_COUNT {{ chip_endpoint_generated_event_count }} #define GENERATED_EVENTS {{ chip_endpoint_generated_event_list }} // clang-format on -#define ZAP_GENERATED_EVENTS_INDEX(index) (&generatedEvents[index]) - // Cluster function static arrays #define GENERATED_FUNCTION_ARRAYS {{chip_endpoint_generated_functions}} @@ -62,16 +49,12 @@ {{/last}} {{/chip_endpoint_generated_commands_list}} -#define ZAP_CLUSTER_MASK(mask) CLUSTER_MASK_ ## mask +// This is an array of EmberAfCluster structures. #define GENERATED_CLUSTER_COUNT {{endpoint_cluster_count}} - - // clang-format off #define GENERATED_CLUSTERS {{chip_endpoint_cluster_list}} // clang-format on -#define ZAP_CLUSTER_INDEX(index) (&generatedClusters[index]) - #define ZAP_FIXED_ENDPOINT_DATA_VERSION_COUNT {{chip_endpoint_data_version_count}} // This is an array of EmberAfEndpointType structures. diff --git a/zzz_generated/darwin/controller-clusters/zap-generated/endpoint_config.h b/zzz_generated/darwin/controller-clusters/zap-generated/endpoint_config.h index 2cbe65050a2eec..721a201f18ea7e 100644 --- a/zzz_generated/darwin/controller-clusters/zap-generated/endpoint_config.h +++ b/zzz_generated/darwin/controller-clusters/zap-generated/endpoint_config.h @@ -20,6 +20,7 @@ // Prevent multiple inclusion #pragma once +#include #include // Default values for the attributes longer than a pointer, @@ -37,40 +38,16 @@ #define GENERATED_DEFAULTS_COUNT (0) -#define ZAP_TYPE(type) ZCL_##type##_ATTRIBUTE_TYPE -#define ZAP_LONG_DEFAULTS_INDEX(index) \ - { \ - &generatedDefaults[index] \ - } -#define ZAP_MIN_MAX_DEFAULTS_INDEX(index) \ - { \ - &minMaxDefaults[index] \ - } -#define ZAP_EMPTY_DEFAULT() \ - { \ - (uint32_t) 0 \ - } -#define ZAP_SIMPLE_DEFAULT(x) \ - { \ - (uint32_t) x \ - } - // This is an array of EmberAfAttributeMinMaxValue structures. #define GENERATED_MIN_MAX_DEFAULT_COUNT 0 #define GENERATED_MIN_MAX_DEFAULTS \ {} -#define ZAP_ATTRIBUTE_MASK(mask) ATTRIBUTE_MASK_##mask // This is an array of EmberAfAttributeMetadata structures. #define GENERATED_ATTRIBUTE_COUNT 0 #define GENERATED_ATTRIBUTES \ {} -// This is an array of EmberAfCluster structures. -#define ZAP_ATTRIBUTE_INDEX(index) (&generatedAttributes[index]) - -#define ZAP_GENERATED_COMMANDS_INDEX(index) (&generatedCommands[index]) - // clang-format off #define GENERATED_EVENT_COUNT 0 #define GENERATED_EVENTS { \ @@ -78,14 +55,11 @@ // clang-format on -#define ZAP_GENERATED_EVENTS_INDEX(index) (&generatedEvents[index]) - // Cluster function static arrays #define GENERATED_FUNCTION_ARRAYS -#define ZAP_CLUSTER_MASK(mask) CLUSTER_MASK_##mask +// This is an array of EmberAfCluster structures. #define GENERATED_CLUSTER_COUNT 66 - // clang-format off #define GENERATED_CLUSTERS { \ { \ @@ -950,8 +924,6 @@ // clang-format on -#define ZAP_CLUSTER_INDEX(index) (&generatedClusters[index]) - #define ZAP_FIXED_ENDPOINT_DATA_VERSION_COUNT 0 // This is an array of EmberAfEndpointType structures.