// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0x58, %rsp
movq %rdi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x50a0
movq -0x40(%rbp), %rax
movl $0x14, 0x10(%rax)
movl $0x14, 0x14(%rax)
movl $0xf, 0x18(%rax)
movb $0x0, -0x29(%rbp)
movl $0xa, -0x30(%rbp)
testb $0x1, 0x8(%rax)
jne 0xc7df
jmp 0xc7a1
leaq 0x19af1(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xc7d1
movq 0x19824(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0x104c1(%rip), %rsi     # 0x1cc7f
leaq 0x104e5(%rip), %rdx     # 0x1ccaa
movl $0x24, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xc7d3
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xcb42
jmp 0xc7e1
movq -0x40(%rbp), %rdi
movq (%rdi), %rax
movl $0x8050, %esi           # imm = 0x8050
leaq -0x29(%rbp), %rdx
movl $0x1, %ecx
callq *0x20(%rax)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0xc83f
jmp 0xc804
leaq 0x19a8e(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xc838
movq 0x197a1(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movl -0x30(%rbp), %r8d
leaq 0x104fb(%rip), %rsi     # 0x1cd20
leaq 0x1047e(%rip), %rdx     # 0x1ccaa
movl $0x2a, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xc83a
jmp 0xc8d7
jmp 0xc841
leaq 0x19a51(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xc876
movq 0x19764(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x29(%rbp), %r8d
leaq 0x104f1(%rip), %rsi     # 0x1cd54
leaq 0x10440(%rip), %rdx     # 0x1ccaa
movl $0x2d, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xc878
movq -0x40(%rbp), %rdi
leaq -0x28(%rbp), %rdx
movq (%rdi), %rax
movl $0x8240, %esi           # imm = 0x8240
movl $0xc, %ecx
callq *0x20(%rax)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0xc8d3
jmp 0xc89b
leaq 0x199f7(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xc8cf
movq 0x1970a(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movl -0x30(%rbp), %r8d
leaq 0x104b5(%rip), %rsi     # 0x1cd71
leaq 0x103e7(%rip), %rdx     # 0x1ccaa
movl $0x30, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xc8d1
jmp 0xc8d5
jmp 0xc8e9
jmp 0xc8d7
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, %eax
jne 0xc7e1
jmp 0xc8eb
leaq 0x199a7(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xc91b
movq 0x196ba(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
leaq 0x10499(%rip), %rsi     # 0x1cda1
leaq 0x1039b(%rip), %rdx     # 0x1ccaa
movl $0x34, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xc91d
jmp 0xc91f
leaq 0x19973(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xc974
movq 0x19686(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x28(%rbp), %r8d
movzbl -0x27(%rbp), %r9d
movzbl -0x26(%rbp), %r11d
movzbl -0x25(%rbp), %r10d
movzbl -0x24(%rbp), %eax
leaq 0x1046d(%rip), %rsi     # 0x1cdc1
leaq 0x1034f(%rip), %rdx     # 0x1ccaa
movl $0x36, %ecx
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x5190
jmp 0xc976
jmp 0xc978
leaq 0x1991a(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xc9d5
movq 0x1962d(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x23(%rbp), %r8d
movzbl -0x22(%rbp), %r9d
movzbl -0x21(%rbp), %ebx
movzbl -0x20(%rbp), %r11d
movzbl -0x1f(%rbp), %r10d
movzbl -0x1e(%rbp), %eax
leaq 0x10445(%rip), %rsi     # 0x1cdf6
leaq 0x102f2(%rip), %rdx     # 0x1ccaa
movl $0x38, %ecx
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x5190
jmp 0xc9d7
cmpl $0x0, -0x30(%rbp)
jne 0xc9e9
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xcb42
movq -0x40(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0xc, %edx
callq 0xf780
movb %al, -0x31(%rbp)
cmpb $0x0, -0x31(%rbp)
je 0xca49
jmp 0xca06
leaq 0x1988c(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xca3b
movq 0x195bf(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
movzbl -0x31(%rbp), %r8d
leaq 0x11574(%rip), %rsi     # 0x1df9c
leaq 0x1027b(%rip), %rdx     # 0x1ccaa
movl $0x3f, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xca3d
movl $0xfffffffe, -0xc(%rbp) # imm = 0xFFFFFFFE
jmp 0xcb42
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, 0x1c(%rax)
movb $0x0, 0x20(%rax)
leaq 0x1983b(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xca8f
movq -0x40(%rbp), %r8
movq 0x1954a(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
addq $0x1c, %r8
leaq 0x103f3(%rip), %rsi     # 0x1ce6f
leaq 0x10227(%rip), %rdx     # 0x1ccaa
movl $0x44, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xca91
movq -0x40(%rbp), %rax
movzbl -0x1e(%rbp), %ecx
andl $0xf, %ecx
movl %ecx, 0x18(%rax)
leaq 0x197f3(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xcad7
movq -0x40(%rbp), %rax
movq 0x19502(%rip), %rcx     # 0x25fb8
movq (%rcx), %rdi
movl 0x18(%rax), %r8d
leaq 0x103c4(%rip), %rsi     # 0x1ce88
leaq 0x101df(%rip), %rdx     # 0x1ccaa
movl $0x46, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xcad9
movq -0x40(%rbp), %rax
movzbl -0x23(%rbp), %ecx
movl %ecx, 0x10(%rax)
movzbl -0x22(%rbp), %ecx
shll $0x10, %ecx
movzbl -0x21(%rbp), %edx
shll $0x8, %edx
orl %edx, %ecx
movzbl -0x29(%rbp), %edx
orl %edx, %ecx
movl %ecx, 0x14(%rax)
leaq 0x19795(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xcb39
movq -0x40(%rbp), %rax
movq 0x194a4(%rip), %rcx     # 0x25fb8
movq (%rcx), %rdi
movl 0x10(%rax), %r8d
movl 0x14(%rax), %r9d
leaq 0x10380(%rip), %rsi     # 0x1cea6
leaq 0x1017d(%rip), %rdx     # 0x1ccaa
movl $0x4c, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xcb3b
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x58, %rsp
popq %rbx
popq %rbp
retq
nopl (%rax)