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

📄 source.c

📁 IT projecotr reference design.
💻 C
字号:
/*****************************************************************************
**             TEXAS INSTRUMENTS PROPRIETARY INFORMATION
**
**  (c) Copyright, Texas Instruments Incorporated, 2006.
**      All Rights Reserved.
**
**  Property of Texas Instruments Incorporated. Restricted Rights -
**  Use, duplication, or disclosure is subject to restrictions set
**  forth in TI's program license agreement and associated documentation.
******************************************************************************/
/****************************************************************************/
/* source.c                                                                 */
/*                                                                          */
/* source: Implements control functions for internally generated sources:   */
/*         Solid field generator, Splash screen, and Test Pattern Generator */
/****************************************************************************/

#include "common.h"
#include "sfg.h"
#include "tpg.h"
#include "flash_table.h"
#include "splash.h"
#include "src.h"
#include "disp.h"
#include "dmd.h"

#include "datapath.h"
#include "source.h"
#include "dispfmt.h"
#include "eeprom.h"

const struct
{
    uint08 r, g, b;
} sfgColorTable[] =
{
    {   0,   0,   0 },   /* black */
    {   0,   0, 128 },    /* blue */
    {  64,  64,  64 },    /* gray */
    { 128,   0,   0 },     /* red */
    {   0, 128,   0 },   /* green */
    { 255, 255,   0 },  /* yellow */
    {   0, 255, 255 },    /* cyan */
    { 255,   0, 255 }, /* magenta */
    { 255, 255, 255 }    /* white */
};


static DP_TPG tpgPattern = DPTPG_NONE;
static uint08 sfgColor = 0;

void source_InitializeOnce( DP_SOURCEDESC *srcDesc )
{
    SRC_PORT_CFG port_cfg;
    SRC_SOURCE_CONFIG src_cfg;
    SRC_CHANNEL_CFG chan_cfg;
    uint08 blankcolor;

    port_cfg.PortWidth = SRC_30_BITS;
    port_cfg.ABC_Mux = SRC_ABC_SWAP_AB;
    port_cfg.DataEnableSource = SRC_PORT1;
    SRC_SetPortConfiguration( SRC_PORT1, &port_cfg );

    DISP_SetBackgroundColor( 0, 0, 0 );
    
    chan_cfg.SyncPort = SRC_PORT1;
    SRC_SetChannelConfiguration( SRC_PRIMARY, &chan_cfg );
    
    SRC_GetSourceConfiguration( SRC_PORT1, &src_cfg );
    src_cfg.VSyncCfg = SRC_PORT_SYNC_NOINV;
    src_cfg.HSyncCfg = SRC_PORT_SYNC_NOINV;
    src_cfg.TopField = SRC_PORT_SYNC_NOINV;
    src_cfg.DownSampleCfg = SRC_NO_DOWNSAMPLE;
    src_cfg.IsClockPolarityPositive = TRUE;
    src_cfg.Is422 = FALSE;
    src_cfg.IsRGB = TRUE;
    src_cfg.IsExternalDE = TRUE;
    src_cfg.IsInterlaced = FALSE;
    src_cfg.IsOffsetBinary = FALSE;
    src_cfg.IsTopFieldInvertedAtScaler = FALSE;

    src_cfg.TotalArea.PixelsPerLine = 1352;
    src_cfg.TotalArea.LinesPerFrame = 802;
    
    src_cfg.ActiveArea.FirstPixel = 182;
    src_cfg.ActiveArea.FirstLine = 12;
    src_cfg.ActiveArea.PixelsPerLine = 1024;
    src_cfg.ActiveArea.LinesPerFrame = 768;
     
    src_cfg.BottomFieldFirstLine = 12;
    src_cfg.PixelClockFreqInkHz = 65037;

    src_cfg.ColorSpaceConvCoeffs[0] = 1024;
    src_cfg.ColorSpaceConvCoeffs[1] = 0;
    src_cfg.ColorSpaceConvCoeffs[2] = 0;
    src_cfg.ColorSpaceConvCoeffs[3] = 0;
    src_cfg.ColorSpaceConvCoeffs[4] = 1024;
    src_cfg.ColorSpaceConvCoeffs[5] = 0;
    src_cfg.ColorSpaceConvCoeffs[6] = 0;
    src_cfg.ColorSpaceConvCoeffs[7] = 0;
    src_cfg.ColorSpaceConvCoeffs[8] = 1024;

    src_cfg.Offset[0] = 0;
    src_cfg.Offset[1] = 0;
    src_cfg.Offset[2] = 0;
    SRC_SetSourceConfiguration( SRC_PORT1, &src_cfg );
    
    EE_GETVAR( UserMachine.Projector.BlankScreenColor, blankcolor );
    source_SetUserSFGColor( srcDesc, blankcolor );
    source_DisplaySFG( srcDesc );
}


int08 source_DisplaySplash( DP_SOURCEDESC *srcDesc )
{
    uint32 splash_addr;               /* storage for address of splash data */
    int08 retval;
    uint16 splashWidth, splashHeight;
    uint08 splashIndex;
    
    EE_GETVAR( UserMachine.Projector.SplashSource, splashIndex );
    
                                              /* Get pointer to splash data */
    retval = FLASH_GetFlashAddr(SPLASH_DATA, splashIndex, &splash_addr);
    if( retval != PASS || splash_addr == 0xFFFFFFFF )
    {
        return FAIL;
    }

    DISP_SetChannelSource( SRC_PRIMARY, DISP_SPLASH_SOURCE );
    SPLASH_LoadImage( (uint32*)splash_addr );

    SPLASH_GetSplashSize( &splashWidth, &splashHeight );

                  /* set inputWidth and inputHeight, but leave nativeWidth  */
                  /* and nativeHeight the same as the previous source       */
                  /* inputFrameRate is don't care for splash                */
    srcDesc->inputWidth = splashWidth;
    srcDesc->inputHeight = splashHeight;
    srcDesc->activeDisplay = DP_SPLASH;
    
    return PASS;
}


void source_DisplaySFG( DP_SOURCEDESC *srcDesc )
{
    if( sfgColor >= 9 )
    {
        /* the color is set to "splash screen" */
        if( source_DisplaySplash( srcDesc ) == PASS )
            return;
    }
  
    DISP_SetChannelSource( SRC_PRIMARY, DISP_SOLID_FIELD_SOURCE );
    
      /* inputWidth, inputHeight, inputFrameRate are don't care for SFG     */
      /* leave nativeWidth and nativeHeight the same as the previous source */ 
    srcDesc->activeDisplay = DP_SFG;
}


void source_SetUserSFGColor( DP_SOURCEDESC *srcDesc, uint08 color )
{
    DISP_DISPLAY_SOURCE disp_source;
    sfgColor = color;
    
    if( sfgColor < 9 )
    {
        SFG_SetColor( sfgColorTable[sfgColor].r, sfgColorTable[sfgColor].g, sfgColorTable[sfgColor].b );
    }
    
    DISP_GetChannelSource( SRC_PRIMARY, &disp_source );
    if( disp_source != DISP_EXTERNAL_SOURCE )
    {
        source_DisplaySFG( srcDesc );
        dispfmt_ConfigureForSource( FALSE );
    }
}


int08 source_SetTestPattern( DP_TPG pattern, DP_SOURCEDESC *srcDesc )
{
    uint16 hres, vres;
    TPG_COLOR color;
    uint32 minclock;
    uint08 borderWidth;

    if( pattern == DPTPG_NONE )
    {
        if( TPG_Enable( FALSE ) == PASS )
        {
            tpgPattern = DPTPG_NONE;
            return PASS;
        }
        else
            return FAIL;
    }

                    /* always disable first, according to API documentation */
    TPG_Enable(FALSE);

    DMD_GetResolution( &hres, &vres );

                /* default to white foreground, black background --         */
                /* for RGBW ramp and colorbars, this will enable all colors */
    color.Blu_A = 1023;
    color.Grn_A = 1023;
    color.Red_A = 1023;
    color.Blu_B = 0;
    color.Grn_B = 0;
    color.Red_B = 0;
    TPG_SetColor( &color );
        
    switch( pattern )
    {       
    case DPTPG_RGBRAMP:
        borderWidth = 0;
        TPG_SetColorRampHorizontal( TPG_HRAMP_1024, vres>>2 ); /* size for 4 ramps */
        hres = 1024;
        break;
        
    case DPTPG_COLORBAR:
        borderWidth = 0;
        TPG_SetColorbars( hres>>3 );               /* size for 8 color bars */
        break;
        
    case DPTPG_STEPBARS:
        borderWidth = 0;
        TPG_SetFixedRampHorizontal( 0, hres>>4, 1024>>4 ); /* size for 16 steps */
        break;
        
    case DPTPG_CHECKERBOARD:
        borderWidth = 0; 
        TPG_SetCheckerboard( hres>>3, vres>>3 );
        break;
        
    case DPTPG_GRID:
        borderWidth = 2;
        TPG_SetGrid( 2, (hres>>4)-2, 2, (vres>>4)-2 );
        break;
        
    case DPTPG_HLINES:
        borderWidth = 1;
        TPG_SetLinesHorizontal( 1, (hres>>4)-1 );
        break;
    
    case DPTPG_VLINES:
        borderWidth = 1;
        TPG_SetLinesVertical( 1, (vres>>4)-1 );
        break;
    
    case DPTPG_DIAGLINES:
        borderWidth = 1;
        TPG_SetLinesDiagonal( 63 );                    /* must be (2^x) - 1 */
        break;
    
    case DPTPG_HRAMP:
        borderWidth = 0;
        TPG_SetRampHorizontal( TPG_HRAMP_1024 );
        hres = 1024;
        break;
    
    case DPTPG_VRAMP:
        borderWidth = 0;
        TPG_SetRampVertical( TPG_VRAMP_512 ); 
        vres = 512;
        break;
    
    default:
        return FAIL;
    }
    
    TPG_SetResolution( hres, vres );
    
    /* pixel clock = 60Hz * (active lines + 30 lines blanking) * (active pixels + 25% blanking) */
    minclock = 60 * (vres + 30) * (hres + (hres >> 2));

           /* select the appropriate pixel clock based on the source timing */
           /* and begin filling the srcConfig struct                        */

    if( minclock <= 33333333 )
    {
        TPG_SetFrameRate( TPG_PXLCLK_33MHZ, 30, 60 );
    }
    else if( minclock <= 66666667 )
    {
        TPG_SetFrameRate( TPG_PXLCLK_67MHZ, 30, 60 );
    }
    else if( minclock <= 150000000 )
    {
        TPG_SetFrameRate( TPG_PXLCLK_150MHZ, 30, 60 );
    }
    else
        return FAIL;

    if( TPG_Enable(TRUE) == PASS )
    {
        TPG_SetBorderWidth( borderWidth );
        tpgPattern = pattern;
        
        srcDesc->inputFrameRate = 60.0f;
        srcDesc->inputHeight = vres;
        srcDesc->inputWidth = hres;
                  /* set the native height and width back to DMD resolution */
        DMD_GetResolution( &hres, &vres );
        srcDesc->nativeHeight = vres;
        srcDesc->nativeWidth = hres;

        return PASS;
    }
    
    return FAIL;
}

DP_TPG source_GetTestPattern( void )
{
    return tpgPattern;
}

⌨️ 快捷键说明

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