From ec0b8339e6dc74bdf3075e756002166c06312e08 Mon Sep 17 00:00:00 2001 From: Yehor Popovych Date: Tue, 13 Feb 2024 21:39:05 +0000 Subject: [PATCH] clang format --- .clang-format | 1 - src/common/buffer_ext.h | 4 +--- src/common/rwbuffer.h | 35 ++++++++++++++++++++--------------- src/context.h | 24 ++++++++++++------------ src/helpers/cmd_macros.h | 11 ++++++----- src/ui/ui_main.h | 5 ++--- src/ui/ui_menu.h | 2 +- 7 files changed, 42 insertions(+), 40 deletions(-) mode change 100755 => 100644 src/common/rwbuffer.h diff --git a/.clang-format b/.clang-format index b4abfa06..c76e9fc2 100644 --- a/.clang-format +++ b/.clang-format @@ -12,7 +12,6 @@ SortIncludes: false SpaceAfterCStyleCast: true AllowShortCaseLabelsOnASingleLine: false AllowAllArgumentsOnNextLine: false -AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: Never AllowShortFunctionsOnASingleLine: None BinPackArguments: false diff --git a/src/common/buffer_ext.h b/src/common/buffer_ext.h index d7661f11..105cbe29 100644 --- a/src/common/buffer_ext.h +++ b/src/common/buffer_ext.h @@ -13,9 +13,7 @@ * Data size of the buffer. * */ -static inline void buffer_init(buffer_t *buffer, - const uint8_t *ptr, - size_t data_size) { +static inline void buffer_init(buffer_t *buffer, const uint8_t *ptr, size_t data_size) { buffer->ptr = ptr; buffer->offset = 0; buffer->size = data_size; diff --git a/src/common/rwbuffer.h b/src/common/rwbuffer.h old mode 100755 new mode 100644 index e0f1de97..6f58854d --- a/src/common/rwbuffer.h +++ b/src/common/rwbuffer.h @@ -2,36 +2,35 @@ #include "buffer_ext.h" -#define RW_BUFFER_FROM_ARRAY_FULL(_name, _array, _size) \ - rw_buffer_t _name; \ +#define RW_BUFFER_FROM_ARRAY_FULL(_name, _array, _size) \ + rw_buffer_t _name; \ rw_buffer_init(&_name, _array, _size, _size) #define RW_BUFFER_FROM_ARRAY_EMPTY(_name, _array, _size) \ rw_buffer_t _name; \ rw_buffer_init(&_name, _array, _size, 0) -#define RW_BUFFER_FROM_VAR_FULL(_name, _var) \ - rw_buffer_t _name; \ +#define RW_BUFFER_FROM_VAR_FULL(_name, _var) \ + rw_buffer_t _name; \ rw_buffer_init(&_name, &_var, sizeof(_var), sizeof(_var)) #define RW_BUFFER_FROM_VAR_EMPTY(_name, _var) \ - rw_buffer_t _name; \ + rw_buffer_t _name; \ rw_buffer_init(&_name, &_var, sizeof(_var), 0) -#define RW_BUFFER_NEW_LOCAL_EMPTY(_name, _size) \ - uint8_t __##_name[_size]; \ - rw_buffer_t _name; \ +#define RW_BUFFER_NEW_LOCAL_EMPTY(_name, _size) \ + uint8_t __##_name[_size]; \ + rw_buffer_t _name; \ rw_buffer_init(&_name, __##_name, _size, 0) /** * Struct for buffer with size and read+write offset. */ typedef struct { - buffer_t read; /// read buffer. size is a write offset. - size_t size; /// full allocated size of the buffer + buffer_t read; /// read buffer. size is a write offset. + size_t size; /// full allocated size of the buffer } rw_buffer_t; - /** * Initialize buffer. * @@ -110,7 +109,7 @@ static inline const uint8_t *rw_buffer_read_ptr(const rw_buffer_t *buffer) { * */ static inline uint8_t *rw_buffer_write_ptr(rw_buffer_t *buffer) { - return ((uint8_t* )buffer->read.ptr) + buffer->read.size; + return ((uint8_t *) buffer->read.ptr) + buffer->read.size; } /** @@ -281,7 +280,9 @@ static inline bool rw_buffer_read_u8(rw_buffer_t *buffer, uint8_t *value) { * @return true if success, false otherwise. * */ -static inline bool rw_buffer_read_u16(rw_buffer_t *buffer, uint16_t *value, endianness_t endianness) { +static inline bool rw_buffer_read_u16(rw_buffer_t *buffer, + uint16_t *value, + endianness_t endianness) { return buffer_read_u16(&buffer->read, value, endianness); } @@ -298,7 +299,9 @@ static inline bool rw_buffer_read_u16(rw_buffer_t *buffer, uint16_t *value, endi * @return true if success, false otherwise. * */ -static inline bool rw_buffer_read_u32(rw_buffer_t *buffer, uint32_t *value, endianness_t endianness) { +static inline bool rw_buffer_read_u32(rw_buffer_t *buffer, + uint32_t *value, + endianness_t endianness) { return buffer_read_u32(&buffer->read, value, endianness); } @@ -315,7 +318,9 @@ static inline bool rw_buffer_read_u32(rw_buffer_t *buffer, uint32_t *value, endi * @return true if success, false otherwise. * */ -static inline bool rw_buffer_read_u64(rw_buffer_t *buffer, uint64_t *value, endianness_t endianness) { +static inline bool rw_buffer_read_u64(rw_buffer_t *buffer, + uint64_t *value, + endianness_t endianness) { return buffer_read_u64(&buffer->read, value, endianness); } diff --git a/src/context.h b/src/context.h index fc3d714f..88cda123 100644 --- a/src/context.h +++ b/src/context.h @@ -24,82 +24,82 @@ typedef struct { /** * Global application context -*/ + */ extern app_ctx_t G_app_context; /** * Check is ui busy -*/ + */ static inline bool app_is_ui_busy() { return G_app_context.is_ui_busy; } /** * Set UI busy -*/ + */ static inline void app_set_ui_busy(bool is_busy) { G_app_context.is_ui_busy = is_busy; } /** * Get connected application id. -*/ + */ static inline uint32_t app_connected_app_id(void) { return G_app_context.connected_app_id; } /** * Set connected application id. -*/ + */ static inline void app_set_connected_app_id(uint32_t id) { G_app_context.connected_app_id = id; } /** * Get session key. -*/ + */ static inline const uint8_t* app_session_key(void) { return G_app_context.session_key; } /** * Get current command key. -*/ + */ static inline command_e app_current_command(void) { return G_app_context.current_command; } /** * Attest Input command context -*/ + */ static inline attest_input_ctx_t* app_attest_input_context(void) { return &G_app_context.commands_ctx.attest_input; } /** * Sign Transaction command context -*/ + */ static inline sign_transaction_ctx_t* app_sign_transaction_context(void) { return &G_app_context.commands_ctx.sign_tx; } /** * Derive Address command context -*/ + */ static inline derive_address_ctx_t* app_derive_address_context(void) { return &G_app_context.commands_ctx.derive_address; } /** * Extended Public Key command context -*/ + */ static inline extended_public_key_ctx_t* app_extended_public_key_context(void) { return &G_app_context.commands_ctx.ext_pub_key; } /** * Init application context -*/ + */ void app_init(void); /** diff --git a/src/helpers/cmd_macros.h b/src/helpers/cmd_macros.h index 98f8b6ab..edd5d0c1 100644 --- a/src/helpers/cmd_macros.h +++ b/src/helpers/cmd_macros.h @@ -13,8 +13,9 @@ #define CHECK_PROPER_STATE(_ctx, _state) \ if (_ctx->state != _state) return COMMAND_ERROR_HANDLER(_ctx, SW_BAD_STATE) -#define CHECK_PROPER_STATES(_ctx, _state1, _state2) \ - if (_ctx->state != _state1 && _ctx->state != _state2) return COMMAND_ERROR_HANDLER(_ctx, SW_BAD_STATE) +#define CHECK_PROPER_STATES(_ctx, _state1, _state2) \ + if (_ctx->state != _state1 && _ctx->state != _state2) \ + return COMMAND_ERROR_HANDLER(_ctx, SW_BAD_STATE) #define CHECK_READ_PARAM(_ctx, _call) \ if (!_call) return COMMAND_ERROR_HANDLER(_ctx, SW_NOT_ENOUGH_DATA) @@ -22,9 +23,9 @@ #define CHECK_PARAMS_FINISHED(_ctx, _buffer) \ if (buffer_can_read(_buffer, 1)) return COMMAND_ERROR_HANDLER(_ctx, SW_TOO_MUCH_DATA) -#define CHECK_CALL_RESULT_SW_OK(_ctx, _call) \ - do { \ - uint16_t _res = _call; \ +#define CHECK_CALL_RESULT_SW_OK(_ctx, _call) \ + do { \ + uint16_t _res = _call; \ if (_res != SW_OK) return COMMAND_ERROR_HANDLER(_ctx, _res); \ } while (0) diff --git a/src/ui/ui_main.h b/src/ui/ui_main.h index 5a4c0f44..d14d3d1b 100644 --- a/src/ui/ui_main.h +++ b/src/ui/ui_main.h @@ -8,7 +8,7 @@ /** * Global array for UI screen flow */ -extern ux_flow_step_t const *G_ux_flow_steps[MAX_NUMBER_OF_SCREENS + 1]; +extern ux_flow_step_t const* G_ux_flow_steps[MAX_NUMBER_OF_SCREENS + 1]; static inline const ux_flow_step_t** ui_next_sreen_ptr(uint8_t* position) { if (*position >= MAX_NUMBER_OF_SCREENS) return NULL; @@ -21,7 +21,7 @@ static inline bool ui_add_screen(const ux_flow_step_t* screen, uint8_t* position return true; } -static inline bool ui_display_screens(uint8_t *postition) { +static inline bool ui_display_screens(uint8_t* postition) { if (MAX_NUMBER_OF_SCREENS - *postition < 2) return false; G_ux_flow_steps[(*postition)++] = FLOW_LOOP; @@ -35,4 +35,3 @@ static inline bool ui_display_screens(uint8_t *postition) { } #endif - diff --git a/src/ui/ui_menu.h b/src/ui/ui_menu.h index c4258c9e..d9c69e08 100644 --- a/src/ui/ui_menu.h +++ b/src/ui/ui_menu.h @@ -8,4 +8,4 @@ void ui_menu_main(void); /** * Show about submenu (copyright, date). */ -void ui_menu_about(void); +void ui_menu_about(void);