A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol
C arduinobluetoothcan-busdebuggingeepromesp32flipperzerogpiohardware-hackingi2cjtagopenocdprotocolspwmradiorfidspisubghzuartwifi
Added an "analogic" command
fdufnews235687799190
diff --git a/src/Controllers/SubGhzController.cpp b/src/Controllers/SubGhzController.cppindex 1d741471..8cb55aa3 100644--- a/src/Controllers/SubGhzController.cpp+++ b/src/Controllers/SubGhzController.cpp@@ -464,7 +464,7 @@ void SubGhzController::handleTrace() {// Renderif (buffer.size() >= 240) {buffer.resize(240);- deviceView.drawLogicTrace(gdo, buffer);+ deviceView.drawLogicTrace(gdo, buffer, 1);buffer.clear();}diff --git a/src/Controllers/UtilityController.cpp b/src/Controllers/UtilityController.cppindex 48dcd7bd..827181cc 100644--- a/src/Controllers/UtilityController.cpp+++ b/src/Controllers/UtilityController.cpp@@ -29,6 +29,7 @@ void UtilityController::handleCommand(const TerminalCommand& cmd) {else if (cmd.getRoot() == "P") handleEnablePullups();else if (cmd.getRoot() == "p") handleDisablePullups();else if (cmd.getRoot() == "logic") handleLogicAnalyzer(cmd);+ else if (cmd.getRoot() == "analogic") handleAnalogic(cmd);else if (cmd.getRoot() == "system") handleSystem();else {terminalView.println("Unknown command. Try 'help'.");@@ -207,6 +208,11 @@ void UtilityController::handleEnablePullups() {Logic*/void UtilityController::handleLogicAnalyzer(const TerminalCommand& cmd) {++ uint16_t tDelay = 500;+ uint16_t inc = 100; // tDelay will be decremented/incremented by inc+ uint8_t step = 1; // step of the trace display kind of a zoom+if (cmd.getSubcommand().empty() || !argTransformer.isValidNumber(cmd.getSubcommand())) {terminalView.println("Usage: logic <pin>");return;@@ -214,19 +220,24 @@ void UtilityController::handleLogicAnalyzer(const TerminalCommand& cmd) {// Verify protected pinuint8_t pin = argTransformer.toUint8(cmd.getSubcommand());+ /*auto forbidden = state.getProtectedPins();if (std::find(forbidden.begin(), forbidden.end(), pin) != forbidden.end()) {terminalView.println("Logic Analyzer: This pin is protected or reserved.");return;}-+*/+ if (state.isPinProtected(pin)) {+ terminalView.println("Logic Analyzer: This pin is protected or reserved.");+ return;+ }terminalView.println("\nLogic Analyzer: Monitoring pin " + std::to_string(pin) + "... Press [ENTER] to stop.");terminalView.println("Displaying waveform on the ESP32 screen...\n");pinService.setInput(pin);std::vector<uint8_t> buffer;- buffer.reserve(240); // 240 samples+ buffer.reserve(320); // 320 samplesunsigned long lastCheck = millis();deviceView.clear();@@ -244,32 +255,147 @@ void UtilityController::handleLogicAnalyzer(const TerminalCommand& cmd) {terminalView.println("Logic Analyzer: Stopped by user.");break;}+ if (c == 's'){+ if (tDelay > inc){+ tDelay -= inc;+ terminalView.println("delay : " + std::to_string(tDelay) + "\n");+ }+ };+ if (c == 'S'){+ if (tDelay < 10000){+ tDelay += inc;+ terminalView.println("delay : " + std::to_string(tDelay) + "\n");+ }+ };+ if (c == 'z'){+ if (step > 1){+ step--;+ terminalView.println("step : " + std::to_string(step) + "\n");+ }+ };+ if (c == 'Z'){+ if (step < 4){+ step++;+ terminalView.println("step : " + std::to_string(step) + "\n");+ }+ };}// Draw- if (buffer.size() >= 240) {- buffer.resize(240);- deviceView.drawLogicTrace(pin, buffer);+ if (buffer.size() >= 320) {+ buffer.resize(320);+ deviceView.drawLogicTrace(pin, buffer, step);- // fdufnews 2025/10/24 added a poor man's drawLogicTrace() on terminal- // draw logic trace on 3 consecutive lines in order to be compatible with small 80x25 terminal window+ // The poor man's drawLogicTrace() on terminal+ // draws a 132 samples sub part of the buffer to speed up the thingsif (state.getTerminalMode() == TerminalTypeEnum::Serial){terminalView.println("Logic trace");uint8_t pos = 0;- for(size_t i = 0; i < buffer.size(); i++, pos++){- if(pos > 79){- pos = 0;- terminalView.println("");- }- terminalView.print(buffer[i]?"-":"_");+ for(size_t i = 0; i < 132; i++, pos++){+ terminalView.print(buffer[i]?"-":"_");}- terminalView.print("\r\x1b[3A"); // Up 3 lines to put cursor at the correct place for the next draw+ terminalView.print("\r\x1b[A"); // Up 1 line to put cursor at the correct place for the next draw}buffer.clear();}buffer.push_back(pinService.read(pin));- delayMicroseconds(500);+ delayMicroseconds(tDelay);+ }+}++/*+Analogic+*/+void UtilityController::handleAnalogic(const TerminalCommand& cmd) {+ uint16_t tDelay = 500;+ uint16_t inc = 100; // tDelay will be decremented/incremented by inc+ uint8_t step = 1; // step of the trace display kind of a zoom++ if (cmd.getSubcommand().empty() || !argTransformer.isValidNumber(cmd.getSubcommand())) {+ terminalView.println("Usage: analogic <pin>");+ return;+ }++ // Verify protected pin+ uint8_t pin = argTransformer.toUint8(cmd.getSubcommand());+ if (state.isPinProtected(pin)) {+ terminalView.println("Logic Analyzer: This pin is protected or reserved.");+ return;+ }+ if (!state.isPinAnalog(pin)){+ terminalView.println("Logic Analyzer: This pin is not an analog one");+ return;+ };++ terminalView.println("\nAnalog plotter: Monitoring pin " + std::to_string(pin) + "... Press [ENTER] to stop.");+ terminalView.println("Displaying waveform on the ESP32 screen...\n");+++ pinService.setInput(pin);+ std::vector<uint8_t> buffer;+ buffer.reserve(320); // 320 samples++ unsigned long lastCheck = millis();+ deviceView.clear();+ deviceView.topBar("Analog plotter", false, false);+ int count = 0;+ while (true) {+ // Enter press+ if (millis() - lastCheck > 10) {+ lastCheck = millis();+ char c = terminalInput.readChar();+ if (c == '\r' || c == '\n') {+ terminalView.println("Analog plotter: Stopped by user.");+ break;+ }+ if (c == 's'){+ if (tDelay > inc){+ tDelay -= inc;+ terminalView.println("\ndelay : " + std::to_string(tDelay) + "\n");+ }+ };+ if (c == 'S'){+ if (tDelay < 10000){+ tDelay += inc;+ terminalView.println("\ndelay : " + std::to_string(tDelay) + "\n");+ }+ };+ if (c == 'z'){+ if (step > 1){+ step--;+ terminalView.println("\nstep : " + std::to_string(step) + "\n");+ }+ };+ if (c == 'Z'){+ if (step < 4){+ step++;+ terminalView.println("\nstep : " + std::to_string(step) + "\n");+ }+ };+ count++;+ if (count > 50){+ int raw = pinService.readAnalog(pin);+ float voltage = (raw / 4095.0f) * 3.3f;++ std::ostringstream oss;+ oss << " Analog pin " << static_cast<int>(pin)+ << ": " << raw+ << " (" << voltage << " V)";+ terminalView.println(oss.str());+ count = 0;+ }+ }++ // Draw+ if (buffer.size() >= 320) {+ buffer.resize(320);+ deviceView.drawAnalogicTrace(pin, buffer, step);+ buffer.clear();+ }++ buffer.push_back(pinService.readAnalog(pin) >> 4); // convert the readAnalog() value to a uint8_t (4096 ==> 256)+ delayMicroseconds(tDelay);}}@@ -293,6 +419,7 @@ void UtilityController::handleHelp() {terminalView.println(" system - Show system infos");terminalView.println(" mode <name> - Set active mode");terminalView.println(" logic <pin> - Logic analyzer");+ terminalView.println(" analogic <pin> - Analogic plotter");terminalView.println(" P - Enable pull-up");terminalView.println(" p - Disable pull-up");@@ -554,6 +681,6 @@ bool UtilityController::isGlobalCommand(const TerminalCommand& cmd) {}return (root == "mode" || root == "m" || root == "l" ||- root == "logic" || root == "P" || root == "p") ||+ root == "logic" || root == "analogic" || root == "P" || root == "p") ||root == "system";}diff --git a/src/Controllers/UtilityController.h b/src/Controllers/UtilityController.hindex 7b599181..8d8c42d5 100644--- a/src/Controllers/UtilityController.h+++ b/src/Controllers/UtilityController.h@@ -35,9 +35,12 @@ public:// Process mode change command and return new modeModeEnum handleModeChangeCommand(const TerminalCommand& cmd);- // Loic Analyzer on device screen+ // Logic Analyzer on device screenvoid handleLogicAnalyzer(const TerminalCommand& cmd);+ // Analogic plotter on device screen+ void handleAnalogic(const TerminalCommand& cmd);+// Check if a command is a global utility commandbool isGlobalCommand(const TerminalCommand& cmd);@@ -65,4 +68,4 @@ private:ArgTransformer& argTransformer;SysInfoShell& sysInfoShell;GlobalState& state = GlobalState::getInstance();-};\ No newline at end of file+};diff --git a/src/Interfaces/IDeviceView.h b/src/Interfaces/IDeviceView.hindex 3a28c20d..65b64d68 100644--- a/src/Interfaces/IDeviceView.h+++ b/src/Interfaces/IDeviceView.h@@ -33,7 +33,10 @@ public:virtual void clear() = 0;// Logic analyzer- virtual void drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer) = 0;+ virtual void drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) = 0;++ // Analogic plotter+ virtual void drawAnalogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) = 0;// Set screen rotationvirtual void setRotation(uint8_t rotation) = 0;diff --git a/src/States/GlobalState.h b/src/States/GlobalState.hindex 72c19370..23c4b5f3 100644--- a/src/States/GlobalState.h+++ b/src/States/GlobalState.h@@ -434,6 +434,10 @@ public:return std::find(protectedPins.begin(), protectedPins.end(), pin) != protectedPins.end();}+ bool isPinAnalog(uint8_t pin) const {+ return ((pin > 0) && (pin < 19));+ }+// ConstructorGlobalState() {#ifdef LED_PINdiff --git a/src/Views/CardputerDeviceView.cpp b/src/Views/CardputerDeviceView.cppindex 0fda3e59..ed7e8219 100644--- a/src/Views/CardputerDeviceView.cpp+++ b/src/Views/CardputerDeviceView.cpp@@ -3,8 +3,11 @@#include "CardputerDeviceView.h"// Reuse the M5DeviceView implementation-void CardputerDeviceView::drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer) {- M5DeviceView::drawLogicTrace(pin, buffer);+void CardputerDeviceView::drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) {+ M5DeviceView::drawLogicTrace(pin, buffer, step);}+void CardputerDeviceView::drawAnalogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) {+ M5DeviceView::drawAnalogicTrace(pin, buffer, step);+}#endif // DEVICE_CARDPUTERdiff --git a/src/Views/CardputerDeviceView.h b/src/Views/CardputerDeviceView.hindex 37b72965..64999316 100644--- a/src/Views/CardputerDeviceView.h+++ b/src/Views/CardputerDeviceView.h@@ -20,7 +20,8 @@ public:void loading() override {}// Only this one is implemented- void drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer) override;+ void drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) override;+ void drawAnalogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) override;};#endif // DEVICE_CARDPUTERdiff --git a/src/Views/M5DeviceView.cpp b/src/Views/M5DeviceView.cppindex 32b20f23..0464d002 100644--- a/src/Views/M5DeviceView.cpp+++ b/src/Views/M5DeviceView.cpp@@ -263,7 +263,7 @@ void M5DeviceView::loading() {M5.Lcd.drawString("Loading...", 75, 60);}-void M5DeviceView::drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer) {+void M5DeviceView::drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) {static constexpr int canvasWidth = 240;static constexpr int canvasHeight = 65;static constexpr int midY = canvasHeight / 2;@@ -275,14 +275,21 @@ void M5DeviceView::drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffecanvas.fillSprite(BACKGROUND_COLOR);// Trace+ int x0 = 0;for (size_t i = 1; i < buffer.size() && i < canvasWidth; ++i) {- int x0 = i - 1;- int x1 = i;- int amplitude = 20;- int y0 = buffer[i - 1] ? midY - amplitude : midY + amplitude;- int y1 = buffer[i] ? midY - amplitude : midY + amplitude;-- canvas.drawLine(x0, y0, x1, y1, PRIMARY_COLOR);+ uint8_t prev = buffer[i - 1];+ uint8_t curr = buffer[i];+ int y1 = prev ? midY - 20 : midY + 20;+ int y2 = curr ? midY - 20 : midY + 20;++ if (curr != prev){+ canvas.drawLine(x0, y1, x0 + step, y1, PRIMARY_COLOR );+ canvas.drawLine(x0 + step, y1, x0 + step, y2, PRIMARY_COLOR );+ } else {+ canvas.drawLine(x0, y1, x0 + step, y2, PRIMARY_COLOR );+ }+ x0 += step;+ if (x0 > canvasWidth - step) break;}// Pin num@@ -296,4 +303,32 @@ void M5DeviceView::drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffecanvas.deleteSprite();}+void M5DeviceView::drawAnalogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) {+ static constexpr int canvasWidth = 240;+ static constexpr int canvasHeight = 65;++ M5Canvas canvas(&M5.Lcd);+ canvas.setColorDepth(8);+ canvas.createSprite(canvasWidth, canvasHeight);+ canvas.fillSprite(BACKGROUND_COLOR);++ // Trace+ int x = 0;+ for (size_t i = 1; i < buffer.size() && i < canvasWidth; i ++) {++ uint8_t prev = canvasHeight - 1 - (buffer[i - 1] >> 2);+ uint8_t curr = canvasHeight - 1 - (buffer[i] >> 2);+ canvas.drawLine(x, prev, x + step, curr, PRIMARY_COLOR);+ x += step;+ if (x > canvasWidth - step) break;+ }++ // Pin num+ canvas.drawString("Pin " + String(pin), 5, 0);++ canvas.pushSprite(0, 35);+ canvas.deleteSprite();+}++#endif\ No newline at end of filediff --git a/src/Views/M5DeviceView.h b/src/Views/M5DeviceView.hindex 7ccd8d9d..c903f297 100644--- a/src/Views/M5DeviceView.h+++ b/src/Views/M5DeviceView.h@@ -34,7 +34,8 @@ public:void clear() override;void setRotation(uint8_t rotation);void topBar(const std::string& title, bool submenu, bool searchBar) override;- void drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer);+ void drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) override;+ void drawAnalogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) override;void horizontalSelection(const std::vector<std::string>& options,uint16_t selectedIndex,diff --git a/src/Views/NoScreenDeviceView.cpp b/src/Views/NoScreenDeviceView.cppindex 33129766..3c446322 100644--- a/src/Views/NoScreenDeviceView.cpp+++ b/src/Views/NoScreenDeviceView.cpp@@ -16,7 +16,7 @@ void NoScreenDeviceView::loading() {}void NoScreenDeviceView::clear() {}-void NoScreenDeviceView::drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer) {}+void NoScreenDeviceView::drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) {}void NoScreenDeviceView::setRotation(uint8_t rotation) {}diff --git a/src/Views/NoScreenDeviceView.h b/src/Views/NoScreenDeviceView.hindex 61359f2d..9b685c24 100644--- a/src/Views/NoScreenDeviceView.h+++ b/src/Views/NoScreenDeviceView.h@@ -13,7 +13,7 @@ public:void show(PinoutConfig& config) override;void loading() override;void clear() override;- void drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer) override;+ void drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) override;void setRotation(uint8_t rotation) override;void topBar(const std::string& title, bool submenu, bool searchBar) override;void horizontalSelection(diff --git a/src/Views/TembedDeviceView.cpp b/src/Views/TembedDeviceView.cppindex d7fe42ed..357b3a0a 100644--- a/src/Views/TembedDeviceView.cpp+++ b/src/Views/TembedDeviceView.cpp@@ -82,11 +82,11 @@ void TembedDeviceView::clear() {tft.fillScreen(TFT_BLACK);}-void TembedDeviceView::drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer) {+void TembedDeviceView::drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) {const int canvasWidth = 320;const int canvasHeight = 80;const int logicCenterY = canvasHeight / 2;- const int step = 4;+ //const int step = 1;canvas.setColorDepth(8);canvas.createSprite(canvasWidth, canvasHeight);@@ -107,7 +107,12 @@ void TembedDeviceView::drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& bint y1 = prev ? logicCenterY - 15 : logicCenterY + 15;int y2 = curr ? logicCenterY - 15 : logicCenterY + 15;- canvas.drawLine(x, y1, x + step, y2, curr ? TFT_GREEN : TFT_WHITE );+ if (curr != prev){+ canvas.drawLine(x, y1, x + step, y1, prev ? TFT_GREEN : TFT_WHITE );+ canvas.drawLine(x + step, y1, x + step, y2, curr ? TFT_GREEN : TFT_WHITE );+ } else {+ canvas.drawLine(x, y1, x + step, y2, curr ? TFT_GREEN : TFT_WHITE );+ }x += step;if (x > canvasWidth - step) break;}@@ -116,6 +121,36 @@ void TembedDeviceView::drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& bcanvas.deleteSprite();}+void TembedDeviceView::drawAnalogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) {+ const int canvasWidth = 320;+ const int canvasHeight = 135;++ canvas.setColorDepth(8);+ canvas.createSprite(canvasWidth, canvasHeight);+ canvas.fillSprite(TFT_BLACK);++ // Pin num+ canvas.setTextColor(TFT_WHITE, TFT_BLACK);+ canvas.setTextSize(1);+ canvas.setCursor(10, 0);+ canvas.print("Pin ");+ canvas.print(pin);++ // Trace+ int x = 10;+ for (size_t i = 1; i < buffer.size(); ++i) {++ uint8_t prev = canvasHeight - 1 - (buffer[i - 1] >> 1);+ uint8_t curr = canvasHeight - 1 - (buffer[i] >> 1);+ canvas.drawLine(x, prev, x + step, curr, TFT_GREEN);+ x += step;+ if (x > canvasWidth - step) break;+ }++ canvas.pushSprite(0, 35);+ canvas.deleteSprite();+}+void TembedDeviceView::setRotation(uint8_t rotation) {tft.setRotation(rotation);}diff --git a/src/Views/TembedDeviceView.h b/src/Views/TembedDeviceView.hindex 979df176..2e74c469 100644--- a/src/Views/TembedDeviceView.h+++ b/src/Views/TembedDeviceView.h@@ -52,7 +52,8 @@ public:void show(PinoutConfig& config) override;void loading() override;void clear() override;- void drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer) override;+ void drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) override;+ void drawAnalogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer, uint8_t step) override;void setRotation(uint8_t rotation) override;void topBar(const std::string& title, bool submenu, bool searchBar) override;void horizontalSelection(