mirror of
https://github.com/opentx/opentx.git
synced 2025-07-26 01:35:21 +03:00
SBUS
This commit is contained in:
parent
d4e64d9c2b
commit
0a86153843
17 changed files with 129 additions and 17 deletions
|
@ -108,6 +108,7 @@ inline int geteepromsize() {
|
||||||
#include "radio/src/keys.cpp"
|
#include "radio/src/keys.cpp"
|
||||||
#include "radio/src/bmp.cpp"
|
#include "radio/src/bmp.cpp"
|
||||||
#include "radio/src/haptic.cpp"
|
#include "radio/src/haptic.cpp"
|
||||||
|
#include "radio/src/sbus.cpp"
|
||||||
#include "radio/src/targets/taranis/haptic_driver.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!
|
// TODO Because FatFS in not C++ there cannot be namespaces there and the functions are defined several times!
|
||||||
#undef SDCARD
|
#undef SDCARD
|
||||||
|
|
|
@ -683,7 +683,7 @@ ifeq ($(PCB), TARANIS)
|
||||||
EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp eeprom_conversions.cpp
|
EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp eeprom_conversions.cpp
|
||||||
LCDSRC = lcd_common.cpp lcd_taranis.cpp
|
LCDSRC = lcd_common.cpp lcd_taranis.cpp
|
||||||
PULSESSRC = pulses/pulses_arm.cpp pulses/ppm_arm.cpp pulses/pxx_arm.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 += 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
|
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
|
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c
|
||||||
|
|
|
@ -308,6 +308,7 @@ enum uartModes {
|
||||||
UART_MODE_NONE,
|
UART_MODE_NONE,
|
||||||
UART_MODE_TELEMETRY_MIRROR,
|
UART_MODE_TELEMETRY_MIRROR,
|
||||||
UART_MODE_TELEMETRY,
|
UART_MODE_TELEMETRY,
|
||||||
|
UART_MODE_SBUS_TRAINER,
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
UART_MODE_DEBUG,
|
UART_MODE_DEBUG,
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2216,6 +2216,10 @@ void doMixerCalculations()
|
||||||
|
|
||||||
getADC();
|
getADC();
|
||||||
|
|
||||||
|
#if defined(PCBTARANIS)
|
||||||
|
processSbusInput();
|
||||||
|
#endif
|
||||||
|
|
||||||
getSwitchesPosition(!s_mixer_first_run_done);
|
getSwitchesPosition(!s_mixer_first_run_done);
|
||||||
|
|
||||||
#if defined(CPUARM)
|
#if defined(CPUARM)
|
||||||
|
|
|
@ -949,6 +949,10 @@ void checkAll();
|
||||||
void getADC();
|
void getADC();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(PCBTARANIS)
|
||||||
|
void processSbusInput();
|
||||||
|
#endif
|
||||||
|
|
||||||
extern void backlightOn();
|
extern void backlightOn();
|
||||||
|
|
||||||
enum Analogs {
|
enum Analogs {
|
||||||
|
|
88
radio/src/sbus.cpp
Executable file
88
radio/src/sbus.cpp
Executable file
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
* Authors (alphabetical order)
|
||||||
|
* - Andre Bernet <bernet.andre@gmail.com>
|
||||||
|
* - Andreas Weitl
|
||||||
|
* - Bertrand Songis <bsongis@gmail.com>
|
||||||
|
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||||
|
* - Cameron Weeks <th9xer@gmail.com>
|
||||||
|
* - Erez Raviv
|
||||||
|
* - Gabriel Birkus
|
||||||
|
* - Jean-Pierre Parisy
|
||||||
|
* - Karl Szmutny
|
||||||
|
* - Michael Blandford
|
||||||
|
* - Michal Hlavinka
|
||||||
|
* - Pat Mackenzie
|
||||||
|
* - Philip Moss
|
||||||
|
* - Rob Thomson
|
||||||
|
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||||
|
* - 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<NUM_TRAINER; i++) {
|
||||||
|
while (inputbitsavailable < 11) {
|
||||||
|
inputbits |= *sbus++ << inputbitsavailable;
|
||||||
|
inputbitsavailable += 8;
|
||||||
|
}
|
||||||
|
*pulses++ = ((int32_t) (inputbits & 0x7FF) - 0x3E0) * 5 / 8;
|
||||||
|
inputbitsavailable -= 11;
|
||||||
|
inputbits >>= 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,9 +36,10 @@
|
||||||
|
|
||||||
#include "../../opentx.h"
|
#include "../../opentx.h"
|
||||||
|
|
||||||
bool uart3Telemetry = false;
|
uint8_t uart3Mode = UART_MODE_NONE;
|
||||||
Fifo<512> uart3TxFifo;
|
Fifo<512> uart3TxFifo;
|
||||||
extern Fifo<512> telemetryFifo;
|
extern Fifo<512> telemetryFifo;
|
||||||
|
extern Fifo<28> sbusFifo;
|
||||||
|
|
||||||
void uart3Setup(unsigned int baudrate)
|
void uart3Setup(unsigned int baudrate)
|
||||||
{
|
{
|
||||||
|
@ -79,7 +80,8 @@ void uart3Setup(unsigned int baudrate)
|
||||||
void uart3Init(unsigned int mode, unsigned int protocol)
|
void uart3Init(unsigned int mode, unsigned int protocol)
|
||||||
{
|
{
|
||||||
USART_DeInit(USART3);
|
USART_DeInit(USART3);
|
||||||
uart3Telemetry = false;
|
|
||||||
|
uart3Mode = false;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case UART_MODE_TELEMETRY_MIRROR:
|
case UART_MODE_TELEMETRY_MIRROR:
|
||||||
|
@ -93,10 +95,15 @@ void uart3Init(unsigned int mode, unsigned int protocol)
|
||||||
case UART_MODE_TELEMETRY:
|
case UART_MODE_TELEMETRY:
|
||||||
if (protocol == PROTOCOL_FRSKY_D_SECONDARY) {
|
if (protocol == PROTOCOL_FRSKY_D_SECONDARY) {
|
||||||
uart3Setup(FRSKY_D_BAUDRATE);
|
uart3Setup(FRSKY_D_BAUDRATE);
|
||||||
uart3Telemetry = true;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case UART_MODE_SBUS_TRAINER:
|
||||||
|
uart3Setup(100000);
|
||||||
|
USART3->CR1 |= USART_CR1_M | USART_CR1_PCE ;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uart3Mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart3Putc(const char c)
|
void uart3Putc(const char c)
|
||||||
|
@ -108,7 +115,7 @@ void uart3Putc(const char c)
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
void debugPutc(const char c)
|
void debugPutc(const char c)
|
||||||
{
|
{
|
||||||
if (g_eeGeneral.uart3Mode == UART_MODE_DEBUG) {
|
if (uart3Mode == UART_MODE_DEBUG) {
|
||||||
uart3Putc(c);
|
uart3Putc(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,8 +142,15 @@ extern "C" void USART3_IRQHandler(void)
|
||||||
while (status & (USART_FLAG_RXNE | USART_FLAG_ERRORS)) {
|
while (status & (USART_FLAG_RXNE | USART_FLAG_ERRORS)) {
|
||||||
uint8_t data = USART3->DR;
|
uint8_t data = USART3->DR;
|
||||||
|
|
||||||
if (uart3Telemetry && !(status & USART_FLAG_ERRORS)) {
|
if (!(status & USART_FLAG_ERRORS)) {
|
||||||
telemetryFifo.push(data);
|
switch (uart3Mode) {
|
||||||
|
case UART_MODE_TELEMETRY:
|
||||||
|
telemetryFifo.push(data);
|
||||||
|
break;
|
||||||
|
case UART_MODE_SBUS_TRAINER:
|
||||||
|
sbusFifo.push(data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status = USART3->SR;
|
status = USART3->SR;
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
#define TR_TRNCHN "CH1CH2CH3CH4"
|
#define TR_TRNCHN "CH1CH2CH3CH4"
|
||||||
|
|
||||||
#define LEN_UART3MODES "\017"
|
#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 LEN_POTTYPES "\017"
|
||||||
#define TR_POTTYPES "Není\0 ""Pot s aretací\0 ""Vícepol. přep.\0""Potenciometr\0"
|
#define TR_POTTYPES "Není\0 ""Pot s aretací\0 ""Vícepol. přep.\0""Potenciometr\0"
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
#define TR_TRNCHN "CH1CH2CH3CH4"
|
#define TR_TRNCHN "CH1CH2CH3CH4"
|
||||||
|
|
||||||
#define LEN_UART3MODES "\017"
|
#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 LEN_POTTYPES "\017"
|
||||||
#define TR_POTTYPES "Kein\0 ""Poti mit Raste ""Stufen-Schalter""Poti ohne Raste\0"
|
#define TR_POTTYPES "Kein\0 ""Poti mit Raste ""Stufen-Schalter""Poti ohne Raste\0"
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
#define TR_TRNCHN "CH1CH2CH3CH4"
|
#define TR_TRNCHN "CH1CH2CH3CH4"
|
||||||
|
|
||||||
#define LEN_UART3MODES "\017"
|
#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 LEN_POTTYPES "\017"
|
||||||
#define TR_POTTYPES "None\0 ""Pot with detent""Multipos Switch""Pot\0"
|
#define TR_POTTYPES "None\0 ""Pot with detent""Multipos Switch""Pot\0"
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
#define TR_TRNCHN "CH1CH2CH3CH4"
|
#define TR_TRNCHN "CH1CH2CH3CH4"
|
||||||
|
|
||||||
#define LEN_UART3MODES "\017"
|
#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 LEN_POTTYPES "\017"
|
||||||
#define TR_POTTYPES "None\0 ""Pot with detent""Multipos Switch""Pot\0"
|
#define TR_POTTYPES "None\0 ""Pot with detent""Multipos Switch""Pot\0"
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
#define TR_TRNCHN "CH1CH2CH3CH4"
|
#define TR_TRNCHN "CH1CH2CH3CH4"
|
||||||
|
|
||||||
#define LEN_UART3MODES "\017"
|
#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 LEN_POTTYPES "\017"
|
||||||
#define TR_POTTYPES "None\0 ""Pot with detent""Monias. Kytkin\0""Potikka\0"
|
#define TR_POTTYPES "None\0 ""Pot with detent""Monias. Kytkin\0""Potikka\0"
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
#define TR_TRNCHN "CH1CH2CH3CH4"
|
#define TR_TRNCHN "CH1CH2CH3CH4"
|
||||||
|
|
||||||
#define LEN_UART3MODES "\017"
|
#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 LEN_POTTYPES "\017"
|
||||||
#define TR_POTTYPES "Rien\0 ""Pot avec centre""Inter multi-pos""Potentiomètre\0"
|
#define TR_POTTYPES "Rien\0 ""Pot avec centre""Inter multi-pos""Potentiomètre\0"
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
#define TR_TRNCHN "ch1ch2ch3ch4"
|
#define TR_TRNCHN "ch1ch2ch3ch4"
|
||||||
|
|
||||||
#define LEN_UART3MODES "\017"
|
#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 LEN_POTTYPES "\017"
|
||||||
#define TR_POTTYPES "None\0 ""Pot. con centro""Inter. Multipos""Potenziometro\0 "
|
#define TR_POTTYPES "None\0 ""Pot. con centro""Inter. Multipos""Potenziometro\0 "
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
#define TR_TRNCHN "KN1KN2KN3KN4"
|
#define TR_TRNCHN "KN1KN2KN3KN4"
|
||||||
|
|
||||||
#define LEN_UART3MODES "\017"
|
#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 LEN_POTTYPES "\017"
|
||||||
#define TR_POTTYPES "Brak\0 ""Poten z zapadką""Przeł.Wielopoz.""Potencjometr\0"
|
#define TR_POTTYPES "Brak\0 ""Poten z zapadką""Przeł.Wielopoz.""Potencjometr\0"
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
#define TR_TRNCHN "CH1CH2CH3CH4"
|
#define TR_TRNCHN "CH1CH2CH3CH4"
|
||||||
|
|
||||||
#define LEN_UART3MODES "\017"
|
#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 LEN_POTTYPES "\017"
|
||||||
#define TR_POTTYPES "None\0 ""Pot with detent""Multipos Switch""Pot\0"
|
#define TR_POTTYPES "None\0 ""Pot with detent""Multipos Switch""Pot\0"
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
#define TR_TRNCHN "KN1KN2KN3KN4"
|
#define TR_TRNCHN "KN1KN2KN3KN4"
|
||||||
|
|
||||||
#define LEN_UART3MODES "\022"
|
#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 LEN_POTTYPES "\020"
|
||||||
#define TR_POTTYPES "Ingen\0 ""Mittläges-pot\0 ""Flerlägesväljare""Potentiometer\0"
|
#define TR_POTTYPES "Ingen\0 ""Mittläges-pot\0 ""Flerlägesväljare""Potentiometer\0"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue