Skip to content

Commit

Permalink
add new macro
Browse files Browse the repository at this point in the history
  • Loading branch information
ftheirs committed Dec 12, 2023
1 parent 42e82e9 commit 5a48bac
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 38 deletions.
1 change: 1 addition & 0 deletions app/ui/view_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "coin.h"
#include "zxerror.h"
#include "view.h"
#include "zxmacros.h"

#define CUR_FLOW G_ux.flow_stack[G_ux.stack_count-1]

Expand Down
1 change: 1 addition & 0 deletions include/segwit_addr.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define _SEGWIT_ADDR_H_ 1

#include <stdint.h>
#include <stddef.h>

/** Encode a SegWit address
*
Expand Down
36 changes: 0 additions & 36 deletions include/zxerror.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#pragma once

#include "zxmacros.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -37,40 +35,6 @@ typedef enum {
zxerr_ledger_api_error = 0b00001111,
} zxerr_t;

__Z_INLINE uint8_t getErrorMessage(char *buffer, uint16_t bufferLen, zxerr_t err) {
MEMZERO(buffer, bufferLen);
if (bufferLen == 0) {
return 0;
}

switch (err) {
case zxerr_unknown:
snprintf(buffer, bufferLen - 1, "zxerr_unknown");
break;
case zxerr_ok:
snprintf(buffer, bufferLen - 1, "zxerr_ok");
break;
case zxerr_no_data:
snprintf(buffer, bufferLen - 1, "zxerr_no_data");
break;
case zxerr_out_of_bounds:
snprintf(buffer, bufferLen - 1, "zxerr_out_of_bounds");
break;
case zxerr_encoding_failed:
snprintf(buffer, bufferLen - 1, "zxerr_encoding_failed");
break;
case zxerr_invalid_crypto_settings:
snprintf(buffer, bufferLen - 1, "zxerr_invalid_crypto_settings");
break;
case zxerr_ledger_api_error:
snprintf(buffer, bufferLen - 1, "zxerr_ledger_api_error");
break;
default:
snprintf(buffer, bufferLen - 1, "err N/A");
}
return strlen(buffer);
}

//0b00000000
//0b00000011
//0b00000101
Expand Down
13 changes: 11 additions & 2 deletions include/zxmacros_ledger.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "cx.h"
#include "os_io_seproxyhal.h"
#include "ux.h"
#include "zxerror.h"

#define MEMCPY_NV nvm_write

Expand Down Expand Up @@ -67,7 +68,7 @@ extern unsigned int app_stack_canary;
if (__cx_err != CX_OK) { \
return __cx_err; \
} \
} while (0);
} while (0)


#define CATCH_CXERROR(CALL) \
Expand All @@ -76,6 +77,14 @@ extern unsigned int app_stack_canary;
if (__cx_err != CX_OK) { \
goto catch_cx_error; \
} \
} while (0);
} while (0)

#define CHECK_CX_OK(CALL) \
do { \
cx_err_t __cx_err = CALL; \
if (__cx_err != CX_OK) { \
return zxerr_unknown; \
} \
} while (0)

#endif

0 comments on commit 5a48bac

Please sign in to comment.