This commit is contained in:
tipouic 2016-11-19 22:54:18 +01:00
parent f12ff1c58d
commit a08370ce97
8 changed files with 173 additions and 167 deletions

View File

@ -20,14 +20,13 @@
#define EVEN_ODD 0x00 #define EVEN_ODD 0x00
//#define EVEN_ODD 0x01 //#define EVEN_ODD 0x01
static uint8_t PROGMEM A7105_regs[] = { const uint8_t PROGMEM JOYSWAY_A7105_regs[] = {
0x00, 0x62, 0xFF, 0x0f, 0x00, 0xFF , 0xFF , 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0xf5, 0x00, 0x15, 0x00, 0x62, 0xFF, 0x0f, 0x00, 0xFF , 0xFF , 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0xf5, 0x00, 0x15,
0x9e, 0x4b, 0x00, 0x03, 0x56, 0x2b, 0x12, 0x4a, 0x02, 0x80, 0x80, 0x00, 0x0e, 0x91, 0x03, 0x0f, 0x9e, 0x4b, 0x00, 0x03, 0x56, 0x2b, 0x12, 0x4a, 0x02, 0x80, 0x80, 0x00, 0x0e, 0x91, 0x03, 0x0f,
0x16, 0x2a, 0x00, 0xFF, 0xFF, 0xFF, 0x3a, 0x06, 0x1f, 0x47, 0x80, 0x01, 0x05, 0x45, 0x18, 0x00, 0x16, 0x2a, 0x00, 0xFF, 0xFF, 0xFF, 0x3a, 0x06, 0x1f, 0x47, 0x80, 0x01, 0x05, 0x45, 0x18, 0x00,
0x01, 0x0f, 0x00 0x01, 0x0f, 0x00
}; };
static void joysway_build_packet() static void joysway_build_packet() {
{
int i; int i;
//-100% =~ 0x03e8 //-100% =~ 0x03e8
//+100% =~ 0x07ca //+100% =~ 0x07ca
@ -55,8 +54,7 @@ static void joysway_build_packet()
packet[15] = value; packet[15] = value;
} }
static uint16_t joysway_cb() static uint16_t joysway_cb() {
{
if (phase == 254) { if (phase == 254) {
phase = 0; phase = 0;
A7105_WriteID(0x5475c52a); A7105_WriteID(0x5475c52a);
@ -90,10 +88,10 @@ static uint16_t JOYSWAY_Setup() {
//u8 vco_calibration1; //u8 vco_calibration1;
counter = 0; counter = 0;
next_ch = 0x30; // next_ch = 0x30;
for (i = 0; i < 0x33; i++) { for (i = 0; i < 0x33; i++) {
uint8_t val=pgm_read_byte_near(&A7105_Regs[i]); uint8_t val=pgm_read_byte_near(&JOYSWAY_A7105_regs[i]);
if( val != 0xFF) if( val != 0xFF)
A7105_WriteReg(i, val); A7105_WriteReg(i, val);
} }

View File

@ -477,13 +477,15 @@ void Update_All()
} }
update_aux_flags(); update_aux_flags();
PPM_FLAG_off; // wait for next frame before update PPM_FLAG_off; // wait for next frame before update
INPUT_SIGNAL_on; //valid signal received
last_signal=millis();
} }
#endif //ENABLE_PPM #endif //ENABLE_PPM
update_led_status();
#if defined(TELEMETRY) #if defined(TELEMETRY)
if((protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) ) if((protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) )
TelemetryUpdate(); TelemetryUpdate();
#endif #endif
update_led_status();
} }
// Update Servo_AUX flags based on servo AUX positions // Update Servo_AUX flags based on servo AUX positions
@ -508,10 +510,18 @@ static void update_aux_flags(void)
// Update led status based on binding and serial // Update led status based on binding and serial
static void update_led_status(void) static void update_led_status(void)
{ {
if(IS_INPUT_SIGNAL_on)
if(millis()-last_signal>50)
INPUT_SIGNAL_off; //no valid signal (PPM or Serial) received for 50ms
if(blink<millis()) if(blink<millis())
{ {
if(cur_protocol[1]==0) //No valid serial received at least once if(IS_INPUT_SIGNAL_off)
blink+=BLINK_SERIAL_TIME; //blink slowly while waiting a valid serial input {
if(mode_select==MODE_SERIAL)
blink+=BLINK_SERIAL_TIME; //blink slowly if no valid serial input
else
blink+=BLINK_PPM_TIME; //blink more slowly if no valid PPM input
}
else else
if(remote_callback == 0) if(remote_callback == 0)
{ // Invalid protocol { // Invalid protocol
@ -521,10 +531,11 @@ static void update_led_status(void)
blink+=BLINK_BAD_PROTO_TIME_HIGH; blink+=BLINK_BAD_PROTO_TIME_HIGH;
} }
else else
{
if(IS_BIND_DONE_on) if(IS_BIND_DONE_on)
LED_off; //bind completed -> led on LED_off; //bind completed force led on
else
blink+=BLINK_BIND_TIME; //blink fastly during binding blink+=BLINK_BIND_TIME; //blink fastly during binding
}
LED_toggle; LED_toggle;
} }
} }
@ -1150,25 +1161,27 @@ static uint32_t random_id(uint16_t adress, uint8_t create_new)
#endif #endif
#endif #endif
{ // Interrupt on PPM pin { // Interrupt on PPM pin
static int8_t chan=-1; static int8_t chan=0,bad_frame=1;
static uint16_t Prev_TCNT1=0; static uint16_t Prev_TCNT1=0;
uint16_t Cur_TCNT1; uint16_t Cur_TCNT1;
Cur_TCNT1=TCNT1-Prev_TCNT1; // Capture current Timer1 value Cur_TCNT1=TCNT1-Prev_TCNT1; // Capture current Timer1 value
if(Cur_TCNT1<1000) if(Cur_TCNT1<1000)
chan=-1; // bad frame bad_frame=1; // bad frame
else else
if(Cur_TCNT1>4840) if(Cur_TCNT1>4840)
{ { //start of frame
chan=0; // start of frame if(chan>3)
PPM_FLAG_on; // full frame present (even at startup since PPM_data has been initialized) PPM_FLAG_on; // good frame received if at least 4 channels have been seen
chan=0; // reset channel counter
bad_frame=0;
} }
else else
if(chan!=-1) // need to wait for start of frame if(bad_frame==0) // need to wait for start of frame
{ //servo values between 500us and 2420us will end up here { //servo values between 500us and 2420us will end up here
PPM_data[chan]= Cur_TCNT1>>1;; PPM_data[chan]= Cur_TCNT1>>1;;
if(chan++>=NUM_CHN) if(chan++>=NUM_CHN)
chan=-1; // don't accept any new channels bad_frame=1; // don't accept any new channels
} }
Prev_TCNT1+=Cur_TCNT1; Prev_TCNT1+=Cur_TCNT1;
} }

View File

@ -12,7 +12,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>. along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
*/ */
// Last sync with hexfet new_protocols/slt_nrf24l01.c dated 2015-02-13 // Last sync with deviation main github branch
#if defined(SLT_NRF24L01_INO) #if defined(SLT_NRF24L01_INO)
@ -24,11 +24,11 @@
#define SLT_TXID_SIZE 4 #define SLT_TXID_SIZE 4
enum { enum {
SLT_INIT2 = 0, SLT_BUILD=0,
SLT_BIND,
SLT_DATA1, SLT_DATA1,
SLT_DATA2, SLT_DATA2,
SLT_DATA3 SLT_DATA3,
SLT_BIND
}; };
static void __attribute__((unused)) SLT_init() static void __attribute__((unused)) SLT_init()
@ -45,24 +45,18 @@ static void __attribute__((unused)) SLT_init()
NRF24L01_SetPower(); NRF24L01_SetPower();
NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, (uint8_t*)"\xC3\xC3\xAA\x55", 4); NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, (uint8_t*)"\xC3\xC3\xAA\x55", 4);
NRF24L01_FlushRx(); NRF24L01_FlushRx();
} NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, rx_tx_addr, SLT_TXID_SIZE);
static void __attribute__((unused)) SLT_init2()
{
NRF24L01_FlushTx(); NRF24L01_FlushTx();
packet_sent = 0;
hopping_frequency_no = 0;
// Turn radio power on // Turn radio power on
NRF24L01_SetTxRxMode(TX_EN); NRF24L01_SetTxRxMode(TX_EN);
} }
static void __attribute__((unused)) SLT_set_tx_id(void) static void __attribute__((unused)) SLT_set_freq(void)
{ {
// Frequency hopping sequence generation // Frequency hopping sequence generation
for (uint8_t i = 0; i < 4; ++i) for (uint8_t i = 0; i < SLT_TXID_SIZE; ++i)
{ {
uint8_t next_i = (i+1) % 4; // is & 3 better than % 4 ? uint8_t next_i = (i+1) % SLT_TXID_SIZE; // is & 3 better than % 4 ?
uint8_t base = i < 2 ? 0x03 : 0x10; uint8_t base = i < 2 ? 0x03 : 0x10;
hopping_frequency[i*4 + 0] = (rx_tx_addr[i] & 0x3f) + base; hopping_frequency[i*4 + 0] = (rx_tx_addr[i] & 0x3f) + base;
hopping_frequency[i*4 + 1] = (rx_tx_addr[i] >> 2) + base; hopping_frequency[i*4 + 1] = (rx_tx_addr[i] >> 2) + base;
@ -72,8 +66,9 @@ static void __attribute__((unused)) SLT_set_tx_id(void)
} }
// unique // unique
uint8_t done = 0;
for (uint8_t i = 0; i < SLT_NFREQCHANNELS; ++i) for (uint8_t i = 0; i < SLT_NFREQCHANNELS; ++i)
{
uint8_t done = 0;
while (!done) while (!done)
{ {
done = 1; done = 1;
@ -86,8 +81,7 @@ static void __attribute__((unused)) SLT_set_tx_id(void)
hopping_frequency[i] = hopping_frequency[i] - 0x50 + 0x03; hopping_frequency[i] = hopping_frequency[i] - 0x50 + 0x03;
} }
} }
}
NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, rx_tx_addr, 4);
} }
static void __attribute__((unused)) SLT_wait_radio() static void __attribute__((unused)) SLT_wait_radio()
@ -109,9 +103,15 @@ static void __attribute__((unused)) SLT_send_data(uint8_t *data, uint8_t len)
static void __attribute__((unused)) SLT_build_packet() static void __attribute__((unused)) SLT_build_packet()
{ {
// Set radio channel - once per packet batch
NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no]);
if (++hopping_frequency_no >= SLT_NFREQCHANNELS)
hopping_frequency_no = 0;
// aileron, elevator, throttle, rudder, gear, pitch // aileron, elevator, throttle, rudder, gear, pitch
uint8_t e = 0; // byte where extension 2 bits for every 10-bit channel are packed uint8_t e = 0; // byte where extension 2 bits for every 10-bit channel are packed
for (uint8_t i = 0; i < 4; ++i) { for (uint8_t i = 0; i < 4; ++i)
{
uint16_t v = convert_channel_10b(CH_AETR[i]); uint16_t v = convert_channel_10b(CH_AETR[i]);
packet[i] = v; packet[i] = v;
e = (e >> 2) | (uint8_t) ((v >> 2) & 0xC0); e = (e >> 2) | (uint8_t) ((v >> 2) & 0xC0);
@ -121,81 +121,71 @@ static void __attribute__((unused)) SLT_build_packet()
// 8-bit channels // 8-bit channels
packet[5] = convert_channel_8b(AUX1); packet[5] = convert_channel_8b(AUX1);
packet[6] = convert_channel_8b(AUX2); packet[6] = convert_channel_8b(AUX2);
// Set radio channel - once per packet batch
NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no]);
if (++hopping_frequency_no >= SLT_NFREQCHANNELS)
hopping_frequency_no = 0;
} }
static void __attribute__((unused)) SLT_send_bind_packet() static void __attribute__((unused)) SLT_send_bind_packet()
{ {
SLT_wait_radio(); SLT_wait_radio();
BIND_IN_PROGRESS; // autobind protocol BIND_IN_PROGRESS; //Limit TX power to bind level
NRF24L01_SetPower(); NRF24L01_SetPower();
NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, (uint8_t *)"\x7E\xB8\x63\xA9", 4); BIND_DONE;
NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, (uint8_t *)"\x7E\xB8\x63\xA9", SLT_TXID_SIZE);
NRF24L01_WriteReg(NRF24L01_05_RF_CH, 0x50); NRF24L01_WriteReg(NRF24L01_05_RF_CH, 0x50);
SLT_send_data(rx_tx_addr, 4); SLT_send_data(rx_tx_addr, SLT_TXID_SIZE);
// NB: we should wait until the packet's sent before changing TX address! SLT_wait_radio(); //Wait until the packet's sent before changing TX address!
SLT_wait_radio();
BIND_DONE; NRF24L01_SetPower(); //Change power back to normal level
NRF24L01_SetPower(); NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, rx_tx_addr, SLT_TXID_SIZE);
NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, rx_tx_addr, 4);
} }
uint16_t SLT_callback() uint16_t SLT_callback()
{ {
uint16_t delay_us = 20000; // 3 packets with 1ms intervals every 22ms
switch (phase) switch (phase)
{ {
case SLT_INIT2: case SLT_BUILD:
SLT_init2();
phase = SLT_BIND;
delay_us = 150;
break;
case SLT_BIND:
SLT_send_bind_packet();
phase = SLT_DATA1;
delay_us = 19000;
break;
case SLT_DATA1:
SLT_build_packet(); SLT_build_packet();
SLT_send_data(packet, 7); phase++;
phase = SLT_DATA2; return 1000;
delay_us = 1000; case SLT_DATA1:
break; SLT_send_data(packet, SLT_PAYLOADSIZE);
phase++;
return 1000;
case SLT_DATA2: case SLT_DATA2:
SLT_send_data(packet, 7); SLT_send_data(packet, SLT_PAYLOADSIZE);
phase = SLT_DATA3; phase++;
delay_us = 1000; return 1000;
break;
case SLT_DATA3: case SLT_DATA3:
SLT_send_data(packet, 7); SLT_send_data(packet, SLT_PAYLOADSIZE);
if (++counter >= 100) if (++packet_count >= 100)
{ {
counter = 0; packet_count = 0;
phase = SLT_BIND; phase++;
delay_us = 1000; return 1000;
} }
else else
{ {
NRF24L01_SetPower(); // Set tx_power NRF24L01_SetPower(); // Set tx_power
phase = SLT_DATA1; phase = SLT_BUILD;
return 19000;
} }
break; case SLT_BIND:
SLT_send_bind_packet();
phase = SLT_BUILD;
return 18000;
} }
return delay_us; return 19000;
} }
uint16_t initSLT() uint16_t initSLT()
{ {
counter = 0; packet_count = 0;
packet_sent = 0;
hopping_frequency_no = 0;
SLT_set_freq();
SLT_init(); SLT_init();
phase = SLT_INIT2; phase = SLT_BIND;
SLT_set_tx_id();
return 50000; return 50000;
} }

View File

@ -56,6 +56,7 @@
//PPM values used to compare //PPM values used to compare
#define PPM_MIN_COMMAND 1250 #define PPM_MIN_COMMAND 1250
#define PPM_SWITCH 1550 #define PPM_SWITCH 1550
#define PPM_SWITCH_B 1450
#define PPM_MAX_COMMAND 1750 #define PPM_MAX_COMMAND 1750
//Channel definitions //Channel definitions

View File

@ -196,14 +196,11 @@ static void __attribute__((unused)) V2X2_send_packet(uint8_t bind)
// Channel 11 // Channel 11
if (Servo_AUX7) flags2 |= JXD_FLAG_EMERGENCY; if (Servo_AUX7) flags2 |= JXD_FLAG_EMERGENCY;
/* // Channel 12 down // Channel 12 down
if (num_channels < 11 || Channels[CHANNEL11] >= CHAN_MIN_VALUE/2) *flags2 &= ~FLAG_CAMERA_DN; if (Servo_data[AUX8] < PPM_SWITCH_B) flags2 |= JXD_FLAG_CAMERA_DN;
else *flags2 |= JXD_FLAG_CAMERA_DN;
// Channel 12 up // Channel 12 up
if (num_channels < 11 || Channels[CHANNEL11] <= CHAN_MAX_VALUE/2) *flags2 &= ~FLAG_CAMERA_UP; if (Servo_data[AUX8] > PPM_SWITCH) flags2 |= JXD_FLAG_CAMERA_UP;
else *flags2 |= JXD_FLAG_CAMERA_UP;
*/
} else { } else {
// Channel 10 // Channel 10
if (Servo_AUX6) if (Servo_AUX6)

View File

@ -60,7 +60,7 @@
//Comment the protocols you are not using with "//" to save Flash space. //Comment the protocols you are not using with "//" to save Flash space.
//The protocols below need an A7105 to be installed //The protocols below need an A7105 to be installed
// #define JOYSWAY_A7105_INO #define JOYSWAY_A7105_INO
#define FLYSKY_A7105_INO #define FLYSKY_A7105_INO
#define HUBSAN_A7105_INO #define HUBSAN_A7105_INO

View File

@ -167,7 +167,7 @@ enum FY326
FY326 = 0, FY326 = 0,
FY319 = 1 FY319 = 1
}; };
enum{ enum V2X2 {
FORMAT_V202 = 0, FORMAT_V202 = 0,
FORMAT_JXD506 = 1, FORMAT_JXD506 = 1,
}; };
@ -266,12 +266,18 @@ struct PPM_Parameters
#define IS_TX_RX_PAUSE_on ( ( protocol_flags2 & _BV(4) ) !=0 ) #define IS_TX_RX_PAUSE_on ( ( protocol_flags2 & _BV(4) ) !=0 )
#define IS_TX_PAUSE_on ( ( protocol_flags2 & (_BV(4)|_BV(3)) ) !=0 ) #define IS_TX_PAUSE_on ( ( protocol_flags2 & (_BV(4)|_BV(3)) ) !=0 )
//Signal OK
#define INPUT_SIGNAL_off protocol_flags2 &= ~_BV(5)
#define INPUT_SIGNAL_on protocol_flags2 |= _BV(5)
#define IS_INPUT_SIGNAL_on ( ( protocol_flags2 & _BV(5) ) !=0 )
#define IS_INPUT_SIGNAL_off ( ( protocol_flags2 & _BV(5) ) ==0 )
//******************** //********************
//*** Blink timing *** //*** Blink timing ***
//******************** //********************
#define BLINK_BIND_TIME 100 #define BLINK_BIND_TIME 100
#define BLINK_SERIAL_TIME 500 #define BLINK_SERIAL_TIME 500
#define BLINK_PPM_TIME 1000
#define BLINK_BAD_PROTO_TIME_LOW 1000 #define BLINK_BAD_PROTO_TIME_LOW 1000
#define BLINK_BAD_PROTO_TIME_HIGH 50 #define BLINK_BAD_PROTO_TIME_HIGH 50
@ -461,6 +467,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
DSM2_11 1 DSM2_11 1
DSMX_22 2 DSMX_22 2
DSMX_11 3 DSMX_11 3
DSM_AUTO 4
sub_protocol==YD717 sub_protocol==YD717
YD717 0 YD717 0
SKYWLKR 1 SKYWLKR 1

Binary file not shown.