15,793,535 members
See more:
I have a series of 8x8 LED matrices. They can be daisy chained, and should be able to be arranged in a grid, such that you can specify the number segments and the segments in width and it will arrange the "display surface" such that those matrices present a unified whole surface to display on. That way you can chain up to 256 of them together on a single SPI bus for a large display.

The trouble is this: The display hardware doesn't know about multiple rows of segments. It assumes that the segments are all arranged left to right.

Consequently, my frame buffer which holds a bit for each individual LED must be a long "strip" instead of a rectangle.

I'm having trouble computing the framebuffer such that every N segments is a new row. It should be easy but my head just isn't wrapping around it right now. I just need to fill or clear the right bits in the frame buffer memory and i need the algorithm to find the offset.

So like each [] is 1 8x8 matrix.

you can lay them out like this
[][][][]
[][][][]
but the frame buffer must be laid out as though it's like this:
[][][][][][][][]

It's simple math but I'm just not getting there at the moment. More coffee?

What I have tried:

C++
```for(int y = 0;y<h;++y) {
const int yy = (y+b.y1)&7;
const int xx = b.x1 + (y/8)*???; // GRRRR!
const size_t offs = ((y+b.y1)*width+(b.x1)); // wrong too
uint8_t* const pbegin = m_frame_buffer+(offs/8);
// just sets a range of bits of a particular length to a value. this works.
bits::set_bits(pbegin,offs%8,w,color);
}```
Posted
Updated 26-Mar-22 20:51pm
v2
k5054 26-Mar-22 21:40pm
Would it be correct to assume that you work with a buffer then tell the display that you have some data for it? In which case, if the [8x8]xn array for the display is contiguous, can't you just work with the 8x8 cells as a 8x8xn array and then inform the display that you've got data starting at location X of length n (or whatever it requires)?
Just trying to understand the problem ... since an `int X[a][b][c]` covers a*b*c*sizeof(int) bytes, its directly analogous to `int X[a*b*c]` If that works for you, you could venture into the dangerous world of type-punning or abuse of unions.
honey the codewitch 26-Mar-22 21:59pm
Yes that would be correct. As far as your solution, I'll have to think about it. It does give me an idea. There's a chance it will complicate another part of the code and right now I'm too foggy to determine whether it will without diving into it.

## Solution 1

My initial code (not the above) was actually correct. The frame buffer is in the final format. I was interpreting this code incorrectly on account of me being hasty and it being old.

I just needed an outer loop in my update code.

C++
```int line = 0;
for(int y=0;y<height;y+=8) {
for(int x = 0;x<width;x+=8) {
for(int yy=0;yy<8;++yy) {
int yyy = y + yy;
if(x<=bounds.x2&&x+7>=bounds.x1&&yyy<=bounds.y2&&yyy>=bounds.y1) {
const uint8_t* p = m_frame_buffer+(yyy*width+x)/8;
if(!set_line(line,*p)) {
return false;
}
}
++line;
}
}
}```

That gets the frame buffer out to the matrices in the right order.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Rick York 90 Chris Copeland 65 Dave Kreskowiak 40 Richard MacCutchan 20 KarstenK 20
 Andre Oosthuizen 200 Rick York 90 Maxim Kartavenkov 90 CPallini 68 Chris Copeland 65

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900