// File: /workspace/github_cpp_makefile_star2_O3/goodix[P]gdix_hid_firmware_update/gtx9/gtx9.cpp
// Function: GTx9Device::SetBasicProperties()
int GTx9Device::SetBasicProperties()
{
	uint8_t tempBuf[14] = {0};
	int ret;
	// uint8_t main_ver;
	uint8_t vice_ver;
	uint8_t inter_ver;
	uint8_t cfg_ver;

	/* read pid/vid/sensorid */
	ret = Read(0x1001E, tempBuf, 14);
	if (ret < 0) {
		gdix_err("Failed read PID/VID\n");
		return ret;
	}
	gdix_dbg_array(tempBuf, 14);
	memcpy(m_pid, tempBuf, 8);
	memcpy(m_vid, tempBuf + 8, 4);
	m_sensorID = tempBuf[13];

	// main_ver = tempBuf[9];
	vice_ver = tempBuf[10];
	inter_ver = tempBuf[11];

	/* read config id/version */
	ret = Read(0x10076, tempBuf, 5);
	if (ret < 0) {
		gdix_err("Failed read config id/version\n");
		return ret;
	}
	m_configID = *((uint32_t *)tempBuf);
	cfg_ver = tempBuf[4];

	// m_firmwareVersionMajor = main_ver;
	m_firmwareVersionMajor = 0;
	m_firmwareVersionMinor = (vice_ver << 16) | (inter_ver << 8) | cfg_ver;

	gdix_info("PID:%s\n", m_pid);
	gdix_info("VID:%02x %02x %02x %02x\n", m_vid[0], m_vid[1], m_vid[2],
			  m_vid[3]);
	gdix_info("sensorID:%d\n", m_sensorID);
	gdix_info("configID:%08x\n", m_configID);
	gdix_info("configVer:%02x\n", cfg_ver);
	gdix_info("version:%d.%d\n", m_firmwareVersionMajor,
			  m_firmwareVersionMinor);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
xorl %eax, %eax
movq %rsp, %rdx
movq %rax, 0x6(%rdx)
movq %rax, (%rdx)
movq (%rdi), %rax
movl $0x1001e, %esi          # imm = 0x1001E
movl $0xe, %ecx
callq *0x20(%rax)
testl %eax, %eax
js 0x10c6a
movq %rsp, %rdx
movq (%rdx), %rax
movq %rax, 0x10(%rbx)
movl 0x8(%rdx), %r14d
movl %r14d, 0x18(%rbx)
movb 0xd(%rdx), %al
movb %al, 0x1c(%rbx)
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x10076, %esi          # imm = 0x10076
movl $0x5, %ecx
callq *0x20(%rax)
testl %eax, %eax
js 0x10c7f
movl (%rsp), %eax
movl %eax, 0x20(%rbx)
movzbl 0x4(%rsp), %ebp
movl $0x0, 0x24(%rbx)
movl %r14d, %eax
andl $0xff0000, %eax         # imm = 0xFF0000
shrl $0x10, %r14d
andl $0xff00, %r14d          # imm = 0xFF00
orl %eax, %r14d
orl %ebp, %r14d
movl %r14d, 0x28(%rbx)
leaq 0x10763(%rip), %r14     # 0x21291
movb (%r14), %al
cmpb $0x1, %al
jne 0x10b60
leaq 0x10(%rbx), %r8
movq 0x10478(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0x825e(%rip), %rsi      # 0x18da8
leaq 0x6108(%rip), %rdx      # 0x16c59
movl $0x18e, %ecx            # imm = 0x18E
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
testb $0x1, %al
je 0x10ba7
movq 0x1044d(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x18(%rbx), %r8d
movzbl 0x19(%rbx), %r9d
movzbl 0x1a(%rbx), %r10d
movzbl 0x1b(%rbx), %r11d
leaq 0x8238(%rip), %rsi      # 0x18dc1
leaq 0x60c9(%rip), %rdx      # 0x16c59
movl $0x190, %ecx            # imm = 0x190
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x5180
addq $0x10, %rsp
movb (%r14), %al
testb $0x1, %al
je 0x10bd7
movq 0x10406(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x1c(%rbx), %r8d
leaq 0x822a(%rip), %rsi      # 0x18deb
leaq 0x6091(%rip), %rdx      # 0x16c59
movl $0x191, %ecx            # imm = 0x191
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
testb $0x1, %al
je 0x10c06
movq 0x103d6(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movl 0x20(%rbx), %r8d
leaq 0x8219(%rip), %rsi      # 0x18e09
leaq 0x6062(%rip), %rdx      # 0x16c59
movl $0x192, %ecx            # imm = 0x192
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
testb $0x1, %al
je 0x10c34
movq 0x103a7(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0x820e(%rip), %rsi      # 0x18e29
leaq 0x6037(%rip), %rdx      # 0x16c59
movl $0x193, %ecx            # imm = 0x193
movl %ebp, %r8d
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
xorl %ebp, %ebp
testb $0x1, %al
je 0x10c8d
movq 0x10377(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movl 0x24(%rbx), %r8d
movl 0x28(%rbx), %r9d
leaq 0x81f7(%rip), %rsi      # 0x18e4a
leaq 0x5fff(%rip), %rdx      # 0x16c59
xorl %ebp, %ebp
movl $0x195, %ecx            # imm = 0x195
xorl %eax, %eax
callq 0x5180
jmp 0x10c8d
movl %eax, %ebp
leaq 0x1061e(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
jne 0x10c8d
callq 0x60a4
jmp 0x10c8d
movl %eax, %ebp
leaq 0x10609(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
je 0x10c98
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
callq 0x607a
jmp 0x10c8d
nop