⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smi2d.c

📁 sm501 芯片的linux驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
    }

    regWrite32(DE_FOREGROUND,
        FIELD_VALUE(0, DE_FOREGROUND, COLOR, nColor));

    regWrite32(DE_DESTINATION,
        FIELD_SET  (0, DE_DESTINATION, WRAP, DISABLE) |
        FIELD_VALUE(0, DE_DESTINATION, X,    dst_X)     |
        FIELD_VALUE(0, DE_DESTINATION, Y,    dst_Y));

    regWrite32(DE_DIMENSION,
        FIELD_VALUE(0, DE_DIMENSION, X,    dst_width) |
        FIELD_VALUE(0, DE_DIMENSION, Y_ET, dst_height));

    regWrite32(DE_CONTROL,
        FIELD_SET  (0, DE_CONTROL, STATUS,     START)          |
        FIELD_SET  (0, DE_CONTROL, DIRECTION,  LEFT_TO_RIGHT)  |
        FIELD_SET  (0, DE_CONTROL, LAST_PIXEL, OFF)            |
        FIELD_SET  (0, DE_CONTROL, COMMAND,    RECTANGLE_FILL) |
        FIELD_SET  (0, DE_CONTROL, ROP_SELECT, ROP2)           |
        FIELD_VALUE(0, DE_CONTROL, ROP,        0x0C));

    SMI_de_busy = 1;
}


/**********************************************************************
 *
 * deRotatePattern
 *
 * Purpose
 *    Rotate the given pattern if necessary
 *
 * Parameters
 *    [in]
 *        pPattern  - Pointer to DE_SURFACE structure containing
 *                    pattern attributes
 *        patternX  - X position (0-7) of pattern origin
 *        patternY  - Y position (0-7) of pattern origin
 *
 *    [out]
 *        pattern_dstaddr - Pointer to pre-allocated buffer containing rotated pattern
 *
 *
 **********************************************************************/
void deRotatePattern(unsigned char* pattern_dstaddr,
                     unsigned long pattern_src_addr,
                     unsigned long pattern_BPP,
                     unsigned long pattern_stride,
                     int patternX,
                     int patternY)
{
    unsigned int i;
    unsigned long pattern_read_addr;
    unsigned long pattern[PATTERN_WIDTH * PATTERN_HEIGHT];
    unsigned int x, y;
	unsigned char* pjPatByte;

    if (pattern_dstaddr != NULL)
    {
        deWaitForNotBusy();
        
        /* Load pattern from local video memory into pattern array */
        pattern_read_addr = pattern_src_addr;
        
        for (i = 0; i < (pattern_BPP * 2); i++)
        {
            pattern[i] = memRead32(pattern_read_addr);
            pattern_read_addr += 4;
        }
        
        if (patternX || patternY)
        {
            /* Rotate pattern */
            pjPatByte = (unsigned char*)pattern;
            
            switch (pattern_BPP)
            {
            case 8:
                {
                    for (y = 0; y < 8; y++)
                    {
                        unsigned char* pjBuffer = pattern_dstaddr + ((patternY + y) & 7) * 8;
                        for (x = 0; x < 8; x++)
                        {
                            pjBuffer[(patternX + x) & 7] = pjPatByte[x];
                        }
                        pjPatByte += pattern_stride;
                    }
                    break;
                }
                
            case 16:
                {
                    for (y = 0; y < 8; y++)
                    {
                        unsigned short* pjBuffer = (unsigned short*) pattern_dstaddr + ((patternY + y) & 7) * 8;
                        for (x = 0; x < 8; x++)
                        {
                            pjBuffer[(patternX + x) & 7] = ((unsigned short*) pjPatByte)[x];
                        }
                        pjPatByte += pattern_stride;
                    }
                    break;
                }
                
            case 32:
                {
                    for (y = 0; y < 8; y++)
                    {
                        unsigned long* pjBuffer = (unsigned long*) pattern_dstaddr + ((patternY + y) & 7) * 8;
                        for (x = 0; x < 8; x++)
                        {
                            pjBuffer[(patternX + x) & 7] = ((unsigned long*) pjPatByte)[x];
                        }
                        pjPatByte += pattern_stride;
                    }
                    break;
                }
            }
        }
        else
        {
            /* Don't rotate, just copy pattern into pattern_dstaddr */
            for (i = 0; i < (pattern_BPP * 2); i++)
            {
                ((unsigned long *)pattern_dstaddr)[i] = pattern[i];
            }
        }
        
    }
}


/**********************************************************************
 *
 * deMonoPatternFill
 *
 * Purpose
 *    Copy the specified monochrome pattern into the destination surface
 *
 * Remarks
 *       Pattern size must be 8x8 pixel. 
 *       Pattern color depth must be same as destination bitmap or monochrome.
**********************************************************************/
void deMonoPatternFill(unsigned long dst_base,
                       unsigned long dst_pitch,  
                       unsigned long dst_BPP,
                       unsigned long dstX, 
                       unsigned long dstY,
                       unsigned long dst_width,
                       unsigned long dst_height,
                       unsigned long pattern_FGcolor,
                       unsigned long pattern_BGcolor,
                       unsigned long pattern_low, 
                       unsigned long pattern_high)
{
    deWaitForNotBusy();
    
    regWrite32(DE_WINDOW_DESTINATION_BASE, FIELD_VALUE(0, DE_WINDOW_DESTINATION_BASE, ADDRESS, dst_base));
    
    regWrite32(DE_PITCH, FIELD_VALUE(0, DE_PITCH, DESTINATION, dst_pitch) |  FIELD_VALUE(0, DE_PITCH, SOURCE, dst_pitch));
    
    regWrite32(DE_WINDOW_WIDTH,
        FIELD_VALUE(0, DE_WINDOW_WIDTH, DESTINATION, dst_pitch) |
        FIELD_VALUE(0, DE_WINDOW_WIDTH, SOURCE,      dst_pitch));

    regWrite32(DE_FOREGROUND,
        FIELD_VALUE(0, DE_FOREGROUND, COLOR, pattern_FGcolor));

    regWrite32(DE_BACKGROUND,
        FIELD_VALUE(0, DE_BACKGROUND, COLOR, pattern_BGcolor));

    regWrite32(DE_MONO_PATTERN_LOW,
        FIELD_VALUE(0, DE_MONO_PATTERN_LOW, PATTERN, pattern_low));

    regWrite32(DE_MONO_PATTERN_HIGH,
        FIELD_VALUE(0, DE_MONO_PATTERN_HIGH, PATTERN, pattern_high));
    
    regWrite32(DE_DESTINATION,
        FIELD_SET  (0, DE_DESTINATION, WRAP, DISABLE) |
        FIELD_VALUE(0, DE_DESTINATION, X,    dstX)      |
        FIELD_VALUE(0, DE_DESTINATION, Y,    dstY));

    regWrite32(DE_DIMENSION,
        FIELD_VALUE(0, DE_DIMENSION, X,    dst_width) |
        FIELD_VALUE(0, DE_DIMENSION, Y_ET, dst_height));
    
    regWrite32(DE_CONTROL, 
        FIELD_VALUE(0, DE_CONTROL, ROP, 0xF0) |
        FIELD_SET(0, DE_CONTROL, COMMAND, BITBLT) |
        FIELD_SET(0, DE_CONTROL, PATTERN, MONO)  |
        FIELD_SET(0, DE_CONTROL, STATUS, START));

    SMI_de_busy = 1;
} /* deMonoPatternFill() */


/**********************************************************************
 *
 * deColorPatternFill
 *
 * Purpose
 *    Copy the specified pattern into the destination surface
 *
 * Parameters
 *    [in]
 *        pDestSurface   - Pointer to DE_SURFACE structure containing
 *                         destination surface attributes
 *        nX             - X coordinate of destination surface to be filled
 *        nY             - Y coordinate of destination surface to be filled
 *        dst_width         - Width (in pixels) of area to be filled
 *        dst_height        - Height (in lines) of area to be filled
 *        pPattern       - Pointer to DE_SURFACE structure containing
 *                         pattern attributes
 *        pPatternOrigin - Pointer to Point structure containing pattern origin
 *        pMonoInfo      - Pointer to mono_pattern_info structure
 *        pClipRect      - Pointer to Rect structure describing clipping
 *                         rectangle; NULL if no clipping required
 *
 *    [out]
 *        None
 *
 * Remarks
 *       Pattern size must be 8x8 pixel. 
 *       Pattern color depth must be same as destination bitmap.
**********************************************************************/
void deColorPatternFill(unsigned long dst_base,
                        unsigned long dst_pitch,  
                        unsigned long dst_BPP,  
                        unsigned long dst_X, 
                        unsigned long dst_Y, 
                        unsigned long dst_width,
                        unsigned long dst_height,
                        unsigned long pattern_src_addr,
                        unsigned long pattern_stride,
                        int PatternOriginX,
                        int PatternOriginY)
{
    unsigned int i;
    unsigned long de_data_port_write_addr;
    unsigned char ajPattern[PATTERN_WIDTH * PATTERN_HEIGHT * 4];
    unsigned long de_ctrl = 0;
    
    deWaitForNotBusy();
    
    de_ctrl = FIELD_SET(0, DE_CONTROL, PATTERN, COLOR);
    
    regWrite32(DE_CONTROL, de_ctrl);
    
    /* Rotate pattern if necessary */
    deRotatePattern(ajPattern, pattern_src_addr, dst_BPP, pattern_stride, PatternOriginX, PatternOriginY);
    
    /* Load pattern to 2D Engine Data Port */
    de_data_port_write_addr = DE_DATA_PORT;
    
    for (i = 0; i < (dst_BPP * 2); i++)
    {
        regWrite32(de_data_port_write_addr, ((unsigned long *)ajPattern)[i]);
        de_data_port_write_addr += 4;
    }
    
    deWaitForNotBusy();

    regWrite32(DE_WINDOW_DESTINATION_BASE, FIELD_VALUE(0, DE_WINDOW_DESTINATION_BASE, ADDRESS, dst_base));
 
    regWrite32(DE_PITCH,
        FIELD_VALUE(0, DE_PITCH, DESTINATION, dst_pitch) |
        FIELD_VALUE(0, DE_PITCH, SOURCE,      dst_pitch));

    regWrite32(DE_WINDOW_WIDTH,
        FIELD_VALUE(0, DE_WINDOW_WIDTH, DESTINATION, dst_pitch) |
        FIELD_VALUE(0, DE_WINDOW_WIDTH, SOURCE,      dst_pitch));

    regWrite32(DE_DESTINATION,
        FIELD_SET  (0, DE_DESTINATION, WRAP, DISABLE) |
        FIELD_VALUE(0, DE_DESTINATION, X,    dst_X)      |
        FIELD_VALUE(0, DE_DESTINATION, Y,    dst_Y));

    regWrite32(DE_DIMENSION,
        FIELD_VALUE(0, DE_DIMENSION, X,    dst_width) |
        FIELD_VALUE(0, DE_DIMENSION, Y_ET, dst_height));
    
    regWrite32(DE_CONTROL, 
        FIELD_VALUE(0, DE_CONTROL, ROP, 0xF0) |
        FIELD_SET(0, DE_CONTROL, COMMAND, BITBLT) |
        FIELD_SET(0, DE_CONTROL, PATTERN, COLOR) |
        FIELD_SET(0, DE_CONTROL, STATUS, START));

    SMI_de_busy = 1;
} /* deColorPatternFill() */


/**********************************************************************
 *
 * deCopy
 *
 * Purpose
 *    Copy a rectangular area of the source surface to a destination surface
 *
 * Remarks
 *       Source bitmap must have the same color depth (BPP) as the destination bitmap.
 *
**********************************************************************/
void deCopy(unsigned long dst_base,
            unsigned long dst_pitch,  
            unsigned long dst_BPP,  
            unsigned long dst_X, 
            unsigned long dst_Y, 
            unsigned long dst_width,
            unsigned long dst_height,
            unsigned long src_base, 
            unsigned long src_pitch,  
            unsigned long src_X, 
            unsigned long src_Y, 
            pTransparent pTransp,
            unsigned char nROP2)
{
    unsigned long nDirection = 0;
    unsigned long nTransparent = 0;
    unsigned long opSign = 1;    // Direction of ROP2 operation: 1 = Left to Right, (-1) = Right to Left
    unsigned long xWidth = 192 / (dst_BPP / 8); // xWidth is in pixels
    unsigned long de_ctrl = 0;
    
    deWaitForNotBusy();

    regWrite32(DE_WINDOW_DESTINATION_BASE, FIELD_VALUE(0, DE_WINDOW_DESTINATION_BASE, ADDRESS, dst_base));

    regWrite32(DE_WINDOW_SOURCE_BASE, FIELD_VALUE(0, DE_WINDOW_SOURCE_BASE, ADDRESS, src_base));

    if (dst_pitch && src_pitch)
    {
        regWrite32(DE_PITCH,
            FIELD_VALUE(0, DE_PITCH, DESTINATION, dst_pitch) |
            FIELD_VALUE(0, DE_PITCH, SOURCE,      src_pitch));
        
        regWrite32(DE_WINDOW_WIDTH,
            FIELD_VALUE(0, DE_WINDOW_WIDTH, DESTINATION, dst_pitch) |
            FIELD_VALUE(0, DE_WINDOW_WIDTH, SOURCE,      src_pitch));
    }
    
    /* Set transparent bits if necessary */
    if (pTransp != NULL)
    {
        nTransparent = pTransp->match | pTransp->select | pTransp->control;
        
        /* Set color compare register */
        regWrite32(DE_COLOR_COMPARE,
            FIELD_VALUE(0, DE_COLOR_COMPARE, COLOR, pTransp->color));
    }
    
    /* Determine direction of operation */
    if (src_Y < dst_Y)
    {
    /* +----------+
    |S         |
    |   +----------+
    |   |      |   |
    |   |      |   |
    +---|------+   |
    |         D|
        +----------+ */
        
        nDirection = BOTTOM_TO_TOP;
    }
    else if (src_Y > dst_Y)
    {
    /* +----------+
    |D         |
    |   +----------+
    |   |      |   |
    |   |      |   |
    +---|------+   |
    |         S|
        +----------+ */
        
        nDirection = TOP_TO_BOTTOM;
    }
    else
    {
        /* src_Y == dst_Y */
        
        if (src_X <= dst_X)
        {
        /* +------+---+------+
        |S     |   |     D|
        |      |   |      |
        |      |   |      |
        |      |   |      |
            +------+---+------+ */
            
            nDirection = RIGHT_TO_LEFT;
        }
        else
        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -