From 9b30a3d72aa8d82837101e57f6979b005a1b82f9 Mon Sep 17 00:00:00 2001 From: Pascal Langer Date: Sat, 4 Aug 2018 23:47:15 +0200 Subject: [PATCH] FrSky X: SPORT polling Mike's corrections to make SPORT working on Taranis. --- Multiprotocol/FrSkyX_cc2500.ino | 5 +++ Multiprotocol/Hitec_cc2500.ino | 4 +- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Multiprotocol.ino | 5 +++ Multiprotocol/Telemetry.ino | 68 +++++++++++++++++++++++++++++++++ Multiprotocol/_Config.h | 4 +- 6 files changed, 83 insertions(+), 5 deletions(-) diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index 4a317af..40f0622 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -333,6 +333,11 @@ uint16_t initFrSkyX() //rx_tx_addr[2]=0xFD; //************************ frskyX_init(); +#if defined SPORT_POLLING +#ifdef INVERT_SERIAL + start_timer4() ; +#endif +#endif // if(IS_BIND_IN_PROGRESS) { diff --git a/Multiprotocol/Hitec_cc2500.ino b/Multiprotocol/Hitec_cc2500.ino index 7a7a05e..4fcffde 100644 --- a/Multiprotocol/Hitec_cc2500.ino +++ b/Multiprotocol/Hitec_cc2500.ino @@ -17,7 +17,7 @@ #include "iface_cc2500.h" -//#define HITEC_FORCE_ID //Use the ID and hopping table from original dump +//#define HITEC_FORCE_ID //Use the ID and hopping table from the original dump #define HITEC_COARSE 0 @@ -158,7 +158,7 @@ static void __attribute__((unused)) HITEC_build_packet() } packet[19] = 0x08; // packet number packet[20] = 0x00; // starts with 0x00 and after some time it alternates between 0x00 and 0xF5 - packet[21] = 0x00; // unknown when [20]=0xF5 then the value is 0xE0 or 0xDC + packet[21] = 0x00; // unknown when [20]=0xF5 then this value is between 0xDB and 0xE0. TODO: test if it could be RSSI related? } else { diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index c9f2796..0951b80 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 2 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 23 +#define VERSION_PATCH_LEVEL 24 //****************** // Protocols diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index ece93d9..6c1ae97 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -55,6 +55,11 @@ #include #include HardwareTimer HWTimer2(2); +#if defined SPORT_POLLING +#ifdef INVERT_TELEMETRY + HardwareTimer HWTimer4(4); +#endif +#endif void PPM_decode(); void ISR_COMPB(); extern "C" diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index c686f9d..1a6b723 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -91,6 +91,11 @@ static void multi_send_header(uint8_t type, uint8_t len) static void multi_send_status() { #ifdef SPORT_POLLING + #ifdef INVERT_SERIAL + USART3_BASE->CR1 &= ~USART_CR1_TE ; + TX_INV_on; //activate inverter for both serial TX and RX signals + USART3_BASE->CR1 |= USART_CR1_TE ; + #endif rx_pause(); #endif multi_send_header(MULTI_TELEMETRY_STATUS, 5); @@ -476,6 +481,13 @@ const uint8_t PROGMEM Indices[] = { 0x00, 0xA1, 0x22, 0x83, 0xE4, 0x45, #ifdef MULTI_TELEMETRY void sportSend(uint8_t *p) { + #ifdef SPORT_POLLING + #ifdef INVERT_SERIAL + USART3_BASE->CR1 &= ~USART_CR1_TE ; + TX_INV_on; //activate inverter for both serial TX and RX signals + USART3_BASE->CR1 |= USART_CR1_TE ; + #endif + #endif multi_send_header(MULTI_TELEMETRY_SPORT, 9); uint16_t crc_s = 0; uint8_t x = p[0] ; @@ -500,6 +512,13 @@ const uint8_t PROGMEM Indices[] = { 0x00, 0xA1, 0x22, 0x83, 0xE4, 0x45, void sportSend(uint8_t *p) { uint16_t crc_s = 0; + #ifdef SPORT_POLLING + #ifdef INVERT_SERIAL + USART3_BASE->CR1 &= ~USART_CR1_TE ; + TX_INV_on; //activate inverter for both serial TX and RX signals + USART3_BASE->CR1 |= USART_CR1_TE ; + #endif + #endif Serial_write(START_STOP);//+9 Serial_write(p[0]) ; for (uint8_t i = 1; i < 9; i++) @@ -585,6 +604,33 @@ uint8_t nextID() return poll_idx ; } +#ifdef INVERT_SERIAL +void start_timer4() +{ + TIMER4_BASE->PSC = 71; // 72-1;for 72 MHZ / 1.0sec/(71+1) + TIMER4_BASE->CCER = 0 ; + TIMER4_BASE->DIER = 0 ; + TIMER4_BASE->CCMR1 = 0 ; + TIMER4_BASE->CCMR1 = TIMER_CCMR1_OC1M ; + HWTimer4.attachInterrupt(TIMER_CH1, __irq_timer4); // Assign function to Timer2/Comp2 interrupt + nvic_irq_set_priority( NVIC_TIMER4, 14 ) ; +} + +void stop_timer4() +{ + TIMER5_BASE->CR1 = 0 ; + nvic_irq_disable( NVIC_TIMER4 ) ; +} + +void __irq_timer4(void) +{ + TIMER4_BASE->DIER = 0 ; + TIMER4_BASE->CR1 = 0 ; + TX_INV_on; //activate inverter for both serial TX and RX signals +} + +#endif + void pollSport() { uint8_t pindex = nextID() ; @@ -597,12 +643,25 @@ void pollSport() } SportIndexPolling = pindex ; RxIndex = 0; + #ifdef INVERT_SERIAL + USART3_BASE->CR1 &= ~USART_CR1_TE ; + TX_INV_on; //activate inverter for both serial TX and RX signals + USART3_BASE->CR1 |= USART_CR1_TE ; + #endif #ifdef MULTI_TELEMETRY multi_send_header(MULTI_TELEMETRY_SPORT_POLLING, 1); #else Serial_write(TxData[0]); #endif + RxIndex=0; Serial_write(TxData[1]); + USART3_BASE->CR1 |= USART_CR1_TCIE ; +#ifdef INVERT_SERIAL + TIMER4_BASE->CNT = 0 ; + TIMER4_BASE->CCR1 = 3000 ; + TIMER4_BASE->DIER = TIMER_DIER_CC1IE ; + TIMER4_BASE->CR1 = TIMER_CR1_CEN ; +#endif } bool checkSportPacket() @@ -1039,6 +1098,15 @@ void TelemetryUpdate() { // Transmit interrupt #ifdef STM32_BOARD #ifdef SPORT_POLLING + if(USART3_BASE->SR & USART_SR_TC) + { + if ( USART3_BASE->CR1 & USART_CR1_TCIE ) + { + USART3_BASE->CR1 &= ~USART_CR1_TCIE ; + TX_INV_off; + } + } + if(USART3_BASE->SR & USART_SR_RXNE) { USART3_BASE->SR &= ~USART_SR_RXNE; diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index e2d6756..21092ed 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -89,8 +89,8 @@ //#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. +//For optimal performance the CC2500 RF module used by the FrSkyD, FrSkyV, FrSkyX, SFHSS, CORONA and Hitec protocols needs to be tuned for each protocol. +//Initial tuning should be done via the radio menu with a genuine FrSky/Futaba/CORONA/Hitec 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.