Skip to content

Commit 1276ce5

Browse files
committed
Fix display orientation for _stage module
Initially this library assumed the display is rotated by 90 degrees, so the x and y were swapped. I'm now handling the display rotation in the driver, with the hardware display settings, so the library should use a sane order of x and y. This way it will work with any display orientation.
1 parent 27d5f27 commit 1276ce5

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

shared-module/_stage/Layer.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ uint16_t get_layer_pixel(layer_obj_t *layer, int16_t x, uint16_t y) {
4747
uint8_t tx = x >> 4;
4848
uint8_t ty = y >> 4;
4949

50-
frame = layer->map[(tx * layer->width + ty) >> 1];
51-
if (ty & 0x01) {
50+
frame = layer->map[(ty * layer->width + tx) >> 1];
51+
if (tx & 0x01) {
5252
frame &= 0x0f;
5353
} else {
5454
frame >>= 4;
@@ -60,41 +60,41 @@ uint16_t get_layer_pixel(layer_obj_t *layer, int16_t x, uint16_t y) {
6060
y &= 0x0f;
6161

6262
// Rotate the image.
63-
uint8_t tx = x; // Temporary variable for swapping.
63+
uint8_t ty = y; // Temporary variable for swapping.
6464
switch (layer->rotation) {
6565
case 1: // 90 degrees clockwise
66-
x = 15 - y;
67-
y = tx;
66+
y = 15 - x;
67+
x = ty;
6868
break;
6969
case 2: // 180 degrees
70-
x = 15 - tx;
71-
y = 15 - y;
70+
y = 15 - ty;
71+
x = 15 - x;
7272
break;
7373
case 3: // 90 degrees counter-clockwise
74-
x = y;
75-
y = 15 - tx;
74+
y = x;
75+
x = 15 - ty;
7676
break;
7777
case 4: // 0 degrees, mirrored
78-
y = 15 - y;
78+
x = 15 - x;
7979
break;
8080
case 5: // 90 degrees clockwise, mirrored
81-
x = y;
82-
y = tx;
81+
y = x;
82+
x = ty;
8383
break;
8484
case 6: // 180 degrees, mirrored
85-
x = 15 - tx;
85+
y = 15 - ty;
8686
break;
8787
case 7: // 90 degrees counter-clockwise, mirrored
88-
x = 15 - y;
89-
y = 15 - tx;
88+
y = 15 - x;
89+
x = 15 - ty;
9090
break;
9191
default: // 0 degrees
9292
break;
9393
}
9494

9595
// Get the value of the pixel.
96-
uint8_t pixel = layer->graphic[(frame << 7) + (x << 3) + (y >> 1)];
97-
if (y & 0x01) {
96+
uint8_t pixel = layer->graphic[(frame << 7) + (y << 3) + (x >> 1)];
97+
if (x & 0x01) {
9898
pixel &= 0x0f;
9999
} else {
100100
pixel >>= 4;

shared-module/_stage/Text.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ uint16_t get_text_pixel(text_obj_t *text, int16_t x, uint16_t y) {
5959
y &= 0x07;
6060

6161
// Get the value of the pixel.
62-
uint8_t pixel = text->font[(c << 4) + (x << 1) + (y >> 2)];
63-
pixel = ((pixel >> ((y & 0x03) << 1)) & 0x03) + color_offset;
62+
uint8_t pixel = text->font[(c << 4) + (y << 1) + (x >> 2)];
63+
pixel = ((pixel >> ((x & 0x03) << 1)) & 0x03) + color_offset;
6464

6565
// Convert to 16-bit color using the palette.
6666
return text->palette[pixel << 1] | text->palette[(pixel << 1) + 1] << 8;

0 commit comments

Comments
 (0)