From 216cdc56a7fb6144ef5bac7cf3fe112de22e4e17 Mon Sep 17 00:00:00 2001 From: schauausgmbh Date: Wed, 7 Oct 2026 22:47:32 +0200 Subject: [PATCH] code cleanup --- AES256_Seed_Phrase_encryptor.ino | 42 ++++++++++++++++++++---- display.cpp | 37 +++++++++++++++++++++ display.h | 33 ++++--------------- matrix_keyboard.cpp | 56 ++++++++++++++++++++++++++++++++ matrix_keyboard.h | 9 +++++ 5 files changed, 144 insertions(+), 33 deletions(-) create mode 100644 matrix_keyboard.cpp create mode 100644 matrix_keyboard.h diff --git a/AES256_Seed_Phrase_encryptor.ino b/AES256_Seed_Phrase_encryptor.ino index 384f280..0f04698 100644 --- a/AES256_Seed_Phrase_encryptor.ino +++ b/AES256_Seed_Phrase_encryptor.ino @@ -1,4 +1,6 @@ /* + * AES256 Seed Phrase Encryptor + * * Copyright (C) 2026 SCHAUAUS GmbH * * Permission is hereby granted, free of charge, to any person obtaining a @@ -23,8 +25,8 @@ // compiler values definition #define PRINT_SERIAL 1 #define DEBUG 0 -#define USE_DISPLAY 1 -#define HAS_KEYBOARD 0 +#define USE_DISPLAY 0 +#define HAS_KEYBOARD 1 #define BTN_HOME 9 @@ -36,7 +38,13 @@ #include // project files to include -#include "display.h" +#if USE_DISPLAY + #include "display.h" +#endif + +#if HAS_KEYBOARD + #include "matrix_keyboard.h" +#endif //creating an object of AES256 class AES256_ESP aes256; @@ -228,7 +236,10 @@ void encryptData (String data) { #if PRINT_SERIAL Serial.println(); #endif - display_crypt_block(fullString, BTN_HOME); + + #if USE_DISPLAY + display_crypt_block(fullString, BTN_HOME); + #endif } void clearCryptograficInformation () { @@ -242,7 +253,9 @@ void clearCryptograficInformation () { Serial.println("Memory cleared"); #endif - display_home(); + #if USE_DISPLAY + display_home(); + #endif } void restartDevice () { @@ -299,7 +312,20 @@ void setup() { Serial.begin(115200); while(!Serial); pinMode(BTN_HOME, INPUT); - display_setup(); + + #if USE_DISPLAY + display_setup(); + #endif + + #if HAS_KEYBOARD + initKeyboard(); + #endif + pinMode(4, OUTPUT); + pinMode(5, OUTPUT); + digitalWrite(4, 0); + digitalWrite(5, 0); + pinMode(4, INPUT_PULLDOWN); + Serial.println("Waiting for command"); #if PRINT_SERIAL Serial.println("send \"help\" for available commands"); @@ -309,4 +335,8 @@ void setup() { void loop() { readCmd(); readHome(); // check for Home-button being pressed + #if HAS_KEYBOARD + char keyRead = readKeyboard(); + if(keyRead != '\0') Serial.print("Keyboard input: " + keyRead + '\0'); + #endif } diff --git a/display.cpp b/display.cpp index 30c7144..6705f03 100644 --- a/display.cpp +++ b/display.cpp @@ -1,6 +1,43 @@ +/* + * AES256 Seed Phrase Encryptor + * + * Copyright (C) 2026 SCHAUAUS GmbH + * +*/ + +// genereal definitions +#define DEBUG_DISPLAY 1 + +// pin definition +#define TFT_CS 14 +#define TFT_DC 15 +#define TFT_IPS true +#define TFT_MISO -1 +#define TFT_MOSI 6 +#define TFT_RST 21 +#define TFT_SCK 7 +#define TFT_BKL 22 +#define RGB_LED 8 + +// display dimensions ESP32-C6-LCD1.47 is portrait by default +#define TFT_HEIGHT 320 +#define TFT_WIDTH 172 +#define TFT_COL_OFFSET 34 // offset needed due to organization of ST7789 VRAM +#define TFT_ROW_OFFSET 0 // offset needed due to organization of ST7789 VRAM + +// set display rotation (needs to be 0 for offsets to be applied properly!) +#define TFT_ROTATION 0 + +// backlight settings +#define TFT_BKL_DUTY 50 + #include #include #include "pins_arduino.h" + +//#include +#include + #include "display.h" Arduino_DataBus *bus = new Arduino_HWSPI( TFT_DC, TFT_CS); diff --git a/display.h b/display.h index a4d31bc..8abdb1f 100644 --- a/display.h +++ b/display.h @@ -1,30 +1,9 @@ -//#include -#include - -#define DEBUG_DISPLAY 0 - -// pin definition -#define TFT_CS 14 -#define TFT_DC 15 -#define TFT_IPS true -#define TFT_MISO -1 -#define TFT_MOSI 6 -#define TFT_RST 21 -#define TFT_SCK 7 -#define TFT_BKL 22 -#define RGB_LED 8 - -// display dimensions ESP32-C6-LCD1.47 is portrait by default -#define TFT_HEIGHT 320 -#define TFT_WIDTH 172 -#define TFT_COL_OFFSET 34 // offset needed due to organization of ST7789 VRAM -#define TFT_ROW_OFFSET 0 // offset needed due to organization of ST7789 VRAM - -// set display rotation (needs to be 0 for offsets to be applied properly!) -#define TFT_ROTATION 0 - -// backlight settings -#define TFT_BKL_DUTY 50 +/* + * AES256 Seed Phrase Encryptor + * + * Copyright (C) 2026 SCHAUAUS GmbH + * +*/ void display_setup(); void display_help(); diff --git a/matrix_keyboard.cpp b/matrix_keyboard.cpp new file mode 100644 index 0000000..2d26b06 --- /dev/null +++ b/matrix_keyboard.cpp @@ -0,0 +1,56 @@ +#include +#include +#include "esp32-hal-gpio.h" +/* + * AES256 Seed Phrase Encryptor + * + * Copyright (C) 2026 SCHAUAUS GmbH + * +*/ + +// pin definitions +#define KEYBOARD_COL1_PIN 1 +#define KEYBOARD_COL2_PIN 2 +#define KEYBOARD_COL3_PIN 3 +#define KEYBOARD_COL4_PIN 0 +#define KEYBOARD_COL5_PIN 5 + +#define KEYBOARD_ROW1_PIN 18 +#define KEYBOARD_ROW2_PIN 19 +#define KEYBOARD_ROW3_PIN 20 +#define KEYBOARD_ROW4_PIN 23 + +// project includes +#include "matrix_keyboard.h" + +char keyboardCharacters[] = "0123456789ABCDEF"; +int colPins[] = { KEYBOARD_COL1_PIN, KEYBOARD_COL2_PIN, KEYBOARD_COL3_PIN, KEYBOARD_COL4_PIN }; +int rowPins[] = { KEYBOARD_ROW1_PIN, KEYBOARD_ROW2_PIN, KEYBOARD_ROW3_PIN, KEYBOARD_ROW4_PIN }; + +void initKeyboard () { + // set column pins as input pulled low + for ( int i = 0; i < sizeof(colPins) / sizeof(colPins[0]); i++ ) + pinMode(colPins[i], INPUT_PULLDOWN); + + //set row pins as output + for ( int j = 0; j < sizeof(rowPins) / sizeof(rowPins[0]); j++ ) { + pinMode(rowPins[j], OUTPUT); + digitalWrite(rowPins[j], 0); + } +} + +char readKeyboard () { + for ( int i = 0; i < sizeof(rowPins) / sizeof(rowPins[0]); i++ ) { // walk through each row of keys on the matrix keyboard + digitalWrite(rowPins[i], 1); + delay(100); + for ( int j = 0; j < sizeof(colPins) / sizeof(colPins[0]); j++ ) { // read each column of the keyboard to identify a pressed key + if ( digitalRead( colPins[j] ) ) { // check if button is pressed + while ( digitalRead( colPins[j] ) ); // wait until button is released again + digitalWrite(rowPins[i], 0); + return keyboardCharacters[i*4 + j]; // return key + } + } + digitalWrite(rowPins[i], 0); + } + return '\0'; +} \ No newline at end of file diff --git a/matrix_keyboard.h b/matrix_keyboard.h new file mode 100644 index 0000000..5208ebd --- /dev/null +++ b/matrix_keyboard.h @@ -0,0 +1,9 @@ +/* + * AES256 Seed Phrase Encryptor + * + * Copyright (C) 2026 SCHAUAUS GmbH + * +*/ + +void initKeyboard (); +char readKeyboard (); \ No newline at end of file