// File: /workspace/github_cpp_makefile_star2_O2/goodix[P]gdix_hid_firmware_update/gt7868q/gt7868q.cpp
// Function: GT7868QDevice::SetBasicProperties()
int GT7868QDevice::SetBasicProperties()
{
	int ret;
	unsigned char fw_info[32] = {0};
	m_firmwareVersionMajor = 20;
	m_firmwareVersionMinor = 20;
	m_sensorID = 0xF;
	unsigned char cfg_ver = 0;
	int retry = 10;
	unsigned short chksum;
	unsigned char buf_dis_report_coor[] = {0x33, 0x00, 0x00, 0x00, 0x33};
	unsigned char buf_en_report_coor[] = {0x34, 0x00, 0x00, 0x00, 0x34};

	if (!m_deviceOpen) {
		gdix_err("Please open device first\n");
		return -1;
	}
	/*dis report coor*/
	gdix_info("disable report coor in read version\n");
	retry = 3;
	do {
		ret = Write(CMD_ADDR, buf_dis_report_coor, sizeof(buf_dis_report_coor));
		if (ret < 0) {
			gdix_err("Failed disable report coor\n");
		}
	} while (--retry);
	// read cfg ver
	retry = 10;
	do {
		ret = Read(CFG_START_ADDR, &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(VER_ADDR, 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]);
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[11],
			 fw_info[12], fw_info[13], fw_info[14], fw_info[15], fw_info[16]);
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[17], fw_info[18],
			 fw_info[19], fw_info[20], fw_info[21]);
	gdix_dbg("0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", fw_info[22],
			 fw_info[23], fw_info[24], fw_info[25], fw_info[26], fw_info[27]);
	if (!retry) {
		ret = -1;
		goto ver_end;
	}

	/*check fw version*/
	chksum = ChecksumU8_ys(fw_info, sizeof(fw_info));
	if (chksum) {
		gdix_err("fw version check sum error:0x%x\n", chksum);
		ret = -2;
		goto ver_end;
	}

	memcpy(m_pid, &fw_info[14], 4);
	if (!memcmp(m_pid, "7869", 4)) {
		memcpy(m_pid, "7868Q", 5);
		m_pid[5] = '\0';
	} else {
		m_pid[4] = '\0';
	}
	gdix_dbg("pid:%s\n", m_pid);
	m_sensorID = fw_info[27] & 0xff;
	gdix_dbg("sensorID:%d\n", m_sensorID);

	m_firmwareVersionMajor = fw_info[23];
	m_firmwareVersionMinor =
		((fw_info[24] << 16) | (fw_info[25]) << 8) | cfg_ver;

	gdix_dbg("version:0x%x,0x%x\n", m_firmwareVersionMajor,
			 m_firmwareVersionMinor);

	ret = 0;
ver_end:
	/*en report coor*/
	gdix_info("enable report coor\n");
	if (Write(CMD_ADDR, buf_en_report_coor, sizeof(buf_en_report_coor)) < 0) {
		gdix_err("Failed enable report coor in read version\n");
	}
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movabsq $0x1400000014, %rax     # imm = 0x1400000014
movq %rax, 0x10(%rdi)
movl $0xf, 0x18(%rdi)
movb $0x0, 0xf(%rsp)
movb $0x33, 0x44(%rsp)
movl $0x33, 0x40(%rsp)
movb $0x34, 0x3c(%rsp)
movl $0x34, 0x38(%rsp)
leaq 0x1960f(%rip), %rax     # 0x20291
movb (%rax), %al
cmpb $0x0, 0x8(%rdi)
je 0x6d18
movq %rdi, %rbx
testb %al, %al
je 0x6cb7
movq 0x1931c(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xefc6(%rip), %rsi      # 0x15c6c
leaq 0xefac(%rip), %rdx      # 0x15c59
pushq $0x39
popq %rcx
xorl %eax, %eax
callq 0x5180
pushq $-0x3
popq %r15
leaq 0x40(%rsp), %r14
pushq $0x5
popq %rbp
leaq 0xef8f(%rip), %r12      # 0x15c59
pushq $0x3e
popq %r13
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x4160, %esi           # imm = 0x4160
movq %r14, %rdx
movl %ebp, %ecx
callq *0x30(%rax)
testl %eax, %eax
jns 0x6cf1
leaq 0x195a5(%rip), %rax     # 0x20291
cmpb $0x1, (%rax)
je 0x6cf8
incl %r15d
jne 0x6cce
jmp 0x6d42
movq 0x192d9(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0xef99(%rip), %rsi      # 0x15ca2
movq %r12, %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x5180
jmp 0x6cf1
pushq $-0x1
popq %rbp
testb %al, %al
je 0x71bb
movq 0x192ae(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0xeefa(%rip), %rsi      # 0x15c2e
leaq 0xef1e(%rip), %rdx      # 0x15c59
pushq $0x35
jmp 0x71e6
pushq $0xa
popq %rbp
leaq 0xf(%rsp), %r14
pushq $0x1
popq %r15
leaq 0xef04(%rip), %r13      # 0x15c59
pushq $0x20
popq %r12
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x96f8, %esi           # imm = 0x96F8
movq %r14, %rdx
movl %r15d, %ecx
callq *0x20(%rax)
leaq 0x1951d(%rip), %rcx     # 0x20291
movb (%rcx), %cl
testl %eax, %eax
js 0x6de2
testb %cl, %cl
je 0x6da2
movq 0x19233(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
movzbl 0xf(%rsp), %r8d
leaq 0xef6e(%rip), %rsi      # 0x15d03
movq %r13, %rdx
pushq $0x49
popq %rcx
xorl %eax, %eax
callq 0x5180
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x4014, %esi           # imm = 0x4014
leaq 0x10(%rsp), %rdx
movl %r12d, %ecx
callq *0x20(%rax)
leaq 0x194d2(%rip), %rcx     # 0x20291
movb (%rcx), %cl
testl %eax, %eax
jns 0x6e1d
testb $0x1, %cl
je 0x6e07
movq 0x191e7(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xef45(%rip), %rsi      # 0x15d20
movq %r13, %rdx
pushq $0x4c
jmp 0x6dfc
testb %cl, %cl
je 0x6e07
movq 0x191cb(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xeed8(%rip), %rsi      # 0x15ccf
movq %r13, %rdx
pushq $0x46
popq %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x5180
decl %ebp
jne 0x6d59
leaq 0x1947b(%rip), %rax     # 0x20291
movb (%rax), %cl
movb $0x1, %bpl
jmp 0x6e1f
xorl %ebp, %ebp
testb $0x1, %cl
je 0x6e4f
movq 0x1918d(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xef1b(%rip), %rsi      # 0x15d50
leaq 0xee1d(%rip), %rdx      # 0x15c59
pushq $0x50
popq %rcx
xorl %eax, %eax
callq 0x5180
leaq 0x19444(%rip), %rax     # 0x20291
movb (%rax), %cl
testb $0x1, %cl
je 0x6eab
movq 0x1915d(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
movzbl 0x10(%rsp), %r8d
movzbl 0x11(%rsp), %r9d
movzbl 0x12(%rsp), %r10d
movzbl 0x13(%rsp), %r11d
movzbl 0x14(%rsp), %r14d
subq $0x8, %rsp
leaq 0xeee9(%rip), %rsi      # 0x15d70
leaq 0xedcb(%rip), %rdx      # 0x15c59
pushq $0x52
popq %rcx
xorl %eax, %eax
pushq %r14
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
leaq 0x193e8(%rip), %rax     # 0x20291
movb (%rax), %cl
testb $0x1, %cl
je 0x6f0b
movq 0x19101(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
movzbl 0x15(%rsp), %r8d
movzbl 0x16(%rsp), %r9d
movzbl 0x17(%rsp), %r10d
movzbl 0x18(%rsp), %r11d
movzbl 0x19(%rsp), %r14d
movzbl 0x1a(%rsp), %r15d
leaq 0xeec0(%rip), %rsi      # 0x15da5
leaq 0xed6d(%rip), %rdx      # 0x15c59
pushq $0x54
popq %rcx
xorl %eax, %eax
pushq %r15
pushq %r14
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
leaq 0x19388(%rip), %rax     # 0x20291
movb (%rax), %cl
testb $0x1, %cl
je 0x6f6b
movq 0x190a1(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
movzbl 0x1b(%rsp), %r8d
movzbl 0x1c(%rsp), %r9d
movzbl 0x1d(%rsp), %r10d
movzbl 0x1e(%rsp), %r11d
movzbl 0x1f(%rsp), %r14d
movzbl 0x20(%rsp), %r15d
leaq 0xee60(%rip), %rsi      # 0x15da5
leaq 0xed0d(%rip), %rdx      # 0x15c59
pushq $0x56
popq %rcx
xorl %eax, %eax
pushq %r15
pushq %r14
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
leaq 0x19328(%rip), %rax     # 0x20291
movb (%rax), %cl
testb $0x1, %cl
je 0x6fc7
movq 0x19041(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
movzbl 0x21(%rsp), %r8d
movzbl 0x22(%rsp), %r9d
movzbl 0x23(%rsp), %r10d
movzbl 0x24(%rsp), %r11d
movzbl 0x25(%rsp), %r14d
subq $0x8, %rsp
leaq 0xedcd(%rip), %rsi      # 0x15d70
leaq 0xecaf(%rip), %rdx      # 0x15c59
pushq $0x58
popq %rcx
xorl %eax, %eax
pushq %r14
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
leaq 0x192cc(%rip), %rax     # 0x20291
movb (%rax), %cl
testb $0x1, %cl
je 0x701e
movq 0x18fe5(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
movzbl 0x26(%rsp), %r8d
movzbl 0x27(%rsp), %r9d
movzbl 0x28(%rsp), %r10d
movzbl 0x29(%rsp), %r11d
movzbl 0x2a(%rsp), %r14d
movzbl 0x2b(%rsp), %r15d
leaq 0xeda4(%rip), %rsi      # 0x15da5
leaq 0xec51(%rip), %rdx      # 0x15c59
pushq $0x5a
popq %rcx
xorl %eax, %eax
pushq %r15
pushq %r14
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
testb %bpl, %bpl
je 0x702b
pushq $-0x1
popq %rbp
jmp 0x7167
leaq 0x10(%rsp), %rsi
pushq $0x20
popq %rdx
callq 0x6b90
testw %ax, %ax
je 0x707b
pushq $-0x2
popq %rbp
leaq 0x1924a(%rip), %rcx     # 0x20291
cmpb $0x1, (%rcx)
jne 0x7167
movq 0x18f81(%rip), %rcx     # 0x1ffd8
movq (%rcx), %rdi
movzwl %ax, %r8d
leaq 0xed7c(%rip), %rsi      # 0x15de1
leaq 0xebed(%rip), %rdx      # 0x15c59
pushq $0x63
popq %rcx
xorl %eax, %eax
callq 0x5180
jmp 0x7167
leaq 0x1c(%rbx), %r8
movl 0x1e(%rsp), %eax
movl %eax, 0x1c(%rbx)
cmpl $0x39363837, %eax       # imm = 0x39363837
jne 0x709f
movb $0x51, 0x4(%r8)
movl $0x38363837, (%r8)      # imm = 0x38363837
movb $0x0, 0x21(%rbx)
jmp 0x70a3
movb $0x0, 0x20(%rbx)
leaq 0x191e7(%rip), %rax     # 0x20291
movb (%rax), %al
cmpb $0x1, %al
jne 0x70db
movq 0x18f01(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xed58(%rip), %rsi      # 0x15e19
leaq 0xeb91(%rip), %rdx      # 0x15c59
pushq $0x6f
popq %rcx
xorl %eax, %eax
callq 0x5180
leaq 0x191b8(%rip), %rax     # 0x20291
movb (%rax), %al
movzbl 0x2b(%rsp), %r8d
movl %r8d, 0x18(%rbx)
testb $0x1, %al
je 0x7114
movq 0x18ec8(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xed38(%rip), %rsi      # 0x15e32
leaq 0xeb58(%rip), %rdx      # 0x15c59
pushq $0x71
popq %rcx
xorl %eax, %eax
callq 0x5180
leaq 0x1917f(%rip), %rax     # 0x20291
movb (%rax), %al
movzbl 0x27(%rsp), %r8d
movl %r8d, 0x10(%rbx)
movzbl 0x28(%rsp), %ecx
shll $0x10, %ecx
movzbl 0x29(%rsp), %edx
shll $0x8, %edx
orl %ecx, %edx
movzbl 0xf(%rsp), %r9d
orl %edx, %r9d
movl %r9d, 0x14(%rbx)
xorl %ebp, %ebp
testb $0x1, %al
je 0x7167
movq 0x18e6e(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xecfc(%rip), %rsi      # 0x15e50
leaq 0xeafe(%rip), %rdx      # 0x15c59
xorl %ebp, %ebp
pushq $0x78
popq %rcx
xorl %eax, %eax
callq 0x5180
leaq 0x19123(%rip), %rax     # 0x20291
cmpb $0x1, (%rax)
jne 0x7195
movq 0x18e3e(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xecf0(%rip), %rsi      # 0x15e74
leaq 0xeace(%rip), %rdx      # 0x15c59
pushq $0x7d
popq %rcx
xorl %eax, %eax
callq 0x5180
movq (%rbx), %rax
leaq 0x38(%rsp), %rdx
pushq $0x5
popq %rcx
movq %rbx, %rdi
movl $0x4160, %esi           # imm = 0x4160
callq *0x30(%rax)
testl %eax, %eax
jns 0x71bb
leaq 0x190db(%rip), %rax     # 0x20291
cmpb $0x1, (%rax)
je 0x71cc
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18e05(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0xecbc(%rip), %rsi      # 0x15e99
leaq 0xea75(%rip), %rdx      # 0x15c59
pushq $0x7f
popq %rcx
xorl %eax, %eax
callq 0x5180
jmp 0x71bb