/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/


#ifndef _COMMAND_TASK_H_
#define _COMMAND_TASK_H_

#include "custom_def.h"

//Command ARM to T8032
#define Cmd_EnterPowerDown       0x01
#define Cmd_EnterPowerNormal    0x02
	#define Cmd_Sub_PowerStage_loader         0x01
    	#define Cmd_Sub_PowerStage_normal      0x02
#define Cmd_QuerySwVersion        0x03
#define Cmd_EnterXdataSwitch      0x04
    #define Cmd_Sub_Xdata_ARM         0x01
    #define Cmd_Sub_Xdata_T8032      0x02
#define Cmd_ReadT8032WakeUp   0x05
#define Cmd_SetLightGuideLevel   0x06
#define Cmd_AliveCheck		      0x07
#define Cmd_SetClearErrCode	      0x08
	#define Cmd_Sub_ClearErrBuf	      0xFF
#define Cmd_EnableDisableErrCode 0x09
	#define Cmd_Sub_EnableErrCode	      0x01
	#define Cmd_Sub_DisableErrCode	      0x02
//CEC command
#define Cmd_CEC_MenuLanguage 	0x0a
#define Cmd_CEC_EnableCEC	 	0x0b
#define Cmd_CEC_EnableOneTouch	0x0c
#define Cmd_SetLEDBlink			0x0d
#define Cmd_SetFWUpgrate		0x0e
#define Cmd_SetPowerDownJob	0x0f
#define Cmd_ClrPowerDownJob	0x10

#define Cmd_ColdReboot			0x11
#define Cmd_DigitKeyWakeup		0x12

//#define Cmd_SetCustData	0x13

#define Cmd_SetBaudrate	0x16
//#define Cmd_EnableDisableLedToggle 0x17
//#define Cmd_SetT8032DebugLevel 0x18
#define Cmd_GetIrWakeupValue        0x18

#define Cmd_EnableWRGBLed 		 0x19
#if SUSPEND_MODE
#define Cmd_ConsoleLockQuery     0x20
#define Cmd_ConsoleLockSet       0x21
    #define Cmd_Sub_ConsoleLockOff		  0x00
    #define Cmd_Sub_ConsoleLockOn		  0x01

#endif
#define Cmd_NextWakeupTime      0x22

#define Cmd_CM4TriggerT8032Wakeup  0x30

#if 1//CUS_S_MULTI_KEY_ECO
#define Cmd_QueryServiceMode	0x40
#endif
#if RC56_IR_DRIVER
#define Cmd_SetClrIR_FILTER		0x41
	#define Cmd_Sub_SetIR_FilterSysCode	      0x01
	#define Cmd_Sub_ClrIR_FilterSysCode	      0x02
#endif
#define Cmd_CEC_SupportUserControlPressed 0x50
#define Cmd_CEC_SetVendorID 0x51
#define Cmd_CEC_SetVersion 	0x52
#define Cmd_CEC_SetOSDName1 0x53
#define Cmd_CEC_SetOSDName2 0x54
#define Cmd_CEC_SetOSDName3 0x55
#define Cmd_CEC_SetOSDName4 0x56
#define Cmd_CEC_SetWakeupOpCode1	0x57
#define Cmd_CEC_SetWakeupOpCode2	0x58
#define Cmd_CEC_SetWakeupOpCode3	0x59
#define Cmd_CEC_SetT8032CtlCEC		0x5a

#if SIF_PDWNC_TEST
#define    Cmd_PDSIF_READ	  0x60
#define    Cmd_PDSIF_WRITE	  0x61
#define    Cmd_PDSIF_EEP_READ	  0x62
#define    Cmd_PDSIF_EEP_WRITE	  0x63
#endif
#if SUSPEND_MODE
#define Cmd_EnterSuspend     0x70
#endif
#define Cmd_EnterDramSelfRefresh 0x77
#define Cmd_GPIOOutputEnable 	 0x80
#define Cmd_GPIOOutput			 0x81
#define Cmd_GPIOInput			 0x82
#define Cmd_ServoOutputEnable 	 0x83
#define Cmd_ServoOutput			 0x84
#define Cmd_ServoInput			 0x85
#define Cmd_OtherEngineSwitch	 0x86
#define Cmd_Sub_OtherEngine_ARM         0x01
#define Cmd_Sub_OtherEngine_T8032      0x02
//#ifdef ENABLE_CBUS
#define Cmd_Cbus_SetT8032CtlCbus		0x87
//#endif
#define Cmd_Cbus_SetT8032CtlActiveStd 0x75

#define Cmd_Turnkey_Max	 0x88


#define Cmd_SetIRWakeupKEY (Cmd_Turnkey_Max + 1)
#define Cmd_SetDisableWakeupTime (Cmd_Turnkey_Max + 2)
#define Cmd_SetCustData	(Cmd_Turnkey_Max + 3)
#define Cmd_GetCustData	(Cmd_Turnkey_Max + 4)
#if CY8C20110_SUPPORT
#define Cmd_SetCapSenseAddress (Cmd_Turnkey_Max + 5)
#endif
#if STANDBY_AC_DETECTION
#define Cmd_SetACDetectPins     (Cmd_Turnkey_Max + 6) 
#endif
#define Cmd_SetEcoMode	(Cmd_Turnkey_Max + 7) //95

#define Cmd_SetPowerKey1	    (Cmd_Turnkey_Max + 8) //96
#define Cmd_SetPowerKey2	    (Cmd_Turnkey_Max + 9) //97
#define Cmd_SetPowerKey3	    (Cmd_Turnkey_Max + 10) //98
#define Cmd_SetPowerKey4	    (Cmd_Turnkey_Max + 11) //99
#define Cmd_SetPowerKey5	    (Cmd_Turnkey_Max + 12) //100
#define Cmd_SetPowerKey6	    (Cmd_Turnkey_Max + 13) //101
#define Cmd_SetPowerKey7	    (Cmd_Turnkey_Max + 14) //102
#define Cmd_SetPowerKey8	    (Cmd_Turnkey_Max + 15) //103
#define Cmd_SetPowerKey9	    (Cmd_Turnkey_Max + 16) //104
#define Cmd_SetPowerKey10	    (Cmd_Turnkey_Max + 17) //105
#define Cmd_SetPowerKey11	    (Cmd_Turnkey_Max + 18) //106
#define Cmd_SetPowerKey12	    (Cmd_Turnkey_Max + 19) //107
#define Cmd_SetPowerKey13	    (Cmd_Turnkey_Max + 20) //108
#define Cmd_SetPowerKey14	    (Cmd_Turnkey_Max + 21) //109
#define Cmd_SetPowerKey15	    (Cmd_Turnkey_Max + 22) //110
#define Cmd_SetPowerKey16	    (Cmd_Turnkey_Max + 23) //111

#define Cmd_ReadT8032WakeUpNew  (Cmd_Turnkey_Max + 24)//112  

    #define T8032_IR_WAK_POWER      0x01
    #define T8032_IR_WAK_CH_UP_DOWN 0x02    
    #define T8032_IR_WAK_NUMERIC    0x04        
    #define T8032_IR_WAK_DTV        0x08    
    #define T8032_IR_WAK_ATV        0x10    
    #define T8032_IR_WAK_JUMP       0x20
    #define T8032_IR_WAK_ADTV_SW    0x40
	#define T8032_IR_WAK_NETFLIX_SW 0x80 
#if QUERY_IR_POWER_KEY_STATE_SUPPORT
#define Cmd_QueryIRPowerKeyState            0x99
#endif
#define Cmd_IceModeQuery     Cmd_Turnkey_Max+25
#define Cmd_IceModeSet       Cmd_Turnkey_Max+26

//#define Cmd_QueryIRPowerKeyState            0x99
//#define Cmd_QueryIRPowerKeyStateOK	 0x99

//Command T8032 to ARM
#define Cmd_EnterPowerNormalReady    0x02
#define Cmd_ResponseSWVersion            0x03
#define Cmd_XdataSwitchOutReady         0x04
#define Cmd_ResponseWakeupReason    0x05
    #define Cmd_Sub_WakeUP_CEC         	0x01
    #define Cmd_Sub_WakeUP_ColdReboot    0x02
#define Cmd_SetLightGuideLevelOK         0x06
#define Cmd_T8032Alive			         0x07
	#define Cmd_Sub_T8032AliveInitializing	0x00
	#define Cmd_Sub_T8032AliveReady		0x01
#define Cmd_SetClearErrCodeOK		  0x08
#define Cmd_EnableDisableErrCodeOK    0x09
#define Cmd_ResponseCEC_MenuLanguage 	0x0a
#define Cmd_ResponseCEC_EnableCEC	 	0x0b
#define Cmd_ResponseCEC_EnableOneTouch	0x0c
#define Cmd_SetLEDBlinkOK	0x0d
#define Cmd_SetFWUpgrateOK	0x0e
#define Cmd_SetPowerDownJobOK	0x0f
#define Cmd_ClrPowerDownJobOK	0x10

//#define Cmd_ColdRebootOK			0x11 //cold reboot doesn't need response
#define Cmd_DigitKeyWakeupOK		0x12
#define Cmd_ResponseSetCustData	0x13
#if 1//CUS_S_MULTI_KEY_ECO
#define Cmd_responseServiceMode	0x40
#endif

#define Cmd_ResponseCEC_SupportUserControlPressed 	0x50
#define Cmd_ResponseCEC_SetVendorID 	0x51
#define Cmd_ResponseCEC_SetVersion 		0x52
#define Cmd_ResponseCEC_SetOSDName1 	0x53
#define Cmd_ResponseCEC_SetOSDName2 	0x54
#define Cmd_ResponseCEC_SetOSDName3 	0x55
#define Cmd_ResponseCEC_SetOSDName4 	0x56
#define Cmd_ResponseCEC_SetWakeupOpCode1	0x57
#define Cmd_ResponseCEC_SetWakeupOpCode2	0x58
#define Cmd_ResponseCEC_SetWakeupOpCode3	0x59
#define Cmd_ResponseCEC_SetT8032CtlCEC		0x5a

#define Cmd_ResponseGPIOOutputEnable 	 0x80
#define Cmd_ResponseGPIOOutput			 0x81
#define Cmd_ResponseGPIOInput			 0x82
#define Cmd_ResponseServoOutputEnable 	 0x83
#define Cmd_ResponseServoOutput		 0x84
#define Cmd_ResponseServoInput			 0x85
//#ifdef ENABLE_CBUS
#define Cmd_ResponseCbus_SetT8032CtlCbus		0x87
//#endif

#define Cmd_ResponseOtherEngineSwitch	 0x88

#define Cmd_ResponseCbus_SetT8032CtlMhlPullDown		0x90
#define Cmd_ResponseCbus_enable_pulldown		    0x79

#if IR_DEBOUNCE
extern UINT8 u1IRDebounceTime; 
#endif


#if ENABLE_CEC
extern UINT8 fgCECMenuLanguage;
extern UINT8 fgCECEnableCEC;
extern UINT8 fgCECEnableOneTouchPlay;
extern UINT8 fgCECT8032CtlCEC;
extern UINT8 fgCECSetVendorID;
extern UINT8 fgCECSetVersion;
#ifdef CEC_FEATURE_3_1 
extern UINT8 fgCECSetOSDName1;
extern UINT8 fgCECSetOSDName2;
extern UINT8 fgCECSetOSDName3;
extern UINT8 fgCECSetOSDName4;
extern UINT8 fgCECSetWkpCode1;
extern UINT8 fgCECSetWkpCode2;
extern UINT8 fgCECSetWkpCode3;
#endif
#endif
extern UINT8 fgOtherEngineSwitch;
extern UINT8 bOtherEngine;
#if UART_PD_RX_EN
extern UINT8 xdata uRs232Data[32];
extern UINT8 xdata uRs232Rxidx;
extern UINT8 xdata fgRs232Rx;
#endif

#if IR_MULTIKEY_WAKEUP
extern UINT8 xdata u1IRkeyBuf[5];
extern UINT8 xdata u1IRBufIdx;
#endif


#if SUPORT_DIGIT_KEY_WAKEUP
extern UINT8 fgWakeUpDigitKey;
extern UINT8 u1WakeUpDigit;
#endif
extern UINT8 xdata u1WakeupReason;
extern UINT8 fgTrigARMIntEn;


extern void vCommandTaskInit(void);
extern void vCommandTask(void);
extern void vCMD_RESONSE(UINT8 u1Cmd, UINT8 u1Para0, UINT8 u1Para1, UINT8 u1Para2);
#if 0
typedef union DATA_FROM_ARM
{
       struct DATA_FROM_ARM_BYTE
	{
            UINT8 byte0;
            UINT8 byte1;
            UINT8 byte2;
            UINT8 byte3;            
        }BYTES;

    UINT32 u4Value;
}DATA_FROM_ARM;
#endif

#endif //_COMMAND_TASK_H_
