1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

Name unnamed structs and remove duplicated semicolons

This commit is contained in:
Themba Dube 2019-03-15 19:41:54 -04:00
parent 51824b4316
commit edb58cc61b
8 changed files with 71 additions and 51 deletions

View File

@ -39,7 +39,7 @@ typedef union {
struct {
MEM_UNIT used: 1; //1: if the entry is used
MEM_UNIT d_size: 31; //Size off the data (1 means 4 bytes)
};
} s;
MEM_UNIT header; //The header (used + d_size)
} lv_mem_header_t;
@ -92,9 +92,9 @@ void lv_mem_init(void)
#endif
lv_mem_ent_t * full = (lv_mem_ent_t *)work_mem;
full->header.used = 0;
full->header.s.used = 0;
/*The total mem size id reduced by the first header and the close patterns */
full->header.d_size = LV_MEM_SIZE - sizeof(lv_mem_header_t);
full->header.s.d_size = LV_MEM_SIZE - sizeof(lv_mem_header_t);
#endif
}
@ -147,8 +147,8 @@ void * lv_mem_alloc(uint32_t size)
/*Allocate a header too to store the size*/
alloc = LV_MEM_CUSTOM_ALLOC(size + sizeof(lv_mem_header_t));
if(alloc != NULL) {
((lv_mem_ent_t *) alloc)->header.d_size = size;
((lv_mem_ent_t *) alloc)->header.used = 1;
((lv_mem_ent_t *) alloc)->header.s.d_size = size;
((lv_mem_ent_t *) alloc)->header.s.used = 1;
alloc = &((lv_mem_ent_t *) alloc)->first_data;
}
#endif /* LV_ENABLE_GC */
@ -180,7 +180,7 @@ void lv_mem_free(const void * data)
#if LV_ENABLE_GC==0
/*e points to the header*/
lv_mem_ent_t * e = (lv_mem_ent_t *)((uint8_t *) data - sizeof(lv_mem_header_t));
e->header.used = 0;
e->header.s.used = 0;
#endif
#if LV_MEM_CUSTOM == 0
@ -190,8 +190,8 @@ void lv_mem_free(const void * data)
lv_mem_ent_t * e_next;
e_next = ent_get_next(e);
while(e_next != NULL) {
if(e_next->header.used == 0) {
e->header.d_size += e_next->header.d_size + sizeof(e->header);
if(e_next->header.s.used == 0) {
e->header.s.d_size += e_next->header.s.d_size + sizeof(e->header);
} else {
break;
}
@ -222,7 +222,7 @@ void * lv_mem_realloc(void * data_p, uint32_t new_size)
/*data_p could be previously freed pointer (in this case it is invalid)*/
if(data_p != NULL) {
lv_mem_ent_t * e = (lv_mem_ent_t *)((uint8_t *) data_p - sizeof(lv_mem_header_t));
if(e->header.used == 0) {
if(e->header.s.used == 0) {
data_p = NULL;
}
}
@ -281,7 +281,7 @@ void lv_mem_defrag(void)
while(1) {
/*Search the next free entry*/
while(e_free != NULL) {
if(e_free->header.used != 0) {
if(e_free->header.s.used != 0) {
e_free = ent_get_next(e_free);
} else {
break;
@ -293,8 +293,8 @@ void lv_mem_defrag(void)
/*Joint the following free entries to the free*/
e_next = ent_get_next(e_free);
while(e_next != NULL) {
if(e_next->header.used == 0) {
e_free->header.d_size += e_next->header.d_size + sizeof(e_next->header);
if(e_next->header.s.used == 0) {
e_free->header.s.d_size += e_next->header.s.d_size + sizeof(e_next->header);
} else {
break;
}
@ -326,11 +326,11 @@ void lv_mem_monitor(lv_mem_monitor_t * mon_p)
e = ent_get_next(e);
while(e != NULL) {
if(e->header.used == 0) {
if(e->header.s.used == 0) {
mon_p->free_cnt++;
mon_p->free_size += e->header.d_size;
if(e->header.d_size > mon_p->free_biggest_size) {
mon_p->free_biggest_size = e->header.d_size;
mon_p->free_size += e->header.s.d_size;
if(e->header.s.d_size > mon_p->free_biggest_size) {
mon_p->free_biggest_size = e->header.s.d_size;
}
} else {
mon_p->used_cnt++;
@ -360,7 +360,7 @@ uint32_t lv_mem_get_size(const void * data)
lv_mem_ent_t * e = (lv_mem_ent_t *)((uint8_t *) data - sizeof(lv_mem_header_t));
return e->header.d_size;
return e->header.s.d_size;
}
#else /* LV_ENABLE_GC */
@ -390,7 +390,7 @@ static lv_mem_ent_t * ent_get_next(lv_mem_ent_t * act_e)
next_e = (lv_mem_ent_t *) work_mem;
} else { /*Get the next entry */
uint8_t * data = &act_e->first_data;
next_e = (lv_mem_ent_t *)&data[act_e->header.d_size];
next_e = (lv_mem_ent_t *)&data[act_e->header.s.d_size];
if(&next_e->first_data >= &work_mem[LV_MEM_SIZE]) next_e = NULL;
}
@ -410,11 +410,11 @@ static void * ent_alloc(lv_mem_ent_t * e, uint32_t size)
void * alloc = NULL;
/*If the memory is free and big enough then use it */
if(e->header.used == 0 && e->header.d_size >= size) {
if(e->header.s.used == 0 && e->header.s.d_size >= size) {
/*Truncate the entry to the desired size */
ent_trunc(e, size),
e->header.used = 1;
e->header.s.used = 1;
/*Save the allocated data*/
alloc = &e->first_data;
@ -445,20 +445,20 @@ static void ent_trunc(lv_mem_ent_t * e, uint32_t size)
#endif
/*Don't let empty space only for a header without data*/
if(e->header.d_size == size + sizeof(lv_mem_header_t)) {
size = e->header.d_size;
if(e->header.s.d_size == size + sizeof(lv_mem_header_t)) {
size = e->header.s.d_size;
}
/* Create the new entry after the current if there is space for it */
if(e->header.d_size != size) {
if(e->header.s.d_size != size) {
uint8_t * e_data = &e->first_data;
lv_mem_ent_t * after_new_e = (lv_mem_ent_t *)&e_data[size];
after_new_e->header.used = 0;
after_new_e->header.d_size = e->header.d_size - size - sizeof(lv_mem_header_t);
after_new_e->header.s.used = 0;
after_new_e->header.s.d_size = e->header.s.d_size - size - sizeof(lv_mem_header_t);
}
/* Set the new size for the original entry */
e->header.d_size = size;
e->header.s.d_size = size;
}
#endif

View File

@ -15,6 +15,10 @@
* TYPEDEFS
**********************/
/* This typedef exists purely to keep -Wpedantic happy when the file is empty. */
/* It can be removed. */
typedef int keep_pedantic_happy;
/**********************
* STATIC PROTOTYPES
**********************/

View File

@ -228,4 +228,8 @@ static lv_res_t lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param
return res;
}
#else /* Enable this file at the top */
/* This dummy typedef exists purely to silence -Wpedantic. */
typedef int keep_pedantic_happy;
#endif

View File

@ -144,10 +144,10 @@ void lv_table_set_cell_value(lv_obj_t * table, uint16_t row, uint16_t col, const
}
/*Initialize the format byte*/
else {
format.align = LV_LABEL_ALIGN_LEFT;
format.right_merge = 0;
format.type = 0;
format.crop = 0;
format.s.align = LV_LABEL_ALIGN_LEFT;
format.s.right_merge = 0;
format.s.type = 0;
format.s.crop = 0;
}
@ -262,7 +262,7 @@ void lv_table_set_cell_align(lv_obj_t * table, uint16_t row, uint16_t col, lv_la
lv_table_cell_format_t format;
format.format_byte = ext->cell_data[cell][0];
format.align = align;
format.s.align = align;
ext->cell_data[cell][0] = format.format_byte;
}
@ -293,7 +293,7 @@ void lv_table_set_cell_type(lv_obj_t * table, uint16_t row, uint16_t col, uint8_
lv_table_cell_format_t format;
format.format_byte = ext->cell_data[cell][0];
format.type = type;
format.s.type = type;
ext->cell_data[cell][0] = format.format_byte;
}
@ -321,7 +321,7 @@ void lv_table_set_cell_crop(lv_obj_t * table, uint16_t row, uint16_t col, bool c
lv_table_cell_format_t format;
format.format_byte = ext->cell_data[cell][0];
format.crop = crop;
format.s.crop = crop;
ext->cell_data[cell][0] = format.format_byte;
}
@ -351,7 +351,7 @@ void lv_table_set_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col,
lv_table_cell_format_t format;
format.format_byte = ext->cell_data[cell][0];
format.right_merge = en ? 1 : 0;
format.s.right_merge = en ? 1 : 0;
ext->cell_data[cell][0] = format.format_byte;
refr_size(table);
}
@ -474,7 +474,7 @@ lv_label_align_t lv_table_get_cell_align(lv_obj_t * table, uint16_t row, uint16_
else {
lv_table_cell_format_t format;
format.format_byte = ext->cell_data[cell][0];
return format.align;
return format.s.align;
}
}
@ -498,7 +498,7 @@ lv_label_align_t lv_table_get_cell_type(lv_obj_t * table, uint16_t row, uint16_t
else {
lv_table_cell_format_t format;
format.format_byte = ext->cell_data[cell][0];
return format.type + 1; /*0,1,2,3 is stored but user sees 1,2,3,4*/
return format.s.type + 1; /*0,1,2,3 is stored but user sees 1,2,3,4*/
}
}
@ -522,7 +522,7 @@ lv_label_align_t lv_table_get_cell_crop(lv_obj_t * table, uint16_t row, uint16_t
else {
lv_table_cell_format_t format;
format.format_byte = ext->cell_data[cell][0];
return format.crop;
return format.s.crop;
}
}
@ -547,7 +547,7 @@ bool lv_table_get_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col)
else {
lv_table_cell_format_t format;
format.format_byte = ext->cell_data[cell][0];
return format.right_merge ? true : false;
return format.s.right_merge ? true : false;
}
}
@ -638,13 +638,13 @@ static bool lv_table_design(lv_obj_t * table, const lv_area_t * mask, lv_design_
if(ext->cell_data[cell]) {
format.format_byte = ext->cell_data[cell][0];
} else {
format.right_merge = 0;
format.align = LV_LABEL_ALIGN_LEFT;
format.type = 0;
format.crop = 1;
format.s.right_merge = 0;
format.s.align = LV_LABEL_ALIGN_LEFT;
format.s.type = 0;
format.s.crop = 1;
}
cell_style = ext->cell_style[format.type];
cell_style = ext->cell_style[format.s.type];
cell_area.x1 = cell_area.x2;
cell_area.x2 = cell_area.x1 + ext->col_w[col];
@ -653,7 +653,7 @@ static bool lv_table_design(lv_obj_t * table, const lv_area_t * mask, lv_design_
if(ext->cell_data[cell + col_merge] != NULL) {
format.format_byte = ext->cell_data[cell + col_merge][0];
if(format.right_merge) cell_area.x2 += ext->col_w[col + col_merge + 1];
if(format.s.right_merge) cell_area.x2 += ext->col_w[col + col_merge + 1];
else break;
} else {
break;
@ -669,7 +669,7 @@ static bool lv_table_design(lv_obj_t * table, const lv_area_t * mask, lv_design_
txt_area.y1 = cell_area.y1 + cell_style->body.padding.top;
txt_area.y2 = cell_area.y2 - cell_style->body.padding.bottom;
/*Align the content to the middle if not cropped*/
if(format.crop == 0) {
if(format.s.crop == 0) {
txt_flags = LV_TXT_FLAG_NONE;
} else {
txt_flags = LV_TXT_FLAG_EXPAND;
@ -679,12 +679,12 @@ static bool lv_table_design(lv_obj_t * table, const lv_area_t * mask, lv_design_
cell_style->text.letter_space, cell_style->text.line_space, lv_area_get_width(&txt_area), txt_flags);
/*Align the content to the middle if not cropped*/
if(format.crop == 0) {
if(format.s.crop == 0) {
txt_area.y1 = cell_area.y1 + h_row / 2 - txt_size.y / 2;
txt_area.y2 = cell_area.y1 + h_row / 2 + txt_size.y / 2;
}
switch(format.align) {
switch(format.s.align) {
default:
case LV_LABEL_ALIGN_LEFT:
txt_flags |= LV_TXT_FLAG_NONE;
@ -822,7 +822,7 @@ static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id)
if(ext->cell_data[cell + col_merge] != NULL) {
lv_table_cell_format_t format;
format.format_byte = ext->cell_data[cell + col_merge][0];
if(format.right_merge) txt_w += ext->col_w[col + col_merge + 1];
if(format.s.right_merge) txt_w += ext->col_w[col + col_merge + 1];
else break;
} else {
break;
@ -831,10 +831,10 @@ static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id)
lv_table_cell_format_t format;
format.format_byte = ext->cell_data[cell][0];
cell_style = ext->cell_style[format.type];
cell_style = ext->cell_style[format.s.type];
/*With text crop assume 1 line*/
if(format.crop) {
if(format.s.crop) {
h_max = LV_MATH_MAX(lv_font_get_height(cell_style->text.font) +
cell_style->body.padding.top + cell_style->body.padding.bottom,
h_max);

View File

@ -47,7 +47,7 @@ typedef union {
uint8_t right_merge:1;
uint8_t type:2;
uint8_t crop:1;
};
} s;
uint8_t format_byte;
}lv_table_cell_format_t;

View File

@ -184,4 +184,8 @@ static void mem_fill(lv_color_t * dest, uint32_t length, lv_color_t color)
#endif /*LV_USE_GPU*/
#else /* Enable this file at the top */
/* This dummy typedef exists purely to silence -Wpedantic. */
typedef int keep_pedantic_happy;
#endif

View File

@ -358,4 +358,8 @@ static lv_fs_res_t fs_dir_close (void * rddir_p)
return res;
}
#else /* Enable this file at the top */
/* This dummy typedef exists purely to silence -Wpedantic. */
typedef int keep_pedantic_happy;
#endif

View File

@ -421,4 +421,8 @@ static bool button_is_pressed(uint8_t id)
return false;
}
#else /* Enable this file at the top */
/* This dummy typedef exists purely to silence -Wpedantic. */
typedef int keep_pedantic_happy;
#endif