42#define USB_TIMEOUT 100000
45extern int find_hid_device(
HID_DEV_T *hdev);
46extern EP_INFO_T *hid_get_ep_info(
USB_DEV_T *dev,
int ifnum, uint16_t dir);
49static int usb_snd_control_msg(
HID_DEV_T *hdev,
int requesttype,
int request,
50 int value,
int index,
char *bytes,
int size,
int timeout)
55 request, requesttype,
value, index, bytes, size, timeout);
58int usb_rcv_control_msg(
HID_DEV_T *hdev,
int requesttype,
int request,
59 int value,
int index,
char *bytes,
int size,
int timeout)
64 request, requesttype,
value, index, bytes, size, timeout);
87 len = usb_rcv_control_msg(hdev,
89 USB_REQ_GET_DESCRIPTOR,
90 (USB_DT_HID << 8) + 0, hdev->
ifnum,
91 (
char*)desc_buf, buf_max_len,
96 HID_DBGMSG(
"failed to get HID descriptor.\n");
100 len = desc_buf[7] | (desc_buf[8] << 8);
102 HID_DBGMSG(
"Report descriptor size is %d\n", len);
104 if (buf_max_len < len)
107 len = usb_rcv_control_msg(hdev,
109 USB_REQ_GET_DESCRIPTOR,
110 (USB_DT_REPORT << 8) + 0, hdev->
ifnum,
111 (
char*)desc_buf, len,
116 HID_DBGMSG(
"failed to get HID descriptor.\n");
120 HID_DBGMSG(
"successfully initialised HID descriptor %d bytes.\n", len);
143 uint8_t *data,
int len)
145 len = usb_rcv_control_msg(hdev,
146 USB_DIR_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
148 rtp_id + (rtp_typ << 8),
150 (
char *)data, len, USB_TIMEOUT);
154 HID_DBGMSG(
"failed to get report!\n");
179 uint8_t *data,
int len)
181 len = usb_snd_control_msg(hdev,
182 USB_DIR_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
184 rtp_id + (rtp_typ << 8),
186 (
char *)data, len, USB_TIMEOUT);
190 HID_DBGMSG(
"failed to set report!\n");
212 len = usb_rcv_control_msg(hdev,
213 USB_DIR_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
217 (
char *)idle_rate, 1, USB_TIMEOUT);
221 HID_DBGMSG(
"failed to get idle rate! %d\n", len);
243 uint16_t wValue = idle_rate;
245 ret = usb_snd_control_msg(hdev,
246 USB_DIR_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
248 rtp_id + (wValue << 8),
250 NULL, 0, USB_TIMEOUT);
254 HID_DBGMSG(
"failed to set idle rate! %d\n", ret);
276 len = usb_rcv_control_msg(hdev,
277 USB_DIR_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
281 (
char *)protocol, 1, USB_TIMEOUT);
285 HID_DBGMSG(
"failed to get protocol! %d\n", len);
306 ret = usb_snd_control_msg(hdev,
307 USB_DIR_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
311 NULL, 0, USB_TIMEOUT);
315 HID_DBGMSG(
"failed to set protocol! %d\n", ret);
326static void hid_read_irq(
URB_T *urb)
332 hdev = find_hid_deivce_by_urb(urb);
338 HID_DBGMSG(
"hid_read_irq - has error: 0x%x\n", urb->
status);
349static void hid_write_irq(
URB_T *urb)
355 hdev = find_hid_deivce_by_urb(urb);
361 HID_DBGMSG(
"hid_write_irq - has error: 0x%x\n", urb->
status);
396 ep_info = hid_get_ep_info(udev, hdev->
ifnum, USB_DIR_IN);
399 HID_DBGMSG(
"Interrupt-in endpoint not found in this device!\n");
406 HID_DBGMSG(
"Failed to allocated URB!\n");
410 pipe = usb_rcvintpipe(udev, ep_info->bEndpointAddress);
411 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
413 HID_DBGMSG(
"Endpoint 0x%x maximum packet size is %d.\n", ep_info->bEndpointAddress, maxp);
415 FILL_INT_URB(urb, udev, pipe, &hdev->
inbuf[0], maxp, hid_read_irq,
416 hdev, ep_info->bInterval);
424 HID_DBGMSG(
"Error - failed to submit interrupt read request (%d)", ret);
457 ep_info = hid_get_ep_info(hdev->
udev, hdev->
ifnum, USB_DIR_OUT);
460 HID_DBGMSG(
"Assigned endpoint address 0x%x not found in this device!\n", ep_info->bEndpointAddress);
467 HID_DBGMSG(
"Failed to allocated URB!\n");
471 pipe = usb_sndintpipe(udev, ep_info->bEndpointAddress);
472 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
474 HID_DBGMSG(
"Endpoint 0x%x maximum packet size is %d.\n", ep_info->bEndpointAddress, maxp);
476 FILL_INT_URB(urb, udev, pipe,
NULL, maxp, hid_write_irq,
477 hdev, ep_info->bInterval);
487 HID_DBGMSG(
"Error - failed to submit interrupt read request (%d)", ret);
URB_T * USBH_AllocUrb(void)
Allocate an URB from USB Core driver internal URB pool.
int32_t USBH_SubmitUrb(URB_T *urb)
Submit an URB to USB core for transfer data.
int transfer_buffer_length
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.
#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)
USB Host core driver header file.
HIDDEN_SYMBOLS struct usb_device USB_DEV_T