From baa5ed36f359098ddbd39237e8e68b5d83dc224b Mon Sep 17 00:00:00 2001 From: Janek Date: Thu, 21 Nov 2024 10:56:17 +0100 Subject: [PATCH] added SBUS_TRAINER define to make it build time option (#439) * added SBUS_TRAINER define to make it build time option * exclude more, exclude trainer connect/disconnect sounds, make it build time option --- radio/src/dataconstants.h | 6 +++++- radio/src/gui/128x64/model_setup.cpp | 12 ++++-------- radio/src/opentx.cpp | 3 ++- .../common/arm/stm32/aux_serial_driver.cpp | 15 +++++++++++---- radio/src/targets/flysky/CMakeLists.txt | 16 ++++++++++------ radio/src/targets/flysky/hal.h | 3 ++- radio/src/targets/flysky/telemetry_driver.cpp | 13 +------------ radio/src/targets/flysky/trainer_driver.cpp | 4 +++- radio/src/tasks.cpp | 4 ++-- tools/build-flysky.py | 1 + 10 files changed, 41 insertions(+), 36 deletions(-) diff --git a/radio/src/dataconstants.h b/radio/src/dataconstants.h index 2381a58fdd5..7bba58c58e3 100644 --- a/radio/src/dataconstants.h +++ b/radio/src/dataconstants.h @@ -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 diff --git a/radio/src/gui/128x64/model_setup.cpp b/radio/src/gui/128x64/model_setup.cpp index e9604bb283c..fe6a641fe5c 100644 --- a/radio/src/gui/128x64/model_setup.cpp +++ b/radio/src/gui/128x64/model_setup.cpp @@ -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 @@ -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) @@ -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; diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index dab5afea252..85c11991369 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -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; diff --git a/radio/src/targets/common/arm/stm32/aux_serial_driver.cpp b/radio/src/targets/common/arm/stm32/aux_serial_driver.cpp index d14b822a531..62fb7f1f02c 100644 --- a/radio/src/targets/common/arm/stm32/aux_serial_driver.cpp +++ b/radio/src/targets/common/arm/stm32/aux_serial_driver.cpp @@ -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; @@ -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); @@ -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); @@ -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 @@ -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); } diff --git a/radio/src/targets/flysky/CMakeLists.txt b/radio/src/targets/flysky/CMakeLists.txt index 654699a420b..756e463fe55 100644 --- a/radio/src/targets/flysky/CMakeLists.txt +++ b/radio/src/targets/flysky/CMakeLists.txt @@ -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)") @@ -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 @@ -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 diff --git a/radio/src/targets/flysky/hal.h b/radio/src/targets/flysky/hal.h index 7356e8b73e2..06080b6968b 100644 --- a/radio/src/targets/flysky/hal.h +++ b/radio/src/targets/flysky/hal.h @@ -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) diff --git a/radio/src/targets/flysky/telemetry_driver.cpp b/radio/src/targets/flysky/telemetry_driver.cpp index ff31da515d1..68933acea0e 100644 --- a/radio/src/targets/flysky/telemetry_driver.cpp +++ b/radio/src/targets/flysky/telemetry_driver.cpp @@ -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(); @@ -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 } diff --git a/radio/src/targets/flysky/trainer_driver.cpp b/radio/src/targets/flysky/trainer_driver.cpp index ed8d3607f97..f1af4f823d3 100644 --- a/radio/src/targets/flysky/trainer_driver.cpp +++ b/radio/src/targets/flysky/trainer_driver.cpp @@ -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) { @@ -48,4 +49,5 @@ int sbusGetByte(uint8_t * byte) default: return false; } -} \ No newline at end of file +} +#endif diff --git a/radio/src/tasks.cpp b/radio/src/tasks.cpp index a837b7141f1..e149cfbbd0e 100644 --- a/radio/src/tasks.cpp +++ b/radio/src/tasks.cpp @@ -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(); } @@ -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); diff --git a/tools/build-flysky.py b/tools/build-flysky.py index 387a631ac9c..d9582ae259d 100755 --- a/tools/build-flysky.py +++ b/tools/build-flysky.py @@ -60,6 +60,7 @@ "PPM_UNIT": "PERCENT_PREC1", "PCBI6X_USB_VBUS": "NO", "PCBI6X_USB_MSD": "YES", + "SBUS_TRAINER": "NO", }