38#define USB_TIMEOUT 100000
41extern int find_hid_device(
HID_DEV_T *hdev);
42extern EP_INFO_T *hid_get_ep_info(
USB_DEV_T *dev,
int ifnum, uint16_t dir);
45static int usb_snd_control_msg(
HID_DEV_T *hdev,
int requesttype,
int request,
46 int value,
int index,
char *bytes,
int size,
int timeout)
51 request, requesttype,
value, index, bytes, size, timeout);
54int usb_rcv_control_msg(
HID_DEV_T *hdev,
int requesttype,
int request,
55 int value,
int index,
char *bytes,
int size,
int timeout)
60 request, requesttype,
value, index, bytes, size, timeout);
83 len = usb_rcv_control_msg(hdev,
85 USB_REQ_GET_DESCRIPTOR,
86 (USB_DT_HID << 8) + 0, hdev->
ifnum,
87 (
char*)desc_buf, buf_max_len,
92 HID_DBGMSG(
"failed to get HID descriptor.\n");
96 len = desc_buf[7] | (desc_buf[8] << 8);
98 HID_DBGMSG(
"Report descriptor size is %d\n", len);
100 if (buf_max_len < len)
103 len = usb_rcv_control_msg(hdev,
105 USB_REQ_GET_DESCRIPTOR,
106 (USB_DT_REPORT << 8) + 0, hdev->
ifnum,
107 (
char*)desc_buf, len,
112 HID_DBGMSG(
"failed to get HID descriptor.\n");
116 HID_DBGMSG(
"successfully initialised HID descriptor %d bytes.\n", len);
139 uint8_t *data,
int len)
141 len = usb_rcv_control_msg(hdev,
142 USB_DIR_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
144 rtp_id + (rtp_typ << 8),
146 (
char *)data, len, USB_TIMEOUT);
150 HID_DBGMSG(
"failed to get report!\n");
175 uint8_t *data,
int len)
177 len = usb_snd_control_msg(hdev,
178 USB_DIR_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
180 rtp_id + (rtp_typ << 8),
182 (
char *)data, len, USB_TIMEOUT);
186 HID_DBGMSG(
"failed to set report!\n");
208 len = usb_rcv_control_msg(hdev,
209 USB_DIR_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
213 (
char *)idle_rate, 1, USB_TIMEOUT);
217 HID_DBGMSG(
"failed to get idle rate! %d\n", len);
239 uint16_t wValue = idle_rate;
241 ret = usb_snd_control_msg(hdev,
242 USB_DIR_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
244 rtp_id + (wValue << 8),
246 NULL, 0, USB_TIMEOUT);
250 HID_DBGMSG(
"failed to set idle rate! %d\n", ret);
272 len = usb_rcv_control_msg(hdev,
273 USB_DIR_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
277 (
char *)protocol, 1, USB_TIMEOUT);
281 HID_DBGMSG(
"failed to get protocol! %d\n", len);
303 ret = usb_snd_control_msg(hdev,
304 USB_DIR_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
308 NULL, 0, USB_TIMEOUT);
312 HID_DBGMSG(
"failed to set protocol! %d\n", ret);
324static void hid_read_irq(
URB_T *urb)
330 hdev = find_hid_deivce_by_urb(urb);
336 HID_DBGMSG(
"hid_read_irq - has error: 0x%x\n", urb->
status);
347static void hid_write_irq(
URB_T *urb)
353 hdev = find_hid_deivce_by_urb(urb);
359 HID_DBGMSG(
"hid_write_irq - has error: 0x%x\n", urb->
status);
394 ep_info = hid_get_ep_info(udev, hdev->
ifnum, USB_DIR_IN);
397 HID_DBGMSG(
"Interrupt-in endpoint not found in this device!\n");
404 HID_DBGMSG(
"Failed to allocated URB!\n");
408 pipe = usb_rcvintpipe(udev, ep_info->bEndpointAddress);
409 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
411 HID_DBGMSG(
"Endpoint 0x%x maximum packet size is %d.\n", ep_info->bEndpointAddress, maxp);
413 FILL_INT_URB(urb, udev, pipe, &hdev->
inbuf[0], maxp, hid_read_irq,
414 hdev, ep_info->bInterval);
422 HID_DBGMSG(
"Error - failed to submit interrupt read request (%d)", ret);
455 ep_info = hid_get_ep_info(hdev->
udev, hdev->
ifnum, USB_DIR_OUT);
458 HID_DBGMSG(
"Assigned endpoint address 0x%x not found in this device!\n", ep_info->bEndpointAddress);
465 HID_DBGMSG(
"Failed to allocated URB!\n");
469 pipe = usb_sndintpipe(udev, ep_info->bEndpointAddress);
470 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
472 HID_DBGMSG(
"Endpoint 0x%x maximum packet size is %d.\n", ep_info->bEndpointAddress, maxp);
474 FILL_INT_URB(urb, udev, pipe,
NULL, maxp, hid_write_irq,
475 hdev, ep_info->bInterval);
485 HID_DBGMSG(
"Error - failed to submit interrupt read request (%d)", ret);
NUC472/NUC442 peripheral access layer header file. This file contains all the peripheral register's d...
int32_t USBH_SubmitUrb(URB_T *urb)
Submit an URB to USB core for transfer data.
int transfer_buffer_length
URB_T * USBH_AllocUrb(void)
Allocate an URB from USB Core driver internal URB pool.
void USBH_FreeUrb(URB_T *)
Free the URB allocated from USBH_AllocUrb()
int32_t USBH_SendCtrlMsg(USB_DEV_T *dev, uint32_t pipe, uint8_t request, uint8_t requesttype, uint16_t value, uint16_t index, void *data, uint16_t size, int timeout)
Execute a control transfer.
HIDDEN_SYMBOLS struct usb_device USB_DEV_T
#define HID_RET_INVALID_PARAMETER
#define HID_RET_NOT_SUPPORTED
#define HID_RET_OUT_OF_MEMORY
int32_t USBH_HidStartIntReadPipe(HID_DEV_T *hdev, HID_IR_FUNC *func)
Start purge the USB interrupt in transfer.
int32_t HID_HidGetProtocol(HID_DEV_T *hdev, uint8_t *protocol)
HID class standard request Get_Protocol request. The Get_Protocol request reads which protocol is cur...
int32_t HID_HidGetReportDescriptor(HID_DEV_T *hdev, uint8_t *desc_buf, int buf_max_len)
Get report descriptor request.
int32_t HID_HidGetIdle(HID_DEV_T *hdev, int rtp_id, uint8_t *idle_rate)
HID class standard request Get_Idle request. The Get_Idle request reads the current idle rate for a p...
int32_t HID_HidSetIdle(HID_DEV_T *hdev, int rtp_id, uint8_t idle_rate)
HID class standard request Set_Idle request. The Set_Idle request silences a particular report on the...
uint8_t inbuf[HID_MAX_BUFFER_SIZE]
int32_t USBH_HidStartIntWritePipe(HID_DEV_T *hdev, HID_IW_FUNC *func)
Start purge the USB interrupt out transfer.
int32_t HID_HidGetReport(HID_DEV_T *hdev, int rtp_typ, int rtp_id, uint8_t *data, int len)
HID class standard request Get_Report request. The Get_Report request allows the host to receive a re...
int32_t HID_HidSetReport(HID_DEV_T *hdev, int rtp_typ, int rtp_id, uint8_t *data, int len)
HID class standard request Set_Report request. The Set_Report request allows the host to send a repor...
int32_t HID_HidSetProtocol(HID_DEV_T *hdev, uint8_t protocol)
HID class standard request Set_Protocol request. The Set_Protocol switches between the boot protocol ...
void() HID_IR_FUNC(struct usbhid_dev *hdev, uint8_t *rdata, int data_len)
void() HID_IW_FUNC(struct usbhid_dev *hdev, uint8_t **wbuff, int *buff_size)
#define NULL
NULL pointer.
USB Host core driver header file.