From b1e3c52b0874b52f0aa819a01df074bad4cd98e6 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Wed, 8 Jun 2016 17:55:25 +0200 Subject: [PATCH] remove DialogIcon enum, use bitmap structure directly --- bootloader/bootloader.c | 10 +++++----- bootloader/usb.c | 14 +++++++------- demo/demo.c | 2 +- firmware/fsm.c | 22 +++++++++++----------- firmware/layout2.c | 26 +++++++++++++------------- firmware/layout2.h | 3 ++- firmware/protect.c | 4 ++-- firmware/recovery.c | 4 ++-- firmware/reset.c | 10 +++++----- firmware/storage.c | 2 +- firmware/trezor.c | 2 +- layout.c | 28 ++++------------------------ layout.h | 12 ++---------- 13 files changed, 56 insertions(+), 83 deletions(-) diff --git a/bootloader/bootloader.c b/bootloader/bootloader.c index b6b389ad9..30abc4bc5 100644 --- a/bootloader/bootloader.c +++ b/bootloader/bootloader.c @@ -45,18 +45,18 @@ void layoutFirmwareHash(uint8_t *hash) for (i = 0; i < 4; i++) { data2hex(hash + i * 8, 8, str[i]); } - layoutDialog(DIALOG_ICON_QUESTION, "Abort", "Continue", "Compare fingerprints", str[0], str[1], str[2], str[3], NULL, NULL); + layoutDialog(&bmp_icon_question, "Abort", "Continue", "Compare fingerprints", str[0], str[1], str[2], str[3], NULL, NULL); } void show_halt(void) { - layoutDialog(DIALOG_ICON_ERROR, NULL, NULL, NULL, "Unofficial firmware", "aborted.", NULL, "Unplug your TREZOR", "and see our support", "page at mytrezor.com"); + layoutDialog(&bmp_icon_error, NULL, NULL, NULL, "Unofficial firmware", "aborted.", NULL, "Unplug your TREZOR", "and see our support", "page at mytrezor.com"); system_halt(); } void show_unofficial_warning(uint8_t *hash) { - layoutDialog(DIALOG_ICON_WARNING, "Abort", "I'll take the risk", NULL, "WARNING!", NULL, "Unofficial firmware", "detected.", NULL, NULL); + layoutDialog(&bmp_icon_warning, "Abort", "I'll take the risk", NULL, "WARNING!", NULL, "Unofficial firmware", "detected.", NULL, NULL); do { delay(100000); @@ -124,7 +124,7 @@ void check_firmware_sanity(void) broken++; } if (broken) { - layoutDialog(DIALOG_ICON_ERROR, NULL, NULL, NULL, "Firmware appears", "to be broken.", NULL, "Unplug your TREZOR", "and see our support", "page at mytrezor.com"); + layoutDialog(&bmp_icon_error, NULL, NULL, NULL, "Firmware appears", "to be broken.", NULL, "Unplug your TREZOR", "and see our support", "page at mytrezor.com"); system_halt(); } } @@ -133,7 +133,7 @@ uint32_t __stack_chk_guard; void __attribute__((noreturn)) __stack_chk_fail(void) { - layoutDialog(DIALOG_ICON_ERROR, NULL, NULL, NULL, "Stack smashing", "detected.", NULL, "Please unplug", "the device.", NULL); + layoutDialog(&bmp_icon_error, NULL, NULL, NULL, "Stack smashing", "detected.", NULL, "Please unplug", "the device.", NULL); for (;;) {} // loop forever } diff --git a/bootloader/usb.c b/bootloader/usb.c index f4a73533e..3745b0cac 100644 --- a/bootloader/usb.c +++ b/bootloader/usb.c @@ -272,7 +272,7 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep) if (flash_state == STATE_OPEN) { if (msg_id == 0x0006) { // FirmwareErase message (id 6) - layoutDialog(DIALOG_ICON_QUESTION, "Abort", "Continue", NULL, "Install new", "firmware?", NULL, "Never do this without", "your recovery card!", NULL); + layoutDialog(&bmp_icon_question, "Abort", "Continue", NULL, "Install new", "firmware?", NULL, "Never do this without", "your recovery card!", NULL); do { delay(100000); buttonUpdate(); @@ -299,7 +299,7 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep) } send_msg_failure(dev); flash_state = STATE_END; - layoutDialog(DIALOG_ICON_WARNING, NULL, NULL, NULL, "Firmware installation", "aborted.", NULL, "You may now", "unplug your TREZOR.", NULL); + layoutDialog(&bmp_icon_warning, NULL, NULL, NULL, "Firmware installation", "aborted.", NULL, "You may now", "unplug your TREZOR.", NULL); return; } return; @@ -310,7 +310,7 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep) if (buf[9] != 0x0a) { // invalid contents send_msg_failure(dev); flash_state = STATE_END; - layoutDialog(DIALOG_ICON_ERROR, NULL, NULL, NULL, "Error installing ", "firmware.", NULL, "Unplug your TREZOR", "and try again.", NULL); + layoutDialog(&bmp_icon_error, NULL, NULL, NULL, "Error installing ", "firmware.", NULL, "Unplug your TREZOR", "and try again.", NULL); return; } // read payload length @@ -319,7 +319,7 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep) if (flash_len > FLASH_TOTAL_SIZE + FLASH_META_DESC_LEN - (FLASH_APP_START - FLASH_ORIGIN)) { // firmware is too big send_msg_failure(dev); flash_state = STATE_END; - layoutDialog(DIALOG_ICON_ERROR, NULL, NULL, NULL, "Firmware is too big.", NULL, "Get official firmware", "from mytrezor.com", NULL, NULL); + layoutDialog(&bmp_icon_error, NULL, NULL, NULL, "Firmware is too big.", NULL, "Get official firmware", "from mytrezor.com", NULL, NULL); return; } sha256_Init(&ctx); @@ -348,7 +348,7 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep) if (buf[0] != '?') { // invalid contents send_msg_failure(dev); flash_state = STATE_END; - layoutDialog(DIALOG_ICON_ERROR, NULL, NULL, NULL, "Error installing ", "firmware.", NULL, "Unplug your TREZOR", "and try again.", NULL); + layoutDialog(&bmp_icon_error, NULL, NULL, NULL, "Error installing ", "firmware.", NULL, "Unplug your TREZOR", "and try again.", NULL); return; } p = buf + 1; @@ -432,10 +432,10 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep) } flash_state = STATE_END; if (hash_check_ok) { - layoutDialog(DIALOG_ICON_OK, NULL, NULL, NULL, "New firmware", "successfully installed.", NULL, "You may now", "unplug your TREZOR.", NULL); + layoutDialog(&bmp_icon_ok, NULL, NULL, NULL, "New firmware", "successfully installed.", NULL, "You may now", "unplug your TREZOR.", NULL); send_msg_success(dev); } else { - layoutDialog(DIALOG_ICON_WARNING, NULL, NULL, NULL, "Firmware installation", "aborted.", NULL, "You need to repeat", "the procedure with", "the correct firmware."); + layoutDialog(&bmp_icon_warning, NULL, NULL, NULL, "Firmware installation", "aborted.", NULL, "You need to repeat", "the procedure with", "the correct firmware."); send_msg_failure(dev); } return; diff --git a/demo/demo.c b/demo/demo.c index cfed6d6f6..f4ee18ac2 100644 --- a/demo/demo.c +++ b/demo/demo.c @@ -242,7 +242,7 @@ uint32_t __stack_chk_guard; void __attribute__((noreturn)) __stack_chk_fail(void) { - layoutDialog(DIALOG_ICON_ERROR, NULL, NULL, NULL, "Stack smashing", "detected.", NULL, "Please unplug", "the device.", NULL); + layoutDialog(&bmp_icon_error, NULL, NULL, NULL, "Stack smashing", "detected.", NULL, "Please unplug", "the device.", NULL); for (;;) {} // loop forever } diff --git a/firmware/fsm.c b/firmware/fsm.c index 0b08e1d18..b7c6e5025 100644 --- a/firmware/fsm.c +++ b/firmware/fsm.c @@ -161,7 +161,7 @@ void fsm_msgPing(Ping *msg) RESP_INIT(Success); if (msg->has_button_protection && msg->button_protection) { - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "answer to ping?", NULL, NULL, NULL, NULL); + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", "answer to ping?", NULL, NULL, NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Ping cancelled"); layoutHome(); @@ -196,16 +196,16 @@ void fsm_msgChangePin(ChangePin *msg) bool removal = msg->has_remove && msg->remove; if (removal) { if (storage_hasPin()) { - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "remove current PIN?", NULL, NULL, NULL, NULL); + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", "remove current PIN?", NULL, NULL, NULL, NULL); } else { fsm_sendSuccess("PIN removed"); return; } } else { if (storage_hasPin()) { - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "change current PIN?", NULL, NULL, NULL, NULL); + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", "change current PIN?", NULL, NULL, NULL, NULL); } else { - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "set new PIN?", NULL, NULL, NULL, NULL); + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", "set new PIN?", NULL, NULL, NULL, NULL); } } if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { @@ -233,7 +233,7 @@ void fsm_msgChangePin(ChangePin *msg) void fsm_msgWipeDevice(WipeDevice *msg) { (void)msg; - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "wipe the device?", NULL, "All data will be lost.", NULL, NULL); + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", "wipe the device?", NULL, "All data will be lost.", NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_WipeDevice, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Wipe cancelled"); layoutHome(); @@ -263,7 +263,7 @@ void fsm_msgFirmwareUpload(FirmwareUpload *msg) void fsm_msgGetEntropy(GetEntropy *msg) { - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "send entropy?", NULL, NULL, NULL, NULL); + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", "send entropy?", NULL, NULL, NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Entropy cancelled"); layoutHome(); @@ -332,7 +332,7 @@ void fsm_msgLoadDevice(LoadDevice *msg) return; } - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "I take the risk", NULL, "Loading private seed", "is not recommended.", "Continue only if you", "know what you are", "doing!", NULL); + layoutDialogSwipe(&bmp_icon_question, "Cancel", "I take the risk", NULL, "Loading private seed", "is not recommended.", "Continue only if you", "know what you are", "doing!", NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Load cancelled"); layoutHome(); @@ -489,7 +489,7 @@ void fsm_msgClearSession(ClearSession *msg) void fsm_msgApplySettings(ApplySettings *msg) { if (msg->has_label) { - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "change label to", msg->label, "?", NULL, NULL); + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", "change label to", msg->label, "?", NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); layoutHome(); @@ -497,7 +497,7 @@ void fsm_msgApplySettings(ApplySettings *msg) } } if (msg->has_language) { - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "change language to", msg->language, "?", NULL, NULL); + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", "change language to", msg->language, "?", NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); layoutHome(); @@ -505,7 +505,7 @@ void fsm_msgApplySettings(ApplySettings *msg) } } if (msg->has_use_passphrase) { - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", msg->use_passphrase ? "enable passphrase" : "disable passphrase", "encryption?", NULL, NULL, NULL); + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", msg->use_passphrase ? "enable passphrase" : "disable passphrase", "encryption?", NULL, NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); layoutHome(); @@ -513,7 +513,7 @@ void fsm_msgApplySettings(ApplySettings *msg) } } if (msg->has_homescreen) { - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", NULL, "Do you really want to", "change the home", "screen ?", NULL, NULL, NULL); + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, "Do you really want to", "change the home", "screen ?", NULL, NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Apply settings cancelled"); layoutHome(); diff --git a/firmware/layout2.c b/firmware/layout2.c index 7805258b6..16b867441 100644 --- a/firmware/layout2.c +++ b/firmware/layout2.c @@ -31,7 +31,7 @@ void *layoutLast = layoutHome; -void layoutDialogSwipe(LayoutDialogIcon icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6) +void layoutDialogSwipe(const BITMAP *icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6) { layoutLast = layoutDialogSwipe; oledSwipeLeft(); @@ -119,7 +119,7 @@ void layoutConfirmOutput(const CoinType *coin, const TxOutputType *out) static char first_half[17 + 1]; strlcpy(first_half, out->address, sizeof(first_half)); const char *str_out = str_amount(out->amount, coin->has_coin_shortcut ? coin->coin_shortcut : NULL, buf_out, sizeof(buf_out)); - layoutDialogSwipe(DIALOG_ICON_QUESTION, + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, @@ -136,7 +136,7 @@ void layoutConfirmTx(const CoinType *coin, uint64_t amount_out, uint64_t amount_ { const char *str_out = str_amount(amount_out, coin->has_coin_shortcut ? coin->coin_shortcut : NULL, buf_out, sizeof(buf_out)); const char *str_fee = str_amount(amount_fee, coin->has_coin_shortcut ? coin->coin_shortcut : NULL, buf_fee, sizeof(buf_fee)); - layoutDialogSwipe(DIALOG_ICON_QUESTION, + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, @@ -153,7 +153,7 @@ void layoutFeeOverThreshold(const CoinType *coin, uint64_t fee, uint32_t kb) { (void)kb; const char *str_out = str_amount(fee, coin->has_coin_shortcut ? coin->coin_shortcut : NULL, buf_out, sizeof(buf_out)); - layoutDialogSwipe(DIALOG_ICON_QUESTION, + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", NULL, @@ -191,7 +191,7 @@ const char **split_message(const uint8_t *msg, uint32_t len, uint32_t rowlen) void layoutSignMessage(const uint8_t *msg, uint32_t len) { const char **str = split_message(msg, len, 16); - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", "Sign message?", str[0], str[1], str[2], str[3], NULL, NULL); } @@ -199,7 +199,7 @@ void layoutSignMessage(const uint8_t *msg, uint32_t len) void layoutVerifyAddress(const char *address) { const char **str = split_message((const uint8_t *)address, strlen(address), 17); - layoutDialogSwipe(DIALOG_ICON_INFO, "Cancel", "Confirm", + layoutDialogSwipe(&bmp_icon_info, "Cancel", "Confirm", "Confirm address?", "Message signed by:", NULL, str[0], str[1], str[2], NULL); @@ -208,7 +208,7 @@ void layoutVerifyAddress(const char *address) void layoutVerifyMessage(const uint8_t *msg, uint32_t len) { const char **str = split_message(msg, len, 16); - layoutDialogSwipe(DIALOG_ICON_INFO, "Cancel", "Confirm", + layoutDialogSwipe(&bmp_icon_info, "Cancel", "Confirm", "Verified message", str[0], str[1], str[2], str[3], NULL, NULL); } @@ -216,7 +216,7 @@ void layoutVerifyMessage(const uint8_t *msg, uint32_t len) void layoutCipherKeyValue(bool encrypt, const char *key) { const char **str = split_message((const uint8_t *)key, strlen(key), 16); - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", encrypt ? "Encode value of this key?" : "Decode value of this key?", str[0], str[1], str[2], str[3], NULL, NULL); } @@ -224,7 +224,7 @@ void layoutCipherKeyValue(bool encrypt, const char *key) void layoutEncryptMessage(const uint8_t *msg, uint32_t len, bool signing) { const char **str = split_message(msg, len, 16); - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", signing ? "Encrypt+Sign message?" : "Encrypt message?", str[0], str[1], str[2], str[3], NULL, NULL); } @@ -232,7 +232,7 @@ void layoutEncryptMessage(const uint8_t *msg, uint32_t len, bool signing) void layoutDecryptMessage(const uint8_t *msg, uint32_t len, const char *address) { const char **str = split_message(msg, len, 16); - layoutDialogSwipe(DIALOG_ICON_INFO, NULL, "OK", + layoutDialogSwipe(&bmp_icon_info, NULL, "OK", address ? "Decrypted signed message" : "Decrypted message", str[0], str[1], str[2], str[3], NULL, NULL); } @@ -286,7 +286,7 @@ void layoutPublicKey(const uint8_t *pubkey) data2hex(pubkey, 1, desc + 12); data2hex(pubkey + 1, 32, hex); const char **str = split_message((const uint8_t *)hex, 32*2, 16); - layoutDialogSwipe(DIALOG_ICON_QUESTION, NULL, "Continue", NULL, + layoutDialogSwipe(&bmp_icon_question, NULL, "Continue", NULL, desc, str[0], str[1], str[2], str[3], NULL); } @@ -326,7 +326,7 @@ void layoutSignIdentity(const IdentityType *identity, const char *challenge) row_user[0] = 0; } - layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm", + layoutDialogSwipe(&bmp_icon_question, "Cancel", "Confirm", "Do you want to sign in?", row_proto[0] ? row_proto : NULL, row_hostport[0] ? row_hostport : NULL, @@ -337,5 +337,5 @@ void layoutSignIdentity(const IdentityType *identity, const char *challenge) } void layoutU2FDialog(const char *verb, const char *appid) { - layoutDialog(DIALOG_ICON_QUESTION, NULL, verb, NULL, verb, "U2F security key?", "", appid, "", NULL); + layoutDialog(&bmp_icon_question, NULL, verb, NULL, verb, "U2F security key?", "", appid, "", NULL); } diff --git a/firmware/layout2.h b/firmware/layout2.h index 6cbe30c43..d17ec7faa 100644 --- a/firmware/layout2.h +++ b/firmware/layout2.h @@ -22,8 +22,9 @@ #include "layout.h" #include "types.pb.h" +#include "bitmaps.h" -void layoutDialogSwipe(LayoutDialogIcon icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6); +void layoutDialogSwipe(const BITMAP *icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6); void layoutProgressSwipe(const char *desc, int permil); void layoutScreensaver(void); diff --git a/firmware/protect.c b/firmware/protect.c index a1b127ffb..f92010915 100644 --- a/firmware/protect.c +++ b/firmware/protect.c @@ -162,7 +162,7 @@ bool protectPin(bool use_cached) if (wait == 1) { secstrbuf[16] = 0; } - layoutDialog(DIALOG_ICON_INFO, NULL, NULL, NULL, "Wrong PIN entered", NULL, "Please wait", secstr, "to continue ...", NULL); + layoutDialog(&bmp_icon_info, NULL, NULL, NULL, "Wrong PIN entered", NULL, "Please wait", secstr, "to continue ...", NULL); // wait one second usbDelay(800000); wait--; @@ -216,7 +216,7 @@ bool protectPassphrase(void) usbTiny(1); msg_write(MessageType_MessageType_PassphraseRequest, &resp); - layoutDialogSwipe(DIALOG_ICON_INFO, NULL, NULL, NULL, "Please enter your", "passphrase using", "the computer's", "keyboard.", NULL, NULL); + layoutDialogSwipe(&bmp_icon_info, NULL, NULL, NULL, "Please enter your", "passphrase using", "the computer's", "keyboard.", NULL, NULL); bool result; for (;;) { diff --git a/firmware/recovery.c b/firmware/recovery.c index bd5bda70f..7ddceed63 100644 --- a/firmware/recovery.c +++ b/firmware/recovery.c @@ -41,7 +41,7 @@ void next_word(void) { if (word_pos == 0) { const char * const *wl = mnemonic_wordlist(); strlcpy(fake_word, wl[random_uniform(2048)], sizeof(fake_word)); - layoutDialogSwipe(DIALOG_ICON_INFO, NULL, NULL, NULL, "Please enter the word", NULL, fake_word, NULL, "on your computer", NULL); + layoutDialogSwipe(&bmp_icon_info, NULL, NULL, NULL, "Please enter the word", NULL, fake_word, NULL, "on your computer", NULL); } else { fake_word[0] = 0; char desc[] = "##th word"; @@ -60,7 +60,7 @@ void next_word(void) { if (word_pos == 3 || word_pos == 23) { desc[2] = 'r'; desc[3] = 'd'; } - layoutDialogSwipe(DIALOG_ICON_INFO, NULL, NULL, NULL, "Please enter the", NULL, (word_pos < 10 ? desc + 1 : desc), NULL, "of your mnemonic", NULL); + layoutDialogSwipe(&bmp_icon_info, NULL, NULL, NULL, "Please enter the", NULL, (word_pos < 10 ? desc + 1 : desc), NULL, "of your mnemonic", NULL); } WordRequest resp; memset(&resp, 0, sizeof(WordRequest)); diff --git a/firmware/reset.c b/firmware/reset.c index 1ecad15f4..7b2fa7223 100644 --- a/firmware/reset.c +++ b/firmware/reset.c @@ -52,7 +52,7 @@ void reset_init(bool display_random, uint32_t _strength, bool passphrase_protect data2hex(int_entropy + 24, 8, ent_str[3]); if (display_random) { - layoutDialogSwipe(DIALOG_ICON_INFO, "Cancel", "Continue", NULL, "Internal entropy:", ent_str[0], ent_str[1], ent_str[2], ent_str[3], NULL); + layoutDialogSwipe(&bmp_icon_info, "Cancel", "Continue", NULL, "Internal entropy:", ent_str[0], ent_str[1], ent_str[2], ent_str[3], NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ResetDevice, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Reset cancelled"); layoutHome(); @@ -129,15 +129,15 @@ void reset_entropy(const uint8_t *ext_entropy, uint32_t len) current_word_display[j + 1] = 0; if (word_pos == (int)strength/32*3) { // last word if (pass == 1) { - layoutDialogSwipe(DIALOG_ICON_INFO, NULL, "Finish", NULL, "Please check the seed", NULL, (word_pos < 10 ? desc + 1 : desc), current_word_display, NULL, NULL); + layoutDialogSwipe(&bmp_icon_info, NULL, "Finish", NULL, "Please check the seed", NULL, (word_pos < 10 ? desc + 1 : desc), current_word_display, NULL, NULL); } else { - layoutDialogSwipe(DIALOG_ICON_INFO, NULL, "Again", NULL, "Write down the seed", NULL, (word_pos < 10 ? desc + 1 : desc), current_word_display, NULL, NULL); + layoutDialogSwipe(&bmp_icon_info, NULL, "Again", NULL, "Write down the seed", NULL, (word_pos < 10 ? desc + 1 : desc), current_word_display, NULL, NULL); } } else { if (pass == 1) { - layoutDialogSwipe(DIALOG_ICON_INFO, NULL, "Next", NULL, "Please check the seed", NULL, (word_pos < 10 ? desc + 1 : desc), current_word_display, NULL, NULL); + layoutDialogSwipe(&bmp_icon_info, NULL, "Next", NULL, "Please check the seed", NULL, (word_pos < 10 ? desc + 1 : desc), current_word_display, NULL, NULL); } else { - layoutDialogSwipe(DIALOG_ICON_INFO, NULL, "Next", NULL, "Write down the seed", NULL, (word_pos < 10 ? desc + 1 : desc), current_word_display, NULL, NULL); + layoutDialogSwipe(&bmp_icon_info, NULL, "Next", NULL, "Write down the seed", NULL, (word_pos < 10 ? desc + 1 : desc), current_word_display, NULL, NULL); } } if (!protectButton(ButtonRequestType_ButtonRequest_ConfirmWord, true)) { diff --git a/firmware/storage.c b/firmware/storage.c index e7bb56182..f1a21196a 100644 --- a/firmware/storage.c +++ b/firmware/storage.c @@ -100,7 +100,7 @@ static char sessionPassphrase[51]; void storage_show_error(void) { - layoutDialog(DIALOG_ICON_ERROR, NULL, NULL, NULL, "Storage failure", "detected.", NULL, "Please unplug", "the device.", NULL); + layoutDialog(&bmp_icon_error, NULL, NULL, NULL, "Storage failure", "detected.", NULL, "Please unplug", "the device.", NULL); for (;;) { } } diff --git a/firmware/trezor.c b/firmware/trezor.c index aa154d6e6..e54d81c7c 100644 --- a/firmware/trezor.c +++ b/firmware/trezor.c @@ -32,7 +32,7 @@ uint32_t __stack_chk_guard; void __attribute__((noreturn)) __stack_chk_fail(void) { - layoutDialog(DIALOG_ICON_ERROR, NULL, NULL, NULL, "Stack smashing", "detected.", NULL, "Please unplug", "the device.", NULL); + layoutDialog(&bmp_icon_error, NULL, NULL, NULL, "Stack smashing", "detected.", NULL, "Please unplug", "the device.", NULL); for (;;) {} // loop forever } diff --git a/layout.c b/layout.c index ecb97210b..28a71ac9f 100644 --- a/layout.c +++ b/layout.c @@ -22,33 +22,13 @@ #include "layout.h" #include "oled.h" -void layoutDialog(LayoutDialogIcon icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6) +void layoutDialog(const BITMAP *icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6) { int left = 0; oledClear(); - switch (icon) { - case DIALOG_NOICON: - break; - case DIALOG_ICON_ERROR: - oledDrawBitmap(0, 0, &bmp_icon_error); - left = 20; - break; - case DIALOG_ICON_INFO: - oledDrawBitmap(0, 0, &bmp_icon_info); - left = 20; - break; - case DIALOG_ICON_QUESTION: - oledDrawBitmap(0, 0, &bmp_icon_question); - left = 20; - break; - case DIALOG_ICON_WARNING: - oledDrawBitmap(0, 0, &bmp_icon_warning); - left = 20; - break; - case DIALOG_ICON_OK: - oledDrawBitmap(0, 0, &bmp_icon_ok); - left = 20; - break; + if (icon) { + oledDrawBitmap(0, 0, icon); + left = icon->width + 4; } if (line1) oledDrawString(left, 0 * 9, line1); if (line2) oledDrawString(left, 1 * 9, line2); diff --git a/layout.h b/layout.h index c7f127a92..27f81d49e 100644 --- a/layout.h +++ b/layout.h @@ -22,17 +22,9 @@ #include #include +#include "bitmaps.h" -typedef enum { - DIALOG_NOICON = 0, - DIALOG_ICON_ERROR, - DIALOG_ICON_INFO, - DIALOG_ICON_QUESTION, - DIALOG_ICON_WARNING, - DIALOG_ICON_OK, -} LayoutDialogIcon; - -void layoutDialog(LayoutDialogIcon icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6); +void layoutDialog(const BITMAP *icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6); void layoutProgressUpdate(bool refresh); void layoutProgress(const char *desc, int permil);