cyberjax

SmartMatrix code puzzling me.

3 posts in this topic

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();
        }  
}

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now