From: penglei <1624952103@qq.com> Date: Fri, 7 Nov 2025 12:20:45 +0000 (+0800) Subject: 优化272 TP效果 X-Git-Tag: V1.0.9_20251128_194606_LN~102 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=64e877e0494cd4051beaf87c1f7a500b8b8b7c1b;p=mirrors%2FFD230.git 优化272 TP效果 --- diff --git a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c index 2e726b433..adb528a9b 100644 --- a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -175,12 +175,9 @@ static void sample_gfx_init(void) ztw523_host_init_sample(); #endif #endif - printf("11111 \n"); uapi_lcd_init(); uapi_vau_module_init(); - printf("22222 \n"); uapi_dpu_module_init(); - printf("33333 \n"); #ifdef SUPPORT_GPU_JPEG uapi_jpeg_module_init(); #endif diff --git a/code/sdk/drivers/drivers/driver/touch/cst92xx_touch/cst92xx_ctrl.c b/code/sdk/drivers/drivers/driver/touch/cst92xx_touch/cst92xx_ctrl.c index 46e2f6a4e..f79240522 100644 --- a/code/sdk/drivers/drivers/driver/touch/cst92xx_touch/cst92xx_ctrl.c +++ b/code/sdk/drivers/drivers/driver/touch/cst92xx_touch/cst92xx_ctrl.c @@ -101,17 +101,21 @@ ext_errno cst92xx_tp_i2c_data_read(uint32_t reg_addr, uint8_t reg_len, uint8_t * uint8_t reg_addr_buf[4] = {0}; - ret = cst92xx_tp_i2c_rd_wr_param_check(data_buf, data_len); - if (ret != 0) { - tp_err("tp data read param invalid! ret=0x%x", ret); - return ret; - } + if(data_len) + { + ret = cst92xx_tp_i2c_rd_wr_param_check(data_buf, data_len); + if (ret != 0) { + tp_err("tp data read param invalid! ret=0x%x", ret); + return ret; + } - if (memset_s(g_tp_recv_buf, data_len, 0, data_len) != EOK) { - tp_err("tp read buff set fail!"); - return EXT_ERR_FAILURE; + if (memset_s(g_tp_recv_buf, data_len, 0, data_len) != EOK) { + tp_err("tp read buff set fail!"); + return EXT_ERR_FAILURE; + } } + // printf("reg_addr : 0x%x\n",reg_addr); // for(int i = 0; i < reg_len; i++) // { @@ -146,27 +150,48 @@ ext_errno cst92xx_tp_i2c_data_read(uint32_t reg_addr, uint8_t reg_len, uint8_t * data.send_buf = reg_buf; data.send_len = reg_len; - data.receive_buf = g_tp_recv_buf; - data.receive_len = data_len; + if(data_len) + { + data.receive_buf = g_tp_recv_buf; + data.receive_len = data_len; + } + + // printf("send_buf[0]:[%x] send_buf[1]:[%x] send_buf[2]:[%x] send_buf[3]:[%x]\n",data.send_buf[0],data.send_buf[1],data.send_buf[2],data.send_buf[3]); + if(data_len) + { + for (retry = 0; retry < CST92XX_I2C_TIME_MAX; retry++) { + ret = uapi_i2c_master_writeread(CST92XX_I2C_BUS, CST92XX_I2C_ADDR, &data); + if (ret == EXT_ERR_SUCCESS) { + break; + } + } + if (ret != EXT_ERR_SUCCESS) { + tp_err("tp data read fail! ret=0x%x", ret); + return ret; + } - for (retry = 0; retry < CST92XX_I2C_TIME_MAX; retry++) { - ret = uapi_i2c_master_writeread(CST92XX_I2C_BUS, CST92XX_I2C_ADDR, &data); + ret = (uint32_t)memcpy_s(data_buf, data_len, g_tp_recv_buf, data_len); + if (ret != EOK) { + tp_err("tp data buf content copy fail! ret=0x%x", ret); + return ret; + } + } + else + { + for (retry = 0; retry < CST92XX_I2C_TIME_MAX; retry++) { + ret = uapi_i2c_master_write(CST92XX_I2C_BUS, CST92XX_I2C_ADDR, &data); if (ret == EXT_ERR_SUCCESS) { break; } - } - if (ret != EXT_ERR_SUCCESS) { - tp_err("tp data read fail! ret=0x%x", ret); - return ret; + } + if (ret != EXT_ERR_SUCCESS) { + tp_err("tp data write fail! ret=0x%x", ret); + return ret; + } } - ret = (uint32_t)memcpy_s(data_buf, data_len, g_tp_recv_buf, data_len); - if (ret != EOK) { - tp_err("tp data buf content copy fail! ret=0x%x", ret); - return ret; - } return EXT_ERR_SUCCESS; } diff --git a/code/sdk/drivers/drivers/driver/touch/cst92xx_touch/cst92xx_touch1.c b/code/sdk/drivers/drivers/driver/touch/cst92xx_touch/cst92xx_touch1.c index ef6fee65d..5524ab5c7 100644 --- a/code/sdk/drivers/drivers/driver/touch/cst92xx_touch/cst92xx_touch1.c +++ b/code/sdk/drivers/drivers/driver/touch/cst92xx_touch/cst92xx_touch1.c @@ -63,13 +63,13 @@ static int hyn_write_data(struct hyn_ts_data *hyn_92xxdata,uint8_t *buf, uint8_t { cst92xx_tp_i2c_data_write(buf,reg_len+len); - return 0; + return 1; } static int hyn_wr_reg(struct hyn_ts_data *hyn_92xxdata, uint32_t reg_addr, uint8_t reg_len, uint8_t *rbuf, uint16_t rlen) { cst92xx_tp_i2c_data_read(reg_addr,reg_len,rbuf,rlen); - return 0; + return 1; } // cst92xx_drv_data g_cst92xx_drv = { @@ -217,7 +217,7 @@ int cst92xx_init(struct hyn_ts_data* ts_data) hyn_delay_ms(40); ret = cst92xx_updata_tpinfo(); - if(ret == FALSE){ + if(ret != 0){ HYN_INFO("cst92xx_updata_tpinfo failed"); } ret |= cst92xx_set_workmode(NOMAL_MODE,0); @@ -228,70 +228,60 @@ int cst92xx_init(struct hyn_ts_data* ts_data) } #endif -static int cst92xx_enter_boot(void) +static int cst92xx_enter_boot(void) { - if(hyn_92xxdata == NULL) - { - return EXT_ERR_FAILURE; - } - - int ok = FALSE,t,retry = 3; + int ok = FALSE,t; uint8_t i2c_buf[4] = {0}; - hyn_set_i2c_addr(hyn_92xxdata,BOOT_I2C_ADDR); + for (t = 10;; t += 2) { - if(t >= 30 || retry==0){ + if (t >= 30){ return FALSE; } - // cst92xx_reset(); cst92xx_reset(); hyn_delay_ms(t); - ok = hyn_wr_reg(hyn_92xxdata, 0xA001AA, 3, i2c_buf, 2); - if(ok == FALSE || (i2c_buf[0]==0x5A && i2c_buf[1]==0x5A)){ - if(ok==TRUE && retry){ - retry--; - t = 10; - } + ok = hyn_wr_reg(hyn_92xxdata, 0xA001AA, 3, i2c_buf, 0); + if(ok == FALSE){ continue; } + hyn_delay_ms(1); + ok = hyn_wr_reg(hyn_92xxdata, 0xA002, 2, i2c_buf, 2); if(ok == FALSE){ continue; } + if ((i2c_buf[0] == 0x55) && (i2c_buf[1] == 0xB0)) { break; } } - ok = hyn_wr_reg(hyn_92xxdata, 0xA00100, 3, i2c_buf, 2); + + ok = hyn_wr_reg(hyn_92xxdata, 0xA00100, 3, i2c_buf, 0); if(ok == FALSE){ return FALSE; } + return TRUE; } static int erase_all_mem(void) { - if(hyn_92xxdata == NULL) - { - return EXT_ERR_FAILURE; - } - int ok = FALSE,t; uint8_t i2c_buf[8]; //erase_all_mem - ok = hyn_wr_reg(hyn_92xxdata, 0xA0140000, 4, i2c_buf, 2); + ok = hyn_wr_reg(hyn_92xxdata, 0xA0140000, 4, i2c_buf, 0); if (ok == FALSE){ return FALSE; } - ok = hyn_wr_reg(hyn_92xxdata, 0xA00C807F, 4, i2c_buf, 2); + ok = hyn_wr_reg(hyn_92xxdata, 0xA00C807F, 4, i2c_buf, 0); if (ok == FALSE){ return FALSE; } - ok = hyn_wr_reg(hyn_92xxdata, 0xA004EC, 3, i2c_buf, 2); + ok = hyn_wr_reg(hyn_92xxdata, 0xA004EC, 3, i2c_buf, 0); if (ok == FALSE){ return FALSE; } @@ -353,7 +343,7 @@ static int write_mem_page(uint16_t addr, uint8_t *buf, uint16_t len) } - ok = hyn_wr_reg(hyn_92xxdata,0xA004EE,3,i2c_buf,2); + ok = hyn_wr_reg(hyn_92xxdata,0xA004EE,3,i2c_buf,0); if(ok == FALSE){ return FALSE; } @@ -420,7 +410,8 @@ static uint32_t cst92xx_read_checksum(void) uint32_t chip_checksum = 0; uint8_t retry = 5; - ok = hyn_wr_reg(hyn_92xxdata,0xA00300,3,i2c_buf,2); + hyn_92xxdata->boot_is_pass = 0; + ok = hyn_wr_reg(hyn_92xxdata,0xA00300,3,i2c_buf,0); if (ok == FALSE) { return FALSE; } @@ -436,12 +427,17 @@ static uint32_t cst92xx_read_checksum(void) hyn_delay_ms(1); if(i2c_buf[0] == 0x01){ + hyn_92xxdata->boot_is_pass = 1; memset(i2c_buf,0,sizeof(i2c_buf)); ok = hyn_wr_reg(hyn_92xxdata,0xA008,2,i2c_buf,4); if (ok == FALSE) { return FALSE; } - chip_checksum = uint8_tTO32(i2c_buf[3],i2c_buf[2],i2c_buf[1],i2c_buf[0]); + + chip_checksum = ((uint32_t)(i2c_buf[0])) | + (((uint32_t)(i2c_buf[1])) << 8) | + (((uint32_t)(i2c_buf[2])) << 16) | + (((uint32_t)(i2c_buf[3])) << 24); } else{ hyn_92xxdata->need_updata_fw = 1; @@ -471,13 +467,13 @@ static int cst92xx_updata_fw(uint8_t *bin_addr, uint16_t len) if(0 != hyn_92xxdata->fw_file_name[0]){ //node to update ok = copy_for_updata(hyn_92xxdata,i2c_buf,CST92XX_BIN_SIZE-20,4); - fw_checksum = uint8_tTO32(i2c_buf[3],i2c_buf[2],i2c_buf[1],i2c_buf[0]); + fw_checksum = U8TO32(i2c_buf[3],i2c_buf[2],i2c_buf[1],i2c_buf[0]); if(hyn_92xxdata->hw_info.ic_fw_checksum == fw_checksum || ok != 0){ HYN_INFO("no update,fw_checksum is same:0x%04x",fw_checksum); goto UPDATA_END; } }else{ - fw_checksum = uint8_tTO32(bin_addr[CHECKSUM_OFFECT+3],bin_addr[CHECKSUM_OFFECT+2],bin_addr[CHECKSUM_OFFECT+1],bin_addr[CHECKSUM_OFFECT+0]); + fw_checksum = U8TO32(bin_addr[CHECKSUM_OFFECT+3],bin_addr[CHECKSUM_OFFECT+2],bin_addr[CHECKSUM_OFFECT+1],bin_addr[CHECKSUM_OFFECT+0]); } HYN_INFO("updating fw checksum:0x%04x",fw_checksum); @@ -517,7 +513,7 @@ static int cst92xx_updata_fw(uint8_t *bin_addr, uint16_t len) break; } - hyn_wr_reg(hyn_92xxdata,0xA006EE,3,i2c_buf,2); //exit boot + hyn_wr_reg(hyn_92xxdata,0xA006EE,3,i2c_buf,0); //exit boot hyn_delay_ms(2); UPDATA_END: @@ -538,39 +534,135 @@ UPDATA_END: return ok_copy; } - -static int cst92xx_updata_tpinfo(void) +static int16_t read_word_from_mem(uint8_t type, uint16_t addr, uint32_t *value) { - if(hyn_92xxdata == NULL) + int16_t ret = 0; + uint8_t i2c_buf[4] = {0},t; + + i2c_buf[0] = 0xA0; + i2c_buf[1] = 0x10; + i2c_buf[2] = type; + ret = hyn_write_data(hyn_92xxdata,i2c_buf,2,3); + if (ret) + { return -1; + } - uint8_t buf[30],retry=8; - struct tp_info *ic = &hyn_92xxdata->hw_info; - if(ic == NULL) + i2c_buf[0] = 0xA0; + i2c_buf[1] = 0x0C; + i2c_buf[2] = addr; + i2c_buf[3] = addr >> 8; + ret = hyn_write_data(hyn_92xxdata,i2c_buf,2,4); + if (ret) + { return -1; + } - int ret = 0; - hyn_92xxdata->boot_is_pass = 0; - while(retry--){ - cst92xx_set_workmode(0xff,DISABLE); - ret = hyn_wr_reg(hyn_92xxdata,0xD101,2,buf,2); - if(ret) continue; - ret = hyn_wr_reg(hyn_92xxdata,0xD1F4,2,buf,28); - printf("buf[19] :0x%x\n",buf[19]); - if(ret==0 && (buf[19]==0x92||buf[19]==0x91)){ + i2c_buf[0] = 0xA0; + i2c_buf[1] = 0x04; + i2c_buf[2] = 0xE4; + ret = hyn_write_data(hyn_92xxdata,i2c_buf,2,3); + if (ret) + { + return -1; + } + + for (t = 0;; t++) + { + if (t >= 100) + { + return -1; + } + ret =hyn_wr_reg(hyn_92xxdata,0xA004,2,i2c_buf,1); + if (ret) + { + continue; + } + if (i2c_buf[0] == 0x00) + { break; } - ret = -1; } - if(ret){ - return FALSE; + ret =hyn_wr_reg(hyn_92xxdata,0xA018,2,i2c_buf,4); + if (ret) + { + return -1; + } + *value = ((uint32_t)(i2c_buf[0])) | + (((uint32_t)(i2c_buf[1])) << 8) | + (((uint32_t)(i2c_buf[2])) << 16) | + (((uint32_t)(i2c_buf[3])) << 24); + + return 0; +} +static int cst92xx_read_chip_id(void) +{ + int16_t ret = 0; + uint8_t retry = 3; + uint32_t partno_chip_type,module_id; + + ret = cst92xx_enter_boot(); + if (ret == FALSE) + { + HYN_ERROR("enter_bootloader error"); + return -1; + } + for (; retry > 0; retry--) + { + // partno + ret = read_word_from_mem(1, 0x077C, &partno_chip_type); + if (ret) + { + continue; + } + // module id + ret = read_word_from_mem(0, 0x7FC0, &module_id); + if (ret) + { + continue; + } + if ((partno_chip_type >> 16) == 0xCACA) + { + partno_chip_type &= 0xffff; + break; + } + } + cst92xx_reset(); + LOS_Mdelay(30); + HYN_INFO("partno_chip_type: 0x%04x", partno_chip_type); + HYN_INFO("module_id: 0x%04x", module_id); + if ((partno_chip_type != 0x9217) && (partno_chip_type != 0x9220)) + { + HYN_ERROR("partno_chip_type error 0x%04x", partno_chip_type); + //return -1; + } + return 0; +} + +static int cst92xx_updata_tpinfo(void) +{ + uint8_t buf[30]; + struct tp_info *ic = &hyn_92xxdata->hw_info; + int ret = 0; + + cst92xx_set_workmode(0xff,DISABLE); + ret = hyn_wr_reg(hyn_92xxdata,0xD101,2,buf,0); + if(ret == FALSE){ + return FALSE; + } + LOS_Mdelay(5); + + //firmware_project_id firmware_ic_type + ret = hyn_wr_reg(hyn_92xxdata,0xD1F4,2,buf,28); + if(ret == FALSE){ + return FALSE; } - hyn_92xxdata->boot_is_pass = 1; ic->fw_project_id = ((uint16_t)buf[17] <<8) + buf[16]; ic->fw_chip_type = ((uint16_t)buf[19] <<8) + buf[18]; //firmware_version ic->fw_ver = (buf[23]<<24)|(buf[22]<<16)|(buf[21]<<8)|buf[20]; + //tx_num rx_num key_num ic->fw_sensor_txnum = ((uint16_t)buf[1]<<8) + buf[0]; ic->fw_sensor_rxnum = buf[2]; @@ -581,11 +673,12 @@ static int cst92xx_updata_tpinfo(void) //fw_checksum ic->ic_fw_checksum = (buf[27]<<24)|(buf[26]<<16)|(buf[25]<<8)|buf[24]; + HYN_INFO("IC_info project_id:%04x ictype:%04x fw_ver:%x checksum:%#x",ic->fw_project_id,ic->fw_chip_type,ic->fw_ver,ic->ic_fw_checksum); cst92xx_set_workmode(NOMAL_MODE,ENABLE); - return TRUE; + return 0; } static int cst92xx_updata_judge(uint8_t *p_fw, uint16_t len) @@ -593,22 +686,35 @@ static int cst92xx_updata_judge(uint8_t *p_fw, uint16_t len) uint32_t f_checksum,f_fw_ver,f_ictype,f_fw_project_id; uint8_t *p_data = p_fw + len - 28; //7F64 struct tp_info *ic = &hyn_92xxdata->hw_info; + int ret; - f_fw_project_id = uint8_tTO16(p_data[1],p_data[0]); - f_ictype = uint8_tTO16(p_data[3],p_data[2]); + ret = cst92xx_enter_boot(); + if (ret == FALSE){ + HYN_INFO("cst92xx_enter_boot fail,need update"); + return 1; + } + hyn_92xxdata->hw_info.ic_fw_checksum = cst92xx_read_checksum(); + if(hyn_92xxdata->boot_is_pass == 0){ + HYN_INFO("boot_is_pass %d,need force update",hyn_92xxdata->boot_is_pass); + return 1; //need updata + } + + f_fw_project_id = U8TO16(p_data[1],p_data[0]); + f_ictype = U8TO16(p_data[3],p_data[2]); - f_fw_ver = uint8_tTO16(p_data[7],p_data[6]); - f_fw_ver = (f_fw_ver<<16)|uint8_tTO16(p_data[5],p_data[4]); + f_fw_ver = U8TO16(p_data[7],p_data[6]); + f_fw_ver = (f_fw_ver<<16)|U8TO16(p_data[5],p_data[4]); - f_checksum = uint8_tTO16(p_data[11],p_data[10]); - f_checksum = (f_checksum << 16)|uint8_tTO16(p_data[9],p_data[8]); + f_checksum = U8TO16(p_data[11],p_data[10]); + f_checksum = (f_checksum << 16)|U8TO16(p_data[9],p_data[8]); HYN_INFO("Bin_info project_id:0x%04x ictype:0x%04x fw_ver:0x%x checksum:0x%x",f_fw_project_id,f_ictype,f_fw_ver,f_checksum); - if( - (f_checksum != ic->ic_fw_checksum && f_fw_ver >= ic->fw_ver && f_ictype == ic->fw_chip_type) - || (hyn_92xxdata->boot_is_pass==0) //empty chip - ){ + if(f_ictype != ic->fw_chip_type || f_fw_project_id != ic->fw_project_id){ + HYN_ERROR("not update,please confirm: ic_type 0x%04x,ic_project_id 0x%04x",ic->fw_chip_type,ic->fw_project_id); + return 0; //not updata + } + if(f_checksum != ic->ic_fw_checksum && f_fw_ver > ic->fw_ver){ HYN_INFO("need update!"); return 1; //need updata } @@ -620,68 +726,82 @@ static int cst92xx_updata_judge(uint8_t *p_fw, uint16_t len) int cst92xx_set_workmode(uint8_t mode,uint8_t enable) { - // printf("mode : %d\n",mode); int ok = FALSE; uint8_t i2c_buf[4] = {0}; uint8_t i = 0; hyn_92xxdata->work_mode = mode; - - for(i=0;i<3;i++){ - ok = hyn_wr_reg(hyn_92xxdata,0xD11E,2,i2c_buf,2); - LOS_Udelay(200); - ok |= hyn_wr_reg(hyn_92xxdata,0x0002,2,i2c_buf,2); - printf("i2c_buf[1] :0x%x\n",i2c_buf[1]); - if(ok==TRUE && i2c_buf[1] == 0x1E){ + // if(mode != NOMAL_MODE){ + // hyn_esdcheck_switch(hyn_92xxdata,DISABLE); + // } + for(i=0;i<3;i++) + { + ok = hyn_wr_reg(hyn_92xxdata,0xD11E,2,i2c_buf,0); + if (ok == FALSE) { + msleep(1); + continue; + } + msleep(1); + ok = hyn_wr_reg(hyn_92xxdata,0x0002,2,i2c_buf,2); + if (ok == FALSE) { + msleep(1); + continue; + } + if(i2c_buf[1] == 0x1E){ break; } } - // hyn_esdcheck_switch(hyn_92xxdata,enable); + switch(mode){ case NOMAL_MODE: hyn_irq_set(hyn_92xxdata,ENABLE); - ok = hyn_wr_reg(hyn_92xxdata,0xD109,2,i2c_buf,2); + // hyn_esdcheck_switch(hyn_92xxdata,ENABLE); + ok = hyn_wr_reg(hyn_92xxdata,0xD109,2,i2c_buf,0); + if (ok == FALSE) { + return FALSE; + } break; case GESTURE_MODE: - ok = hyn_wr_reg(hyn_92xxdata,0xD104,2,i2c_buf,2); + ok = hyn_wr_reg(hyn_92xxdata,0xD104,2,i2c_buf,0); + if (ok == FALSE) { + return FALSE; + } break; case LP_MODE: - ok = hyn_wr_reg(hyn_92xxdata,0xD107,2,i2c_buf,2); + ok = hyn_wr_reg(hyn_92xxdata,0xD107,2,i2c_buf,0); + if (ok == FALSE) { + return FALSE; + } break; case DIFF_MODE: - ok = hyn_wr_reg(hyn_92xxdata,0xD10D,2,i2c_buf,2); + ok = hyn_wr_reg(hyn_92xxdata,0xD10D,2,i2c_buf,0); + if (ok == FALSE) { + return FALSE; + } break; + case RAWDATA_MODE: - ok = hyn_wr_reg(hyn_92xxdata,0xD10A,2,i2c_buf,2); + ok = hyn_wr_reg(hyn_92xxdata,0xD10A,2,i2c_buf,0); + if (ok == FALSE) { + return FALSE; + } break; case FAC_TEST_MODE: - hyn_wr_reg(hyn_92xxdata,0xD114,2,i2c_buf,2); - msleep(50); - break; - case CHARGE_EXIT: - case CHARGE_ENTER: - hyn_92xxdata->charge_is_enable = mode&0x01; - ok = hyn_wr_reg(hyn_92xxdata,(mode&0x01)? 0xD01F:0xD020,2,i2c_buf,2); //charg mode - mode = hyn_92xxdata->work_mode; //not switch work mode - HYN_INFO("set_charge:%d",hyn_92xxdata->charge_is_enable); - break; - case ENTER_BOOT_MODE: - ok = cst92xx_enter_boot(); + hyn_wr_reg(hyn_92xxdata,0xD114,2,i2c_buf,0); break; case DEEPSLEEP: - hyn_wr_reg(hyn_92xxdata,0xD105,2,i2c_buf,2); + hyn_wr_reg(hyn_92xxdata,0xD105,2,i2c_buf,0); break; default : hyn_92xxdata->work_mode = NOMAL_MODE; - ok = -2; break; } - if(ok != -2){ - hyn_92xxdata->work_mode = mode; - } - HYN_INFO("set_workmode:%d ret:%d",mode,ok); - return ok; + + return 0; } + + + static int cst92xx_supend(void) { HYN_ENTER(); @@ -689,209 +809,234 @@ static int cst92xx_supend(void) return 0; } - static int cst92xx_resum(void) { cst92xx_reset(); msleep(50); - cst92xx_set_workmode(NOMAL_MODE,1); + cst92xx_set_workmode(NOMAL_MODE,0); return 0; } - // if (model == 0) - // { - // g_cst92xx_drv.touch_msg.tp_event = MC_TP_RELEASE; - // point_count=0; - // }else{ - // if (point_count==0) - // { - // g_cst92xx_drv.touch_msg.tp_event = MC_TP_PRESS; - // }else{ - // g_cst92xx_drv.touch_msg.tp_event = MC_TP_MOVE; - // } - // point_count++; - // } +static int cst92xx_report(void) +{ + static int point_count = 0; + int ok = FALSE; + uint8_t i2c_buf[MAX_POINTS_REPORT*5+5] = {0}; + uint8_t finger_num = 0; + uint8_t key_state=0,key_id = 0; + + hyn_92xxdata->rp_buf.report_need = REPORT_NONE; + + ok = hyn_wr_reg(hyn_92xxdata,0xD000,2,i2c_buf,sizeof(i2c_buf)); + if (ok == FALSE){ + return FALSE; + } - // g_cst92xx_drv.touch_msg.tp_event_info.x_axis[0] = x_axis; - // g_cst92xx_drv.touch_msg.tp_event_info.y_axis[0] = y_axis; - // g_cst92xx_drv.touch_msg.tv_usec = (uint32_t)uapi_tcxo_get_ms(); - - // // } else { - // // g_cst92xx_drv.touch_msg.tp_event = MC_TP_INVALID; - // // tp_warning("TOUCH:parse wrong touchstatus %d", touch_status); - // // return EXT_ERR_SUCCESS; - // // } + ok = hyn_wr_reg(hyn_92xxdata,0xD000AB,3,i2c_buf,0); + if (ok == FALSE){ + return FALSE; + } - // return EXT_ERR_SUCCESS; -static int cst92xx_report(void) -{ - if(hyn_92xxdata == NULL) - { - return EXT_ERR_FAILURE; + if (i2c_buf[6] != 0xAB) { + HYN_INFO("fail buf[6]=0x%02x",i2c_buf[6]); + return FALSE; } - int ret = FALSE; - uint8_t i2c_buf[MAX_FINGER*5+5] = {0}; - uint8_t finger_num = 0,key_state=0,retry=3,re_len=0,ges_state; - while(--retry){ - hyn_wr_reg(hyn_92xxdata,0xD000,2,i2c_buf,2); //wakeup - LOS_Udelay(200); - ret = hyn_wr_reg(hyn_92xxdata,0xD000,2,i2c_buf,7); - if(ret || i2c_buf[6]!=0xAB || i2c_buf[0]==0xAB){ - ret = -1; - continue; - } - finger_num = i2c_buf[5] & 0x7F; - printf("finger_num : %d\n",finger_num); - if(finger_num > MAX_FINGER){ - ret = -2; - continue; - } - key_state = i2c_buf[5]>>7; - printf("key_state : %d\n",key_state); - re_len = ((finger_num>1 ? finger_num-1:0)+key_state)*5; - if(re_len){ - ret = hyn_wr_reg(hyn_92xxdata,0xD007,2,i2c_buf+7,re_len); - if(ret){ - ret = -2; - continue; - } - } - ret = hyn_wr_reg(hyn_92xxdata,0xD000AB,3,i2c_buf,2); //write end flag - if(ret){ - ret = -3; - continue; - } - else{ - break; - } - } + finger_num = i2c_buf[5] & 0x7F; - if(ret){ - HYN_ERROR("read point erro:%d\r\n",ret); - hyn_wr_reg(hyn_92xxdata,0xD000AB,3,i2c_buf,2); //write end flag - return ret; + if (finger_num > MAX_POINTS_REPORT) { + HYN_INFO("fail finger_num=%d",finger_num); + return TRUE; } + hyn_92xxdata->rp_buf.rep_num = finger_num; - ges_state = i2c_buf[4]>>4; - // printf("ges_state :%d\n",ges_state); - if(ges_state){ //gesture - if((ges_state&0x80) == 0x80){ //palm - hyn_92xxdata->gesture_id = IDX_POWER;//IDX_Z;// palm - } - else{ //other gesture - hyn_92xxdata->gesture_id = IDX_POWER;//GESTURE wakeup - } - HYN_INFO("gesture buf4:%#x\r\n",i2c_buf[4]); - hyn_92xxdata->rp_buf.report_need |= REPORT_GES; - printf("111 hyn_92xxdata->rp_buf.report_need |= REPORT_GES \n"); - } - // printf("key_state :%d\n",key_state); - if(key_state){ - uint8_t *data_ptr = i2c_buf; - if(finger_num){ - data_ptr += (finger_num*5+2); + + if ((i2c_buf[5] & 0x80) == 0x80) { // button + uint8_t *data = i2c_buf + finger_num * 5; + if (finger_num > 0) { + data += 2; } - if( hyn_92xxdata->rp_buf.report_need==REPORT_NONE){ + key_state = data[0];//0x83:������� 0x80:����̧�� + key_id = data[1]; // data[1]; :0x17 0x27 0x37 + + if(key_state&0x80){ hyn_92xxdata->rp_buf.report_need |= REPORT_KEY; + if((key_id == hyn_92xxdata->rp_buf.key_id || 0 == hyn_92xxdata->rp_buf.key_state)&& key_state == 0x83){ + hyn_92xxdata->rp_buf.key_id = key_id; + hyn_92xxdata->rp_buf.key_state = 1; + } + else{ + hyn_92xxdata->rp_buf.key_state = 0; + } } - hyn_92xxdata->rp_buf.key_id = (data_ptr[1]>>4)-1; //0x17 0x27 0x37 - hyn_92xxdata->rp_buf.key_state = data_ptr[0]==0x83 ? 1:0; //0x83 0x80 - printf("hyn_92xxdata->rp_buf.key_id : %d\n",hyn_92xxdata->rp_buf.key_id); - printf("hyn_92xxdata->rp_buf.key_state : %d\n",hyn_92xxdata->rp_buf.key_state); } - - if(finger_num){ - uint8_t i = 0,index = 0,id = 0; - uint8_t *data_ptr = i2c_buf; - if( hyn_92xxdata->rp_buf.report_need==REPORT_NONE){ - hyn_92xxdata->rp_buf.report_need |= REPORT_POS; + else//pos + { + uint8_t index = 0,i; + if((i2c_buf[4]&0xF0) > 0){ + if((i2c_buf[4]&0x80) == 0x80) + hyn_92xxdata->gesture_id = 14;//KEY_POWER;// palm + else if(i2c_buf[4]&0x70) + hyn_92xxdata->gesture_id = 14;//GESTURE wakeup + HYN_INFO("i2c_buf[4]=0x%x,gesture_id=0x%x",i2c_buf[4],hyn_92xxdata->gesture_id); + hyn_92xxdata->rp_buf.report_need |= REPORT_GES; + return TRUE; } - for (i = 0; i < finger_num; i++) { - id = data_ptr[0] >> 4; - - hyn_92xxdata->rp_buf.pos_info[index].pos_id = id; - hyn_92xxdata->rp_buf.pos_info[index].event = (data_ptr[0]&0x0F) ? 1 : 0; - hyn_92xxdata->rp_buf.pos_info[index].pos_x = (data_ptr[1] << 4) | (data_ptr[3] >> 4); - hyn_92xxdata->rp_buf.pos_info[index].pos_y = (data_ptr[2] << 4) | (data_ptr[3] & 0x0F); - hyn_92xxdata->rp_buf.pos_info[index].pres_z = (data_ptr[4] & 0x7F); - - data_ptr += (i==0 ? 7:5); - - - printf("hyn_92xxdata->rp_buf.pos_info[index].event : %d index:%d\n",hyn_92xxdata->rp_buf.pos_info[index].event,index); - uint8_t event = hyn_92xxdata->rp_buf.pos_info[index].event; // 事件标识(0=抬起,1=有效) - uint16_t curr_x = hyn_92xxdata->rp_buf.pos_info[index].pos_x; // 当前X坐标 - uint16_t curr_y = hyn_92xxdata->rp_buf.pos_info[index].pos_y; // 当前Y坐标 - - printf("curr_x:%d,curr_y:%d\n",curr_x,curr_y); - if(curr_x >= 466 || curr_y >= 466) - continue; - - hyn_92xxdata->touch_msg.tp_event_info.x_axis[0] = curr_x; - hyn_92xxdata->touch_msg.tp_event_info.y_axis[0] = curr_y; - hyn_92xxdata->touch_msg.tv_usec = (uint32_t)uapi_tcxo_get_ms(); - - if(event == 0) + hyn_92xxdata->rp_buf.report_need |= REPORT_POS; + if (finger_num > 0) { + uint8_t *data = i2c_buf; + //uint8_t *data_ges = i2c_buf + finger_num * 5 + 2; + uint8_t id = data[0] >> 4; + uint8_t switch_ = data[0] & 0x0F; + uint16_t x = ((uint16_t)(data[1]) << 4) | (data[3] >> 4); + uint16_t y = ((uint16_t)(data[2]) << 4) | (data[3] & 0x0F); + uint16_t z = (data[3] & 0x1F) + 0x03; + + // HYN_INFO("finger=%d id=%d x=%d y=%d z=%d switch_=%d",finger_num,id,x,y,z,switch_); + + if (switch_ == 0) { - point_count = 0; hyn_92xxdata->touch_msg.tp_event = MC_TP_RELEASE; - } - else - { - if(point_count == 0) + point_count=0; + }else{ + if (point_count==0) + { hyn_92xxdata->touch_msg.tp_event = MC_TP_PRESS; - else + }else{ hyn_92xxdata->touch_msg.tp_event = MC_TP_MOVE; - + } point_count++; } + + HYN_INFO("finger=%d id=%d x=%d y=%d z=%d switch_=%d point_count:%d",finger_num,id,y,x,z,switch_,point_count); + + hyn_92xxdata->touch_msg.tp_event_info.x_axis[0] = y; + hyn_92xxdata->touch_msg.tp_event_info.y_axis[0] = x; + hyn_92xxdata->touch_msg.tv_usec = (uint32_t)uapi_tcxo_get_ms(); - printf("hyn_92xxdata->touch_msg.tp_event %d\n",hyn_92xxdata->touch_msg.tp_event); + if (id < MAX_POINTS_REPORT) { + hyn_92xxdata->rp_buf.pos_info[index].pos_id = id; + hyn_92xxdata->rp_buf.pos_info[index].event = (switch_ == 0x06 || switch_ == 0x07) ? 1 : 0; + hyn_92xxdata->rp_buf.pos_info[index].pos_x = x; + hyn_92xxdata->rp_buf.pos_info[index].pos_y = y; + hyn_92xxdata->rp_buf.pos_info[index].pres_z = z; + index++; + } + - index++; } - hyn_92xxdata->rp_buf.rep_num = index; - - + for (i = 1; i < finger_num; i++) { + uint8_t *data = i2c_buf+5*i+2; + uint8_t id = data[0] >> 4; + uint8_t switch_ = data[0] & 0x0F; + uint16_t x = ((uint16_t)(data[1]) << 4) | (data[3] >> 4); + uint16_t y = ((uint16_t)(data[2]) << 4) | (data[3] & 0x0F); + uint16_t z = (data[4] & 0x7F); + + if (id < MAX_POINTS_REPORT) { + hyn_92xxdata->rp_buf.pos_info[index].pos_id = id; + hyn_92xxdata->rp_buf.pos_info[index].event = (switch_ == 0x06) ? 1 : 0; + hyn_92xxdata->rp_buf.pos_info[index].pos_x = x; + hyn_92xxdata->rp_buf.pos_info[index].pos_y = y; + hyn_92xxdata->rp_buf.pos_info[index].pres_z = z; + index++; + } + } } - return 0; } - - static uint32_t cst92xx_check_esd(void) { - int ok = FALSE; + int ret = 0; + uint8_t retry=3; + uint8_t buf[6]; + HYN_ENTER(); + while (retry--) + { + ret = hyn_wr_reg(hyn_92xxdata,0xD040,2,buf,0); + ret = hyn_wr_reg(hyn_92xxdata,0xD040,2,buf,6); + if(ret ==0 && hyn_sum16(0xA5,buf,4)==U8TO16(buf[4],buf[5])){ + ret = U8TO32(buf[0],buf[1],buf[2],buf[3]); + break; + } + } + + + return ret; +} +#if 0 +static u32 cst92xx_check_esd(void) +{ + + int16_t ok = FALSE; uint8_t i2c_buf[6], retry; + uint8_t flag = 0; + uint16_t checksum = 0; uint32_t esd_value = 0; + + if ((hyn_92xxdata->work_mode != NOMAL_MODE)&&(hyn_92xxdata->work_mode != GESTURE_MODE)) + { + HYN_ERROR("esd_check work_mode error return"); + return 0; + } retry = 4; - while (retry--){ - hyn_wr_reg(hyn_92xxdata,0xD048,2,i2c_buf,2); - LOS_Udelay(200); - ok = hyn_wr_reg(hyn_92xxdata,0xD048,2,i2c_buf,1); - if (ok == 0 &&((i2c_buf[0]&0xF0) == 0x20 || (i2c_buf[0]&0xF0) == 0xA0)&&(i2c_buf[0]&0x0F)<10){ - break; - } - else{ - ok = -2; + flag = 0; + while (retry--) + { + ok = hyn_wr_reg(hyn_92xxdata,0xD040,2,i2c_buf,6); + if (ok == FALSE){ + msleep(1); + continue; + } + else + { + checksum = i2c_buf[0] + i2c_buf[1] + i2c_buf[2] + i2c_buf[3] + 0xA5; + esd_value = (i2c_buf[0] << 24) + (i2c_buf[1] << 16) + (i2c_buf[2] << 8) + i2c_buf[3]; + flag = 1; + if (((i2c_buf[4] << 8) + i2c_buf[5]) == checksum) + { + flag = 2; + if (((esd_value - hyn_92xxdata->esd_last_value) < 1) && (esd_value > 20)) + { + flag = 3; + } + break; + } + else + { + HYN_INFO("ESD data checksum err:0x%x,0x%x", esd_value, checksum); + continue; + } } } - if(-2==ok){ //esdcheck failed rest system - hyn_92xxdata->esd_fail_cnt = 3; - esd_value = hyn_92xxdata->esd_last_value; - } - else{ - esd_value = hyn_92xxdata->esd_last_value+1; + HYN_INFO("ESD data:%d,0x%04x,0x%04x", flag, esd_value, hyn_92xxdata->esd_last_value); + + if ((flag == 0) || (flag == 3) || (flag == 1)) + { + cst92xx_rst(); + msleep(40); + esd_value = 0; + hyn_92xxdata->esd_last_value = 0; + HYN_INFO("esd_check power reset ic"); + if (hyn_92xxdata->work_mode == GESTURE_MODE) + { + ok = hyn_wr_reg(hyn_92xxdata,0xD104,2,i2c_buf,0); + if (ok == FALSE){ + HYN_ERROR("enter_sleep failed"); + } + } } + + hyn_92xxdata->esd_last_value = esd_value; + return esd_value; } - +#endif static int cst92xx_prox_handle(uint8_t cmd) { @@ -938,7 +1083,7 @@ static int cst92xx_get_dbg_data(uint8_t *buf, uint16_t len) static int cst92xx_get_test_result(uint8_t *buf, uint16_t len) { - int ret = 0; + int ret = 0,timeout; struct tp_info *ic = &hyn_92xxdata->hw_info; uint16_t scap_len = (ic->fw_sensor_txnum + ic->fw_sensor_rxnum)*2; uint16_t mt_len = ic->fw_sensor_rxnum*ic->fw_sensor_txnum*2,i = 0; @@ -950,29 +1095,41 @@ static int cst92xx_get_test_result(uint8_t *buf, uint16_t len) return FAC_GET_DATA_FAIL; } HYN_INFO("---open_higdrv---"); - hyn_wr_reg(hyn_92xxdata,0xD110,2,buf,2); ////test open high - hyn_wait_irq_timeout(hyn_92xxdata,7000); + timeout = 500; + hyn_wr_reg(hyn_92xxdata,0xD110,2,buf,0); ////test open high + while(--timeout){ //wait rise edge + if(hyn_wait_irq_timeout(hyn_92xxdata,100) == 0) break; + LOS_Mdelay(10); + } if(hyn_wr_reg(hyn_92xxdata,0x3000,2,buf,mt_len)){ //open high ret = FAC_GET_DATA_FAIL; HYN_ERROR("read open high failed"); goto selftest_end; } - hyn_wr_reg(hyn_92xxdata,0x000005,3,buf,2); + hyn_wr_reg(hyn_92xxdata,0x000005,3,buf,0); HYN_INFO("---open_low---"); - hyn_wr_reg(hyn_92xxdata,0xD111,2,buf,2); ////test open low - hyn_wait_irq_timeout(hyn_92xxdata,7000); + timeout = 500; + hyn_wr_reg(hyn_92xxdata,0xD111,2,buf,0); ////test open low + while(--timeout){ //wait rise edge + if(hyn_wait_irq_timeout(hyn_92xxdata,100) == 0) break; + LOS_Mdelay(10); + } if(hyn_wr_reg(hyn_92xxdata,0x1000,2,buf + mt_len,mt_len)){ //open low ret = FAC_GET_DATA_FAIL; HYN_ERROR("read open low failed"); goto selftest_end; } - hyn_wr_reg(hyn_92xxdata,0x000005,3,buf,2); + hyn_wr_reg(hyn_92xxdata,0x000005,3,buf,0); //short test HYN_INFO("---short---"); - hyn_wr_reg(hyn_92xxdata,0xD112,2,buf,2); //// short test - hyn_wait_irq_timeout(hyn_92xxdata,7000); + timeout = 500; + hyn_wr_reg(hyn_92xxdata,0xD112,2,buf,0); //// short test + while(--timeout){ //wait rise edge + if(hyn_wait_irq_timeout(hyn_92xxdata,100) == 0) break; + LOS_Mdelay(10); + } if(hyn_wr_reg(hyn_92xxdata,0x5000,2,buf+(mt_len*2),scap_len)){ ret = FAC_GET_DATA_FAIL; HYN_ERROR("read fac short failed"); @@ -997,8 +1154,8 @@ selftest_end: if(0 == fac_test_log_save(FACTEST_LOG_PATH,hyn_92xxdata,(int16_t*)buf,ret,FACTEST_ITEM)){ HYN_INFO("fac_test log save success"); } - cst92xx_resum(); - + cst92xx_reset(); + LOS_Mdelay(40); return ret; } diff --git a/code/sdk/drivers/drivers/driver/touch/cst92xx_touch/cst92xx_touch1.h b/code/sdk/drivers/drivers/driver/touch/cst92xx_touch/cst92xx_touch1.h index f8532813a..4039cf8d4 100644 --- a/code/sdk/drivers/drivers/driver/touch/cst92xx_touch/cst92xx_touch1.h +++ b/code/sdk/drivers/drivers/driver/touch/cst92xx_touch/cst92xx_touch1.h @@ -7,7 +7,8 @@ // #include "hyn_cfg.h" -#define HYN_INFO(fmt, args...) printf("[HYN]"fmt"\n", ##args) +// #define HYN_INFO(fmt, args...) printf("[HYN]"fmt"\n", ##args) +#define HYN_INFO(fmt, args...) #define HYN_INFO2(fmt, args...) if(hyn_data->log_level > 0)printf("[HYN]"fmt"\n", ##args) #define HYN_INFO3(fmt, args...) if(hyn_data->log_level > 1)printf("[HYN]"fmt"\n", ##args) #define HYN_INFO4(fmt, args...) if(hyn_data->log_level > 2)printf("[HYN]"fmt"\n", ##args)