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/>.
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"
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)
54 hardwareRevision
= BJF4_REV3
;
56 IO_t pin2
= IOGetByTag(IO_TAG(PB13
));
57 IOInit(pin2
, OWNER_SYSTEM
, 2);
58 IOConfigGPIO(pin2
, IOCFG_IPU
);
61 hardwareRevision
= BJF4_REV4
;
64 IO_t pin2
= IOGetByTag(IO_TAG(PB13
));
65 IOInit(pin2
, OWNER_SYSTEM
, 2);
66 IOConfigGPIO(pin2
, IOCFG_OUT_PP
);
71 hardwareRevision
= BJF4_MINI_REV3A
;
75 if (hardwareRevision
== UNKNOWN
) {
76 hardwareRevision
= BJF4_REV2
;
81 void updateHardwareRevision(void)
83 if (hardwareRevision
!= BJF4_REV2
) {
88 if flash exists on PB3 then Rev1
90 flashConfig_t flashConfig
= { .csTag
= IO_TAG(PB3
) };
91 if (flashInit(&flashConfig
)) {
92 hardwareRevision
= BJF4_REV1
;
94 IOInit(IOGetByTag(IO_TAG(PB3
)), OWNER_FREE
, 0);