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

	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;
		}

		ret = Read(0x8140, fw_info, sizeof(fw_info));
		if (ret < 0)
			gdix_dbg("Failed read VERSION, retry=%d\n", retry);
		else
			break;
	} while (--retry);

	if (!retry)
		return -1;

	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);

	if (!memcmp(m_pid, "7288", 4)) {
		m_firmwareVersionMajor = fw_info[5];
		m_firmwareVersionMinor = ((fw_info[6] << 16) | (0x00) << 8) | cfg_ver;
	} else {
		m_firmwareVersionMajor = fw_info[4];
		m_firmwareVersionMinor =
			((fw_info[5] << 16) | (fw_info[6]) << 8) | cfg_ver;
	}

	gdix_dbg("cfg version:%d\n", 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 $0x2, 0x18(%rdi)
movb $0x0, 0x7(%rsp)
cmpb $0x1, 0x8(%rdi)
jne 0xa654
movq %rdi, %rbx
movl $0xa, %ebp
leaq 0x7(%rsp), %r14
leaq 0x16cd6(%rip), %r15     # 0x21291
leaq 0xc697(%rip), %r12      # 0x16c59
leaq 0x8(%rsp), %r13
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x8050, %esi           # imm = 0x8050
movq %r14, %rdx
movl $0x1, %ecx
callq *0x20(%rax)
testl %eax, %eax
js 0xa61c
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x8140, %esi           # imm = 0x8140
movq %r13, %rdx
movl $0xc, %ecx
callq *0x20(%rax)
testl %eax, %eax
jns 0xa67a
cmpb $0x1, (%r15)
jne 0xa645
movq 0x169b0(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xc70e(%rip), %rsi      # 0x16d20
movq %r12, %rdx
movl $0x3e, %ecx
jmp 0xa63b
cmpb $0x1, (%r15)
jne 0xa645
movq 0x1698f(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xc69c(%rip), %rsi      # 0x16ccf
movq %r12, %rdx
movl $0x38, %ecx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x5180
decl %ebp
jne 0xa5c7
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0xa669
leaq 0x16c36(%rip), %rax     # 0x21291
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpb $0x1, (%rax)
je 0xa79a
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c(%rbx), %r14
movl 0x8(%rsp), %eax
movl %eax, 0x1c(%rbx)
movb $0x0, 0x20(%rbx)
movb (%r15), %al
cmpb $0x1, %al
jne 0xa6ba
movq 0x16921(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xc778(%rip), %rsi      # 0x16e19
leaq 0xc5b1(%rip), %rdx      # 0x16c59
movl $0x48, %ecx
movq %r14, %r8
xorl %eax, %eax
callq 0x5180
movb (%r15), %al
movzbl 0x12(%rsp), %r8d
andl $0xf, %r8d
movl %r8d, 0x18(%rbx)
testb $0x1, %al
je 0xa6f0
movq 0x168e5(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xc755(%rip), %rsi      # 0x16e32
leaq 0xc575(%rip), %rdx      # 0x16c59
movl $0x4a, %ecx
xorl %eax, %eax
callq 0x5180
cmpl $0x38383237, (%r14)     # imm = 0x38383237
jne 0xa707
movb 0xd(%rsp), %al
movzbl 0xe(%rsp), %ecx
shll $0x10, %ecx
jmp 0xa71d
movb 0xc(%rsp), %al
movzbl 0xd(%rsp), %edx
shll $0x10, %edx
movzbl 0xe(%rsp), %ecx
shll $0x8, %ecx
orl %edx, %ecx
movzbl 0x7(%rsp), %r8d
orl %r8d, %ecx
movzbl %al, %eax
movl %eax, 0x10(%rbx)
movl %ecx, 0x14(%rbx)
movb (%r15), %al
cmpb $0x1, %al
jne 0xa75d
movq 0x1687b(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xd3d5(%rip), %rsi      # 0x17b1c
leaq 0xc50b(%rip), %rdx      # 0x16c59
movl $0x55, %ecx
xorl %eax, %eax
callq 0x5180
movb (%r15), %al
xorl %ebp, %ebp
testb $0x1, %al
je 0xa669
movq 0x1684a(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movl 0x10(%rbx), %r8d
movl 0x14(%rbx), %r9d
leaq 0xc6d0(%rip), %rsi      # 0x16e50
leaq 0xc4d2(%rip), %rdx      # 0x16c59
xorl %ebp, %ebp
movl $0x57, %ecx
xorl %eax, %eax
callq 0x5180
jmp 0xa669
callq 0x5689
jmp 0xa669