diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index 278bdafab5..f6627759af 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -461,11 +461,11 @@ static bool isKnownCommand(char command) { } // this function runs indefinitely -void runBinaryProtocolLoop(ts_channel_s *tsChannel, bool isConsoleRedirect) { +void runBinaryProtocolLoop(ts_channel_s *tsChannel) { int wasReady = false; while (true) { - int isReady = sr5IsReady(isConsoleRedirect); + int isReady = sr5IsReady(tsChannel); if (!isReady) { chThdSleepMilliseconds(10); wasReady = false; @@ -586,7 +586,7 @@ static THD_FUNCTION(tsThreadEntryPoint, arg) { startTsPort(&tsChannel); - runBinaryProtocolLoop(&tsChannel, false); + runBinaryProtocolLoop(&tsChannel); } void syncTunerStudioCopy(void) { diff --git a/firmware/console/binary/tunerstudio.h b/firmware/console/binary/tunerstudio.h index c269573cc2..5a7bb2477a 100644 --- a/firmware/console/binary/tunerstudio.h +++ b/firmware/console/binary/tunerstudio.h @@ -66,7 +66,7 @@ void requestBurn(void); void startTunerStudioConnectivity(void); void syncTunerStudioCopy(void); -void runBinaryProtocolLoop(ts_channel_s *tsChannel, bool isConsoleRedirect); +void runBinaryProtocolLoop(ts_channel_s *tsChannel); #if defined __GNUC__ // GCC diff --git a/firmware/console/binary/tunerstudio_io.cpp b/firmware/console/binary/tunerstudio_io.cpp index 6b7a72c2ee..fc62f56809 100644 --- a/firmware/console/binary/tunerstudio_io.cpp +++ b/firmware/console/binary/tunerstudio_io.cpp @@ -23,8 +23,7 @@ extern LoggingWithStorage tsLogger; #if HAL_USE_SERIAL_USB || defined(__DOXYGEN__) extern SerialUSBDriver SDU1; -#define CONSOLE_USB_DEVICE &SDU1 -#endif +#endif /* HAL_USE_SERIAL_USB */ #if TS_UART_DMA_MODE // Async. FIFO buffer takes some RAM... @@ -85,14 +84,14 @@ static SerialConfig tsSerialConfig = { 0, 0, USART_CR2_STOP1_BITS | USART_CR2_LI void startTsPort(ts_channel_s *tsChannel) { #if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_USB_SERIAL || defined(__DOXYGEN__) - if (isCommandLineConsoleOverTTL()) { + if (true) { print("TunerStudio over USB serial"); /** * This method contains a long delay, that's the reason why this is not done on the main thread */ usb_serial_start(); // if console uses UART then TS uses USB - tsChannel->channel = (BaseChannel *) CONSOLE_USB_DEVICE; + tsChannel->channel = (BaseChannel *) &CONSOLE_USB_DEVICE; } else #endif { @@ -138,7 +137,7 @@ void startTsPort(ts_channel_s *tsChannel) { bool stopTsPort(ts_channel_s *tsChannel) { #if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_USB_SERIAL || defined(__DOXYGEN__) - if (isCommandLineConsoleOverTTL()) { + if (true) { #if 0 usb_serial_stop(); #endif @@ -257,17 +256,13 @@ void sr5SendResponse(ts_channel_s *tsChannel, ts_response_format_e mode, const u } } -bool sr5IsReady(bool isConsoleRedirect) { -#if EFI_PROD_CODE || defined(__DOXYGEN__) - if (isCommandLineConsoleOverTTL() ^ isConsoleRedirect) { +bool sr5IsReady(ts_channel_s *tsChannel) { +#if EFI_USB_SERIAL || defined(__DOXYGEN__) + if (isUsbSerial(tsChannel->channel)) { // TS uses USB when console uses serial return is_usb_serial_ready(); - } else { - // TS uses serial when console uses USB - return true; } -#else +#endif /* EFI_USB_SERIAL */ return true; -#endif } diff --git a/firmware/console/binary/tunerstudio_io.h b/firmware/console/binary/tunerstudio_io.h index 0a5b6ecd82..263f67290c 100644 --- a/firmware/console/binary/tunerstudio_io.h +++ b/firmware/console/binary/tunerstudio_io.h @@ -85,6 +85,9 @@ typedef struct { // todo: double-check this #define CRC_WRAPPING_SIZE (CRC_VALUE_SIZE + 3) +#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__) +#define CONSOLE_USB_DEVICE SDU1 +#endif /* HAL_USE_SERIAL_USB */ void startTsPort(ts_channel_s *tsChannel); bool stopTsPort(ts_channel_s *tsChannel); @@ -100,6 +103,6 @@ void sr5WriteCrcPacket(ts_channel_s *tsChannel, const uint8_t responseCode, cons void sr5SendResponse(ts_channel_s *tsChannel, ts_response_format_e mode, const uint8_t * buffer, int size); int sr5ReadData(ts_channel_s *tsChannel, uint8_t * buffer, int size); int sr5ReadDataTimeout(ts_channel_s *tsChannel, uint8_t * buffer, int size, int timeout); -bool sr5IsReady(bool isConsoleRedirect); +bool sr5IsReady(ts_channel_s *tsChannel); #endif /* CONSOLE_TUNERSTUDIO_TUNERSTUDIO_IO_H_ */ diff --git a/firmware/console/console_io.cpp b/firmware/console/console_io.cpp index 6f9ec2f851..223ba6a719 100644 --- a/firmware/console/console_io.cpp +++ b/firmware/console/console_io.cpp @@ -132,23 +132,27 @@ static bool getConsoleLine(BaseSequentialStream *chp, char *line, unsigned size) CommandHandler console_line_callback; -bool isCommandLineConsoleOverTTL(void) { - return true; -} - #if (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR ) || defined(__DOXYGEN__) static SerialConfig serialConfig = { 0, 0, USART_CR2_STOP1_BITS | USART_CR2_LINEN, 0 }; #endif #if EFI_PROD_CODE || EFI_EGT || defined(__DOXYGEN__) +bool isUsbSerial(BaseChannel * channel) { +#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__) + return channel == (BaseChannel *) &CONSOLE_USB_DEVICE; +#else + return false; +#endif +} + BaseChannel * getConsoleChannel(void) { #if defined(EFI_CONSOLE_UART_DEVICE) || defined(__DOXYGEN__) return (BaseChannel *) EFI_CONSOLE_UART_DEVICE; #endif /* EFI_CONSOLE_UART_DEVICE */ #if HAL_USE_SERIAL_USB || defined(__DOXYGEN__) - return (BaseChannel *) &SDU1; + return (BaseChannel *) &CONSOLE_USB_DEVICE; #else return NULL; #endif /* HAL_USE_SERIAL_USB */ @@ -168,20 +172,10 @@ static THD_FUNCTION(consoleThreadThreadEntryPoint, arg) { (void) arg; chRegSetThreadName("console thread"); -#if (EFI_PROD_CODE && EFI_USB_SERIAL) || defined(__DOXYGEN__) - if (!isCommandLineConsoleOverTTL()) { - /** - * This method contains a long delay, that's the reason why this is not done on the main thread - */ - usb_serial_start(); - } -#endif /* EFI_PROD_CODE */ - - binaryConsole.channel = (BaseChannel *) getConsoleChannel(); if (binaryConsole.channel != NULL) { #if EFI_TUNER_STUDIO || defined(__DOXYGEN__) - runBinaryProtocolLoop(&binaryConsole, true); + runBinaryProtocolLoop(&binaryConsole); #endif /* EFI_TUNER_STUDIO */ } } @@ -211,8 +205,6 @@ void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p) console_line_callback = console_line_callback_p; #if (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR) || defined(__DOXYGEN__) - - if (isCommandLineConsoleOverTTL()) { /* * Activates the serial * it is important to set 'NONE' as flow control! in terminal application on the PC @@ -227,7 +219,6 @@ void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p) isSerialConsoleStarted = true; chEvtRegisterMask((event_source_t *) chnGetEventSource(EFI_CONSOLE_UART_DEVICE), &consoleEventListener, 1); - } #endif /* EFI_PROD_CODE */ #if !defined(EFI_CONSOLE_NO_THREAD) || defined(__DOXYGEN__) diff --git a/firmware/console/console_io.h b/firmware/console/console_io.h index 2a203430b9..f3dcaf6ecc 100644 --- a/firmware/console/console_io.h +++ b/firmware/console/console_io.h @@ -32,8 +32,8 @@ BaseChannel * getConsoleChannel(void); void consolePutChar(int x); void consoleOutputBuffer(const uint8_t *buf, int size); void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p); -bool isCommandLineConsoleOverTTL(void); void onDataArrived(void); +bool isUsbSerial(BaseChannel * channel); #if EFI_PROD_CODE || EFI_SIMULATOR || EFI_EGT bool isCommandLineConsoleReady(void); diff --git a/simulator/simulator/efifeatures.h b/simulator/simulator/efifeatures.h index 0668e3243e..8727fc4977 100644 --- a/simulator/simulator/efifeatures.h +++ b/simulator/simulator/efifeatures.h @@ -24,6 +24,8 @@ #define TS_UART_MODE FALSE +#define EFI_USB_SERIAL FALSE + #define EFI_CDM_INTEGRATION FALSE #define EFI_BLUETOOTH_SETUP FALSE