Skip to content

Commit

Permalink
samples: drivers: display: fix mono buffer size
Browse files Browse the repository at this point in the history
Rounding errors due to the division of non-integrally divisible
buffer sizes lead to the loss of one byte. This can be avoided
with the DIV_ROUND_UP() macro.

Signed-off-by: Stephan Linz <linz@li-pro.net>
  • Loading branch information
rexut authored and MaureenHelm committed Jan 12, 2024
1 parent 6d53c2a commit e462656
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion samples/drivers/display/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ int main(void)
case PIXEL_FORMAT_MONO01:
case PIXEL_FORMAT_MONO10:
fill_buffer_fnc = fill_buffer_mono;
buf_size /= 8;
buf_size = DIV_ROUND_UP(DIV_ROUND_UP(
buf_size, NUM_BITS(uint8_t)), sizeof(uint8_t));
break;
default:
LOG_ERR("Unsupported pixel format. Aborting sample.");
Expand Down

0 comments on commit e462656

Please sign in to comment.