Latest Arduino Library Version:
Latest Espressif Component Version:
esp-lib-utils is a library designed for ESP SoCs to provide utility functions, including logging
, memory management
, and checking
.
// Define the log tag for the current library, should be declared before `esp_utils_library.h`
#define ESP_UTILS_LOG_TAG "MyLibrary"
#include "esp_utils_library.h"
void test_log(void)
{
ESP_UTILS_LOG_TRACE_ENTER();
ESP_UTILS_LOGD("This is a debug message");
ESP_UTILS_LOGI("This is an info message");
ESP_UTILS_LOGW("This is a warning message");
ESP_UTILS_LOGE("This is an error message");
ESP_UTILS_LOG_TRACE_EXIT();
}
void test_memory(void)
{
// Allocate memory in C style (`malloc/calloc` and `free` are re-defined by the library)
int *c_ptr = (int *)malloc(sizeof(int));
ESP_UTILS_CHECK_NULL_EXIT(c_ptr, "Failed to allocate memory");
free(c_ptr);
// Allocate memory in C++ style
std::shared_ptr<int> cxx_ptr = nullptr;
ESP_UTILS_CHECK_EXCEPTION_EXIT(
(cxx_ptr = esp_utils::make_shared<int>()), "Failed to allocate memory"
);
cxx_ptr = nullptr;
}