STM32L4R5板子模拟带鼠标功能的USB键盘(方法二)的问题
[复制链接]
我参考网上的STM32例程和电脑圈圈的书,想实现带鼠标功能的USB键盘(方法二)。
现在模拟的鼠标和键盘都出来了。
可是按键不反应。
我的按键代码如下:
if(HAL_GPIO_ReadPin(GPIOC,KEY_Pin)==1) //键盘
{
sendbuffer[0]=1;
if((KeyPress&1)==0)
{
HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_SET);
sendbuffer[3]=0x04;
}
if((KeyPress&2)==0)
sendbuffer[3]=0x05;
if((KeyPress&4)==0)
sendbuffer[3]=0x06;
if((KeyPress&8)==0)
sendbuffer[3]=0x07;
USBD_HID_SendReport(&hUsbDeviceFS,sendbuffer,9);//发送报文
memset(sendbuffer,0,9);
KeyDown=0;
KeyUp=0;
}
else
{
sendbuffer1[0]=1;
if((KeyPress&1)==0)
{
HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_SET);
sendbuffer1[2]=-10;
}
if((KeyPress&2)==0)
sendbuffer1[2]=10;
if((KeyPress&4)==0)
sendbuffer1[3]=-10;
if((KeyPress&8)==0)
sendbuffer1[3]=10;
USBD_HID_SendReport(&hUsbDeviceFS,sendbuffer1,5);//发送报文
memset(sendbuffer1,0,5);
KeyDown=0;
KeyUp=0;
}
板子上的键按下代表键盘功能,松开代表鼠标功能。又从另外一块板子上接了四个键。
我现在有一个疑问,圈圈的书上说,前面的例子发送报告是通过端点1,现在发送键盘报告是通过端点1,发送鼠标报告通过端点2.
那在程序里如何体现呢?
请高手指教,谢谢!
|