I experimented with the memcpy function and it seems to work very well.
byte display_byte[3][64]; // display array - 64 bytes x 3 colours
byte buffer_byte[3][64]; // buffer copy test
void mem() {
memcpy(buffer_byte, display_byte, sizeof(buffer_byte)); // Copies Buffer display_byte to buffer_byte
}
I tried changing the 2D array to 3D, no luck. Trying to shift every 8th byte in one direction or another would be a nightmare. In looking at the i2c slave code, the slave sets x,y coordinates based on incoming data (64 bytes for each color). i.e.
if (c == 0){
for (byte x = 0; x < 8; x++){
for (byte y = 0; y < 8; y++){
PixelRGB *p = Colorduino.GetPixel(x,y); // my comment: Get.Pixel, actually "sets pixel" for writing in the offscreen framebuffer
p->r = Wire.read();
}
}
}
{
//1 pixel = 3 bytes B00000000 B00000000 B00000000.
//We send R then G then B bytes as 3 separate transfers
//This is because if we make the I2C buffer too large, we run out of SRAM for other things on our master Arduino
if (Wire.available()>66) { //when buffer full, process data. 66 = start byte + colour + 64 pixel data + end byte
// error check - make sure our data starts with the right byte
if (Wire.read() != START_OF_DATA) {
//else handle error by reading remaining data until end of data marker (if available)
while (Wire.available()>0 && Wire.read()!=END_OF_DATA) {}
return;
}
byte c = Wire.read(); //read our color byte so we know if these are the R, G or B pixels.
//depeding on c read pixels in as R G or B
//read red display data
if (c == 0){
for (byte x = 0; x < 8; x++){
for (byte y = 0; y < 8; y++){
PixelRGB *p = Colorduino.GetPixel(x,y);
p->r = Wire.read();
}
}
}
//read green display data
if (c == 1){
for (byte x = 0; x < 8; x++){
for (byte y = 0; y < 8; y++){
PixelRGB *p = Colorduino.GetPixel(x,y);
p->g = Wire.read();
}
}
}
//read blue display data
if (c == 2){
for (byte x = 0; x < 8; x++){
for (byte y = 0; y < 8; y++){
PixelRGB *p = Colorduino.GetPixel(x,y);
p->b = Wire.read();
}
}
}
//read end of data marker
if (Wire.read()==END_OF_DATA) {
//if colour is blue, then update display
if (c == 2){Colorduino.FlipPage();}
}
}
}
I'm thinking I could have the slave do the work in shifting pixels by adding additional i2c commands:
the following functions exist in the lib:
void FlipPage() { // my comment: offscreen to active framebuffer
cli();
// swap frame buffers
PixelRGB *tmp = curDrawFrame;
curDrawFrame = curWriteFrame;
curWriteFrame = tmp;
sei();
}
// get a pixel for writing in the offscreen framebuffer
PixelRGB *GetPixel(unsigned char x,unsigned char y) {
return curWriteFrame + (y * ColorduinoScreenWidth) + x;
}
// get a pixel from the active framebuffer
PixelRGB *GetDrawPixel(unsigned char x,unsigned char y) {
return curDrawFrame + (y * ColorduinoScreenWidth) + x;
}
// set a pixel in the offscreen frame buffer
void SetPixel(unsigned char x, unsigned char y, unsigned char r, unsigned char g, unsigned char b)
{
PixelRGB *p = GetPixel(x,y);
p->r = r;
p->g = g;
p->b = b;
}
Thanks again for your time.