// File: /workspace/github_cpp_makefile_star2_O3/goodix[P]gdix_hid_firmware_update/gtx3/gtx3.cpp
// Function: GTx3Device::SetBasicProperties()
int GTx3Device::SetBasicProperties()
{
	int ret;
	unsigned char fw_info[12] = {0};
	m_firmwareVersionMajor = 20;
	m_firmwareVersionMinor = 20;
	m_sensorID = 0xF;
	unsigned char cfg_ver = 0;
	int retry = 10;
	unsigned char chksum;

	if (!m_deviceOpen) {
		gdix_err("Please open device first\n");
		return -1;
	}
	do {
		ret = Read(0x8050, &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(0x8240, 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]);
	if (!retry)
		return -1;

	/*check fw version*/
	chksum = ChecksumU8(fw_info, sizeof(fw_info));
	if (chksum) {
		gdix_err("fw version check sum error:%d\n", chksum);
		return -2;
	}
	memcpy(m_pid, fw_info, 4);
	m_pid[4] = '\0';
	gdix_dbg("pid:%s\n", m_pid);
	m_sensorID = fw_info[10] & 0x0f;
	gdix_dbg("sensorID:%d\n", m_sensorID);

	m_firmwareVersionMajor = fw_info[5];
	m_firmwareVersionMinor = ((fw_info[6] << 16) | (fw_info[7]) << 8) | cfg_ver;

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

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl $0x0, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
movabsq $0x1400000014, %rax     # imm = 0x1400000014
movq %rax, 0x10(%rdi)
movl $0xf, 0x18(%rdi)
movb $0x0, 0x7(%rsp)
cmpb $0x1, 0x8(%rdi)
jne 0xb9f3
movq %rdi, %rbx
movl $0xa, %ebp
leaq 0x7(%rsp), %r14
leaq 0x15968(%rip), %r13     # 0x21291
leaq 0xb329(%rip), %r12      # 0x16c59
leaq 0x8(%rsp), %r15
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x8050, %esi           # imm = 0x8050
movq %r14, %rdx
movl $0x1, %ecx
callq *0x20(%rax)
movb (%r13), %cl
testl %eax, %eax
js 0xb9bb
testb %cl, %cl
je 0xb97d
movq 0x1565a(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x7(%rsp), %r8d
leaq 0xb395(%rip), %rsi      # 0x16d03
movq %r12, %rdx
movl $0x2d, %ecx
xorl %eax, %eax
callq 0x5180
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x8240, %esi           # imm = 0x8240
movq %r15, %rdx
movl $0xc, %ecx
callq *0x20(%rax)
movb (%r13), %cl
testl %eax, %eax
jns 0xba12
testb $0x1, %cl
je 0xb9e2
movq 0x15611(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xb36f(%rip), %rsi      # 0x16d20
movq %r12, %rdx
movl $0x30, %ecx
jmp 0xb9d8
testb %cl, %cl
je 0xb9e2
movq 0x155f2(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xb2ff(%rip), %rsi      # 0x16ccf
movq %r12, %rdx
movl $0x2a, %ecx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x5180
decl %ebp
jne 0xb935
movb (%r13), %cl
movb $0x1, %r14b
jmp 0xba15
leaq 0x15897(%rip), %rax     # 0x21291
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpb $0x1, (%rax)
jne 0xbc03
callq 0x5841
jmp 0xbc03
xorl %r14d, %r14d
testb $0x1, %cl
je 0xba42
movq 0x15597(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xb325(%rip), %rsi      # 0x16d50
leaq 0xb227(%rip), %rdx      # 0x16c59
movl $0x34, %ecx
xorl %eax, %eax
callq 0x5180
movb (%r13), %cl
testb $0x1, %cl
je 0xba9b
movq 0x1556a(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x8(%rsp), %r8d
movzbl 0x9(%rsp), %r9d
movzbl 0xa(%rsp), %r10d
movzbl 0xb(%rsp), %r11d
movzbl 0xc(%rsp), %r15d
subq $0x8, %rsp
leaq 0xb2f6(%rip), %rsi      # 0x16d70
leaq 0xb1d8(%rip), %rdx      # 0x16c59
movl $0x36, %ecx
xorl %eax, %eax
pushq %r15
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
movb (%r13), %cl
testb $0x1, %cl
je 0xbaf4
movq 0x15511(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0xd(%rsp), %r8d
movzbl 0xe(%rsp), %r9d
movzbl 0xf(%rsp), %r10d
movzbl 0x10(%rsp), %r11d
movzbl 0x11(%rsp), %r15d
movzbl 0x12(%rsp), %r12d
leaq 0xb2d0(%rip), %rsi      # 0x16da5
leaq 0xb17d(%rip), %rdx      # 0x16c59
movl $0x38, %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 0xbc03
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
movl $0xc, %edx
callq 0xdb8a
testb %al, %al
je 0xbb35
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
cmpb $0x1, (%r13)
jne 0xbc03
movzbl %al, %edi
callq 0x5863
jmp 0xbc03
movl 0x8(%rsp), %eax
movl %eax, 0x1c(%rbx)
movb $0x0, 0x20(%rbx)
movb (%r13), %al
cmpb $0x1, %al
jne 0xbb74
leaq 0x1c(%rbx), %r8
movq 0x15465(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xb2bc(%rip), %rsi      # 0x16e19
leaq 0xb0f5(%rip), %rdx      # 0x16c59
movl $0x44, %ecx
xorl %eax, %eax
callq 0x5180
movb (%r13), %al
movzbl 0x12(%rsp), %r8d
andl $0xf, %r8d
movl %r8d, 0x18(%rbx)
testb $0x1, %al
je 0xbbae
movq 0x1542b(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xb29b(%rip), %rsi      # 0x16e32
leaq 0xb0bb(%rip), %rdx      # 0x16c59
movl $0x46, %ecx
xorl %eax, %eax
callq 0x5180
movb (%r13), %al
movzbl 0xd(%rsp), %r8d
movl %r8d, 0x10(%rbx)
movzbl 0xe(%rsp), %ecx
shll $0x10, %ecx
movzbl 0xf(%rsp), %edx
shll $0x8, %edx
orl %ecx, %edx
movzbl 0x7(%rsp), %r9d
orl %edx, %r9d
movl %r9d, 0x14(%rbx)
xorl %ebp, %ebp
testb $0x1, %al
je 0xbc03
movq 0x153d4(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xb262(%rip), %rsi      # 0x16e50
leaq 0xb064(%rip), %rdx      # 0x16c59
xorl %ebp, %ebp
movl $0x4c, %ecx
xorl %eax, %eax
callq 0x5180
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq