Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / src / main / target / BLUEJAYF4 / hardware_revision.c
blob8c9acdb32a7cfe5fbaee09d82c76579942406dcc
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>
23 #include <stdlib.h>
25 #include "platform.h"
27 #include "build/build_config.h"
29 #include "drivers/bus_spi.h"
30 #include "drivers/flash.h"
31 #include "drivers/io.h"
32 #include "drivers/time.h"
34 #include "pg/flash.h"
36 #include "hardware_revision.h"
38 uint8_t hardwareRevision = UNKNOWN;
40 void detectHardwareRevision(void)
42 IO_t pin1 = IOGetByTag(IO_TAG(PB12));
43 IOInit(pin1, OWNER_SYSTEM, 1);
44 IOConfigGPIO(pin1, IOCFG_IPU);
46 // Check hardware revision
47 delayMicroseconds(10); // allow configuration to settle
50 if both PB12 and 13 are tied to GND then it is Rev3A (mini)
51 if only PB12 is tied to GND then it is a Rev3 (full size)
53 if (!IORead(pin1)) {
54 hardwareRevision = BJF4_REV3;
56 IO_t pin2 = IOGetByTag(IO_TAG(PB13));
57 IOInit(pin2, OWNER_SYSTEM, 2);
58 IOConfigGPIO(pin2, IOCFG_IPU);
60 if (!IORead(pin2)) {
61 hardwareRevision = BJF4_REV4;
63 } else {
64 IO_t pin2 = IOGetByTag(IO_TAG(PB13));
65 IOInit(pin2, OWNER_SYSTEM, 2);
66 IOConfigGPIO(pin2, IOCFG_OUT_PP);
68 IOWrite(pin2, false);
70 if (!IORead(pin1)) {
71 hardwareRevision = BJF4_MINI_REV3A;
75 if (hardwareRevision == UNKNOWN) {
76 hardwareRevision = BJF4_REV2;
77 return;
81 void updateHardwareRevision(void)
83 if (hardwareRevision != BJF4_REV2) {
84 return;
88 if flash exists on PB3 then Rev1
90 flashConfig_t flashConfig = { .csTag = IO_TAG(PB3) };
91 if (flashInit(&flashConfig)) {
92 hardwareRevision = BJF4_REV1;
93 } else {
94 IOInit(IOGetByTag(IO_TAG(PB3)), OWNER_FREE, 0);