led: improve row_buf calculation

This commit is contained in:
Puck Meerburg
2026-02-23 18:49:26 +00:00
committed by hueso
parent 2bc8143045
commit f3819c84eb

View File

@@ -70,8 +70,8 @@ void display_make_buf(uint16_t *fb, struct row_buf *b, int i) {
b->pb_out = 0; b->pb_out = 0;
b->pb_drv = 0; b->pb_drv = 0;
uint16_t col1 = fb[i * 2]; uint32_t col1 = fb[i * 2];
uint16_t col2 = fb[i * 2 + 1]; uint32_t col2 = fb[i * 2 + 1];
#if NEEDS_SWAP #if NEEDS_SWAP
// On the first column, the lower two pins are swapped. Fix this in software. // On the first column, the lower two pins are swapped. Fix this in software.
@@ -83,17 +83,22 @@ void display_make_buf(uint16_t *fb, struct row_buf *b, int i) {
#endif #endif
// The LEDs are written in a zig-zag pattern. // The LEDs are written in a zig-zag pattern.
uint32_t merged = 0; //
merged |= ((col1 & 1) << 22); // The two rows are zippered together; use a slightly
merged |= ((col2 & 1) << 23); // optimized trick for this.
for (int j = 0; j < 11; j++) {
col1 >>= 1;
col2 >>= 1;
merged >>= 2; // We start off with 0b123456789ab
merged |= (col1 & 1) << 22; col1 = (col1 | (col1 << 8)) & 0x00FF00FF; // 0b------12--------456789ab
merged |= (col2 & 1) << 23; col2 = (col2 | (col2 << 8)) & 0x00FF00FF;
} col1 = (col1 | (col1 << 4)) & 0x0F0F0F0F; // 0b------12----4567----89ab
col2 = (col2 | (col2 << 4)) & 0x0F0F0F0F;
col1 = (col1 | (col1 << 2)) & 0x33333333;
col2 = (col2 | (col2 << 2)) & 0x33333333; // 0b------12--45--67--89--ab
col1 = (col1 | (col1 << 1)) & 0x55555555;
col2 = (col2 | (col2 << 1)) & 0x55555555; // 0b-----1-2-4-5-6-7-8-9-a-b
// Zip col1 and col2 together.
uint32_t merged = col1 | (col2 << 1);
// In this LED matrix, we set row N as a high output, // In this LED matrix, we set row N as a high output,
// then set all other lines to tristate or low, depending // then set all other lines to tristate or low, depending