Skip to content

Commit 044e5ef

Browse files
authored
feat: support C++ building (#77)
* chore: minor templates cleanup * feat: support C++ building Increase minimum supported version to properly support this change. This will allow to provide more flexibility in how code is implemented. Also this will reduce number of required templates to define.
1 parent 54f141e commit 044e5ef

File tree

17 files changed

+70
-43
lines changed

17 files changed

+70
-43
lines changed

config/device.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ type Board struct {
5959
}
6060

6161
func ParseFromFile(configPath string) (*Device, error) {
62+
var minimumNCSVersion = types.NewSemver(2, 6, 0)
63+
6264
cfg := &Device{
6365
General: General{
6466
RunEvery: time.Minute,
@@ -68,7 +70,7 @@ func ParseFromFile(configPath string) (*Device, error) {
6870
}
6971
return "~/ncs"
7072
}(),
71-
NCSVersion: "v2.6.1",
73+
NCSVersion: minimumNCSVersion.String(),
7274
Manufacturer: "FFexix113",
7375
DeviceName: "dongle",
7476
},
@@ -86,6 +88,15 @@ func ParseFromFile(configPath string) (*Device, error) {
8688
return nil, fmt.Errorf("unmarshal config file: %w", err)
8789
}
8890

91+
selectedNCSVersion, err := types.ParseSemver(cfg.General.NCSVersion)
92+
if err != nil {
93+
return nil, fmt.Errorf("could not parse selected NCS version: %w", err)
94+
}
95+
96+
if minimumNCSVersion.Compare(selectedNCSVersion) == 1 {
97+
return nil, fmt.Errorf("selected NCS version is lower than minimum supported version: selected %q, minimum supported %q", cfg.General.NCSVersion, minimumNCSVersion)
98+
}
99+
89100
return cfg, nil
90101
}
91102

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
general:
22
board: nrf52840dongle_nrf52840
33
# We can force specific version of toolchain (if it is available).
4-
ncs_version: v2.5.0
4+
ncs_version: v2.6.2

templates/extenders/sensor.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (Sensor) AppConfig() []appconfig.ConfigValue {
2323

2424
// Includes implements templates.Extender.
2525
func (Sensor) Includes() []string {
26-
return []string{"zephyr/drivers/sensor.h", "zbhome_sensor.h"}
26+
return []string{"zephyr/drivers/sensor.h", "zbhome_sensor.hpp"}
2727
}
2828

2929
// Template implements templates.Extender.
@@ -35,12 +35,12 @@ func (Sensor) Template() string {
3535
func (Sensor) WriteFiles() []generator.WriteFile {
3636
return []generator.WriteFile{
3737
{
38-
FileName: "zbhome_sensor.h",
39-
TemplateName: "zbhome_sensor.h",
38+
FileName: "zbhome_sensor.hpp",
39+
TemplateName: "zbhome_sensor.hpp",
4040
},
4141
{
42-
FileName: "zbhome_sensor.c",
43-
TemplateName: "zbhome_sensor.c",
42+
FileName: "zbhome_sensor.cpp",
43+
TemplateName: "zbhome_sensor.cpp",
4444
},
4545
}
4646
}

templates/src/CMakeLists.txt.tpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ project(zigbee_common)
2424
################################################################################
2525

2626
# NORDIC SDK APP START
27+
FILE(GLOB app_sources_cpp src/*.cpp src/**/*.cpp)
2728
FILE(GLOB app_sources src/*.c src/**/*.c)
28-
target_sources(app PRIVATE ${app_sources})
29+
target_sources(app
30+
PRIVATE ${app_sources_cpp}
31+
PRIVATE ${app_sources}
32+
)
2933

3034
# NORDIC SDK APP END

templates/src/device.h.tpl renamed to templates/src/device.hpp.tpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

3-
#include "clusters.h"
3+
#include <zboss_api_addons.h>
4+
#include "clusters.hpp"
45

56
/* Delay for console initialization */
67
#define WAIT_FOR_CONSOLE_MSEC 100

templates/src/extenders/sensors/device_temperature.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ if (err != NRFX_SUCCESS)
88
}
99
{{ end}}
1010

11+
{{ define "top_level" }}
12+
{{/* No need to define a device, as it is handled by NRFX lib */}}
13+
{{- end}}
14+
1115
{{ define "loop"}}
1216
int res = nrfx_temp_measure();
1317
if (res != NRFX_SUCCESS) {

templates/src/extenders/zbhome_sensor.c.tpl renamed to templates/src/extenders/zbhome_sensor.cpp.tpl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#include <zboss_api.h>
21
#include <zephyr/logging/log.h>
32
#include <zephyr/drivers/sensor.h>
43

5-
#include "zbhome_sensor.h"
6-
#include "clusters.h"
4+
#include "zbhome_sensor.hpp"
5+
#include "clusters.hpp"
76

87
LOG_MODULE_DECLARE(app, LOG_LEVEL_INF);
98

templates/src/extenders/zbhome_sensor.h.tpl renamed to templates/src/extenders/zbhome_sensor.hpp.tpl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef ZBHOME_SENSOR_H
2-
#define ZBHOME_SENSOR_H
1+
#pragma once
32

43
#define GENERATE_ATTR_VAL_SETTER(cluster_name, cluster) \
54
zb_zcl_status_t zbhome_set_attr_val_for_##cluster_name(int endpoint, zb_uint8_t * data_ptr) { \
@@ -51,5 +50,3 @@ NAME_GENERATE_SENSOR_FULL_FOR_ATTR(pressure);
5150
#ifdef ZB_ZCL_CLUSTER_ID_CARBON_DIOXIDE
5251
NAME_GENERATE_SENSOR_FULL_FOR_ATTR(carbon_dioxide);
5352
#endif
54-
55-
#endif

templates/src/main.c.tpl renamed to templates/src/main.cpp.tpl

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,26 @@
66

77
// Generated by zigbee_home on {{ .GeneratedOn }}, version {{ .Version }}
88

9+
#include <zephyr/kernel.h>
910
#include <zephyr/device.h>
10-
#include <dk_buttons_and_leds.h>
11-
// #include <zephyr/drivers/uart.h>
12-
#include <zephyr/logging/log.h>
1311
#include <ram_pwrdn.h>
12+
#include <dk_buttons_and_leds.h>
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
1418
#include <zb_nrf_platform.h>
15-
#include <zboss_api.h>
16-
#include <zboss_api_addons.h>
17-
#include <zephyr/kernel.h>
19+
20+
#ifdef __cplusplus
21+
}
22+
#endif
23+
1824
#include <zigbee/zigbee_app_utils.h>
1925
#include <zigbee/zigbee_error_handler.h>
2026

2127
// Header only, why not?
22-
#include "device.h"
28+
#include "device.hpp"
2329

2430
// Extender includes
2531
{{- range .Extenders}}
@@ -192,7 +198,7 @@ static void zcl_device_cb(zb_bufid_t bufid)
192198
ZB_FALSE);
193199
194200
switch (cluster_id) {
195-
case ZB_ZCL_CLUSTER_ID_ON_OFF:
201+
case ZB_ZCL_CLUSTER_ID_ON_OFF: {
196202
uint8_t value =
197203
device_cb_param->cb_param.set_attr_value_param
198204
.values.data8;
@@ -211,13 +217,15 @@ static void zcl_device_cb(zb_bufid_t bufid)
211217
{{- end}}
212218
}
213219
break;
214-
default:
220+
}
221+
default: {
215222
/* Other clusters can be processed here */
216223
LOG_INF("Unhandled cluster attribute id: %d",
217224
cluster_id);
218225
device_cb_param->status = RET_NOT_IMPLEMENTED;
219226
break;
220227
}
228+
}
221229

222230
break;
223231

templates/src/zigbee/carbon_dioxide.tpl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void zb_zcl_carbon_dioxide_init_server()
2727
}
2828

2929
#define ZB_ZCL_CLUSTER_ID_CARBON_DIOXIDE_SERVER_ROLE_INIT zb_zcl_carbon_dioxide_init_server
30-
#define ZB_ZCL_CLUSTER_ID_CARBON_DIOXIDE_CLIENT_ROLE_INIT (NULL)
30+
#define ZB_ZCL_CLUSTER_ID_CARBON_DIOXIDE_CLIENT_ROLE_INIT ((zb_zcl_cluster_init_t)NULL)
3131

3232

3333
typedef void * zb_voidp_t;
@@ -36,9 +36,7 @@ typedef void * zb_voidp_t;
3636
ZB_ZCL_ATTR_CARBON_DIOXIDE_VALUE_ID, \
3737
ZB_ZCL_ATTR_TYPE_SINGLE, \
3838
ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \
39-
{{ if not ncsVersionIs_2_5 -}}
4039
(ZB_UINT16_MAX), \
41-
{{ end -}}
4240
(zb_voidp_t) data_ptr \
4341
}
4442

@@ -47,9 +45,7 @@ typedef void * zb_voidp_t;
4745
ZB_ZCL_ATTR_CARBON_DIOXIDE_MIN_VALUE_ID, \
4846
ZB_ZCL_ATTR_TYPE_SINGLE, \
4947
ZB_ZCL_ATTR_ACCESS_READ_ONLY, \
50-
{{ if not ncsVersionIs_2_5 -}}
5148
(ZB_UINT16_MAX), \
52-
{{ end -}}
5349
(zb_voidp_t) data_ptr \
5450
}
5551

@@ -58,9 +54,7 @@ typedef void * zb_voidp_t;
5854
ZB_ZCL_ATTR_CARBON_DIOXIDE_MAX_VALUE_ID, \
5955
ZB_ZCL_ATTR_TYPE_SINGLE, \
6056
ZB_ZCL_ATTR_ACCESS_READ_ONLY, \
61-
{{ if not ncsVersionIs_2_5 -}}
6257
(ZB_UINT16_MAX), \
63-
{{ end -}}
6458
(zb_voidp_t) data_ptr \
6559
}
6660

@@ -69,9 +63,7 @@ typedef void * zb_voidp_t;
6963
ZB_ZCL_ATTR_CARBON_DIOXIDE_TOLERANCE_ID, \
7064
ZB_ZCL_ATTR_TYPE_SINGLE, \
7165
ZB_ZCL_ATTR_ACCESS_READ_ONLY, \
72-
{{ if not ncsVersionIs_2_5 -}}
7366
(ZB_UINT16_MAX), \
74-
{{ end -}}
7567
(zb_voidp_t) data_ptr \
7668
}
7769

0 commit comments

Comments
 (0)