/******************************************************************************* * * * File: app_tp_transfer.c * Description touch I2C/SPI 初始化、以及数据通信 * Version V0.1 * Date 2021-10-14 * Author zhanghz *******************************************************************************/ #include "test_cfg_global.h" #include "app_tp_transfer.h" #include "hal_i2c_master.h" #include "hal_i2c_slave.h" #include "hal_spi_master.h" #include "hal_spi_slave.h" #include "tau_log.h" #include "tau_delay.h" #include "ap_demo.h" #include "app_tp_st_touch.h" #if 1//def AP_TP_TRANSFER uint8_t read_point; //当前要读的报点数。一个报点8BYTE数据 uint8_t s_screen_number[2]; uint8_t s_screen_temp[2]; uint8_t s_screen_read_bak[80]; static uint8_t s_screen_read_buffer[BUFFER_SIZE_MAX]; static uint8_t s_phone_read_buffer[BUFFER_SIZE_MAX]; uint8_t s_screen_read_MI10Pro[8]; uint8_t s_screen_read_MI10Pro_1[100]; static bool s_spim_write = false; //记录SPI主机是否配置发送,是的话需要清除RXFIFO static bool s_screen_int_flag = false; //记录是否接收到屏幕的报点中断 static bool s_phone_reset_flag = false; //记录是否接收到手机的开机复位信号 static bool s_screen_int_transfer_status = false; //记录是否已经开始通信 bool s_screen_init_complate = false; //屏幕TP开机初始化完成标志 static uint8_t s_screen_const_transfer_count = 0xff; //记录当前通信到哪一步,初始值必须大于 screen_reg_start_data_size #ifdef USE_FOR_SUMSUNG_S20 uint16_t u16TouchID; #endif static void app_tp_transfer_phone(size_t recieve_num); //static void app_tp_reset_callback(void *data); #if PHONE_SLAVE_TRANSFER_I2C //消除warning static void app_tp_i2cs_callback(e_i2c_s_int_status int_status, size_t recieve_num); #endif #if PHONE_SLAVE_TRANSFER_SPI //消除warning static void app_tp_spis_callback(hal_spis_event_e event, hal_spi_packet_info_t *packet_info); #endif #ifdef USE_FOR_MI10_PRO uint8_t MI10_PRO_screen_init_data1[3] = {0xA0,0x00,0x01}; uint8_t MI10_PRO_screen_init_data2[6] = {0xA2,0x03,0x00,0x00,0x00,0x03}; uint8_t MI10_PRO_screen_init_data3[3] = {0xA2,0x02,0x00}; uint8_t MI10_PRO_screen_init_data4[3] = {0xC0,0x07,0x01}; uint8_t MI10_PRO_screen_init_data5[3] = {0xA4,0x06,0x70}; uint8_t MI10_PRO_screen_init_data6[3] = {0xA6,0x00,0x00}; uint8_t MI10_PRO_screen_init_data7[5] = {0xFA,0x20,0x00,0x00,0x78}; uint8_t MI10_PRO_screen_init_data8[6] = {0xA2,0x03,0x20,0x00,0x00,0x00}; uint8_t MI10_PRO_screen_init_data9[2] = {0xA0,0x01}; uint8_t MI10_PRO_screen_init_data10[3] = {0xA0,0x00,0x00}; uint8_t MI10_PRO_screen_init_data11[3] = {0xC0,0x07,0x00}; uint8_t MI10_PRO_screen_init_data12[3] = {0xA4,0x00,0x00}; #endif #if 0//def ADD_TP_TUNING uint8_t MI10_PRO_TP_Tuning_data1[3] = {0xA4,0x00,0x00}; // System Reset uint8_t MI10_PRO_TP_Tuning_data2[3] = {0xA4,0x00,0x03}; // FPnl Init uint8_t MI10_PRO_TP_Tuning_data3[3] = {0xA4,0x00,0x02}; // Pnl Init uint8_t MI10_PRO_TP_Tuning_data4[4] = {0xA4,0x03,0x13,0x00}; // TuneM uint8_t MI10_PRO_TP_Tuning_data5[4] = {0xA4,0x03,0x0C,0x00}; // TuneS uint8_t MI10_PRO_TP_Tuning_data6[3] = {0xA4,0x05,0x01}; // SvCfg uint8_t MI10_PRO_TP_Tuning_data7[3] = {0xA4,0x05,0x02}; // SvCx uint8_t MI10_PRO_TP_Tuning_data8[3] = {0xA4,0x05,0x04}; // SvPnl #endif /************************************************************************** * @name : app_tp_screen_int_callback * @brief : screen 报点中断 回调函数 * @param[in] : * @return : * @retval : **************************************************************************/ static void app_tp_screen_int_callback(void *data) { s_screen_int_flag = true; } /************************************************************************** * @name : app_tp_screen_int_lvl_low * @brief : 获取 screen 报点中断 IO 电平 * @param[in] : * @return : true:IO 为低电平 * @retval : **************************************************************************/ static bool app_tp_screen_int_lvl_low(void) { #if SCREEN_MASTER_TRANSFER_I2C return false; #elif SCREEN_MASTER_TRANSFER_SPI return !hal_gpio_get_input_data(g_screen_input_int_pad); //应对SPI主机通信过程中偶尔突然拉低CS 导致通信异常 #else return false; #endif } /************************************************************************** * @name : app_tp_screen_int_init * @brief : screen 报点中断 IO 初始化 * @param[in] : * @return : * @retval : **************************************************************************/ static void app_tp_screen_int_init(void) { hal_gpio_set_pull_state(g_screen_input_int_pad, ENABLE, DISABLE); // 1.配置上拉 hal_gpio_ctrl_eint(g_screen_input_int_pad, DISABLE); // 2.关闭中断 hal_gpio_init_eint(g_screen_input_int_pad, DETECT_FALLING_EDGE); // 3.中断初始化,TP一般都是下降沿触发中断 hal_gpio_reg_eint_cb(g_screen_input_int_pad, app_tp_screen_int_callback); // 4.注册回调 hal_gpio_ctrl_eint(g_screen_input_int_pad, ENABLE); // 5.使能中断 } #if 0 /************************************************************************** * @name : app_tp_phone_reset_init * @brief : phone reset 中断 IO 初始化 * @param[in] : * @return : * @retval : **************************************************************************/ static void app_tp_phone_reset_init(void) { /*0.配置为输入*/ hal_gpio_init_input(g_phone_input_rst_pad); /*1.关闭中断*/ hal_gpio_ctrl_eint(g_phone_input_rst_pad, DISABLE); /*2.中断初始化*/ hal_gpio_init_eint(g_phone_input_rst_pad, DETECT_RISING_EDGE); /*3.注册回调*/ hal_gpio_reg_eint_cb(g_phone_input_rst_pad, app_tp_reset_callback); /*4.使能中断*/ hal_gpio_ctrl_eint(g_phone_input_rst_pad, ENABLE); } #endif /************************************************************************** * @name : app_tp_screen_init * @brief : screen IO 跳变,开始初始化 * @param[in] : * @return : * @retval : **************************************************************************/ void app_tp_screen_init(void) { hal_gpio_init_output(g_screen_input_rst_pad, IO_LVL_HIGH); delayUs(200); hal_gpio_set_output_data(g_screen_input_rst_pad, IO_LVL_LOW); delayUs(200); hal_gpio_set_output_data(g_screen_input_rst_pad, IO_LVL_HIGH); } /************************************************************************** * @name : app_tp_init * @brief : 初始化通信相关 * @param[in] : * @return : * @retval : **************************************************************************/ void app_tp_init(void) { #if 0//def DISABLE_TDDI_I2C_FUNCTION // hal_gpio_init_output(g_phone_output_int_pad, IO_LVL_HIGH); //配置phone报点输出中断IO口 hal_gpio_init_output(g_screen_input_rst_pad, IO_LVL_HIGH); //配置模组TP RESET // hal_gpio_set_mode(IO_PAD_TD_SPIM_CLK,IO_MODE_I2C1_SCL); // hal_gpio_set_mode(IO_PAD_TD_SPIM_CSN,IO_MODE_I2C1_SDA); return; #else hal_gpio_set_pull_state(IO_PAD_TD_SPIM_CLK, ENABLE, DISABLE); hal_gpio_set_pull_state(IO_PAD_TD_SPIM_CSN, ENABLE, DISABLE); #endif app_tp_screen_init(); //初始化手机复位的IO口 // app_tp_screen_int_init(); //配置screen中断输入引脚 #ifdef G_PHONE_INT_DEFAULT_LOW hal_gpio_init_output(g_phone_output_int_pad, IO_LVL_LOW); //配置phone报点输出中断IO口 #else hal_gpio_init_output(g_phone_output_int_pad, IO_LVL_HIGH); //配置phone报点输出中断IO口 // hal_gpio_init_input(g_phone_output_int_pad); hal_gpio_set_pull_state(g_screen_input_int_pad, ENABLE, DISABLE); hal_gpio_init_input(g_screen_input_int_pad); #endif hal_gpio_init_output(g_screen_input_rst_pad, IO_LVL_HIGH); //配置模组TP RESET #if SCREEN_MASTER_TRANSFER_I2C hal_i2c_m_dma_init(SCREEN_I2C_ADDRESS, SCREEN_I2C_ADDR_BITS, I2C_MASTER_SPEED); #elif SCREEN_MASTER_TRANSFER_SPI hal_spi_m_dma_init(SPI_MASTER_SPEED, SCREEN_SPI_CPHA, SCREEN_SPI_CPOL); #endif #if PHONE_SLAVE_TRANSFER_I2C hal_i2c_s_init(CHIP_I2C_ADDRESS, CHIP_I2C_ADDR_BITS); hal_i2c_s_set_transfer(app_tp_i2cs_callback); hal_i2c_s_nonblocking_read(s_phone_read_buffer, BUFFER_SIZE_MAX); //先配置接收 buffer #elif PHONE_SLAVE_TRANSFER_SPI hal_spi_slave_init(PHONE_SPI_CPHA, PHONE_SPI_CPOL, true); // 初始化spi以及dma hal_spi_slave_register_callback(app_tp_spis_callback); // 注册回调 hal_spi_slave_auto_transfer_abort(); // 停止传输 hal_spi_slave_flush_fifo(); // Flush FIFO /* 每个packet自动接收, circle mode 为false, 即收到buffer max size数据后buffer不再更新, packet完成后调用回调 */ hal_spi_slave_set_auto_rx_buffer(s_phone_read_buffer, BUFFER_SIZE_MAX, false); // 设置auto rx buffer hal_spi_slave_set_auto_tx_buffer(phone_reg_const_data[0].write_back, phone_reg_const_data[0].write_back_size, false); // 配置TX BUFFER hal_spi_slave_enable(); // 启动spis hal_spi_slave_auto_transfer_start(); // 启动rx自动接收 #endif } /************************************************************************** * @name : app_tp_m_transfer_complate * @brief : 获取主机通信完成状态 * @param[in] : * @return :true: 通信完成 * @retval : **************************************************************************/ bool app_tp_m_transfer_complate(void) { #if SCREEN_MASTER_TRANSFER_I2C return hal_i2c_m_transfer_complate(); #elif SCREEN_MASTER_TRANSFER_SPI return hal_spi_m_get_transfer_complate(); #else return true; #endif } /************************************************************************** * @name : app_tp_s_transfer_complate * @brief : 获取从机通信完成状态 * @param[in] : * @return :true: 通信完成 * @retval : **************************************************************************/ bool app_tp_s_transfer_complate(void) { #if SCREEN_MASTER_TRANSFER_I2C return hal_i2c_s_write_complate() && hal_i2c_s_read_complate(); #elif SCREEN_MASTER_TRANSFER_SPI return !hal_spi_slave_busy(); #else return true; #endif } /************************************************************************** * @name : app_tp_m_write * @brief : 根据通信方式配置发送txbuffer中的数据 * @param[in] :txbuffer: 发送数据 buffer 头地址 * @param[in] :buffer_size: 发送数据 buffer 长度 * @return : * @retval : **************************************************************************/ void app_tp_m_write(const uint8_t *txbuffer, size_t buffer_size) { #if SCREEN_MASTER_TRANSFER_I2C hal_i2c_m_dma_write(txbuffer, buffer_size); #elif SCREEN_MASTER_TRANSFER_SPI hal_spi_m_dma_write(txbuffer, buffer_size); s_spim_write = true; #endif } /************************************************************************** * @name : app_tp_m_read * @brief : 根据通信方式配置发送txbuffer中的数据和rxbuffer * @param[in] :cmd: 发送命令 buffer 头地址 * @param[in] :cmd_size: 发送命令 buffer 长度 * @param[in] :data_buffer: 读取数据 buffer 头地址 * @param[in] :data_size: 读取数据 buffer 长度 * @return : * @retval : **************************************************************************/ void app_tp_m_read(const uint8_t *cmd, size_t cmd_size, uint8_t *data_buffer, size_t data_size) { #if SCREEN_MASTER_TRANSFER_I2C uint8_t i = 0; uint32_t address = 0; for (i = 0; i < cmd_size; i++) //先将要发送的数据整合到 address { address |= (uint32_t)cmd[i] << i * 8; } hal_i2c_m_dma_read(address, cmd_size, data_buffer, data_size); #elif SCREEN_MASTER_TRANSFER_SPI hal_spi_m_dma_read(cmd, cmd_size, data_buffer, data_size); #endif } /************************************************************************** * @name : app_tp_s_write * @brief : 根据通信方式配置发送txbuffer中的数据 * @param[in] :txbuffer: 发送数据 buffer 头地址 * @param[in] :buffer_size: 发送数据 buffer 长度 * @return : * @retval : **************************************************************************/ void app_tp_s_write(const uint8_t *txbuffer, size_t buffer_size) { #if PHONE_SLAVE_TRANSFER_I2C hal_i2c_s_dma_write(txbuffer, buffer_size); #elif PHONE_SLAVE_TRANSFER_SPI //while (hal_spi_slave_busy()); hal_spi_slave_auto_transfer_abort(); hal_spi_slave_flush_fifo(); hal_spi_slave_set_auto_tx_buffer(txbuffer, buffer_size, true); hal_spi_slave_auto_transfer_start(); #endif } /************************************************************************** * @name : app_tp_s_read * @brief : 根据通信方式配置rxbuffer * @param[in] :rxBuffer: 读取数据 buffer 头地址 * @param[in] :data_size: 读取数据 buffer 长度 * @return : * @retval : **************************************************************************/ void app_tp_s_read(void *rxBuffer, size_t data_size) { #if PHONE_SLAVE_TRANSFER_I2C hal_i2c_s_nonblocking_read(rxBuffer, data_size); #endif } /************************************************************************** * @name : app_tp_spis_callback * @brief : SPI slave 中断处理函数 * @param[in] : * @return : * @retval : **************************************************************************/ #if PHONE_SLAVE_TRANSFER_I2C //消除warning //经测试。int_status=0,为读命令。=2,为STOP。=1未测试到。 //recieve_num为接收到的指令个数 static void app_tp_i2cs_callback(e_i2c_s_int_status int_status, size_t recieve_num) { #if 0 // 1: test if (int_status >2) { s_phone_read_buffer[2]=int_status; s_phone_read_buffer[3]=recieve_num; app_tp_m_write(s_phone_read_buffer, 4); } #endif app_tp_transfer_phone(recieve_num); } #endif /************************************************************************** * @name : app_tp_spis_callback * @brief : SPI slave 中断处理函数 * @param[in] : * @return : * @retval : **************************************************************************/ #if PHONE_SLAVE_TRANSFER_SPI //消除warning static void app_tp_spis_callback(hal_spis_event_e event, hal_spi_packet_info_t *packet_info) { app_tp_transfer_phone(packet_info->packet_size); } #endif #if 0 /************************************************************************** * @name : app_tp_reset_callback * @brief : 手机 IO跳变复位的中断处理函数 * @param[in] : * @return : * @retval : **************************************************************************/ static void app_tp_reset_callback(void *data) { TAU_LOGD("app_tp_reset_callback\n"); s_phone_reset_flag = true; app_tp_s_write(phone_reg_const_data[0].write_back, phone_reg_const_data[0].write_back_size); #if PHONE_SLAVE_TRANSFER_SPI hal_gpio_set_output_data(IO_PAD_AP_INT, IO_LVL_LOW); #endif } #endif /************************************************************************** * @name : app_tp_transfer_screen_const * @brief : 按照flow读写screen,完成 开机 screen 初始化 * @param[in] : * @return : * @retval : *修改TP第1步:模组初始化!!!!!! *执行数组screen_reg_start_data[]。 **************************************************************************/ static void app_tp_transfer_screen_const(void) { // static bool screen_const_transfer_buffer_ready = true; //发送 buffer 是否已准备好 uint8_t ii; uint8_t len=0; /**** 1. 判断当前状态通信已结束, 状态通信已结束,并且开机初始化流程还未走完****/ #if 1 if(phone_start_flag) { app_tp_m_read(screen_reg_int_data[0].buffer, 1, s_screen_read_buffer, 8); while(!hal_i2c_m_transfer_complate()); delayMs(2); while(!hal_gpio_get_input_data(g_screen_input_int_pad)) { app_tp_m_read(screen_reg_int_data[0].buffer, 1, s_screen_read_buffer, 8); while(!hal_i2c_m_transfer_complate()); delayMs(2); } app_tp_m_write(MI10_PRO_screen_init_data1, sizeof(MI10_PRO_screen_init_data1));//0xA0,0x00,0x01 while(!hal_i2c_m_transfer_complate()); delayMs(1); app_tp_m_write(MI10_PRO_screen_init_data2, sizeof(MI10_PRO_screen_init_data2));//0xA2,0x03,0x00,0x00,0x00,0x03 while(!hal_i2c_m_transfer_complate()); delayMs(1); app_tp_m_write(MI10_PRO_screen_init_data3, sizeof(MI10_PRO_screen_init_data3));//0xA2,0x02,0x00 while(!hal_i2c_m_transfer_complate()); delayMs(1); app_tp_m_write(MI10_PRO_screen_init_data4, sizeof(MI10_PRO_screen_init_data4));//0xC0,0x07,0x01 while(!hal_i2c_m_transfer_complate()); delayMs(1); #ifdef ADD_TP_TUNING app_tp_m_write(MI10_PRO_TP_Tuning_data1, sizeof(MI10_PRO_TP_Tuning_data1)); while(!hal_i2c_m_transfer_complate()); delayMs(10); app_tp_m_write(MI10_PRO_TP_Tuning_data2, sizeof(MI10_PRO_TP_Tuning_data2)); while(!hal_i2c_m_transfer_complate()); delayMs(1); app_tp_m_write(MI10_PRO_TP_Tuning_data3, sizeof(MI10_PRO_TP_Tuning_data3)); while(!hal_i2c_m_transfer_complate()); delayMs(1); app_tp_m_write(MI10_PRO_TP_Tuning_data4, sizeof(MI10_PRO_TP_Tuning_data4)); while(!hal_i2c_m_transfer_complate()); delayMs(1); app_tp_m_write(MI10_PRO_TP_Tuning_data5, sizeof(MI10_PRO_TP_Tuning_data5)); while(!hal_i2c_m_transfer_complate()); delayMs(1); app_tp_m_write(MI10_PRO_TP_Tuning_data6, sizeof(MI10_PRO_TP_Tuning_data6)); while(!hal_i2c_m_transfer_complate()); delayMs(1); app_tp_m_write(MI10_PRO_TP_Tuning_data7, sizeof(MI10_PRO_TP_Tuning_data7)); while(!hal_i2c_m_transfer_complate()); delayMs(1); app_tp_m_write(MI10_PRO_TP_Tuning_data8, sizeof(MI10_PRO_TP_Tuning_data8)); while(!hal_i2c_m_transfer_complate()); delayMs(1); #endif app_tp_m_read(screen_reg_int_data[0].buffer, 1, s_screen_read_buffer, 8); while(!hal_i2c_m_transfer_complate()); if(s_screen_read_buffer[7]>0) { len=s_screen_read_buffer[7]*8; app_tp_m_read(screen_reg_int_data[0].buffer, 1, s_screen_read_buffer, len); while(!hal_i2c_m_transfer_complate()); } #endif if(hal_gpio_get_input_data(g_screen_input_int_pad)) { s_screen_init_complate = true; app_tp_screen_int_init(); phone_start_flag=0; } } } void ap_doubleclick(void) { // app_tp_m_write(MI10_PRO_screen_init_data8, sizeof(MI10_PRO_screen_init_data8));//0xA2,0x03,0x20,0x00,0x00,0x00 // while(!hal_i2c_m_transfer_complate()); // delayMs(1); // app_tp_m_write(MI10_PRO_screen_init_data9, sizeof(MI10_PRO_screen_init_data9));//0xA0,0x01, // while(!hal_i2c_m_transfer_complate()); // delayMs(1); app_tp_m_write(MI10_PRO_screen_init_data10, sizeof(MI10_PRO_screen_init_data10));//0xA0,0x00,0x00 while(!hal_i2c_m_transfer_complate()); delayMs(1); } void ap_doubleclick_1(void) { app_tp_m_write(MI10_PRO_screen_init_data11, sizeof(MI10_PRO_screen_init_data11));//0xC0,0x07,0x00 while(!hal_i2c_m_transfer_complate()); delayMs(1); } /************************************************************************** * @name : app_tp_transfer_screen_start * @brief : 按照flow读写screen,开始开机初始化 * @param[in] : * @return : * @retval : **************************************************************************/ void app_tp_transfer_screen_start(void) { // s_screen_init_complate = false; s_screen_const_transfer_count = 0; //app_tp_screen_init(); #ifndef DISABLE_I2C_INIT_CODE // app_tp_transfer_screen_const(); #endif // s_screen_int_flag = false; } /************************************************************************** * @name : app_tp_transfer_screen_int * @brief : 接收screen中断后,按照flow读写screen,即报点协议转换 * @param[in] : * @return : * @retval : *修改TP第2步:读取模组报点!!!!!! *执行数组screen_reg_int_data[]。也可以自己写。 **************************************************************************/ void app_tp_transfer_screen_int(void) { uint8_t len=0; uint8_t i=0; uint8_t count=0; bool screen_gpio_int = false; static uint8_t screen_int_transfer_count = 0; //记录当前通信到哪一步 static bool screen_int_transfer_buffer_ready = true; //发送 buffer 是否已准备好 // static uint8_t test_flag = 0; if (!s_screen_init_complate) //TP 初始化还未完成,则先进行初始化操作 { app_tp_transfer_screen_const(); // TAU_LOGD("tp screen init"); //debug return; } #if 0 //test test_flag++; if (test_flag >1000000) { test_flag =0; //TAU_LOGD("Run ok!!\n"); //app_tp_m_read(screen_reg_int_data[0].buffer, screen_reg_int_data[0].txbuffer_size, s_screen_number, screen_reg_int_data[0].rxbuffer_size); //while(!hal_i2c_m_transfer_complate()); } #endif /**** 1. 判断 screen 是否发出中断信号 ****/ // s_screen_int_flag: 中断信号标志位 // app_tp_screen_int_lvl_low : SPI 长时间通信时,偶尔会出现cs拉高导致通信异常卡死,该标志位用于解决卡死的问题 screen_gpio_int = s_screen_int_flag || app_tp_screen_int_lvl_low(); if (((screen_gpio_int) || (s_screen_int_transfer_status)) && app_tp_m_transfer_complate()) //判断当前不处于通信状态,并且准备通信 { s_screen_int_flag = false; if (s_spim_write) //SPI 写数据后需要把接收FIFO的数据读出,不然会影响下一次读取 { hal_spi_m_clear_rxfifo(); s_spim_write = false; } /**** 2. 发送或读取从机数据 ****/ if (screen_int_transfer_buffer_ready) { #ifndef READ_MODULE_TP_ONE_BY_ONE screen_int_transfer_buffer_ready = false; s_screen_int_transfer_status = true; #ifdef USE_FOR_MI10_PRO app_tp_m_read(screen_reg_int_data[0].buffer, 1, s_screen_read_buffer, 8); while(!hal_i2c_m_transfer_complate()); if(s_screen_read_buffer[7]>0) { len=s_screen_read_buffer[7]*8; app_tp_m_read(screen_reg_int_data[0].buffer, 1, &s_screen_read_buffer[8], len); while(!hal_i2c_m_transfer_complate()); } delayUs(100); #if 0 if(!hal_gpio_get_input_data(g_screen_input_int_pad)) { if((s_screen_read_MI10Pro[0]==0x43)&&(s_screen_read_MI10Pro[1]==0x0A)&&(s_screen_read_MI10Pro[2]==0x01))//根据蔚来星给出的建议,检测到43 0A 01大面积触摸状态,中断不拉高时,进行一次 System Reset 是0xA4 00 00 { app_tp_m_write(MI10_PRO_screen_init_data12, sizeof(MI10_PRO_screen_init_data12));//0xA4,0x00,0x00 while(!hal_i2c_m_transfer_complate()); s_screen_init_complate=0; phone_start_flag=1; // delayMs(40); for(i=0;i<10;i++) { s_screen_read_MI10Pro[i*8+0]=0x43; s_screen_read_MI10Pro[i*8+1]=((i+1)<<4)+1; s_screen_read_MI10Pro[i*8+2]=0; s_screen_read_MI10Pro[i*8+3]=0; s_screen_read_MI10Pro[i*8+4]=0; s_screen_read_MI10Pro[i*8+5]=0; s_screen_read_MI10Pro[i*8+6]=0; s_screen_read_MI10Pro[i*8+7]=9-i; } } } #endif if(!hal_gpio_get_input_data(g_screen_input_int_pad)) { // if((s_screen_read_MI10Pro[0]==0x43)&&(s_screen_read_MI10Pro[1]==0x0A))//根据蔚来星给出的建议,检测到43 0A 01大面积触摸状态,中断不拉高时,进行一次 System Reset 是0xA4 00 00 { app_tp_m_read(screen_reg_int_data[0].buffer, 1, s_screen_read_buffer, 8); while(!hal_i2c_m_transfer_complate()); if(s_screen_read_buffer[7]>0) { len=s_screen_read_buffer[7]*8; app_tp_m_read(screen_reg_int_data[0].buffer, 1, &s_screen_read_buffer[8], len); while(!hal_i2c_m_transfer_complate()); } } } ap_tp_st_touch_scan_point_record_event(s_screen_read_buffer,len+8); ap_tp_st_touch_error_handler_F3(s_screen_read_buffer); ap_tp_st_touch_error_handler_FF(s_screen_read_buffer); #else app_tp_m_read(screen_reg_int_data[0].buffer, screen_reg_int_data[0].txbuffer_size, s_screen_temp, screen_reg_int_data[0].rxbuffer_size); while(!hal_i2c_m_transfer_complate()); app_tp_m_read(screen_reg_int_data[1].buffer, screen_reg_int_data[1].txbuffer_size, s_screen_number, screen_reg_int_data[1].rxbuffer_size); while(!hal_i2c_m_transfer_complate()); //TAU_LOGD("s_screen_number[%4x], size[%4x]", ((s_screen_number[1]<<8)|s_screen_number[0]), ((s_screen_temp[1]<<8)|s_screen_temp[0])); if(s_screen_number[1]) { if (s_screen_number[1]>3) { read_point =1; s_screen_int_transfer_status = false; } else if (s_screen_number[1] &0x02) read_point =10; else read_point =9; } else { if(s_screen_number[0] &0x80) read_point =8; else if(s_screen_number[0] &0x40) read_point =7; else if(s_screen_number[0] &0x20) read_point =6; else if(s_screen_number[0] &0x10) read_point =5; else if(s_screen_number[0] &0x08) read_point =4; else if(s_screen_number[0] &0x04) read_point =3; else if(s_screen_number[0] &0x02) read_point =2; else read_point =1; } read_point =8*read_point; app_tp_m_read(screen_reg_int_data[0].buffer, 1, s_screen_read_buffer, 8); while(!hal_i2c_m_transfer_complate()); #endif #else if (!screen_reg_int_data[screen_int_transfer_count].read_flag) //当前通信不需要读回,直接写 { app_tp_m_write(screen_reg_int_data[screen_int_transfer_count].buffer, screen_reg_int_data[screen_int_transfer_count].txbuffer_size); } else //当前通信需要读回,先写再读 { s_screen_int_transfer_status = true; if (screen_int_transfer_count==0) { app_tp_m_read(screen_reg_int_data[screen_int_transfer_count].buffer, screen_reg_int_data[screen_int_transfer_count].txbuffer_size, \ s_screen_temp, screen_reg_int_data[screen_int_transfer_count].rxbuffer_size); screen_int_transfer_count =1; } else if (screen_int_transfer_count==1) { app_tp_m_read(screen_reg_int_data[screen_int_transfer_count].buffer, screen_reg_int_data[screen_int_transfer_count].txbuffer_size, \ s_screen_number, screen_reg_int_data[screen_int_transfer_count].rxbuffer_size); screen_int_transfer_count =2; } else if (screen_int_transfer_count==2) { if(s_screen_number[1]) { TAU_LOGD("s_screen_number[%4x], size[%4x]", ((s_screen_number[1]<<8)|s_screen_number[0]), ((s_screen_temp[1]<<8)|s_screen_temp[0])); if (s_screen_number[1] &0x02) read_point =10; else read_point =9; } else { if(s_screen_number[0] &0x80) read_point =8; else if(s_screen_number[0] &0x40) read_point =7; else if(s_screen_number[0] &0x20) read_point =6; else if(s_screen_number[0] &0x10) read_point =5; else if(s_screen_number[0] &0x08) read_point =4; else if(s_screen_number[0] &0x04) read_point =3; else if(s_screen_number[0] &0x02) read_point =2; else read_point =1; } read_point =8*read_point; app_tp_m_read(screen_reg_int_data[screen_int_transfer_count].buffer, screen_reg_int_data[screen_int_transfer_count].txbuffer_size, \ s_screen_read_buffer, read_point); screen_int_transfer_count =0; screen_int_transfer_buffer_ready = false; } } #endif } /**** 3. 解析本次通信数据,并准备下一次通信的buffer ****/ else { #if 1 #ifdef USE_FOR_SUMSUNG_S20 u16TouchID=0x0000; #endif // if(s_screen_read_buffer[0] == 0xF3 && s_screen_read_buffer[1] == 0x02 && s_screen_read_buffer[2] == 0x00) // 收到 TP 异常回复 0xF3 0x02 0x00 0x00 0x00 0x00 0x00 0x00 // { // s_screen_read_buffer[0] =0; // ap_tp_system_softReset(); // TAU_LOGD("TP system reset3\n"); // return; // } // else // { // // printf("%2x,%2d,%2d\n",s_screen_read_buffer[0],screen_reg_int_data[2].rxbuffer_size,screen_int_transfer_count); // } // screen_int_transfer_buffer_ready = true; phone_touch_flag=0; screen_int_transfer_count = app_tp_screen_analysis_int(screen_int_transfer_count, s_screen_read_buffer,screen_reg_int_data[2].rxbuffer_size); screen_int_transfer_count = 0; s_screen_int_transfer_status = false; #else screen_int_transfer_buffer_ready = true; screen_int_transfer_count = app_tp_screen_analysis_int(screen_int_transfer_count, s_screen_read_buffer, \ screen_reg_int_data[screen_int_transfer_count].rxbuffer_size); if (screen_int_transfer_count > screen_reg_int_data_size) //解析需要等最后一次通信结束,最后一次数据解析后,停止通信 { screen_int_transfer_count = 0; s_screen_int_transfer_status = false; return; } #endif } } } /************************************************************************** * @name : app_tp_transfer_phone * @brief : 根据数据解析进行相应的答复 * @param[in] : recieve_num:接收数据长度 * @return : * @retval : **************************************************************************/ static void app_tp_transfer_phone(size_t recieve_num) { const uint8_t *phone_write_buffer; size_t phone_write_buffer_size = 0; /* 数据解析,判断是否需要答复以及答复的buffer指针 */ if (recieve_num > 0) { #if 0// 1: test s_phone_read_buffer[3]=recieve_num; app_tp_m_write(s_phone_read_buffer, 4); #endif app_tp_phone_analysis_data(s_phone_read_buffer, recieve_num, &phone_write_buffer, &phone_write_buffer_size); } app_tp_s_read(s_phone_read_buffer, BUFFER_SIZE_MAX); if (phone_write_buffer_size) //大于0表示需要答复手机,配置发送buffer { app_tp_s_write(phone_write_buffer, phone_write_buffer_size); } } /************************************************************************** * @name : app_tp_phone_reset_on * @brief : 获取手机复位信号的状态 * @param[in] : * @return : * @retval : **************************************************************************/ bool app_tp_phone_reset_on(void) { return s_phone_reset_flag; } /************************************************************************** * @name : app_tp_phone_clear_reset_on * @brief : 清除手机复位信号的状态 * @param[in] : * @return : * @retval : **************************************************************************/ void app_tp_phone_clear_reset_on(void) { s_phone_reset_flag = false; } #else void app_tp_screen_init(void) { } void app_tp_init(void) { } void app_tp_transfer_screen_int(void) { } void app_tp_transfer_screen_start(void) { } bool app_tp_phone_reset_on(void) { return false; } void app_tp_phone_clear_reset_on(void) { } void app_tp_s_write(const uint8_t *txbuffer, size_t buffer_size) { } bool app_tp_enter_sleep_on(void) { return false; } #endif