// File: /workspace/github_cpp_makefile_star2_O3/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 0x18b33(%rip), %r13     # 0x21291
movb (%r13), %al
cmpb $0x0, 0x8(%rdi)
je 0x87cb
movq %rdi, %rbx
testb %al, %al
je 0x8793
movq 0x18842(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe4ec(%rip), %rsi      # 0x16c6c
leaq 0xe4d2(%rip), %rdx      # 0x16c59
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 0x87be
cmpb $0x1, (%r13)
je 0x87c4
incl %ebp
jne 0x879d
jmp 0x87e2
callq 0x5314
jmp 0x87be
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testb %al, %al
je 0x8c1a
callq 0x52f2
jmp 0x8c1a
movl $0xa, %ebp
leaq 0xf(%rsp), %r14
leaq 0xe466(%rip), %r12      # 0x16c59
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 0x887e
testb %cl, %cl
je 0x8840
movq 0x18797(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0xf(%rsp), %r8d
leaq 0xe4d2(%rip), %rsi      # 0x16d03
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)
movb (%r13), %cl
testl %eax, %eax
jns 0x88b6
testb $0x1, %cl
je 0x88a5
movq 0x1874e(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe4ac(%rip), %rsi      # 0x16d20
movq %r12, %rdx
movl $0x4c, %ecx
jmp 0x889b
testb %cl, %cl
je 0x88a5
movq 0x1872f(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe43c(%rip), %rsi      # 0x16ccf
movq %r12, %rdx
movl $0x46, %ecx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x5180
decl %ebp
jne 0x87f8
movb (%r13), %cl
movb $0x1, %r14b
jmp 0x88b9
xorl %r14d, %r14d
testb $0x1, %cl
je 0x88e6
movq 0x186f3(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe481(%rip), %rsi      # 0x16d50
leaq 0xe383(%rip), %rdx      # 0x16c59
movl $0x50, %ecx
xorl %eax, %eax
callq 0x5180
movb (%r13), %cl
testb $0x1, %cl
je 0x893f
movq 0x186c6(%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 0xe452(%rip), %rsi      # 0x16d70
leaq 0xe334(%rip), %rdx      # 0x16c59
movl $0x52, %ecx
xorl %eax, %eax
pushq %r15
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
movb (%r13), %cl
testb $0x1, %cl
je 0x899c
movq 0x1866d(%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 0xe42c(%rip), %rsi      # 0x16da5
leaq 0xe2d9(%rip), %rdx      # 0x16c59
movl $0x54, %ecx
xorl %eax, %eax
pushq %r12
pushq %r15
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
movb (%r13), %cl
testb $0x1, %cl
je 0x89f9
movq 0x18610(%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 0xe3cf(%rip), %rsi      # 0x16da5
leaq 0xe27c(%rip), %rdx      # 0x16c59
movl $0x56, %ecx
xorl %eax, %eax
pushq %r12
pushq %r15
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
movb (%r13), %cl
testb $0x1, %cl
je 0x8a52
movq 0x185b3(%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 0xe33f(%rip), %rsi      # 0x16d70
leaq 0xe221(%rip), %rdx      # 0x16c59
movl $0x58, %ecx
xorl %eax, %eax
pushq %r15
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
movb (%r13), %cl
testb $0x1, %cl
je 0x8aab
movq 0x1855a(%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 0xe319(%rip), %rsi      # 0x16da5
leaq 0xe1c6(%rip), %rdx      # 0x16c59
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 0x8bcc
leaq 0x10(%rsp), %rsi
movl $0x20, %edx
callq 0x866c
testw %ax, %ax
je 0x8ae9
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
cmpb $0x1, (%r13)
jne 0x8bcc
movl %eax, %edi
callq 0x533c
jmp 0x8bcc
leaq 0x1c(%rbx), %r8
movl 0x1e(%rsp), %eax
movl %eax, 0x1c(%rbx)
cmpl $0x39363837, %eax       # imm = 0x39363837
jne 0x8b0d
movb $0x51, 0x4(%r8)
movl $0x38363837, (%r8)      # imm = 0x38363837
movb $0x0, 0x21(%rbx)
jmp 0x8b11
movb $0x0, 0x20(%rbx)
movb (%r13), %al
cmpb $0x1, %al
jne 0x8b41
movq 0x18498(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe2ef(%rip), %rsi      # 0x16e19
leaq 0xe128(%rip), %rdx      # 0x16c59
movl $0x6f, %ecx
xorl %eax, %eax
callq 0x5180
movb (%r13), %al
movzbl 0x2b(%rsp), %r8d
movl %r8d, 0x18(%rbx)
testb $0x1, %al
je 0x8b77
movq 0x18462(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe2d2(%rip), %rsi      # 0x16e32
leaq 0xe0f2(%rip), %rdx      # 0x16c59
movl $0x71, %ecx
xorl %eax, %eax
callq 0x5180
movb (%r13), %al
movzbl 0x27(%rsp), %r8d
movl %r8d, 0x10(%rbx)
movzbl 0x28(%rsp), %ecx
shll $0x10, %ecx
movzbl 0x29(%rsp), %edx
shll $0x8, %edx
orl %ecx, %edx
movzbl 0xf(%rsp), %r9d
orl %edx, %r9d
movl %r9d, 0x14(%rbx)
xorl %ebp, %ebp
testb $0x1, %al
je 0x8bcc
movq 0x1840b(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe299(%rip), %rsi      # 0x16e50
leaq 0xe09b(%rip), %rdx      # 0x16c59
xorl %ebp, %ebp
movl $0x78, %ecx
xorl %eax, %eax
callq 0x5180
cmpb $0x1, (%r13)
jne 0x8bf7
movq 0x183de(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe290(%rip), %rsi      # 0x16e74
leaq 0xe06e(%rip), %rdx      # 0x16c59
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 0x8c1a
cmpb $0x1, (%r13)
je 0x8c2b
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x536b
jmp 0x8c1a