// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
xorl %eax, %eax
leaq 0x8(%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 0x10db0
leaq 0x8(%rsp), %rdx
movq (%rdx), %rax
movq %rax, 0x10(%rbx)
movl 0x8(%rdx), %eax
movl %eax, 0x18(%rbx)
movb 0xd(%rdx), %al
movb %al, 0x1c(%rbx)
movzbl 0xa(%rdx), %r15d
movzbl 0xb(%rdx), %r14d
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x10076, %esi          # imm = 0x10076
movl $0x5, %ecx
callq *0x20(%rax)
testl %eax, %eax
js 0x10dc5
movl 0x8(%rsp), %eax
movl %eax, 0x20(%rbx)
movzbl 0xc(%rsp), %ebp
movl $0x0, 0x24(%rbx)
shll $0x10, %r15d
shll $0x8, %r14d
orl %r15d, %r14d
orl %ebp, %r14d
movl %r14d, 0x28(%rbx)
leaq 0x10617(%rip), %r14     # 0x21291
cmpb $0x1, (%r14)
jne 0x10ca8
leaq 0x10(%rbx), %r8
movq 0x1032d(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0x814d(%rip), %rsi      # 0x18de2
leaq 0x601e(%rip), %rdx      # 0x16cba
movl $0x18e, %ecx            # imm = 0x18E
xorl %eax, %eax
callq 0x5180
cmpb $0x1, (%r14)
jne 0x10cee
movq 0x10303(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x18(%rbx), %r8d
movzbl 0x19(%rbx), %r9d
movzbl 0x1a(%rbx), %r10d
movzbl 0x1b(%rbx), %r11d
leaq 0x8128(%rip), %rsi      # 0x18dfb
leaq 0x5fe0(%rip), %rdx      # 0x16cba
movl $0x190, %ecx            # imm = 0x190
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x5180
addq $0x10, %rsp
cmpb $0x1, (%r14)
jne 0x10d1d
movq 0x102bd(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x1c(%rbx), %r8d
leaq 0x811b(%rip), %rsi      # 0x18e25
leaq 0x5fa9(%rip), %rdx      # 0x16cba
movl $0x191, %ecx            # imm = 0x191
xorl %eax, %eax
callq 0x5180
cmpb $0x1, (%r14)
jne 0x10d4b
movq 0x1028e(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movl 0x20(%rbx), %r8d
leaq 0x810b(%rip), %rsi      # 0x18e43
leaq 0x5f7b(%rip), %rdx      # 0x16cba
movl $0x192, %ecx            # imm = 0x192
xorl %eax, %eax
callq 0x5180
cmpb $0x1, (%r14)
jne 0x10d78
movq 0x10260(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0x8101(%rip), %rsi      # 0x18e63
leaq 0x5f51(%rip), %rdx      # 0x16cba
movl $0x193, %ecx            # imm = 0x193
movl %ebp, %r8d
xorl %eax, %eax
callq 0x5180
xorl %ebp, %ebp
cmpb $0x1, (%r14)
jne 0x10dd3
movq 0x10231(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movl 0x24(%rbx), %r8d
movl 0x28(%rbx), %r9d
leaq 0x80eb(%rip), %rsi      # 0x18e84
leaq 0x5f1a(%rip), %rdx      # 0x16cba
xorl %ebp, %ebp
movl $0x195, %ecx            # imm = 0x195
xorl %eax, %eax
callq 0x5180
jmp 0x10dd3
movl %eax, %ebp
leaq 0x104d8(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
jne 0x10dd3
callq 0x60f8
jmp 0x10dd3
movl %eax, %ebp
leaq 0x104c3(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
je 0x10de0
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x60ce
jmp 0x10dd3
nop