UART1 SP inversion fix (BlueJayF4)
[betaflight.git] / src / main / target / BLUEJAYF4 / initialisation.c
blob389f12e64b4ba33e9a227d24cf598454ad43b96a
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdbool.h>
19 #include <stdint.h>
21 #include "platform.h"
22 #include "drivers/bus_i2c.h"
23 #include "drivers/bus_spi.h"
24 #include "hardware_revision.h"
25 #include "config/config_master.h"
26 #include "drivers/io.h"
27 #include "config/feature.h"
29 void targetPreInit(void)
31 switch (hardwareRevision) {
32 case BJF4_REV3:
33 case BJF4_MINI_REV3A:
34 case BJF4_REV4:
35 break;
36 default:
37 return;
40 IO_t inverter = IOGetByTag(IO_TAG(UART1_INVERTER));
41 IOInit(inverter, OWNER_INVERTER, 1);
42 IOConfigGPIO(inverter, IOCFG_OUT_PP);
44 bool high = false;
45 serialPortConfig_t *portConfig = serialFindPortConfiguration(SERIAL_PORT_USART1);
46 if (portConfig) {
47 bool smartportEnabled = (portConfig->functionMask & FUNCTION_TELEMETRY_SMARTPORT);
48 if (smartportEnabled && (telemetryConfig()->telemetry_inversion) && (feature(FEATURE_TELEMETRY))) {
49 high = true;
52 /* reverse this for rev4, as it does not use the XOR gate */
53 if (hardwareRevision == BJF4_REV4) {
54 high = !high;
56 IOWrite(inverter, high);
58 /* ensure the CS pin for the flash is pulled hi so any SD card initialisation does not impact the chip */
59 if (hardwareRevision == BJF4_REV3) {
60 IO_t io = IOGetByTag(IO_TAG(M25P16_CS_PIN));
61 IOConfigGPIO(io, IOCFG_OUT_PP);
62 IOHi(io);