// File: /workspace/github_cpp_makefile_star2_O1/goodix[P]gdix_hid_firmware_update/gt7868q/gt7868q.cpp
// Function: GT7868QDevice::SetBasicProperties()
int GT7868QDevice::SetBasicProperties()
{
	int ret;
	unsigned char fw_info[32] = {0};
	m_firmwareVersionMajor = 20;
	m_firmwareVersionMinor = 20;
	m_sensorID = 0xF;
	unsigned char cfg_ver = 0;
	int retry = 10;
	unsigned short chksum;
	unsigned char buf_dis_report_coor[] = {0x33, 0x00, 0x00, 0x00, 0x33};
	unsigned char buf_en_report_coor[] = {0x34, 0x00, 0x00, 0x00, 0x34};

	if (!m_deviceOpen) {
		gdix_err("Please open device first\n");
		return -1;
	}
	/*dis report coor*/
	gdix_info("disable report coor in read version\n");
	retry = 3;
	do {
		ret = Write(CMD_ADDR, buf_dis_report_coor, sizeof(buf_dis_report_coor));
		if (ret < 0) {
			gdix_err("Failed disable report coor\n");
		}
	} while (--retry);
	// read cfg ver
	retry = 10;
	do {
		ret = Read(CFG_START_ADDR, &cfg_ver, 1);
		if (ret < 0) {
			gdix_dbg("Failed read cfg VERSION, retry=%d\n", retry);
			continue;
		}
		gdix_dbg("cfg ver:%d\n", cfg_ver);
		ret = Read(VER_ADDR, fw_info, sizeof(fw_info));
		if (ret < 0)
			gdix_dbg("Failed read VERSION, retry=%d\n", retry);
		else
			break;
	} while (--retry);
	gdix_dbg("Fw_info array\n");
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[0], fw_info[1],
			 fw_info[2], fw_info[3], fw_info[4]);
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[5],
			 fw_info[6], fw_info[7], fw_info[8], fw_info[9], fw_info[10]);
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[11],
			 fw_info[12], fw_info[13], fw_info[14], fw_info[15], fw_info[16]);
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[17], fw_info[18],
			 fw_info[19], fw_info[20], fw_info[21]);
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[22],
			 fw_info[23], fw_info[24], fw_info[25], fw_info[26], fw_info[27]);
	if (!retry) {
		ret = -1;
		goto ver_end;
	}

	/*check fw version*/
	chksum = ChecksumU8_ys(fw_info, sizeof(fw_info));
	if (chksum) {
		gdix_err("fw version check sum error:0x%x\n", chksum);
		ret = -2;
		goto ver_end;
	}

	memcpy(m_pid, &fw_info[14], 4);
	if (!memcmp(m_pid, "7869", 4)) {
		memcpy(m_pid, "7868Q", 5);
		m_pid[5] = '\0';
	} else {
		m_pid[4] = '\0';
	}
	gdix_dbg("pid:%s\n", m_pid);
	m_sensorID = fw_info[27] & 0xff;
	gdix_dbg("sensorID:%d\n", m_sensorID);

	m_firmwareVersionMajor = fw_info[23];
	m_firmwareVersionMinor =
		((fw_info[24] << 16) | (fw_info[25]) << 8) | cfg_ver;

	gdix_dbg("version:0x%x,0x%x\n", m_firmwareVersionMajor,
			 m_firmwareVersionMinor);

	ret = 0;
ver_end:
	/*en report coor*/
	gdix_info("enable report coor\n");
	if (Write(CMD_ADDR, buf_en_report_coor, sizeof(buf_en_report_coor)) < 0) {
		gdix_err("Failed enable report coor in read version\n");
	}
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movabsq $0x1400000014, %rax     # imm = 0x1400000014
movq %rax, 0x10(%rdi)
movl $0xf, 0x18(%rdi)
movb $0x0, 0xf(%rsp)
movb $0x33, 0x44(%rsp)
movl $0x33, 0x40(%rsp)
movb $0x34, 0x3c(%rsp)
movl $0x34, 0x38(%rsp)
leaq 0x189d3(%rip), %r13     # 0x21291
movb (%r13), %al
cmpb $0x0, 0x8(%rdi)
je 0x892b
movq %rdi, %rbx
testb %al, %al
je 0x88f3
movq 0x186e2(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe3ed(%rip), %rsi      # 0x16ccd
leaq 0xe3d3(%rip), %rdx      # 0x16cba
movl $0x39, %ecx
xorl %eax, %eax
callq 0x5180
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
leaq 0x40(%rsp), %r14
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x4160, %esi           # imm = 0x4160
movq %r14, %rdx
movl $0x5, %ecx
callq *0x30(%rax)
testl %eax, %eax
jns 0x891e
cmpb $0x1, (%r13)
je 0x8924
incl %ebp
jne 0x88fd
jmp 0x8942
callq 0x5314
jmp 0x891e
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testb %al, %al
je 0x8d69
callq 0x52f2
jmp 0x8d69
movl $0xa, %ebp
leaq 0xf(%rsp), %r14
leaq 0xe367(%rip), %r12      # 0x16cba
leaq 0x10(%rsp), %r15
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x96f8, %esi           # imm = 0x96F8
movq %r14, %rdx
movl $0x1, %ecx
callq *0x20(%rax)
movb (%r13), %cl
testl %eax, %eax
js 0x89dc
testb %cl, %cl
je 0x89a0
movq 0x18637(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0xf(%rsp), %r8d
leaq 0xe3d3(%rip), %rsi      # 0x16d64
movq %r12, %rdx
movl $0x49, %ecx
xorl %eax, %eax
callq 0x5180
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x4014, %esi           # imm = 0x4014
movq %r15, %rdx
movl $0x20, %ecx
callq *0x20(%rax)
testl %eax, %eax
jns 0x8a10
cmpb $0x1, (%r13)
jne 0x8a03
movq 0x185f0(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe3af(%rip), %rsi      # 0x16d81
movq %r12, %rdx
movl $0x4c, %ecx
jmp 0x89f9
testb %cl, %cl
je 0x8a03
movq 0x185d1(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe33f(%rip), %rsi      # 0x16d30
movq %r12, %rdx
movl $0x46, %ecx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x5180
decl %ebp
jne 0x8958
movb $0x1, %r14b
jmp 0x8a13
xorl %r14d, %r14d
cmpb $0x1, (%r13)
jne 0x8a3e
movq 0x18597(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe386(%rip), %rsi      # 0x16db1
leaq 0xe288(%rip), %rdx      # 0x16cba
movl $0x50, %ecx
xorl %eax, %eax
callq 0x5180
cmpb $0x1, (%r13)
jne 0x8a95
movq 0x1856c(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x10(%rsp), %r8d
movzbl 0x11(%rsp), %r9d
movzbl 0x12(%rsp), %r10d
movzbl 0x13(%rsp), %r11d
movzbl 0x14(%rsp), %r15d
subq $0x8, %rsp
leaq 0xe359(%rip), %rsi      # 0x16dd1
leaq 0xe23b(%rip), %rdx      # 0x16cba
movl $0x52, %ecx
xorl %eax, %eax
pushq %r15
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
cmpb $0x1, (%r13)
jne 0x8af0
movq 0x18515(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x15(%rsp), %r8d
movzbl 0x16(%rsp), %r9d
movzbl 0x17(%rsp), %r10d
movzbl 0x18(%rsp), %r11d
movzbl 0x19(%rsp), %r15d
movzbl 0x1a(%rsp), %r12d
leaq 0xe335(%rip), %rsi      # 0x16e06
leaq 0xe1e2(%rip), %rdx      # 0x16cba
movl $0x54, %ecx
xorl %eax, %eax
pushq %r12
pushq %r15
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
cmpb $0x1, (%r13)
jne 0x8b4b
movq 0x184ba(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x1b(%rsp), %r8d
movzbl 0x1c(%rsp), %r9d
movzbl 0x1d(%rsp), %r10d
movzbl 0x1e(%rsp), %r11d
movzbl 0x1f(%rsp), %r15d
movzbl 0x20(%rsp), %r12d
leaq 0xe2da(%rip), %rsi      # 0x16e06
leaq 0xe187(%rip), %rdx      # 0x16cba
movl $0x56, %ecx
xorl %eax, %eax
pushq %r12
pushq %r15
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
cmpb $0x1, (%r13)
jne 0x8ba2
movq 0x1845f(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x21(%rsp), %r8d
movzbl 0x22(%rsp), %r9d
movzbl 0x23(%rsp), %r10d
movzbl 0x24(%rsp), %r11d
movzbl 0x25(%rsp), %r15d
subq $0x8, %rsp
leaq 0xe24c(%rip), %rsi      # 0x16dd1
leaq 0xe12e(%rip), %rdx      # 0x16cba
movl $0x58, %ecx
xorl %eax, %eax
pushq %r15
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
cmpb $0x1, (%r13)
jne 0x8bfd
movq 0x18408(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x26(%rsp), %r8d
movzbl 0x27(%rsp), %r9d
movzbl 0x28(%rsp), %r10d
movzbl 0x29(%rsp), %r11d
movzbl 0x2a(%rsp), %r15d
movzbl 0x2b(%rsp), %r12d
leaq 0xe228(%rip), %rsi      # 0x16e06
leaq 0xe0d5(%rip), %rdx      # 0x16cba
movl $0x5a, %ecx
xorl %eax, %eax
pushq %r12
pushq %r15
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testb %r14b, %r14b
jne 0x8d1b
leaq 0x10(%rsp), %rsi
movl $0x20, %edx
callq 0x87d4
testw %ax, %ax
je 0x8c3b
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
cmpb $0x1, (%r13)
jne 0x8d1b
movl %eax, %edi
callq 0x533c
jmp 0x8d1b
leaq 0x1c(%rbx), %r8
movl 0x1e(%rsp), %eax
movl %eax, 0x1c(%rbx)
cmpl $0x39363837, %eax       # imm = 0x39363837
jne 0x8c5f
movb $0x51, 0x4(%r8)
movl $0x38363837, (%r8)      # imm = 0x38363837
movb $0x0, 0x21(%rbx)
jmp 0x8c63
movb $0x0, 0x20(%rbx)
cmpb $0x1, (%r13)
jne 0x8c8e
movq 0x18347(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe1ff(%rip), %rsi      # 0x16e7a
leaq 0xe038(%rip), %rdx      # 0x16cba
movl $0x6f, %ecx
xorl %eax, %eax
callq 0x5180
movzbl 0x2b(%rsp), %r8d
movl %r8d, 0x18(%rbx)
cmpb $0x1, (%r13)
jne 0x8cc3
movq 0x18312(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe1e3(%rip), %rsi      # 0x16e93
leaq 0xe003(%rip), %rdx      # 0x16cba
movl $0x71, %ecx
xorl %eax, %eax
callq 0x5180
movzbl 0x27(%rsp), %r8d
movl %r8d, 0x10(%rbx)
movzbl 0x28(%rsp), %eax
shll $0x10, %eax
movzbl 0x29(%rsp), %ecx
shll $0x8, %ecx
orl %eax, %ecx
movzbl 0xf(%rsp), %r9d
orl %ecx, %r9d
movl %r9d, 0x14(%rbx)
xorl %ebp, %ebp
cmpb $0x1, (%r13)
jne 0x8d1b
movq 0x182bc(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe1ab(%rip), %rsi      # 0x16eb1
leaq 0xdfad(%rip), %rdx      # 0x16cba
xorl %ebp, %ebp
movl $0x78, %ecx
xorl %eax, %eax
callq 0x5180
cmpb $0x1, (%r13)
jne 0x8d46
movq 0x1828f(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe1a2(%rip), %rsi      # 0x16ed5
leaq 0xdf80(%rip), %rdx      # 0x16cba
movl $0x7d, %ecx
xorl %eax, %eax
callq 0x5180
movq (%rbx), %rax
leaq 0x38(%rsp), %rdx
movq %rbx, %rdi
movl $0x4160, %esi           # imm = 0x4160
movl $0x5, %ecx
callq *0x30(%rax)
testl %eax, %eax
jns 0x8d69
cmpb $0x1, (%r13)
je 0x8d7a
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x536b
jmp 0x8d69
nop