Skip to content

Commit

Permalink
feat(radio): discover SBUS trainer availability
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcoeffic committed Oct 30, 2023
1 parent 745bb8d commit 68745a8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
39 changes: 27 additions & 12 deletions radio/src/gui/gui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,26 +1068,41 @@ bool isTrainerModeAvailable(int mode)
return false;
#endif

if (mode == TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE ||
mode == TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE) {

#if !defined(TRAINER_MODULE_CPPM)
if (mode == TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE)
return false;
if (mode == TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE)
return false;
#endif

#if !defined(TRAINER_MODULE_SBUS)
if (mode == TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE)
return false;
if (mode == mode == TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE)
return false;
#endif

#if defined(TRAINER_MODULE_CPPM) || defined(TRAINER_MODULE_SBUS)
if (IS_EXTERNAL_MODULE_ENABLED() &&
(mode == TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE ||
mode == TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE))
return false;
// no external module or is enabled
if (!modulePortGetModuleDescription(EXTERNAL_MODULE) ||
IS_EXTERNAL_MODULE_ENABLED()) {
return false;
}

if (mode == TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE) {
#if defined(EXTMODULE_USART) || defined(CONFIGURABLE_MODULE_PORT)
auto port = modulePortFind(EXTERNAL_MODULE, ETX_MOD_TYPE_SERIAL,
ETX_MOD_PORT_UART, ETX_Pol_Normal);
return port != nullptr;
#elif defined(TRAINER_MODULE_SBUS_USART)
return true;
#else
return false;
#endif
}
}

#if !defined(MULTIMODULE) || !defined(HARDWARE_INTERNAL_MODULE) || !defined(HARDWARE_EXTERNAL_MODULE)
if (mode == TRAINER_MODE_MULTI)
return false;
#if !defined(MULTIMODULE) || !defined(HARDWARE_INTERNAL_MODULE) || \
!defined(HARDWARE_EXTERNAL_MODULE)
if (mode == TRAINER_MODE_MULTI) return false;
#else
if (mode == TRAINER_MODE_MULTI &&
((!IS_INTERNAL_MODULE_ENABLED() && !IS_EXTERNAL_MODULE_ENABLED()) ||
Expand Down
4 changes: 4 additions & 0 deletions radio/src/targets/horus/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,10 @@
#define TRAINER_MODULE_CPPM_TIMER_IRQHandler TIM4_IRQHandler
#define TRAINER_MODULE_CPPM_GPIO_AF LL_GPIO_AF_2

#if defined(EXTMODULE_USART) || defined(CONFIGURABLE_MODULE_PORT)
#define TRAINER_MODULE_SBUS
#endif

// Millisecond timer
#define MS_TIMER TIM14
#define MS_TIMER_IRQn TIM8_TRG_COM_TIM14_IRQn
Expand Down
1 change: 1 addition & 0 deletions radio/src/targets/nv14/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@
#define TRAINER_GPIO_AF LL_GPIO_AF_2
#define TRAINER_TIMER_FREQ (PERI1_FREQUENCY * TIMER_MULT_APB1)

#define TRAINER_MODULE_SBUS

//BLUETOOTH
#define BLUETOOTH_ON_RCC_AHB1Periph RCC_AHB1Periph_GPIOI
Expand Down

0 comments on commit 68745a8

Please sign in to comment.