VSF Documented
esp_macros.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18/*
19 * Clean-room re-implementation of ESP-IDF public API "esp_macros.h".
20 *
21 * General-purpose helper macros used across ESP-IDF:
22 * CHOOSE_MACRO_VA_ARG — variadic overload selection
23 * ESP_VA_NARG — count VA_ARGS arguments
24 * ESP_UNUSED — suppress unused-variable warning
25 * ESP_INFINITE_LOOP — intentional infinite loop
26 *
27 * Baseline: ESP-IDF v5.1 public API.
28 */
29
30#ifndef __VSF_ESPIDF_ESP_MACROS_H__
31#define __VSF_ESPIDF_ESP_MACROS_H__
32
33#include <assert.h>
34#include "esp_compiler.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/* ------------------------------------------------------------------ */
41/* CHOOSE_MACRO_VA_ARG — pick macro based on whether __VA_ARGS__ is */
42/* empty. Dual-path: C++20 __VA_OPT__ vs GNU ##__VA_ARGS__ */
43/* ------------------------------------------------------------------ */
44#if defined(__cplusplus) && (__cplusplus > 201703L)
45# define _ESP_CHOOSE_VA_ARG_INN_IMPL(...) __VA_OPT__(0)
46# define _ESP_CHOOSE_VA_ARG_INN(one, MACRO1, MACRO2, ...) MACRO1
47# define CHOOSE_MACRO_VA_ARG(MACRO_WITH_ARGS, MACRO_WITH_NO_ARGS, ...) \
48 _ESP_CHOOSE_VA_ARG_INN(_ESP_CHOOSE_VA_ARG_INN_IMPL(__VA_ARGS__) \
49 __VA_OPT__(,) MACRO_WITH_ARGS, MACRO_WITH_NO_ARGS, 0)
50#else
51# define _ESP_CHOOSE_VA_ARG_INN(one, two, MACRO1, MACRO2, ...) MACRO1
52# define CHOOSE_MACRO_VA_ARG(MACRO_WITH_ARGS, MACRO_WITH_NO_ARGS, ...) \
53 _ESP_CHOOSE_VA_ARG_INN(0, ##__VA_ARGS__, \
54 MACRO_WITH_ARGS, MACRO_WITH_NO_ARGS, 0)
55#endif
56
57/* ------------------------------------------------------------------ */
58/* ESP_VA_NARG — count number of arguments (0..16) */
59/* ------------------------------------------------------------------ */
60#ifndef ESP_VA_NARG
61# define ESP_VA_NARG(...) _ESP_NARG(_0, ##__VA_ARGS__, _ESP_RSEQ_N())
62
63# define _ESP_NARG(...) _ESP_GET_NTH_ARG(__VA_ARGS__)
64# define _ESP_GET_NTH_ARG( \
65 _01,_02,_03,_04,_05,_06,_07,_08,_09,_10, \
66 _11,_12,_13,_14,_15,_16,N,...) N
67# define _ESP_RSEQ_N() \
68 15,14,13,12,11,10, \
69 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
70#endif
71
72/* ------------------------------------------------------------------ */
73/* ESP_UNUSED — suppress "unused variable" warning */
74/* ------------------------------------------------------------------ */
75#ifndef ESP_UNUSED
76# define ESP_UNUSED(x) ((void)(x))
77#endif
78
79/* ------------------------------------------------------------------ */
80/* ESP_INFINITE_LOOP — intentional infinite loop with diag suppression */
81/* ------------------------------------------------------------------ */
82#define ESP_INFINITE_LOOP() \
83 do { \
84 ESP_COMPILER_DIAGNOSTIC_PUSH_IGNORE("-Wanalyzer-infinite-loop") \
85 while(1); \
86 ESP_COMPILER_DIAGNOSTIC_POP("-Wanalyzer-infinite-loop") \
87 } while(1)
88
89#ifdef __cplusplus
90}
91#endif
92
93#endif // __VSF_ESPIDF_ESP_MACROS_H__
Generated from commit: vsfteam/vsf@c3767bf