include soc/uarts.h for pin definitions (#2939)
[ExpressLRS.git] / src / include / targets.h
blobb3eb3cb3cefae009fa2b95e5b40292361e72ec64
1 #pragma once
2 #if !defined TARGET_NATIVE
3 #include <Arduino.h>
4 #endif
6 #define UNDEF_PIN (-1)
8 /// General Features ///
9 #define LED_MAX_BRIGHTNESS 50 //0..255 for max led brightness
11 /////////////////////////
13 #define WORD_ALIGNED_ATTR __attribute__((aligned(4)))
14 #define WORD_PADDED(size) (((size)+3) & ~3)
16 #ifdef PLATFORM_STM32
17 /* ICACHE_RAM_ATTR1 is always linked into RAM */
18 #define ICACHE_RAM_ATTR1 __section(".ram_code")
19 /* ICACHE_RAM_ATTR2 is linked into RAM only if enough space */
20 #if RAM_CODE_LIMITED
21 #define ICACHE_RAM_ATTR2
22 #else
23 #define ICACHE_RAM_ATTR2 __section(".ram_code")
24 #endif
25 #define ICACHE_RAM_ATTR //nothing//
26 #else
27 #undef ICACHE_RAM_ATTR //fix to allow both esp32 and esp8266 to use ICACHE_RAM_ATTR for mapping to IRAM
28 #define ICACHE_RAM_ATTR IRAM_ATTR
29 #endif
31 #if defined(TARGET_NATIVE)
32 #define IRAM_ATTR
33 #include "native.h"
34 #endif
36 #ifndef DMA_ATTR
37 #define DMA_ATTR
38 #endif
41 * Features
42 * define features based on pins before defining pins as UNDEF_PIN
44 #if defined(GPIO_PIN_FAN_EN)
45 #define HAS_FAN
46 #endif
47 #if defined(USE_OLED_I2C) || defined(USE_OLED_SPI) || defined(USE_OLED_SPI_SMALL) || defined(HAS_TFT_SCREEN)
48 #define HAS_SCREEN
49 #endif
50 #if defined(GPIO_PIN_SPI_VTX_NSS)
51 #if !defined(HAS_VTX_SPI)
52 #define HAS_VTX_SPI
53 #define HAS_MSP_VTX
54 #define OPT_HAS_VTX_SPI true
55 #endif
56 #else
57 #define OPT_HAS_VTX_SPI false
58 #endif
60 #ifndef USE_TX_BACKPACK
61 #define OPT_USE_TX_BACKPACK false
62 #elif !defined(OPT_USE_TX_BACKPACK)
63 #define OPT_USE_TX_BACKPACK true
64 #endif
66 #ifndef HAS_THERMAL
67 #define OPT_HAS_THERMAL false
68 #define OPT_HAS_THERMAL_LM75A false
69 #elif !defined(OPT_HAS_THERMAL)
70 #define OPT_HAS_THERMAL true
71 #endif
73 #ifndef HAS_GSENSOR
74 #define OPT_HAS_GSENSOR false
75 #elif !defined(OPT_HAS_GSENSOR)
76 #define OPT_HAS_GSENSOR true
77 #endif
79 #if defined(GPIO_PIN_SDA) && defined(GPIO_PIN_SCL)
80 #define USE_I2C
81 #else
82 #define GPIO_PIN_SDA UNDEF_PIN
83 #define GPIO_PIN_SCL UNDEF_PIN
84 #endif
86 #ifndef GPIO_PIN_BUFFER_OE
87 #define GPIO_PIN_BUFFER_OE UNDEF_PIN
88 #endif
89 #ifndef GPIO_PIN_SCK
90 #define GPIO_PIN_SCK UNDEF_PIN
91 #endif
92 #ifndef GPIO_PIN_NSS_2
93 #define GPIO_PIN_NSS_2 UNDEF_PIN
94 #endif
95 #ifndef GPIO_PIN_RST
96 #define GPIO_PIN_RST UNDEF_PIN
97 #endif
98 #ifndef GPIO_PIN_RST_2
99 #define GPIO_PIN_RST_2 UNDEF_PIN
100 #endif
101 #ifndef GPIO_PIN_BUSY
102 #define GPIO_PIN_BUSY UNDEF_PIN
103 #endif
104 #ifndef GPIO_PIN_BUSY_2
105 #define GPIO_PIN_BUSY_2 UNDEF_PIN
106 #endif
107 #ifndef GPIO_PIN_DIO0
108 #define GPIO_PIN_DIO0 UNDEF_PIN
109 #endif
110 #ifndef GPIO_PIN_DIO0_2
111 #define GPIO_PIN_DIO0_2 UNDEF_PIN
112 #endif
113 #ifndef GPIO_PIN_DIO1
114 #define GPIO_PIN_DIO1 UNDEF_PIN
115 #endif
116 #ifndef GPIO_PIN_DIO1_2
117 #define GPIO_PIN_DIO1_2 UNDEF_PIN
118 #endif
119 #ifndef GPIO_PIN_DIO2
120 #define GPIO_PIN_DIO2 UNDEF_PIN
121 #endif
122 #ifndef GPIO_PIN_PA_ENABLE
123 #define GPIO_PIN_PA_ENABLE UNDEF_PIN
124 #endif
125 #ifndef GPIO_PIN_RX_ENABLE
126 #define GPIO_PIN_RX_ENABLE UNDEF_PIN
127 #endif
128 #ifndef GPIO_PIN_RX_ENABLE_2
129 #define GPIO_PIN_RX_ENABLE_2 UNDEF_PIN
130 #endif
131 #ifndef GPIO_PIN_TX_ENABLE
132 #define GPIO_PIN_TX_ENABLE UNDEF_PIN
133 #endif
134 #ifndef GPIO_PIN_TX_ENABLE_2
135 #define GPIO_PIN_TX_ENABLE_2 UNDEF_PIN
136 #endif
137 #ifndef GPIO_PIN_ANT_CTRL
138 #define GPIO_PIN_ANT_CTRL UNDEF_PIN
139 #endif
140 #ifndef GPIO_PIN_ANT_CTRL_COMPL
141 #define GPIO_PIN_ANT_CTRL_COMPL UNDEF_PIN
142 #endif
143 #ifndef GPIO_PIN_RFamp_APC1
144 #define GPIO_PIN_RFamp_APC1 UNDEF_PIN
145 #endif
146 #ifndef GPIO_PIN_RFamp_APC2
147 #define GPIO_PIN_RFamp_APC2 UNDEF_PIN
148 #endif
149 #ifndef POWER_OUTPUT_FIXED
150 #define POWER_OUTPUT_FIXED -99
151 #endif
152 #ifndef GPIO_PIN_FAN_EN
153 #define GPIO_PIN_FAN_EN UNDEF_PIN
154 #endif
155 #ifndef GPIO_PIN_FAN_PWM
156 #define GPIO_PIN_FAN_PWM UNDEF_PIN
157 #endif
158 #ifndef GPIO_PIN_FAN_TACHO
159 #define GPIO_PIN_FAN_TACHO UNDEF_PIN
160 #endif
161 #ifndef GPIO_PIN_OLED_MOSI
162 #define GPIO_PIN_OLED_MOSI UNDEF_PIN
163 #endif
164 #ifndef GPIO_PIN_OLED_CS
165 #define GPIO_PIN_OLED_CS UNDEF_PIN
166 #endif
167 #ifndef GPIO_PIN_OLED_DC
168 #define GPIO_PIN_OLED_DC UNDEF_PIN
169 #endif
172 #ifndef GPIO_PIN_FIVE_WAY_INPUT1
173 #define GPIO_PIN_FIVE_WAY_INPUT1 UNDEF_PIN
174 #endif
175 #ifndef GPIO_PIN_FIVE_WAY_INPUT2
176 #define GPIO_PIN_FIVE_WAY_INPUT2 UNDEF_PIN
177 #endif
178 #ifndef GPIO_PIN_FIVE_WAY_INPUT3
179 #define GPIO_PIN_FIVE_WAY_INPUT3 UNDEF_PIN
180 #endif
183 #ifndef GPIO_PIN_OLED_SCK
184 #define GPIO_PIN_OLED_SCK GPIO_PIN_SCL
185 #endif
186 #ifndef GPIO_PIN_OLED_SDA
187 #define GPIO_PIN_OLED_SDA GPIO_PIN_SDA
188 #endif
190 #if !defined(BACKPACK_LOGGING_BAUD)
191 #define BACKPACK_LOGGING_BAUD 460800
192 #endif
193 #ifndef GPIO_PIN_BACKPACK_BOOT
194 #define GPIO_PIN_BACKPACK_BOOT UNDEF_PIN
195 #endif
197 #ifndef GPIO_PIN_SPI_VTX_NSS
198 #define GPIO_PIN_SPI_VTX_NSS UNDEF_PIN
199 #endif
202 #if defined(TARGET_TX)
203 #if defined(PLATFORM_ESP32)
204 #ifndef GPIO_PIN_DEBUG_RX
205 #define GPIO_PIN_DEBUG_RX 3
206 #endif
207 #ifndef GPIO_PIN_DEBUG_TX
208 #define GPIO_PIN_DEBUG_TX 1
209 #endif
210 #elif defined(PLATFORM_ESP8266)
211 #ifndef GPIO_PIN_DEBUG_RX
212 #define GPIO_PIN_DEBUG_RX UNDEF_PIN
213 #endif
214 #ifndef GPIO_PIN_DEBUG_TX
215 #define GPIO_PIN_DEBUG_TX UNDEF_PIN
216 #endif
217 #endif
218 #if !defined(TARGET_UNIFIED_TX)
219 #if defined(DEBUG_LOG) || defined(DEBUG_LOG_VERBOSE) || defined(USE_TX_BACKPACK)
220 #if GPIO_PIN_RCSIGNAL_TX == GPIO_PIN_DEBUG_TX || GPIO_PIN_RCSIGNAL_TX == GPIO_PIN_DEBUG_RX
221 #error "Cannot debug out the RC signal port!"
222 #endif
223 #if !defined(GPIO_PIN_DEBUG_RX) || !defined(GPIO_PIN_DEBUG_TX) || GPIO_PIN_DEBUG_RX == UNDEF_PIN || GPIO_PIN_DEBUG_TX == UNDEF_PIN
224 #error "When using DEBUG_LOG, DEBUG_LOG_VERBOSE or USE_TX_BACKPACK you must define both GPIO_PIN_DEBUG_RX and GPIO_PIN_DEBUG_TX"
225 #endif
226 #endif
227 #endif
228 #else // TARGET_RX
229 #ifndef GPIO_PIN_RCSIGNAL_TX_SBUS
230 #define GPIO_PIN_RCSIGNAL_TX_SBUS UNDEF_PIN
231 #endif
232 #ifndef GPIO_PIN_RCSIGNAL_RX_SBUS
233 #define GPIO_PIN_RCSIGNAL_RX_SBUS UNDEF_PIN
234 #endif
235 #if defined(PLATFORM_ESP8266)
236 #ifndef GPIO_PIN_DEBUG_RX
237 #define GPIO_PIN_DEBUG_RX 3
238 #endif
239 #ifndef GPIO_PIN_DEBUG_TX
240 #define GPIO_PIN_DEBUG_TX 1
241 #endif
242 #endif
243 #endif
245 // Using these DEBUG_* imply that no SerialIO will be used so the output is readable
246 #if !defined(DEBUG_CRSF_NO_OUTPUT) && defined(TARGET_RX) && (defined(DEBUG_RCVR_LINKSTATS) || defined(DEBUG_RX_SCOREBOARD) || defined(DEBUG_RCVR_SIGNAL_STATS))
247 #define DEBUG_CRSF_NO_OUTPUT
248 #endif
250 #if defined(DEBUG_CRSF_NO_OUTPUT)
251 #define OPT_CRSF_RCVR_NO_SERIAL true
252 #elif defined(TARGET_UNIFIED_RX)
253 extern bool pwmSerialDefined;
255 #define OPT_CRSF_RCVR_NO_SERIAL (GPIO_PIN_RCSIGNAL_RX == UNDEF_PIN && GPIO_PIN_RCSIGNAL_TX == UNDEF_PIN && !pwmSerialDefined)
256 #else
257 #define OPT_CRSF_RCVR_NO_SERIAL false
258 #endif
260 #if defined(USE_ANALOG_VBAT) && !defined(GPIO_ANALOG_VBAT)
261 #define GPIO_ANALOG_VBAT A0
262 #if !defined(ANALOG_VBAT_SCALE)
263 #define ANALOG_VBAT_SCALE 1
264 #endif
265 #endif
267 #if defined(RADIO_SX128X)
268 #define Regulatory_Domain_ISM_2400 1
269 // ISM 2400 band is in use => undefine other requlatory domain defines
270 #undef Regulatory_Domain_AU_915
271 #undef Regulatory_Domain_EU_868
272 #undef Regulatory_Domain_IN_866
273 #undef Regulatory_Domain_FCC_915
274 #undef Regulatory_Domain_AU_433
275 #undef Regulatory_Domain_EU_433
276 #undef Regulatory_Domain_US_433
277 #undef Regulatory_Domain_US_433_WIDE
279 #elif defined(RADIO_SX127X) || defined(RADIO_LR1121)
280 #if !(defined(Regulatory_Domain_AU_915) || defined(Regulatory_Domain_FCC_915) || \
281 defined(Regulatory_Domain_EU_868) || defined(Regulatory_Domain_IN_866) || \
282 defined(Regulatory_Domain_AU_433) || defined(Regulatory_Domain_EU_433) || \
283 defined(Regulatory_Domain_US_433) || defined(Regulatory_Domain_US_433_WIDE) || \
284 defined(UNIT_TEST))
285 #error "Regulatory_Domain is not defined for 900MHz device. Check user_defines.txt!"
286 #endif
287 #else
288 #error "Either RADIO_SX127X, RADIO_LR1121 or RADIO_SX128X must be defined!"
289 #endif
291 #if defined(TARGET_UNIFIED_TX) || defined(TARGET_UNIFIED_RX)
292 #if defined(PLATFORM_ESP32)
293 #include <soc/uart_pins.h>
294 #endif
295 #if !defined(U0RXD_GPIO_NUM)
296 #define U0RXD_GPIO_NUM (3)
297 #endif
298 #if !defined(U0TXD_GPIO_NUM)
299 #define U0TXD_GPIO_NUM (1)
300 #endif
301 #include "hardware.h"
302 #endif