Merge pull request #10558 from iNavFlight/MrD_Correct-comments-on-OSD-symbols
[inav.git] / src / main / target / BLUEJAYF4 / hardware_revision.c
blobc2cf36c248e8305539e511115bf6c2fcf765372c
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>
20 #include <stdlib.h>
22 #include "platform.h"
24 #include "build/build_config.h"
26 #include "drivers/bus.h"
27 #include "drivers/time.h"
28 #include "drivers/io.h"
29 #include "drivers/flash_m25p16.h"
30 #include "hardware_revision.h"
32 uint8_t hardwareRevision = UNKNOWN;
34 void detectHardwareRevision(void)
36 IO_t pin1 = IOGetByTag(IO_TAG(PB12));
37 IOInit(pin1, OWNER_SYSTEM, RESOURCE_INPUT, 1);
38 IOConfigGPIO(pin1, IOCFG_IPU);
40 IO_t pin2 = IOGetByTag(IO_TAG(PB13));
41 IOInit(pin2, OWNER_SYSTEM, RESOURCE_INPUT, 2);
42 IOConfigGPIO(pin2, IOCFG_IPU);
44 // Check hardware revision
45 delayMicroseconds(10); // allow configuration to settle
48 if both PB12 and 13 are tied to GND then it is Rev3A (mini)
49 if only PB12 is tied to GND then it is a Rev3 (full size)
51 if (!IORead(pin1)) {
52 if (!IORead(pin2)) {
53 hardwareRevision = BJF4_REV3A;
55 hardwareRevision = BJF4_REV3;
58 if (hardwareRevision == UNKNOWN) {
59 hardwareRevision = BJF4_REV2;
60 return;
64 enable the UART1 inversion PC9
66 TODO: once param groups are in place, inverter outputs
67 can be moved to be simple IO outputs, and merely set them
68 HI or LO in configuration.
70 IO_t uart1invert = IOGetByTag(IO_TAG(PC9));
71 IOInit(uart1invert, OWNER_INVERTER, RESOURCE_OUTPUT, 2);
72 IOConfigGPIO(uart1invert, IOCFG_AF_PP);
73 IOLo(uart1invert);
76 /* BJF4_REV1 has different connection of memory chip */
77 BUSDEV_REGISTER_SPI_TAG(m25p16_bjf3_rev1, DEVHW_M25P16, M25P16_SPI_BUS, PB3, NONE, 1, DEVFLAGS_NONE, 0);
79 void updateHardwareRevision(void)
81 if (hardwareRevision != BJF4_REV2) {
82 return;
85 /* if flash exists on PB3 (busDevice m25p16_bjf3_rev1) then Rev1 */
86 if (flashInit()) {
87 hardwareRevision = BJF4_REV1;
88 } else {
89 IOInit(IOGetByTag(IO_TAG(PB3)), OWNER_FREE, RESOURCE_NONE, 0);