From 9d2c1e62cfeea57d67fe188198b9cf1c6e390f76 Mon Sep 17 00:00:00 2001 From: Chi-Feng Tsai Date: Wed, 24 Jul 2024 10:09:47 +0800 Subject: [PATCH] fix bug of display rotation --- fw/Core/Hitcon/Logic/Display/display.cc | 8 +------- fw/Core/Hitcon/Logic/Display/display.h | 12 ++++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/fw/Core/Hitcon/Logic/Display/display.cc b/fw/Core/Hitcon/Logic/Display/display.cc index 8715df10..adc75ad8 100644 --- a/fw/Core/Hitcon/Logic/Display/display.cc +++ b/fw/Core/Hitcon/Logic/Display/display.cc @@ -108,13 +108,7 @@ void display_get_frame_packed(display_buf_t *buf, int frame) { } if (display_orientation) { - uint8_t tmp[DISPLAY_HEIGHT][DISPLAY_WIDTH]; - for (int y = 0; y < DISPLAY_HEIGHT; y++) { - for (int x = 0; x < DISPLAY_WIDTH; x++) { - tmp[y][x] = buf[sizeof(tmp) - 1 - (y * DISPLAY_WIDTH + x)]; - } - } - memcpy(buf, tmp, sizeof(tmp)); + display_buf_rotate_180(buf); } display_current_frame = frame; diff --git a/fw/Core/Hitcon/Logic/Display/display.h b/fw/Core/Hitcon/Logic/Display/display.h index d360385e..6228f0b5 100644 --- a/fw/Core/Hitcon/Logic/Display/display.h +++ b/fw/Core/Hitcon/Logic/Display/display.h @@ -3,6 +3,7 @@ #include #include +#include // clang-format off /** @@ -108,6 +109,17 @@ inline void display_buf_unpack(uint8_t *dst, const display_buf_t *src, } } +inline void display_buf_rotate_180(display_buf_t *buf) { + display_buf_t tmp[DISPLAY_WIDTH]; + for (int y = 0; y < DISPLAY_HEIGHT; ++y) { + for (int x = 0; x < DISPLAY_WIDTH; ++x) { + display_buf_assign(tmp[DISPLAY_WIDTH - 1 - x], DISPLAY_HEIGHT - 1 - y, + display_buf_get(buf[x], y)); + } + } + memcpy(buf, tmp, sizeof(tmp)); +} + void display_init(); // Toggle the orientation of the display.