usbd_dfu.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @file usbd_dfu.c
  3. * @brief
  4. *
  5. * Copyright (c) 2022 sakumisu
  6. *
  7. * Licensed to the Apache Software Foundation (ASF) under one or more
  8. * contributor license agreements. See the NOTICE file distributed with
  9. * this work for additional information regarding copyright ownership. The
  10. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  11. * "License"); you may not use this file except in compliance with the
  12. * License. You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  18. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  19. * License for the specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. */
  23. #include "usbd_core.h"
  24. #include "usbd_dfu.h"
  25. /* Device data structure */
  26. struct dfu_cfg_priv {
  27. struct dfu_info info;
  28. } usbd_dfu_cfg;
  29. static int dfu_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
  30. {
  31. USB_LOG_WRN("DFU Class request: "
  32. "bRequest 0x%02x\r\n",
  33. setup->bRequest);
  34. switch (setup->bRequest) {
  35. case DFU_REQUEST_DETACH:
  36. break;
  37. case DFU_REQUEST_DNLOAD:
  38. break;
  39. case DFU_REQUEST_UPLOAD:
  40. break;
  41. case DFU_REQUEST_GETSTATUS:
  42. break;
  43. case DFU_REQUEST_CLRSTATUS:
  44. break;
  45. case DFU_REQUEST_GETSTATE:
  46. break;
  47. case DFU_REQUEST_ABORT:
  48. break;
  49. default:
  50. USB_LOG_WRN("Unhandled DFU Class bRequest 0x%02x\r\n", setup->bRequest);
  51. return -1;
  52. }
  53. return 0;
  54. }
  55. static void dfu_notify_handler(uint8_t event, void *arg)
  56. {
  57. switch (event) {
  58. case USBD_EVENT_RESET:
  59. break;
  60. default:
  61. break;
  62. }
  63. }
  64. void usbd_dfu_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
  65. {
  66. static usbd_class_t *last_class = NULL;
  67. if (last_class != devclass) {
  68. last_class = devclass;
  69. usbd_class_register(devclass);
  70. }
  71. intf->class_handler = dfu_class_request_handler;
  72. intf->custom_handler = NULL;
  73. intf->vendor_handler = NULL;
  74. intf->notify_handler = dfu_notify_handler;
  75. usbd_class_add_interface(devclass, intf);
  76. }