8000 GitHub - esp-arduino-libs/esp-lib-utils at d6bfe558e20eb35b418f43f9453261a72af93063
[go: up one dir, main page]

Skip to content

esp-arduino-libs/esp-lib-utils

Repository files navigation

Arduino Lint pre-commit Build Test Apps Version Consistency

Latest Arduino Library Version: GitHub Release

Latest Espressif Component Version: Espressif Release

ESP Library Utils

esp-lib-utils is a library designed for ESP SoCs to provide utility functions, including logging, memory management, and checking.

How to Use

// 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;
}
0