forked from trombik/esp-homie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esp_idf_lib_helpers.h
147 lines (125 loc) · 5.74 KB
/
esp_idf_lib_helpers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#if !defined(__ESP_IDF_LIB_HELPERS__H__)
#define __ESP_IDF_LIB_HELPERS__H__
/*
* MIT License
*
* Copyright (c) 2019 Tomoyuki Sakurai
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/* XXX this header file does not need to include freertos/FreeRTOS.h.
* but without it, ESP8266 RTOS SDK does not include `sdkconfig.h` in correct
* order. as this header depends on sdkconfig.h, sdkconfig.h must be included
* first. however, the SDK includes this header first, then includes
* `sdkconfig.h` when freertos/FreeRTOS.h is not explicitly included. an
* evidence can be found in `build/${COMPONENT}/${COMPONENT}.d` in a failed
* build.
*/
#include <freertos/FreeRTOS.h>
/* {{{ pre-tests */
#if defined(CONFIG_IDF_TARGET_ESP32) && defined(CONFIG_IDF_TARGET_ESP8266)
#error BUG: defined(CONFIG_IDF_TARGET_ESP32) && defined(CONFIG_IDF_TARGET_ESP8266)
#endif
/* }}} */
/* Constant macros for TARGET and SDK version
*/
#define HELPER_TARGET_VERSION_ESP32_V0 (32000000)
#define HELPER_TARGET_VERSION_ESP32_V3_3 (32030300)
#define HELPER_TARGET_VERSION_ESP32_V3_2 (32030200)
#define HELPER_TARGET_VERSION_ESP32_V4 (32040000)
#define HELPER_TARGET_VERSION_ESP32_V_MAX (32999999)
#define HELPER_TARGET_VERSION_ESP8266_V0 (8266000000)
#define HELPER_TARGET_VERSION_ESP8266_V3_2 (8266030200)
#define HELPER_TARGET_VERSION_ESP8266_V_MAX (8266999999)
/* Target and SDK version guestimation.
*
* ESP_IDF_VERSION_VAL macro is provided in esp-idf 4.x, or the current master
* branch. Other esp-idf versions and ESP8266 RTOS SDK do not provide macro to
* branch code flow.
*/
#if defined(CONFIG_IDF_TARGET_ESP32) && defined(CONFIG_SDK_TOOLPREFIX)
/* esp32 and esp-idf 4.x */
#define HELPER_TARGET_VERSION HELPER_TARGET_VERSION_ESP32_V4
#elif defined(CONFIG_IDF_TARGET_ESP8266)
/* ESP8266 RTOS SDK 3.2 */
#define HELPER_TARGET_VERSION HELPER_TARGET_VERSION_ESP8266_V3_2
#elif !defined(CONFIG_IDF_TARGET_ESP32) && !defined(CONFIG_SDK_TOOLPREFIX) && defined(ESP_PLATFORM)
/* esp-idf 3.2 does not define CONFIG_IDF_TARGET_*, ESP_PLATFORM, nor CONFIG_SDK_TOOLPREFIX.
*/
#define HELPER_TARGET_VERSION HELPER_TARGET_VERSION_ESP32_V3_2
#elif defined(CONFIG_IDF_TARGET_ESP32) && !defined(CONFIG_SDK_TOOLPREFIX) && defined(ESP_PLATFORM)
/* but if ESP_PLATFORM is set in build environment, it is 3.3
*/
#define HELPER_TARGET_VERSION HELPER_TARGET_VERSION_ESP32_V3_3
#else
#error BUG: Cannot guess target version
#endif
/* HELPER_TARGET_IS_ESP32
*
* 1 when the target is esp32
*/
#if (HELPER_TARGET_VERSION >= HELPER_TARGET_VERSION_ESP32_V0) && (HELPER_TARGET_VERSION <= HELPER_TARGET_VERSION_ESP32_V_MAX)
#define HELPER_TARGET_IS_ESP32 (1)
#define HELPER_TARGET_IS_ESP8266 (0)
/* HELPER_TARGET_IS_ESP8266
* 1 when the target is esp8266
*/
#elif HELPER_TARGET_VERSION >= HELPER_TARGET_VERSION_ESP8266_V0 && HELPER_TARGET_VERSION <= HELPER_TARGET_VERSION_ESP8266_V_MAX
#define HELPER_TARGET_IS_ESP32 (0)
#define HELPER_TARGET_IS_ESP8266 (1)
#else
#error BUG: cannot determine the target
#endif
/* {{{ post-tests */
#if HELPER_TARGET_IS_ESP32 == 1 && HELPER_TARGET_IS_ESP8266 == 1
#error BUG: HELPER_TARGET_IS_ESP32 == 1 && HELPER_TARGET_IS_ESP8266 == 1
#endif
#if HELPER_TARGET_IS_ESP32 && HELPER_TARGET_IS_ESP8266
#error BUG: HELPER_TARGET_IS_ESP32 && HELPER_TARGET_IS_ESP8266
#endif
#if HELPER_TARGET_IS_ESP32 == 0 && HELPER_TARGET_IS_ESP8266 == 0
#error BUG: HELPER_TARGET_IS_ESP32 == 0 && HELPER_TARGET_IS_ESP8266 == 0
#endif
#if !HELPER_TARGET_IS_ESP32 && !HELPER_TARGET_IS_ESP8266
#error BUG: !HELPER_TARGET_IS_ESP32 && !HELPER_TARGET_IS_ESP8266
#endif
#if HELPER_TARGET_VERSION > HELPER_TARGET_VERSION_ESP8266_V_MAX || HELPER_TARGET_VERSION < HELPER_TARGET_VERSION_ESP32_V0
#error BUG: HELPER_TARGET_VERSION range under/overflow
#endif
#if HELPER_TARGET_IS_ESP32 && HELPER_TARGET_VERSION >= HELPER_TARGET_VERSION_ESP8266_V0
#error HELPER_TARGET_IS_ESP32 is true but HELPER_TARGET_VERSION >= HELPER_TARGET_VERSION_ESP8266_V0
#endif
#if HELPER_TARGET_IS_ESP8266 && HELPER_TARGET_VERSION < HELPER_TARGET_VERSION_ESP8266_V0
#error HELPER_TARGET_IS_ESP8266 is true but HELPER_TARGET_VERSION < HELPER_TARGET_VERSION_ESP8266_V0
#endif
/* }}} */
/* show the actual values for debugging */
#if defined(DEBUG)
#define VALUE_TO_STRING(x) #x
#define VALUE(x) VALUE_TO_STRING(x)
#define VAR_NAME_VALUE(var) #var "=" VALUE(var)
#pragma message(VAR_NAME_VALUE(CONFIG_IDF_TARGET_ESP32))
#pragma message(VAR_NAME_VALUE(CONFIG_IDF_TARGET_ESP8266))
#pragma message(VAR_NAME_VALUE(CONFIG_SDK_TOOLPREFIX))
#pragma message(VAR_NAME_VALUE(ESP_PLATFORM))
#pragma message(VAR_NAME_VALUE(HELPER_TARGET_VERSION))
#pragma message(VAR_NAME_VALUE(HELPER_TARGET_IS_ESP8266))
#pragma message(VAR_NAME_VALUE(HELPER_TARGET_IS_ESP32))
#endif
#endif // !defined(__ESP_IDF_LIB_HELPERS__H__)