From 186080c1366893b76164e1e0e8f87e711a69acf0 Mon Sep 17 00:00:00 2001 From: rusefillc <48498823+rusefillc@users.noreply.github.com> Date: Fri, 7 Jul 2023 01:23:42 -0400 Subject: [PATCH] Just need a bullet-proof solution which would work regardless of class, struct, typedef struct or not defined type (#5395) --- .../config/boards/f407-discovery/board.mk | 2 +- .../boards/hellen/alphax-4chan/board.mk | 3 +- firmware/config/boards/s105/board.mk | 2 +- .../config/boards/subaru_eg33/efifeatures.h | 1 + .../binary/tunerstudio_io_serial_ports.cpp | 43 +++++++------------ simulator/simulator/efifeatures.h | 2 + 6 files changed, 23 insertions(+), 30 deletions(-) diff --git a/firmware/config/boards/f407-discovery/board.mk b/firmware/config/boards/f407-discovery/board.mk index b5d7139f27..10b396b63f 100644 --- a/firmware/config/boards/f407-discovery/board.mk +++ b/firmware/config/boards/f407-discovery/board.mk @@ -39,7 +39,7 @@ DDEFS += -DEFI_SENT_SUPPORT=TRUE # TS_SECONDARY_UxART_PORT DDEFS += -DSTM32_SERIAL_USE_USART3=TRUE -DDEFS += -DTS_SECONDARY_UxART_PORT=SD3 +DDEFS += -DTS_SECONDARY_UxART_PORT=SD3 -DEFI_TS_SECONDARY_IS_SERIAL=TRUE DDEFS += -DSTM32_I2C_USE_I2C3=TRUE diff --git a/firmware/config/boards/hellen/alphax-4chan/board.mk b/firmware/config/boards/hellen/alphax-4chan/board.mk index a23222d1d5..509bbb23fd 100644 --- a/firmware/config/boards/hellen/alphax-4chan/board.mk +++ b/firmware/config/boards/hellen/alphax-4chan/board.mk @@ -27,7 +27,8 @@ ifeq ($(PROJECT_CPU),ARCH_STM32F7) #Linker options, flash size USE_OPT += -Wl,--defsym=FLASH_SIZE=768k # TODO do we only support serial on F7 but not UART? - DDEFS += -DEFI_CONSOLE_TX_BRAIN_PIN=Gpio::D6 -DEFI_CONSOLE_RX_BRAIN_PIN=Gpio::D5 -DTS_PRIMARY_UxART_PORT=SD2 -DSTM32_SERIAL_USE_USART2=TRUE -DSTM32_UART_USE_USART2=FALSE + DDEFS += -DEFI_CONSOLE_TX_BRAIN_PIN=Gpio::D6 -DEFI_CONSOLE_RX_BRAIN_PIN=Gpio::D5 + DDEFS += -DTS_PRIMARY_UxART_PORT=SD2 -DEFI_TS_PRIMARY_IS_SERIAL=TRUE -DSTM32_SERIAL_USE_USART2=TRUE -DSTM32_UART_USE_USART2=FALSE else ifeq ($(PROJECT_CPU),ARCH_STM32F4) DDEFS += -DSHORT_BOARD_NAME=alphax-4chan DDEFS += $(PRIMARY_COMMUNICATION_PORT_USART2) diff --git a/firmware/config/boards/s105/board.mk b/firmware/config/boards/s105/board.mk index 82242e2800..c10e9d1fbb 100644 --- a/firmware/config/boards/s105/board.mk +++ b/firmware/config/boards/s105/board.mk @@ -31,7 +31,7 @@ USE_FATFS = no # TS serial DDEFS += -DSTM32_SERIAL_USE_USART1=TRUE -DDEFS += -DTS_PRIMARY_UxART_PORT=SD1 +DDEFS += -DTS_PRIMARY_UxART_PORT=SD1 -DEFI_TS_PRIMARY_IS_SERIAL=TRUE # WARNING: those are USB pins on discovery or rusEFI brain board so make sure to power those NOT via USB DDEFS += -DEFI_CONSOLE_TX_BRAIN_PIN=Gpio::A9 -DEFI_CONSOLE_RX_BRAIN_PIN=Gpio::A10 diff --git a/firmware/config/boards/subaru_eg33/efifeatures.h b/firmware/config/boards/subaru_eg33/efifeatures.h index e58a14149c..a0631c60f7 100644 --- a/firmware/config/boards/subaru_eg33/efifeatures.h +++ b/firmware/config/boards/subaru_eg33/efifeatures.h @@ -13,6 +13,7 @@ /* debug console */ #define TS_PRIMARY_UxART_PORT SD1 +#define EFI_TS_PRIMARY_IS_SERIAL TRUE /* Knock detection */ #undef EFI_HIP_9011 diff --git a/firmware/console/binary/tunerstudio_io_serial_ports.cpp b/firmware/console/binary/tunerstudio_io_serial_ports.cpp index 48886ef9dc..7b57a447dc 100644 --- a/firmware/console/binary/tunerstudio_io_serial_ports.cpp +++ b/firmware/console/binary/tunerstudio_io_serial_ports.cpp @@ -14,27 +14,16 @@ #include "hellen_meta.h" #endif // HW_HELLEN -// These may not be defined due to the HAL, but they're necessary for the compiler to do it's magic -class UARTDriver; -class UartDmaTsChannel; -class UartTsChannel; -class SerialTsChannel; - #ifdef TS_PRIMARY_UxART_PORT -// We want to instantiate the correct channel type depending on what type of serial port we're -// using. ChibiOS supports two - UART and Serial. We compare the type of the port we're given -// against UartDriver and decide whether to instantiate a UART TS Channel or a Serial version. The -// UART is further subdivided into two depending whether we support DMA or not. We use the right -// combination of std::conditional, std::is_same, and #if to get what we want. - std::conditional_t< - std::is_same_v, -#if EFI_USE_UART_DMA - UartDmaTsChannel, -#else // EFI_USE_UART_DMA - UartTsChannel, -#endif // EFI_USE_UART_DMA - SerialTsChannel> primaryChannel(TS_PRIMARY_UxART_PORT); +#if EFI_TS_PRIMARY_IS_SERIAL + SerialTsChannel +#elif EFI_USE_UART_DMA + UartDmaTsChannel +#else + UartTsChannel +#endif + primaryChannel(TS_PRIMARY_UxART_PORT); struct PrimaryChannelThread : public TunerstudioThread { PrimaryChannelThread() : TunerstudioThread("Primary TS Channel") { } @@ -57,14 +46,14 @@ class SerialTsChannel; #endif // defined(TS_PRIMARY_UxART_PORT) #ifdef TS_SECONDARY_UxART_PORT - std::conditional_t< - std::is_same_v, -#if EFI_USE_UART_DMA - UartDmaTsChannel, -#else // EFI_USE_UART_DMA - UartTsChannel, -#endif // EFI_USE_UART_DMA - SerialTsChannel> secondaryChannel(TS_SECONDARY_UxART_PORT); +#if EFI_TS_SECONDARY_IS_SERIAL + SerialTsChannel +#elif EFI_USE_UART_DMA + UartDmaTsChannel +#else + UartTsChannel +#endif + secondaryChannel(TS_SECONDARY_UxART_PORT); struct SecondaryChannelThread : public TunerstudioThread { SecondaryChannelThread() : TunerstudioThread("Secondary TS Channel") { } diff --git a/simulator/simulator/efifeatures.h b/simulator/simulator/efifeatures.h index d6b9c8a09a..5eb8044255 100644 --- a/simulator/simulator/efifeatures.h +++ b/simulator/simulator/efifeatures.h @@ -9,7 +9,9 @@ // see SIM_SD1_PORT and SIM_SD2_PORT #define TS_PRIMARY_UxART_PORT SD1 +#define EFI_TS_PRIMARY_IS_SERIAL TRUE #define TS_SECONDARY_UxART_PORT SD2 +#define EFI_TS_SECONDARY_IS_SERIAL TRUE #define EFI_ENABLE_ASSERTS TRUE #define EFI_LAUNCH_CONTROL TRUE