From 6f966dc0669545f62ca12a22078b41b7126b9ede Mon Sep 17 00:00:00 2001 From: Michael Jakob Date: Sat, 22 Jul 2017 01:38:23 +0200 Subject: [PATCH] Support for FORTINIF4 OSD revision --- src/main/target/FF_FORTINIF4/config.c | 10 ++++ .../target/FF_FORTINIF4/hardware_revision.c | 53 +++++++++++++++++++ .../target/FF_FORTINIF4/hardware_revision.h | 28 ++++++++++ src/main/target/FF_FORTINIF4/target.h | 11 ++++ src/main/target/FF_FORTINIF4/target.mk | 4 +- 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/main/target/FF_FORTINIF4/hardware_revision.c create mode 100644 src/main/target/FF_FORTINIF4/hardware_revision.h diff --git a/src/main/target/FF_FORTINIF4/config.c b/src/main/target/FF_FORTINIF4/config.c index 8cbd093706..d427645ad5 100644 --- a/src/main/target/FF_FORTINIF4/config.c +++ b/src/main/target/FF_FORTINIF4/config.c @@ -21,10 +21,20 @@ #include #ifdef TARGET_CONFIG +#include "fc/config.h" + +#include "config/feature.h" + #include "telemetry/telemetry.h" +#include "hardware_revision.h" + void targetConfiguration(void) { + if (hardwareRevision == FORTINIF4_REV_2) { + featureSet(FEATURE_OSD); + } + telemetryConfigMutable()->halfDuplex = false; } #endif diff --git a/src/main/target/FF_FORTINIF4/hardware_revision.c b/src/main/target/FF_FORTINIF4/hardware_revision.c new file mode 100644 index 0000000000..5a583991af --- /dev/null +++ b/src/main/target/FF_FORTINIF4/hardware_revision.c @@ -0,0 +1,53 @@ +/* + * This file is part of Cleanflight. + * + * Cleanflight is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cleanflight is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cleanflight. If not, see . + */ + +#include +#include +#include + +#include "platform.h" + +#include "build/build_config.h" + +#include "drivers/io.h" +#include "drivers/time.h" + +#include "hardware_revision.h" + +uint8_t hardwareRevision = FORTINIF4_UNKNOWN; + +static IO_t HWDetectPin = IO_NONE; + +void detectHardwareRevision(void) +{ + HWDetectPin = IOGetByTag(IO_TAG(HW_PIN)); + IOInit(HWDetectPin, OWNER_SYSTEM, 0); + IOConfigGPIO(HWDetectPin, IOCFG_IPU); + + delayMicroseconds(10); // allow configuration to settle + + // Check hardware revision + if (IORead(HWDetectPin)) { + hardwareRevision = FORTINIF4_REV_1; + } else { + hardwareRevision = FORTINIF4_REV_2; + } +} + +void updateHardwareRevision(void) +{ +} diff --git a/src/main/target/FF_FORTINIF4/hardware_revision.h b/src/main/target/FF_FORTINIF4/hardware_revision.h new file mode 100644 index 0000000000..7362d32feb --- /dev/null +++ b/src/main/target/FF_FORTINIF4/hardware_revision.h @@ -0,0 +1,28 @@ +/* + * This file is part of Cleanflight. + * + * Cleanflight is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cleanflight is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cleanflight. If not, see . + */ +#pragma once + +typedef enum ftf4HardwareRevision_t { + FORTINIF4_UNKNOWN = 0, + FORTINIF4_REV_1, // SPI Flash + FORTINIF4_REV_2 // OSD +} ftf4HardwareRevision_e; + +extern uint8_t hardwareRevision; + +void updateHardwareRevision(void); +void detectHardwareRevision(void); diff --git a/src/main/target/FF_FORTINIF4/target.h b/src/main/target/FF_FORTINIF4/target.h index 3e8b81bbab..a8b10fb262 100644 --- a/src/main/target/FF_FORTINIF4/target.h +++ b/src/main/target/FF_FORTINIF4/target.h @@ -19,6 +19,8 @@ #define TARGET_BOARD_IDENTIFIER "FORT" #define USBD_PRODUCT_STRING "FortiniF4" #define TARGET_CONFIG +#define USE_HARDWARE_REVISION_DETECTION +#define HW_PIN PC14 /*--------------LED----------------*/ #define LED0_PIN PB5 #define LED1_PIN PB6 @@ -80,6 +82,15 @@ #define USE_FLASH_M25P16 /*---------------------------------*/ +/*-------------OSD-----------------*/ +#define OSD +#define USE_MAX7456 +#define MAX7456_SPI_INSTANCE SPI3 +#define MAX7456_SPI_CS_PIN PB3 +#define MAX7456_SPI_CLK (SPI_CLOCK_STANDARD*2) +#define MAX7456_RESTORE_CLK (SPI_CLOCK_FAST) +/*---------------------------------*/ + /*-----------USB-UARTs-------------*/ #define USE_VCP //#define VBUS_SENSING_PIN PA8 diff --git a/src/main/target/FF_FORTINIF4/target.mk b/src/main/target/FF_FORTINIF4/target.mk index 2ff6a102fa..13717c509b 100644 --- a/src/main/target/FF_FORTINIF4/target.mk +++ b/src/main/target/FF_FORTINIF4/target.mk @@ -5,4 +5,6 @@ TARGET_SRC = \ drivers/accgyro/accgyro_spi_mpu6000.c \ drivers/accgyro/accgyro_mpu6500.c \ drivers/accgyro/accgyro_spi_mpu6500.c \ - drivers/accgyro/accgyro_spi_icm20689.c + drivers/accgyro/accgyro_spi_icm20689.c \ + drivers/max7456.c + \ No newline at end of file