This repository has been archived on 2023-07-17. You can view files and clone it, but cannot push or open issues or pull requests.
bl_mcu_sdk/components/usb_stack/class/video/usbd_video.c

134 lines
3.8 KiB
C
Raw Normal View History

2021-04-13 19:23:11 +08:00
/**
* @file usbd_video.c
2021-06-20 12:25:46 +08:00
*
2021-04-13 19:23:11 +08:00
* Copyright (c) 2021 Bouffalolab team
2021-06-20 12:25:46 +08:00
*
2021-04-13 19:23:11 +08:00
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
2021-06-20 12:25:46 +08:00
*
2021-04-13 19:23:11 +08:00
* http://www.apache.org/licenses/LICENSE-2.0
2021-06-20 12:25:46 +08:00
*
2021-04-13 19:23:11 +08:00
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
2021-06-20 12:25:46 +08:00
*
2021-04-13 19:23:11 +08:00
*/
#include "usbd_core.h"
#include "usbd_video.h"
2021-06-04 17:51:38 +08:00
extern struct video_probe_and_commit_controls probe;
extern struct video_probe_and_commit_controls commit;
2021-04-13 19:23:11 +08:00
int video_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
{
USBD_LOG_DBG("Class request:"
"bRequest 0x%02x, bmRequestType 0x%02x len %d",
setup->bRequest, setup->bmRequestType, *len);
2021-06-20 12:25:46 +08:00
switch (setup->bRequest) {
2021-04-13 19:23:11 +08:00
case VIDEO_REQUEST_SET_CUR:
2021-06-20 12:25:46 +08:00
if (setup->wValue == 256) {
memcpy((uint8_t *)&probe, *data, setup->wLength);
} else if (setup->wValue == 512) {
memcpy((uint8_t *)&commit, *data, setup->wLength);
}
2021-04-13 19:23:11 +08:00
break;
2021-06-20 12:25:46 +08:00
2021-04-13 19:23:11 +08:00
case VIDEO_REQUEST_GET_CUR:
2021-06-20 12:25:46 +08:00
if (setup->wValue == 256) {
2021-04-13 19:23:11 +08:00
*data = (uint8_t *)&probe;
2021-06-20 12:25:46 +08:00
} else if (setup->wValue == 512) {
2021-04-13 19:23:11 +08:00
*data = (uint8_t *)&commit;
2021-06-20 12:25:46 +08:00
}
2021-04-13 19:23:11 +08:00
break;
2021-06-20 12:25:46 +08:00
2021-04-13 19:23:11 +08:00
case VIDEO_REQUEST_GET_MIN:
2021-06-20 12:25:46 +08:00
if (setup->wValue == 256) {
2021-04-13 19:23:11 +08:00
*data = (uint8_t *)&probe;
2021-06-20 12:25:46 +08:00
} else if (setup->wValue == 512) {
2021-04-13 19:23:11 +08:00
*data = (uint8_t *)&commit;
2021-06-20 12:25:46 +08:00
}
2021-04-13 19:23:11 +08:00
break;
2021-06-20 12:25:46 +08:00
2021-04-13 19:23:11 +08:00
case VIDEO_REQUEST_GET_MAX:
2021-06-20 12:25:46 +08:00
if (setup->wValue == 256) {
2021-04-13 19:23:11 +08:00
*data = (uint8_t *)&probe;
2021-06-20 12:25:46 +08:00
} else if (setup->wValue == 512) {
2021-04-13 19:23:11 +08:00
*data = (uint8_t *)&commit;
2021-06-20 12:25:46 +08:00
}
2021-04-13 19:23:11 +08:00
break;
2021-06-20 12:25:46 +08:00
2021-04-13 19:23:11 +08:00
case VIDEO_REQUEST_GET_RES:
break;
2021-06-20 12:25:46 +08:00
2021-04-13 19:23:11 +08:00
case VIDEO_REQUEST_GET_LEN:
break;
2021-06-20 12:25:46 +08:00
2021-04-13 19:23:11 +08:00
case VIDEO_REQUEST_GET_INFO:
break;
2021-06-20 12:25:46 +08:00
2021-04-13 19:23:11 +08:00
case VIDEO_REQUEST_GET_DEF:
2021-06-20 12:25:46 +08:00
if (setup->wLength == 256) {
2021-04-13 19:23:11 +08:00
*data = (uint8_t *)&probe;
2021-06-20 12:25:46 +08:00
} else if (setup->wLength == 512) {
2021-04-13 19:23:11 +08:00
*data = (uint8_t *)&commit;
2021-06-20 12:25:46 +08:00
}
2021-04-13 19:23:11 +08:00
break;
2021-06-20 12:25:46 +08:00
2021-04-13 19:23:11 +08:00
default:
USBD_LOG_ERR("Unhandled request 0x%02x", setup->bRequest);
break;
}
2021-06-20 12:25:46 +08:00
2021-04-13 19:23:11 +08:00
return 0;
}
2021-06-04 17:51:38 +08:00
2021-06-20 12:25:46 +08:00
void video_notify_handler(uint8_t event, void *arg)
2021-04-13 19:23:11 +08:00
{
2021-06-20 12:25:46 +08:00
switch (event) {
case USB_EVENT_RESET:
break;
2021-06-04 17:51:38 +08:00
2021-06-20 12:25:46 +08:00
case USB_EVENT_SOF:
2021-06-04 17:51:38 +08:00
usbd_video_sof_callback();
2021-06-20 12:25:46 +08:00
break;
case USB_EVENT_SET_INTERFACE:
usbd_video_set_interface_callback(((uint8_t *)arg)[3]);
break;
default:
break;
}
2021-04-13 19:23:11 +08:00
}
2021-06-04 17:51:38 +08:00
void usbd_video_add_interface(usbd_class_t *class, usbd_interface_t *intf)
2021-04-13 19:23:11 +08:00
{
2021-06-20 12:25:46 +08:00
static usbd_class_t *last_class = NULL;
if (last_class != class) {
last_class = class;
usbd_class_register(class);
}
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(class, intf);
2021-04-13 19:23:11 +08:00
}