Skip to content

Commit a2a0b03

Browse files
committed
nimble/host: Replace ble_audio.h macros with __VA_OPT__
Fixes an error at 'newt test all' in Github Actions: repos/apache-mynewt-nimble/nimble/host/audio/include/audio/ble_audio.h:52: error: "TEST" redefined [-Werror] 52 | #define TEST(x, A, FUNC, ...) FUNC |
1 parent 9d7e855 commit a2a0b03

File tree

1 file changed

+42
-63
lines changed

1 file changed

+42
-63
lines changed

nimble/host/audio/include/audio/ble_audio.h

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,6 @@
3333
* @{
3434
*/
3535

36-
/**
37-
* @cond
38-
* Helper macros for BLE_AUDIO_BUILD_CODEC_CONFIG
39-
* @private @{
40-
*/
41-
#define FIELD_LEN_2(_len, _type, _field) _len, _type, _field,
42-
#define FIELD_LEN_5(_len, _type, _field) _len, _type, _field, \
43-
_field >> 8, _field >> 16, \
44-
_field >> 24,
45-
46-
#define FIELD_TESTED_0(_len, _type, _field)
47-
#define FIELD_TESTED_1(_len, _type, _field) FIELD_LEN_ ## _len(_len, \
48-
_type, \
49-
_field)
50-
#define EMPTY() FIELD_TESTED_0
51-
#define PRESENT(X) FIELD_TESTED_1
52-
#define TEST(x, A, FUNC, ...) FUNC
53-
#define TEST_FIELD(...) TEST(, ## __VA_ARGS__, \
54-
PRESENT(__VA_ARGS__), \
55-
EMPTY(__VA_ARGS__))
56-
#define FIELD_TESTED(_test, _len, _type, _field) _test(_len, _type, _field)
57-
#define OPTIONAL_FIELD(_len, _type, ...) FIELD_TESTED(TEST_FIELD \
58-
(__VA_ARGS__), \
59-
_len, \
60-
_type, \
61-
__VA_ARGS__)
62-
63-
/**
64-
* @}
65-
* @endcond
66-
*/
67-
6836
/** Broadcast Audio Broadcast Code Size. */
6937
#define BLE_AUDIO_BROADCAST_CODE_SIZE 16
7038

@@ -439,6 +407,22 @@
439407

440408
/** @} */
441409

410+
/**
411+
* @cond
412+
* Helper macros for BLE_AUDIO_BUILD_CODEC_CONFIG and BLE_AUDIO_BUILD_CODEC_CAPS
413+
* @private @{
414+
*/
415+
#define _BLE_AUDIO_FIELD_LEN_2(_len, _type, _field) _len, _type, _field,
416+
#define _BLE_AUDIO_FIELD_LEN_5(_len, _type, _field) \
417+
_len, _type, _field, _field >> 8, _field >> 16, _field >> 24,
418+
419+
#define _BLE_AUDIO_OPTIONAL_FIELD(_len, _type, ...) \
420+
__VA_OPT__(_BLE_AUDIO_FIELD_LEN_##len(len, type, __VA_ARGS__))
421+
/**
422+
* @}
423+
* @endcond
424+
*/
425+
442426
/**
443427
* @brief Helper macro used to build LTV array of Codec_Specific_Configuration.
444428
*
@@ -453,20 +437,18 @@
453437
*
454438
* @return Pointer to a `ble_uuid16_t` structure.
455439
*/
456-
#define BLE_AUDIO_BUILD_CODEC_CONFIG(_sampling_freq, \
457-
_frame_duration, \
458-
_audio_channel_alloc, \
459-
_octets_per_codec_frame, \
460-
_codec_frame_blocks_per_sdu) \
461-
{ \
462-
2, BLE_AUDIO_CODEC_CONF_SAMPLING_FREQ_TYPE, _sampling_freq, \
463-
2, BLE_AUDIO_CODEC_CONF_FRAME_DURATION_TYPE, _frame_duration, \
464-
OPTIONAL_FIELD(5, BLE_AUDIO_CODEC_CONF_AUDIO_CHANNEL_ALLOCATION_TYPE, \
465-
_audio_channel_alloc) \
466-
3, BLE_AUDIO_CODEC_CONF_OCTETS_PER_CODEC_FRAME_TYPE, \
467-
(_octets_per_codec_frame), ((_octets_per_codec_frame) >> 8), \
468-
OPTIONAL_FIELD(2, BLE_AUDIO_CODEC_CONF_FRAME_BLOCKS_PER_SDU_TYPE, \
469-
_codec_frame_blocks_per_sdu) \
440+
#define BLE_AUDIO_BUILD_CODEC_CONFIG(_sampling_freq, _frame_duration, \
441+
_audio_channel_alloc, _octets_per_codec_frame, \
442+
_codec_frame_blocks_per_sdu) \
443+
{ \
444+
2, BLE_AUDIO_CODEC_CONF_SAMPLING_FREQ_TYPE, _sampling_freq, 2, \
445+
BLE_AUDIO_CODEC_CONF_FRAME_DURATION_TYPE, _frame_duration, \
446+
_BLE_AUDIO_OPTIONAL_FIELD(5, BLE_AUDIO_CODEC_CONF_AUDIO_CHANNEL_ALLOCATION_TYPE, \
447+
_audio_channel_alloc) 3, \
448+
BLE_AUDIO_CODEC_CONF_OCTETS_PER_CODEC_FRAME_TYPE, \
449+
(_octets_per_codec_frame), ((_octets_per_codec_frame) >> 8), \
450+
_BLE_AUDIO_OPTIONAL_FIELD(2, BLE_AUDIO_CODEC_CONF_FRAME_BLOCKS_PER_SDU_TYPE, \
451+
_codec_frame_blocks_per_sdu) \
470452
}
471453

472454
/**
@@ -489,23 +471,20 @@
489471
*
490472
* @return Pointer to a `ble_uuid16_t` structure.
491473
*/
492-
#define BLE_AUDIO_BUILD_CODEC_CAPS(_sampling_freq, \
493-
_frame_duration, \
494-
_audio_channel_counts, \
495-
_min_octets_per_codec_frame, \
496-
_max_octets_per_codec_frame, \
497-
_codec_frames_per_sdu) \
498-
{ \
499-
3, BLE_AUDIO_CODEC_CAPS_SAMPLING_FREQ_TYPE, \
500-
(_sampling_freq), ((_sampling_freq) >> 8), \
501-
2, BLE_AUDIO_CODEC_CAPS_FRAME_DURATION_TYPE, _frame_duration, \
502-
OPTIONAL_FIELD(2, BLE_AUDIO_CODEC_CAPS_SUP_AUDIO_CHANNEL_COUNTS_TYPE, \
503-
_audio_channel_counts) \
504-
5, BLE_AUDIO_CODEC_CAPS_OCTETS_PER_CODEC_FRAME_TYPE, \
505-
(_min_octets_per_codec_frame), ((_min_octets_per_codec_frame) >> 8), \
506-
(_max_octets_per_codec_frame), ((_max_octets_per_codec_frame) >> 8), \
507-
OPTIONAL_FIELD(2, BLE_AUDIO_CODEC_CAPS_FRAMES_PER_SDU_TYPE, \
508-
_codec_frames_per_sdu) \
474+
#define BLE_AUDIO_BUILD_CODEC_CAPS( \
475+
_sampling_freq, _frame_duration, _audio_channel_counts, \
476+
_min_octets_per_codec_frame, _max_octets_per_codec_frame, _codec_frames_per_sdu) \
477+
{ \
478+
3, BLE_AUDIO_CODEC_CAPS_SAMPLING_FREQ_TYPE, (_sampling_freq), \
479+
((_sampling_freq) >> 8), 2, \
480+
BLE_AUDIO_CODEC_CAPS_FRAME_DURATION_TYPE, _frame_duration, \
481+
_BLE_AUDIO_OPTIONAL_FIELD(2, BLE_AUDIO_CODEC_CAPS_SUP_AUDIO_CHANNEL_COUNTS_TYPE, \
482+
_audio_channel_counts) 5, \
483+
BLE_AUDIO_CODEC_CAPS_OCTETS_PER_CODEC_FRAME_TYPE, \
484+
(_min_octets_per_codec_frame), ((_min_octets_per_codec_frame) >> 8), \
485+
(_max_octets_per_codec_frame), ((_max_octets_per_codec_frame) >> 8), \
486+
_BLE_AUDIO_OPTIONAL_FIELD(2, BLE_AUDIO_CODEC_CAPS_FRAMES_PER_SDU_TYPE, \
487+
_codec_frames_per_sdu) \
509488
}
510489

511490
/** Codec Information */

0 commit comments

Comments
 (0)