/*******************************************************************************
*
*
* File:        app_tp_for_custom.c
* Description  tp 协议处理文件，包括报点协议转换、start/sleep/awake 等固定传输数据的配置
* Version      V0.1
* Date         2021-10-14
* Author       zhanghz
*******************************************************************************/
#include "test_cfg_global.h"


#include "app_tp_for_custom_s21u.h"
#include "app_tp_phone_transfer_data_s21u.h"
#include "app_tp_screen_transfer_data_s21u.h"
#include "tau_log.h"
#include "tau_delay.h"

#ifdef LOG_TAG
    #undef LOG_TAG
#endif
#define LOG_TAG "s21u_tp"

#define S8_TP_DEBUG_LOG 0

#define Touch_Single_AOD 		1  // 息屏后单点触摸唤醒 AOD 显示
#define Touch_Double_PowerUp 	2  // 息屏后双击唤醒屏幕进入界面

#define Touch_Single_AOD_Time 		20  // 息屏后单点持续时间 小于20*10 = 200ms
#define Touch_Double_PowerUp_Time 	50  // 息屏后双击唤醒：两个点释放相差时间不超过 50*10 = 500ms

io_pad_e g_screen_input_rst_pad = IO_PAD_TD_TPRSTN;
io_pad_e g_screen_input_int_pad = IO_PAD_TD_INT;
io_pad_e g_phone_input_rst_pad  = IO_PAD_AP_TPRSTN;
io_pad_e g_phone_output_int_pad = IO_PAD_AP_INT;

/*************************************报点协议 master 相关 buffer ****************************************/
#if 1
#if 1
    #ifndef u8
        #define u8  uint8_t
    #endif
    #ifndef u16
        #define u16 uint16_t
    #endif
    #ifndef u32
        #define u32 uint32_t
    #endif
    #ifndef u64
        #define u64 uint64_t
    #endif
    #ifndef U8
        #define U8  uint8_t
    #endif
    #ifndef U16
        #define U16 uint16_t
    #endif
    #ifndef U32
        #define U32 uint32_t
    #endif
    #ifndef U64
        #define U64 uint64_t
    #endif
    #ifndef s8
        #define s8  int8_t
    #endif
    #ifndef s16
        #define s16 int16_t
    #endif
    #ifndef s32
        #define s32 int32_t
    #endif
    #ifndef s64
        #define s64 int64_t
    #endif
    #ifndef S8
        #define S8  int8_t
    #endif
    #ifndef S16
        #define S16 int16_t
    #endif
    #ifndef S32
        #define S32 int32_t
    #endif
    #ifndef S64
        #define S64 int64_t
    #endif
#endif

#define Touch_Release_Event_Time    2   //手指松开时间 50ms步进
#define Touch_MAX_Point 5  //最大触摸点
typedef struct
{
    u16 X; // 坐标
    u16 Y; // 坐标
    u16 X_in; // 坐标
    u16 Y_in; // 坐标
    u16 Z; // 触摸面积
    u8  Event;//0无触 1按下 2移动 3松开
    u8  Eventbk;//0无触 1按下 2移动 3松开
    u16  Event_Time;//事件保持时间
} Touch_Single_Point_str;

typedef struct
{
    Touch_Single_Point_str Touch_Single_Point[Touch_MAX_Point];//最大 5 个触摸点
    u8 Event_Hold;//事件保持 1表示有触摸点事件
    u8 Event_Single_Flag;//单次触发触摸点事件,1表示当前可以触发一次触点事件,可给中断
} Touch_str;
Touch_str Touch = //初始化值
{
    .Touch_Single_Point[0] = (Touch_Single_Point_str){.X = 0, .Y = 0, .X_in = 0, .Y_in = 0, .Z = 0, .Event = 0, .Eventbk = 0, .Event_Time = 0,},
    .Touch_Single_Point[1] = (Touch_Single_Point_str){.X = 0, .Y = 0, .X_in = 0, .Y_in = 0, .Z = 0, .Event = 0, .Eventbk = 0, .Event_Time = 0,},
    .Touch_Single_Point[2] = (Touch_Single_Point_str){.X = 0, .Y = 0, .X_in = 0, .Y_in = 0, .Z = 0, .Event = 0, .Eventbk = 0, .Event_Time = 0,},
    .Touch_Single_Point[3] = (Touch_Single_Point_str){.X = 0, .Y = 0, .X_in = 0, .Y_in = 0, .Z = 0, .Event = 0, .Eventbk = 0, .Event_Time = 0,},
    .Touch_Single_Point[4] = (Touch_Single_Point_str){.X = 0, .Y = 0, .X_in = 0, .Y_in = 0, .Z = 0, .Event = 0, .Eventbk = 0, .Event_Time = 0,},
#if (Touch_MAX_Point==10)
    .Touch_Single_Point[5] = (Touch_Single_Point_str){.X = 0, .Y = 0, .X_in = 0, .Y_in = 0, .Z = 0, .Event = 0, .Eventbk = 0, .Event_Time = 0,},
    .Touch_Single_Point[6] = (Touch_Single_Point_str){.X = 0, .Y = 0, .X_in = 0, .Y_in = 0, .Z = 0, .Event = 0, .Eventbk = 0, .Event_Time = 0,},
    .Touch_Single_Point[7] = (Touch_Single_Point_str){.X = 0, .Y = 0, .X_in = 0, .Y_in = 0, .Z = 0, .Event = 0, .Eventbk = 0, .Event_Time = 0,},
    .Touch_Single_Point[8] = (Touch_Single_Point_str){.X = 0, .Y = 0, .X_in = 0, .Y_in = 0, .Z = 0, .Event = 0, .Eventbk = 0, .Event_Time = 0,},
    .Touch_Single_Point[9] = (Touch_Single_Point_str){.X = 0, .Y = 0, .X_in = 0, .Y_in = 0, .Z = 0, .Event = 0, .Eventbk = 0, .Event_Time = 0,},
#endif
    .Event_Hold = 0,
    .Event_Single_Flag = 0,
};



typedef struct
{
//    uint16_t    record_cmd_len;
//    uint8_t     record_cmd;
//    uint8_t     dma_handshake;
//    uint8_t     gesture_en;
//    uint8_t     status;
//    uint8_t     status_app;
//    uint8_t     status_wait_idle_boot; // For FT8719_SPI_STATUS_PACKAGE

    uint8_t     D60_count; // FTS_REG_FW_VER
    uint8_t     D85_count; // FTS_REG_FW_VER
    uint8_t     D92_count; // FTS_REG_FW_VER
    uint8_t     reg_60_0[16]; // FTS_REG_FW_VER
    uint8_t     reg_60_1[16]; // FTS_REG_FW_VER
    uint8_t     reg_60_2[16]; // FTS_REG_FW_VER
    uint8_t     reg_60_3[16]; // FTS_REG_FW_VER
    uint8_t     reg_60_4[16]; // FTS_REG_FW_VER
    uint8_t     reg_60_5[16]; // FTS_REG_FW_VER
    uint8_t     reg_60_6[16]; // FTS_REG_FW_VER
    uint8_t     reg_60_7[16]; // FTS_REG_FW_VER
    uint8_t     reg_60_8[16]; // FTS_REG_FW_VER
    uint8_t     reg_60_9[16]; // FTS_REG_FW_VER
    uint8_t     reg_60_10[16]; // FTS_REG_FW_VER
    uint8_t     reg_60_11[16]; // FTS_REG_FW_VER
    uint8_t     reg_60_12[16]; // FTS_REG_FW_VER

    uint8_t     reg_60_1_0[48]; // FTS_REG_FW_VER
    uint8_t     reg_60_1_1[16]; // FTS_REG_FW_VER
    uint8_t     reg_60_1_2[16]; // FTS_REG_FW_VER
    uint8_t     reg_61_0[16]; // FTS_REG_FW_VER
    uint8_t     reg_61_1[16]; // FTS_REG_FW_VER
    uint8_t     reg_61_2[16]; // FTS_REG_FW_VER
	uint8_t 	reg_61_3[16]; // FTS_REG_FW_VER

    uint8_t     reg_22[5]; // FTS_REG_FW_VER
    uint8_t     reg_21[1]; // FTS_REG_FW_VER
    uint8_t     reg_55[1]; // FTS_REG_FW_VER
    uint8_t     reg_af[4]; // FTS_REG_FW_VER
    uint8_t     reg_f1[4]; // FTS_REG_FW_VER
    uint8_t     reg_a3[4]; // FTS_REG_FW_VER
    uint8_t     reg_a4[4]; // FTS_REG_FW_VER
    uint8_t     reg_a5[4]; // FTS_REG_FW_VER
    uint8_t     reg_52[3]; // FTS_REG_FW_VER
    uint8_t     reg_23[11]; // FTS_REG_FW_VER
    uint8_t     reg_30[2]; // FTS_REG_FW_VER
    uint8_t     reg_90[10]; // FTS_REG_FW_VER
    uint8_t     reg_85_0[28]; // FTS_REG_WORKMODE
    uint8_t     reg_85_1[1]; // FTS_REG_WORKMODE
    uint8_t     reg_e4_0[1]; // FTS_REG_GESTURE_EN
    uint8_t     reg_e4_1[1]; // FTS_REG_GESTURE_EN
    uint8_t     Touch_ON[1]; // 报点标志
    uint8_t     reg_92_0[6];
    uint8_t     reg_92_1[4];
	uint8_t     reg_92_2[2];
    bool         Phone_Init_Done;

}   SAMSUNG_s21u_str;

SAMSUNG_s21u_str SAMSUNG_s21u =
{
    .D60_count = 0x00,
    .D85_count = 0x00,
    .D92_count = 0x00,
    .reg_60_0 = {   0x09, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    .reg_60_1 = {   0x1D, 0x61, 0x02, 0x02, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    .reg_60_2 = {   0x1D, 0x61, 0x02, 0x02, 0x06, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    .reg_60_3 = {   0x1D, 0x61, 0x02, 0x02, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    .reg_60_4 = {   0x1D, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    .reg_60_5 = {   0x1D, 0x61, 0x02, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    .reg_60_6 = {   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    .reg_60_7 = {   0x1D, 0x61, 0x02, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    .reg_60_8 = {   0x1D, 0x61, 0x03, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    .reg_60_9 = {   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    .reg_60_10 = {   0x1D, 0x61, 0x03, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 2
    .reg_60_11 = {   0x1D, 0x61, 0x02, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    .reg_60_12 = {   0x1D, 0x6B, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
 
    .reg_60_1_0 = {   0x1D, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    .reg_60_1_1 = {   0x1D, 0x61, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    .reg_60_1_2 = {   0x1D, 0x61, 0x03, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    
    .reg_61_0 = {   0x1D, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    				0x1D, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    				0x1D, 0x6F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    .reg_61_1 = {   0x1D, 0x61, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},

	.reg_61_2 = {   0x1D, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    .reg_61_3 = {   0x1D, 0x59, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    
    .reg_22 = { 0x53, 0x45, 0x37, 0x92, 0x00},
    .reg_21 = { 0x80},
    .reg_55 = { 0x20},
    .reg_af = { 0x00, 0x02, 0x01, 0x00},
    .reg_f1 = { 0x07, 0x07, 0x00, 0xA2},
    .reg_a5 = { 0x28, 0x20, 0x01, 0x25},
    .reg_a3 = { 0x28, 0x20, 0x01, 0x00},
    .reg_a4 = { 0x28, 0x20, 0x01, 0x02},
    .reg_52 = { 0xAC, 0x37, 0x71},
    .reg_23 = {
        0x10, 0x00, 0x10, 0x00, 0x05, 0xA0, 0x0C, 0x80,
        0x12, 0x28, 0x00
    },
    .reg_30 = { 0x61, 0x00},
    .reg_90 = {
        0x4E, 0x39, 0x37, 0x35, 0x00, 0x04, 0x00, 0x0A,
        0x10, 0x00
    },
    .reg_85_0 = {
        0x01,0x20,0x01,0x04,0x01,0x00,0x03,0xDE,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x01,0x00
    },
    .reg_85_1 = { 0xFF },
    .reg_e4_0 = {0x00},
    .reg_e4_1 = {0x01},
    .Touch_ON = {0x00},
    .reg_92_0 = { 0xF3, 0x00, 0xA2, 0x00, 0xF3, 0x00},
    .reg_92_1 = { 0x12, 0x12, 0x29, 0x00},
    .reg_92_2 = { 0x8A, 0x25},
    .Phone_Init_Done = false,
};

#endif
uint8_t screen_data_write_1[1] = {0x86};                                                    //触点/坐标 数据读取对应的发送buffer
uint8_t screen_data_write_2[3] = {0xc0, 0x05, 0x01};                                        //配置buffer
uint8_t screen_data_write_3[3] = {0xc0, 0x05, 0x00};                                        //配置buffer

st_screen_data screen_reg_int_data[] = {{screen_data_write_1, 1, 8, SCREEN_TRANSFER_READ}
};
const uint8_t screen_reg_int_data_size = sizeof(screen_reg_int_data) / sizeof(st_screen_data);//结构体数组的元素个数，数组按照协议发送数据先后排列
/***********************************报点协议 master 相关 buffer 截止**************************************/

/***********************************开机屏幕初始化 master 相关 buffer ************************************/
// 数组按照协议发送数据先后排列
st_screen_const_data screen_reg_start_data[] =
{
    {data_num_00, screen_86_data, sizeof(screen_86_data), 8, SCREEN_TRANSFER_READ}, \
    {data_num_01, screen_a0_00_01_data, sizeof(screen_a0_00_01_data), 0, SCREEN_TRANSFER_WRITE}, \
    {data_num_02, screen_a2_03_00_data, sizeof(screen_a2_03_00_data), 0, SCREEN_TRANSFER_WRITE}, \
    {data_num_03, screen_a2_02_00_data, sizeof(screen_a2_02_00_data), 0, SCREEN_TRANSFER_WRITE}, \
    {data_num_04, screen_c0_07_01_data, sizeof(screen_c0_07_01_data), 0, SCREEN_TRANSFER_WRITE}, \
//    {data_num_05, screen_86_data, sizeof(screen_86_data), 8, SCREEN_TRANSFER_READ}, \
//    {data_num_06, screen_86_data, sizeof(screen_86_data), 8, SCREEN_TRANSFER_READ}, \
//    {data_num_07, screen_86_data, sizeof(screen_86_data), 8, SCREEN_TRANSFER_READ}, \
//    {data_num_08, screen_86_data, sizeof(screen_86_data), 8, SCREEN_TRANSFER_READ}, 
};
const uint8_t screen_reg_start_data_size = sizeof(screen_reg_start_data) / sizeof(st_screen_const_data);
/*********************************开机屏幕初始化 master 相关 buffer 截止**********************************/

//st_screen_const_data screen_reg_tp_sendcmd_data[] = { \
//    {data_num_00, screen_87_data, sizeof(screen_87_data), 10, SCREEN_TRANSFER_READ}, \
//    {data_num_01, screen_a0_00_01_data, sizeof(screen_a0_00_01_data), 0, SCREEN_TRANSFER_WRITE}, \

//};
////    {data_num_03, screen_a3_a4_fc_data, sizeof(screen_a3_a4_fc_data), 0, SCREEN_TRANSFER_WRITE},
//const uint8_t screen_reg_tp_sendcmd_data_size = sizeof(screen_reg_tp_sendcmd_data) / sizeof(st_screen_const_data);


//st_screen_const_data screen_reg_tp_software_reset_data[] = { \

//{data_num_00, screen_fa_software_reset_data, sizeof(screen_fa_software_reset_data), 0, SCREEN_TRANSFER_WRITE}, \
//{data_num_01, screen_87_data, sizeof(screen_87_data), 10, SCREEN_TRANSFER_READ}, \
//{data_num_02, screen_a0_00_01_data, sizeof(screen_a0_00_01_data), 0, SCREEN_TRANSFER_WRITE}, \
//                                                           };
////    {data_num_03, screen_a3_a4_fc_data, sizeof(screen_a3_a4_fc_data), 0, SCREEN_TRANSFER_WRITE},
//const uint8_t screen_reg_tp_software_reset_data_size = sizeof(screen_reg_tp_software_reset_data) / sizeof(st_screen_const_data);

uint8_t  g_screen_tp_reg_43_software_reset_flag = false;
bool g_screen_tp_init_start = false;
bool g_screen_tp_init_restart = false;
bool g_tp_sleep_in = false;
bool g_ap_tp_init_done = false;

uint8_t Flag_blacklight_EN = false;
uint8_t tp_sleep_in = false;
uint8_t tp_sleep_count = false;


uint8_t g_ap_tp_init_E4 = false;	// false 无  1 E4 00  2 E4 01 

uint8_t g_tp_wakeup = false;
uint8_t g_tp_sleep_delay_count = 0;

/*************************************报点协议 slave 相关 buffer******************************************/

uint8_t phone_reg_coord_data[] = {0x60};                                                //坐标 数据反馈对应的接收数据
uint8_t phone_reg_coord_back[16] = {0x09, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
									0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};     //坐标 数据反馈对应的数据buffer
uint8_t phone_reg_coord_back_X61[80] = {0x09, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00};     //坐标 数据反馈对应的数据buffer
uint8_t phone_reg_coord_back_BUF[10][10] = {0x09, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00};     //坐标 数据反馈对应的数据buffer
uint8_t phone_reg_coord_BUF_NUM = 0;

st_reg_data phone_reg_int_data[] = {{1, 8, phone_reg_coord_data, phone_reg_coord_back}};
uint8_t phone_reg_int_size = sizeof(phone_reg_int_data) / sizeof(phone_reg_int_data[0]);
/***********************************报点协议 slave 相关 buffer 截止***************************************/

/****************************开机阶段slave需要反馈的数据及其对应的接收开头********************************/

st_reg_const_data phone_reg_const_data[] = { \
    {sizeof(phone_60_start_back), sizeof(phone_60_start_back), phone_60_start_back, phone_60_start_back},
    {sizeof(phone_22_data), sizeof(phone_22_back), phone_22_data, phone_22_back},
    {sizeof(phone_21_data), sizeof(phone_21_back), phone_21_data, phone_21_back},
};

uint8_t phone_reg_const_data_size = sizeof(phone_reg_const_data) / sizeof(phone_reg_const_data[0]);
/***************************开机阶段slave需要反馈的数据及其对应的接收开头截止******************************/




/**************************************************************************
* @name : app_tp_screen_analysis_const
* @brief : screen start 阶段数据解析函数，由客户定制
* @param[in] :
* @return :
* @retval :
**************************************************************************/
uint8_t app_tp_screen_analysis_const(uint8_t transfer_now, uint8_t *rxbuffer, size_t data_size)
{
    uint8_t return_num = transfer_now + 1;

//	g_tp_sleep_in = false;		// 退出息屏状态
	
//    static uint8_t  app_tp_count = 0;

//    switch (transfer_now)
//    {
//    case data_num_02:                                   //87
//        if (rxbuffer[0] == 0x03)
//        {
//#if S8_TP_DEBUG_LOG
//            TAU_LOGD("87 wait 03 ok\n");
//#endif
//        }
//        else
//        {
//#if S8_TP_DEBUG_LOG
//            TAU_LOGD("TD TP init [%d]\n", rxbuffer[2]);
//#endif
//            app_tp_count++;
//            return_num = transfer_now;
//            if (app_tp_count >  120)                    //初始化不成功，重新reset screen
//            {
//                app_tp_count = 0;
//                app_tp_screen_init();
//                return_num = data_num_00;
//            }
//            delayMs(10);
//        }
//        break;
//    default:
//        break;
//    }

    return return_num;

}

/**************************************************************************
* @name : app_tp_screen_analysis_wake_up
* @brief : screen 息屏双击唤醒功能
* @param[in] :
* @return : 0表示触摸类事件；1表示状态事件；2表示手势事件；3表示空事件
* @retval :
**************************************************************************/
uint8_t app_tp_screen_analysis_wake_up(uint8_t *rxbuffer, uint8_t touch_number)
{
	uint16_t x = 0,y = 0;
	uint8_t touch_event = 0;
	
	uint8_t result = 0;	// 0表示触摸类事件；1表示状态事件；2表示手势事件；3表示空事件
	
	if(touch_number == 1)	// 单点触摸
	{
		touch_event = rxbuffer[0] >> 4;//触摸事件
		if(touch_event == 0x01)	// 按下事件 单击事件
		{
			Touch.Touch_Single_Point[0].Event++;
			if(Touch.Touch_Single_Point[0].Event == 1)	// 第一点按压事件
			g_tp_sleep_delay_count = 0;
		}
		
		if(touch_event == 0x03)	// 释放事件 单击事件
		{	
			Touch.Touch_Single_Point[0].X_in = (((u16)rxbuffer[3] & 0x0F) << 8) | (rxbuffer[2]);
            Touch.Touch_Single_Point[0].Y_in = ((u16)rxbuffer[4] << 4) | ((rxbuffer[3] & 0xF0) >> 4);

			if(Touch.Touch_Single_Point[0].Event == 1)
			{
				if(g_tp_sleep_delay_count < Touch_Single_AOD_Time) // 20*10 = 200ms单击事件
				{
					g_tp_wakeup = Touch_Single_AOD;
				}
			}
			else
			{
				if(g_tp_sleep_delay_count < Touch_Double_PowerUp_Time)	// 50*10 = 500ms 内双击事件
				{
					x = abs(Touch.Touch_Single_Point[0].X_in-Touch.Touch_Single_Point[1].X_in);
					y = abs(Touch.Touch_Single_Point[0].Y_in-Touch.Touch_Single_Point[1].Y_in);
					if(x<100 && y<100)		// 双击 x y的范围小于100个像素点
					{
						g_tp_wakeup = Touch_Double_PowerUp;
						Touch.Touch_Single_Point[0].Event = 0;
						Touch.Touch_Single_Point[0].X_in = 0;
						Touch.Touch_Single_Point[0].Y_in = 0;
					}
				}
			}

			// 保存x y数值
			Touch.Touch_Single_Point[1].X_in = Touch.Touch_Single_Point[0].X_in;
			Touch.Touch_Single_Point[1].Y_in = Touch.Touch_Single_Point[0].Y_in;
			g_tp_sleep_delay_count = 0;
		}	
	}
	else
	{
		g_tp_sleep_delay_count = 0;
		Touch.Touch_Single_Point[0].X_in = 0;
		Touch.Touch_Single_Point[0].Y_in = 0;
		Touch.Touch_Single_Point[0].Event = 0;
		Touch.Touch_Single_Point[1].X_in = Touch.Touch_Single_Point[0].X_in;
		Touch.Touch_Single_Point[1].Y_in = Touch.Touch_Single_Point[0].Y_in;
	}
	
//	return result;
}

void app_tp_screen_analysis_wake_up_exec(void)
{
	if(g_tp_wakeup == Touch_Double_PowerUp)
	{
		TAU_LOGD("TP Double\n");
		g_tp_wakeup = false;
		Touch.Touch_Single_Point[0].Event = 0;
//		delayMs(100);
		phone_reg_coord_back_X61[0] = 0x46;              //44 press C4 leave 84 move
	    phone_reg_coord_back_X61[1] = 0x01;      //x 高八位
	    phone_reg_coord_back_X61[2] = 0x2D;      //y 高八位
	    phone_reg_coord_back_X61[3] = 0x34;   //bit0-bit3:y低四位;bit4-bit7:x低四位;
	    phone_reg_coord_back_X61[4] = 0xD8;                                //major
	    phone_reg_coord_back_X61[5] = 0;                                //minor
	    //touch type：0:普通手指触摸；1:盘旋；2:保护套；3:手套;4:尖笔;5:手掌;6:潮湿的;7:接近;8:轻摇
	//            phone_reg_coord_back_X61[((s1) * 8) + 6] = ((Touch.Touch_Single_Point[ss].Z & 0xFE) >> 2);                //bit0-bit5:z只有6位;bit6-bit7:touch type的高两位
	//            phone_reg_coord_back_X61[((s1) * 8) + 7] = --Touch_num;                              //bit0-bit5:buffer里面剩余多少个事件;bit6-bit7：touch type 低两位

	    phone_reg_coord_back_X61[6] = 0;
	    phone_reg_coord_back_X61[7] = 0;
	    
	    phone_reg_coord_back_X61[8] = 0;
	    phone_reg_coord_back_X61[9] = 0;
	    phone_reg_coord_back_X61[10] = 0;
	    phone_reg_coord_back_X61[11] = 0;
	    phone_reg_coord_back_X61[12] = 0;
	    phone_reg_coord_back_X61[13] = 0;
	    phone_reg_coord_back_X61[14] = 0;
	    phone_reg_coord_back_X61[15] = 0;
		SAMSUNG_s21u.Touch_ON[0] = 1;
	    hal_gpio_set_output_data(g_phone_output_int_pad, IO_LVL_LOW);   //拉低TP中断脚,通知AP读取TP数据
	    Touch.Event_Single_Flag = 0;
	}
	else if(g_tp_wakeup == Touch_Single_AOD && g_tp_sleep_delay_count > (Touch_Double_PowerUp_Time+10))	// 单击事件后无触摸报点
	{
		TAU_LOGD("TP Single\n");
		g_tp_wakeup = false;
		Touch.Touch_Single_Point[0].Event = 0;
//		delayMs(100);
		phone_reg_coord_back_X61[0] = 0x52;              //44 press C4 leave 84 move
	    phone_reg_coord_back_X61[1] = 0x00;      //x 高八位
	    phone_reg_coord_back_X61[2] = 0x22;      //y 高八位
	    phone_reg_coord_back_X61[3] = 0x45;   //bit0-bit3:y低四位;bit4-bit7:x低四位;
	    phone_reg_coord_back_X61[4] = 0xBB;                                //major
	    phone_reg_coord_back_X61[5] = 0;                                //minor
	    //touch type：0:普通手指触摸；1:盘旋；2:保护套；3:手套;4:尖笔;5:手掌;6:潮湿的;7:接近;8:轻摇
	//            phone_reg_coord_back_X61[((s1) * 8) + 6] = ((Touch.Touch_Single_Point[ss].Z & 0xFE) >> 2);                //bit0-bit5:z只有6位;bit6-bit7:touch type的高两位
	//            phone_reg_coord_back_X61[((s1) * 8) + 7] = --Touch_num;                              //bit0-bit5:buffer里面剩余多少个事件;bit6-bit7：touch type 低两位

	    phone_reg_coord_back_X61[6] = 0;
	    phone_reg_coord_back_X61[7] = 0;
	    
	    phone_reg_coord_back_X61[8] = 0;
	    phone_reg_coord_back_X61[9] = 0;
	    phone_reg_coord_back_X61[10] = 0;
	    phone_reg_coord_back_X61[11] = 0;
	    phone_reg_coord_back_X61[12] = 0;
	    phone_reg_coord_back_X61[13] = 0;
	    phone_reg_coord_back_X61[14] = 0;
	    phone_reg_coord_back_X61[15] = 0;
		SAMSUNG_s21u.Touch_ON[0] = 1;
	    hal_gpio_set_output_data(g_phone_output_int_pad, IO_LVL_LOW);   //拉低TP中断脚,通知AP读取TP数据
	    Touch.Event_Single_Flag = 0;
	}
}

/**************************************************************************
* @name : app_tp_screen_analysis_int
* @brief : screen 报点数据解析函数，由客户定制
* @param[in] :
* @return :
* @retval :
**************************************************************************/

uint8_t app_tp_screen_analysis_int(uint8_t transfer_now, uint8_t *rxbuffer, size_t data_size)
{
	uint8_t touch_number = 0;
	uint8_t ii = 0,ss = 0;
	uint8_t touch_event_flag = 0;	// 触摸事件统计

	phone_reg_coord_BUF_NUM = data_size/8;
	
	if (phone_reg_coord_BUF_NUM >= Touch_MAX_Point)phone_reg_coord_BUF_NUM = Touch_MAX_Point;
	
	for (ii = 0; ii < phone_reg_coord_BUF_NUM; ii++)
	{	
		for (ss = 0; ss < 8; ss++)
		phone_reg_coord_back_BUF[ii][ss] = rxbuffer[ii*8+ss];
	}
    
    //ST TP数据分析处理
//    byte0: bit4-bit7：0x1:按下事件;0x2:移动事件;0x3:松开事件; bit2-bit3:reserved; bit0-bit1:0x3
//    byte1: bit4-bit7：touchId; 手指数 0x0: Pointer ID 0、0x1: Pointer ID 1 ... 0xF: Pointer ID 15
//           bit0-bit3：touchType: 0x0: Invalid、0x1: Finger touch、0x2: Glove touch、0x3: Stylus touch、0x4: Palm touch、Others: Reserved
//    byte2: X低8位
//    byte3: 高4位:Y的bit0-bit3; 低4位:X的bit11-bit8
//    byte4: Y的：bit11-bit4
//    byte5: reserved
//    byte6: reserved
//    byte7: bit5-bit7:reserved; bit0-bit4:buffer中剩余的事件数 evt_left

    Touch.Event_Single_Flag = 1;
 //   phone_reg_coord_BUF_NUM = 0;
 //	TAU_LOGD("TP [%d]\n", g_tp_sleep_in);
 //	TAU_LOGD("TP [%d]\n", g_ap_tp_init_done);

    if (g_tp_sleep_in == false)
    {
        u8 s1 = 0;
        for (ss = 0; ss < phone_reg_coord_BUF_NUM; ss++)
        {
        	uint8_t touch_id = 0;
	        uint8_t touch_event_id = 0;
			uint8_t ap_event_id = 0;

	        touch_id = phone_reg_coord_back_BUF[ss][1] >> 4;
	        if (touch_id >= Touch_MAX_Point)continue; //判断手指编号是否超出范围
        	
			touch_event_id = phone_reg_coord_back_BUF[ss][0] >> 4;//触摸事件
			if(touch_event_id > 0 && touch_event_id < 4)	// bit4-bit7：0x1:按下事件;0x2:移动事件;0x3:松开事件;
			{
				touch_event_flag++;
			}
//			if((touch_event_id == 0x01)||(touch_event_id == 0x02))		// 按下事件 // 移动事件
//			{
//				
//			}
			Touch.Touch_Single_Point[0].X_in = (((u16)phone_reg_coord_back_BUF[ss][3] & 0x0F) << 8) | (phone_reg_coord_back_BUF[ss][2]);
            Touch.Touch_Single_Point[0].Y_in = ((u16)phone_reg_coord_back_BUF[ss][4] << 4) | ((phone_reg_coord_back_BUF[ss][3] & 0xF0) >> 4);
            //分辨率转换
            Touch.Touch_Single_Point[0].X = (((float)Touch.Touch_Single_Point[0].X_in) * (float)INPUT_WIDTH_VALUE) / ((float)OUTPUT_WIDTH_VALUE);
            Touch.Touch_Single_Point[0].Y = (((float)Touch.Touch_Single_Point[0].Y_in) * (float)INPUT_HEIGHT_VALUE) / ((float)OUTPUT_HEIGHT_VALUE);
			
            u16 X0, Y0;
            X0 = ((float)Touch.Touch_Single_Point[0].X) * 4095.0 / ((float)INPUT_WIDTH_VALUE);
            Y0 = ((float)Touch.Touch_Single_Point[0].Y) * 4095.0 / ((float)INPUT_HEIGHT_VALUE);
            if (X0 > 0xfff)X0 = 0xfff;
            if (Y0 > 0xfff)Y0 = 0xfff;

			X0 = 0xfff - X0;	// 零点上下不一致，需要转换

//            hal_gpio_set_output_data(IO_PAD_AP_SPIS_MISO, IO_LVL_LOW);
            //bit0-bit1:event id;   0表示触摸类事件；1表示状态事件；2表示手势事件；3表示空事件
            //bit2-bit5:touch id;   表示第几个触摸手指
            //bit6-bit7:touch action; 0：没有触摸事件；1:按下;2:移动;3:松开

            phone_reg_coord_back_X61[((s1) * 16) + 0] = (touch_event_id << 6) | ((touch_id + 1) << 2) | ap_event_id;              //44 press C4 leave 84 move
            phone_reg_coord_back_X61[((s1) * 16) + 1] = (uint8_t)((X0 & 0xFF0) >> 4);      //x 高八位
            phone_reg_coord_back_X61[((s1) * 16) + 2] = (uint8_t)((Y0 & 0xFF0) >> 4);      //y 高八位
            phone_reg_coord_back_X61[((s1) * 16) + 3] = ((X0 & 0xF) << 4) | ((Y0 & 0xF));   //bit0-bit3:y低四位;bit4-bit7:x低四位;
            phone_reg_coord_back_X61[((s1) * 16) + 4] = 4;                                //major
            phone_reg_coord_back_X61[((s1) * 16) + 5] = 4;                                //minor
            //touch type：0:普通手指触摸；1:盘旋；2:保护套；3:手套;4:尖笔;5:手掌;6:潮湿的;7:接近;8:轻摇
//            phone_reg_coord_back_X61[((s1) * 8) + 6] = ((Touch.Touch_Single_Point[ss].Z & 0xFE) >> 2);                //bit0-bit5:z只有6位;bit6-bit7:touch type的高两位
//            phone_reg_coord_back_X61[((s1) * 8) + 7] = --Touch_num;                              //bit0-bit5:buffer里面剩余多少个事件;bit6-bit7：touch type 低两位

            phone_reg_coord_back_X61[((s1) * 16) + 6] = 0x1b;
            phone_reg_coord_back_X61[((s1) * 16) + 7] = 0x20+(phone_reg_coord_BUF_NUM-1-ss);
            
            phone_reg_coord_back_X61[((s1) * 16) + 8] = 0x04;
            phone_reg_coord_back_X61[((s1) * 16) + 9] = 0x96;
            phone_reg_coord_back_X61[((s1) * 16) + 10] = 0;
            phone_reg_coord_back_X61[((s1) * 16) + 11] = 0;
            phone_reg_coord_back_X61[((s1) * 16) + 12] = 0;
            phone_reg_coord_back_X61[((s1) * 16) + 13] = 0;
            phone_reg_coord_back_X61[((s1) * 16) + 14] = 0;
            phone_reg_coord_back_X61[((s1) * 16) + 15] = 0;
            
            Touch.Touch_Single_Point[ss].Eventbk = Touch.Touch_Single_Point[ss].Event;

            Touch.Touch_Single_Point[ss].Event = 0;
//            hal_gpio_set_output_data(IO_PAD_AP_SPIS_MISO, IO_LVL_HIGH);
//          }
            s1++;
        }
        SAMSUNG_s21u.Touch_ON[0] = 1;
		if(g_ap_tp_init_done && touch_event_flag > 0)	// 有触摸事件才报点
        hal_gpio_set_output_data(g_phone_output_int_pad, IO_LVL_LOW);   //拉低TP中断脚,通知AP读取TP数据
        Touch.Event_Single_Flag = 0;
    }
	else
	{	
		// 息屏触摸处理
//		TAU_LOGD("TP sleep mode\n");
		app_tp_screen_analysis_wake_up(rxbuffer,phone_reg_coord_BUF_NUM);
	}
    
    return screen_reg_int_data_size + 1;
//  TAU_LOGD("TD [%d]\n", x);
}


/**************************************************************************
* @name : hal_tp_phone_analysis_data
* @brief : phone 数据解析函数，由客户定制
* @param[in] :
* @return :
* @retval :
**************************************************************************/
void app_tp_phone_analysis_data(uint8_t *rxbuffer, size_t rxbuffer_size, const uint8_t **txbuffer, size_t *txbuffer_size)
{

    *txbuffer_size = 0;
//    if ((!((rxbuffer[0] == 0x60) || (rxbuffer[0] == 0x61))) || (SAMSUNG_s21u.Phone_Init_Done == false))
	if (!((rxbuffer[0] == 0x60) || (rxbuffer[0] == 0x61))) 
    {
        SAMSUNG_s21u.Touch_ON[0] = 0;
    }
	if(phone_reg_coord_BUF_NUM<2)	// 单点触摸
    hal_gpio_set_output_data(g_phone_output_int_pad, IO_LVL_HIGH);
    switch (rxbuffer[0])
    {
    case 0x60:
    {
        if (SAMSUNG_s21u.Touch_ON[0] == 1)
        {
            *txbuffer = phone_reg_coord_back_X61;
            *txbuffer_size = sizeof(phone_reg_coord_back);
	//		TAU_LOGD("TD OK\n");
        }
        else
        {
        	
            if (SAMSUNG_s21u.D60_count == 0)
            {
                if(g_screen_tp_init_start == true)  //开机
                {
                    *txbuffer = SAMSUNG_s21u.reg_60_0;
                    *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_0);
                    SAMSUNG_s21u.D60_count = 1;
                }
                else
                {
                    *txbuffer = SAMSUNG_s21u.reg_60_1_0;
                    *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_1_0);
                    SAMSUNG_s21u.D60_count = 1;
                }
            }
            else if (SAMSUNG_s21u.D60_count == 1)
            {
                *txbuffer = SAMSUNG_s21u.reg_60_1;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_1);
            }
            else if (SAMSUNG_s21u.D60_count == 2)
            {
                *txbuffer = SAMSUNG_s21u.reg_60_2;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_2);
                SAMSUNG_s21u.D60_count = 3;
            }
            else if (SAMSUNG_s21u.D60_count == 3)
            {
                *txbuffer = SAMSUNG_s21u.reg_60_3;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_3);
                SAMSUNG_s21u.D60_count = 4;
            }
            else if (SAMSUNG_s21u.D60_count == 4)
            {
                *txbuffer = SAMSUNG_s21u.reg_60_4;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_4);
                SAMSUNG_s21u.D60_count = 5;
            }
            else if (SAMSUNG_s21u.D60_count == 5)
            {
                *txbuffer = SAMSUNG_s21u.reg_60_5;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_5);
				if(g_ap_tp_init_E4)
				{
					g_ap_tp_init_E4 = 0;
					hal_gpio_set_output_data(g_phone_output_int_pad, IO_LVL_HIGH);
				}
            }
            else if (SAMSUNG_s21u.D60_count == 6)
            {
                *txbuffer = SAMSUNG_s21u.reg_60_6;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_6);
                SAMSUNG_s21u.D60_count = 6;
            }
            else if (SAMSUNG_s21u.D60_count == 7)
            {
                *txbuffer = SAMSUNG_s21u.reg_60_7;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_7);
                SAMSUNG_s21u.D60_count = 7;
            }
            else if (SAMSUNG_s21u.D60_count == 8)
            {
                *txbuffer = SAMSUNG_s21u.reg_60_8;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_8);
                SAMSUNG_s21u.D60_count = 8;				
            }
            else if (SAMSUNG_s21u.D60_count == 9)
            {
                *txbuffer = SAMSUNG_s21u.reg_60_9;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_9);
                SAMSUNG_s21u.D60_count = 10;
            }
            else if (SAMSUNG_s21u.D60_count == 10)
            {
                *txbuffer = SAMSUNG_s21u.reg_60_10;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_10);
                SAMSUNG_s21u.D60_count = 11;
            }
			else if (SAMSUNG_s21u.D60_count == 11)
            {
                *txbuffer = SAMSUNG_s21u.reg_60_10;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_10);
                SAMSUNG_s21u.D60_count = 12;
            }
			else if (SAMSUNG_s21u.D60_count == 12)
            {
                *txbuffer = SAMSUNG_s21u.reg_60_11;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_11);
                SAMSUNG_s21u.D60_count = 12;
            }
			else if (SAMSUNG_s21u.D60_count == 13)
            {
                *txbuffer = SAMSUNG_s21u.reg_60_12;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_12);
                SAMSUNG_s21u.D60_count = 1;
            }

        }
    }
    break;
    case 0x61:
    {
        if (SAMSUNG_s21u.Touch_ON[0] == 1)
        {
        	hal_gpio_set_output_data(g_phone_output_int_pad, IO_LVL_HIGH);	// 多点触摸
			
            *txbuffer = &phone_reg_coord_back_X61[16];
            *txbuffer_size = sizeof(phone_reg_coord_back_X61) - 16;
        }
        else
        {  
        	hal_gpio_set_output_data(g_phone_output_int_pad, IO_LVL_HIGH);
			if(g_ap_tp_init_E4 == 1)
			{
				*txbuffer = SAMSUNG_s21u.reg_61_3;
            	*txbuffer_size = sizeof(SAMSUNG_s21u.reg_61_3);
			}
			else if(g_ap_tp_init_E4 == 2)
			{
				*txbuffer = SAMSUNG_s21u.reg_61_2;
            	*txbuffer_size = sizeof(SAMSUNG_s21u.reg_61_2);
			}
			else
			{
				*txbuffer = SAMSUNG_s21u.reg_61_0;
            	*txbuffer_size = sizeof(SAMSUNG_s21u.reg_61_0);
			}
        }
    }
    break;
    case 0x22:
    {
        *txbuffer = SAMSUNG_s21u.reg_22;
        *txbuffer_size = sizeof(SAMSUNG_s21u.reg_22);
//		app_tp_transfer_screen_start();
		g_screen_tp_init_restart = true;

    }
    break;
    case 0x21:
    {
        *txbuffer = SAMSUNG_s21u.reg_21;
        *txbuffer_size = sizeof(SAMSUNG_s21u.reg_21);
    }
    break;
    case 0x55:
    {
        *txbuffer = SAMSUNG_s21u.reg_55;
        *txbuffer_size = sizeof(SAMSUNG_s21u.reg_55);
    }
    break;
    case 0xaf:
    {
        *txbuffer = SAMSUNG_s21u.reg_af;
        *txbuffer_size = sizeof(SAMSUNG_s21u.reg_af);
    }
    break;
    case 0xf1:
    {
        *txbuffer = SAMSUNG_s21u.reg_f1;
        *txbuffer_size = sizeof(SAMSUNG_s21u.reg_f1);
    }
    break;
    case 0xa5:
    {
        *txbuffer = SAMSUNG_s21u.reg_a5;
        *txbuffer_size = sizeof(SAMSUNG_s21u.reg_a5);
    }
    break;
    case 0xa3:
    {
        *txbuffer = SAMSUNG_s21u.reg_a3;
        *txbuffer_size = sizeof(SAMSUNG_s21u.reg_a3);
    }
    break;
    case 0xa4:
    {
        *txbuffer = SAMSUNG_s21u.reg_a4;
        *txbuffer_size = sizeof(SAMSUNG_s21u.reg_a4);
    }
    break;
    case 0x52:
    {
        *txbuffer = SAMSUNG_s21u.reg_52;
        *txbuffer_size = sizeof(SAMSUNG_s21u.reg_52);
    }
    break;
    case 0x23:
    {
        *txbuffer = SAMSUNG_s21u.reg_23;
        *txbuffer_size = sizeof(SAMSUNG_s21u.reg_23);
    }
    break;
    case 0x30:
    {
        *txbuffer = SAMSUNG_s21u.reg_30;
        *txbuffer_size = sizeof(SAMSUNG_s21u.reg_30);
    }
    break;
    case 0x90:
    {
        *txbuffer = SAMSUNG_s21u.reg_90;
        *txbuffer_size = sizeof(SAMSUNG_s21u.reg_90);
    }
    break;
    case 0x11:
    {
        SAMSUNG_s21u.D60_count = 2;
    }
    break;
    case 0x85:
    {
        if (rxbuffer_size > 1)
        {
            if ((rxbuffer[1] == 0x00) && (rxbuffer[2] == 0x00))
            {
                SAMSUNG_s21u.D85_count = 1;
            }
            return;
        }
        else
        {
            if(SAMSUNG_s21u.D85_count == 0x00)
            {
                *txbuffer = SAMSUNG_s21u.reg_85_0;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_85_0);
            }
            else if(SAMSUNG_s21u.D85_count == 0x01)
            {
                *txbuffer = SAMSUNG_s21u.reg_85_1;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_85_1);
            }
        }
    }
    break;
	case 0x92:
    {
        if (rxbuffer_size == 1)
        {
            if(SAMSUNG_s21u.D92_count == 0x00)
            {
                *txbuffer = SAMSUNG_s21u.reg_92_0;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_92_0);
				SAMSUNG_s21u.D92_count = 1;
            }
            else if(SAMSUNG_s21u.D92_count == 0x01)
            {
                *txbuffer = SAMSUNG_s21u.reg_92_1;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_92_1);
				SAMSUNG_s21u.D92_count = 2;
            }
			else
			{
				*txbuffer = SAMSUNG_s21u.reg_92_2;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_92_2);
			//	SAMSUNG_s21u.D92_count = 0;
			}
        }
		
		if (rxbuffer_size == 3)
		{
			if((rxbuffer[1] == 0xF0)&&(rxbuffer[2] == 0x00))
			{
				SAMSUNG_s21u.D92_count = 2;
			}
		}
    }
    break;
//    case 0x72:
//    {
//        *txbuffer = SAMSUNG_s21u.reg_60_0;
//        *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_0);
//    }
    case 0x74:
    {
        if(rxbuffer_size == 2)
        {
            if(rxbuffer[1] == 0x01)
                SAMSUNG_s21u.D60_count = 5;
            else if((rxbuffer[1] == 0x02) || (rxbuffer[1] == 0x03))
                SAMSUNG_s21u.D60_count = 6;
        }
    }
    break;
//    case 0x80:
//    {
//        *txbuffer = SAMSUNG_s21u.reg_60_0;
//        *txbuffer_size = sizeof(SAMSUNG_s21u.reg_60_0);
//    }
//    break;
    case 0xE4:
    {	
    	g_tp_sleep_in = false;		// 退出息屏状态
		g_ap_tp_init_done = true;
        if (rxbuffer_size  == 2)
        {            	
            if(rxbuffer[1] == 0x00)
            {
            	g_ap_tp_init_E4 = 1;
				SAMSUNG_s21u.D60_count = 0;
				hal_gpio_set_output_data(g_phone_output_int_pad, IO_LVL_LOW);
            }          
            else if(rxbuffer[1] == 0x01)
            {
            	g_ap_tp_init_E4 = 2;
            	SAMSUNG_s21u.D60_count = 15;
				hal_gpio_set_output_data(g_phone_output_int_pad, IO_LVL_LOW);
            }
                
        }
        else
        {
            if(SAMSUNG_s21u.Phone_Init_Done == false)
            {
                *txbuffer = SAMSUNG_s21u.reg_e4_0;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_e4_0);
            }
            else{
                *txbuffer = SAMSUNG_s21u.reg_e4_1;
                *txbuffer_size = sizeof(SAMSUNG_s21u.reg_e4_1);
            }
        }
    }
    break;
    case 0xF3:
    {
        if (rxbuffer_size  == 2)
        {
            if(rxbuffer[1] == 0x00)
                SAMSUNG_s21u.D60_count = 9;
        }
    }
    break;
    case 0xAE:
    {
        if (rxbuffer_size > 1)
        {
            if ((rxbuffer[1] == 0xA3) && (rxbuffer[2] == 0x40))
            {
                //if(D60_count==0)
                {
                    SAMSUNG_s21u.D60_count = 4;

                }

            }
        }
    }
    break;
    case 0xBE:
    { 	
        if (rxbuffer_size == 2)
        {
            SAMSUNG_s21u.Phone_Init_Done = true;
        }
    }
    break;
	case 0x9B:
    { 	
        if (rxbuffer_size == 2)
        {
            g_tp_sleep_in = true;		// 进入息屏状态
        }
    }
    break;

    }
    //hal_gpio_set_output_data(IO_PAD_AP_SPIS_MISO,0);

}


