• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
9 struct usbd_printer_priv {
10     const uint8_t *device_id;
11     uint8_t device_id_len;
12     uint8_t port_status;
13 } g_usbd_printer;
14 
printer_class_interface_request_handler(struct usb_setup_packet * setup,uint8_t ** data,uint32_t * len)15 static int printer_class_interface_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
16 {
17     USB_LOG_DBG("Printer Class request: "
18                 "bRequest 0x%02x\r\n",
19                 setup->bRequest);
20 
21     switch (setup->bRequest) {
22         case PRINTER_REQUEST_GET_DEVICE_ID:
23             memcpy(*data, g_usbd_printer.device_id, g_usbd_printer.device_id_len);
24             *len = g_usbd_printer.device_id_len;
25             break;
26         case PRINTER_REQUEST_GET_PORT_SATTUS:
27 
28             break;
29         case PRINTER_REQUEST_SOFT_RESET:
30 
31             break;
32         default:
33             USB_LOG_WRN("Unhandled Printer Class bRequest 0x%02x\r\n", setup->bRequest);
34             return -1;
35     }
36 
37     return 0;
38 }
39 
printer_notify_handler(uint8_t event,void * arg)40 static void printer_notify_handler(uint8_t event, void *arg)
41 {
42     switch (event) {
43         case USBD_EVENT_RESET:
44             break;
45 
46         default:
47             break;
48     }
49 }
50 
usbd_printer_init_intf(struct usbd_interface * intf,const uint8_t * device_id,uint8_t device_id_len)51 struct usbd_interface *usbd_printer_init_intf(struct usbd_interface *intf, const uint8_t *device_id, uint8_t device_id_len)
52 {
53     intf->class_interface_handler = printer_class_interface_request_handler;
54     intf->class_endpoint_handler = NULL;
55     intf->vendor_handler = NULL;
56     intf->notify_handler = printer_notify_handler;
57 
58     g_usbd_printer.device_id = device_id;
59     g_usbd_printer.device_id_len = device_id_len;
60     return intf;
61 }
62