Skip to content

A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol

ensure reconfiguring pins before any use, to be able to switch mode without conflicts

Geod66a989c73f1
diff --git a/platformio.ini b/platformio.ini
index 0328f313..e9b3db61 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -87,8 +87,8 @@ build_flags =
; --- UART ---
-DUART_BAUD=9600
- -DUART_RX_PIN=0
- -DUART_TX_PIN=25
+ -DUART_RX_PIN=33
+ -DUART_TX_PIN=32
; --- HDUART ---
-DHDUART_BAUD=9600
diff --git a/src/Controllers/HdUartController.cpp b/src/Controllers/HdUartController.cpp
index 55963078..5abf6822 100644
--- a/src/Controllers/HdUartController.cpp
+++ b/src/Controllers/HdUartController.cpp
@@ -109,7 +109,25 @@ Ensure Configuration
*/
void HdUartController::ensureConfigured() {
uartService.end();
- if (!hdUartService.getConfigured()) {
+
+ if (!configured) {
handleConfig();
+ configured = true;
+ return;
}
+
+ hdUartService.end();
+
+ // User could have set the same pin to a different usage
+ // eg. select UART, then select I2C, then select UART
+ // Always reconfigure pins before use
+ auto rx = state.getHdUartPin();
+ auto parityStr = state.getHdUartParity();
+ auto baud = state.getHdUartBaudRate();
+ auto dataBits = state.getHdUartDataBits();
+ auto stopBits = state.getHdUartStopBits();
+ bool inverted = state.isHdUartInverted();
+ char parity = !parityStr.empty() ? parityStr[0] : 'N';
+
+ hdUartService.configure(baud, dataBits, parity, stopBits, rx, inverted);
}
\ No newline at end of file
diff --git a/src/Controllers/HdUartController.h b/src/Controllers/HdUartController.h
index a06fd613..732abd45 100644
--- a/src/Controllers/HdUartController.h
+++ b/src/Controllers/HdUartController.h
@@ -33,7 +33,9 @@ private:
ArgTransformer& argTransformer;
UserInputManager& userInputManager;
GlobalState& state = GlobalState::getInstance();
-
+
+ bool configured = false;
+
// HDUART Bridge mode read/write on one line
void handleBridge();
diff --git a/src/Controllers/I2cController.cpp b/src/Controllers/I2cController.cpp
index 72b0dc29..e363a3a2 100644
--- a/src/Controllers/I2cController.cpp
+++ b/src/Controllers/I2cController.cpp
@@ -87,6 +87,10 @@ void I2cController::handleSniff() {
i2c_sniffer_begin(state.getI2cSclPin(), state.getI2cSdaPin()); // dont need freq to work
i2c_sniffer_setup();
+ terminalView.println(" [INFO] I2C sniffer mode is experimental.");
+ terminalView.println(" It may crash or freeze the firmware");
+ terminalView.println(" if the data stream is too fast or continuous.\n");
+
std::string line;
while (true) {
@@ -284,13 +288,15 @@ void I2cController::ensureConfigured() {
if (!configured) {
handleConfig();
configured = true;
- } else {
- // Reset I2C
- i2cService.end();
- uint8_t sda = state.getI2cSdaPin();
- uint8_t scl = state.getI2cSclPin();
- uint32_t freq = state.getI2cFrequency();
- i2cService.configure(sda, scl, freq);
-
+ return;
}
+
+ // User could have set the same pin to a different usage
+ // eg. select I2C then select UART then select I2C
+ // Always reconfigure pins before use
+ i2cService.end();
+ uint8_t sda = state.getI2cSdaPin();
+ uint8_t scl = state.getI2cSclPin();
+ uint32_t freq = state.getI2cFrequency();
+ i2cService.configure(sda, scl, freq);
}
\ No newline at end of file
diff --git a/src/Controllers/InfraredController.cpp b/src/Controllers/InfraredController.cpp
index 12bc0e37..d1321a1e 100644
--- a/src/Controllers/InfraredController.cpp
+++ b/src/Controllers/InfraredController.cpp
@@ -221,5 +221,11 @@ void InfraredController::ensureConfigured() {
if (!configured) {
handleConfig();
configured = true;
+ return;
}
+
+ // Always reconfigure before use
+ uint8_t tx = state.getInfraredTxPin();
+ uint8_t rx = state.getInfraredRxPin();
+ infraredService.configure(tx, rx);
}
\ No newline at end of file
diff --git a/src/Controllers/JtagController.cpp b/src/Controllers/JtagController.cpp
index 22528aed..2e52ebb0 100644
--- a/src/Controllers/JtagController.cpp
+++ b/src/Controllers/JtagController.cpp
@@ -30,7 +30,7 @@ void JtagController::handleScan() {
Config
*/
void JtagController::handleConfig() {
- terminalView.println(" [Info] This mode is not implemented yet.");
+ terminalView.println(" [INFO] This mode is not implemented yet.");
terminalView.println(" Support is planned for a future release.\n");
}
diff --git a/src/Controllers/LedController.cpp b/src/Controllers/LedController.cpp
index f2075a48..fd2b0851 100644
--- a/src/Controllers/LedController.cpp
+++ b/src/Controllers/LedController.cpp
@@ -33,7 +33,7 @@ void LedController::handleInstruction(const std::vector<ByteCode>& bytecodes) {
Config
*/
void LedController::handleConfig() {
- terminalView.println(" [Info] This mode is not implemented yet.");
+ terminalView.println(" [INFO] This mode is not implemented yet.");
terminalView.println(" Support is planned for a future release.\n");
}
diff --git a/src/Controllers/OneWireController.cpp b/src/Controllers/OneWireController.cpp
index a4387737..2b97c38d 100644
--- a/src/Controllers/OneWireController.cpp
+++ b/src/Controllers/OneWireController.cpp
@@ -365,7 +365,7 @@ Sniff
void OneWireController::handleSniff() {
terminalView.println("OneWire Sniff: Oberserving data line... Press [ENTER] to stop.\n");
- terminalView.println(" [Info] This feature uses very fast timing.");
+ terminalView.println(" [INFO] This feature uses very fast timing.");
terminalView.println(" The Web CLI may miss some signals,");
terminalView.println(" use Serial CLI for best results.\n");
@@ -453,5 +453,9 @@ void OneWireController::ensureConfigured() {
if (!configured) {
handleConfig();
configured = true;
+ return;
}
+
+ uint8_t pin = state.getOneWirePin();
+ oneWireService.configure(pin);
}
\ No newline at end of file
diff --git a/src/Controllers/SpiController.cpp b/src/Controllers/SpiController.cpp
index bfc89695..46a4a797 100644
--- a/src/Controllers/SpiController.cpp
+++ b/src/Controllers/SpiController.cpp
@@ -92,7 +92,7 @@ void SpiController::handleFlashErase() {
Config
*/
void SpiController::handleConfig() {
- terminalView.println(" [Info] This mode is not implemented yet.");
+ terminalView.println(" [INFO] This mode is not implemented yet.");
terminalView.println(" Support is planned for a future release.\n");
}
diff --git a/src/Controllers/ThreeWireController.cpp b/src/Controllers/ThreeWireController.cpp
index 5ae93082..a2c13687 100644
--- a/src/Controllers/ThreeWireController.cpp
+++ b/src/Controllers/ThreeWireController.cpp
@@ -31,7 +31,7 @@ void ThreeWireController::handleInstruction(const std::vector<ByteCode>& bytecod
Config
*/
void ThreeWireController::handleConfig() {
- terminalView.println(" [Info] This mode is not implemented yet.");
+ terminalView.println(" [INFO] This mode is not implemented yet.");
terminalView.println(" Support is planned for a future release.\n");
}
diff --git a/src/Controllers/TwoWireController.cpp b/src/Controllers/TwoWireController.cpp
index 351d57c4..37d60141 100644
--- a/src/Controllers/TwoWireController.cpp
+++ b/src/Controllers/TwoWireController.cpp
@@ -46,7 +46,7 @@ void TwoWireController::handleSniff() {
Config
*/
void TwoWireController::handleConfig() {
- terminalView.println(" [Info] This mode is not implemented yet.");
+ terminalView.println(" [INFO] This mode is not implemented yet.");
terminalView.println(" Support is planned for a future release.\n");
}
diff --git a/src/Controllers/UartController.cpp b/src/Controllers/UartController.cpp
index 9f12e29a..4c8de0de 100644
--- a/src/Controllers/UartController.cpp
+++ b/src/Controllers/UartController.cpp
@@ -363,8 +363,24 @@ void UartController::handleGlitch() {
Ensure Config
*/
void UartController::ensureConfigured() {
- // hdUartService.end(); // it crashes the app for some reasons
- if (!uartService.getConfigured()) {
+ // hdUartService.end() // It crashed the app for some reasons, not rly needed
+
+ if (!configured) {
handleConfig();
+ configured = true;
+ return;
}
+
+ // User could have set the same pin to a different usage
+ // eg. select UART, then select I2C, then select UART
+ // Always reconfigure pins before use
+ uartService.end();
+
+ uint8_t rx = state.getUartRxPin();
+ uint8_t tx = state.getUartTxPin();
+ uint32_t baud = state.getUartBaudRate();
+ uint32_t config = state.getUartConfig();
+ bool inverted = state.isUartInverted();
+
+ uartService.configure(baud, config, rx, tx, inverted);
}
\ No newline at end of file
diff --git a/src/Controllers/UartController.h b/src/Controllers/UartController.h
index a764c86c..001b901e 100644
--- a/src/Controllers/UartController.h
+++ b/src/Controllers/UartController.h
@@ -84,6 +84,7 @@ public:
ArgTransformer& argTransformer;
UserInputManager& userInputManager;
GlobalState& state = GlobalState::getInstance();
+ bool configured = false;
bool scanCancelled = false;
// Predefined probe commands for scan()
diff --git a/src/Services/HdUartService.cpp b/src/Services/HdUartService.cpp
index 3ab88943..0762a581 100644
--- a/src/Services/HdUartService.cpp
+++ b/src/Services/HdUartService.cpp
@@ -28,19 +28,12 @@ void HdUartService::configure(unsigned long baud, uint8_t dataBits, char parity,
// Route UART signals to shared pin
esp_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;
- }
+ uart_driver_delete(HD_UART_PORT);
}
-bool HdUartService::getConfigured() {
- return hdUartConfigured;
-}
void HdUartService::write(uint8_t data) {
uart_write_bytes(HD_UART_PORT, &data, 1);
diff --git a/src/Services/HdUartService.h b/src/Services/HdUartService.h
index ca696976..5e145c5d 100644
--- a/src/Services/HdUartService.h
+++ b/src/Services/HdUartService.h
@@ -24,13 +24,11 @@ public:
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.cpp
index 303b7d4a..7499834b 100644
--- a/src/Services/UartService.cpp
+++ b/src/Services/UartService.cpp
@@ -3,17 +3,10 @@
void UartService::configure(unsigned long baud, uint32_t config, uint8_t rx, uint8_t tx, bool inverted) {
Serial1.end(); // stop before reconfigure
Serial1.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.h
index 400e6baf..9b2dc2b9 100644
--- a/src/Services/UartService.h
+++ b/src/Services/UartService.h
@@ -26,8 +26,5 @@ public:
void flush();
void clearUartBuffer();
void end();
- bool getConfigured();
uint32_t buildUartConfig(uint8_t dataBits, char parity, uint8_t stopBits);
-private:
- bool uartConfigured = false;
};
diff --git a/src/States/GlobalState.h b/src/States/GlobalState.h
index 1706d617..e73fbf4b 100644
--- a/src/States/GlobalState.h
+++ b/src/States/GlobalState.h
@@ -62,7 +62,7 @@ private:
bool hdUartInverted = false;
uint8_t hdUartPin = 1;
uint8_t hdUartDataBits = 8;
- std::string hdUartParity = "None";
+ std::string hdUartParity = "N";
bool hdUartFlowControl = false;
uint8_t hdUartStopBits = 1;