#ifndef _IR_H_
#define _IR_H_
#include "types.h"
#include "drv_types.h"
#ifndef _CCOPTS_
#include <sys/types.h>
#endif
#include "Customization.h"

#define IRRECEIVEWAITTIME 100000000
#define IR_INVALID_VALUE	0x100	/**<IR Invalid Value	*/
#define IR_EVENT_REPEAT_TYPE    (0x80000000)
#define KEYPAD_EVENT_REPEAT_TYPE    (0x40000000)
#define IR_EVENT_REPEAT_END    (0x20000000)
#define KEYPAD_EVENT_REPEAT_END    (0x10000000)
#define IR_EVENT_SINGLE_END    (0x08000000)


#define CUS_CODE_COUNT 		10
#define IR_KEY_NUMBER_MAX 	128

typedef	void	(*pfunc)(UINT32*);
typedef	UINT8	(*pfunc3)(UINT32, UINT8, UINT32 *);

enum{
	ir_Press,
	ir_Single_end,
	ir_Repeat,
	ir_repeat_end,
};

typedef enum {
	KEYSTATUS_NORMAL,
	KEYSTATUS_CONT,
	KEYSTATUS_CONTEND,
	KEYSTATUS_NOREND
}KEYSTATUS;

typedef struct _IRKeymap_t {
    UINT16 CusCode;
    UINT8 Keycode;
    UINT32 Event;
} IRKeymap_t, *PIRKeymap_t;

typedef struct {
    IRKeymap_t irUMFMapping[IR_KEY_NUMBER_MAX];
    UINT16 irCstCode[CUS_CODE_COUNT];
    IR_PowerOnKeyCode irPowerOnKey;
} IRKeyInfo_t, *PIRKeyInfo_t;

typedef struct {
    const UINT8 IRName[16];
    const IRKeymap_t *pdIR_Map;
    UINT8 IR_Count;
    UINT16 *pCID;
    pfunc pfIRConvert;
    pfunc3 pfIRGetEvent;
} IR_MAP_t;

typedef struct
{
    UINT8 *Items;
    UINT8 Size;
} IR_RC_RepeatKey;


typedef struct _IRKey_t
{
	BOOLEAN bValid;
	UINT8 IRKeyStatus;
	UINT16 IRKey;
	UINT16 IRAndroidKey;
}IRKey_t;

typedef enum {
	IRSTATUS_NORMAL,
	IRSTATUS_POWEROFF
}IRDevStatus;

#pragma pack(push,1)

#define IRKeySettingNumber 2
#define IRKeyAddressNumber 2


//up to two HW key address
typedef struct _KeyMap_t
{
	UINT16 HWKey_H;
	UINT16 HWKey_L;
	UINT16 KeyCode;
	UINT16 AndroidKeyCode;
}KeyMap_t;

#pragma pack(pop)


typedef struct _Keycode_t
{
	UINT32		key;
	UINT32		status;
}Keycode_t, *PKeycode_t;


//------- IR key status --------------------

#define IR_KEY_NORMAL					0
#define IR_CONTINUE_KEY_START_END		1
#define IR_CONTINUE_KEY_START			2
#define IR_CONTINUE_KEY_END				3
#define IR_KEY_NORMAL_END				5

//----------------------------------------

//------- Keypad key status-----------------

#define KP_KEY_NORMAL			0
#define KP_CONTINUE_KEY_START	1
#define KP_CONTINUE_KEY_END		2
#define KP_KEY_NORMAL_END		5

//------- ---------------------------------

typedef	void (* IR_CallBack_t)(UINT32 KeyCode, UINT32 CusCode, UINT8 KeyValue);
#if defined (CONFIG_KEYPAD_SINGLE_REUSE)  || defined(CONFIG_KEYPAD_THREE_KEY_REUSE) ||  defined(CONFIG_KEYPAD_FIVE_KEY_REUSE)
typedef	void (* KP_CallBack_t)(UINT32 *dMessage);
#endif

INT32 ir_SetMappingTable(IR_MAP_t* pIRTable, UINT32 dTableSize);
INT32 ir_init(IR_CallBack_t pIR_CallBackFunc);
int ir_finalize(void);

#ifndef _CCOPTS_
HRESULT umfsleep(time_t  sec, long nsec);
#endif

#ifdef CONFIG_TESTAUTOREBOOT
void ir_autoreboot_disable(void);
void ir_autoreboot_enable(void);
#endif
int ir_LoadEventCode(UINT8 table_index);
void KP_Set_MapTable(UINT8 table_index);

#ifdef SUPPORT_FACTORY_AUTO_TEST_MODE4
UINT16 ir_GetLastKPKey(void);
#endif

#if defined (CONFIG_KEYPAD_SINGLE_REUSE)  || defined(CONFIG_KEYPAD_THREE_KEY_REUSE) ||  defined(CONFIG_KEYPAD_FIVE_KEY_REUSE)
void ir_RegisterKpCallback(KP_CallBack_t pKP_CallBackFunc);
#endif

#endif //_IR_H_

