diff --git a/src/main/cms/cms_menu_vtx_rtc6705.c b/src/main/cms/cms_menu_vtx_rtc6705.c index 2ec3f190a6..6e01a21b3f 100644 --- a/src/main/cms/cms_menu_vtx_rtc6705.c +++ b/src/main/cms/cms_menu_vtx_rtc6705.c @@ -41,15 +41,7 @@ static uint8_t cmsx_vtxBand; static uint8_t cmsx_vtxChannel; static uint8_t cmsx_vtxPower; -static const char * const rtc6705BandNames[] = { - "BOSCAM A", - "BOSCAM B", - "BOSCAM E", - "FATSHARK", - "RACEBAND", -}; - -static OSD_TAB_t entryVtxBand = {&cmsx_vtxBand, ARRAYLEN(rtc6705BandNames) - 1, &rtc6705BandNames[0]}; +static OSD_TAB_t entryVtxBand = {&cmsx_vtxBand, VTX_RTC6705_BAND_COUNT - 1, &vtx58BandNames[1]}; static OSD_UINT8_t entryVtxChannel = {&cmsx_vtxChannel, 1, VTX_SETTINGS_CHANNEL_COUNT, 1}; static OSD_TAB_t entryVtxPower = {&cmsx_vtxPower, VTX_RTC6705_POWER_COUNT - 1 - VTX_RTC6705_MIN_POWER, &rtc6705PowerNames[VTX_RTC6705_MIN_POWER]}; diff --git a/src/main/drivers/vtx_rtc6705.c b/src/main/drivers/vtx_rtc6705.c index 9a4445fa1f..cc179afe90 100644 --- a/src/main/drivers/vtx_rtc6705.c +++ b/src/main/drivers/vtx_rtc6705.c @@ -38,47 +38,6 @@ #define RTC6705_SET_HEAD 0x3210 //fosc=8mhz r=400 -#define RTC6705_SET_A1 0x8F3031 //5865 -#define RTC6705_SET_A2 0x8EB1B1 //5845 -#define RTC6705_SET_A3 0x8E3331 //5825 -#define RTC6705_SET_A4 0x8DB4B1 //5805 -#define RTC6705_SET_A5 0x8D3631 //5785 -#define RTC6705_SET_A6 0x8CB7B1 //5765 -#define RTC6705_SET_A7 0x8C4131 //5745 -#define RTC6705_SET_A8 0x8BC2B1 //5725 -#define RTC6705_SET_B1 0x8BF3B1 //5733 -#define RTC6705_SET_B2 0x8C6711 //5752 -#define RTC6705_SET_B3 0x8CE271 //5771 -#define RTC6705_SET_B4 0x8D55D1 //5790 -#define RTC6705_SET_B5 0x8DD131 //5809 -#define RTC6705_SET_B6 0x8E4491 //5828 -#define RTC6705_SET_B7 0x8EB7F1 //5847 -#define RTC6705_SET_B8 0x8F3351 //5866 -#define RTC6705_SET_E1 0x8B4431 //5705 -#define RTC6705_SET_E2 0x8AC5B1 //5685 -#define RTC6705_SET_E3 0x8A4731 //5665 -#define RTC6705_SET_E4 0x89D0B1 //5645 -#define RTC6705_SET_E5 0x8FA6B1 //5885 -#define RTC6705_SET_E6 0x902531 //5905 -#define RTC6705_SET_E7 0x90A3B1 //5925 -#define RTC6705_SET_E8 0x912231 //5945 -#define RTC6705_SET_F1 0x8C2191 //5740 -#define RTC6705_SET_F2 0x8CA011 //5760 -#define RTC6705_SET_F3 0x8D1691 //5780 -#define RTC6705_SET_F4 0x8D9511 //5800 -#define RTC6705_SET_F5 0x8E1391 //5820 -#define RTC6705_SET_F6 0x8E9211 //5840 -#define RTC6705_SET_F7 0x8F1091 //5860 -#define RTC6705_SET_F8 0x8F8711 //5880 -#define RTC6705_SET_R1 0x8A2151 //5658 -#define RTC6705_SET_R2 0x8B04F1 //5695 -#define RTC6705_SET_R3 0x8BF091 //5732 -#define RTC6705_SET_R4 0x8CD431 //5769 -#define RTC6705_SET_R5 0x8DB7D1 //5806 -#define RTC6705_SET_R6 0x8EA371 //5843 -#define RTC6705_SET_R7 0x8F8711 //5880 -#define RTC6705_SET_R8 0x9072B1 //5917 - #define RTC6705_SET_R 400 //Reference clock #define RTC6705_SET_FDIV 1024 //128*(fosc/1000000) #define RTC6705_SET_NDIV 16 //Remainder divider to get 'A' part of equation @@ -116,15 +75,6 @@ static IO_t vtxCLKPin = IO_NONE; #define DISABLE_VTX_POWER() IOHi(vtxPowerPin) -// Define variables -static const uint32_t channelArray[VTX_RTC6705_BAND_COUNT][VTX_RTC6705_CHANNEL_COUNT] = { - { RTC6705_SET_A1, RTC6705_SET_A2, RTC6705_SET_A3, RTC6705_SET_A4, RTC6705_SET_A5, RTC6705_SET_A6, RTC6705_SET_A7, RTC6705_SET_A8 }, - { RTC6705_SET_B1, RTC6705_SET_B2, RTC6705_SET_B3, RTC6705_SET_B4, RTC6705_SET_B5, RTC6705_SET_B6, RTC6705_SET_B7, RTC6705_SET_B8 }, - { RTC6705_SET_E1, RTC6705_SET_E2, RTC6705_SET_E3, RTC6705_SET_E4, RTC6705_SET_E5, RTC6705_SET_E6, RTC6705_SET_E7, RTC6705_SET_E8 }, - { RTC6705_SET_F1, RTC6705_SET_F2, RTC6705_SET_F3, RTC6705_SET_F4, RTC6705_SET_F5, RTC6705_SET_F6, RTC6705_SET_F7, RTC6705_SET_F8 }, - { RTC6705_SET_R1, RTC6705_SET_R2, RTC6705_SET_R3, RTC6705_SET_R4, RTC6705_SET_R5, RTC6705_SET_R6, RTC6705_SET_R7, RTC6705_SET_R8 }, -}; - /** * Reverse a uint32_t (LSB to MSB) * This is easier for when generating the frequency to then @@ -191,25 +141,11 @@ static void rtc6705Transfer(uint32_t command) delayMicroseconds(2); } -/** - * Set a band and channel - */ -void rtc6705SetBandAndChannel(uint8_t band, uint8_t channel) -{ - band = constrain(band, 0, VTX_RTC6705_BAND_COUNT - 1); - channel = constrain(channel, 0, VTX_RTC6705_CHANNEL_COUNT - 1); - - spiSetDivisor(RTC6705_SPI_INSTANCE, SPI_CLOCK_SLOW); - - rtc6705Transfer(RTC6705_SET_HEAD); - rtc6705Transfer(channelArray[band][channel]); -} - /** - * Set a freq in mhz + * Set a frequency in Mhz * Formula derived from datasheet */ -void rtc6705SetFreq(uint16_t frequency) +void rtc6705SetFrequency(uint16_t frequency) { frequency = constrain(frequency, VTX_RTC6705_FREQ_MIN, VTX_RTC6705_FREQ_MAX); diff --git a/src/main/drivers/vtx_rtc6705.h b/src/main/drivers/vtx_rtc6705.h index 17d23f039f..c71fb733b2 100644 --- a/src/main/drivers/vtx_rtc6705.h +++ b/src/main/drivers/vtx_rtc6705.h @@ -43,8 +43,7 @@ #define VTX_RTC6705_BOOT_DELAY 350 // milliseconds void rtc6705IOInit(void); -void rtc6705SetBandAndChannel(uint8_t band, uint8_t channel); -void rtc6705SetFreq(uint16_t freq); +void rtc6705SetFrequency(uint16_t freq); void rtc6705SetRFPower(uint8_t rf_power); void rtc6705Disable(void); void rtc6705Enable(void); diff --git a/src/main/drivers/vtx_rtc6705_soft_spi.c b/src/main/drivers/vtx_rtc6705_soft_spi.c index 3cd03adad3..99f11d30c7 100644 --- a/src/main/drivers/vtx_rtc6705_soft_spi.c +++ b/src/main/drivers/vtx_rtc6705_soft_spi.c @@ -46,15 +46,6 @@ #define DISABLE_RTC6705 IOHi(rtc6705CsnPin) #define ENABLE_RTC6705 IOLo(rtc6705CsnPin) -const uint16_t vtx_freq[] = -{ - 5865, 5845, 5825, 5805, 5785, 5765, 5745, 5725, // Boacam A - 5733, 5752, 5771, 5790, 5809, 5828, 5847, 5866, // Boscam B - 5705, 5685, 5665, 5645, 5885, 5905, 5925, 5945, // Boscam E - 5740, 5760, 5780, 5800, 5820, 5840, 5860, 5880, // FatShark - 5658, 5695, 5732, 5769, 5806, 5843, 5880, 5917, // RaceBand -}; - static IO_t rtc6705DataPin = IO_NONE; static IO_t rtc6705CsnPin = IO_NONE; static IO_t rtc6705ClkPin = IO_NONE; @@ -113,7 +104,7 @@ static void rtc6705_write_register(uint8_t addr, uint32_t data) DISABLE_RTC6705; } -void rtc6705SetFreq(uint16_t channel_freq) +void rtc6705SetFrequency(uint16_t channel_freq) { uint32_t freq = (uint32_t)channel_freq * 1000; freq /= 40; @@ -123,14 +114,6 @@ void rtc6705SetFreq(uint16_t channel_freq) rtc6705_write_register(1, (N << 7) | A); } -void rtc6705SetBandAndChannel(uint8_t band, uint8_t channel) -{ - const uint8_t freqIndex = (band * VTX_RTC6705_CHANNEL_COUNT) + channel; - - const uint16_t freq = vtx_freq[freqIndex]; - rtc6705SetFreq(freq); -} - void rtc6705SetRFPower(uint8_t rf_power) { rtc6705_write_register(7, (rf_power > 1 ? PA_CONTROL_DEFAULT : (PA_CONTROL_DEFAULT | PD_Q5G_MASK) & (~(PA5G_PW_MASK | PA5G_BS_MASK)))); diff --git a/src/main/io/vtx_rtc6705.c b/src/main/io/vtx_rtc6705.c index 289d163d0d..6dfcbe9f7f 100644 --- a/src/main/io/vtx_rtc6705.c +++ b/src/main/io/vtx_rtc6705.c @@ -70,6 +70,8 @@ static vtxDevice_t vtxRTC6705 = { }; #endif +static void vtxRTC6705SetBandAndChannel(uint8_t band, uint8_t channel); + bool vtxRTC6705Init(void) { vtxCommonRegisterDevice(&vtxRTC6705); @@ -80,7 +82,7 @@ bool vtxRTC6705Init(void) void vtxRTC6705Configure(void) { rtc6705SetRFPower(vtxRTC6705.powerIndex); - rtc6705SetBandAndChannel(vtxRTC6705.band - 1, vtxRTC6705.channel - 1); + vtxRTC6705SetBandAndChannel(vtxRTC6705.band, vtxRTC6705.channel); } bool vtxRTC6705CanUpdate(void) @@ -124,16 +126,15 @@ bool vtxRTC6705IsReady(void) return true; } -void vtxRTC6705SetBandAndChannel(uint8_t band, uint8_t channel) +static void vtxRTC6705SetBandAndChannel(uint8_t band, uint8_t channel) { while (!vtxRTC6705CanUpdate()); - if (band && channel) { + if (band >= 1 && band <= VTX_SETTINGS_BAND_COUNT && channel >= 1 && channel <= VTX_SETTINGS_CHANNEL_COUNT) { if (vtxRTC6705.powerIndex > 0) { - rtc6705SetBandAndChannel(band - 1, channel - 1); - vtxRTC6705.band = band; vtxRTC6705.channel = channel; + rtc6705SetFrequency(vtx58frequencyTable[vtxRTC6705.band-1][ vtxRTC6705.channel-1]); } } }