diff --git a/src/main/drivers/vtx_rtc6705.c b/src/main/drivers/vtx_rtc6705.c index eb1d90ab5a..cac6f592a8 100644 --- a/src/main/drivers/vtx_rtc6705.c +++ b/src/main/drivers/vtx_rtc6705.c @@ -134,8 +134,7 @@ static uint32_t reverse32(uint32_t in) { uint32_t out = 0; - for (uint8_t i = 0 ; i < 32 ; i++) - { + for (uint8_t i = 0 ; i < 32 ; i++) { out |= ((in>>i) & 1)<<(31-i); } @@ -145,11 +144,9 @@ static uint32_t reverse32(uint32_t in) /** * Start chip if available */ - void rtc6705IOInit(void) { #ifdef RTC6705_POWER_PIN - vtxPowerPin = IOGetByTag(IO_TAG(RTC6705_POWER_PIN)); IOInit(vtxPowerPin, OWNER_VTX, 0); @@ -216,12 +213,10 @@ void rtc6705SetFreq(uint16_t frequency) { frequency = constrain(frequency, RTC6705_FREQ_MIN, RTC6705_FREQ_MAX); - uint32_t val_hex = 0; + 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_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) - 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) - - val_hex |= RTC6705_SET_WRITE; + uint32_t val_hex |= RTC6705_SET_WRITE; val_hex |= (val_a << 5); val_hex |= (val_n << 12); @@ -240,7 +235,7 @@ void rtc6705SetRFPower(uint8_t rf_power) uint32_t val_hex = RTC6705_RW_CONTROL_BIT; // write val_hex |= RTC6705_ADDRESS; // address - uint32_t data = rf_power == 0 ? (PA_CONTROL_DEFAULT | PD_Q5G_MASK) & (~(PA5G_PW_MASK | PA5G_BS_MASK)) : PA_CONTROL_DEFAULT; + const uint32_t data = rf_power == 0 ? (PA_CONTROL_DEFAULT | PD_Q5G_MASK) & (~(PA5G_PW_MASK | PA5G_BS_MASK)) : PA_CONTROL_DEFAULT; val_hex |= data << 5; // 4 address bits and 1 rw bit. rtc6705Transfer(val_hex); diff --git a/src/main/drivers/vtx_rtc6705.h b/src/main/drivers/vtx_rtc6705.h index 3baa594573..35af689c88 100644 --- a/src/main/drivers/vtx_rtc6705.h +++ b/src/main/drivers/vtx_rtc6705.h @@ -36,8 +36,8 @@ #define RTC6705_BOOT_DELAY 350 // milliseconds void rtc6705IOInit(void); -void rtc6705SetBandAndChannel(const uint8_t band, const uint8_t channel); -void rtc6705SetFreq(const uint16_t freq); -void rtc6705SetRFPower(const uint8_t rf_power); +void rtc6705SetBandAndChannel(uint8_t band, uint8_t channel); +void rtc6705SetFreq(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 bc66ae2001..78c7e84065 100644 --- a/src/main/drivers/vtx_rtc6705_soft_spi.c +++ b/src/main/drivers/vtx_rtc6705_soft_spi.c @@ -43,8 +43,8 @@ #define RTC6705_SPIDATA_ON IOHi(rtc6705DataPin) #define RTC6705_SPIDATA_OFF IOLo(rtc6705DataPin) -#define RTC6705_SPILE_ON IOHi(rtc6705LePin) -#define RTC6705_SPILE_OFF IOLo(rtc6705LePin) +#define DISABLE_RTC6705 IOHi(rtc6705CsnPin) +#define ENABLE_RTC6705 IOLo(rtc6705CsnPin) const uint16_t vtx_freq[] = { @@ -56,18 +56,18 @@ const uint16_t vtx_freq[] = }; static IO_t rtc6705DataPin = IO_NONE; -static IO_t rtc6705LePin = IO_NONE; +static IO_t rtc6705CsnPin = IO_NONE; static IO_t rtc6705ClkPin = IO_NONE; void rtc6705IOInit(void) { rtc6705DataPin = IOGetByTag(IO_TAG(RTC6705_SPIDATA_PIN)); - rtc6705LePin = IOGetByTag(IO_TAG(RTC6705_SPILE_PIN)); + rtc6705CsnPin = IOGetByTag(IO_TAG(RTC6705_SPILE_PIN)); rtc6705ClkPin = IOGetByTag(IO_TAG(RTC6705_SPICLK_PIN)); - IOInit(rtc6705LePin, OWNER_SPI_CS, RESOURCE_SOFT_OFFSET); - IOConfigGPIO(rtc6705LePin, IOCFG_OUT_PP); - RTC6705_SPILE_ON; + IOInit(rtc6705CsnPin, OWNER_SPI_CS, RESOURCE_SOFT_OFFSET); + IOConfigGPIO(rtc6705CsnPin, IOCFG_OUT_PP); + DISABLE_RTC6705; IOInit(rtc6705DataPin, OWNER_SPI_MOSI, RESOURCE_SOFT_OFFSET); IOConfigGPIO(rtc6705DataPin, IOCFG_OUT_PP); @@ -78,16 +78,15 @@ void rtc6705IOInit(void) static void rtc6705_write_register(uint8_t addr, uint32_t data) { - uint8_t i; - - RTC6705_SPILE_OFF; + ENABLE_RTC6705; delay(1); // send address - for (i=0; i<4; i++) { - if ((addr >> i) & 1) + for (int i = 0; i < 4; i++) { + if ((addr >> i) & 1) { RTC6705_SPIDATA_ON; - else + } else { RTC6705_SPIDATA_OFF; + } RTC6705_SPICLK_ON; delay(1); @@ -95,46 +94,44 @@ static void rtc6705_write_register(uint8_t addr, uint32_t data) delay(1); } // Write bit - RTC6705_SPIDATA_ON; RTC6705_SPICLK_ON; delay(1); RTC6705_SPICLK_OFF; delay(1); - for (i=0; i<20; i++) { - if ((data >> i) & 1) + for (int i = 0; i < 20; i++) { + if ((data >> i) & 1) { RTC6705_SPIDATA_ON; - else + } else { RTC6705_SPIDATA_OFF; + } RTC6705_SPICLK_ON; delay(1); RTC6705_SPICLK_OFF; delay(1); } - RTC6705_SPILE_ON; + DISABLE_RTC6705; } void rtc6705SetFreq(uint16_t channel_freq) { uint32_t freq = (uint32_t)channel_freq * 1000; - uint32_t N, A; - freq /= 40; - N = freq / 64; - A = freq % 64; + const uint32_t N = freq / 64; + const uint32_t A = freq % 64; rtc6705_write_register(0, 400); rtc6705_write_register(1, (N << 7) | A); } -void rtc6705SetBandAndChannel(const uint8_t band, const uint8_t channel) +void rtc6705SetBandAndChannel(uint8_t band, uint8_t channel) { - uint8_t freqIndex = (band * RTC6705_CHANNEL_COUNT) + channel; + const uint8_t freqIndex = (band * RTC6705_CHANNEL_COUNT) + channel; - uint16_t freq = vtx_freq[freqIndex]; + const uint16_t freq = vtx_freq[freqIndex]; rtc6705SetFreq(freq); } -void rtc6705SetRFPower(const uint8_t rf_power) +void rtc6705SetRFPower(uint8_t rf_power) { rtc6705_write_register(7, (rf_power ? PA_CONTROL_DEFAULT : (PA_CONTROL_DEFAULT | PD_Q5G_MASK) & (~(PA5G_PW_MASK | PA5G_BS_MASK)))); } diff --git a/src/main/fc/fc_init.c b/src/main/fc/fc_init.c index ec8e011381..112ceb03e1 100644 --- a/src/main/fc/fc_init.c +++ b/src/main/fc/fc_init.c @@ -268,9 +268,9 @@ void init(void) ensureEEPROMContainsValidData(); readEEPROM(); - /* TODO: Check to be removed when moving to generic targets */ + // !!TODO: Check to be removed when moving to generic targets if (strncasecmp(systemConfig()->boardIdentifier, TARGET_BOARD_IDENTIFIER, sizeof(TARGET_BOARD_IDENTIFIER))) { - resetEEPROM(); + resetEEPROM(); } systemState |= SYSTEM_STATE_CONFIG_LOADED; @@ -418,7 +418,7 @@ void init(void) #ifdef USE_SPI_DEVICE_4 spiInit(SPIDEV_4); #endif -#endif /* USE_SPI */ +#endif // USE_SPI #ifdef USE_I2C i2cHardwareConfigure(); @@ -438,9 +438,9 @@ void init(void) #ifdef USE_I2C_DEVICE_4 i2cInit(I2CDEV_4); #endif -#endif /* USE_I2C */ +#endif // USE_I2C -#endif /* TARGET_BUS_INIT */ +#endif // TARGET_BUS_INIT #ifdef USE_HARDWARE_REVISION_DETECTION updateHardwareRevision(); diff --git a/src/main/io/vtx_rtc6705.c b/src/main/io/vtx_rtc6705.c index 1b387fff4f..315265438b 100644 --- a/src/main/io/vtx_rtc6705.c +++ b/src/main/io/vtx_rtc6705.c @@ -19,8 +19,6 @@ #include #include -#include -#include #include "platform.h" @@ -174,7 +172,6 @@ void vtxRTC6705SetPowerByIndex(uint8_t index) #ifdef RTC6705_POWER_PIN if (index == 0) { // power device off - if (vtxRTC6705.powerIndex > 0) { // on, power it off vtxRTC6705.powerIndex = index; @@ -240,5 +237,4 @@ static vtxVTable_t rtc6705VTable = { }; #endif // VTX_COMMON - #endif // VTX_RTC6705