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

📄 irremotepoint.c

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

/****************************************************************************/
/* irRemotePoint.c                                                          */
/*                                                                          */
/* RemotePoint mouse IR protocol handler.                                   */
/*                                                                          */
/* This module receives an intialization call to prepare for decoding, then */
/* receives an event indication each time the detected IR power changes     */
/* from OFF to next OFF state. These events are used to run a finite state  */
/* machine which decodes the protcol and returns a keycode to the caller    */
/* when one is detected.                                                    */
/****************************************************************************/

#include "common.h"

#include "irRemote.h"
#include "keycode.h"
#include "irRemotePoint.h"
#include "dbmessage.h"


/****************************************************************************/
/* Protocol interface.                                                      */
/*                                                                          */
/* Defines entry points into IR protocol handler.                           */
/****************************************************************************/


static void buttRPMStart( uint08 port );
static BOOL buttRPMEvent( UIREP *report, uint08 port, uint16 event );

IR_PROTOIF_STRUCT const RPMouseProtocol =
{
    buttRPMStart,
    buttRPMEvent
};



/****************************************************************************/
/* RPMouse key repeat timing constants.                                     */
/****************************************************************************/

#define RPM_KEY_SEPARATE    200      /* milliseconds separating key presses */
#define RPM_KEY_REPDELAY    500                       /* first repeat delay */



/****************************************************************************/
/* RPMouse field extractors.                                                */
/****************************************************************************/

#define RPM_GET_LRCLICK( report ) ( 0x8080 == ( report & 0x8080 ))
#define RPM_GET_RCLICK( report )  ( 0x8000 == ( report & 0x8000 ))
#define RPM_GET_LCLICK( report )  ( 0x0080 == ( report & 0x0080 ))

#define RPM_GET_XMOUSE( report )  ((int16)(( report & 0x7f00 ) << 1 ) >> 8 )
#define RPM_GET_YMOUSE( report )  ((int16)(( report & 0x007f ) << 9 ) >> 8 )



/****************************************************************************/
/* Expected pulse widths, either one half or a full bit period duration.    */
/* Each element is defined by its width in microseconds divided by the IR   */
/* sampling rate in microseconds. The nominal rate is 10 uSec, but it is    */
/* parameterized to allow simple modification if sampling rate or noise     */
/* filter constant is changed to adapt to application requirements.         */
/****************************************************************************/

#define H_WIDTH  (  600 / IRSAMPLEPERIOD )                   /* half period */
#define F_WIDTH  ( 1200 / IRSAMPLEPERIOD )                   /* full period */



/****************************************************************************/
/* Protocol pulse description constants. These define expected protocol     */
/* pulse widths and high/low states. They are decoded from IR receiver FIFO */
/* events.                                                                  */
/****************************************************************************/

#define LO_WIDTH1  (( 0 << 1 ) + 0 )                /* half bit period low  */
#define LO_WIDTH2  (( 1 << 1 ) + 0 )                /* full bit period low  */
#define LO_WIDTHX  (( 2 << 1 ) + 0 )          /* unexpected bit period low  */ 
#define HI_WIDTH1  (( 0 << 1 ) + 1 )                /* half bit period high */
#define HI_WIDTH2  (( 1 << 1 ) + 1 )                /* full bit period high */
#define HI_WIDTHX  (( 2 << 1 ) + 1 )          /* unexpected bit period high */



/****************************************************************************/
/* Protocol handler finite state machine states. State numbers are shifted  */
/* three bits so that state and pulse description may be ORd in the finite  */
/* state machine to determine state action.                                 */
/****************************************************************************/

#define MS_IDLE  ( 0 << 3 )                        /* state machine is idle */
#define MS_SYNC  ( 1 << 3 )      /* waveform decode is at end of sync pulse */
#define MS_BGN0  ( 2 << 3 )      /* waveform decode is at start  of a 0 bit */
#define MS_BGN1  ( 3 << 3 )      /* waveform decode is at start  of a 1 bit */
#define MS_MID0  ( 4 << 3 )      /* waveform decode is at middle of a 0 bit */
#define MS_MID1  ( 5 << 3 )      /* waveform decode is at middle of a 1 bit */



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

typedef struct irStateStruct        /* Protocol handler state, one per port */
{
    uint08     fsmState;                      /* Finite state machine state */
    uint08     bitCount;                 /* Count of function bits received */
    KCODE_ENUM keyPrior;                                       /* prior key */
    uint08     keyRepeat;                              /* key is repeatable */
    uint32     keyFirstTime;       /* first time at which this key reported */
    uint32     keyTime;                /*time at which last key report sent */
    uint16     keyRepCount;             /* number of times key has repeated */
    uint16     bitRegister;                           /* Function data bits */
}
    IRSTATE;

static IRSTATE issRPM[2];          /* state of front and back IR interfaces */
static BOOL    isKeyMode;              /* TRUE == pointer is in keypad mode */
       

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

static BOOL reportRPKey( UIREP *report, IRSTATE *pss, KCODE_ENUM thisKey );
static BOOL testCode( UIREP *report, IRSTATE *pss );



/****************************************************************************/
/* Start decoder at reset time.                                             */
/****************************************************************************/

static void buttRPMStart( uint08 port )
{
    if( port > 1 )                                  /* limit port to 0 or 1 */
        return;

    isKeyMode             = FALSE;                   /* start in mouse mode */
    issRPM[port].fsmState = MS_IDLE;     /* initialize finite state machine */
    issRPM[port].keyTime  = 0;                               /* no key time */
}



/****************************************************************************/
/* Set mode of thumb button.                                                */
/****************************************************************************/

void rpmouse_setkeymode( BOOL keyMode )
{
    isKeyMode = keyMode;
}



/****************************************************************************/
/* Process an IR event.                                                     */
/*                                                                          */
/*   report: Pointer to an IR report structure, filled if an IR event is    */
/*           decoded.                                                       */
/*     port: IR hardware port zero or one.                                  */
/*    event: IR event description.                                          */
/*             bit 15     - 0: power low interval   1: power high interval  */
/*             bit 14..00 - duration, in sample periods.                    */
/*                                                                          */
/* Reurns:                                                                  */
/*  TRUE if a report completed decode with the current event.               */
/****************************************************************************/

static BOOL buttRPMEvent( UIREP *report, uint08 port, uint16 event )
{
    IRSTATE *pss = &issRPM[port];          /* pointer to IR state structure */
    uint08   eventDesc;                             /* IR event description */
    
    if( port > 1 )                                  /* limit port to 0 or 1 */
        return FALSE;

                        /****************************************************/
                        /* Determine if this is an IR message sync point.   */
                        /*                                                  */
                        /* Start/end of an IR message is indicated by the   */
                        /* IRMSGSYNC constant value.                        */
                        /****************************************************/
                        
    if( event == IRMSGSYNC )                               /* if sync point */
    {
        pss -> fsmState = MS_IDLE;       /* initialize finite state machine */
        
        return FALSE;
    }
                        /****************************************************/
                        /* Generate event description.                      */
                        /*                                                  */
                        /* Half-width or full-width assignment is made if   */
                        /* the reported width is within 25% of nominal.     */
                        /****************************************************/
    
    eventDesc = ( 0x8000 == ( 0x8000 & event ));          /* high/low state */
    
    event &= 0x7fff;                  /* mask off high/low state indication */
    
    if( ABS( event - H_WIDTH ) <= ( H_WIDTH >> 2 ))
        eventDesc |= LO_WIDTH1;                               /* half-width */
        
    else if( ABS( event - F_WIDTH ) <= ( F_WIDTH >> 2 )) 
        eventDesc |= LO_WIDTH2;                               /* full-width */
        

⌨️ 快捷键说明

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