A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol
C arduinobluetoothcan-busdebuggingeepromesp32flipperzerogpiohardware-hackingi2cjtagopenocdprotocolspwmradiorfidspisubghzuartwifi
fix conflict between uart and hduart
Geof802daaab637
diff --git a/src/Controllers/HdUartController.cpp b/src/Controllers/HdUartController.cppindex 85132c52..55963078 100644--- a/src/Controllers/HdUartController.cpp+++ b/src/Controllers/HdUartController.cpp@@ -4,9 +4,9 @@Constructor*/HdUartController::HdUartController(ITerminalView& terminalView, IInput& terminalInput, IInput& deviceInput,- HdUartService& hdUartService, ArgTransformer& argTransformer, UserInputManager& userInputManager)+ HdUartService& hdUartService, UartService& uartService, ArgTransformer& argTransformer, UserInputManager& userInputManager): terminalView(terminalView), terminalInput(terminalInput), deviceInput(deviceInput),- hdUartService(hdUartService), argTransformer(argTransformer), userInputManager(userInputManager) {}+ hdUartService(hdUartService), uartService(uartService), argTransformer(argTransformer), userInputManager(userInputManager) {}/*Entry point for HDUART commands@@ -104,9 +104,12 @@ void HdUartController::handleHelp() {" config Set TX/RX pin, baud etc.\n");}+/*+Ensure Configuration+*/void HdUartController::ensureConfigured() {- if (!configured) {+ uartService.end();+ if (!hdUartService.getConfigured()) {handleConfig();- configured = true;}-}+}\ No newline at end of filediff --git a/src/Controllers/HdUartController.h b/src/Controllers/HdUartController.hindex bde47c97..a06fd613 100644--- a/src/Controllers/HdUartController.h+++ b/src/Controllers/HdUartController.h@@ -5,6 +5,7 @@#include "Models/ByteCode.h"#include "Models/TerminalCommand.h"#include "Services/HdUartService.h"+#include "Services/UartService.h"#include "Transformers/ArgTransformer.h"#include "States/GlobalState.h"#include "Managers/UserInputManager.h"@@ -12,7 +13,7 @@class HdUartController {public:HdUartController(ITerminalView& terminalView, IInput& terminalInput, IInput& deviceInput,- HdUartService& hdUartService, ArgTransformer& argTransformer, UserInputManager& userInputManager);+ HdUartService& hdUartService, UartService& uartService, ArgTransformer& argTransformer, UserInputManager& userInputManager);// Entry point for HDUART commandvoid handleCommand(const TerminalCommand& cmd);@@ -28,18 +29,17 @@ private:IInput& terminalInput;IInput& deviceInput;HdUartService& hdUartService;+ UartService& uartService;ArgTransformer& argTransformer;UserInputManager& userInputManager;GlobalState& state = GlobalState::getInstance();-- bool configured = false;-+// HDUART Bridge mode read/write on one linevoid handleBridge();// Configure HDUARTvoid handleConfig();- // HDURT Available commands+ // Show HDUART Available commandsvoid handleHelp();};diff --git a/src/Controllers/UartController.cpp b/src/Controllers/UartController.cppindex ff68b952..9f12e29a 100644--- a/src/Controllers/UartController.cpp+++ b/src/Controllers/UartController.cpp@@ -4,8 +4,8 @@Constructor*/UartController::UartController(ITerminalView& terminalView, IInput& terminalInput, IInput& deviceInput,- UartService& uartService, ArgTransformer& argTransformer, UserInputManager& userInputManager)- : terminalView(terminalView), terminalInput(terminalInput), deviceInput(deviceInput), uartService(uartService), argTransformer(argTransformer), userInputManager(userInputManager) {}+ UartService& uartService, HdUartService& hDUartService, ArgTransformer& argTransformer, UserInputManager& userInputManager)+ : terminalView(terminalView), terminalInput(terminalInput), deviceInput(deviceInput), uartService(uartService), hdUartService(hdUartService), argTransformer(argTransformer), userInputManager(userInputManager) {}/*@@ -363,8 +363,8 @@ void UartController::handleGlitch() {Ensure Config*/void UartController::ensureConfigured() {- if (!configured) {+ // hdUartService.end(); // it crashes the app for some reasons+ if (!uartService.getConfigured()) {handleConfig();- configured = true;}}\ No newline at end of filediff --git a/src/Controllers/UartController.h b/src/Controllers/UartController.hindex b7ec61e4..a764c86c 100644--- a/src/Controllers/UartController.h+++ b/src/Controllers/UartController.h@@ -6,6 +6,7 @@#include "Models/TerminalCommand.h"#include "Models/ByteCode.h"#include "Services/UartService.h"+#include "Services/HdUartService.h"#include "Interfaces/ITerminalView.h"#include "Interfaces/IInput.h"#include "States/GlobalState.h"@@ -19,6 +20,7 @@ public:IInput& terminalInput,IInput& deviceInput,UartService& uartService,+ HdUartService& hdUartService,ArgTransformer& argTransformer,UserInputManager& userInputManager);@@ -78,10 +80,10 @@ public:IInput& terminalInput;IInput& deviceInput;UartService& uartService;+ HdUartService& hdUartService;ArgTransformer& argTransformer;UserInputManager& userInputManager;GlobalState& state = GlobalState::getInstance();- bool configured = false;bool scanCancelled = false;// Predefined probe commands for scan()diff --git a/src/Providers/DependencyProvider.cpp b/src/Providers/DependencyProvider.cppindex c686337e..74613d36 100644--- a/src/Providers/DependencyProvider.cpp+++ b/src/Providers/DependencyProvider.cpp@@ -28,12 +28,12 @@ DependencyProvider::DependencyProvider(ITerminalView& terminalView, IDeviceView&userInputManager(terminalView, terminalInput, argTransformer),horizontalSelector(deviceView, deviceInput),terminalTypeConfigurator(horizontalSelector),- uartController(terminalView, terminalInput, deviceInput, uartService, argTransformer, userInputManager),+ uartController(terminalView, terminalInput, deviceInput, uartService, hdUartService, argTransformer, userInputManager),i2cController(terminalView, terminalInput, i2cService, argTransformer, userInputManager),oneWireController(terminalView, terminalInput, oneWireService, argTransformer, userInputManager),infraredController(terminalView, terminalInput, infraredService, argTransformer, userInputManager),utilityController(terminalView, terminalInput, pinService, userInputManager),- hdUartController(terminalView, terminalInput, deviceInput, hdUartService, argTransformer, userInputManager),+ hdUartController(terminalView, terminalInput, deviceInput, hdUartService, uartService, argTransformer, userInputManager),spiController(terminalView, terminalInput, spiService, argTransformer, userInputManager),jtagController(terminalView, terminalInput),twoWireController(terminalView, terminalInput),diff --git a/src/Services/HdUartService.cpp b/src/Services/HdUartService.cppindex 659ca49d..3ab88943 100644--- a/src/Services/HdUartService.cpp+++ b/src/Services/HdUartService.cpp@@ -28,6 +28,18 @@ void HdUartService::configure(unsigned long baud, uint8_t dataBits, char parity,// Route UART signals to shared pinesp_rom_gpio_connect_out_signal(ioPin, UART_PERIPH_SIGNAL(HD_UART_PORT, SOC_UART_TX_PIN_IDX), false, false);esp_rom_gpio_connect_in_signal(ioPin, UART_PERIPH_SIGNAL(HD_UART_PORT, SOC_UART_RX_PIN_IDX), false);+ hdUartConfigured = true;+}++void HdUartService::end() {+ if (hdUartConfigured) {+ uart_driver_delete(HD_UART_PORT);+ hdUartConfigured = false;+ }+}++bool HdUartService::getConfigured() {+ return hdUartConfigured;}void HdUartService::write(uint8_t data) {diff --git a/src/Services/HdUartService.h b/src/Services/HdUartService.hindex 52cdfe59..ca696976 100644--- a/src/Services/HdUartService.h+++ b/src/Services/HdUartService.h@@ -9,7 +9,7 @@#include "soc/uart_periph.h"#include "Models/ByteCode.h"-#define HD_UART_PORT UART_NUM_1+#define HD_UART_PORT UART_NUM_2#define UART_RX_BUFFER_SIZE 256class HdUartService {@@ -23,11 +23,14 @@ public:std::string executeByteCode(const std::vector<ByteCode>& bytecodes);void flush();uart_config_t buildUartConfig(unsigned long baud, uint8_t bits, char parity, uint8_t stop);+ void end();+ bool getConfigured();private:uint8_t ioPin;unsigned long baudRate;uint32_t serialConfig;bool isInverted;+ bool hdUartConfigured = false;};diff --git a/src/Services/UartService.cpp b/src/Services/UartService.cppindex 707c73a9..303b7d4a 100644--- a/src/Services/UartService.cpp+++ b/src/Services/UartService.cpp@@ -3,6 +3,17 @@void UartService::configure(unsigned long baud, uint32_t config, uint8_t rx, uint8_t tx, bool inverted) {Serial1.end(); // stop before reconfigureSerial1.begin(baud, config, rx, tx, inverted);+ uartConfigured = true;+}++void UartService::end() {+ if (!uartConfigured) return;+ Serial1.end();+ uartConfigured = false;+}++bool UartService::getConfigured() {+ return uartConfigured;}std::string UartService::readLine() {diff --git a/src/Services/UartService.h b/src/Services/UartService.hindex df09126e..400e6baf 100644--- a/src/Services/UartService.h+++ b/src/Services/UartService.h@@ -1,8 +1,15 @@#pragma once#include <string>#include <vector>-#include "Models/ByteCode.h"#include "Arduino.h"+#include "driver/uart.h"+#include "driver/gpio.h"+#include "esp_rom_gpio.h"+#include "hal/uart_types.h"+#include "soc/uart_periph.h"+#include "Models/ByteCode.h"++#define UART_PORT UART_NUM_1class UartService {public:@@ -18,5 +25,9 @@ public:void switchBaudrate(unsigned long newBaud);void flush();void clearUartBuffer();+ void end();+ bool getConfigured();uint32_t buildUartConfig(uint8_t dataBits, char parity, uint8_t stopBits);+private:+ bool uartConfigured = false;};