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/>.
23 #if defined(VTX_RTC6705) && defined(VTX_RTC6705SOFTSPI)
28 #include "light_led.h"
30 #include "vtx_rtc6705.h"
32 #define DP_5G_MASK 0x7000
33 #define PA5G_BS_MASK 0x0E00
34 #define PA5G_PW_MASK 0x0180
35 #define PD_Q5G_MASK 0x0040
36 #define QI_5G_MASK 0x0038
37 #define PA_BS_MASK 0x0007
39 #define PA_CONTROL_DEFAULT 0x4FBD
41 #define RTC6705_SPICLK_ON IOHi(rtc6705ClkPin)
42 #define RTC6705_SPICLK_OFF IOLo(rtc6705ClkPin)
44 #define RTC6705_SPIDATA_ON IOHi(rtc6705DataPin)
45 #define RTC6705_SPIDATA_OFF IOLo(rtc6705DataPin)
47 #define RTC6705_SPILE_ON IOHi(rtc6705LePin)
48 #define RTC6705_SPILE_OFF IOLo(rtc6705LePin)
50 const uint16_t vtx_freq
[] =
52 5865, 5845, 5825, 5805, 5785, 5765, 5745, 5725, // Boacam A
53 5733, 5752, 5771, 5790, 5809, 5828, 5847, 5866, // Boscam B
54 5705, 5685, 5665, 5645, 5885, 5905, 5925, 5945, // Boscam E
55 5740, 5760, 5780, 5800, 5820, 5840, 5860, 5880, // FatShark
56 5658, 5695, 5732, 5769, 5806, 5843, 5880, 5917, // RaceBand
59 static IO_t rtc6705DataPin
= IO_NONE
;
60 static IO_t rtc6705LePin
= IO_NONE
;
61 static IO_t rtc6705ClkPin
= IO_NONE
;
63 void rtc6705IOInit(void)
65 rtc6705DataPin
= IOGetByTag(IO_TAG(RTC6705_SPIDATA_PIN
));
66 rtc6705LePin
= IOGetByTag(IO_TAG(RTC6705_SPILE_PIN
));
67 rtc6705ClkPin
= IOGetByTag(IO_TAG(RTC6705_SPICLK_PIN
));
69 IOInit(rtc6705DataPin
, OWNER_SPI_MOSI
, RESOURCE_SOFT_OFFSET
);
70 IOConfigGPIO(rtc6705DataPin
, IOCFG_OUT_PP
);
72 IOInit(rtc6705LePin
, OWNER_SPI_CS
, RESOURCE_SOFT_OFFSET
);
73 IOConfigGPIO(rtc6705LePin
, IOCFG_OUT_PP
);
75 IOInit(rtc6705ClkPin
, OWNER_SPI_SCK
, RESOURCE_SOFT_OFFSET
);
76 IOConfigGPIO(rtc6705ClkPin
, IOCFG_OUT_PP
);
79 static void rtc6705_write_register(uint8_t addr
, uint32_t data
)
104 for (i
=0; i
<20; i
++) {
117 void rtc6705SetFreq(uint16_t channel_freq
)
119 uint32_t freq
= (uint32_t)channel_freq
* 1000;
125 rtc6705_write_register(0, 400);
126 rtc6705_write_register(1, (N
<< 7) | A
);
129 void rtc6705SetChannel(const uint8_t band
, const uint8_t channel
)
131 // band and channel are 1-based, not 0-based
133 // example for raceband/ch8:
134 // (5 - 1) * 8 + (8 - 1)
137 uint8_t freqIndex
= ((band
- 1) * RTC6705_BAND_COUNT
) + (channel
- 1);
139 uint16_t freq
= vtx_freq
[freqIndex
];
140 rtc6705SetFreq(freq
);
143 void rtc6705SetRFPower(const uint8_t rf_power
)
145 rtc6705_write_register(7, (rf_power
? PA_CONTROL_DEFAULT
: (PA_CONTROL_DEFAULT
| PD_Q5G_MASK
) & (~(PA5G_PW_MASK
| PA5G_BS_MASK
))));
148 void rtc6705Disable(void)
152 void rtc6705Enable(void)