// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x1e(%rbp), %rdi
xorl %esi, %esi
movl $0xe, %edx
callq 0x50a0
movq -0x30(%rbp), %rdi
leaq -0x1e(%rbp), %rdx
movq (%rdi), %rax
movl $0x1001e, %esi          # imm = 0x1001E
movl $0xe, %ecx
callq *0x20(%rax)
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x140f4
jmp 0x140b7
leaq 0x121db(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x140e7
movq 0x11f0e(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0xacbc(%rip), %rsi      # 0x1ed90
leaq 0x8bcf(%rip), %rdx      # 0x1ccaa
movl $0x175, %ecx            # imm = 0x175
movb $0x0, %al
callq 0x5190
jmp 0x140e9
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1432e
jmp 0x140f6
jmp 0x140f8
movq -0x30(%rbp), %rdi
movq -0x1e(%rbp), %rax
movq %rax, 0x10(%rdi)
movl -0x16(%rbp), %eax
movl %eax, 0x18(%rdi)
movb -0x11(%rbp), %al
movb %al, 0x1c(%rdi)
movb -0x14(%rbp), %al
movb %al, -0x25(%rbp)
movb -0x13(%rbp), %al
movb %al, -0x26(%rbp)
leaq -0x1e(%rbp), %rdx
movq (%rdi), %rax
movl $0x10076, %esi          # imm = 0x10076
movl $0x5, %ecx
callq *0x20(%rax)
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x14178
jmp 0x1413b
leaq 0x12157(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x1416b
movq 0x11e8a(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0xac5e(%rip), %rsi      # 0x1edb6
leaq 0x8b4b(%rip), %rdx      # 0x1ccaa
movl $0x184, %ecx            # imm = 0x184
movb $0x0, %al
callq 0x5190
jmp 0x1416d
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1432e
movq -0x30(%rbp), %rax
movl -0x1e(%rbp), %ecx
movl %ecx, 0x20(%rax)
movb -0x1a(%rbp), %cl
movb %cl, -0x27(%rbp)
movl $0x0, 0x24(%rax)
movzbl -0x25(%rbp), %ecx
shll $0x10, %ecx
movzbl -0x26(%rbp), %edx
shll $0x8, %edx
orl %edx, %ecx
movzbl -0x27(%rbp), %edx
orl %edx, %ecx
movl %ecx, 0x28(%rax)
leaq 0x120ea(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x141e0
movq -0x30(%rbp), %r8
movq 0x11df9(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
addq $0x10, %r8
leaq 0xac19(%rip), %rsi      # 0x1ede6
leaq 0x8ad6(%rip), %rdx      # 0x1ccaa
movl $0x18e, %ecx            # imm = 0x18E
movb $0x0, %al
callq 0x5190
jmp 0x141e2
jmp 0x141e4
leaq 0x120ae(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x14233
movq -0x30(%rbp), %rax
movq 0x11dbd(%rip), %rcx     # 0x25fb8
movq (%rcx), %rdi
movzbl 0x18(%rax), %r8d
movzbl 0x19(%rax), %r9d
movzbl 0x1a(%rax), %r10d
movzbl 0x1b(%rax), %eax
leaq 0xabe7(%rip), %rsi      # 0x1edff
leaq 0x8a8b(%rip), %rdx      # 0x1ccaa
movl $0x190, %ecx            # imm = 0x190
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x5190
jmp 0x14235
jmp 0x14237
leaq 0x1205b(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x14270
movq -0x30(%rbp), %rax
movq 0x11d6a(%rip), %rcx     # 0x25fb8
movq (%rcx), %rdi
movzbl 0x1c(%rax), %r8d
leaq 0xabcc(%rip), %rsi      # 0x1ee29
leaq 0x8a46(%rip), %rdx      # 0x1ccaa
movl $0x191, %ecx            # imm = 0x191
movb $0x0, %al
callq 0x5190
jmp 0x14272
jmp 0x14274
leaq 0x1201e(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x142ac
movq -0x30(%rbp), %rax
movq 0x11d2d(%rip), %rcx     # 0x25fb8
movq (%rcx), %rdi
movl 0x20(%rax), %r8d
leaq 0xabae(%rip), %rsi      # 0x1ee47
leaq 0x8a0a(%rip), %rdx      # 0x1ccaa
movl $0x192, %ecx            # imm = 0x192
movb $0x0, %al
callq 0x5190
jmp 0x142ae
jmp 0x142b0
leaq 0x11fe2(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x142e5
movq 0x11cf5(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x27(%rbp), %r8d
leaq 0xab95(%rip), %rsi      # 0x1ee67
leaq 0x89d1(%rip), %rdx      # 0x1ccaa
movl $0x193, %ecx            # imm = 0x193
movb $0x0, %al
callq 0x5190
jmp 0x142e7
jmp 0x142e9
leaq 0x11fa9(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x14325
movq -0x30(%rbp), %rax
movq 0x11cb8(%rip), %rcx     # 0x25fb8
movq (%rcx), %rdi
movl 0x24(%rax), %r8d
movl 0x28(%rax), %r9d
leaq 0xab76(%rip), %rsi      # 0x1ee88
leaq 0x8991(%rip), %rdx      # 0x1ccaa
movl $0x195, %ecx            # imm = 0x195
movb $0x0, %al
callq 0x5190
jmp 0x14327
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)