usbd_printer.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2022, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "usbd_core.h"
  7. #include "usbd_printer.h"
  8. struct usbd_printer_priv {
  9. const uint8_t *device_id;
  10. uint8_t device_id_len;
  11. uint8_t port_status;
  12. } g_usbd_printer;
  13. static int printer_class_interface_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
  14. {
  15. USB_LOG_DBG("Printer Class request: "
  16. "bRequest 0x%02x\r\n",
  17. setup->bRequest);
  18. switch (setup->bRequest) {
  19. case PRINTER_REQUEST_GET_DEVICE_ID:
  20. memcpy(*data, g_usbd_printer.device_id, g_usbd_printer.device_id_len);
  21. *len = g_usbd_printer.device_id_len;
  22. break;
  23. case PRINTER_REQUEST_GET_PORT_SATTUS:
  24. break;
  25. case PRINTER_REQUEST_SOFT_RESET:
  26. break;
  27. default:
  28. USB_LOG_WRN("Unhandled Printer Class bRequest 0x%02x\r\n", setup->bRequest);
  29. return -1;
  30. }
  31. return 0;
  32. }
  33. static void printer_notify_handler(uint8_t event, void *arg)
  34. {
  35. switch (event) {
  36. case USBD_EVENT_RESET:
  37. break;
  38. default:
  39. break;
  40. }
  41. }
  42. struct usbd_interface *usbd_printer_init_intf(struct usbd_interface *intf, const uint8_t *device_id, uint8_t device_id_len)
  43. {
  44. intf->class_interface_handler = printer_class_interface_request_handler;
  45. intf->class_endpoint_handler = NULL;
  46. intf->vendor_handler = NULL;
  47. intf->notify_handler = printer_notify_handler;
  48. g_usbd_printer.device_id = device_id;
  49. g_usbd_printer.device_id_len = device_id_len;
  50. return intf;
  51. }