ESPixelStick Firmware
Firmware for the ESPixelStick
Loading...
Searching...
No Matches
backported.h
Go to the documentation of this file.
1#pragma once
2#include <Arduino.h>
3
4
5// ESP32 defines various types and functions that are missing on ESP8266.
6// Backport missing types / macros to allow simpler source management.
7
8#if defined(ARDUINO_ARCH_ESP32)
9# include "esp_err.h"
10#elif defined(ARDUINO_ARCH_ESP8266)
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16typedef int esp_err_t; // currently only need two defined status: OK & FAIL
17#define ESP_OK 0
18#define ESP_FAIL -1
19
20#ifdef DEBUG_ESP_PORT
21 #define LOG_ERROR_MSG(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )
22#else
23 #define LOG_ERROR_MSG(...)
24#endif
25
26#ifndef likely
27 #define likely(x) __builtin_expect(!!(x), 1)
28#endif
29#ifndef unlikely
30 #define unlikely(x) __builtin_expect(!!(x), 0)
31#endif
32
33#if defined(NDEBUG)
34 #define ESP_ERROR_CHECK(x) \
35 do { \
36 esp_err_t err_rc_ = (x); \
37 (void) sizeof(err_rc_); \
38 } while(0)
39#elif defined(CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT)
40 #define ESP_ERROR_CHECK(x) \
41 do { \
42 esp_err_t err_rc_ = (x); \
43 if (unlikely(err_rc_ != ESP_OK)) { \
44 abort(); \
45 } \
46 } while(0)
47#else
48 #define ESP_ERROR_CHECK(x) \
49 do { \
50 esp_err_t err_rc_ = (x); \
51 if (unlikely(err_rc_ != ESP_OK)) { \
52 LOG_ERROR_MSG("err: esp_err_t = %d", rc); \
53 assert(0 && #x); \
54 } \
55 } while(0);
56
57#endif
58
59
60
61
62
63#ifdef __cplusplus
64}
65#endif
66
67#else
68# error "Unsupported CPU type"
69#endif
70
71