Moved configuration validation into 'config.c'.
[betaflight.git] / src / main / target / BLUEJAYF4 / initialisation.c
blob6c49ab5abc2d63b597f1c64d832e46fa82815bc1
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 #include <stdbool.h>
22 #include <stdint.h>
24 #include "platform.h"
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) {
45 case BJF4_REV3:
46 case BJF4_MINI_REV3A:
47 case BJF4_REV4:
48 break;
49 default:
50 return;
53 IO_t inverter = IOGetByTag(IO_TAG(UART1_INVERTER));
54 IOInit(inverter, OWNER_INVERTER, 1);
55 IOConfigGPIO(inverter, IOCFG_OUT_PP);
57 bool high = false;
58 serialPortConfig_t *portConfig = serialFindPortConfigurationMutable(SERIAL_PORT_USART1);
59 if (portConfig) {
60 bool smartportEnabled = (portConfig->functionMask & FUNCTION_TELEMETRY_SMARTPORT);
61 if (smartportEnabled && (!telemetryConfig()->telemetry_inverted) && (featureIsEnabled(FEATURE_TELEMETRY))) {
62 high = true;
65 /* reverse this for rev4, as it does not use the XOR gate */
66 if (hardwareRevision == BJF4_REV4) {
67 high = !high;
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);
75 IOHi(flashIo);
77 IO_t sdcardIo = IOGetByTag(IO_TAG(SDCARD_SPI_CS_PIN));
78 IOConfigGPIO(sdcardIo, IOCFG_OUT_PP);
79 IOHi(sdcardIo);