From 162a8f00c13ac0dfc8d9df0bccb269a0b67fc317 Mon Sep 17 00:00:00 2001 From: Stephan Linz Date: Mon, 1 Jan 2024 14:43:05 +0100 Subject: [PATCH] samples: drivers: display: support small displays With extremely small displays (much smaller than 64x24), the calculation of the blocks in the four corners fails. These might then be too large and no longer fit into the available area of the small displays. Signed-off-by: Stephan Linz --- samples/drivers/display/src/main.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/samples/drivers/display/src/main.c b/samples/drivers/display/src/main.c index 642558e2af95..a9267b51c747 100644 --- a/samples/drivers/display/src/main.c +++ b/samples/drivers/display/src/main.c @@ -210,8 +210,17 @@ int main(void) rect_h = 1; } - h_step = rect_h; - scale = (capabilities.x_resolution / 8) / rect_h; + if ((capabilities.x_resolution < 3 * rect_w) || + (capabilities.y_resolution < 3 * rect_h) || + (capabilities.x_resolution < 8 * rect_h)) { + rect_w = capabilities.x_resolution * 40 / 100; + rect_h = capabilities.y_resolution * 40 / 100; + h_step = capabilities.y_resolution * 20 / 100; + scale = 1; + } else { + h_step = rect_h; + scale = (capabilities.x_resolution / 8) / rect_h; + } rect_w *= scale; rect_h *= scale;