SmartMatrix code puzzling me.


cyberjax

Recommended Posts

I've been all through the SmartMatrix sketch and circuit.  I believe I understand every line of code except for the impact soff has on the Wishbone port.  See code below.

First. why does it start with 32*128?  Looking at the VHDL associated with the circuit, it appears to have no impact at all.

Second, why is it incremented by 128 for every increment of y instead of 32?  At first I thought that it was to adjust for 4 addresses for every 32 bit word, but the REGISTER macro adjusts for that by shifting the offset parameter by 2;  I can't see where the gap in addresses are accounted for in the VHDL

 

void SmartMatrix::apply(void) {

 uint8_t r,g,b,brightness;
 uint16_t temp0red,temp0green,temp0blue,temp1red,temp1green,temp1blue;

 bool bHasForeground = hasForeground;
 bool bHasCC = SmartMatrix::_ccmode != ccNone;

        int x,y;
        unsigned offset = 32*128;
        unsigned soff = offset;

  rgb24 *pix = &currentDrawBufferPtr[0][0];

  rgb24 tempPixel0;
  
        for (y=0;y<MATRIX_HEIGHT;y++) {

            for (x=0;x<MATRIX_WIDTH;x++) {
    brightness = dimmingFactor;
    
    
/*    if (bHasForeground && getForegroundPixel(x, y, &tempPixel0)) {
    if(bHasCC) {
     // load foreground pixel with color correction
     r = colorCorrection(tempPixel0.red);
     g = colorCorrection(tempPixel0.green);
     b = colorCorrection(tempPixel0.blue);
    } else {
     // load foreground pixel without color correction
     r = tempPixel0.red;
     g = tempPixel0.green;
     b = tempPixel0.blue;
    }
   } else {
    if(bHasCC) {
     // load background pixel with color correction
     r = backgroundColorCorrection(pix->red);
     g = backgroundColorCorrection(pix->green);
     b = backgroundColorCorrection(pix->blue);
    } else {
     // load background pixel without color correction
     r = pix->red;
     g = pix->green;
     b = pix->blue;
    }
   } */    
    
    
    if (bHasForeground && getForegroundPixel(x, y, &tempPixel0)) {
     r = tempPixel0.red;
     g = tempPixel0.green;
     b = tempPixel0.blue;    
    }
    else {
     r = pix->red;
     g = pix->green;
     b = pix->blue;
    }
    
    r = ((unsigned)r * brightness)>>8;
    g = ((unsigned)g * brightness)>>8;
    b = ((unsigned)b * brightness)>>8;    
    
    unsigned v = ((unsigned)r<<16) + ((unsigned)g<<8) + ((unsigned)b);
    REGISTER(IO_SLOT(9),soff + x) = v;
                pix++;
            }
            soff+=128;
   handleBufferSwap();
   handleForegroundDrawingCopy();
   calculateBackgroundLUT();
   updateForeground();
        }  
}

Link to comment
Share on other sites

Hello CyberJax,

I was just heading out for a weekend getaway so I'm not going to have a chance to look at this until Monday. It's been a while since I looked at this code so I need to look it over again to help with your questions. The code can probably use some cleaning up since it was originally written for 4 displays chained together.

In the meantime, here is the VHDL driver code that might help shed some light on your questions.

https://github.com/GadgetFactory/DesignLab_Examples/blob/master/libraries/RGB_Matrix/VIDEO_zpuino_wb_rgb_panel.vhd

Jack.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.