usbd_printer.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @file usbd_printer.h
  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_printer.h"
  25. /* Device data structure */
  26. struct printer_cfg_priv {
  27. uint8_t *device_id;
  28. uint8_t port_status;
  29. } usbd_printer_cfg;
  30. /**
  31. * @brief Handler called for Class requests not handled by the USB stack.
  32. *
  33. * @param setup Information about the request to execute.
  34. * @param len Size of the buffer.
  35. * @param data Buffer containing the request result.
  36. *
  37. * @return 0 on success, negative errno code on fail.
  38. */
  39. static int printer_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
  40. {
  41. USB_LOG_DBG("Printer Class request: "
  42. "bRequest 0x%02x\r\n",
  43. setup->bRequest);
  44. switch (setup->bRequest) {
  45. case PRINTER_REQUEST_GET_DEVICE_ID:
  46. break;
  47. case PRINTER_REQUEST_GET_PORT_SATTUS:
  48. break;
  49. case PRINTER_REQUEST_SOFT_RESET:
  50. break;
  51. default:
  52. USB_LOG_WRN("Unhandled Printer Class bRequest 0x%02x\r\n", setup->bRequest);
  53. return -1;
  54. }
  55. return 0;
  56. }
  57. static void printer_notify_handler(uint8_t event, void *arg)
  58. {
  59. switch (event) {
  60. case USBD_EVENT_RESET:
  61. break;
  62. default:
  63. break;
  64. }
  65. }
  66. void usbd_printer_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
  67. {
  68. static usbd_class_t *last_class = NULL;
  69. if (last_class != devclass) {
  70. last_class = devclass;
  71. usbd_class_register(devclass);
  72. }
  73. intf->class_handler = printer_class_request_handler;
  74. intf->custom_handler = NULL;
  75. intf->vendor_handler = NULL;
  76. intf->notify_handler = printer_notify_handler;
  77. usbd_class_add_interface(devclass, intf);
  78. }