Skip to content

Commit

Permalink
fix bug of display rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
ktpss95112 authored and john0312 committed Jul 24, 2024
1 parent 62738f9 commit 9d2c1e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 1 addition & 7 deletions fw/Core/Hitcon/Logic/Display/display.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions fw/Core/Hitcon/Logic/Display/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <Logic/Display/font.h>
#include <stdint.h>
#include <string.h>

// clang-format off
/**
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 9d2c1e6

Please sign in to comment.