Skip to content

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

add tembed view

Geod0791b8a9e41
diff --git a/src/Views/TembedDeviceView.cpp b/src/Views/TembedDeviceView.cpp
new file mode 100644
index 00000000..83e975a1
--- /dev/null
+++ b/src/Views/TembedDeviceView.cpp
@@ -0,0 +1,322 @@
+#if defined(DEVICE_TEMBEDS3) || defined(DEVICE_TEMBEDS3CC1101)
+
+#include "TembedDeviceView.h"
+#include <Arduino.h>
+
+
+TembedDeviceView::TembedDeviceView() {
+ pinMode(PIN_POWER_ON, OUTPUT);
+ digitalWrite(PIN_POWER_ON, HIGH);
+ tft.begin();
+ tft.fillScreen(TFT_BLACK);
+ initDisplayRegs();
+ tft.setRotation(3);
+ tft.setSwapBytes(true);
+ pinMode(PIN_LCD_BL, OUTPUT);
+ digitalWrite(PIN_LCD_BL, HIGH);
+ tft.setTextColor(TFT_WHITE, TFT_BLACK);
+}
+
+void TembedDeviceView::initDisplayRegs() {
+ for (uint8_t i = 0; i < sizeof(lcd_st7789v) / sizeof(lcd_cmd_t); i++) {
+ tft.writecommand(lcd_st7789v[i].cmd);
+ for (int j = 0; j < (lcd_st7789v[i].len & 0x7F); j++) {
+ tft.writedata(lcd_st7789v[i].data[j]);
+ }
+ if (lcd_st7789v[i].len & 0x80) {
+ delay(120);
+ }
+ }
+}
+
+void TembedDeviceView::initialize() {
+ tft.fillScreen(TFT_BLACK);
+ tft.setTextColor(TFT_WHITE, TFT_BLACK);
+}
+
+void TembedDeviceView::logo() {
+ clear();
+
+ // Rect
+ tft.fillRoundRect(60, 55, 200, 60, 8, DARK_GREY_RECT);
+
+ // Border
+ tft.drawRoundRect(60, 55, 200, 60, 8, TFT_GREEN);
+
+ // Titre
+ tft.setTextColor(TFT_GREEN, DARK_GREY_RECT);
+ drawCenterText("Bus Pirate", 80, 4.5);
+
+ // Sub
+ tft.setTextColor(TFT_WHITE, DARK_GREY_RECT);
+ drawCenterText("Version 0.2 - Geo", 100, 1.9);
+
+ delay(3000);
+}
+
+void TembedDeviceView::welcome(TerminalTypeEnum& terminalType, std::string& terminalInfos) {
+ if (terminalType == TerminalTypeEnum::WiFiClient) welcomeWeb(terminalInfos);
+ else welcomeSerial(terminalInfos);
+}
+
+void TembedDeviceView::loading() {
+ tft.fillScreen(TFT_BLACK);
+ tft.setTextSize(1);
+ tft.setTextColor(TFT_WHITE);
+ drawCenterText("Loading...", 80, 2);
+}
+
+void TembedDeviceView::clear() {
+ tft.fillScreen(TFT_BLACK);
+}
+
+void TembedDeviceView::drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer) {
+ const int canvasWidth = 320;
+ const int canvasHeight = 80;
+ const int logicCenterY = canvasHeight / 2;
+ const int step = 4;
+
+ 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 = buffer[i - 1];
+ uint8_t curr = buffer[i];
+ int 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 );
+ x += step;
+ if (x > canvasWidth - step) break;
+ }
+
+ canvas.pushSprite(0, 50);
+ canvas.deleteSprite();
+}
+
+void TembedDeviceView::setRotation(uint8_t rotation) {
+ tft.setRotation(rotation);
+}
+
+void TembedDeviceView::topBar(const std::string& title, bool submenu, bool searchBar) {
+ tft.setTextColor(TFT_GREEN, TFT_BLACK);
+ tft.setTextSize(2);
+ drawCenterText(title.c_str(), 20, 2);
+
+ if (submenu) {
+ // TODO
+ }
+ if (searchBar) {
+ // TODO
+ }
+}
+
+void TembedDeviceView::horizontalSelection(
+ const std::vector<std::string>& options,
+ uint16_t selectedIndex,
+ const std::string& description1,
+ const std::string& description2)
+{
+ canvas.setColorDepth(16);
+ canvas.createSprite(tft.width(), tft.height() - 30); // without topBar
+ canvas.fillSprite(TFT_BLACK);
+
+ // Description 1
+ canvas.setTextColor(TFT_WHITE, TFT_BLACK);
+ canvas.setTextDatum(MC_DATUM);
+ canvas.setTextFont(2);
+ canvas.setTextSize(1);
+ canvas.drawString(description1.c_str(), canvas.width() / 2, 26);
+
+ // Description 2
+ canvas.setTextColor(DARK_GREY_RECT, TFT_BLACK);
+ canvas.drawString("Long press button to shut down", canvas.width() / 2, canvas.height() - 15);
+
+ // Option placing
+ const std::string& option = options[selectedIndex];
+ int boxX = 60;
+ int boxW = canvas.width() - 120;
+ int boxY = 45;
+ int boxH = 50;
+ int corner = 8;
+
+ // Option Rect
+ canvas.fillRoundRect(boxX, boxY, boxW, boxH, corner, DARK_GREY_RECT);
+ canvas.drawRoundRect(boxX, boxY, boxW, boxH, corner, TFT_GREEN);
+
+ // Option name
+ canvas.setTextColor(TFT_WHITE, DARK_GREY_RECT);
+ canvas.setTextFont(2);
+ canvas.setTextSize(2);
+ int textW = canvas.textWidth(option.c_str(), 2);
+ int textX = (canvas.width() - textW) / 2;
+ canvas.setCursor(textX, boxY + 10);
+ canvas.print(option.c_str());
+
+ // Arrows
+ canvas.setTextSize(1);
+ canvas.setTextColor(TFT_WHITE, TFT_BLACK);
+ canvas.setTextFont(2);
+ canvas.setCursor(35, boxY + 19);
+ canvas.print("<");
+ canvas.setCursor(canvas.width() - 40, boxY + 19);
+ canvas.print(">");
+
+ // Display
+ canvas.pushSprite(0, 30); // topbar height
+
+ // Release
+ canvas.deleteSprite();
+}
+
+void TembedDeviceView::drawCenterText(const std::string& text, int y, int fontSize) {
+ int16_t x1, y1;
+ uint16_t w, h;
+ tft.setTextDatum(MC_DATUM);
+ tft.setTextFont(fontSize);
+ tft.drawString(text.c_str(), tft.width() / 2, y);
+}
+
+void TembedDeviceView::welcomeSerial(const std::string& baudStr) {
+ canvas.setColorDepth(16);
+ canvas.setTextFont(2);
+ canvas.createSprite(tft.width(), tft.height());
+ canvas.fillSprite(TFT_BLACK);
+
+ // Titre
+ canvas.setTextColor(TFT_WHITE, TFT_BLACK);
+ canvas.setTextDatum(TL_DATUM);
+ canvas.setCursor(88, 35);
+ canvas.println("Open Serial (USB COM)");
+
+ // Rect baudrate
+ canvas.fillRoundRect(70, 60, 180, 40, 8, DARK_GREY_RECT);
+ canvas.drawRoundRect(70, 60, 180, 40, 8, TFT_GREEN);
+
+ // Texte Baud
+ std::string baud = "Baudrate: " + baudStr;
+ int16_t textW = canvas.textWidth(baud.c_str(), 2);
+ canvas.setCursor((canvas.width() - textW) / 2, 73);
+ canvas.setTextColor(TFT_WHITE, DARK_GREY_RECT);
+ canvas.print(baud.c_str());
+
+ // Sub
+ canvas.setTextColor(TFT_WHITE, TFT_BLACK);
+ canvas.setCursor(80, 107);
+ canvas.println("Then press a key to start");
+
+ canvas.pushSprite(0, 0);
+ canvas.deleteSprite();
+}
+
+
+void TembedDeviceView::welcomeWeb(const std::string& ipStr) {
+ canvas.setColorDepth(16);
+ canvas.createSprite(tft.width(), tft.height());
+ canvas.fillSprite(TFT_BLACK);
+
+ // Titre
+ canvas.setTextColor(TFT_WHITE, TFT_BLACK);
+ canvas.setTextDatum(TL_DATUM);
+ canvas.setTextFont(2);
+ canvas.setCursor(82, 34);
+ canvas.println("Open browser to connect");
+
+ // Rectangle IP
+ canvas.fillRoundRect(60, 60, 200, 40, 8, DARK_GREY_RECT);
+ canvas.drawRoundRect(60, 60, 200, 40, 8, TFT_GREEN);
+
+ // Texte IP
+ std::string ip = "http://" + ipStr;
+ int16_t textW = canvas.textWidth(ip.c_str(), 2);
+ canvas.setCursor((canvas.width() - textW) / 2, 73);
+ canvas.setTextColor(TFT_WHITE, DARK_GREY_RECT);
+ canvas.setTextFont(2);
+ canvas.print(ip.c_str());
+
+ canvas.pushSprite(0, 0);
+ canvas.deleteSprite();
+}
+
+void TembedDeviceView::shutDown() {
+ tft.setRotation(3); // it is called from input
+ tft.fillScreen(TFT_BLACK);
+ tft.setCursor(40, 60);
+ tft.setTextColor(TFT_WHITE);
+ tft.setTextFont(2);
+ drawCenterText("Shutting down...", 80, 2);
+ delay(1000);
+ digitalWrite(PIN_LCD_BL, LOW);
+ digitalWrite(PIN_POWER_ON, LOW);
+ initialize(); // black screen
+}
+
+void TembedDeviceView::show(PinoutConfig& config) {
+ clear();
+
+ const auto& mappings = config.getMappings();
+ auto mode = config.getMode();
+
+ canvas.setColorDepth(16);
+ canvas.createSprite(tft.width(), tft.height());
+ canvas.fillSprite(TFT_BLACK);
+
+ // Mode name
+ canvas.setTextColor(TFT_GREEN);
+ canvas.setTextFont(2.5);
+ std::string modeStr = "MODE " + mode;
+ int modeW = canvas.textWidth(modeStr.c_str(), 2);
+ int modeX = (canvas.width() - modeW) / 2;
+ canvas.drawString(modeStr.c_str(), modeX, 13);
+
+ // No mapping
+ if (mappings.empty()) {
+ canvas.fillRoundRect(20, 45, canvas.width() - 40, canvas.height() - 70, 5, TFT_BLACK);
+ canvas.drawRoundRect(20, 45, canvas.width() - 40, canvas.height() - 70, 5, TFT_GREEN);
+
+ canvas.setTextColor(TFT_WHITE);
+ canvas.setTextFont(2);
+ canvas.drawString("No mapping defined", 100, 85);
+ canvas.pushSprite(0, 0);
+ canvas.deleteSprite();
+ return;
+ }
+
+ // Mapping
+ int boxHeight = 24;
+ int startY = 40;
+ int spacing = 4;
+ int margin = 10;
+
+ for (size_t i = 0; i < mappings.size(); ++i) {
+ const std::string& mapping = mappings[i];
+ int y = startY + i * (boxHeight + spacing);
+
+ canvas.fillRoundRect(margin * 2, y, canvas.width() - 4 * margin, boxHeight, 6, DARK_GREY_RECT);
+ canvas.drawRoundRect(margin *2, y, canvas.width() - 4 * margin, boxHeight, 6, TFT_GREEN);
+
+ int textW = canvas.textWidth(mapping.c_str(), 2);
+ int textX = (canvas.width() - textW) / 2;
+ int textY = y + (boxHeight - 16) / 2 + 1;
+
+ canvas.setTextColor(TFT_WHITE, DARK_GREY_RECT);
+ canvas.setCursor(textX, textY);
+ canvas.setTextFont(2);
+ canvas.print(mapping.c_str());
+ }
+
+ canvas.pushSprite(0, 0);
+ canvas.deleteSprite();
+}
+
+#endif
\ No newline at end of file
diff --git a/src/Views/TembedDeviceView.h b/src/Views/TembedDeviceView.h
new file mode 100644
index 00000000..9abe5652
--- /dev/null
+++ b/src/Views/TembedDeviceView.h
@@ -0,0 +1,74 @@
+#pragma once
+
+#if defined(DEVICE_TEMBEDS3) || defined(DEVICE_TEMBEDS3CC1101)
+
+#include "Interfaces/IDeviceView.h"
+#include <TFT_eSPI.h>
+
+
+#ifdef DEVICE_TEMBEDS3CC1101
+ #define PIN_LCD_BL 21
+#else
+ #define PIN_LCD_BL 15
+#endif
+
+#define PIN_POWER_ON 46
+
+#define DARK_GREY_RECT 0x4208
+
+typedef struct {
+ uint8_t cmd;
+ uint8_t data[14];
+ uint8_t len;
+} lcd_cmd_t;
+
+// Commands to start the Tembed screen
+static const lcd_cmd_t lcd_st7789v[] = {
+ {0x11, {0}, 0 | 0x80},
+ {0x3A, {0X05}, 1},
+ {0xB2, {0X0B, 0X0B, 0X00, 0X33, 0X33}, 5},
+ {0xB7, {0X75}, 1},
+ {0xBB, {0X28}, 1},
+ {0xC0, {0X2C}, 1},
+ {0xC2, {0X01}, 1},
+ {0xC3, {0X1F}, 1},
+ {0xC6, {0X13}, 1},
+ {0xD0, {0XA7}, 1},
+ {0xD0, {0XA4, 0XA1}, 2},
+ {0xD6, {0XA1}, 1},
+ {0xE0, {0XF0, 0X05, 0X0A, 0X06, 0X06, 0X03, 0X2B, 0X32, 0X43, 0X36, 0X11, 0X10, 0X2B, 0X32}, 14},
+ {0xE1, {0XF0, 0X08, 0X0C, 0X0B, 0X09, 0X24, 0X2B, 0X22, 0X43, 0X38, 0X15, 0X16, 0X2F, 0X37}, 14},
+};
+
+class TembedDeviceView : public IDeviceView {
+public:
+ TembedDeviceView();
+
+ void initialize() override;
+ void logo() override;
+ void welcome(TerminalTypeEnum& terminalType, std::string& terminalInfos) override;
+ void show(PinoutConfig& config) override;
+ void loading() override;
+ void clear() override;
+ void drawLogicTrace(uint8_t pin, const std::vector<uint8_t>& buffer) override;
+ void setRotation(uint8_t rotation) override;
+ void topBar(const std::string& title, bool submenu, bool searchBar) override;
+ void horizontalSelection(
+ const std::vector<std::string>& options,
+ uint16_t selectedIndex,
+ const std::string& description1,
+ const std::string& description2) override;
+
+ void shutDown();
+
+private:
+ TFT_eSPI tft;
+ TFT_eSprite canvas = TFT_eSprite(&tft);
+
+ void drawCenterText(const std::string& text, int y, int fontSize);
+ void initDisplayRegs();
+ void welcomeWeb(const std::string& ip);
+ void welcomeSerial(const std::string& baud);
+};
+
+#endif
\ No newline at end of file