Skip to content

Commit

Permalink
added SBUS_TRAINER define to make it build time option (#439)
Browse files Browse the repository at this point in the history
* added SBUS_TRAINER define to make it build time option
* exclude more, exclude trainer connect/disconnect sounds, make it build time option
  • Loading branch information
ajjjjjjjj authored Nov 21, 2024
1 parent 6a5e87c commit baa5ed3
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 36 deletions.
6 changes: 5 additions & 1 deletion radio/src/dataconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@ enum BeeperMode {
#elif defined(PCBX7) || defined(PCBXLITE)
#define TRAINER_MODE_MAX() TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE
#elif defined(PCBI6X)
#define TRAINER_MODE_MAX() TRAINER_MODE_MASTER_BATTERY_COMPARTMENT
#if defined(SBUS_TRAINER)
#define TRAINER_MODE_MAX() TRAINER_MODE_MASTER_BATTERY_COMPARTMENT
#else
#define TRAINER_MODE_MAX() TRAINER_MODE_MASTER_TRAINER_JACK
#endif
#else
#define TRAINER_MODE_MAX() HAS_WIRELESS_TRAINER_HARDWARE() ? TRAINER_MODE_MASTER_BATTERY_COMPARTMENT : TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE
#endif
Expand Down
12 changes: 4 additions & 8 deletions radio/src/gui/128x64/model_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ enum MenuModelSetupItems {
ITEM_MODEL_EXTRA_MODULE_BIND,
#endif
ITEM_MODEL_EXTERNAL_MODULE_FAILSAFE,
#if defined(PCBTARANIS) || defined(PCBI6X)
#if defined(SBUS_TRAINER)
ITEM_MODEL_TRAINER_LABEL,
ITEM_MODEL_TRAINER_MODE,
#endif
Expand All @@ -132,14 +132,10 @@ enum MenuModelSetupItems {
#define MODEL_SETUP_RANGE_OFS 4*FW+3
#define MODEL_SETUP_SET_FAILSAFE_OFS 7*FW-2

#if defined(PCBTARANIS) || defined(PCBI6X)
#if defined(SBUS_TRAINER)
#define CURRENT_MODULE_EDITED(k) (k>=ITEM_MODEL_TRAINER_LABEL ? TRAINER_MODULE : (k>=ITEM_MODEL_EXTERNAL_MODULE_LABEL ? EXTERNAL_MODULE : INTERNAL_MODULE))
#elif defined(PCBSKY9X) && !defined(REVA)
#define CURRENT_MODULE_EDITED(k) (k>=ITEM_MODEL_EXTRA_MODULE_LABEL ? EXTRA_MODULE : EXTERNAL_MODULE)
// #elif defined(PCBI6X)
// #define CURRENT_MODULE_EDITED(k) (k>=ITEM_MODEL_EXTERNAL_MODULE_LABEL ? EXTERNAL_MODULE : INTERNAL_MODULE)
#else
#define CURRENT_MODULE_EDITED(k) (EXTERNAL_MODULE)
#define CURRENT_MODULE_EDITED(k) (k>=ITEM_MODEL_EXTERNAL_MODULE_LABEL ? EXTERNAL_MODULE : INTERNAL_MODULE)
#endif

#if defined(PCBXLITE)
Expand Down Expand Up @@ -952,7 +948,7 @@ void menuModelSetup(event_t event)
break;
#endif

#if defined(PCBTARANIS) || defined(PCBI6X)
#if defined(PCBTARANIS) || defined(SBUS_TRAINER)
case ITEM_MODEL_TRAINER_LABEL:
lcdDrawTextAlignedLeft(y, STR_TRAINER);
break;
Expand Down
3 changes: 2 additions & 1 deletion radio/src/opentx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,8 +1423,9 @@ void doMixerPeriodicUpdates()
s_cnt_1s += 1;

logicalSwitchesTimerTick();
#if defined(SBUS_TRAINER)
checkTrainerSignalWarning();

#endif
if (s_cnt_1s >= 10) { // 1sec
s_cnt_1s -= 10;
sessionTimer += 1;
Expand Down
15 changes: 11 additions & 4 deletions radio/src/targets/common/arm/stm32/aux_serial_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ void auxSerialSetup(unsigned int baudrate, bool dma, uint16_t lenght = USART_Wor
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;

#if defined(SBUS_TRAINER)
GPIO_PinAFConfig(AUX_SERIAL_GPIO, AUX_SERIAL_GPIO_PinSource_RX, AUX_SERIAL_GPIO_AF);
#endif
GPIO_PinAFConfig(AUX_SERIAL_GPIO, AUX_SERIAL_GPIO_PinSource_TX, AUX_SERIAL_GPIO_AF);

GPIO_InitStructure.GPIO_Pin = AUX_SERIAL_GPIO_PIN_TX | AUX_SERIAL_GPIO_PIN_RX;
Expand All @@ -53,6 +55,7 @@ void auxSerialSetup(unsigned int baudrate, bool dma, uint16_t lenght = USART_Wor
USART_Init(AUX_SERIAL_USART, &USART_InitStructure);

if (dma) {
#if defined(SBUS_TRAINER)
auxSerialRxFifo.stream = AUX_SERIAL_DMA_Channel_RX; // workaround, CNDTR reading do not work otherwise
auxSerialRxFifo.clear();
USART_ITConfig(AUX_SERIAL_USART, USART_IT_RXNE, DISABLE);
Expand All @@ -70,10 +73,11 @@ void auxSerialSetup(unsigned int baudrate, bool dma, uint16_t lenght = USART_Wor
| DMA_PeripheralDataSize_Byte
| DMA_MemoryDataSize_Byte;

USART_InvPinCmd(AUX_SERIAL_USART, USART_InvPin_Rx, ENABLE); // Only for SBUS!
USART_InvPinCmd(AUX_SERIAL_USART, USART_InvPin_Rx, ENABLE); // Only for SBUS
USART_DMACmd(AUX_SERIAL_USART, USART_DMAReq_Rx, ENABLE);
USART_Cmd(AUX_SERIAL_USART, ENABLE);
DMA_Cmd(AUX_SERIAL_DMA_Channel_RX, ENABLE);
#endif // SBUS_TRAINER
}
else {
USART_Cmd(AUX_SERIAL_USART, ENABLE);
Expand Down Expand Up @@ -110,9 +114,10 @@ void auxSerialInit(unsigned int mode, unsigned int protocol)
break;
#endif

#if defined(SBUS)
#if defined(SBUS_TRAINER)
case UART_MODE_SBUS_TRAINER:
auxSerialSetup(SBUS_BAUDRATE, true, USART_WordLength_9b, USART_Parity_Even, USART_StopBits_2); // USART_WordLength_9b due to parity bit
// AUX_SERIAL_POWER_ON();
break;
#endif

Expand Down Expand Up @@ -140,16 +145,18 @@ void auxSerialPutc(char c)
#endif
}

#if defined(SBUS_TRAINER)
void auxSerialSbusInit()
{
#if defined(SBUS)
auxSerialInit(UART_MODE_SBUS_TRAINER, 0);
#endif
}
#endif

void auxSerialStop()
{
#if defined(SBUS_TRAINER)
DMA_DeInit(AUX_SERIAL_DMA_Channel_RX);
#endif
USART_DeInit(AUX_SERIAL_USART);
}

Expand Down
16 changes: 10 additions & 6 deletions radio/src/targets/flysky/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ option(PCBI6X_USB_MSD "Enable USB mass storage mode" YES) # 3.2kB
option(AFHDS2A_LQI_CH "Send RSSI at channel 1-17" OFF)
option(DFPLAYER "Enables DFPlayer on AUX3 TX" NO) # ~1.7kB
option(FAKE_RSSI "Enables converting TRSS to RSSI data for receivers not sending RSSI" NO)
option(SBUS_TRAINER "Enables SBUS Trainer mode and trainer lost/back sounds" NO) # ~0.6kB

if(PCB STREQUAL I6X)
set(PWR_BUTTON "SWITCH" CACHE STRING "Pwr button type (PRESS/SWITCH)")
Expand Down Expand Up @@ -96,7 +97,7 @@ set(TARGET_SRC
endif()

if(PCBI6X_USB_MSD STREQUAL YES)
add_definitions(-DPCBI6X_USB_MSD)
add_definitions(-DPCBI6X_USB_MSD)
endif()

set(TARGET_SRC
Expand All @@ -108,11 +109,14 @@ set(TARGET_SRC
../common/arm/stm32/timers_driver.cpp
)

add_definitions(-DSBUS)
set(PULSES_SRC
${PULSES_SRC}
../sbus.cpp
)
if(SBUS_TRAINER STREQUAL YES)
add_definitions(-DSBUS)
add_definitions(-DSBUS_TRAINER)
set(PULSES_SRC
${PULSES_SRC}
../sbus.cpp
)
endif()

set(HSE_VALUE 8000000)
set(SDCARD NO) # ~24kB
Expand Down
3 changes: 2 additions & 1 deletion radio/src/targets/flysky/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,9 @@ extern void ISR_TIMER3_CAPT_vect(void);
#define CR_PSIZE_MASK ((uint32_t)0xFFFFFCFF)

// Serial Port

#if defined(SBUS_TRAINER)
#define TRAINER_BATTERY_COMPARTMENT
#endif

// AUX Serial
#define AUX_SERIAL_RCC_AHB1Periph (RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_DMA1)
Expand Down
13 changes: 1 addition & 12 deletions radio/src/targets/flysky/telemetry_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ extern "C" void TELEMETRY_USART_IRQHandler(void) {
DEBUG_INTERRUPT(INT_TELEM_USART);
uint32_t status = TELEMETRY_USART->ISR;

// TX
// TX, transfer complete
if ((status & USART_ISR_TC) && (TELEMETRY_USART->CR1 & USART_CR1_TCIE)) {
TELEMETRY_USART->CR1 &= ~USART_CR1_TCIE;
telemetryPortSetDirectionInput();
Expand All @@ -184,16 +184,5 @@ extern "C" void TELEMETRY_USART_IRQHandler(void) {

// TODO we should have telemetry in an higher layer, functions above should move to a sport_driver.cpp
uint8_t telemetryGetByte(uint8_t* byte) {
#if defined(AUX_SERIAL) && !defined(PCBI6X)
if (telemetryProtocol == PROTOCOL_FRSKY_D_SECONDARY) {
if (auxSerialMode == UART_MODE_TELEMETRY)
return auxSerialRxFifo.pop(*byte);
else
return false;
} else {
return telemetryDMAFifo.pop(*byte);
}
#else
return telemetryDMAFifo.pop(*byte);
#endif
}
4 changes: 3 additions & 1 deletion radio/src/targets/flysky/trainer_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void stop_trainer_capture()
// nothing to do because it would stop EXTMODULE_TIMER
}

#if defined(SBUS_TRAINER)
int sbusGetByte(uint8_t * byte)
{
switch (currentTrainerMode) {
Expand All @@ -48,4 +49,5 @@ int sbusGetByte(uint8_t * byte)
default:
return false;
}
}
}
#endif
4 changes: 2 additions & 2 deletions radio/src/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void execMixerFrequentActions()
DEBUG_TIMER_STOP(debugTimerTelemetryWakeup);
}

#if defined(SBUS)
#if defined(SBUS_TRAINER)
if (g_eeGeneral.auxSerialMode == UART_MODE_SBUS_TRAINER) {
processSbusInput();
}
Expand Down Expand Up @@ -258,7 +258,7 @@ void tasksStart() {
RTOS_CREATE_TASK(audioTaskId, audioTask, "Audio", audioStack, AUDIO_STACK_SIZE, AUDIO_TASK_PRIO);
#endif

#if !defined(PCBI6X)
#if defined(VOICE)
RTOS_CREATE_MUTEX(audioMutex);
#endif
RTOS_CREATE_MUTEX(mixerMutex);
Expand Down
1 change: 1 addition & 0 deletions tools/build-flysky.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"PPM_UNIT": "PERCENT_PREC1",
"PCBI6X_USB_VBUS": "NO",
"PCBI6X_USB_MSD": "YES",
"SBUS_TRAINER": "NO",
}


Expand Down

0 comments on commit baa5ed3

Please sign in to comment.