Skip to content

Commit

Permalink
clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
ypopovych committed Feb 13, 2024
1 parent a7d428b commit ec0b833
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 40 deletions.
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ SortIncludes: false
SpaceAfterCStyleCast: true
AllowShortCaseLabelsOnASingleLine: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
BinPackArguments: false
Expand Down
4 changes: 1 addition & 3 deletions src/common/buffer_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 20 additions & 15 deletions src/common/rwbuffer.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
24 changes: 12 additions & 12 deletions src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down
11 changes: 6 additions & 5 deletions src/helpers/cmd_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
#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)

#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)

Expand Down
5 changes: 2 additions & 3 deletions src/ui/ui_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {

Check failure on line 24 in src/ui/ui_main.h

View workflow job for this annotation

GitHub Actions / Check misspellings

postition ==> position
if (MAX_NUMBER_OF_SCREENS - *postition < 2) return false;

Check failure on line 25 in src/ui/ui_main.h

View workflow job for this annotation

GitHub Actions / Check misspellings

postition ==> position

G_ux_flow_steps[(*postition)++] = FLOW_LOOP;

Check failure on line 27 in src/ui/ui_main.h

View workflow job for this annotation

GitHub Actions / Check misspellings

postition ==> position
Expand All @@ -35,4 +35,3 @@ static inline bool ui_display_screens(uint8_t *postition) {
}

#endif

2 changes: 1 addition & 1 deletion src/ui/ui_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ void ui_menu_main(void);
/**
* Show about submenu (copyright, date).
*/
void ui_menu_about(void);
void ui_menu_about(void);

0 comments on commit ec0b833

Please sign in to comment.