#pragma once #include #include "esp_err.h" #include "esp_log.h" #define ESP_RETURN_ON_ERROR(x, tag, fmt, ...) \ do { \ esp_err_t err_rc_ = (x); \ if (err_rc_ != ESP_OK) { \ ESP_LOGE(tag, "%s(%d): " fmt, __func__, (int)err_rc_, ##__VA_ARGS__); \ return err_rc_; \ } \ } while (0) #define ESP_RETURN_ON_FALSE(cond, err, tag, fmt, ...) \ do { \ if (!(cond)) { \ ESP_LOGE(tag, "%s(%d): " fmt, __func__, (int)(err), ##__VA_ARGS__); \ return (err); \ } \ } while (0) #define ESP_ERROR_CHECK(x) \ do { \ esp_err_t err_rc_ = (x); \ if (err_rc_ != ESP_OK) { \ ESP_LOGE("check", "%s:%d: %s", __FILE__, __LINE__, esp_err_to_name(err_rc_)); \ abort(); \ } \ } while (0) #define ESP_ERROR_CHECK_WITHOUT_ABORT(x) \ do { \ esp_err_t err_rc_ = (x); \ if (err_rc_ != ESP_OK) { \ ESP_LOGE("check", "%s:%d: %s", __FILE__, __LINE__, esp_err_to_name(err_rc_)); \ } \ } while (0)