Skip to content

Commit a64c81e

Browse files
Implement codegen for global things
1 parent 4334e91 commit a64c81e

File tree

55 files changed

+4337
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4337
-92
lines changed

examples/all-clusters-app/all-clusters-common/all-clusters-app.matter

+19
Original file line numberDiff line numberDiff line change
@@ -6809,6 +6809,7 @@ internal cluster UnitTesting = 4294048773 {
68096809
SimpleBitmap f = 5;
68106810
single g = 6;
68116811
double h = 7;
6812+
optional TestGlobalEnum i = 8;
68126813
}
68136814

68146815
fabric_scoped struct TestFabricScoped {
@@ -6841,6 +6842,7 @@ internal cluster UnitTesting = 4294048773 {
68416842
int8u a = 0;
68426843
boolean b = 1;
68436844
SimpleStruct c = 2;
6845+
optional TestGlobalStruct d = 3;
68446846
}
68456847

68466848
struct NestedStructList {
@@ -6926,6 +6928,8 @@ internal cluster UnitTesting = 4294048773 {
69266928
timedwrite attribute boolean timedWriteBoolean = 48;
69276929
attribute boolean generalErrorBoolean = 49;
69286930
attribute boolean clusterErrorBoolean = 50;
6931+
attribute TestGlobalEnum globalEnum = 51;
6932+
attribute TestGlobalStruct globalStruct = 52;
69296933
attribute optional boolean unsupported = 255;
69306934
attribute nullable boolean nullableBoolean = 16384;
69316935
attribute nullable Bitmap8MaskMap nullableBitmap8 = 16385;
@@ -6961,6 +6965,8 @@ internal cluster UnitTesting = 4294048773 {
69616965
attribute nullable int16u nullableRangeRestrictedInt16u = 16424;
69626966
attribute nullable int16s nullableRangeRestrictedInt16s = 16425;
69636967
attribute optional int8u writeOnlyInt8u = 16426;
6968+
attribute nullable TestGlobalEnum nullableGlobalEnum = 16435;
6969+
attribute nullable TestGlobalStruct nullableGlobalStruct = 16436;
69646970
attribute int8u meiInt8u = 4294070017;
69656971
readonly attribute command_id generatedCommandList[] = 65528;
69666972
readonly attribute command_id acceptedCommandList[] = 65529;
@@ -7112,6 +7118,11 @@ internal cluster UnitTesting = 4294048773 {
71127118
SimpleEnum arg2 = 1;
71137119
}
71147120

7121+
response struct GlobalEchoResponse = 14 {
7122+
TestGlobalStruct field1 = 0;
7123+
TestGlobalEnum field2 = 1;
7124+
}
7125+
71157126
request struct TestNullableOptionalRequestRequest {
71167127
optional nullable int8u arg1 = 0;
71177128
}
@@ -7165,6 +7176,11 @@ internal cluster UnitTesting = 4294048773 {
71657176
octet_string payload = 0;
71667177
}
71677178

7179+
request struct GlobalEchoRequestRequest {
7180+
TestGlobalStruct field1 = 0;
7181+
TestGlobalEnum field2 = 1;
7182+
}
7183+
71687184
request struct TestDifferentVendorMeiRequestRequest {
71697185
int8u arg1 = 0;
71707186
}
@@ -7248,6 +7264,9 @@ internal cluster UnitTesting = 4294048773 {
72487264
the string back. If the string is large then it would require a session that
72497265
supports large payloads. */
72507266
command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24;
7267+
/** Command that takes arguments that are global structs/enums and the
7268+
response just echoes them back. */
7269+
command GlobalEchoRequest(GlobalEchoRequestRequest): GlobalEchoResponse = 25;
72517270
/** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */
72527271
command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962;
72537272
}

examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter

+19
Original file line numberDiff line numberDiff line change
@@ -5458,6 +5458,7 @@ internal cluster UnitTesting = 4294048773 {
54585458
SimpleBitmap f = 5;
54595459
single g = 6;
54605460
double h = 7;
5461+
optional TestGlobalEnum i = 8;
54615462
}
54625463

54635464
fabric_scoped struct TestFabricScoped {
@@ -5490,6 +5491,7 @@ internal cluster UnitTesting = 4294048773 {
54905491
int8u a = 0;
54915492
boolean b = 1;
54925493
SimpleStruct c = 2;
5494+
optional TestGlobalStruct d = 3;
54935495
}
54945496

54955497
struct NestedStructList {
@@ -5575,6 +5577,8 @@ internal cluster UnitTesting = 4294048773 {
55755577
timedwrite attribute boolean timedWriteBoolean = 48;
55765578
attribute boolean generalErrorBoolean = 49;
55775579
attribute boolean clusterErrorBoolean = 50;
5580+
attribute TestGlobalEnum globalEnum = 51;
5581+
attribute TestGlobalStruct globalStruct = 52;
55785582
attribute optional boolean unsupported = 255;
55795583
attribute nullable boolean nullableBoolean = 16384;
55805584
attribute nullable Bitmap8MaskMap nullableBitmap8 = 16385;
@@ -5610,6 +5614,8 @@ internal cluster UnitTesting = 4294048773 {
56105614
attribute nullable int16u nullableRangeRestrictedInt16u = 16424;
56115615
attribute nullable int16s nullableRangeRestrictedInt16s = 16425;
56125616
attribute optional int8u writeOnlyInt8u = 16426;
5617+
attribute nullable TestGlobalEnum nullableGlobalEnum = 16435;
5618+
attribute nullable TestGlobalStruct nullableGlobalStruct = 16436;
56135619
attribute int8u meiInt8u = 4294070017;
56145620
readonly attribute command_id generatedCommandList[] = 65528;
56155621
readonly attribute command_id acceptedCommandList[] = 65529;
@@ -5761,6 +5767,11 @@ internal cluster UnitTesting = 4294048773 {
57615767
SimpleEnum arg2 = 1;
57625768
}
57635769

5770+
response struct GlobalEchoResponse = 14 {
5771+
TestGlobalStruct field1 = 0;
5772+
TestGlobalEnum field2 = 1;
5773+
}
5774+
57645775
request struct TestNullableOptionalRequestRequest {
57655776
optional nullable int8u arg1 = 0;
57665777
}
@@ -5814,6 +5825,11 @@ internal cluster UnitTesting = 4294048773 {
58145825
octet_string payload = 0;
58155826
}
58165827

5828+
request struct GlobalEchoRequestRequest {
5829+
TestGlobalStruct field1 = 0;
5830+
TestGlobalEnum field2 = 1;
5831+
}
5832+
58175833
request struct TestDifferentVendorMeiRequestRequest {
58185834
int8u arg1 = 0;
58195835
}
@@ -5897,6 +5913,9 @@ internal cluster UnitTesting = 4294048773 {
58975913
the string back. If the string is large then it would require a session that
58985914
supports large payloads. */
58995915
command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24;
5916+
/** Command that takes arguments that are global structs/enums and the
5917+
response just echoes them back. */
5918+
command GlobalEchoRequest(GlobalEchoRequestRequest): GlobalEchoResponse = 25;
59005919
/** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */
59015920
command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962;
59025921
}

examples/chef/devices/rootnode_contactsensor_27f76aeaf5.matter

+19
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,7 @@ internal cluster UnitTesting = 4294048773 {
14771477
SimpleBitmap f = 5;
14781478
single g = 6;
14791479
double h = 7;
1480+
optional TestGlobalEnum i = 8;
14801481
}
14811482

14821483
fabric_scoped struct TestFabricScoped {
@@ -1509,6 +1510,7 @@ internal cluster UnitTesting = 4294048773 {
15091510
int8u a = 0;
15101511
boolean b = 1;
15111512
SimpleStruct c = 2;
1513+
optional TestGlobalStruct d = 3;
15121514
}
15131515

15141516
struct NestedStructList {
@@ -1594,6 +1596,8 @@ internal cluster UnitTesting = 4294048773 {
15941596
timedwrite attribute boolean timedWriteBoolean = 48;
15951597
attribute boolean generalErrorBoolean = 49;
15961598
attribute boolean clusterErrorBoolean = 50;
1599+
attribute TestGlobalEnum globalEnum = 51;
1600+
attribute TestGlobalStruct globalStruct = 52;
15971601
attribute optional boolean unsupported = 255;
15981602
attribute nullable boolean nullableBoolean = 16384;
15991603
attribute nullable Bitmap8MaskMap nullableBitmap8 = 16385;
@@ -1629,6 +1633,8 @@ internal cluster UnitTesting = 4294048773 {
16291633
attribute nullable int16u nullableRangeRestrictedInt16u = 16424;
16301634
attribute nullable int16s nullableRangeRestrictedInt16s = 16425;
16311635
attribute optional int8u writeOnlyInt8u = 16426;
1636+
attribute nullable TestGlobalEnum nullableGlobalEnum = 16435;
1637+
attribute nullable TestGlobalStruct nullableGlobalStruct = 16436;
16321638
attribute int8u meiInt8u = 4294070017;
16331639
readonly attribute command_id generatedCommandList[] = 65528;
16341640
readonly attribute command_id acceptedCommandList[] = 65529;
@@ -1780,6 +1786,11 @@ internal cluster UnitTesting = 4294048773 {
17801786
SimpleEnum arg2 = 1;
17811787
}
17821788

1789+
response struct GlobalEchoResponse = 14 {
1790+
TestGlobalStruct field1 = 0;
1791+
TestGlobalEnum field2 = 1;
1792+
}
1793+
17831794
request struct TestNullableOptionalRequestRequest {
17841795
optional nullable int8u arg1 = 0;
17851796
}
@@ -1833,6 +1844,11 @@ internal cluster UnitTesting = 4294048773 {
18331844
octet_string payload = 0;
18341845
}
18351846

1847+
request struct GlobalEchoRequestRequest {
1848+
TestGlobalStruct field1 = 0;
1849+
TestGlobalEnum field2 = 1;
1850+
}
1851+
18361852
request struct TestDifferentVendorMeiRequestRequest {
18371853
int8u arg1 = 0;
18381854
}
@@ -1916,6 +1932,9 @@ internal cluster UnitTesting = 4294048773 {
19161932
the string back. If the string is large then it would require a session that
19171933
supports large payloads. */
19181934
command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24;
1935+
/** Command that takes arguments that are global structs/enums and the
1936+
response just echoes them back. */
1937+
command GlobalEchoRequest(GlobalEchoRequestRequest): GlobalEchoResponse = 25;
19191938
/** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */
19201939
command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962;
19211940
}

src/app/common/templates/templates.json

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
"name": "cluster_enums_enum",
2626
"path": "../../zap-templates/partials/cluster-enums-enum.zapt"
2727
},
28+
{
29+
"name": "cluster_enums_ensure_known_value",
30+
"path": "../../zap-templates/partials/cluster-enums-ensure-known-value.zapt"
31+
},
2832
{
2933
"name": "cluster_objects_field_init",
3034
"path": "../../zap-templates/partials/cluster-objects-field-init.zapt"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{#unless (isInConfigList (concat ns "::" label) "EnumsNotUsedAsTypeInXML")}}
2+
static auto __attribute__((unused)) EnsureKnownEnumValue({{ns}}::{{asType label}} val)
3+
{
4+
using EnumType = {{ns}}::{{asType label}};
5+
switch (val) {
6+
{{#zcl_enum_items}}
7+
case EnumType::k{{asUpperCamelCase label}}:
8+
{{/zcl_enum_items}}
9+
return val;
10+
default:
11+
return EnumType::kUnknownEnumValue;
12+
}
13+
}
14+
{{/unless}}

src/app/zap-templates/templates/app/cluster-enums-check.zapt

+5-28
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,17 @@ namespace app {
99
namespace Clusters {
1010
{{#zcl_enums}}
1111
{{#if has_more_than_one_cluster}}
12-
{{#unless (isInConfigList (concat "::" label) "EnumsNotUsedAsTypeInXML")}}
13-
static auto __attribute__((unused)) EnsureKnownEnumValue(detail::{{asType label}} val)
14-
{
15-
using EnumType = detail::{{asType label}};
16-
switch (val) {
17-
{{#zcl_enum_items}}
18-
case EnumType::k{{asUpperCamelCase label}}:
19-
{{/zcl_enum_items}}
20-
return val;
21-
default:
22-
return EnumType::kUnknownEnumValue;
23-
}
24-
}
25-
{{/unless}}
12+
{{> cluster_enums_ensure_known_value ns="detail"}}
13+
{{else if has_no_clusters}}
14+
{{> cluster_enums_ensure_known_value ns="Globals"}}
15+
2616
{{/if}}
2717
{{/zcl_enums}}
2818

2919
{{#zcl_clusters}}
3020
{{#zcl_enums}}
3121
{{#unless has_more_than_one_cluster}}
32-
{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedAsTypeInXML")}}
33-
static auto __attribute__((unused)) EnsureKnownEnumValue({{asUpperCamelCase ../name}}::{{asType label}} val)
34-
{
35-
using EnumType = {{asUpperCamelCase ../name}}::{{asType label}};
36-
switch (val) {
37-
{{#zcl_enum_items}}
38-
case EnumType::k{{asUpperCamelCase label}}:
39-
{{/zcl_enum_items}}
40-
return val;
41-
default:
42-
return EnumType::kUnknownEnumValue;
43-
}
44-
}
45-
{{/unless}}
22+
{{> cluster_enums_ensure_known_value ns=(asUpperCamelCase ../name)}}
4623
{{/unless}}
4724
{{/zcl_enums}}
4825

src/app/zap-templates/templates/app/cluster-enums.zapt

+31
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,37 @@ k{{asUpperCamelCase label}} = {{asHex mask}},
3737

3838
} // namespace detail
3939

40+
namespace Globals {
41+
// Global enums.
42+
{{#zcl_enums}}
43+
44+
{{#if has_no_clusters}}
45+
46+
{{> cluster_enums_enum ns=""}}
47+
48+
{{/if}}
49+
{{/zcl_enums}}
50+
51+
// Global bitmaps.
52+
{{#zcl_bitmaps}}
53+
54+
{{#if has_no_clusters}}
55+
{{! Work around https://github.com/project-chip/zap/issues/1370 and manually filter out built-in bitmap types. }}
56+
{{#if_is_atomic label}}
57+
{{else}}
58+
59+
// Bitmap for {{label}}
60+
enum class {{asType label}} : {{asUnderlyingZclType name}} {
61+
{{#zcl_bitmap_items}}
62+
k{{asUpperCamelCase label}} = {{asHex mask}},
63+
{{/zcl_bitmap_items}}
64+
};
65+
66+
{{/if_is_atomic}}
67+
{{/if}}
68+
{{/zcl_bitmaps}}
69+
70+
} // namespace Globals
4071

4172
{{#zcl_clusters}}
4273
namespace {{asUpperCamelCase name}} {

src/app/zap-templates/templates/app/cluster-objects-src.zapt

+12
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ namespace Structs {
6464
} // namespace Structs
6565
} // namespace detail
6666

67+
namespace Globals {
68+
// Global structs
69+
namespace Structs {
70+
{{#zcl_structs}}
71+
{{#if has_no_clusters}}
72+
{{> cluster_objects_struct header=false}}
73+
74+
{{/if}}
75+
{{/zcl_structs}}
76+
} // namespace Structs
77+
} // namespace Globals
78+
6779
{{#zcl_clusters}}
6880
namespace {{asUpperCamelCase name}} {
6981
{{#zcl_structs}}

src/app/zap-templates/templates/app/cluster-objects.zapt

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ namespace Structs {
3535
} // namespace detail
3636

3737
namespace Globals {
38+
39+
// Global structs.
40+
namespace Structs {
41+
42+
{{#zcl_structs}}
43+
{{#if has_no_clusters}}
44+
{{> cluster_objects_struct header=true}}
45+
46+
{{/if}}
47+
{{/zcl_structs}}
48+
} // namespace Structs
49+
3850
namespace Attributes {
3951
{{#zcl_attributes_server}}
4052
{{#unless clusterRef}}

0 commit comments

Comments
 (0)