/** * @brief Waits for given number of milliseconds * @param n : Number of milliseconds * @return Nothing */ void ms_timerDelay(uint32_t n) { ms_timer_t timer; ms_timerInit(&timer, n); while (ms_timerExpired(&timer) == false) { __NOP(); __WFI();/* conserve power */ } }
/* HID keyboard init routine */ ErrorCode_t Keyboard_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR *pIntfDesc, uint32_t *mem_base, uint32_t *mem_size) { USBD_HID_INIT_PARAM_T hid_param; USB_HID_REPORT_T reports_data[1]; ErrorCode_t ret = LPC_OK; /* Do a quick check of if the interface descriptor passed is the right one. */ if ((pIntfDesc == 0) || (pIntfDesc->bInterfaceClass != USB_DEVICE_CLASS_HUMAN_INTERFACE)) { return ERR_FAILED; } /* init joystick control */ Board_Joystick_Init(); /* Init HID params */ memset((void *) &hid_param, 0, sizeof(USBD_HID_INIT_PARAM_T)); hid_param.max_reports = 1; hid_param.mem_base = *mem_base; hid_param.mem_size = *mem_size; hid_param.intf_desc = (uint8_t *) pIntfDesc; /* user defined functions */ hid_param.HID_GetReport = Keyboard_GetReport; hid_param.HID_SetReport = Keyboard_SetReport; hid_param.HID_EpIn_Hdlr = Keyboard_EpIN_Hdlr; /* Init reports_data */ reports_data[0].len = Keyboard_ReportDescSize; reports_data[0].idle_time = 0; reports_data[0].desc = (uint8_t *) &Keyboard_ReportDescriptor[0]; hid_param.report_data = reports_data; ret = USBD_API->hid->init(hUsb, &hid_param); /* update memory variables */ *mem_base = hid_param.mem_base; *mem_size = hid_param.mem_size; /* store stack handle for later use. */ g_keyBoard.hUsb = hUsb; /* start the mouse timer */ ms_timerInit(&g_keyBoard.tmo, HID_KEYBRD_REPORT_INTERVAL_MS); return ret; }