Target.h - GaloisInc/betaflight GitHub Wiki

Purpose of this document

This document is meant to describe the purpose of and the content found within target.h. target.h is located in src/main/target/<Target_Flight_Controller>/target.h.

target.h

Each flight controller has its own file to specify which features are enabled/disabled only for it. Sometimes features may need to be disabled for space limitations, or limited computing capacity, or a bug, etc.

This file is located in target/[FLIGHT_CONTROLLER_NAME]/target.h and it's loaded after the target/common_pre.h. So any changes in this file will overwrite the default settings. This file is the place where you must touch to create your custom firmware.

The first thing to do is to #undef all the features that we want to disable from the common_pre.h.

For example, in a NAZE32, if we're using Serial RX, with a FlySky receiver (that uses the iBus protocol) and we don't have an led strip, we will add the following #undef statements to the file:

#undef USE_PPM
#undef USE_PWM
#undef USE_SERIALRX_CRSF       // Team Black Sheep Crossfire protocol
#undef USE_SERIALRX_SBUS       // Frsky and Futaba receivers
#undef USE_SERIALRX_SPEKTRUM   // SRXL, DSM2 and DSMX protocol
#undef USE_SERIALRX_SUMD       // Graupner Hott protocol
#undef USE_SERIALRX_SUMH       // Graupner legacy protocol
#undef USE_SERIALRX_XBUS       // JR

#undef LED_STRIP
#undef TELEMETRY_FRSKY
#undef TELEMETRY_HOTT
#undef TELEMETRY_LTM
#undef TELEMETRY_SMARTPORT
#undef USE_SERVOS

With this change, we have freed some space to add extra features. For example, with this extra space, we can add GPS and telemetry, which also uses iBus protocol. This is done by adding these #define statements that are typically only activated by default for flight controllers with more than 128 megabits:

#define GPS
#define TELEMETRY_IBUS

But be careful, some features are dependent on others. For example, the TELEMETRY_IBUS feature needs the TELEMETRY enabled also.

After modifying target.h, you only need to build your firmware again and you will have your own customized version with all and only the features that you need.

Final considerations

When you activate a feature disabled by the developers, it’s possible to overcharge the processor, or include a bug in your firmware version. So be careful.