Merge pull request #11195 from mathiasvr/pr-elrs-clean
[betaflight.git] / src / main / target / common_post.h
blob44c690e13491f5a0e41ecebc47157851b73cbc73
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 // Touch up configuration
23 #pragma once
25 #include "build/version.h"
27 #if defined(USE_VTX_RTC6705_SOFTSPI)
28 #define USE_VTX_RTC6705
29 #endif
31 #ifndef USE_DSHOT
32 #undef USE_ESC_SENSOR
33 #endif
35 #ifndef USE_ESC_SENSOR
36 #undef USE_ESC_SENSOR_TELEMETRY
37 #endif
39 // XXX Followup implicit dependencies among DASHBOARD, display_xxx and USE_I2C.
40 // XXX This should eventually be cleaned up.
41 #ifndef USE_I2C
42 #undef USE_I2C_OLED_DISPLAY
43 #undef USE_DASHBOARD
44 #else
45 #ifdef USE_DASHBOARD
46 #define USE_I2C_OLED_DISPLAY
47 #endif
48 #endif
50 // XXX Remove USE_BARO_BMP280 and USE_BARO_MS5611 if USE_I2C is not defined.
51 // XXX This should go away buy editing relevant target.h files
52 #if !defined(USE_I2C)
53 #if defined(USE_BARO_BMP280)
54 #undef USE_BARO_BMP280
55 #endif
56 #if defined(USE_BARO_MS5611)
57 #undef USE_BARO_MS5611
58 #endif
59 #endif
61 #if !defined(USE_MAG)
62 #undef USE_MAG_DATA_READY_SIGNAL
63 #undef USE_MAG_HMC5883
64 #undef USE_MAG_SPI_HMC5883
65 #undef USE_MAG_QMC5883
66 #undef USE_MAG_LIS3MDL
67 #undef USE_MAG_AK8963
68 #undef USE_MAG_SPI_AK8963
69 #endif
71 #if !defined(USE_BARO) && !defined(USE_GPS)
72 #undef USE_VARIO
73 #endif
75 #if defined(USE_BARO) && !defined(BARO_EOC_PIN)
76 #define BARO_EOC_PIN NONE
77 #endif
80 #if !defined(USE_SERIAL_RX)
81 #undef USE_SERIALRX_CRSF
82 #undef USE_SERIALRX_IBUS
83 #undef USE_SERIALRX_JETIEXBUS
84 #undef USE_SERIALRX_SBUS
85 #undef USE_SERIALRX_SPEKTRUM
86 #undef USE_SERIALRX_SUMD
87 #undef USE_SERIALRX_SUMH
88 #undef USE_SERIALRX_XBUS
89 #undef USE_SERIALRX_FPORT
90 #endif
92 #if !defined(USE_TELEMETRY)
93 #undef USE_TELEMETRY_CRSF
94 #undef USE_TELEMETRY_GHST
95 #undef USE_TELEMETRY_FRSKY_HUB
96 #undef USE_TELEMETRY_HOTT
97 #undef USE_TELEMETRY_IBUS
98 #undef USE_TELEMETRY_IBUS_EXTENDED
99 #undef USE_TELEMETRY_JETIEXBUS
100 #undef USE_TELEMETRY_LTM
101 #undef USE_TELEMETRY_MAVLINK
102 #undef USE_TELEMETRY_SMARTPORT
103 #undef USE_TELEMETRY_SRXL
104 #undef USE_SERIALRX_FPORT
105 #endif
107 #if !defined(USE_SERIALRX_CRSF)
108 #undef USE_TELEMETRY_CRSF
109 #undef USE_CRSF_LINK_STATISTICS
110 #undef USE_CRSF_V3
111 #endif
113 #if !defined(USE_RX_EXPRESSLRS) && !defined(USE_SERIALRX_CRSF)
114 #undef USE_RX_RSSI_DBM
115 #endif
117 #if !defined(USE_SERIALRX_GHST)
118 #undef USE_TELEMETRY_GHST
119 #endif
121 #if !defined(USE_TELEMETRY_CRSF) || !defined(USE_CMS)
122 #undef USE_CRSF_CMS_TELEMETRY
123 #endif
125 #if !defined(USE_SERIALRX_JETIEXBUS)
126 #undef USE_TELEMETRY_JETIEXBUS
127 #endif
129 #if !defined(USE_TELEMETRY_IBUS)
130 #undef USE_TELEMETRY_IBUS_EXTENDED
131 #endif
133 // If USE_SERIALRX_SPEKTRUM was dropped by a target, drop all related options
134 #ifndef USE_SERIALRX_SPEKTRUM
135 #undef USE_SPEKTRUM_BIND
136 #undef USE_SPEKTRUM_BIND_PLUG
137 #undef USE_SPEKTRUM_REAL_RSSI
138 #undef USE_SPEKTRUM_FAKE_RSSI
139 #undef USE_SPEKTRUM_RSSI_PERCENT_CONVERSION
140 #undef USE_SPEKTRUM_VTX_CONTROL
141 #undef USE_SPEKTRUM_VTX_TELEMETRY
142 #undef USE_TELEMETRY_SRXL
143 #endif
145 #if !defined(USE_CMS) || !defined(USE_TELEMETRY_SRXL)
146 #undef USE_SPEKTRUM_CMS_TELEMETRY
147 #endif
149 #if defined(USE_SERIALRX_SBUS) || defined(USE_SERIALRX_FPORT)
150 #define USE_SBUS_CHANNELS
151 #endif
153 #if !defined(USE_TELEMETRY_SMARTPORT) && !defined(USE_TELEMETRY_CRSF)
154 #undef USE_MSP_OVER_TELEMETRY
155 #endif
157 #if !defined(USE_RX_MSP) && defined(USE_RX_MSP_OVERRIDE)
158 #undef USE_RX_MSP_OVERRIDE
159 #endif
161 /* If either VTX_CONTROL or VTX_COMMON is undefined then remove common code and device drivers */
162 #if !defined(USE_VTX_COMMON) || !defined(USE_VTX_CONTROL)
163 #undef USE_VTX_COMMON
164 #undef USE_VTX_CONTROL
165 #undef USE_VTX_TRAMP
166 #undef USE_VTX_SMARTAUDIO
167 #undef USE_VTX_TABLE
168 #undef USE_VTX_MSP
169 #endif
171 #if defined(USE_RX_FRSKY_SPI_D) || defined(USE_RX_FRSKY_SPI_X) || defined(USE_RX_REDPINE_SPI)
172 #define USE_RX_CC2500
173 #define USE_RX_FRSKY_SPI
174 #endif
176 #if defined(USE_RX_SFHSS_SPI)
177 #define USE_RX_CC2500
178 #endif
180 #if !defined(USE_RX_CC2500)
181 #undef USE_RX_CC2500_SPI_PA_LNA
182 #endif
184 #if !defined(USE_RX_CC2500_SPI_PA_LNA)
185 #undef USE_RX_CC2500_SPI_DIVERSITY
186 #endif
188 // Burst dshot to default off if not configured explicitly by target
189 #ifndef ENABLE_DSHOT_DMAR
190 #define ENABLE_DSHOT_DMAR DSHOT_DMAR_OFF
191 #endif
193 // Some target doesn't define USE_ADC which USE_ADC_INTERNAL depends on
194 #ifndef USE_ADC
195 #undef USE_ADC_INTERNAL
196 #endif
198 #if defined(USE_FLASH_W25M512)
199 #define USE_FLASH_W25M
200 #define USE_FLASH_M25P16
201 #define USE_FLASH_W25M
202 #endif
204 #if defined(USE_FLASH_W25M02G)
205 #define USE_FLASH_W25N01G
206 #define USE_FLASH_W25M
207 #endif
209 #if defined(USE_FLASH_M25P16) || defined(USE_FLASH_W25N01G)
210 #define USE_FLASH_CHIP
211 #endif
213 #ifndef USE_FLASH_CHIP
214 #undef USE_FLASHFS
215 #endif
217 #if (!defined(USE_SDCARD) && !defined(USE_FLASHFS)) || !defined(USE_BLACKBOX)
218 #undef USE_USB_MSC
219 #endif
221 #if !defined(USE_SDCARD)
222 #undef USE_SDCARD_SDIO
223 #undef USE_SDCARD_SPI
224 #endif
226 #if !defined(USE_VCP)
227 #undef USE_USB_CDC_HID
228 #undef USE_USB_MSC
229 #endif
231 #if defined(USE_USB_CDC_HID) || defined(USE_USB_MSC)
232 #define USE_USB_ADVANCED_PROFILES
233 #endif
235 #if defined(USE_MAX7456)
236 #define USE_OSD
237 #endif
239 #if !defined(USE_OSD)
240 #undef USE_RX_LINK_QUALITY_INFO
241 #undef USE_OSD_PROFILES
242 #undef USE_OSD_STICK_OVERLAY
243 #undef USE_RX_LINK_UPLINK_POWER
244 #endif
246 #if defined(USE_GPS_RESCUE)
247 #define USE_GPS
248 #endif
250 // Generate USE_SPI_GYRO or USE_I2C_GYRO
251 #if defined(USE_GYRO_L3G4200D) || defined(USE_GYRO_MPU3050) || defined(USE_GYRO_MPU6000) || defined(USE_GYRO_MPU6050) || defined(USE_GYRO_MPU6500)
252 #define USE_I2C_GYRO
253 #endif
255 #if defined(USE_GYRO_SPI_ICM20689) || defined(USE_GYRO_SPI_MPU6000) || defined(USE_GYRO_SPI_MPU6500) || defined(USE_GYRO_SPI_MPU9250) || defined(USE_GYRO_L3GD20) || defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P)
256 #define USE_SPI_GYRO
257 #endif
259 // CX10 is a special case of SPI RX which requires XN297
260 #if defined(USE_RX_CX10)
261 #define USE_RX_XN297
262 #endif
264 // Setup crystal frequency on F4 for backward compatibility
265 // Should be set to zero for generic targets to ensure USB is working
266 // when unconfigured for targets with non-standard crystal.
267 // Can be set at runtime with with CLI parameter 'system_hse_value'.
268 #if !defined(STM32F4) || defined(USE_UNIFIED_TARGET)
269 #define SYSTEM_HSE_VALUE 0
270 #else
271 #ifdef TARGET_XTAL_MHZ
272 #define SYSTEM_HSE_VALUE TARGET_XTAL_MHZ
273 #else
274 #define SYSTEM_HSE_VALUE (HSE_VALUE/1000000U)
275 #endif
276 #endif // !STM32F4 || USE_UNIFIED_TARGET
278 // Number of pins that needs pre-init
279 #ifdef USE_SPI
280 #ifndef SPI_PREINIT_COUNT
281 #define SPI_PREINIT_COUNT 16 // 2 x 8 (GYROx2, BARO, MAG, MAX, FLASHx2, RX)
282 #endif
283 #endif
285 #ifndef USE_BLACKBOX
286 #undef USE_USB_MSC
287 #endif
289 #if (!defined(USE_FLASHFS) || !defined(USE_RTC_TIME) || !defined(USE_USB_MSC) || !defined(USE_PERSISTENT_OBJECTS))
290 #undef USE_PERSISTENT_MSC_RTC
291 #endif
293 #if !defined(USE_SERIAL_4WAY_BLHELI_BOOTLOADER) && !defined(USE_SERIAL_4WAY_SK_BOOTLOADER)
294 #undef USE_SERIAL_4WAY_BLHELI_INTERFACE
295 #elif !defined(USE_SERIAL_4WAY_BLHELI_INTERFACE) && (defined(USE_SERIAL_4WAY_BLHELI_BOOTLOADER) || defined(USE_SERIAL_4WAY_SK_BOOTLOADER))
296 #define USE_SERIAL_4WAY_BLHELI_INTERFACE
297 #endif
299 #if !defined(USE_PWM_OUTPUT)
300 #undef USE_SERIAL_4WAY_BLHELI_INTERFACE // implementation requires USE_PWM_OUTPUT to find motor outputs.
301 #endif
303 #if !defined(USE_LED_STRIP)
304 #undef USE_LED_STRIP_STATUS_MODE
305 #endif
307 #if defined(USE_LED_STRIP) && !defined(USE_LED_STRIP_STATUS_MODE)
308 #define USE_WS2811_SINGLE_COLOUR
309 #endif
311 #if defined(SIMULATOR_BUILD) || defined(UNIT_TEST)
312 // This feature uses 'arm_math.h', which does not exist for x86.
313 #undef USE_DYN_NOTCH_FILTER
314 #endif
316 #ifndef USE_CMS
317 #undef USE_CMS_FAILSAFE_MENU
318 #endif
320 #ifndef USE_DSHOT
321 #undef USE_DSHOT_TELEMETRY
322 #undef USE_DSHOT_BITBANG
323 #endif
325 #ifndef USE_DSHOT_TELEMETRY
326 #undef USE_RPM_FILTER
327 #undef USE_DSHOT_TELEMETRY_STATS
328 #endif
330 #if !defined(USE_BOARD_INFO)
331 #undef USE_SIGNATURE
332 #endif
334 #if !defined(USE_ACC)
335 #undef USE_GPS_RESCUE
336 #undef USE_ACRO_TRAINER
337 #endif
339 #if (!defined(USE_GPS_RESCUE) || !defined(USE_CMS_FAILSAFE_MENU))
340 #undef USE_CMS_GPS_RESCUE_MENU
341 #endif
343 #ifndef USE_BEEPER
344 #undef BEEPER_PIN
345 #undef BEEPER_PWM_HZ
346 #endif
348 #if defined(USE_DSHOT) || defined(USE_LED_STRIP) || defined(USE_TRANSPONDER)
349 #define USE_TIMER_DMA
350 #else
351 #undef USE_DMA_SPEC
352 #endif
354 #if !defined(USE_DMA_SPEC)
355 #undef USE_TIMER_MGMT
356 #endif
358 #if defined(USE_TIMER_MGMT)
359 #undef USED_TIMERS
360 #else
361 #undef USE_UNIFIED_TARGET
362 #endif
364 #if !defined(USE_RANGEFINDER)
365 #undef USE_RANGEFINDER_HCSR04
366 #undef USE_RANGEFINDER_SRF10
367 #undef USE_RANGEFINDER_HCSR04_I2C
368 #undef USE_RANGEFINDER_VL53L0X
369 #undef USE_RANGEFINDER_UIB
370 #undef USE_RANGEFINDER_TF
371 #endif
373 #ifndef USE_GPS_RESCUE
374 #undef USE_CMS_GPS_RESCUE_MENU
375 #endif
377 // TODO: Remove this once HAL support is fixed for ESCSERIAL
378 #ifdef STM32F7
379 #undef USE_ESCSERIAL
380 #endif
382 #if defined(CONFIG_IN_RAM) || defined(CONFIG_IN_FILE) || defined(CONFIG_IN_EXTERNAL_FLASH) || defined(CONFIG_IN_SDCARD)
383 #ifndef EEPROM_SIZE
384 #define EEPROM_SIZE 4096
385 #endif
386 extern uint8_t eepromData[EEPROM_SIZE];
387 #define __config_start (*eepromData)
388 #define __config_end (*ARRAYEND(eepromData))
389 #else
390 #ifndef CONFIG_IN_FLASH
391 #define CONFIG_IN_FLASH
392 #endif
393 extern uint8_t __config_start; // configured via linker script when building binaries.
394 extern uint8_t __config_end;
395 #endif
397 #if defined(USE_EXST) && !defined(RAMBASED)
398 #define USE_FLASH_BOOT_LOADER
399 #endif
401 #if !defined(USE_RPM_FILTER)
402 #undef USE_DYN_IDLE
403 #endif
405 #ifndef USE_ITERM_RELAX
406 #undef USE_ABSOLUTE_CONTROL
407 #endif
409 #if defined(USE_CUSTOM_DEFAULTS)
410 #define USE_CUSTOM_DEFAULTS_ADDRESS
411 #endif
413 #if defined(USE_RX_SPI) || defined (USE_SERIALRX_SRXL2)
414 #define USE_RX_BIND
415 #endif
417 #ifndef USE_GPS
418 #undef USE_GPS_PLUS_CODES
419 #endif