目标:使用CY7C64215单片机制作HID键盘,支持开机启动。
现状:进入Windows后,键盘正常
困难:开机后,按键有响应,但太快。但LED无响应(如Caps Lock 灯)
实际问题:我设了两个端点EP1(input),EP2(output),也设了subclass。还需要什么改动?望有高人指导,谢谢!
下面是我的主程序
void main(void)
{
int temp1,temp2;
BYTE readout;
LED_1_Start();
LED_2_Start();
LED_3_Start();
LED_1_Switch(0); // Turn on LED_1
LED_2_Switch(0); // Turn on LED_2
LED_3_Switch(0); // Turn on LED_3
M8C_EnableGInt; //Enable Global Interrupts
USBFS_Start(0, USB_5V_OPERATION); //Start USBFS Operation using device 0 and with 5V operation
while(!USBFS_bGetConfiguration()); //Wait for Device to enumerate
//Enumeration is completed load endpoint 1. Do not toggle the first time
USBFS_LoadInEP(1, keycode, 8, USB_NO_TOGGLE);
USBFS_EnableOutEP(2);
while(1)
{
temp1=KEY_input();
if(temp1==0x41)
{
keycode[0]|=0x02;
}
else
{
keycode[0]&=(~0x02);
}
if(temp1==0x43)
{
keycode[0]|=0x02;
temp1=0x11;
}
if(USBFS_bGetEPAckState(1))
{
//ACK has occurred, load the endpoint and toggle the data bit
USBFS_LoadInEP(1, keycode, 8, USB_TOGGLE);
//converting read from Keyboard scan code to PC format
keycode[2]=MakeConversionTable(temp1);
}
}
if(USBFS_bGetEPAckState(2))
{
USBFS_bReadOutEP(2, Buf, 1);
if(Buf[0]&0x02)
{
LED_1_Switch(1);
}
else
{
LED_1_Switch(0);
}
USBFS_EnableOutEP(2);
}
Delay(1000);
}
} |