firmware update to support display on ESP32-C6-LCD-1.47
This commit is contained in:
1 parent
a66ccd75c0
commit
13af4e9ff3
4 files changed
+409
-73
No files matched your search
+184
@@ -0,0 +1,184 @@
|
||||
#include <sys/_stdint.h>
|
||||
#include <sys/_types.h>
|
||||
#include "pins_arduino.h"
|
||||
#include "display.h"
|
||||
|
||||
Arduino_DataBus *bus = new Arduino_HWSPI( TFT_DC, TFT_CS);
|
||||
Arduino_GFX *gfx = new Arduino_ST7789(bus, TFT_RST, TFT_ROTATION, TFT_IPS, TFT_WIDTH, TFT_HEIGHT, TFT_COL_OFFSET, TFT_ROW_OFFSET);
|
||||
|
||||
void display_crypt_block(String str_to_print, uint16_t btn) {
|
||||
const uint8_t textOffsetX = 20;
|
||||
const uint8_t textOffsetY = 3;
|
||||
uint16_t strIndex = 0;
|
||||
|
||||
rgbLedWrite(RGB_LED, 255, 25, 0);
|
||||
gfx->setTextColor( RGB565(255, 255, 0 ) );
|
||||
|
||||
while (true) { //render single pages
|
||||
uint8_t line = 1;
|
||||
|
||||
// clear screen and print page header
|
||||
gfx->fillScreen( RGB565( 255, 100, 0 ) );
|
||||
gfx->setTextSize(3);
|
||||
gfx->setCursor(5, 5);
|
||||
gfx->println("encrypted");
|
||||
gfx->setTextSize(2);
|
||||
gfx->setCursor(textOffsetX, 35);
|
||||
|
||||
while (line <= 14) { // render lines
|
||||
uint8_t word = 1;
|
||||
do { //print next line
|
||||
if(str_to_print[strIndex] == ' ') {
|
||||
word++;
|
||||
if(word % 5) gfx->print(' ');
|
||||
}
|
||||
else gfx->print(str_to_print[strIndex]);
|
||||
strIndex++;
|
||||
if( strIndex >= str_to_print.length() ) break;
|
||||
} while( word % 5);
|
||||
if( strIndex >= str_to_print.length() ) break;
|
||||
gfx->println();
|
||||
gfx->setCursor(textOffsetX, gfx->getCursorY() + textOffsetY);
|
||||
line++;
|
||||
}
|
||||
if( strIndex >= str_to_print.length() ) break;
|
||||
gfx->print('>');
|
||||
|
||||
// wait for Home-button to be pressed and released before continuing to next page
|
||||
while ( digitalRead(btn) ); //Home-button not pressed
|
||||
while ( !digitalRead(btn) ); //Home-button pressed
|
||||
}
|
||||
}
|
||||
|
||||
void display_decrypt_text(String str_to_print, uint16_t btn) {
|
||||
// get number of spaces in string and by that the number of words in the seed phrase
|
||||
uint8_t numWords = 0;
|
||||
for(int i = 0; i < str_to_print.length(); i++) {
|
||||
if (str_to_print[i] == ' ') numWords++;
|
||||
}
|
||||
if(numWords > 0) numWords++;
|
||||
#if DEBUG_DISPLAY
|
||||
Serial.print("Number of seed words: ");
|
||||
Serial.println(numWords);
|
||||
#endif
|
||||
|
||||
int strIndex = 0;
|
||||
for(int page = 0; page <= floor (numWords / 12); page++) {
|
||||
int word = 1;
|
||||
|
||||
gfx->fillScreen( RGB565( 0, 220, 0 ) );
|
||||
rgbLedWrite(RGB_LED, 0, 255, 0);
|
||||
gfx->setTextColor( RGB565(255, 255, 255 ) );
|
||||
gfx->setTextSize(3);
|
||||
gfx->setCursor(5, 5);
|
||||
gfx->println("decrpyted");
|
||||
gfx->setTextSize(2);
|
||||
gfx->setCursor(0, 40);
|
||||
gfx->print(' ');
|
||||
|
||||
do {
|
||||
if(str_to_print[strIndex] == ' ') {
|
||||
gfx->println();
|
||||
word++;
|
||||
gfx->setCursor(0, gfx->getCursorY() + 5);
|
||||
}
|
||||
gfx->print( str_to_print[strIndex] );
|
||||
strIndex++;
|
||||
if( strIndex >= str_to_print.length() ) break;
|
||||
}
|
||||
while (word <= 12);
|
||||
if( strIndex >= str_to_print.length() ) break;
|
||||
gfx->setCursor(0, 300);
|
||||
gfx->print(" >");
|
||||
|
||||
// wait for Home-button to be pressed and released before continuing to next page
|
||||
while ( digitalRead(btn) ); //Home-button not pressed
|
||||
while ( !digitalRead(btn) ); //Home-button pressed
|
||||
}
|
||||
}
|
||||
|
||||
void display_help() {
|
||||
#define TEXT_X_OFFSET 3
|
||||
gfx->fillScreen( RGB565( 0, 0, 255 ) );
|
||||
rgbLedWrite(RGB_LED, 0, 0, 255);
|
||||
gfx->setTextSize(2);
|
||||
gfx->setTextColor( RGB565(255, 255, 255 ) );
|
||||
gfx->setCursor(0, 17);
|
||||
gfx->setCursor(TEXT_X_OFFSET, gfx->getCursorY());
|
||||
gfx->println("help\r\n print this\r\n");
|
||||
gfx->setCursor(TEXT_X_OFFSET, gfx->getCursorY());
|
||||
gfx->println("key\r\n generate\r\n random key");
|
||||
gfx->setCursor(TEXT_X_OFFSET, gfx->getCursorY());
|
||||
gfx->println("key <key>\r\n use def. key\r\n");
|
||||
gfx->setCursor(TEXT_X_OFFSET, gfx->getCursorY());
|
||||
gfx->println("encrypt <seed>\r\n encrypt seed");
|
||||
gfx->setCursor(TEXT_X_OFFSET, gfx->getCursorY());
|
||||
gfx->println("decrpyt<HEX>\r\n decrypt seed\r\n ");
|
||||
gfx->setCursor(TEXT_X_OFFSET, gfx->getCursorY());
|
||||
gfx->println("clear\r\n clear data");
|
||||
gfx->setCursor(TEXT_X_OFFSET, gfx->getCursorY());
|
||||
gfx->println("restart\r\n reboot device");
|
||||
}
|
||||
|
||||
void display_home() {
|
||||
gfx->fillScreen( RGB565( 255, 255, 255 ) );
|
||||
rgbLedWrite(RGB_LED, 255, 255, 255);
|
||||
gfx->setTextSize(2);
|
||||
gfx->setTextColor( RGB565(30, 30, 30 ) );
|
||||
gfx->setCursor(20, 5);
|
||||
gfx->println("Seed Phrase");
|
||||
gfx->setCursor(2, gfx->getCursorY());
|
||||
gfx->println("Crypter AES256");
|
||||
gfx->setTextSize(1);
|
||||
gfx->setCursor(5, 45);
|
||||
gfx->println("Encrypt/Decrypt seed phrase");
|
||||
gfx->setCursor(23, gfx->getCursorY() + 1);
|
||||
gfx->println("with AES256 algorithm");
|
||||
gfx->setTextSize(2);
|
||||
gfx->setCursor(14, 120);
|
||||
gfx->println("Enter 'help'");
|
||||
gfx->setCursor(26, gfx->getCursorY());
|
||||
gfx->println("to display");
|
||||
gfx->setCursor(14, gfx->getCursorY());
|
||||
gfx->println("commands and");
|
||||
gfx->setCursor(20, gfx->getCursorY());
|
||||
gfx->println("information");
|
||||
}
|
||||
|
||||
void display_key(byte hexKey[32]) {
|
||||
const uint8_t textOffsetX = 20;
|
||||
const uint8_t textOffsetY = 3;
|
||||
|
||||
gfx->fillScreen( RGB565( 255, 220, 0 ) );
|
||||
rgbLedWrite(RGB_LED, 255, 100, 0);
|
||||
gfx->setTextSize(3);
|
||||
gfx->setTextColor( RGB565(255, 0, 0 ) );
|
||||
gfx->setCursor(25, 10);
|
||||
gfx->println("Key set");
|
||||
gfx->setTextSize(2);
|
||||
gfx->setCursor(textOffsetX, 50);
|
||||
for(int i=0; i<32; i++) {
|
||||
if(hexKey[i] < 16)
|
||||
gfx->print("0");
|
||||
gfx->print(hexKey[i], HEX);
|
||||
if( (i+1) % 4 == 0 ) {
|
||||
gfx->println();
|
||||
gfx->setCursor(textOffsetX, gfx->getCursorY() + textOffsetY);
|
||||
}
|
||||
else gfx->print(" ");
|
||||
}
|
||||
}
|
||||
|
||||
void display_setup() {
|
||||
pinMode(TFT_BKL, OUTPUT);
|
||||
analogWrite(TFT_BKL, floor(TFT_BKL_DUTY * 255 / 100 + 0.5) );
|
||||
|
||||
SPI.begin(TFT_SCK, TFT_MISO, TFT_MOSI, TFT_CS);
|
||||
|
||||
if (!gfx->begin())
|
||||
{
|
||||
Serial.println("gfx->begin() failed!");
|
||||
}
|
||||
gfx->fillScreen( RGB565( 255, 255, 255 ) );
|
||||
display_home();
|
||||
}
|
||||
Reference in new issue
Block a user