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)
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/>.
26 #include "config/feature.h"
28 #include "drivers/bus_i2c.h"
29 #include "drivers/bus_spi.h"
30 #include "drivers/io.h"
32 #include "config/config.h"
34 #include "io/serial.h"
36 #include "telemetry/telemetry.h"
38 #include "hardware_revision.h"
40 #define UART1_INVERTER PC9
42 void targetPreInit(void)
44 switch (hardwareRevision
) {
53 IO_t inverter
= IOGetByTag(IO_TAG(UART1_INVERTER
));
54 IOInit(inverter
, OWNER_INVERTER
, 1);
55 IOConfigGPIO(inverter
, IOCFG_OUT_PP
);
58 serialPortConfig_t
*portConfig
= serialFindPortConfigurationMutable(SERIAL_PORT_USART1
);
60 bool smartportEnabled
= (portConfig
->functionMask
& FUNCTION_TELEMETRY_SMARTPORT
);
61 if (smartportEnabled
&& (!telemetryConfig()->telemetry_inverted
) && (featureIsEnabled(FEATURE_TELEMETRY
))) {
65 /* reverse this for rev4, as it does not use the XOR gate */
66 if (hardwareRevision
== BJF4_REV4
) {
69 IOWrite(inverter
, high
);
71 /* ensure the CS pin for the flash is pulled hi so any SD card initialisation does not impact the chip */
72 if (hardwareRevision
== BJF4_REV3
) {
73 IO_t flashIo
= IOGetByTag(IO_TAG(FLASH_CS_PIN
));
74 IOConfigGPIO(flashIo
, IOCFG_OUT_PP
);
77 IO_t sdcardIo
= IOGetByTag(IO_TAG(SDCARD_SPI_CS_PIN
));
78 IOConfigGPIO(sdcardIo
, IOCFG_OUT_PP
);