// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rsp, %rdx
andq $0x0, 0x6(%rdx)
andq $0x0, (%rdx)
movq (%rdi), %rax
pushq $0xe
popq %rcx
movl $0x1001e, %esi          # imm = 0x1001E
callq *0x20(%rax)
testl %eax, %eax
js 0xf985
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
pushq $0x5
popq %rcx
movq %rbx, %rdi
movl $0x10076, %esi          # imm = 0x10076
callq *0x20(%rax)
testl %eax, %eax
js 0xf9b2
movl (%rsp), %eax
movl %eax, 0x20(%rbx)
movzbl 0x4(%rsp), %ebp
andl $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 0x10a46(%rip), %r14     # 0x20291
movb (%r14), %al
cmpb $0x1, %al
jne 0xf87d
leaq 0x10(%rbx), %r8
movq 0x1075b(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0x8541(%rip), %rsi      # 0x17da8
leaq 0x63eb(%rip), %rdx      # 0x15c59
movl $0x18e, %ecx            # imm = 0x18E
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
testb $0x1, %al
je 0xf8c2
movq 0x10730(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
movzbl 0x18(%rbx), %r8d
movzbl 0x19(%rbx), %r9d
movzbl 0x1a(%rbx), %r10d
movzbl 0x1b(%rbx), %r11d
leaq 0x851b(%rip), %rsi      # 0x17dc1
leaq 0x63ac(%rip), %rdx      # 0x15c59
movl $0x190, %ecx            # imm = 0x190
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x5180
popq %rcx
popq %rdx
movb (%r14), %al
testb $0x1, %al
je 0xf8f2
movq 0x106eb(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
movzbl 0x1c(%rbx), %r8d
leaq 0x850f(%rip), %rsi      # 0x17deb
leaq 0x6376(%rip), %rdx      # 0x15c59
movl $0x191, %ecx            # imm = 0x191
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
testb $0x1, %al
je 0xf921
movq 0x106bb(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
movl 0x20(%rbx), %r8d
leaq 0x84fe(%rip), %rsi      # 0x17e09
leaq 0x6347(%rip), %rdx      # 0x15c59
movl $0x192, %ecx            # imm = 0x192
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
testb $0x1, %al
je 0xf94f
movq 0x1068c(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0x84f3(%rip), %rsi      # 0x17e29
leaq 0x631c(%rip), %rdx      # 0x15c59
movl $0x193, %ecx            # imm = 0x193
movl %ebp, %r8d
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
xorl %ebp, %ebp
testb $0x1, %al
je 0xf9c0
movq 0x1065c(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
movl 0x24(%rbx), %r8d
movl 0x28(%rbx), %r9d
leaq 0x84dc(%rip), %rsi      # 0x17e4a
leaq 0x62e4(%rip), %rdx      # 0x15c59
xorl %ebp, %ebp
movl $0x195, %ecx            # imm = 0x195
xorl %eax, %eax
callq 0x5180
jmp 0xf9c0
movl %eax, %ebp
leaq 0x10903(%rip), %rax     # 0x20291
cmpb $0x1, (%rax)
jne 0xf9c0
movq 0x1063e(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0x83ae(%rip), %rsi      # 0x17d52
leaq 0x62ae(%rip), %rdx      # 0x15c59
movl $0x175, %ecx            # imm = 0x175
jmp 0xf9e8
movl %eax, %ebp
leaq 0x108d6(%rip), %rax     # 0x20291
cmpb $0x1, (%rax)
je 0xf9cb
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq 0x10606(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0x839c(%rip), %rsi      # 0x17d78
leaq 0x6276(%rip), %rdx      # 0x15c59
movl $0x184, %ecx            # imm = 0x184
xorl %eax, %eax
callq 0x5180
jmp 0xf9c0
nop