// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0x78, %rsp
movq %rdi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x50a0
movq -0x60(%rbp), %rax
movl $0x14, 0x10(%rax)
movl $0x14, 0x14(%rax)
movl $0xf, 0x18(%rax)
movb $0x0, -0x41(%rbp)
movl $0xa, -0x48(%rbp)
movl 0x14ffc(%rip), %ecx     # 0x1cf2b
movl %ecx, -0x4f(%rbp)
movb 0x14ff7(%rip), %cl      # 0x1cf2f
movb %cl, -0x4b(%rbp)
movl 0x14fef(%rip), %ecx     # 0x1cf30
movl %ecx, -0x54(%rbp)
movb 0x14fea(%rip), %cl      # 0x1cf34
movb %cl, -0x50(%rbp)
testb $0x1, 0x8(%rax)
jne 0x7f93
jmp 0x7f55
leaq 0x1e33d(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x7f85
movq 0x1e070(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0x14d0d(%rip), %rsi     # 0x1cc7f
leaq 0x14d31(%rip), %rdx     # 0x1ccaa
movl $0x35, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x7f87
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x8582
jmp 0x7f95
leaq 0x1e2fd(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x7fc5
movq 0x1e010(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
leaq 0x14d0b(%rip), %rsi     # 0x1ccbd
leaq 0x14cf1(%rip), %rdx     # 0x1ccaa
movl $0x39, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x7fc7
movl $0x3, -0x48(%rbp)
movq -0x60(%rbp), %rdi
leaq -0x4f(%rbp), %rdx
movq (%rdi), %rax
movl $0x4160, %esi           # imm = 0x4160
movl $0x5, %ecx
callq *0x30(%rax)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x8025
jmp 0x7ff1
leaq 0x1e2a1(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x8021
movq 0x1dfd4(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0x14ce5(%rip), %rsi     # 0x1ccf3
leaq 0x14c95(%rip), %rdx     # 0x1ccaa
movl $0x3e, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x8023
jmp 0x8025
jmp 0x8027
movl -0x48(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, %eax
jne 0x7fce
movl $0xa, -0x48(%rbp)
movq -0x60(%rbp), %rdi
movq (%rdi), %rax
movl $0x96f8, %esi           # imm = 0x96F8
leaq -0x41(%rbp), %rdx
movl $0x1, %ecx
callq *0x20(%rax)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x809a
jmp 0x805f
leaq 0x1e233(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x8093
movq 0x1df46(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movl -0x48(%rbp), %r8d
leaq 0x14ca0(%rip), %rsi     # 0x1cd20
leaq 0x14c23(%rip), %rdx     # 0x1ccaa
movl $0x46, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x8095
jmp 0x8132
jmp 0x809c
leaq 0x1e1f6(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x80d1
movq 0x1df09(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x41(%rbp), %r8d
leaq 0x14c96(%rip), %rsi     # 0x1cd54
leaq 0x14be5(%rip), %rdx     # 0x1ccaa
movl $0x49, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x80d3
movq -0x60(%rbp), %rdi
leaq -0x40(%rbp), %rdx
movq (%rdi), %rax
movl $0x4014, %esi           # imm = 0x4014
movl $0x20, %ecx
callq *0x20(%rax)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x812e
jmp 0x80f6
leaq 0x1e19c(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x812a
movq 0x1deaf(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movl -0x48(%rbp), %r8d
leaq 0x14c5a(%rip), %rsi     # 0x1cd71
leaq 0x14b8c(%rip), %rdx     # 0x1ccaa
movl $0x4c, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x812c
jmp 0x8130
jmp 0x8144
jmp 0x8132
movl -0x48(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, %eax
jne 0x803c
jmp 0x8146
leaq 0x1e14c(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x8176
movq 0x1de5f(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
leaq 0x14c3e(%rip), %rsi     # 0x1cda1
leaq 0x14b40(%rip), %rdx     # 0x1ccaa
movl $0x50, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x8178
jmp 0x817a
leaq 0x1e118(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x81cf
movq 0x1de2b(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x40(%rbp), %r8d
movzbl -0x3f(%rbp), %r9d
movzbl -0x3e(%rbp), %r11d
movzbl -0x3d(%rbp), %r10d
movzbl -0x3c(%rbp), %eax
leaq 0x14c12(%rip), %rsi     # 0x1cdc1
leaq 0x14af4(%rip), %rdx     # 0x1ccaa
movl $0x52, %ecx
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x5190
jmp 0x81d1
jmp 0x81d3
leaq 0x1e0bf(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x8230
movq 0x1ddd2(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x3b(%rbp), %r8d
movzbl -0x3a(%rbp), %r9d
movzbl -0x39(%rbp), %ebx
movzbl -0x38(%rbp), %r11d
movzbl -0x37(%rbp), %r10d
movzbl -0x36(%rbp), %eax
leaq 0x14bea(%rip), %rsi     # 0x1cdf6
leaq 0x14a97(%rip), %rdx     # 0x1ccaa
movl $0x54, %ecx
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x5190
jmp 0x8232
jmp 0x8234
leaq 0x1e05e(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x8291
movq 0x1dd71(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x35(%rbp), %r8d
movzbl -0x34(%rbp), %r9d
movzbl -0x33(%rbp), %ebx
movzbl -0x32(%rbp), %r11d
movzbl -0x31(%rbp), %r10d
movzbl -0x30(%rbp), %eax
leaq 0x14b89(%rip), %rsi     # 0x1cdf6
leaq 0x14a36(%rip), %rdx     # 0x1ccaa
movl $0x56, %ecx
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x5190
jmp 0x8293
jmp 0x8295
leaq 0x1dffd(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x82ea
movq 0x1dd10(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x2f(%rbp), %r8d
movzbl -0x2e(%rbp), %r9d
movzbl -0x2d(%rbp), %r11d
movzbl -0x2c(%rbp), %r10d
movzbl -0x2b(%rbp), %eax
leaq 0x14af7(%rip), %rsi     # 0x1cdc1
leaq 0x149d9(%rip), %rdx     # 0x1ccaa
movl $0x58, %ecx
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x5190
jmp 0x82ec
jmp 0x82ee
leaq 0x1dfa4(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x834b
movq 0x1dcb7(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x2a(%rbp), %r8d
movzbl -0x29(%rbp), %r9d
movzbl -0x28(%rbp), %ebx
movzbl -0x27(%rbp), %r11d
movzbl -0x26(%rbp), %r10d
movzbl -0x25(%rbp), %eax
leaq 0x14acf(%rip), %rsi     # 0x1cdf6
leaq 0x1497c(%rip), %rdx     # 0x1ccaa
movl $0x5a, %ecx
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x5190
jmp 0x834d
cmpl $0x0, -0x48(%rbp)
jne 0x835f
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
jmp 0x84f5
movq -0x60(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movl $0x20, %edx
callq 0x7df0
movw %ax, -0x4a(%rbp)
cmpw $0x0, -0x4a(%rbp)
je 0x83c1
jmp 0x837e
leaq 0x1df14(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x83b3
movq 0x1dc47(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
movzwl -0x4a(%rbp), %r8d
leaq 0x14a92(%rip), %rsi     # 0x1ce32
leaq 0x14903(%rip), %rdx     # 0x1ccaa
movl $0x63, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x83b5
movl $0xfffffffe, -0x1c(%rbp) # imm = 0xFFFFFFFE
jmp 0x84f5
movq -0x60(%rbp), %rax
movl -0x32(%rbp), %ecx
movl %ecx, 0x1c(%rax)
addq $0x1c, %rax
movl (%rax), %eax
subl $0x39363837, %eax       # imm = 0x39363837
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x83fd
movq -0x60(%rbp), %rax
movl 0x14a7e(%rip), %ecx     # 0x1ce69
movl %ecx, 0x1c(%rax)
movb 0x14a79(%rip), %cl      # 0x1ce6d
movb %cl, 0x20(%rax)
movb $0x0, 0x21(%rax)
jmp 0x8405
movq -0x60(%rbp), %rax
movb $0x0, 0x20(%rax)
jmp 0x8407
leaq 0x1de8b(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x843f
movq -0x60(%rbp), %r8
movq 0x1db9a(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
addq $0x1c, %r8
leaq 0x14a43(%rip), %rsi     # 0x1ce6f
leaq 0x14877(%rip), %rdx     # 0x1ccaa
movl $0x6f, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x8441
movq -0x60(%rbp), %rax
movzbl -0x25(%rbp), %ecx
andl $0xff, %ecx
movl %ecx, 0x18(%rax)
leaq 0x1de40(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x848a
movq -0x60(%rbp), %rax
movq 0x1db4f(%rip), %rcx     # 0x25fb8
movq (%rcx), %rdi
movl 0x18(%rax), %r8d
leaq 0x14a11(%rip), %rsi     # 0x1ce88
leaq 0x1482c(%rip), %rdx     # 0x1ccaa
movl $0x71, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x848c
movq -0x60(%rbp), %rax
movzbl -0x29(%rbp), %ecx
movl %ecx, 0x10(%rax)
movzbl -0x28(%rbp), %ecx
shll $0x10, %ecx
movzbl -0x27(%rbp), %edx
shll $0x8, %edx
orl %edx, %ecx
movzbl -0x41(%rbp), %edx
orl %edx, %ecx
movl %ecx, 0x14(%rax)
leaq 0x1dde2(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x84ec
movq -0x60(%rbp), %rax
movq 0x1daf1(%rip), %rcx     # 0x25fb8
movq (%rcx), %rdi
movl 0x10(%rax), %r8d
movl 0x14(%rax), %r9d
leaq 0x149cd(%rip), %rsi     # 0x1cea6
leaq 0x147ca(%rip), %rdx     # 0x1ccaa
movl $0x78, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x84ee
movl $0x0, -0x1c(%rbp)
jmp 0x84f7
leaq 0x1dd9b(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x8527
movq 0x1daae(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
leaq 0x149b6(%rip), %rsi     # 0x1ceca
leaq 0x1478f(%rip), %rdx     # 0x1ccaa
movl $0x7d, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x8529
movq -0x60(%rbp), %rdi
leaq -0x54(%rbp), %rdx
movq (%rdi), %rax
movl $0x4160, %esi           # imm = 0x4160
movl $0x5, %ecx
callq *0x30(%rax)
cmpl $0x0, %eax
jge 0x857c
jmp 0x8548
leaq 0x1dd4a(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x8578
movq 0x1da7d(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0x1498a(%rip), %rsi     # 0x1ceef
leaq 0x1473e(%rip), %rdx     # 0x1ccaa
movl $0x7f, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x857a
jmp 0x857c
movl -0x1c(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x78, %rsp
popq %rbx
popq %rbp
retq
nopl (%rax)