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 #ifdef VTX_RTC6705SOFTSPI
28 #include "light_led.h"
30 #include "vtx_soft_spi_rtc6705.h"
32 #define RTC6705_SPICLK_ON IOHi(rtc6705ClkPin)
33 #define RTC6705_SPICLK_OFF IOLo(rtc6705ClkPin)
35 #define RTC6705_SPIDATA_ON IOHi(rtc6705DataPin)
36 #define RTC6705_SPIDATA_OFF IOLo(rtc6705DataPin)
38 #define RTC6705_SPILE_ON IOHi(rtc6705LePin)
39 #define RTC6705_SPILE_OFF IOLo(rtc6705LePin)
41 const uint16_t vtx_freq
[] =
43 5865, 5845, 5825, 5805, 5785, 5765, 5745, 5725, // Boacam A
44 5733, 5752, 5771, 5790, 5809, 5828, 5847, 5866, // Boscam B
45 5705, 5685, 5665, 5645, 5885, 5905, 5925, 5945, // Boscam E
46 5740, 5760, 5780, 5800, 5820, 5840, 5860, 5880, // FatShark
47 5658, 5695, 5732, 5769, 5806, 5843, 5880, 5917, // RaceBand
50 static IO_t rtc6705DataPin
= IO_NONE
;
51 static IO_t rtc6705LePin
= IO_NONE
;
52 static IO_t rtc6705ClkPin
= IO_NONE
;
54 void rtc6705_soft_spi_init(void)
56 rtc6705DataPin
= IOGetByTag(IO_TAG(RTC6705_SPIDATA_PIN
));
57 rtc6705LePin
= IOGetByTag(IO_TAG(RTC6705_SPILE_PIN
));
58 rtc6705ClkPin
= IOGetByTag(IO_TAG(RTC6705_SPICLK_PIN
));
60 IOInit(rtc6705DataPin
, OWNER_SPI_MOSI
, RESOURCE_SOFT_OFFSET
);
61 IOConfigGPIO(rtc6705DataPin
, IOCFG_OUT_PP
);
63 IOInit(rtc6705LePin
, OWNER_SPI_CS
, RESOURCE_SOFT_OFFSET
);
64 IOConfigGPIO(rtc6705LePin
, IOCFG_OUT_PP
);
66 IOInit(rtc6705ClkPin
, OWNER_SPI_SCK
, RESOURCE_SOFT_OFFSET
);
67 IOConfigGPIO(rtc6705ClkPin
, IOCFG_OUT_PP
);
70 static void rtc6705_write_register(uint8_t addr
, uint32_t data
)
95 for (i
=0; i
<20; i
++) {
108 void rtc6705_soft_spi_set_freq(uint16_t channel_freq
)
111 uint32_t freq
= (uint32_t)channel_freq
* 1000;
117 rtc6705_write_register(0, 400);
118 rtc6705_write_register(1, (N
<< 7) | A
);
121 void rtc6705_soft_spi_set_band_and_channel(const uint8_t band
, const uint8_t channel
)
123 // band and channel are 1-based, not 0-based
125 // example for raceband/ch8:
126 // (5 - 1) * 8 + (8 - 1)
129 uint8_t freqIndex
= ((band
- 1) * CHANNELS_PER_BAND
) + (channel
- 1);
131 uint16_t freq
= vtx_freq
[freqIndex
];
132 rtc6705_soft_spi_set_freq(freq
);
135 void rtc6705_soft_spi_set_rf_power(uint8_t reduce_power
)
137 rtc6705_write_register(7, (reduce_power
? (PA_CONTROL_DEFAULT
| PD_Q5G_MASK
) & (~(PA5G_PW_MASK
| PA5G_BS_MASK
)) : PA_CONTROL_DEFAULT
));