From 0a86153843916f6e5512d9ef888deeaf917ee2e0 Mon Sep 17 00:00:00 2001 From: bsongis Date: Mon, 1 Sep 2014 15:08:15 +0200 Subject: [PATCH] SBUS --- .../opentx/opentxTaranisSimulator.cpp | 1 + radio/src/Makefile | 2 +- radio/src/myeeprom.h | 1 + radio/src/opentx.cpp | 4 + radio/src/opentx.h | 4 + radio/src/sbus.cpp | 88 +++++++++++++++++++ radio/src/targets/taranis/uart3_driver.cpp | 26 ++++-- radio/src/translations/cz.h.txt | 2 +- radio/src/translations/de.h.txt | 2 +- radio/src/translations/en.h.txt | 2 +- radio/src/translations/es.h.txt | 2 +- radio/src/translations/fi.h.txt | 2 +- radio/src/translations/fr.h.txt | 2 +- radio/src/translations/it.h.txt | 2 +- radio/src/translations/pl.h.txt | 2 +- radio/src/translations/pt.h.txt | 2 +- radio/src/translations/se.h.txt | 2 +- 17 files changed, 129 insertions(+), 17 deletions(-) create mode 100755 radio/src/sbus.cpp diff --git a/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp b/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp index bc8d6c572..51352a1b2 100644 --- a/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp +++ b/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp @@ -108,6 +108,7 @@ inline int geteepromsize() { #include "radio/src/keys.cpp" #include "radio/src/bmp.cpp" #include "radio/src/haptic.cpp" +#include "radio/src/sbus.cpp" #include "radio/src/targets/taranis/haptic_driver.cpp" // TODO Because FatFS in not C++ there cannot be namespaces there and the functions are defined several times! #undef SDCARD diff --git a/radio/src/Makefile b/radio/src/Makefile index 5fa62343e..1a0da41d8 100644 --- a/radio/src/Makefile +++ b/radio/src/Makefile @@ -683,7 +683,7 @@ ifeq ($(PCB), TARANIS) EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp eeprom_conversions.cpp LCDSRC = lcd_common.cpp lcd_taranis.cpp PULSESSRC = pulses/pulses_arm.cpp pulses/ppm_arm.cpp pulses/pxx_arm.cpp - CPPSRC += audio_arm.cpp + CPPSRC += audio_arm.cpp sbus.cpp CPPSRC += targets/taranis/pulses_driver.cpp targets/taranis/keys_driver.cpp targets/taranis/adc_driver.cpp targets/taranis/trainer_driver.cpp targets/taranis/audio_driver.cpp targets/taranis/uart3_driver.cpp targets/taranis/telemetry_driver.cpp CPPSRC += bmp.cpp gui/view_channels.cpp gui/view_about.cpp gui/view_text.cpp loadboot.cpp SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index cea4ce107..3a40f014b 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -308,6 +308,7 @@ enum uartModes { UART_MODE_NONE, UART_MODE_TELEMETRY_MIRROR, UART_MODE_TELEMETRY, + UART_MODE_SBUS_TRAINER, #if defined(DEBUG) UART_MODE_DEBUG, #endif diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 205b4472c..9f1d6600e 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -2216,6 +2216,10 @@ void doMixerCalculations() getADC(); +#if defined(PCBTARANIS) + processSbusInput(); +#endif + getSwitchesPosition(!s_mixer_first_run_done); #if defined(CPUARM) diff --git a/radio/src/opentx.h b/radio/src/opentx.h index a419fe73e..9e4179031 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -949,6 +949,10 @@ void checkAll(); void getADC(); #endif +#if defined(PCBTARANIS) +void processSbusInput(); +#endif + extern void backlightOn(); enum Analogs { diff --git a/radio/src/sbus.cpp b/radio/src/sbus.cpp new file mode 100755 index 000000000..086659833 --- /dev/null +++ b/radio/src/sbus.cpp @@ -0,0 +1,88 @@ +/* + * Authors (alphabetical order) + * - Andre Bernet + * - Andreas Weitl + * - Bertrand Songis + * - Bryan J. Rentoul (Gruvin) + * - Cameron Weeks + * - Erez Raviv + * - Gabriel Birkus + * - Jean-Pierre Parisy + * - Karl Szmutny + * - Michael Blandford + * - Michal Hlavinka + * - Pat Mackenzie + * - Philip Moss + * - Rob Thomson + * - Romolo Manfredini + * - Thomas Husterer + * + * opentx is based on code named + * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, + * er9x by Erez Raviv: http://code.google.com/p/er9x/, + * and the original (and ongoing) project by + * Thomas Husterer, th9x: http://code.google.com/p/th9x/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include "opentx.h" + +Fifo<28> sbusFifo; +uint8_t SbusFrame[28] ; +uint16_t SbusTimer ; +uint8_t SbusIndex = 0 ; + +void processSbusFrame(uint8_t *sbus, int16_t *pulses) +{ + uint32_t inputbitsavailable = 0; + uint32_t inputbits = 0; + + if (*sbus++ != 0x0F) { + return; // not a valid SBUS frame + } + + for (uint32_t i=0; i>= 11; + } +} + +#define SBUS_DELAY 1000 // 500uS +void processSbusInput() +{ + uint8_t rxchar; + uint32_t active = 0; + while (sbusFifo.pop(rxchar)) { + active = 1; + SbusFrame[SbusIndex++] = rxchar; + if (SbusIndex > 27) { + SbusIndex = 27; + } + } + if (active) { + SbusTimer = getTmr2MHz(); + return; + } + else { + if (SbusIndex) { + if ((uint16_t) (getTmr2MHz() - SbusTimer) > SBUS_DELAY) { + processSbusFrame(SbusFrame, g_ppmIns); + SbusIndex = 0; + } + } + } +} diff --git a/radio/src/targets/taranis/uart3_driver.cpp b/radio/src/targets/taranis/uart3_driver.cpp index 7a286262c..8100672cd 100644 --- a/radio/src/targets/taranis/uart3_driver.cpp +++ b/radio/src/targets/taranis/uart3_driver.cpp @@ -36,9 +36,10 @@ #include "../../opentx.h" -bool uart3Telemetry = false; +uint8_t uart3Mode = UART_MODE_NONE; Fifo<512> uart3TxFifo; extern Fifo<512> telemetryFifo; +extern Fifo<28> sbusFifo; void uart3Setup(unsigned int baudrate) { @@ -79,7 +80,8 @@ void uart3Setup(unsigned int baudrate) void uart3Init(unsigned int mode, unsigned int protocol) { USART_DeInit(USART3); - uart3Telemetry = false; + + uart3Mode = false; switch (mode) { case UART_MODE_TELEMETRY_MIRROR: @@ -93,10 +95,15 @@ void uart3Init(unsigned int mode, unsigned int protocol) case UART_MODE_TELEMETRY: if (protocol == PROTOCOL_FRSKY_D_SECONDARY) { uart3Setup(FRSKY_D_BAUDRATE); - uart3Telemetry = true; } break; + case UART_MODE_SBUS_TRAINER: + uart3Setup(100000); + USART3->CR1 |= USART_CR1_M | USART_CR1_PCE ; + break; } + + uart3Mode = mode; } void uart3Putc(const char c) @@ -108,7 +115,7 @@ void uart3Putc(const char c) #if defined(DEBUG) void debugPutc(const char c) { - if (g_eeGeneral.uart3Mode == UART_MODE_DEBUG) { + if (uart3Mode == UART_MODE_DEBUG) { uart3Putc(c); } } @@ -135,8 +142,15 @@ extern "C" void USART3_IRQHandler(void) while (status & (USART_FLAG_RXNE | USART_FLAG_ERRORS)) { uint8_t data = USART3->DR; - if (uart3Telemetry && !(status & USART_FLAG_ERRORS)) { - telemetryFifo.push(data); + if (!(status & USART_FLAG_ERRORS)) { + switch (uart3Mode) { + case UART_MODE_TELEMETRY: + telemetryFifo.push(data); + break; + case UART_MODE_SBUS_TRAINER: + sbusFifo.push(data); + break; + } } status = USART3->SR; diff --git a/radio/src/translations/cz.h.txt b/radio/src/translations/cz.h.txt index 338921c49..e7ae8dc3d 100644 --- a/radio/src/translations/cz.h.txt +++ b/radio/src/translations/cz.h.txt @@ -80,7 +80,7 @@ #define TR_TRNCHN "CH1CH2CH3CH4" #define LEN_UART3MODES "\017" -#define TR_UART3MODES "VYP\0 ""S-Port Mirror\0 ""Telemetrie\0 ""Debug\0 " +#define TR_UART3MODES "VYP\0 ""S-Port Mirror\0 ""Telemetrie\0 ""Trainer\0 ""Debug\0 " #define LEN_POTTYPES "\017" #define TR_POTTYPES "Není\0 ""Pot s aretací\0 ""Vícepol. přep.\0""Potenciometr\0" diff --git a/radio/src/translations/de.h.txt b/radio/src/translations/de.h.txt index 708d46a72..f38388933 100644 --- a/radio/src/translations/de.h.txt +++ b/radio/src/translations/de.h.txt @@ -80,7 +80,7 @@ #define TR_TRNCHN "CH1CH2CH3CH4" #define LEN_UART3MODES "\017" -#define TR_UART3MODES "AUS\0 ""S-Port DataOut\0""Telemetrie\0 ""Debug\0 " +#define TR_UART3MODES "AUS\0 ""S-Port DataOut\0""Telemetrie\0 ""Trainer\0 ""Debug\0 " #define LEN_POTTYPES "\017" #define TR_POTTYPES "Kein\0 ""Poti mit Raste ""Stufen-Schalter""Poti ohne Raste\0" diff --git a/radio/src/translations/en.h.txt b/radio/src/translations/en.h.txt index 072f43be9..3443924f0 100644 --- a/radio/src/translations/en.h.txt +++ b/radio/src/translations/en.h.txt @@ -80,7 +80,7 @@ #define TR_TRNCHN "CH1CH2CH3CH4" #define LEN_UART3MODES "\017" -#define TR_UART3MODES "OFF\0 ""S-Port Mirror\0 ""Telemetry\0 ""Debug\0 " +#define TR_UART3MODES "OFF\0 ""S-Port Mirror\0 ""Telemetry\0 ""SBUS Trainer\0 ""Debug\0 " #define LEN_POTTYPES "\017" #define TR_POTTYPES "None\0 ""Pot with detent""Multipos Switch""Pot\0" diff --git a/radio/src/translations/es.h.txt b/radio/src/translations/es.h.txt index 67ecbd4da..ee996afdf 100644 --- a/radio/src/translations/es.h.txt +++ b/radio/src/translations/es.h.txt @@ -80,7 +80,7 @@ #define TR_TRNCHN "CH1CH2CH3CH4" #define LEN_UART3MODES "\017" -#define TR_UART3MODES "OFF\0 ""S-Port Mirror\0 ""Telemetry\0 ""Debug\0 " +#define TR_UART3MODES "OFF\0 ""S-Port Mirror\0 ""Telemetry\0 ""Trainer\0 ""Debug\0 " #define LEN_POTTYPES "\017" #define TR_POTTYPES "None\0 ""Pot with detent""Multipos Switch""Pot\0" diff --git a/radio/src/translations/fi.h.txt b/radio/src/translations/fi.h.txt index 8454f6488..ac79bc322 100644 --- a/radio/src/translations/fi.h.txt +++ b/radio/src/translations/fi.h.txt @@ -80,7 +80,7 @@ #define TR_TRNCHN "CH1CH2CH3CH4" #define LEN_UART3MODES "\017" -#define TR_UART3MODES "POIS\0 ""S-Port Pelik\0 ""Telemetry\0 ""Debug\0 " +#define TR_UART3MODES "POIS\0 ""S-Port Pelik\0 ""Telemetry\0 ""Trainer\0 ""Debug\0 " #define LEN_POTTYPES "\017" #define TR_POTTYPES "None\0 ""Pot with detent""Monias. Kytkin\0""Potikka\0" diff --git a/radio/src/translations/fr.h.txt b/radio/src/translations/fr.h.txt index 0e05359d1..6d10c98fe 100644 --- a/radio/src/translations/fr.h.txt +++ b/radio/src/translations/fr.h.txt @@ -80,7 +80,7 @@ #define TR_TRNCHN "CH1CH2CH3CH4" #define LEN_UART3MODES "\017" -#define TR_UART3MODES "OFF\0 ""Recopie S-Port\0""Telemetrie\0 ""Debug\0 " +#define TR_UART3MODES "OFF\0 ""Recopie S-Port\0""Telemetrie\0 ""Ecolage SBUS\0 ""Debug\0 " #define LEN_POTTYPES "\017" #define TR_POTTYPES "Rien\0 ""Pot avec centre""Inter multi-pos""Potentiomètre\0" diff --git a/radio/src/translations/it.h.txt b/radio/src/translations/it.h.txt index 62d8b6e63..599128cab 100644 --- a/radio/src/translations/it.h.txt +++ b/radio/src/translations/it.h.txt @@ -80,7 +80,7 @@ #define TR_TRNCHN "ch1ch2ch3ch4" #define LEN_UART3MODES "\017" -#define TR_UART3MODES "OFF\0 ""Replica Porta-S""Telemetria\0 ""Debug\0 " +#define TR_UART3MODES "OFF\0 ""Replica Porta-S""Telemetria\0 ""Trainer\0 ""Debug\0 " #define LEN_POTTYPES "\017" #define TR_POTTYPES "None\0 ""Pot. con centro""Inter. Multipos""Potenziometro\0 " diff --git a/radio/src/translations/pl.h.txt b/radio/src/translations/pl.h.txt index 8b1a3a207..e8c4535e1 100644 --- a/radio/src/translations/pl.h.txt +++ b/radio/src/translations/pl.h.txt @@ -80,7 +80,7 @@ #define TR_TRNCHN "KN1KN2KN3KN4" #define LEN_UART3MODES "\017" -#define TR_UART3MODES "Wyłącz\0 ""S-Port Mirror\0 ""Telemetry\0 ""Debug\0 " +#define TR_UART3MODES "Wyłącz\0 ""S-Port Mirror\0 ""Telemetry\0 ""Trainer\0 ""Debug\0 " #define LEN_POTTYPES "\017" #define TR_POTTYPES "Brak\0 ""Poten z zapadką""Przeł.Wielopoz.""Potencjometr\0" diff --git a/radio/src/translations/pt.h.txt b/radio/src/translations/pt.h.txt index e00553c65..fdfa2e267 100644 --- a/radio/src/translations/pt.h.txt +++ b/radio/src/translations/pt.h.txt @@ -80,7 +80,7 @@ #define TR_TRNCHN "CH1CH2CH3CH4" #define LEN_UART3MODES "\017" -#define TR_UART3MODES "OFF\0 ""S-Port Mirror\0 ""Telemetry\0 ""Debug\0 " +#define TR_UART3MODES "OFF\0 ""S-Port Mirror\0 ""Telemetry\0 ""Trainer\0 ""Debug\0 " #define LEN_POTTYPES "\017" #define TR_POTTYPES "None\0 ""Pot with detent""Multipos Switch""Pot\0" diff --git a/radio/src/translations/se.h.txt b/radio/src/translations/se.h.txt index 85e0a95c4..2c2886af8 100644 --- a/radio/src/translations/se.h.txt +++ b/radio/src/translations/se.h.txt @@ -80,7 +80,7 @@ #define TR_TRNCHN "KN1KN2KN3KN4" #define LEN_UART3MODES "\022" -#define TR_UART3MODES "Av\0 ""Spegling av S-Port""Telemetri\0 ""Debug\0 " +#define TR_UART3MODES "Av\0 ""Spegling av S-Port""Telemetri\0 ""Trainer\0 ""Debug\0 " #define LEN_POTTYPES "\020" #define TR_POTTYPES "Ingen\0 ""Mittläges-pot\0 ""Flerlägesväljare""Potentiometer\0"