Skip to content

Commit

Permalink
Merge pull request #364 from LedgerHQ/do-not-use-anonymous-struct-any…
Browse files Browse the repository at this point in the history
…more

Do not use anonymous struct anymore
  • Loading branch information
nroggeman-ledger authored Jun 29, 2023
2 parents 2229bc2 + 5d33dfe commit 0302de8
Show file tree
Hide file tree
Showing 12 changed files with 753 additions and 770 deletions.
2 changes: 0 additions & 2 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOS TARGET_NANOX TARGET_NA
SDK_SOURCE_PATH += lib_bagl lib_ux
else ifeq ($(TARGET_NAME),TARGET_STAX)
SDK_SOURCE_PATH += lib_nbgl lib_ux_stax qrcode lib_nfc
CFLAGS += -fms-extensions
CFLAGS += -Wno-microsoft-anon-tag
endif

# adding the correct target header to sources
Expand Down
37 changes: 15 additions & 22 deletions lib_nbgl/include/nbgl_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,13 @@ typedef struct {
*/
typedef void (*nbgl_touchCallback_t)(void *obj, nbgl_touchType_t eventType) ;

#ifdef __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmicrosoft-anon-tag"
#endif // __clang__
/**
* @brief Common structure for all graphical objects
*
* @note this type must never be instantiated
*/
typedef struct PACKED__ nbgl_obj_s {
struct nbgl_area_s ; ///< absolute position, backGround color and size of the object. DO NOT MOVE THIS FIELD
nbgl_area_t area; ///< absolute position, backGround color and size of the object. DO NOT MOVE THIS FIELD
nbgl_obj_type_t type; ///< type of the graphical object, must be explicitly set
int16_t rel_x0; ///< horizontal position of top-left corner relative to parent's top-left corner
int16_t rel_y0; ///< vertical position of top-left corner relative to parent's top-left corner, must be multiple of 4
Expand All @@ -207,7 +203,7 @@ typedef struct PACKED__ nbgl_obj_s {
*
*/
typedef struct PACKED__ nbgl_container_s {
struct nbgl_obj_s; ///< common part
nbgl_obj_t obj; ///< common part
nbgl_direction_t layout; ///< layout of children inside this object
uint8_t nbChildren;
bool forceClean; ///< if set to true, a paint will be done with background color
Expand All @@ -219,7 +215,7 @@ typedef struct PACKED__ nbgl_container_s {
*
*/
typedef struct PACKED__ nbgl_line_s {
struct nbgl_obj_s; ///< common part
nbgl_obj_t obj; ///< common part
nbgl_direction_t direction; ///< direction of the line, e.g @ref VERTICAL or @ref HORIZONTAL
color_t lineColor; ///< color of the line
uint8_t thickness; ///< thickness of the line in pixel, maybe different from height for horizontal line
Expand All @@ -238,7 +234,7 @@ typedef nbgl_icon_details_t* (*onImageDrawCallback_t)(uint8_t token);
*
*/
typedef struct PACKED__ nbgl_image_s {
struct nbgl_obj_s; // common part
nbgl_obj_t obj; // common part
color_t foregroundColor; ///< color set to '1' bits, for 1PBB images. '0' are set to background color.
const nbgl_icon_details_t *buffer; ///< buffer containing bitmap, with exact same size as object (width*height*bpp/8 bytes)
onImageDrawCallback_t onDrawCallback; ///< function called if buffer is NULL, with above token as parameter. Can be NULL
Expand All @@ -251,7 +247,7 @@ typedef struct PACKED__ nbgl_image_s {
*
*/
typedef struct PACKED__ nbgl_image_file_s {
struct nbgl_obj_s; // common part
nbgl_obj_t obj; // common part
const uint8_t *buffer; ///< buffer containing image file
} nbgl_image_file_t;

Expand All @@ -260,7 +256,7 @@ typedef struct PACKED__ nbgl_image_file_s {
*
*/
typedef struct PACKED__ nbgl_qrcode_s {
struct nbgl_obj_s; // common part
nbgl_obj_t obj; // common part
color_t foregroundColor; ///< color set to '1' bits, for 1PBB images. '0' are set to background color.
nbgl_qrcode_version_t version; ///< requested version, if V10, size will be fixed to 228*228, if V4, size will be fixed to 132*132
const char *text; ///< text single line (NULL terminated)
Expand All @@ -273,7 +269,7 @@ typedef struct PACKED__ nbgl_qrcode_s {
*
*/
typedef struct PACKED__ nbgl_radio_s {
struct nbgl_obj_s; // common part
nbgl_obj_t obj; // common part
color_t activeColor; ///< color set to to inner circle, when active.
color_t borderColor; ///< color set to border.
nbgl_state_t state; ///< state of the radio button. Active is when state == @ref ON_STATE
Expand All @@ -284,7 +280,7 @@ typedef struct PACKED__ nbgl_radio_s {
*
*/
typedef struct PACKED__ nbgl_switch_s {
struct nbgl_obj_s; // common part
nbgl_obj_t obj; // common part
color_t onColor; ///< color set to border and knob, when ON (knob on the right).
color_t offColor; ///< color set to border and knob, when OFF (knob on the left).
nbgl_state_t state; ///< state of the switch.
Expand All @@ -295,7 +291,7 @@ typedef struct PACKED__ nbgl_switch_s {
* @note if withBorder, the stroke of the border is fixed (3 pixels)
*/
typedef struct PACKED__ nbgl_progress_bar_s {
struct nbgl_obj_s; // common part
nbgl_obj_t obj; // common part
bool withBorder; ///< if set to true, a border in black surround the whole object
uint8_t state; ///< state of the progress, in % (from 0 to 100).
color_t foregroundColor; ///< color of the inner progress bar and border (if applicable)
Expand All @@ -309,7 +305,7 @@ typedef struct PACKED__ nbgl_progress_bar_s {
* @note height is fixed
*/
typedef struct PACKED__ nbgl_navigation_bar_s {
struct nbgl_obj_s; ///< common part
nbgl_obj_t obj; ///< common part
uint8_t nbPages; ///< number of pages.
uint8_t activePage; ///< index of active page (from 0 to nbPages-1).
} nbgl_page_indicator_t;
Expand All @@ -328,7 +324,7 @@ typedef char* (*onTextDrawCallback_t)(uint8_t token);
*
*/
typedef struct PACKED__ nbgl_button_s {
struct nbgl_obj_s; ///< common part
nbgl_obj_t obj; ///< common part
color_t innerColor; ///< color set inside of the button
color_t borderColor; ///< color set to button's border
color_t foregroundColor; ///< color set to '1' bits in icon, and text. '0' are set to innerColor color.
Expand All @@ -349,7 +345,7 @@ typedef struct PACKED__ nbgl_button_s {
*
*/
typedef struct PACKED__ nbgl_text_area_s {
struct nbgl_obj_s; ///< common part
nbgl_obj_t obj; ///< common part
color_t textColor; ///< color set to '1' bits in text. '0' are set to backgroundColor color.
nbgl_aligment_t textAlignment; ///< alignment of text within the area
nbgl_style_t style; ///< to define the style of border
Expand All @@ -371,7 +367,7 @@ typedef struct PACKED__ nbgl_text_area_s {
*
*/
typedef struct PACKED__ nbgl_spinner_s {
struct nbgl_obj_s; ///< common part
nbgl_obj_t obj; ///< common part
uint8_t position; ///< position of the spinner (from 0 to 3). If set to 0xFF, the spinner is entirely black
} nbgl_spinner_t;

Expand Down Expand Up @@ -407,7 +403,7 @@ typedef enum {
*
*/
typedef struct PACKED__ nbgl_keyboard_s {
struct nbgl_obj_s; ///< common part
nbgl_obj_t obj; ///< common part
color_t textColor; ///< color set to letters.
color_t borderColor; ///< color set to key borders
bool lettersOnly; ///< if true, only display letter keys and Backspace
Expand All @@ -424,7 +420,7 @@ typedef struct PACKED__ nbgl_keyboard_s {
*
*/
typedef struct PACKED__ nbgl_keypad_s {
struct nbgl_obj_s; ///< common part
nbgl_obj_t obj; ///< common part
color_t textColor; ///< color set to digits.
color_t borderColor; ///< color set to key borders
bool enableBackspace; ///< if true, Backspace key is enabled
Expand All @@ -434,9 +430,6 @@ typedef struct PACKED__ nbgl_keypad_s {
uint8_t digitIndexes[5]; ///< array of digits indexes, 4 bits per digit
keyboardCallback_t callback; ///< function called when an active key is pressed
} nbgl_keypad_t;
#ifdef __clang__
#pragma GCC diagnostic pop
#endif // __clang__

/**********************
* GLOBAL PROTOTYPES
Expand Down
14 changes: 3 additions & 11 deletions lib_nbgl/include/nbgl_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ typedef void (*nbgl_tickerCallback_t)(void);
*
*/
typedef struct PACKED__ nbgl_screenTickerConfiguration_s {
nbgl_touchCallback_t touchCallback; ///< function to be called on events defined in touchMask field in each sub-object
nbgl_tickerCallback_t tickerCallback; ///< callback called when ticker timer is fired. Set to NULL for no ticker
uint32_t tickerValue; ///< timer initial value, in ms (should be multiple of 100 ms). Set to 0 for no ticker
uint32_t tickerIntervale; ///< for periodic timers, the intervale in ms to rearm the timer (should be multiple of 100 ms). Set to 0 for one-shot timers
Expand All @@ -48,20 +47,13 @@ typedef struct PACKED__ nbgl_screenTickerConfiguration_s {
* @note inherits from container
*
*/
#ifdef __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmicrosoft-anon-tag"
#endif // __clang__
typedef struct PACKED__ nbgl_screen_s {
struct nbgl_container_s; ///< common part
struct nbgl_screenTickerConfiguration_s; ///< ticker configuration
nbgl_container_t container; ///< common part
nbgl_screenTickerConfiguration_t ticker; ///< ticker configuration
nbgl_touchCallback_t touchCallback; ///< function to be called on events defined in touchMask field in each sub-object
struct nbgl_screen_s *next; ///< pointer to screen on top of this one (or NULL is this screen is top of stack)
struct nbgl_screen_s *previous; ///< pointer to screen on bottom of this one (or NULL is this screen is bottom of stack)
} nbgl_screen_t;
#ifdef __clang__
#pragma GCC diagnostic pop
#endif // __clang__


/**********************
* GLOBAL PROTOTYPES
Expand Down
2 changes: 1 addition & 1 deletion lib_nbgl/serialization/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ INC := -I ../include/ -I ../../lib_ux_stax/
DEFINES := -DLINUX_SIMU -DHAVE_LANGUAGE_PACK -DNBGL_GENERATE_DATA_TEST

default: generate_data_test.c
gcc $(INC) -fms-extensions generate_data_test.c $(DEFINES) ../src/nbgl_serialize.c -o generate_data_test
gcc $(INC) generate_data_test.c $(DEFINES) ../src/nbgl_serialize.c -o generate_data_test

run_test: default
./generate_data_test > data_test.txt
Expand Down
24 changes: 12 additions & 12 deletions lib_nbgl/src/nbgl_bottom_button.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,36 +56,36 @@ nbgl_container_t *nbgl_bottomButtonPopulate(const nbgl_icon_details_t *icon, boo
nbgl_container_t *container;

container = (nbgl_container_t *)nbgl_objPoolGet(CONTAINER, layer);
container->width = SCREEN_WIDTH;
container->height = BUTTON_DIAMETER+2*BORDER_MARGIN;
container->obj.area.width = SCREEN_WIDTH;
container->obj.area.height = BUTTON_DIAMETER+2*BORDER_MARGIN;
container->layout = HORIZONTAL ;
container->nbChildren = NB_MAX_CHILDREN;
container->children = (nbgl_obj_t**)nbgl_containerPoolGet(container->nbChildren, layer);
container->alignment = NO_ALIGNMENT;
container->obj.alignment = NO_ALIGNMENT;

button = (nbgl_button_t*)nbgl_objPoolGet(BUTTON,layer);
button->innerColor = WHITE;
button->borderColor = LIGHT_GRAY;
button->width = BUTTON_DIAMETER;
button->height = BUTTON_DIAMETER;
button->obj.area.width = BUTTON_DIAMETER;
button->obj.area.height = BUTTON_DIAMETER;
button->radius = BUTTON_RADIUS;
button->icon = icon;
button->alignment = CENTER;
button->touchMask = (1<<TOUCHED);
button->obj.alignment = CENTER;
button->obj.touchMask = (1<<TOUCHED);
container->children[QUIT_BUTTON_INDEX] = (nbgl_obj_t*)button;

if (separationLine) {
nbgl_line_t *line;
// create horizontal line
line = (nbgl_line_t*)nbgl_objPoolGet(LINE,0);
line->lineColor = LIGHT_GRAY;
line->width = SCREEN_WIDTH;
line->height = 4;
line->obj.area.width = SCREEN_WIDTH;
line->obj.area.height = 4;
line->direction = HORIZONTAL;
line->thickness = 1;
line->alignmentMarginY = BORDER_MARGIN-4;
line->alignTo = (nbgl_obj_t*)button;
line->alignment = TOP_MIDDLE;
line->obj.alignmentMarginY = BORDER_MARGIN-4;
line->obj.alignTo = (nbgl_obj_t*)button;
line->obj.alignment = TOP_MIDDLE;
container->children[LINE_INDEX] = (nbgl_obj_t*)line;
}

Expand Down
Loading

0 comments on commit 0302de8

Please sign in to comment.