Forum Rule: Always post complete source code & details to reproduce any issue!

# Thread: Multiple memory buffers for one DMA channel.

1. ## Multiple memory buffers for one DMA channel.

I am working on a project that involves an rgb LED matrix. I want to be able to have a faster refresh rate and have looked into DMA. I have the basics down doing transfers from one array to another but now I am trying to find a way to take 1 bit from each buffer and put that together to and write it to a port as a byte. Lets say I am doing 8 bit colour, I have a 3 bytes for each pixel on for red, green, and blue. I have these each in their own multidimensional arrays, and for each pixel I write there is a data line for red, green, and blue, so to use BAM I would need to take the first bit of each pixel, then the second, and so on (obviously each bit is going for longer). Is the scatter/gather method the best for this and if so how would I do it. I don't want to use the dma.h library because I want to get a good understanding of everything.

P.S. I am sorry if it is hard to understand my question I will provide clarification if need be.

2. This is unclear "Lets say I am doing 8 bit colour, I have a 3 bytes for each pixel on for red, green, and blue. I have these each in their own multidimensional arrays"

I understand that it is common to have each pixel represented by 8-bits red, 8-bits green and 8-bits blue. That is 24-bit color. What do you mean by 8-bit colour?

I understand a frame buffer as a single multidimensional array where each element is a pixel at 24-bits. What do you mean by each has their own multidimensional arrays?

3. So what I mean is in my code I have an array for red, for green and for blue.

Code:
```//THE COLOUR VALUES FOR EACH PIXEL
int red[32][32];
int green[32][32];
int blue[32][32];```

4. Unless this is purely for educational purposes you should probably just look at the SmartMatrix code: https://github.com/pixelmatix/SmartMatrix

5. I have looked through the code quite a bit and understand some of it but I am having trouble understanding how the buffering to the dma and then from that to the gpio.

6. You'll find it much much easier if you structure your data RGBRGBRGB... this'll make it faster to read but slower to write (in some cases). As you read the structure more frequently it's better to do this

Are you saying you have three data lines like such:
R
G
B

And each one is only one pin? The issue is DMA can only transfer a byte minimum

Can you give us a clearer picture of your setup?

7. Yes I am using one pin per each R G B, one pin for latch, for output enable, and for clock. Each red green and blue are in it's own multi-dimensional array. Would it be better to create a buffer from the data that is one long array?

8. Ah I follow you now.

RGBRGBRGBRGBRGB

You could DMA the first byte. Which will be RGBRGBRG to PortB. Then move your DMA pointer along 3 bits.

As PortB only has the pins, 0, 1, 2, 3, 16, 17, 18, 19 exposed your data will appear on:
0 R
1 G
2 B
3 Will be useless data and will render this pin unusable

I'm not sure if you can offset the data for DMA by less than a byte though so this may not be possible. As always check the datasheet

If it isn't you'll have to store your data like so:
RGB00000
RGB00000
RGB00000
As you can see a serious trade off of memory for speed

9. Yes on the datasheet you can only move the DMA pointer along a byte minimum. I will use the first method you suggested by using a different way to store the data. Thanks for all of the help!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•