/** \brief Processes USB keyboard events. * */ void usbHidProcessKeyboard(uint8_t *pRfData) { extern void halMcuWaitMs(uint16_t msec); uint8_t i; // // Copy data from RX buffer // keyboard.modifiers = pRfData[1]; keyboard.reserved = pRfData[2]; for(i = 0; i < sizeof(keyboard.pKeyCodes); i++) { keyboard.pKeyCodes[i] = pRfData[i + 3]; } // // Update and send the received HID keyboard report if USB endpoint is ready // hidUpdateKeyboardInReport(&keyboard); if(hidSendKeyboardInReport()) { // // For each successfully sent keyboard report, also clear the HID // keyboard report and send a blank report // keyboard.modifiers = 0; keyboard.reserved = 0; for(i = 0; i < sizeof(keyboard.pKeyCodes); i++) { keyboard.pKeyCodes[i] = 0; } hidUpdateKeyboardInReport(&keyboard); hidSendKeyboardInReport(); } }
// // Application entry point // int main(void) { KEYBOARD_IN_REPORT keybReport; uint8_t keybReportSendReq = false; uint8_t currKey = 0x00; // // Initialize board and system clock // bspInit(SYS_CTRL_32MHZ); // // Enable the USB interface // usbHidInit(); // // Initialize GPIO pins for keyboard LEDs (LED 1 on PC0 is used by USB to // control D+ pull-up) // GPIOPinTypeGPIOOutput(BSP_LED_BASE, BSP_LED_2 | BSP_LED_3 | BSP_LED_4); // // Configure interrupt with wakeup for all buttons // IntRegister(INT_GPIOA, selKeyRemoteWakeupIsr); GPIOPowIntTypeSet(BSP_KEY_SEL_BASE, BSP_KEY_SELECT, GPIO_POW_RISING_EDGE); IntRegister(INT_GPIOC, dirKeyRemoteWakeupIsr); GPIOPowIntTypeSet(BSP_KEY_DIR_BASE, BSP_KEY_DIR_ALL, GPIO_POW_RISING_EDGE); // // Initialize button polling for keyboard HID reports // memset(&keybReport, 0x00, sizeof(KEYBOARD_IN_REPORT)); // // Main loop // while (1) { // // Process USB events // usbHidProcessEvents(); // // Generate keyboard input // if (!keybReportSendReq) { switch (bspKeyPushed(BSP_KEY_ALL)) { case BSP_KEY_LEFT: currKey = 0x50; break; case BSP_KEY_RIGHT: currKey = 0x4F; break; case BSP_KEY_UP: currKey = 0x52; break; case BSP_KEY_DOWN: currKey = 0x51; break; case BSP_KEY_SELECT: currKey = 0x28; break; default: currKey = 0x00; break; } if (currKey != keybReport.pKeyCodes[0]) { keybReport.pKeyCodes[0] = currKey; hidUpdateKeyboardInReport(&keybReport); keybReportSendReq = true; } } if (keybReportSendReq) { if (hidSendKeyboardInReport()) { keybReportSendReq = false; } } } }