diff --git a/Multiprotocol/A7105_SPI.ino b/Multiprotocol/A7105_SPI.ino index 2a92464..561f6b6 100644 --- a/Multiprotocol/A7105_SPI.ino +++ b/Multiprotocol/A7105_SPI.ino @@ -168,27 +168,58 @@ void A7105_Strobe(uint8_t address) { // Fine tune A7105 LO base frequency // this is required for some A7105 modules and/or RXs with inaccurate crystal oscillator -// arg: offset in +/-kHz -void A7105_AdjustLOBaseFreq(int16_t offset) +void A7105_AdjustLOBaseFreq(uint8_t cmd) { + static int16_t old_offset=2048; + int16_t offset=1024; + if(cmd==0) + { // Called at init of the A7105 + old_offset=2048; + switch(protocol) + { + case MODE_HUBSAN: + #ifdef FORCE_HUBSAN_TUNING + offset=(int16_t)FORCE_HUBSAN_TUNING; + #endif + break; + case MODE_FLYSKY: + #ifdef FORCE_FLYSKY_TUNING + offset=(int16_t)FORCE_FLYSKY_TUNING; + #endif + break; + case MODE_AFHDS2A: + #ifdef FORCE_AFHDS2A_TUNING + offset=(int16_t)FORCE_AFHDS2A_TUNING; + #endif + break; + } + } + if(offset==1024) // Use channel 15 as an input + offset=map(Channel_data[14],CHANNEL_MIN_100,CHANNEL_MAX_100,-300,300); + + if(old_offset==offset) // offset is the same as before... + return; + old_offset=offset; + // LO base frequency = 32e6*(bip+(bfp/(2^16))) - uint8_t bip; // LO base frequency integer part - uint32_t bfp; // LO base frequency fractional part + uint8_t bip; // LO base frequency integer part + uint16_t bfp; // LO base frequency fractional part + offset++; // as per datasheet, not sure why recommended, but that's a +1kHz drift only ... + offset<<=1; if(offset < 0) { - bip = 0x4a; // 2368 MHz - bfp = 0xffff+((offset<<11)/1000)+1; + bip = 0x4a; // 2368 MHz + bfp = 0xffff + offset; } else { - bip = 0x4b; // 2400 MHz (default) - bfp = (offset<<11)/1000; + bip = 0x4b; // 2400 MHz (default) + bfp = offset; } - if(offset == 0) - bfp = 0x0002; // as per datasheet, not sure why recommended, but that's a +1kHz drift only ... A7105_WriteReg( A7105_11_PLL_III, bip); A7105_WriteReg( A7105_12_PLL_IV, (bfp >> 8) & 0xff); A7105_WriteReg( A7105_13_PLL_V, bfp & 0xff); + //debugln("Channel: %d, offset: %d, bip: %2x, bfp: %4x", Channel_data[14], offset, bip, bfp); } @@ -294,7 +325,7 @@ void A7105_Init(void) A7105_SetTxRxMode(TX_EN); A7105_SetPower(); - A7105_AdjustLOBaseFreq(A7105_FREQ_OFFSET); + A7105_AdjustLOBaseFreq(0); A7105_Strobe(A7105_STANDBY); } diff --git a/Multiprotocol/AFHDS2A_a7105.ino b/Multiprotocol/AFHDS2A_a7105.ino index 773c15a..7d501d7 100644 --- a/Multiprotocol/AFHDS2A_a7105.ino +++ b/Multiprotocol/AFHDS2A_a7105.ino @@ -228,6 +228,9 @@ uint16_t ReadAFHDS2A() static uint16_t packet_counter=0; uint8_t data_rx; uint16_t start; + #ifndef FORCE_AFHDS2A_TUNING + A7105_AdjustLOBaseFreq(1); + #endif switch(phase) { case AFHDS2A_BIND1: diff --git a/Multiprotocol/Common.ino b/Multiprotocol/Common.ino index 1c2be25..97d6c82 100644 --- a/Multiprotocol/Common.ino +++ b/Multiprotocol/Common.ino @@ -27,7 +27,7 @@ void InitFailsafe() { for(uint8_t i=0;i2140 -125%<->+125% + } } RX_DONOTUPDATE_off; #ifdef ORANGE_TX diff --git a/Multiprotocol/TX_Def.h b/Multiprotocol/TX_Def.h index a4ada35..b629fca 100644 --- a/Multiprotocol/TX_Def.h +++ b/Multiprotocol/TX_Def.h @@ -52,6 +52,12 @@ #define SERIAL_MAX_125 2140 // 125% #define SERIAL_MIN_125 860 // 125% +//Channel MIN MAX values +#define CHANNEL_MAX_100 1844 // 100% +#define CHANNEL_MIN_100 204 // 100% +#define CHANNEL_MAX_125 2047 // 125% +#define CHANNEL_MIN_125 0 // 125% + //PPM values used to compare #define PPM_MIN_COMMAND 1250 #define PPM_SWITCH 1550 diff --git a/Multiprotocol/Validate.h b/Multiprotocol/Validate.h index bf1e8c3..87afd5d 100644 --- a/Multiprotocol/Validate.h +++ b/Multiprotocol/Validate.h @@ -86,6 +86,32 @@ #error "The CORONA forced frequency tuning value is outside of the range -127..127." #endif #endif +#ifdef FORCE_FLYSKY_TUNING + #if ( FORCE_FLYSKY_TUNING < -300 ) || ( FORCE_FLYSKY_TUNING > 300 ) + #error "The Flysky forced frequency tuning value is outside of the range -300..300." + #endif +#endif +#ifdef FORCE_HUBSAN_TUNING + #if ( FORCE_HUBSAN_TUNING < -300 ) || ( FORCE_HUBSAN_TUNING > 300 ) + #error "The Hubsan forced frequency tuning value is outside of the range -300..300." + #endif +#endif +#ifdef FORCE_AFHDS2A_TUNING + #if ( FORCE_AFHDS2A_TUNING < -300 ) || ( FORCE_AFHDS2A_TUNING > 300 ) + #error "The AFHDS2A forced frequency tuning value is outside of the range -300..300." + #endif +#endif +#ifndef USE_A7105_CH15_TUNING + #ifndef FORCE_FLYSKY_TUNING + #define FORCE_FLYSKY_TUNING 0 + #endif + #ifndef FORCE_HUBSAN_TUNING + #define FORCE_HUBSAN_TUNING 0 + #endif + #ifndef FORCE_AFHDS2A_TUNING + #define FORCE_AFHDS2A_TUNING 0 + #endif +#endif //Change/Force configuration if OrangeTX #ifdef ORANGE_TX diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 882ec7b..2dfdf5e 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -25,6 +25,16 @@ //To enable this config file remove the // from the line below. It's automatically loaded if the file exists for the AVR platform but not STM32... //#define USE_MY_CONFIG + +/*************************/ +/*** BOOTLOADER USE ***/ +/*************************/ +//Allow flashing multimodule directly with TX(erky9x or opentx modified firmwares) +//Instructions: https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/tree/master/BootLoaders#compiling--uploading-firmware-with-the-flash-from-tx-bootloader +//To enable this feature remove the "//" on the next line. Requires a compatible bootloader or upload method to be selected when you use the Multi 4-in-1 Boards Manager definitions. +//#define CHECK_FOR_BOOTLOADER + + /*******************/ /*** TX SETTINGS ***/ /*******************/ @@ -57,13 +67,6 @@ //The goal is to prevent binding other people's model when powering up the TX, changing model or scanning through protocols. #define WAIT_FOR_BIND -/*************************/ -/*** BOOTLOADER USE ***/ -/*************************/ -//Allow flashing multimodule directly with TX(erky9x or opentx modified firmwares) -//Instructions: https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/tree/master/BootLoaders#compiling--uploading-firmware-with-the-flash-from-tx-bootloader -//To enable this feature remove the "//" on the next line. Requires a compatible bootloader or upload method to be selected when you use the Multi 4-in-1 Boards Manager definitions. -//#define CHECK_FOR_BOOTLOADER /****************/ /*** RF CHIPS ***/ @@ -77,6 +80,36 @@ #define CC2500_INSTALLED #define NRF24L01_INSTALLED +/** OrangeRX TX **/ +//If you compile for the OrangeRX TX module you need to select the correct board type. +//By default the compilation is done for the GREEN board, to switch to a BLUE board uncomment the line below by removing the "//" +//#define ORANGE_TX_BLUE + +/** CC2500 Fine Frequency Tuning **/ +//For optimal performance the CC2500 RF module used by the FrSkyD, FrSkyV, FrSkyX, and SFHSS protocols needs to be tuned for each protocol. +//Initial tuning should be done via the radio menu with a genuine FrSky or Futaba receiver. +//Once a good tuning value is found it can be set here and will override the radio's 'option' setting for all existing and new models which use that protocol. +//For more information: https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/tree/master/docs/Frequency_Tuning.md +//Uncomment the lines below (remove the "//") and set an appropriate value (replace the "0") to enable. Valid range is -127 to +127. +//#define FORCE_FRSKYD_TUNING 0 +//#define FORCE_FRSKYV_TUNING 0 +//#define FORCE_FRSKYX_TUNING 0 +//#define FORCE_SFHSS_TUNING 0 +//#define FORCE_CORONA_TUNING 0 + +/** A7105 Fine Frequency Tuning **/ +//This is required in rare cases where some A7105 modules and/or RXs have an inaccurate crystal oscillator. +//If using Serial mode only (for now), you can use CH15 to find the right tuning value. -100%=-300, 0%=default 0, +100%=+300. +//Uncomment the line below (remove the "//") to enable this feature. +//#define USE_A7105_CH15_TUNING + +//Once a good tuning value is found it can be set here and will override the frequency tuning for a specific protocol. +//Uncomment the lines below (remove the "//") and set an appropriate value (replace the "0") to enable. Valid range is -300 to +300 and default is 0. +//#define FORCE_FLYSKY_TUNING 0 +//#define FORCE_HUBSAN_TUNING 0 +//#define FORCE_AFHDS2A_TUNING 0 + +/** Low Power **/ //Low power is reducing the transmit power of the multi module. This setting is configurable per model in PPM (table below) or Serial mode (radio GUI). //It can be activated when flying indoor or small models since the distance is short or if a model is causing issues when flying closed to the TX. //By default low power is completly disabled on all rf chips to prevent mistakes, but you can enable it by uncommenting the lines below: @@ -85,14 +118,6 @@ //#define CC2500_ENABLE_LOW_POWER //#define NRF24L01_ENABLE_LOW_POWER -//Fine tune of the A7105 LO base frequency -// This is required for some A7105 modules and/or RXs with inaccurate crystal oscillator. -// The offset is in +/-kHz. Default value is 0. -#define A7105_FREQ_OFFSET 0 - -//If you compile for the OrangeRX TX module you need to select the correct board type. -//By default the compilation is done for the GREEN board, to switch to a BLUE board uncomment the line below by removing the "//" -//#define ORANGE_TX_BLUE /*****************/ /*** GLOBAL ID ***/ @@ -110,6 +135,7 @@ //Default is commented, you should uncoment only for test purpose or if you know exactly what you are doing!!! //#define FORCE_CYRF_ID "\x12\x34\x56\x78\x9A\xBC" + /****************************/ /*** PROTOCOLS TO INCLUDE ***/ /****************************/ @@ -182,19 +208,6 @@ // You can force option b. by uncommenting the line below (remove the "//"). //#define FAILSAFE_SERIAL_ONLY -/*******************************/ -/*** CC2500 FREQUENCY TUNING ***/ -/*******************************/ -//For optimal performance the CC2500 RF module used by the FrSkyD, FrSkyV, FrSkyX, and SFHSS protocols needs to be tuned for each protocol. -//Initial tuning should be done via the radio menu with a genuine FrSky or Futaba receiver. -//Once a good tuning value is found it can be set here and will override the radio's 'option' setting for all existing and new models which use that protocol. -//For more information: https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/tree/master/docs/Frequency_Tuning.md -//Uncomment the lines below (remove the "//") and set an appropriate value (replace the "0") to enable. Valid range is -127 to +127. -//#define FORCE_FRSKYD_TUNING 0 -//#define FORCE_FRSKYV_TUNING 0 -//#define FORCE_FRSKYX_TUNING 0 -//#define FORCE_SFHSS_TUNING 0 -//#define FORCE_CORONA_TUNING 0 /**************************/ /*** TELEMETRY SETTINGS ***/ @@ -236,6 +249,7 @@ //!This is a work in progress! //#define SPORT_POLLING + /****************************/ /*** SERIAL MODE SETTINGS ***/ /****************************/ @@ -246,6 +260,7 @@ //If you do not plan to use the Serial mode comment this line using "//" to save Flash space #define ENABLE_SERIAL + /*************************/ /*** PPM MODE SETTINGS ***/ /*************************/ @@ -253,7 +268,7 @@ //If you do not plan to use the PPM mode comment this line using "//" to save Flash space, you don't need to configure anything below in this case #define ENABLE_PPM -/*** TX END POINTS ***/ +/** TX END POINTS **/ //It is important for the module to know the endpoints of your radio. //Below are some standard transmitters already preconfigured. //Uncomment only the one which matches your transmitter. @@ -278,6 +293,7 @@ #define PPM_MIN_125 1000 // 125% #endif +/** Number of PPM Channels **/ // The line below is used to set the minimum number of channels which the module should receive to consider a PPM frame valid. // The default value is 4 to receive at least AETR for flying models but you could also connect the PPM from a car radio which has only 3 channels by changing this number to 3. #define MIN_PPM_CHANNELS 4 @@ -285,6 +301,7 @@ // The default value is 16 to receive all possible channels but you might want to filter some "bad" channels from the PPM frame like the ones above 6 on the Walkera PL0811. #define MAX_PPM_CHANNELS 16 +/** Dial Protocol Selector Settings **/ //The table below indicates which protocol to run when a specific position on the dial has been selected. //All fields and values are explained below. Everything is configurable from here like in the Serial mode. //Example: You can associate multiple times the same protocol to different dial positions to take advantage of the model match (RX_Num)