usbd_video.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * @file usbd_video.c
  3. *
  4. * Copyright (c) 2021 Bouffalolab team
  5. *
  6. * Licensed to the Apache Software Foundation (ASF) under one or more
  7. * contributor license agreements. See the NOTICE file distributed with
  8. * this work for additional information regarding copyright ownership. The
  9. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance with the
  11. * License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  17. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  18. * License for the specific language governing permissions and limitations
  19. * under the License.
  20. *
  21. */
  22. #include "usbd_core.h"
  23. #include "usbd_video.h"
  24. extern struct video_probe_and_commit_controls probe;
  25. extern struct video_probe_and_commit_controls commit;
  26. int video_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
  27. {
  28. USBD_LOG_DBG("Class request:"
  29. "bRequest 0x%02x, bmRequestType 0x%02x len %d",
  30. setup->bRequest, setup->bmRequestType, *len);
  31. switch (setup->bRequest) {
  32. case VIDEO_REQUEST_SET_CUR:
  33. if (setup->wValue == 256) {
  34. memcpy((uint8_t *)&probe, *data, setup->wLength);
  35. } else if (setup->wValue == 512) {
  36. memcpy((uint8_t *)&commit, *data, setup->wLength);
  37. }
  38. break;
  39. case VIDEO_REQUEST_GET_CUR:
  40. if (setup->wValue == 256) {
  41. *data = (uint8_t *)&probe;
  42. } else if (setup->wValue == 512) {
  43. *data = (uint8_t *)&commit;
  44. }
  45. break;
  46. case VIDEO_REQUEST_GET_MIN:
  47. if (setup->wValue == 256) {
  48. *data = (uint8_t *)&probe;
  49. } else if (setup->wValue == 512) {
  50. *data = (uint8_t *)&commit;
  51. }
  52. break;
  53. case VIDEO_REQUEST_GET_MAX:
  54. if (setup->wValue == 256) {
  55. *data = (uint8_t *)&probe;
  56. } else if (setup->wValue == 512) {
  57. *data = (uint8_t *)&commit;
  58. }
  59. break;
  60. case VIDEO_REQUEST_GET_RES:
  61. break;
  62. case VIDEO_REQUEST_GET_LEN:
  63. break;
  64. case VIDEO_REQUEST_GET_INFO:
  65. break;
  66. case VIDEO_REQUEST_GET_DEF:
  67. if (setup->wLength == 256) {
  68. *data = (uint8_t *)&probe;
  69. } else if (setup->wLength == 512) {
  70. *data = (uint8_t *)&commit;
  71. }
  72. break;
  73. default:
  74. USBD_LOG_ERR("Unhandled request 0x%02x", setup->bRequest);
  75. break;
  76. }
  77. return 0;
  78. }
  79. void video_notify_handler(uint8_t event, void *arg)
  80. {
  81. switch (event) {
  82. case USB_EVENT_RESET:
  83. break;
  84. case USB_EVENT_SOF:
  85. usbd_video_sof_callback();
  86. break;
  87. case USB_EVENT_SET_INTERFACE:
  88. usbd_video_set_interface_callback(((uint8_t *)arg)[3]);
  89. break;
  90. default:
  91. break;
  92. }
  93. }
  94. void usbd_video_add_interface(usbd_class_t *class, usbd_interface_t *intf)
  95. {
  96. static usbd_class_t *last_class = NULL;
  97. if (last_class != class) {
  98. last_class = class;
  99. usbd_class_register(class);
  100. }
  101. intf->class_handler = video_class_request_handler;
  102. intf->custom_handler = NULL;
  103. intf->vendor_handler = NULL;
  104. intf->notify_handler = video_notify_handler;
  105. usbd_class_add_interface(class, intf);
  106. }