Skip to content

Commit 94e5b95

Browse files
authored
Merge pull request #12 from esp-arduino-libs/feat/add_thread
### Enhancements: * feat(log): add CXX log trace guard and ESP-IDF log implementation * feat(check): add value check macros * feat(repo): add thread module, support configure thread * feat(repo): add more module, support some guard classes * feat(cmake): remove CXX compile options
2 parents d289aa4 + bc01765 commit 94e5b95

21 files changed

+512
-40
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# ChangeLog
22

3+
## v0.2.2 - 2025-06-27
4+
5+
### Enhancements:
6+
7+
* feat(log): add CXX log trace guard and ESP-IDF log implementation
8+
* feat(check): add value check macros
9+
* feat(repo): add thread module, support configure thread
10+
* feat(repo): add more module, support some guard classes
11+
* feat(cmake): remove CXX compile options
12+
313
## v0.2.1 - 2025-05-30
414

515
### Enhancements:

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ if(ESP_PLATFORM)
66
idf_component_register(
77
SRCS ${SRCS_C} ${SRCS_CPP}
88
INCLUDE_DIRS ${SRC_DIR}
9+
PRIV_REQUIRES pthread
910
)
1011
else()
1112
set(COMPONENT_LIB esp-lib-utils)
@@ -16,8 +17,6 @@ endif()
1617
target_compile_options(${COMPONENT_LIB}
1718
PUBLIC
1819
-Wno-missing-field-initializers
19-
PRIVATE
20-
$<$<COMPILE_LANGUAGE:CXX>:-std=gnu++20>
2120
)
2221

2322
if(NOT ESP_PLATFORM)

Kconfig

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ menu "ESP Library Utils Configurations"
77

88
if ESP_UTILS_CONF_FILE_SKIP
99
menu "Check functions"
10-
choice ESP_UTILS_CONF_CHECK_HANDLE_METHOD
10+
choice ESP_UTILS_CONF_CHECK_HANDLE_METHOD_CHOICE
1111
prompt "Select handle method when check failed"
1212
default ESP_UTILS_CHECK_HANDLE_WITH_ERROR_LOG
1313

@@ -29,7 +29,23 @@ menu "ESP Library Utils Configurations"
2929
endmenu
3030

3131
menu "Log functions"
32-
choice ESP_UTILS_CONF_LOG_LEVEL
32+
choice ESP_UTILS_CONF_LOG_IMPL_TYPE_CHOICE
33+
prompt "Select log implementation"
34+
default ESP_UTILS_CONF_LOG_IMPL_ESP
35+
36+
config ESP_UTILS_CONF_LOG_IMPL_STDLIB
37+
bool "Standard (printf)"
38+
39+
config ESP_UTILS_CONF_LOG_IMPL_ESP
40+
bool "ESP (ESP_LOG)"
41+
endchoice
42+
43+
config ESP_UTILS_CONF_LOG_IMPL_TYPE
44+
int
45+
default 0 if ESP_UTILS_CONF_LOG_IMPL_STDLIB
46+
default 1 if ESP_UTILS_CONF_LOG_IMPL_ESP
47+
48+
choice ESP_UTILS_CONF_LOG_LEVEL_CHOICE
3349
prompt "Select global log level"
3450
default ESP_UTILS_CONF_LOG_LEVEL_INFO
3551

@@ -110,7 +126,7 @@ menu "ESP Library Utils Configurations"
110126
default 2 if ESP_UTILS_CONF_MEM_GEN_ALLOC_TYPE_MICROPYTHON
111127
default 3 if ESP_UTILS_CONF_MEM_GEN_ALLOC_TYPE_CUSTOM
112128

113-
choice ESP_UTILS_CONF_MEM_GEN_ALLOC_ESP_CAPS
129+
choice ESP_UTILS_CONF_MEM_GEN_ALLOC_ESP_CAPS_CHOICE
114130
prompt "ESP memory caps"
115131
depends on ESP_UTILS_CONF_MEM_GEN_ALLOC_TYPE_ESP
116132
default ESP_UTILS_CONF_MEM_GEN_ALLOC_ESP_CAPS_DEFAULT
@@ -177,7 +193,7 @@ menu "ESP Library Utils Configurations"
177193
default 2 if ESP_UTILS_CONF_MEM_CXX_GLOB_ALLOC_TYPE_MICROPYTHON
178194
default 3 if ESP_UTILS_CONF_MEM_CXX_GLOB_ALLOC_TYPE_CUSTOM
179195

180-
choice ESP_UTILS_CONF_MEM_CXX_GLOB_ALLOC_ESP_CAPS
196+
choice ESP_UTILS_CONF_MEM_CXX_GLOB_ALLOC_ESP_CAPS_CHOICE
181197
prompt "ESP memory caps"
182198
depends on ESP_UTILS_CONF_MEM_CXX_GLOB_ALLOC_TYPE_ESP
183199
default ESP_UTILS_CONF_MEM_CXX_GLOB_ALLOC_ESP_CAPS_DEFAULT

esp_utils_conf.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2323
////////////////////////////////////////////////// Log Configurations //////////////////////////////////////////////////
2424
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
25+
/**
26+
* Log implementation, choose one of the following:
27+
* - ESP_UTILS_CONF_LOG_IMPL_STDLIB: Use the standard library log implementation (printf)
28+
* - ESP_UTILS_CONF_LOG_IMPL_ESP: Use the ESP-IDF log implementation (ESP_LOG)
29+
*/
30+
#define ESP_UTILS_CONF_LOG_IMPL_TYPE (ESP_UTILS_CONF_LOG_IMPL_STDLIB)
31+
2532
/**
2633
* Global log level, logs with a level lower than this will not be compiled. Choose one of the following:
2734
* - ESP_UTILS_LOG_LEVEL_DEBUG: Extra information which is not necessary for normal use (values, pointers, sizes, etc)
@@ -135,7 +142,7 @@
135142
* 3. Patch version mismatch: No impact on functionality
136143
*/
137144
#define ESP_UTILS_CONF_FILE_VERSION_MAJOR 1
138-
#define ESP_UTILS_CONF_FILE_VERSION_MINOR 3
145+
#define ESP_UTILS_CONF_FILE_VERSION_MINOR 4
139146
#define ESP_UTILS_CONF_FILE_VERSION_PATCH 0
140147

141148
// *INDENT-ON*

idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "0.2.1"
1+
version: "0.2.2"
22
description: esp-lib-utils is a library designed for ESP SoCs to provide utility functions, including logging, checking, and memory.
33
url: https://github.com/esp-arduino-libs/esp-lib-utils
44
repository: https://github.com/esp-arduino-libs/esp-lib-utils.git

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=esp-lib-utils
2-
version=0.2.1
2+
version=0.2.2
33
author=espressif
44
maintainer=espressif
55
sentence=esp-lib-utils is a library designed for ESP SoCs to provide utility functions, including logging, checking, and memory.

src/check/esp_utils_check.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@
189189
} while (0)
190190
#endif // __cplusplus && CONFIG_COMPILER_CXX_EXCEPTIONS
191191

192+
/**
193+
* @brief Check if the value is within the range [min, max];
194+
*
195+
* @param x Value to check
196+
* @param min Minimum acceptable value
197+
* @param max Maximum acceptable value
198+
*/
199+
#define ESP_UTILS_CHECK_VALUE(x, min, max) do { \
200+
__typeof__(x) _x = (x); \
201+
__typeof__(min) _min = (min); \
202+
__typeof__(max) _max = (max); \
203+
if ((_x < _min) || (_x > _max)) { \
204+
} \
205+
} while(0)
206+
192207
#else
193208

194209
#ifndef unlikely
@@ -392,6 +407,22 @@
392407
} while (0)
393408
#endif // __cplusplus && CONFIG_COMPILER_CXX_EXCEPTIONS
394409

410+
/**
411+
* @brief Check if the value is within the range [min, max]; if not, log an error
412+
*
413+
* @param x Value to check
414+
* @param min Minimum acceptable value
415+
* @param max Maximum acceptable value
416+
*/
417+
#define ESP_UTILS_CHECK_VALUE(x, min, max) do { \
418+
__typeof__(x) _x = (x); \
419+
__typeof__(min) _min = (min); \
420+
__typeof__(max) _max = (max); \
421+
if ((_x < _min) || (_x > _max)) { \
422+
ESP_UTILS_LOGE("Invalid value: %d, should be in range [%d, %d]", _x, _min, _max); \
423+
} \
424+
} while(0)
425+
395426
#elif ESP_UTILS_CONF_CHECK_HANDLE_METHOD == ESP_UTILS_CHECK_HANDLE_WITH_ASSERT
396427

397428
#define ESP_UTILS_CHECK_NULL_RETURN(x, ...) assert((x) != NULL)
@@ -456,9 +487,69 @@
456487
} while (0)
457488
#endif // __cplusplus && CONFIG_COMPILER_CXX_EXCEPTIONS
458489

490+
#define ESP_UTILS_CHECK_VALUE(x, min, max) do { \
491+
__typeof__(x) _x = (x); \
492+
__typeof__(min) _min = (min); \
493+
__typeof__(max) _max = (max); \
494+
assert((_x >= _min) && (_x <= _max)); \
495+
} while(0)
496+
459497
#endif // ESP_UTILS_CONF_CHECK_HANDLE_METHOD
460498
#endif // ESP_UTILS_CONF_CHECK_HANDLE_METHOD
461499

500+
/**
501+
* @brief Check if the value is within the range [min, max]; if not, log an error and return the specified value.
502+
*
503+
* @param x Value to check
504+
* @param min Minimum acceptable value
505+
* @param max Maximum acceptable value
506+
* @param ret Value to return if the value is out of range
507+
* @param fmt Format string for the error message
508+
* @param ... Additional arguments for the format string
509+
*/
510+
#define ESP_UTILS_CHECK_VALUE_RETURN(x, min, max, ret, fmt, ...) do { \
511+
__typeof__(x) __x = (x); \
512+
__typeof__(min) __min = (min); \
513+
__typeof__(max) __max = (max); \
514+
ESP_UTILS_CHECK_VALUE(__x, __min, __max); \
515+
ESP_UTILS_CHECK_FALSE_RETURN((__x >= __min) && (__x <= __max), ret, fmt, ##__VA_ARGS__); \
516+
} while(0)
517+
518+
/**
519+
* @brief Check if the value is within the range [min, max]; if not, log an error and goto the specified label.
520+
*
521+
* @param x Value to check
522+
* @param min Minimum acceptable value
523+
* @param max Maximum acceptable value
524+
* @param goto_tag Label to jump to if the value is out of range
525+
* @param fmt Format string for the error message
526+
* @param ... Additional arguments for the format string
527+
*/
528+
#define ESP_UTILS_CHECK_VALUE_GOTO(x, min, max, goto_tag, fmt, ...) do { \
529+
__typeof__(x) __x = (x); \
530+
__typeof__(min) __min = (min); \
531+
__typeof__(max) __max = (max); \
532+
ESP_UTILS_CHECK_VALUE(__x, __min, __max); \
533+
ESP_UTILS_CHECK_FALSE_GOTO((__x >= __min) && (__x <= __max), goto_tag, fmt, ##__VA_ARGS__); \
534+
} while(0)
535+
536+
/**
537+
* @brief Check if the value is within the range [min, max]; if not, log an error and return without a value.
538+
*
539+
* @param x Value to check
540+
* @param min Minimum acceptable value
541+
* @param max Maximum acceptable value
542+
* @param fmt Format string for the error message
543+
* @param ... Additional arguments for the format string
544+
*/
545+
#define ESP_UTILS_CHECK_VALUE_EXIT(x, min, max, fmt, ...) do { \
546+
__typeof__(x) __x = (x); \
547+
__typeof__(min) __min = (min); \
548+
__typeof__(max) __max = (max); \
549+
ESP_UTILS_CHECK_VALUE(__x, __min, __max); \
550+
ESP_UTILS_CHECK_FALSE_EXIT((__x >= __min) && (__x <= __max), fmt, ##__VA_ARGS__); \
551+
} while(0)
552+
462553
#ifdef __cplusplus
463554
#ifndef ESP_UTILS_CHECK_EXCEPTION_RETURN
464555
#define ESP_UTILS_CHECK_EXCEPTION_RETURN(x, ret, fmt, ...) ((void)(x))

src/esp_lib_utils.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@
1818

1919
/* Memory */
2020
#include "memory/esp_utils_mem.h"
21+
22+
#if defined(__cplusplus)
23+
/* Thread */
24+
#include "thread/esp_utils_thread.hpp"
25+
/* Log */
26+
#include "log/esp_utils_log.hpp"
27+
/* More */
28+
#include "more/esp_utils_more.hpp"
29+
#endif // defined(__cplusplus)

src/esp_utils_conf_kconfig.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2121
////////////////////////////////////////////////// LOG Configurations //////////////////////////////////////////////////
2222
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
23+
#ifndef ESP_UTILS_CONF_LOG_IMPL_TYPE
24+
# ifdef CONFIG_ESP_UTILS_CONF_LOG_IMPL_TYPE
25+
# define ESP_UTILS_CONF_LOG_IMPL_TYPE CONFIG_ESP_UTILS_CONF_LOG_IMPL_TYPE
26+
# else
27+
# define ESP_UTILS_CONF_LOG_IMPL_TYPE ESP_UTILS_LOG_IMPL_STDLIB
28+
# endif
29+
#endif
30+
2331
#ifndef ESP_UTILS_CONF_LOG_LEVEL
2432
# ifdef CONFIG_ESP_UTILS_CONF_LOG_LEVEL
2533
# define ESP_UTILS_CONF_LOG_LEVEL CONFIG_ESP_UTILS_CONF_LOG_LEVEL

src/esp_utils_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
#define ESP_UTILS_CHECK_HANDLE_WITH_ERROR_LOG (1) /*!< Print error message when check failed */
1414
#define ESP_UTILS_CHECK_HANDLE_WITH_ASSERT (2) /*!< Assert when check failed */
1515

16+
/**
17+
* @brief Macros for log implementation
18+
*/
19+
#define ESP_UTILS_LOG_IMPL_STDLIB (0) /*!< Standard (printf) */
20+
#define ESP_UTILS_LOG_IMPL_ESP (1) /*!< ESP (esp_log) */
21+
1622
/**
1723
* @brief Macros for log level
1824
*/

0 commit comments

Comments
 (0)