/** * Set a band and channel */ void rtc6705SetChannel(uint8_t band, uint8_t channel) { band = constrain(band, RTC6705_BAND_MIN, RTC6705_BAND_MAX); channel = constrain(channel, RTC6705_CHANNEL_MIN, RTC6705_CHANNEL_MAX); rtc6705Transfer(RTC6705_SET_HEAD); rtc6705Transfer(channelArray[band-1][channel-1]); }
/** * 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 * Formula derived from datasheet */ void rtc6705SetFreq(uint16_t freq) { freq = constrain(freq, RTC6705_FREQ_MIN, RTC6705_FREQ_MAX); uint32_t val_hex = 0; uint32_t val_a = ((((uint64_t)freq*(uint64_t)RTC6705_SET_DIVMULT*(uint64_t)RTC6705_SET_R)/(uint64_t)RTC6705_SET_DIVMULT) % RTC6705_SET_FDIV) / RTC6705_SET_NDIV; //Casts required to make sure correct math (large numbers) uint32_t val_n = (((uint64_t)freq*(uint64_t)RTC6705_SET_DIVMULT*(uint64_t)RTC6705_SET_R)/(uint64_t)RTC6705_SET_DIVMULT) / RTC6705_SET_FDIV; //Casts required to make sure correct math (large numbers) val_hex |= RTC6705_SET_WRITE; val_hex |= (val_a << 5); val_hex |= (val_n << 12); rtc6705Transfer(RTC6705_SET_HEAD); rtc6705Transfer(val_hex); }
/** * Set a freq in mhz * Formula derived from datasheet */ void rtc6705SetFreq(uint16_t frequency) { frequency = constrain(frequency, VTX_RTC6705_FREQ_MIN, VTX_RTC6705_FREQ_MAX); const uint32_t val_a = ((((uint64_t)frequency*(uint64_t)RTC6705_SET_DIVMULT*(uint64_t)RTC6705_SET_R)/(uint64_t)RTC6705_SET_DIVMULT) % RTC6705_SET_FDIV) / RTC6705_SET_NDIV; //Casts required to make sure correct math (large numbers) const uint32_t val_n = (((uint64_t)frequency*(uint64_t)RTC6705_SET_DIVMULT*(uint64_t)RTC6705_SET_R)/(uint64_t)RTC6705_SET_DIVMULT) / RTC6705_SET_FDIV; //Casts required to make sure correct math (large numbers) uint32_t val_hex = RTC6705_SET_WRITE; val_hex |= (val_a << 5); val_hex |= (val_n << 12); spiSetDivisor(RTC6705_SPI_INSTANCE, SPI_CLOCK_SLOW); rtc6705Transfer(RTC6705_SET_HEAD); delayMicroseconds(10); rtc6705Transfer(val_hex); }
void rtc6705SetRFPower(uint8_t rf_power) { rf_power = constrain(rf_power, VTX_RTC6705_MIN_POWER, VTX_RTC6705_POWER_COUNT - 1); spiSetDivisor(RTC6705_SPI_INSTANCE, SPI_CLOCK_SLOW); uint32_t val_hex = RTC6705_RW_CONTROL_BIT; // write val_hex |= RTC6705_ADDRESS; // address const uint32_t data = rf_power > 1 ? PA_CONTROL_DEFAULT : (PA_CONTROL_DEFAULT | PD_Q5G_MASK) & (~(PA5G_PW_MASK | PA5G_BS_MASK)); val_hex |= data << 5; // 4 address bits and 1 rw bit. rtc6705Transfer(val_hex); }