我想知道,在什么地方发送这个0 ,我试了好多地方都不行,下面是代码:
int main(void)
{
Set_System();
USB_Interrupts_Config();
Set_USBClock();
USB_Init();
while (1)
{
if (bDeviceState == CONFIGURED)
{
if ((JoyState() != 0) && (PrevXferComplete))
{
Keyboard_Send(JoyState());
}
}
}
}
uint8_t JoyState(void)
{
/* "right" key is pressed */
if (!STM_PBGetState(Button_RIGHT))
{
return JOY_RIGHT;
}
/* "left" key is pressed */
if (!STM_PBGetState(Button_LEFT))
{
return JOY_LEFT;
}
/* "up" key is pressed */
if (!STM_PBGetState(Button_UP))
{
return JOY_UP;
}
/* "down" key is pressed */
if (!STM_PBGetState(Button_DOWN))
{
return JOY_DOWN;
}
/* No key is pressed */
else
{
return 0;
}
}
void Keyboard_Send(uint8_t Keys)
{
uint8_t Buffer[8] = {0, 0, 0, 0, 0, 0, 0, 0};
uint8_t i=2;
switch (Keys)
{
case JOY_LEFT:
Buffer[i]=0x50;
i++;
break;
case JOY_RIGHT:
Buffer[i]=0x49;
i++;
break;
case JOY_UP:
Buffer[i]=0x52;
i++;
break;
case JOY_DOWN:
Buffer[i]=0x51;
break;
default:
return;
}
/* Reset the control token to inform upper layer that a transfer is ongoing */
PrevXferComplete = 0;
/* Copy mouse position info in ENDP1 Tx Packet Memory Area*/
USB_SIL_Write(EP1_IN, Buffer, 8);
/* Enable endpoint for transmission */
SetEPTxValid(ENDP1);
// Buffer[0]=0;
// Buffer[1]=0;
// Buffer[2]=0;
// Buffer[3]=0;
// Buffer[4]=0;
// Buffer[5]=0;
// Buffer[6]=0;
// Buffer[7]=0;
// delay_ms(50);
// USB_SIL_Write(EP1_IN, Buffer, 8);
// SetEPTxValid(ENDP1);
}
请赐教!
|