Skip to content

Commit

Permalink
Merge branch 'bugfix/struct_init_order_blemesh_v5.0' into 'release/v5.0'
Browse files Browse the repository at this point in the history
ble_mesh: example: fix the structure init order to meet C++ requirements(backport v5.0)

See merge request espressif/esp-idf!28930
  • Loading branch information
jack0c committed Mar 19, 2024
2 parents a82f02a + 5f11da0 commit 55adcbf
Show file tree
Hide file tree
Showing 32 changed files with 1,456 additions and 708 deletions.
34 changes: 20 additions & 14 deletions components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ typedef uint8_t esp_ble_mesh_octet8_t[ESP_BLE_MESH_OCTET8_LEN];
#define ESP_BLE_MESH_KEY_PRIMARY 0x0000
#define ESP_BLE_MESH_KEY_ANY 0xFFFF

/*!< Internal macros used to initialize array members */
#define ESP_BLE_MESH_KEY_UNUSED_ELT_(IDX, _) ESP_BLE_MESH_KEY_UNUSED
#define ESP_BLE_MESH_ADDR_UNASSIGNED_ELT_(IDX, _) ESP_BLE_MESH_ADDR_UNASSIGNED
#define ESP_BLE_MESH_MODEL_KEYS_UNUSED \
{ LISTIFY(CONFIG_BLE_MESH_MODEL_KEY_COUNT, ESP_BLE_MESH_KEY_UNUSED_ELT_, (,)) }
#define ESP_BLE_MESH_MODEL_GROUPS_UNASSIGNED \
{ LISTIFY(CONFIG_BLE_MESH_MODEL_GROUP_COUNT, ESP_BLE_MESH_ADDR_UNASSIGNED_ELT_, (,)) }

/*!< Primary Network Key index */
#define ESP_BLE_MESH_NET_PRIMARY 0x000

Expand Down Expand Up @@ -264,26 +272,24 @@ typedef enum {
#define ESP_BLE_MESH_SIG_MODEL(_id, _op, _pub, _user_data) \
{ \
.model_id = (_id), \
.op = _op, \
.keys = { [0 ... (CONFIG_BLE_MESH_MODEL_KEY_COUNT - 1)] = \
ESP_BLE_MESH_KEY_UNUSED }, \
.pub = _pub, \
.groups = { [0 ... (CONFIG_BLE_MESH_MODEL_GROUP_COUNT - 1)] = \
ESP_BLE_MESH_ADDR_UNASSIGNED }, \
.keys = ESP_BLE_MESH_MODEL_KEYS_UNUSED, \
.groups = ESP_BLE_MESH_MODEL_GROUPS_UNASSIGNED, \
.op = _op, \
.user_data = _user_data, \
}

/*!< This macro is associated with BLE_MESH_MODEL_VND_CB in mesh_access.h */
#define ESP_BLE_MESH_VENDOR_MODEL(_company, _id, _op, _pub, _user_data) \
{ \
.vnd.company_id = (_company), \
.vnd.model_id = (_id), \
.op = _op, \
.vnd = { \
.company_id = (_company), \
.model_id = (_id), \
}, \
.pub = _pub, \
.keys = { [0 ... (CONFIG_BLE_MESH_MODEL_KEY_COUNT - 1)] = \
ESP_BLE_MESH_KEY_UNUSED }, \
.groups = { [0 ... (CONFIG_BLE_MESH_MODEL_GROUP_COUNT - 1)] = \
ESP_BLE_MESH_ADDR_UNASSIGNED }, \
.keys = ESP_BLE_MESH_MODEL_KEYS_UNUSED, \
.groups = ESP_BLE_MESH_MODEL_GROUPS_UNASSIGNED, \
.op = _op, \
.user_data = _user_data, \
}

Expand All @@ -302,8 +308,8 @@ typedef enum {
{ \
.location = (_loc), \
.sig_model_count = ARRAY_SIZE(_mods), \
.sig_models = (_mods), \
.vnd_model_count = ARRAY_SIZE(_vnd_mods), \
.sig_models = (_mods), \
.vnd_models = (_vnd_mods), \
}

Expand Down Expand Up @@ -416,8 +422,8 @@ typedef struct {
#define ESP_BLE_MESH_MODEL_PUB_DEFINE(_name, _msg_len, _role) \
NET_BUF_SIMPLE_DEFINE_STATIC(bt_mesh_pub_msg_##_name, _msg_len); \
static esp_ble_mesh_model_pub_t _name = { \
.update = (uint32_t)NULL, \
.msg = &bt_mesh_pub_msg_##_name, \
.update = (uint32_t)NULL, \
.dev_role = _role, \
}

Expand Down
10 changes: 5 additions & 5 deletions components/bt/esp_ble_mesh/mesh_common/include/mesh_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -840,22 +840,22 @@ struct net_buf_pool {
#if defined(CONFIG_BLE_MESH_NET_BUF_POOL_USAGE)
#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _destroy) \
{ \
.alloc = _alloc, \
.__bufs = (struct net_buf *)_bufs, \
.buf_count = _count, \
.uninit_count = _count, \
.avail_count = _count, \
.destroy = _destroy, \
.name = STRINGIFY(_pool), \
.destroy = _destroy, \
.alloc = _alloc, \
.__bufs = (struct net_buf *)_bufs, \
}
#else
#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _destroy) \
{ \
.alloc = _alloc, \
.__bufs = (struct net_buf *)_bufs, \
.buf_count = _count, \
.uninit_count = _count, \
.destroy = _destroy, \
.alloc = _alloc, \
.__bufs = (struct net_buf *)_bufs, \
}
#endif /* CONFIG_BLE_MESH_NET_BUF_POOL_USAGE */

Expand Down
35 changes: 35 additions & 0 deletions components/bt/esp_ble_mesh/mesh_common/include/mesh_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stddef.h>
#include "esp_bit_defs.h"
#include "mesh_types.h"
#include "mesh_utils_loops.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -180,6 +181,40 @@ extern "C" {
*/
#define Z_IS_ENABLED3(ignore_this, val, ...) val

/* Used to remove brackets from around a single argument. */
#define __DEBRACKET(...) __VA_ARGS__

#define UTIL_CAT(a, ...) UTIL_PRIMITIVE_CAT(a, __VA_ARGS__)
#define UTIL_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__

/**
* @brief Generates a sequence of code with configurable separator.
*
* Example:
*
* #define FOO(i, _) MY_PWM ## i
* { LISTIFY(PWM_COUNT, FOO, (,)) }
*
* The above two lines expand to:
*
* { MY_PWM0 , MY_PWM1 }
*
* @param LEN The length of the sequence. Must be an integer literal less
* than 255.
* @param F A macro function that accepts at least two arguments:
* <tt>F(i, ...)</tt>. @p F is called repeatedly in the expansion.
* Its first argument @p i is the index in the sequence, and
* the variable list of arguments passed to LISTIFY are passed
* through to @p F.
*
* @param sep Separator (e.g. comma or semicolon). Must be in parentheses;
* this is required to enable providing a comma as separator.
*
* @note Calling LISTIFY with undefined arguments has undefined
* behavior.
*/
#define LISTIFY(LEN, F, sep, ...) UTIL_CAT(Z_UTIL_LISTIFY_, LEN)(F, sep, __VA_ARGS__)

const char *bt_hex(const void *buf, size_t len);

void mem_rcopy(uint8_t *dst, uint8_t const *src, uint16_t len);
Expand Down
Loading

0 comments on commit 55adcbf

Please sign in to comment.