Skip to content

Commit

Permalink
WIP: Compiles
Browse files Browse the repository at this point in the history
Big problems with recursive macro usage (CONCAT and CONCAT2)
  • Loading branch information
PavelVPV committed Dec 13, 2024
1 parent c03a254 commit 2a9c7c8
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 0 deletions.
13 changes: 13 additions & 0 deletions samples/bluetooth/mesh/ngcdp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

set(EXTRA_DTC_OVERLAY_FILE ${CMAKE_CURRENT_SOURCE_DIR}/ble_mesh.overlay)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(blinky)

# Add custom bindings path
zephyr_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dts/bindings)

target_sources(app PRIVATE src/main.c)
21 changes: 21 additions & 0 deletions samples/bluetooth/mesh/ngcdp/ble_mesh.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/ {
mesh: mesh {
elements {
element_1 {
location = <1>;
compatible = "bt,mesh-element";
models {
model-cfg-srv {
compatible = "bt,mesh-model-cfg-srv";
};
model-health-srv {
compatible = "bt,mesh-model-health-srv";
};
model-onoff-cli-0 {
compatible = "bt,mesh-model-onoff-cli";
};
};
};
};
};
};
8 changes: 8 additions & 0 deletions samples/bluetooth/mesh/ngcdp/dts/bindings/ble_mesh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ble_mesh.yaml
description: Bt Mesh Element properties

compatible: "bt,mesh-element"

properties:
location:
type: int
50 changes: 50 additions & 0 deletions samples/bluetooth/mesh/ngcdp/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
CONFIG_NCS_SAMPLES_DEFAULTS=y

# Deferred logging helps improve LPN power consumption
# when friendship is established.
CONFIG_LOG_MODE_DEFERRED=y

# General configuration
CONFIG_NCS_APPLICATION_BOOT_BANNER_STRING="Mesh Light Switch"
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_NVS_LOOKUP_CACHE=y
CONFIG_SETTINGS_NVS_NAME_CACHE=y
CONFIG_HWINFO=y
CONFIG_DK_LIBRARY=y
CONFIG_PM_SINGLE_IMAGE=y
CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE=0x8000
CONFIG_SOC_FLASH_NRF_PARTIAL_ERASE=y

# Bluetooth configuration
CONFIG_BT=y
CONFIG_BT_DEVICE_NAME="Mesh Light Switch"
CONFIG_BT_L2CAP_TX_BUF_COUNT=8
CONFIG_BT_OBSERVER=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_SETTINGS=y
# Increase RX stack size to avoid overflow during provisioning
CONFIG_BT_RX_STACK_SIZE=2700

# Disable unused Bluetooth features
CONFIG_BT_CTLR_LE_ENC=n
CONFIG_BT_PHY_UPDATE=n
CONFIG_BT_CTLR_CHAN_SEL_2=n
CONFIG_BT_CTLR_MIN_USED_CHAN=n
CONFIG_BT_CTLR_PRIVACY=n

# Bluetooth Mesh configuration
CONFIG_BT_MESH=y
CONFIG_BT_MESH_RELAY=y
CONFIG_BT_MESH_FRIEND=y
CONFIG_BT_MESH_TX_SEG_MAX=32
CONFIG_BT_MESH_PB_GATT=y
CONFIG_BT_MESH_GATT_PROXY=y
CONFIG_BT_MESH_PROXY_USE_DEVICE_NAME=y
CONFIG_BT_MESH_DK_PROV=y

# Bluetooth Mesh models
CONFIG_BT_MESH_ONOFF_CLI=y
12 changes: 12 additions & 0 deletions samples/bluetooth/mesh/ngcdp/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sample:
name: Blinky Sample
tests:
sample.basic.blinky:
tags:
- LED
- gpio
filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds")
depends_on: gpio
harness: led
integration_platforms:
- frdm_k64f
90 changes: 90 additions & 0 deletions samples/bluetooth/mesh/ngcdp/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdio.h>
#include <zephyr/kernel.h>

// FIXME:...
#define CONFIG_BT_MESH_USES_TINYCRYPT 1

#include <zephyr/bluetooth/mesh.h>
#include <bluetooth/mesh/models.h>

#include <zephyr/devicetree.h>

static struct bt_mesh_onoff_cli onoff_cli;

/* Define your mesh element nodes */
#define MESH_NODE DT_PATH(mesh) //DT_NODELABEL(mesh)

/* Find a node that is compatible with "bt,mesh-model-health-srv" */
#define CFG_SRV_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(bt_mesh_model_cfg_srv)

#define EXPAND(x) x

#define bt_mesh_model_cfg_srv_MACRO EXPAND(BT_MESH_MODEL_CFG_SRV)
#define bt_mesh_model_health_srv_MACRO EXPAND(BT_MESH_MODEL_HEALTH_SRV(NULL, NULL))
#define bt_mesh_model_onoff_cli_MACRO EXPAND(BT_MESH_MODEL_ONOFF_CLI(&onoff_cli))


//#define MACRO_FROM_COMPAT(compat) compat##_MACRO

//#define DT_BT_MESH_MODEL_INIT(model) DT_PROP(model, compatible)##_MACRO,

// Helper macro to concatenate tokens
#define CONCAT2(a, b) a##b
#define EXPAND_AND_CONCAT(a, b) CONCAT2(a, b)

#define DT_BT_MESH_MODEL_INIT(model) EXPAND_AND_CONCAT(DT_STRING_TOKEN_BY_IDX(model, compatible, 0), _MACRO),


#define MODELS(element) \
((struct bt_mesh_model[]) { DT_FOREACH_CHILD(DT_CHILD(element, models), DT_BT_MESH_MODEL_INIT) })

#define DT_BT_MESH_ELEM_INIT(element) { \
.rt = &(struct bt_mesh_elem_rt_ctx) { 0 }, \
.loc = (DT_PROP(element, location)), \
.model_count = DT_CHILD_NUM(DT_CHILD(element, models)), \
.vnd_model_count = 0, \
.models = MODELS(element), \
.vnd_models = NULL, \
},

struct bt_mesh_elem elements[] = {
DT_FOREACH_CHILD_SEP(DT_CHILD(MESH_NODE, elements), DT_BT_MESH_ELEM_INIT, (,))
};

int main(void)
{
#if 0
/* Extract Element and Model Data */
const struct device *mesh_dev = device_get_binding(DT_LABEL(MESH_NODE));

if (mesh_dev == NULL) {
printk("Failed to get mesh device\n");
return;
}

/* Element 1 */
const int element_1_reg = DT_PROP(DT_CHILD(MESH_NODE, element_1), reg);
const char *model_cfg_srv = DT_PROP(DT_CHILD(DT_CHILD(MESH_NODE, element_1), model_cfg_srv), compatible);

/* Element 2 */
const int element_2_reg = DT_PROP(DT_CHILD(MESH_NODE, element_2), reg);
const char *model_onoff_cli_1 = DT_PROP(DT_CHILD(DT_CHILD(MESH_NODE, element_2), model_onoff_cli_1), compatible);
#endif

/* Further elements and models can be accessed in a similar way */

if (DT_NODE_EXISTS(CFG_SRV_NODE)) {
/* Node exists, you can now use this node */
printk("Config Server node found!\n");
} else {
printk("Config Server node not found!\n");
}

return 0;
}

0 comments on commit 2a9c7c8

Please sign in to comment.