1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-20 06:45:16 +03:00

Merge pull request #4998 from martinbudden/bfa_vtx_rtc6705_tidy

Remove VTX frequency table and band name duplication from RTC6705
This commit is contained in:
Michael Keller 2018-01-31 19:14:12 +13:00 committed by GitHub
commit b22e84a2e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 100 deletions

View file

@ -41,15 +41,7 @@ static uint8_t cmsx_vtxBand;
static uint8_t cmsx_vtxChannel; static uint8_t cmsx_vtxChannel;
static uint8_t cmsx_vtxPower; static uint8_t cmsx_vtxPower;
static const char * const rtc6705BandNames[] = { static OSD_TAB_t entryVtxBand = {&cmsx_vtxBand, VTX_RTC6705_BAND_COUNT - 1, &vtx58BandNames[1]};
"BOSCAM A",
"BOSCAM B",
"BOSCAM E",
"FATSHARK",
"RACEBAND",
};
static OSD_TAB_t entryVtxBand = {&cmsx_vtxBand, ARRAYLEN(rtc6705BandNames) - 1, &rtc6705BandNames[0]};
static OSD_UINT8_t entryVtxChannel = {&cmsx_vtxChannel, 1, VTX_SETTINGS_CHANNEL_COUNT, 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]}; static OSD_TAB_t entryVtxPower = {&cmsx_vtxPower, VTX_RTC6705_POWER_COUNT - 1 - VTX_RTC6705_MIN_POWER, &rtc6705PowerNames[VTX_RTC6705_MIN_POWER]};

View file

@ -38,47 +38,6 @@
#define RTC6705_SET_HEAD 0x3210 //fosc=8mhz r=400 #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_R 400 //Reference clock
#define RTC6705_SET_FDIV 1024 //128*(fosc/1000000) #define RTC6705_SET_FDIV 1024 //128*(fosc/1000000)
#define RTC6705_SET_NDIV 16 //Remainder divider to get 'A' part of equation #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 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) * Reverse a uint32_t (LSB to MSB)
* This is easier for when generating the frequency to then * This is easier for when generating the frequency to then
@ -192,24 +142,10 @@ static void rtc6705Transfer(uint32_t command)
} }
/** /**
* Set a band and channel * Set a frequency in Mhz
*/
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
* Formula derived from datasheet * 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); frequency = constrain(frequency, VTX_RTC6705_FREQ_MIN, VTX_RTC6705_FREQ_MAX);

View file

@ -43,8 +43,7 @@
#define VTX_RTC6705_BOOT_DELAY 350 // milliseconds #define VTX_RTC6705_BOOT_DELAY 350 // milliseconds
void rtc6705IOInit(void); void rtc6705IOInit(void);
void rtc6705SetBandAndChannel(uint8_t band, uint8_t channel); void rtc6705SetFrequency(uint16_t freq);
void rtc6705SetFreq(uint16_t freq);
void rtc6705SetRFPower(uint8_t rf_power); void rtc6705SetRFPower(uint8_t rf_power);
void rtc6705Disable(void); void rtc6705Disable(void);
void rtc6705Enable(void); void rtc6705Enable(void);

View file

@ -46,15 +46,6 @@
#define DISABLE_RTC6705 IOHi(rtc6705CsnPin) #define DISABLE_RTC6705 IOHi(rtc6705CsnPin)
#define ENABLE_RTC6705 IOLo(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 rtc6705DataPin = IO_NONE;
static IO_t rtc6705CsnPin = IO_NONE; static IO_t rtc6705CsnPin = IO_NONE;
static IO_t rtc6705ClkPin = 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; DISABLE_RTC6705;
} }
void rtc6705SetFreq(uint16_t channel_freq) void rtc6705SetFrequency(uint16_t channel_freq)
{ {
uint32_t freq = (uint32_t)channel_freq * 1000; uint32_t freq = (uint32_t)channel_freq * 1000;
freq /= 40; freq /= 40;
@ -123,14 +114,6 @@ void rtc6705SetFreq(uint16_t channel_freq)
rtc6705_write_register(1, (N << 7) | A); 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) 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)))); rtc6705_write_register(7, (rf_power > 1 ? PA_CONTROL_DEFAULT : (PA_CONTROL_DEFAULT | PD_Q5G_MASK) & (~(PA5G_PW_MASK | PA5G_BS_MASK))));

View file

@ -70,6 +70,8 @@ static vtxDevice_t vtxRTC6705 = {
}; };
#endif #endif
static void vtxRTC6705SetBandAndChannel(uint8_t band, uint8_t channel);
bool vtxRTC6705Init(void) bool vtxRTC6705Init(void)
{ {
vtxCommonRegisterDevice(&vtxRTC6705); vtxCommonRegisterDevice(&vtxRTC6705);
@ -80,7 +82,7 @@ bool vtxRTC6705Init(void)
void vtxRTC6705Configure(void) void vtxRTC6705Configure(void)
{ {
rtc6705SetRFPower(vtxRTC6705.powerIndex); rtc6705SetRFPower(vtxRTC6705.powerIndex);
rtc6705SetBandAndChannel(vtxRTC6705.band - 1, vtxRTC6705.channel - 1); vtxRTC6705SetBandAndChannel(vtxRTC6705.band, vtxRTC6705.channel);
} }
bool vtxRTC6705CanUpdate(void) bool vtxRTC6705CanUpdate(void)
@ -124,16 +126,15 @@ bool vtxRTC6705IsReady(void)
return true; return true;
} }
void vtxRTC6705SetBandAndChannel(uint8_t band, uint8_t channel) static void vtxRTC6705SetBandAndChannel(uint8_t band, uint8_t channel)
{ {
while (!vtxRTC6705CanUpdate()); while (!vtxRTC6705CanUpdate());
if (band && channel) { if (band >= 1 && band <= VTX_SETTINGS_BAND_COUNT && channel >= 1 && channel <= VTX_SETTINGS_CHANNEL_COUNT) {
if (vtxRTC6705.powerIndex > 0) { if (vtxRTC6705.powerIndex > 0) {
rtc6705SetBandAndChannel(band - 1, channel - 1);
vtxRTC6705.band = band; vtxRTC6705.band = band;
vtxRTC6705.channel = channel; vtxRTC6705.channel = channel;
rtc6705SetFrequency(vtx58frequencyTable[vtxRTC6705.band-1][ vtxRTC6705.channel-1]);
} }
} }
} }