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

📄 refddcproc.c

📁 IT projecotr reference design.
💻 C
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************/
/*             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.   */
/****************************************************************************/

/****************************************************************************/
/* refDdcProc.c                                                             */
/****************************************************************************/

#include <stdlib.h>
#include <string.h>

#include "common.h"
#include "ddp2230_rtos_include.h"
#include "i2c.h"
#include "tmr.h"
#include "src.h"
#include "al_alc.h"

#include "taskParm.h"
#include "global.h"
#include "app_cfg.h"
#include "dbmessage.h"
#include "ddcCI.h"
#include "refDdcProc.h"
#include "eeprom.h"
#include "datapath.h"
#include "guiApp.h"
#include "pictcont.h"



/****************************************************************************/
/* Local definitions                                                        */
/****************************************************************************/

#define MAXNORM  1024                    /* maximum normalized host setting */
#define UNSET  -32768       /* indicates a CI_SETTINGS member is unmodified */

typedef int08 (*LIMFUNC)( int16 *min, int16 *max );
typedef int08 (*GETFUNC)( int16 *value );
typedef int08 (*SETFUNC)( int16  value );



/****************************************************************************/
/* Buffered debug                                                           */
/*                                                                          */
/* Due to I2C timing requirements on byte transfer acknowledgement, debug   */
/* messaging is constrained: A debug message sent while a byte is pending   */
/* acknowledgement will usually cause a timeout error. If the app config    */
/* member Peripherals.DdcciConfig indicates that buffered debug is to be    */
/* enabled, a buffer is allocated, an app-dependent debug callback is       */
/* installed, and messages are buffered. They are sent when a projector     */
/* control command is sent to dump them.                                    */
/****************************************************************************/

#define DBSIZE 8192                            /* debug message buffer size */

char  *dbuffer = NULL;                   /* pointer to debug message buffer */
char  *dbp;                        /* pointer to next available buffer byte */
int32  dbremain;                         /* bytes remaining in debug buffer */


/****************************************************************************/
/* Local data                                                               */
/****************************************************************************/

CI_SETTINGS ciSettings[ NUM_CONNECTORS ];           /* unique per connector */

const char    capString[] =                          /* capabilities string */
    "prot(display) type(dlp) model(DDP2230) mccs_ver(3) mswhql(xxxxxx) cmds(01 03 07 0c f3) vcp(02 04 08 10 12 14(01 02 03 04 05) 87 8a 90 b6 df)"; 

const  uint16 capLength = (uint16)( sizeof( capString ) - 1 );
static uint16 capOffset = 999;              /* initialized to invalid value */



/****************************************************************************/
/* Local functions                                                          */
/****************************************************************************/

static DDC_COMP ciCmdGetVcp( pCI_MESSAGE pMsg, pCI_MESSAGE pRsp );
static DDC_COMP ciCmdSetVcp( pCI_MESSAGE pMsg, pCI_MESSAGE pRsp );
static DDC_COMP ciCmdSavVcp( pCI_MESSAGE pMsg, pCI_MESSAGE pRsp );
static DDC_COMP ciCmdGetCap( pCI_MESSAGE pMsg, pCI_MESSAGE pRsp );
static DDC_COMP ciCmdGetTim( pCI_MESSAGE pMsg, pCI_MESSAGE pRsp );

static uint08 _ckSum( void *p, uint08 n );
static void   _ddcCallback( char *msg );
static void   _setVCP( int16  *upValue, uint16 hostValue, LIMFUNC limit, SETFUNC set );
static void   _getVCP( uint16 *hostValue, LIMFUNC limit, GETFUNC get );
static void   _unSet( void );



/****************************************************************************/
/* DDC/CI Code dispatch table                                               */
/****************************************************************************/

CI_DISPATCH ciDispatch[] =
{
    { CICMD_GETVCP   , 2, 0, ciCmdGetVcp },    /* 0x01 Get VCP feature      */
    { CICMD_SETVCP   , 4, 0, ciCmdSetVcp },    /* 0x03 Set VCP feature      */
    { CICMD_SAVEVCP  , 1, 0, ciCmdSavVcp },    /* 0x0c Save settings        */
    { CICMD_GETCAP   , 3, 0, ciCmdGetCap },    /* 0xf3 Capabilities request */
    { CICMD_GETTIMING, 1, 0, ciCmdGetTim },    /* 0x07 Get timing report    */
};

const uint08 ciTableSize = (uint08)( sizeof( ciDispatch ) / sizeof( CI_DISPATCH ));



/****************************************************************************/
/* Return task information.                                                 */
/****************************************************************************/

void ddc_info( TASKINFO_STRUCT *info )
{
   char *tName;
    
    info -> taskID    = ddcciInfo( &tName );
    info -> stackSize = STACK_DDCCI;
    info -> taskName  = tName;
}



/****************************************************************************/
/* DDC/CI Initialization.                                                   */
/****************************************************************************/

EXEC_CC_ENUM ddc_init( void )
{
    EXEC_CC_ENUM cc = EXEC_CC_FAIL;        /* assume initialization failure */

   _unSet();                   /* indicate all settings untouched by DDC/CI */
        
                            /************************************************/
                            /* Initialize the app-independent interface,    */
                            /* which opens the specified i2c port and saves */
                            /* the location and size of the message dis-    */
                            /* patch table.                                 */
                            /************************************************/

    switch( ddcciInit( CI_PORT, STACK_DDCCI, PRIORITY_DDCCI, ciTableSize, ciDispatch ))
    {
        case DDC_FAIL:
            dbmsg_trace( DBM_ALWAYS, "ddc/ci init: generalized fail\r\n" );
            break;
            
        case DDC_PASS:
            dbmsg_trace( DBM_ALWAYS, "ddc/ci init: pass\r\n" );
            cc = EXEC_CC_PASS;
            break;
            
        case DDC_I2CPORT:
            dbmsg_trace( DBM_ALWAYS, "ddc/ci init: invalid i2c port number\r\n" );
            break;
            
        case DDC_OPEN:
            dbmsg_trace( DBM_ALWAYS, "ddc/ci init: unable to open i2c slave\r\n" );
            break;
            
        case DDC_TASK:
            dbmsg_trace( DBM_ALWAYS, "ddc/ci init: unable to start DDC/CI task\r\n" );
            break;
    }
    
                            /************************************************/
                            /* Initialize debug messaging if enabled and if */
                            /* memory is available for buffering.           */
                            /************************************************/

    if( gpConfiguration -> Peripherals.DdcciConfig > 1 )
    {
        if( RTA_SUCCESS == RTA_MemRequest( gID_MemPool, DBSIZE, (void**)&dbuffer ))
        {
            dbp      = dbuffer;          /* pointer to first available byte */
            dbremain = DBSIZE;           /* bytes remaining in debug buffer */
           *dbuffer  = 0;                         /* end-of-messages marker */
            ddcciDbCallback( _ddcCallback );
        }
    }
    
    return cc;
}



/****************************************************************************/
/* 0x01 Get VCP feature                                                     */
/*                                                                          */
/* Fetch feature parameters and format a response message when a request    */
/* for a valid feature is received.                                         */
/*                                                                          */
/* The same algorithm is used to fetch all the video features, so the 'get' */
/* functions takes pointers to functions which obtain limits for the        */
/* setting and which get current values from hardware. Values read depend   */
/* on the active connector. If no connector is active (no exernal source    */
/* displayed), a midrange value is returned. This is done to ensure a valid */
/* response is always returned - Some control panel programs assume that    */
/* a feature is not available if a valid response is not returned for a     */
/* query.                                                                   */
/****************************************************************************/

static void _vcpParms( pCI_MESSAGE pmsg, uint16 mParm, uint16 sParm )
{
   pmsg -> text[3] = (uint08)( mParm >> 8 );
   pmsg -> text[4] = (uint08)( mParm );             /* max normalized value */
   pmsg -> text[5] = (uint08)( sParm >> 8 );               /* current value */
   pmsg -> text[6] = (uint08)( sParm );                    /* current value */
}

/****************************************************************************/

static DDC_COMP ciCmdGetVcp( pCI_MESSAGE pMsg, pCI_MESSAGE pRsp )
{
    DDC_COMP     cc = DDC_PASS;                          /* completion code */
    DP_CONNECTOR conn;                           /* active connector number */
    uint16       normValue;                             /* normalized value */
        
    dbmsg_trace( DBM_DDCCI, "ciCmdGetVcp\r\n" );
    
    ddcciRspAvailable( FALSE );      /* any unread response no longer valid */
    
                            /************************************************/
                            /* Get active connector number. If an external  */
                            /* source is not being displayed, format a set  */
                            /* response. This may be overwritten depending  */
                            /* on the VCP code. Note this is an unusual     */
                            /* case since the host uses display output to   */
                            /* manipulate the virtual control panel.        */
                            /************************************************/

    conn = datapath_GetActiveDisplay();

    if( conn >= LAST_CONNECTOR )
       _vcpParms( pRsp, MAXNORM - 1, MAXNORM / 2 );
    
                            /************************************************/
                            /* Fetch the normalized current setting. The    */
                            /* same algorithm is used for each, so the get- */
                            /* function takes pointer to functions which    */
                            /* obtain limits for the setting and which get  */
                            /* current value from hardware.                 */
                            /************************************************/

    switch( pMsg -> text[0] )                                 /* VCP opcode */
    {
        case VCP_CONTRAST:                                      /* contrast */
            if( conn < LAST_CONNECTOR )
            {
               _getVCP( &normValue, pictcont_GetContrastLimits, pictcont_GetContrast );

⌨️ 快捷键说明

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