// File: /workspace/github_c_makefile_star2_O2/ZombiesYard[P]MPU6050-DMP-raspberry-pi/MotionSensor/inv_mpu_lib/inv_mpu_dmp_motion_driver.c
// Function: dmp_set_tap_thresh(unsigned char, unsigned short)
uint8_t dmp_set_tap_thresh(uint8_t axis, uint16_t thresh)
{
	uint8_t tmp[4], accel_fsr;
	float scaled_thresh;
	uint16_t dmp_thresh, dmp_thresh_2;
	if (!(axis & TAP_XYZ) || thresh > 1600)
		return 1;

	scaled_thresh = (float)thresh / DMP_SAMPLE_RATE;

	mpu_get_accel_fsr(&accel_fsr);
	switch (accel_fsr)
	{
	case 2:
		dmp_thresh = (uint16_t)(scaled_thresh * 16384);
		/* dmp_thresh * 0.75 */
		dmp_thresh_2 = (uint16_t)(scaled_thresh * 12288);
		break;
	case 4:
		dmp_thresh = (uint16_t)(scaled_thresh * 8192);
		/* dmp_thresh * 0.75 */
		dmp_thresh_2 = (uint16_t)(scaled_thresh * 6144);
		break;
	case 8:
		dmp_thresh = (uint16_t)(scaled_thresh * 4096);
		/* dmp_thresh * 0.75 */
		dmp_thresh_2 = (uint16_t)(scaled_thresh * 3072);
		break;
	case 16:
		dmp_thresh = (uint16_t)(scaled_thresh * 2048);
		/* dmp_thresh * 0.75 */
		dmp_thresh_2 = (uint16_t)(scaled_thresh * 1536);
		break;
	default:
		return 1;
	}
	tmp[0] = (uint8_t)(dmp_thresh >> 8);
	tmp[1] = (uint8_t)(dmp_thresh & 0xFF);
	tmp[2] = (uint8_t)(dmp_thresh_2 >> 8);
	tmp[3] = (uint8_t)(dmp_thresh_2 & 0xFF);

	if (axis & TAP_X)
	{
		if (mpu_write_mem(DMP_TAP_THX, 2, tmp))
			return 1;
		if (mpu_write_mem(D_1_36, 2, tmp+2))
			return 1;
	}
	if (axis & TAP_Y)
	{
		if (mpu_write_mem(DMP_TAP_THY, 2, tmp))
			return 1;
		if (mpu_write_mem(D_1_40, 2, tmp+2))
			return 1;
	}
	if (axis & TAP_Z)
	{
		if (mpu_write_mem(DMP_TAP_THZ, 2, tmp))
			return 1;
		if (mpu_write_mem(D_1_44, 2, tmp+2))
			return 1;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %r14d
movl %edi, %ebp
testb $0x7, %bpl
sete %al
cmpw $0x641, %r14w           # imm = 0x641
setae %cl
orb %al, %cl
movb $0x1, %bl
jne 0x3fd4
leaq 0x7(%rsp), %r15
movq %r15, %rdi
callq 0x278c
movzbl (%r15), %eax
addl $-0x2, %eax
rorl %eax
cmpl $0x7, %eax
ja 0x3fd4
movl $0x8b, %ecx
btl %eax, %ecx
jae 0x3fd4
movswl %r14w, %ecx
cvtsi2ss %ecx, %xmm0
divss 0x160a(%rip), %xmm0     # 0x5504
movl %eax, %eax
leaq 0x22d5(%rip), %rcx      # 0x61d8
leaq 0x22ee(%rip), %rdx      # 0x61f8
movss (%rcx,%rax,4), %xmm1
mulss %xmm0, %xmm1
mulss (%rdx,%rax,4), %xmm0
cvttss2si %xmm0, %eax
cvttss2si %xmm1, %ecx
movb %ch, 0x3(%rsp)
leaq 0x5(%rsp), %r14
movb %cl, -0x1(%r14)
movb %ah, 0x5(%rsp)
movb %al, 0x1(%r14)
testb $0x1, %bpl
jne 0x3f4e
testb $0x2, %bpl
jne 0x3f7a
testb $0x4, %bpl
jne 0x3fa6
xorl %ebx, %ebx
jmp 0x3fd4
pushq $0x2
popq %rsi
leaq 0x3(%rsp), %rdx
movl $0x1d4, %edi            # imm = 0x1D4
callq 0x3596
testb %al, %al
jne 0x3fd4
pushq $0x2
popq %rsi
movl $0x124, %edi            # imm = 0x124
movq %r14, %rdx
callq 0x3596
testb %al, %al
jne 0x3fd4
jmp 0x3f3b
pushq $0x2
popq %rsi
leaq 0x3(%rsp), %rdx
movl $0x1d8, %edi            # imm = 0x1D8
callq 0x3596
testb %al, %al
jne 0x3fd4
pushq $0x2
popq %rsi
movl $0x128, %edi            # imm = 0x128
movq %r14, %rdx
callq 0x3596
testb %al, %al
jne 0x3fd4
jmp 0x3f41
pushq $0x2
popq %rsi
leaq 0x3(%rsp), %rdx
movl $0x1dc, %edi            # imm = 0x1DC
callq 0x3596
testb %al, %al
jne 0x3fd4
pushq $0x2
popq %rsi
movl $0x12c, %edi            # imm = 0x12C
movq %r14, %rdx
callq 0x3596
testb %al, %al
je 0x3f47
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq