STM32和PDIUSBD12学习(9)— USB鼠标按键模拟

1 USB 鼠标按键模拟

  • key.c
    在这里插入图片描述

  • usb.c

void endpoint1_in_isr(void)
{
	printf("=== endpoint1_in_isr ===\r\n");
	// 清除中断
	// 3 - 端点1-IN
	write_cmd(CMD_Read_Last_Transaction_Status + 3);
}

  • stm32_it.c
int8_t report_data[3];

void EXTI9_5_IRQHandler(void)
{
	GPIO_SetBits(GPIOB,GPIO_Pin_8 |GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11);
	if(EXTI_GetITStatus(EXTI_Line5) == SET)
	{
		// 鼠标按键
		delay_ms(10);
		if(KEY5 == 0)
		{
			report_data[0] |= 0x01;
		}else{
			report_data[0] &= 0xFE;
		}
		EXTI_ClearITPendingBit(EXTI_Line5);
	}
	if(EXTI_GetITStatus(EXTI_Line6) == SET)
	{
		// 鼠标按键
		delay_ms(10);
		if(KEY6 == 0)
		{
			report_data[0] |= 0x02;
		}else{
			report_data[0] &= 0xFD;
		}
		EXTI_ClearITPendingBit(EXTI_Line6);
	}
	if(EXTI_GetITStatus(EXTI_Line7) == SET)
	{
		// 左移
		delay_ms(10);
		if(KEY7 == 0)
		{
			report_data[1] -= 50;
		}else{
			report_data[1] = 0;
		}
		EXTI_ClearITPendingBit(EXTI_Line7);
	}
	if(EXTI_GetITStatus(EXTI_Line8) == SET)
	{
		// 右移
		delay_ms(10);
		if(KEY8 == 0)
		{
			report_data[1] = 50;
		}else{
			report_data[1] = 0;
		}
		EXTI_ClearITPendingBit(EXTI_Line8);
	}
	if(EXTI_GetITStatus(EXTI_Line9) == SET)
	{
		// 上移
		delay_ms(10);
		if(KEY9 == 0)
		{
			report_data[2] = -50;
		}else{
			report_data[2] = 0;
		}
		EXTI_ClearITPendingBit(EXTI_Line9);
	}
	
	write_endpoint(3, 3, report_data);
}

void EXTI15_10_IRQHandler(void)
{
	GPIO_ResetBits(GPIOB,GPIO_Pin_8 |GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11);
	
	if(EXTI_GetITStatus(EXTI_Line10) == SET)
	{
		// 下移
		delay_ms(10);
		if(KEY10 == 0)
		{
			report_data[2] = 50;
		}else{
			report_data[2] = 0;
		}
		EXTI_ClearITPendingBit(EXTI_Line10);
	}
	
	write_endpoint(3, 3, report_data);
}

在这里插入图片描述

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页