第一次应该在main之前放入usb buffer之中,後开usb中断,才会第一次取走00 00 04 00 00 00 00 00的资料。
int32_t main(void)
{
/* Unlock protected registers */
SYS_UnlockReg();
SYS_Init();
UART0_Init();
printf("\n");
printf("+--------------------------------------------------------+\n");
printf("| NuMicro USB HID Keyboard Sample Code |\n");
printf("+--------------------------------------------------------+\n");
printf("If PB.15 = 0, just report it is key 'a'.\n");
USBD_Open(&gsInfo, HID_ClassRequest, NULL);
/* Endpoint configuration */
HID_Init();
USBD_Start();
buf[2] = 0x04; /* Key A */
USBD_SET_PAYLOAD_LEN(EP2, 8);
NVIC_EnableIRQ(USBD_IRQn);
/* start to IN data */
g_u8EP2Ready = 1;
GPIO_SetMode(PD, BIT2, GPIO_PMD_INPUT);
GPIO_EnableInt(PD, 2, GPIO_INT_FALLING);
NVIC_EnableIRQ(GPCDF_IRQn);
GPIO_SET_DEBOUNCE_TIME(GPIO_DBCLKSRC_LIRC, GPIO_DBCLKSEL_2);
GPIO_ENABLE_DEBOUNCE(PD, BIT2);
while(1)
{
HID_UpdateKbData();
}
} |