📄 usblib.c
字号:
* usbDescrParse - search a buffer for the a particular USB descriptor** Searches <pBfr> up to <bfrLen> bytes for a descriptor of type matching* <descriptorType>. Returns a pointer to the descriptor if found. ** RETURNS: pointer to indicated descriptor, or NULL if descr not found*/pVOID usbDescrParse (pUINT8 pBfr, /* buffer to parse */ UINT16 bfrLen, /* length of buffer to parse */ UINT8 descriptorType /* type of descriptor being sought */ ){ return usbDescrParseSkip (&pBfr, &bfrLen, descriptorType);}/***************************************************************************** usbConfigCountGet - Retrieves number of device configurations** Using the <usbdClientHandle> provided by the caller, this function* reads the <nodeId>'s device descriptor and returns the number of * configurations supported by the device in <pNumConfig>.** RETURNS: OK, or ERROR if unable to read device descriptor*/STATUS usbConfigCountGet (USBD_CLIENT_HANDLE usbdClientHandle, /* caller's USBD client handle */ USBD_NODE_ID nodeId, /* device node ID */ pUINT16 pNumConfig /* bfr to receive nbr of config */ ){ USB_DEVICE_DESCR *pDevDescr; UINT16 actLen; if ((pDevDescr = OSS_MALLOC (USB_DEVICE_DESCR_LEN)) == NULL) return ERROR; /* Read the device descriptor to determine the number of configurations. */ if (usbdDescriptorGet (usbdClientHandle, nodeId, USB_RT_STANDARD | USB_RT_DEVICE, USB_DESCR_DEVICE, 0, 0, USB_DEVICE_DESCR_LEN, (UINT8 *) pDevDescr, &actLen) != OK || actLen < USB_DEVICE_DESCR_LEN) { OSS_FREE (pDevDescr); return ERROR; } if (pNumConfig) *pNumConfig = pDevDescr->numConfigurations; OSS_FREE (pDevDescr); return OK;}/***************************************************************************** usbConfigDescrGet - reads full configuration descriptor from device** This function reads the configuration descriptor <cfgNo> and all associated* descriptors (interface, endpoint, etc.) for the device specified by* <nodeId>. The total amount of data returned by a device is variable,* so, this function pre-reads just the configuration descriptor and uses* the "totalLength" field from that descriptor to determine the total* length of the configuration descriptor and its associated descriptors.** This function uses the macro OSS_MALLOC() to allocate a buffer for the* complete descriptor. The size and location of the buffer are returned* in <ppBfr and pBfrLen>. It is the caller's responsibility to free the* buffer using the OSS_FREE() macro.** RETURNS: OK, or ERROR if unable to read descriptor*/STATUS usbConfigDescrGet (USBD_CLIENT_HANDLE usbdClientHandle, /* caller's USBD client handle */ USBD_NODE_ID nodeId, /* device node ID */ UINT16 cfgNo, /* specifies configuration nbr */ pUINT16 pBfrLen, /* receives length of buffer */ pUINT8 * ppBfr /* receives pointer to buffer */ ){ USB_CONFIG_DESCR *pCfgDescr; UINT16 actLen; UINT16 totalLength; pUINT8 pBfr; if ((pCfgDescr = OSS_MALLOC (USB_CONFIG_DESCR_LEN)) == NULL) return ERROR; /* Validate parameters. ppBfr must be non-NULL */ if (ppBfr == NULL) return ERROR; *ppBfr = NULL; /* Read the configuration descriptor to determine the totalLengh of the * configuration. */ if (usbdDescriptorGet (usbdClientHandle, nodeId, USB_RT_STANDARD | USB_RT_DEVICE, USB_DESCR_CONFIGURATION, cfgNo, 0, USB_CONFIG_DESCR_LEN, (UINT8 *) pCfgDescr, &actLen) != OK || actLen < USB_CONFIG_DESCR_LEN) { OSS_FREE (pCfgDescr); return ERROR; } totalLength = FROM_LITTLEW (pCfgDescr->totalLength); OSS_FREE (pCfgDescr); if (pBfrLen != NULL) *pBfrLen = totalLength; /* Allocate a buffer of totalLength bytes. */ if ((pBfr = OSS_MALLOC (totalLength)) == NULL) return ERROR; /* Read the full configuration descriptor. */ if (usbdDescriptorGet (usbdClientHandle, nodeId, USB_RT_STANDARD | USB_RT_DEVICE, USB_DESCR_CONFIGURATION, cfgNo, 0, totalLength, pBfr, NULL) != OK) { OSS_FREE (pBfr); return ERROR; } *ppBfr = pBfr; return OK;}/***************************************************************************** usbHidReportSet - Issues a SET_REPORT request to a USB HID** Using the <usbdClientHandle> provided by the caller, this function * issues a SET_REPORT request to the indicated <nodeId>. The caller* must also specify the <interface>, <reportType>, <reportId>, <reportBfr>,* and <reportLen>. Refer to Section 7.2.2 of the USB HID specification* for further detail.** RETURNS: OK, or ERROR if unable to issue SET_REPORT request.*/STATUS usbHidReportSet (USBD_CLIENT_HANDLE usbdClientHandle, /* caller's USBD client handle */ USBD_NODE_ID nodeId, /* desired node */ UINT16 interface, /* desired interface */ UINT16 reportType, /* report type */ UINT16 reportId, /* report Id */ pUINT8 reportBfr, /* report value */ UINT16 reportLen /* length of report */ ){ UINT16 actLen; if (usbdVendorSpecific (usbdClientHandle, nodeId, USB_RT_HOST_TO_DEV | USB_RT_CLASS | USB_RT_INTERFACE, USB_REQ_HID_SET_REPORT, (reportType << 8) | reportId, interface, reportLen, reportBfr, &actLen) != OK || actLen < reportLen) return ERROR; return OK;}/***************************************************************************** usbHidIdleSet - Issues a SET_IDLE request to a USB HID** Using the <usbdClientHandle> provided by the caller, this function* issues a SET_IDLE request to the indicated <nodeId>. The caller must* also specify the <interface>, <reportId>, and <duration>. If the * <duration> is zero, the idle period is infinite. If <duration> is* non-zero, then it expresses time in 4msec units (e.g., a <duration>* of 1 = 4msec, 2 = 8msec, and so forth). Refer to Section 7.2.4 of the * USB HID specification for further details.** RETURNS: OK, or ERROR if unable to issue SET_IDLE request.*/STATUS usbHidIdleSet (USBD_CLIENT_HANDLE usbdClientHandle, /* caller's USBD client handle */ USBD_NODE_ID nodeId, /* desired node */ UINT16 interface, /* desired interface */ UINT16 reportId, /* desired report */ UINT16 duration /* idle duration */ ){ return usbdVendorSpecific (usbdClientHandle, nodeId, USB_RT_HOST_TO_DEV | USB_RT_CLASS | USB_RT_INTERFACE, USB_REQ_HID_SET_IDLE, (duration << 8) | reportId, interface, 0, NULL, NULL);}/***************************************************************************** usbHidProtocolSet - Issues a SET_PROTOCOL request to a USB HID** Using the <usbdClientHandle> provided by the caller, this function* issues a SET_PROTOCOL request to the indicated <nodeId>. The caller* must specify the <interface> and the desired <protocol>. The <protocol>* is expressed as USB_HID_PROTOCOL_xxxx. Refer to Section 7.2.6 of the* USB HID specification for further details.** RETURNS: OK, or ERROR if unable to issue SET_PROTOCOL request.*/STATUS usbHidProtocolSet (USBD_CLIENT_HANDLE usbdClientHandle, /* caller's USBD client handle */ USBD_NODE_ID nodeId, /* desired node */ UINT16 interface, /* desired interface */ UINT16 protocol /* USB_HID_PROTOCOL_xxxx */ ){ return usbdVendorSpecific (usbdClientHandle, nodeId, USB_RT_HOST_TO_DEV | USB_RT_CLASS | USB_RT_INTERFACE, USB_REQ_HID_SET_PROTOCOL, protocol, interface, 0, NULL, NULL);}/* End of file. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -