From 08e40af088fa5536c4bef69e6e74847e3b4ac50d Mon Sep 17 00:00:00 2001 From: Hydra Date: Mon, 24 Oct 2016 21:38:21 +0200 Subject: [PATCH] SPRACINGF3NEO - VTX Support. Note: Likely there will be a clash with DMA driven OSD and the VTX. There is no support in the code to disable OSD updates prior to changing VTX channel. --- src/main/cms/cms_menu_osd.c | 2 +- src/main/drivers/resource.c | 1 + src/main/drivers/resource.h | 1 + src/main/drivers/vtx_rtc6705.c | 16 ++++++++++++++++ src/main/io/osd.c | 4 +++- src/main/io/osd.h | 2 ++ src/main/io/vtx.c | 1 + src/main/target/SPRACINGF3NEO/target.h | 7 +++++++ src/main/target/SPRACINGF3NEO/target.mk | 4 +++- 9 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/main/cms/cms_menu_osd.c b/src/main/cms/cms_menu_osd.c index 8437fc0ada..c7faeb073e 100644 --- a/src/main/cms/cms_menu_osd.c +++ b/src/main/cms/cms_menu_osd.c @@ -71,7 +71,7 @@ OSD_Entry menuOsdActiveElemsEntries[] = {"NAME", OME_VISIBLE, NULL, &osdProfile()->item_pos[OSD_CRAFT_NAME], 0}, {"THROTTLE", OME_VISIBLE, NULL, &osdProfile()->item_pos[OSD_THROTTLE_POS], 0}, #ifdef VTX - {"VTX CHAN", OME_VISIBLE, NULL, &osdProfile()->item_pos[OSD_VTX_CHANNEL]}, + {"VTX CHAN", OME_VISIBLE, NULL, &osdProfile()->item_pos[OSD_VTX_CHANNEL], 0}, #endif // VTX {"CURRENT (A)", OME_VISIBLE, NULL, &osdProfile()->item_pos[OSD_CURRENT_DRAW], 0}, {"USED MAH", OME_VISIBLE, NULL, &osdProfile()->item_pos[OSD_MAH_DRAWN], 0}, diff --git a/src/main/drivers/resource.c b/src/main/drivers/resource.c index 775907e6e1..aa7b87a49a 100644 --- a/src/main/drivers/resource.c +++ b/src/main/drivers/resource.c @@ -59,5 +59,6 @@ const char * const ownerNames[OWNER_TOTAL_COUNT] = { "INVERTER", "LED_STRIP", "TRANSPONDER" + "VTX", }; diff --git a/src/main/drivers/resource.h b/src/main/drivers/resource.h index a8dd0f0120..f5ba5f6a59 100644 --- a/src/main/drivers/resource.h +++ b/src/main/drivers/resource.h @@ -59,6 +59,7 @@ typedef enum { OWNER_INVERTER, OWNER_LED_STRIP, OWNER_TRANSPONDER, + OWNER_VTX, OWNER_TOTAL_COUNT } resourceOwner_e; diff --git a/src/main/drivers/vtx_rtc6705.c b/src/main/drivers/vtx_rtc6705.c index 08ec758e8d..38915a8750 100644 --- a/src/main/drivers/vtx_rtc6705.c +++ b/src/main/drivers/vtx_rtc6705.c @@ -32,6 +32,7 @@ #include "common/maths.h" #include "vtx_rtc6705.h" +#include "io.h" #include "bus_spi.h" #include "system.h" @@ -86,6 +87,12 @@ #define DISABLE_RTC6705 GPIO_SetBits(RTC6705_CS_GPIO, RTC6705_CS_PIN) #define ENABLE_RTC6705 GPIO_ResetBits(RTC6705_CS_GPIO, RTC6705_CS_PIN) +static IO_t vtxPowerPin = IO_NONE; + +#define ENABLE_VTX_POWER IOLo(vtxPowerPin) +#define DISABLE_VTX_POWER IOHi(vtxPowerPin) + + // Define variables static const uint32_t channelArray[RTC6705_BAND_MAX][RTC6705_CHANNEL_MAX] = { { RTC6705_SET_A1, RTC6705_SET_A2, RTC6705_SET_A3, RTC6705_SET_A4, RTC6705_SET_A5, RTC6705_SET_A6, RTC6705_SET_A7, RTC6705_SET_A8 }, @@ -129,8 +136,17 @@ static uint32_t reverse32(uint32_t in) /** * Start chip if available */ + bool rtc6705Init(void) { +#ifdef RTC6705_POWER_PIN + vtxPowerPin = IOGetByTag(IO_TAG(RTC6705_POWER_PIN)); + IOInit(vtxPowerPin, OWNER_VTX, 0); + IOConfigGPIO(vtxPowerPin, IOCFG_OUT_PP); + + ENABLE_VTX_POWER; +#endif + DISABLE_RTC6705; spiSetDivisor(RTC6705_SPI_INSTANCE, SPI_CLOCK_SLOW); return rtc6705IsReady(); diff --git a/src/main/io/osd.c b/src/main/io/osd.c index ca21509f26..2112a41fd6 100755 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -48,6 +48,8 @@ #include "io/flashfs.h" #include "io/osd.h" +#include "io/vtx.h" + #include "fc/config.h" #include "fc/rc_controls.h" #include "fc/runtime_config.h" @@ -251,7 +253,7 @@ static void osdDrawSingleElement(uint8_t item) break; } -#ifdef VTX +#ifdef USE_RTC6705 case OSD_VTX_CHANNEL: { sprintf(buff, "CH:%d", current_vtx_channel % CHANNELS_PER_BAND + 1); diff --git a/src/main/io/osd.h b/src/main/io/osd.h index c3642218ad..881dba9901 100755 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -17,6 +17,8 @@ #pragma once +#include "common/time.h" + #define VISIBLE_FLAG 0x0800 #define BLINK_FLAG 0x0400 #define VISIBLE(x) (x & VISIBLE_FLAG) diff --git a/src/main/io/vtx.c b/src/main/io/vtx.c index 0b4e727917..8db4c4279b 100644 --- a/src/main/io/vtx.c +++ b/src/main/io/vtx.c @@ -23,6 +23,7 @@ // Own interfaces #include "io/vtx.h" +#include "io/osd.h" //External dependencies #include "config/config_master.h" diff --git a/src/main/target/SPRACINGF3NEO/target.h b/src/main/target/SPRACINGF3NEO/target.h index 3f8da289ef..4f795c53d5 100755 --- a/src/main/target/SPRACINGF3NEO/target.h +++ b/src/main/target/SPRACINGF3NEO/target.h @@ -95,6 +95,13 @@ #define SPI3_MISO_PIN PB4 #define SPI3_MOSI_PIN PB5 +#define VTX +#define RTC6705_CS_GPIO GPIOF +#define RTC6705_CS_PIN GPIO_Pin_4 +#define RTC6705_SPI_INSTANCE SPI3 + +#define RTC6705_POWER_PIN PC3 + #define USE_MAX7456 #define MAX7456_SPI_INSTANCE SPI3 #define MAX7456_SPI_CS_PIN PA15 diff --git a/src/main/target/SPRACINGF3NEO/target.mk b/src/main/target/SPRACINGF3NEO/target.mk index 59fe2523da..c596c191c3 100755 --- a/src/main/target/SPRACINGF3NEO/target.mk +++ b/src/main/target/SPRACINGF3NEO/target.mk @@ -15,5 +15,7 @@ TARGET_SRC = \ drivers/transponder_ir.c \ drivers/transponder_ir_stm32f30x.c \ drivers/max7456.c \ + drivers/vtx_rtc6705.c \ + io/osd.c \ io/transponder_ir.c \ - io/osd.c + io/vtx.c