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

📄 saa7114.c

📁 WinCE 3.0 BSP, 包含Inter SA1110, Intel_815E, Advantech_PCM9574 等
💻 C
📖 第 1 页 / 共 2 页
字号:
    unsigned short dstw, unsigned short dsth)
#endif
{
    unsigned char prescale = 0;
    int scale = 0;

    /* SET THE HORIZONTAL PRESCALE */
    /* Downscale from 1 to 1/63 source size. */

    if (dstw) prescale = (unsigned char) srcw/dstw;
    if (!prescale) prescale = 1; 
    if (prescale > 63) return(1);
    gfx_i2c_write(SAA7114_CHIPADDR, SAA7114_HORZ_PRESCALER, prescale);

    /* SET THE HORIZONTAL SCALING */

    if (!dstw) return(1);
    scale = (int) (1024.*((1.*srcw)/(1.*dstw))*(1./prescale));
    if ((scale > 8191) || (scale < 300)) return(1);
    gfx_i2c_write(SAA7114_CHIPADDR, SAA7114_HSCALE_LUMA_LO,
        (unsigned char) (scale & 0x00FF));
    gfx_i2c_write(SAA7114_CHIPADDR, SAA7114_HSCALE_LUMA_HI,
        (unsigned char) (scale >> 8));
    scale >>= 1;
    gfx_i2c_write(SAA7114_CHIPADDR, SAA7114_HSCALE_CHROMA_LO,
        (unsigned char) (scale & 0x00FF));
    gfx_i2c_write(SAA7114_CHIPADDR, SAA7114_HSCALE_CHROMA_HI,
        (unsigned char) (scale >> 8));

    /* SET THE VERTICAL SCALING (INTERPOLATION MODE) */
        
    if (!dsth) return(1);
    scale = (int)((1024 * srch) / dsth);
    gfx_i2c_write(SAA7114_CHIPADDR, SAA7114_VSCALE_LUMA_LO,
        (unsigned char) (scale & 0x00FF));
    gfx_i2c_write(SAA7114_CHIPADDR, SAA7114_VSCALE_LUMA_HI,
        (unsigned char) (scale >> 8));
    gfx_i2c_write(SAA7114_CHIPADDR, SAA7114_VSCALE_CHROMA_LO,
        (unsigned char) (scale & 0x00FF));
    gfx_i2c_write(SAA7114_CHIPADDR, SAA7114_VSCALE_CHROMA_HI,
        (unsigned char) (scale >> 8));

    if (dsth >= (srch >> 1))
    {
        /* USE INTERPOLATION MODE FOR SCALE FACTOR ABOVE 0.5 */

        gfx_i2c_write(SAA7114_CHIPADDR, SAA7114_VSCALE_CONTROL, 0x00);
    }
    else
    {
        /* USE ACCUMULATION MODE FOR DOWNSCALING BY MORE THAN 2x */

        gfx_i2c_write(SAA7114_CHIPADDR, SAA7114_VSCALE_CONTROL, 0x01);

        /* ADJUST CONTRAST AND SATURATION FOR ACCUMULATION MODE */

        if (srch) scale = (64 * dsth) / srch;
        gfx_i2c_write(SAA7114_CHIPADDR, SAA7114_FILTER_CONTRAST, 
            (unsigned char) scale);
        gfx_i2c_write(SAA7114_CHIPADDR, SAA7114_FILTER_SATURATION, 
            (unsigned char) scale);
    }

    /* SUGGESTED SOFTWARE RESET */ 
    
    gfx_i2c_write(SAA7114_CHIPADDR, 0x88, 0xC0);
    gfx_i2c_write(SAA7114_CHIPADDR, 0x88, 0xF0);
    return(0);
}

/*-----------------------------------------------------------------------------
 * gfx_set_decoder_vbi_format
 *
 * This routine programs the decoder to produce the specified format for 
 * the VBI data.
 *
 *     0 = disabled
 *     1 = raw VBI data
 *     2 = US closed caption
 *-----------------------------------------------------------------------------
 */
#if GFX_DECODER_DYNAMIC
int saa7114_set_decoder_vbi_format(int format)
#else
int gfx_set_decoder_vbi_format(int format)
#endif
{
    unsigned char data = 0xFF;
    switch(format)
    {
        case 1: data = 0x77; break; /* raw VBI data */
        case 2: data = 0x55; break; /* US closed caption */
    }

    /* PROGRAM LINES 20 AND 21 FOR THE SPECIFIED FORMAT */

    gfx_i2c_write(SAA7114_CHIPADDR, 0x53, data);
    gfx_i2c_write(SAA7114_CHIPADDR, 0x54, data);
    return(0);
}

/*************************************************************/
/*  READ ROUTINES  |  INCLUDED FOR DIAGNOSTIC PURPOSES ONLY  */
/*************************************************************/

#if GFX_READ_ROUTINES

/*-----------------------------------------------------------------------------
 * gfx_get_decoder_brightness
 *
 * This routine returns the current brightness of the video decoder.  
 *-----------------------------------------------------------------------------
 */
#if GFX_DECODER_DYNAMIC
unsigned char saa7114_get_decoder_brightness(void)
#else
unsigned char gfx_get_decoder_brightness(void)
#endif
{
    unsigned char brightness = 0;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_BRIGHTNESS, &brightness);
    return(brightness);
}

/*-----------------------------------------------------------------------------
 * gfx_get_decoder_contrast
 *
 * This routine returns the current contrast of the video decoder.  
 *-----------------------------------------------------------------------------
 */
#if GFX_DECODER_DYNAMIC
unsigned char saa7114_get_decoder_contrast(void)
#else
unsigned char gfx_get_decoder_contrast(void)
#endif
{
    unsigned char contrast = 0;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_CONTRAST, &contrast);
    contrast <<= 1;
    return(contrast);
}

/*-----------------------------------------------------------------------------
 * gfx_get_decoder_hue
 *
 * This routine returns the current hue of the video decoder.  
 *-----------------------------------------------------------------------------
 */
#if GFX_DECODER_DYNAMIC
char saa7114_get_decoder_hue(void)
#else
char gfx_get_decoder_hue(void)
#endif
{
    unsigned char hue = 0;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_HUE, &hue);
    return((char)hue);
}

/*-----------------------------------------------------------------------------
 * gfx_get_decoder_saturation
 *
 * This routine returns the current saturation of the video decoder.  
 *-----------------------------------------------------------------------------
 */
#if GFX_DECODER_DYNAMIC
unsigned char saa7114_get_decoder_saturation(void)
#else
unsigned char gfx_get_decoder_saturation(void)
#endif
{
    unsigned char saturation = 0;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_SATURATION, &saturation);
    saturation <<= 1;
    return(saturation);
}

/*-----------------------------------------------------------------------------
 * gfx_get_decoder_input_offset
 *
 * This routine returns the offset into the input window.
 *-----------------------------------------------------------------------------
 */
#if GFX_DECODER_DYNAMIC
unsigned long saa7114_get_decoder_input_offset()
#else
unsigned long gfx_get_decoder_input_offset()
#endif
{
    unsigned long value = 0;
    unsigned char data;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_HORZ_OFFSET_LO, &data);
    value = (unsigned long) data;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_HORZ_OFFSET_HI, &data);
    value |= ((unsigned long) data) << 8;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_VERT_OFFSET_LO, &data);
    value |= ((unsigned long) data) << 16;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_VERT_OFFSET_HI, &data);
    value |= ((unsigned long) data) << 24;
    return(value);
}

/*-----------------------------------------------------------------------------
 * gfx_get_decoder_input_size
 *
 * This routine returns the current size of the input window
 *-----------------------------------------------------------------------------
 */
#if GFX_DECODER_DYNAMIC
unsigned long saa7114_get_decoder_input_size()
#else
unsigned long gfx_get_decoder_input_size()
#endif
{
    unsigned long value = 0;
    unsigned char data;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_HORZ_INPUT_LO, &data);
    value = (unsigned long) data;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_HORZ_INPUT_HI, &data);
    value |= ((unsigned long) data) << 8;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_VERT_INPUT_LO, &data);
    value |= ((unsigned long) data) << 17;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_VERT_INPUT_HI, &data);
    value |= ((unsigned long) data) << 25;
    return(value);
}

/*-----------------------------------------------------------------------------
 * gfx_get_decoder_output_size
 *
 * This routine returns the current size of the output window.
 *-----------------------------------------------------------------------------
 */
#if GFX_DECODER_DYNAMIC
unsigned long saa7114_get_decoder_output_size()
#else
unsigned long gfx_get_decoder_output_size()
#endif
{
    unsigned long value = 0;
    unsigned char data;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_HORZ_OUTPUT_LO, &data);
    value = (unsigned long) data;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_HORZ_OUTPUT_HI, &data);
    value |= ((unsigned long) data) << 8;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_VERT_OUTPUT_LO, &data);
    value |= ((unsigned long) data) << 17;
    gfx_i2c_read(SAA7114_CHIPADDR, SAA7114_VERT_OUTPUT_HI, &data);
    value |= ((unsigned long) data) << 25;
    return(value);
}

/*-----------------------------------------------------------------------------
 * gfx_get_decoder_vbi_format
 *
 * This routine returns the current format of the VBI data.
 *-----------------------------------------------------------------------------
 */
#if GFX_DECODER_DYNAMIC
int saa7114_get_decoder_vbi_format(void)
#else
int gfx_get_decoder_vbi_format(void)
#endif
{
    unsigned char format = 0, data;
    gfx_i2c_read(SAA7114_CHIPADDR, 0x54, &data);
    if (data == 0x77) format = 1;
    else if (data == 0x55) format = 2;
    return(format);
}

#endif /* GFX_READ_ROUTINES */

/* END OF FILE */

⌨️ 快捷键说明

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