refactor usb device intf and ep register
This commit is contained in:
@@ -17,12 +17,8 @@ struct usbd_video_cfg_priv {
|
||||
struct video_probe_and_commit_controls commit;
|
||||
uint8_t power_mode;
|
||||
uint8_t error_code;
|
||||
uint8_t vcintf;
|
||||
uint8_t vsintf;
|
||||
struct video_entity_info info[3];
|
||||
} usbd_video_cfg = {
|
||||
.vcintf = 0xff,
|
||||
.vsintf = 0xff,
|
||||
.info[0] = { .bDescriptorSubtype = VIDEO_VC_INPUT_TERMINAL_DESCRIPTOR_SUBTYPE, .bEntityId = 0x01, .wTerminalType = VIDEO_ITT_CAMERA },
|
||||
.info[1] = { .bDescriptorSubtype = VIDEO_VC_OUTPUT_TERMINAL_DESCRIPTOR_SUBTYPE, .bEntityId = 0x03, .wTerminalType = 0x00 },
|
||||
.info[2] = { .bDescriptorSubtype = VIDEO_VC_PROCESSING_UNIT_DESCRIPTOR_SUBTYPE, .bEntityId = 0x02, .wTerminalType = 0x00 },
|
||||
@@ -672,13 +668,13 @@ static int video_class_request_handler(struct usb_setup_packet *setup, uint8_t *
|
||||
uint8_t intf_num = (uint8_t)setup->wIndex;
|
||||
uint8_t entity_id = (uint8_t)(setup->wIndex >> 8);
|
||||
|
||||
if (usbd_video_cfg.vcintf == intf_num) { /* Video Control Interface */
|
||||
if (intf_num == 0) { /* Video Control Interface */
|
||||
if (entity_id == 0) {
|
||||
return usbd_video_control_request_handler(setup, data, len); /* Interface Control Requests */
|
||||
} else {
|
||||
return usbd_video_control_unit_terminal_request_handler(setup, data, len); /* Unit and Terminal Requests */
|
||||
}
|
||||
} else if (usbd_video_cfg.vsintf == intf_num) { /* Video Stream Inteface */
|
||||
} else if (intf_num == 1) { /* Video Stream Inteface */
|
||||
return usbd_video_stream_request_handler(setup, data, len); /* Interface Stream Requests */
|
||||
}
|
||||
return -1;
|
||||
@@ -707,21 +703,6 @@ static void video_notify_handler(uint8_t event, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_video_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
{
|
||||
intf->class_handler = video_class_request_handler;
|
||||
intf->custom_handler = NULL;
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = video_notify_handler;
|
||||
usbd_class_add_interface(devclass, intf);
|
||||
|
||||
if (usbd_video_cfg.vcintf == 0xff) {
|
||||
usbd_video_cfg.vcintf = intf->intf_num;
|
||||
} else if (usbd_video_cfg.vsintf == 0xff) {
|
||||
usbd_video_cfg.vsintf = intf->intf_num;
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_video_probe_and_commit_controls_init(uint32_t dwFrameInterval, uint32_t dwMaxVideoFrameSize, uint32_t dwMaxPayloadTransferSize)
|
||||
{
|
||||
usbd_video_cfg.probe.hintUnion.bmHint = 0x01;
|
||||
@@ -761,6 +742,23 @@ void usbd_video_probe_and_commit_controls_init(uint32_t dwFrameInterval, uint32_
|
||||
usbd_video_cfg.commit.bMaxVersion = 0;
|
||||
}
|
||||
|
||||
struct usbd_interface *usbd_video_alloc_intf(uint32_t dwFrameInterval, uint32_t dwMaxVideoFrameSize, uint32_t dwMaxPayloadTransferSize)
|
||||
{
|
||||
struct usbd_interface *intf = usb_malloc(sizeof(struct usbd_interface));
|
||||
if (intf == NULL) {
|
||||
USB_LOG_ERR("no mem to alloc intf\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
intf->class_handler = video_class_request_handler;
|
||||
intf->custom_handler = NULL;
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = video_notify_handler;
|
||||
|
||||
usbd_video_probe_and_commit_controls_init(dwFrameInterval, dwMaxVideoFrameSize, dwMaxPayloadTransferSize);
|
||||
return intf;
|
||||
}
|
||||
|
||||
uint32_t usbd_video_mjpeg_payload_fill(uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len)
|
||||
{
|
||||
uint32_t packets;
|
||||
|
||||
@@ -12,11 +12,13 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void usbd_video_add_interface(usbd_class_t *devclass, usbd_interface_t *intf);
|
||||
/* Alloc video interface driver */
|
||||
struct usbd_interface *usbd_video_alloc_intf(uint32_t dwFrameInterval,
|
||||
uint32_t dwMaxVideoFrameSize,
|
||||
uint32_t dwMaxPayloadTransferSize);
|
||||
|
||||
void usbd_video_open(uint8_t intf);
|
||||
void usbd_video_close(uint8_t intf);
|
||||
void usbd_video_probe_and_commit_controls_init(uint32_t dwFrameInterval, uint32_t dwMaxVideoFrameSize, uint32_t dwMaxPayloadTransferSize);
|
||||
uint32_t usbd_video_mjpeg_payload_fill(uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len);
|
||||
void usbd_video_mjpeg_payload_header_toggle(uint8_t *output, uint32_t packets);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user