📄 irbutton.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. */
/****************************************************************************/
/****************************************************************************/
/* irButton.c */
/* */
/* NEC Button IR protocol handler. */
/* */
/* This module receives a necStart() intialization call to prepare for */
/* decoding, then receives a necEvent() call each time an IR power pulse */
/* edge is seen by the IR receiver. These calls are used to run a finite */
/* state machine which decodes the protocol and returns a keycode to the */
/* caller when one is detected. */
/****************************************************************************/
#include "common.h"
#include "irRemote.h"
#include "keycode.h"
#include "irButton.h"
#include "dbmessage.h"
/****************************************************************************/
/* Protocol interface. */
/* */
/* Defines entry points into the IR protocol handler. */
/****************************************************************************/
static void necStart( uint08 port );
static BOOL necEvent( UIREP *report, uint08 port, uint16 width );
const IR_PROTOIF_STRUCT NECButtonProtocol =
{
necStart,
necEvent
};
/****************************************************************************/
/* Application configuration section. */
/* */
/* Elements in this section are modified to adapt the protcol handler for */
/* an application-specific remote control unit. */
/* */
/* Despite the fact that keymap is a static variable, the ARM debugger is */
/* not capable of differentiating between multiple instances of the name. */
/* Thus each protocol handler must use a different variable name if related */
/* code is to be successfully debugged. */
/****************************************************************************/
#define KEYN_SEPARATE 200 /* milliseconds separating key presses */
#define KEYN_REPDELAY 500 /* first repeat delay */
/****************************************************/
/* Scan code to keycode conversion table. */
/****************************************************/
static const struct keymapper_struct
{
uint08 fcode; /* remote control function code */
BOOL repflag; /* repeat flag */
KCODE_ENUM kcode; /* decoded key code */
}
keymapN[] =
{
{ 0x02, FALSE, KCODE_IR_POWER },
{ 0x04, FALSE, KCODE_IR_SOURCE },
{ 0x05, TRUE, KCODE_IR_LEFT_ARROW },
{ 0x06, TRUE, KCODE_IR_RIGHT_ARROW },
{ 0x07, FALSE, KCODE_IR_BLANK },
{ 0x08, TRUE, KCODE_IR_ZOOM_INC },
{ 0x09, TRUE, KCODE_IR_KEYSTONE_INC },
{ 0x0a, TRUE, KCODE_IR_BRIGHT_INC },
{ 0x0b, TRUE, KCODE_IR_ZOOM_DEC },
{ 0x0c, TRUE, KCODE_IR_KEYSTONE_DEC },
{ 0x0d, TRUE, KCODE_IR_BRIGHT_DEC },
{ 0x0e, FALSE, KCODE_IR_EXIT },
{ 0x0f, FALSE, KCODE_IR_MENU },
{ 0x10, FALSE, KCODE_IR_SELECT }
};
static const uint08 keycount = /* number of table entries */
sizeof( keymapN ) / sizeof( struct keymapper_struct );
/****************************************************/
/* Remote control ID, unique to each manufacturer. */
/****************************************************/
static const uint16 customercode =
0x4954; /* customer ID code */
/****************************************************************************/
/* Protocol timing constants. These define protocol element pulse widths */
/* Normally these are not modified. 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 modifi- */
/* cation if sampling rate or noise filter constant is changed to adapt to */
/* application-specific requirements. */
/****************************************************************************/
#define WIDTH_SYN1 ( 9000 / IRSAMPLEPERIOD ) /* message sync high */
#define WIDTH_SYN2 ( 4500 / IRSAMPLEPERIOD ) /* message sync low */
#define WIDTH_ZBIT ( 560 / IRSAMPLEPERIOD ) /* zero-bit */
#define WIDTH_OBIT ( 1740 / IRSAMPLEPERIOD ) /* one-bit */
/****************************************************************************/
/* Protocol pulse description constants. These define expected protocol */
/* pulse widths and high/low states. They are decoded from IR receiver FIFO */
/* events. */
/****************************************************************************/
#define LO_ZBIT (( 0 << 1 ) + 0 ) /* zero bit interval low */
#define LO_OBIT (( 1 << 1 ) + 0 ) /* one bit interval low */
#define LO_SYN1 (( 2 << 1 ) + 0 ) /* sync1 interval low */
#define LO_SYN2 (( 3 << 1 ) + 0 ) /* sync2 interval low */
#define LO_UNEX (( 4 << 1 ) + 0 ) /* unexpected interval low */
#define HI_ZBIT (( 0 << 1 ) + 1 ) /* zero bit interval high */
#define HI_OBIT (( 1 << 1 ) + 1 ) /* one bit interval low */
#define HI_SYN1 (( 2 << 1 ) + 1 ) /* sync1 interval high */
#define HI_SYN2 (( 3 << 1 ) + 1 ) /* sync2 interval high */
#define HI_UNEX (( 4 << 1 ) + 1 ) /* unexpected interval low */
/****************************************************************************/
/* Protocol handler finite state machine states. State numbers are shifted */
/* four bits so that state and pulse description may be ORd in the finite */
/* state machine to determine state action. */
/****************************************************************************/
#define MS_IDLE ( 0 << 4 ) /* idle, wait for message sync pulse high */
#define MS_SYNC ( 1 << 4 ) /* expect message sync pulse low */
#define MS_SBIT ( 2 << 4 ) /* expect data bit sync high */
#define MS_DBIT ( 3 << 4 ) /* wait for data bit low */
/****************************************************************************/
/* 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 */
uint32 bitRegister; /* Function data bits */
}
IRSTATE;
static IRSTATE issN[2];
/****************************************************************************/
/* Local functions. */
/****************************************************************************/
static BOOL reportKey( UIREP *report, IRSTATE *pss, uint08 thisScan, KCODE_ENUM thisKey );
static uint08 scanCode( uint08 fCode );
static BOOL testCode( UIREP *report, IRSTATE *pss );
/****************************************************************************/
/* Start decoder at reset time. */
/****************************************************************************/
static void necStart( uint08 port )
{
if( port > 1 ) /* limit port to 0 or 1 */
return;
issN[port].fsmState = MS_IDLE; /* initialize finite state machine */
}
/****************************************************************************/
/* 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. */
/* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -