• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "usbh_core.h"
2 #include "usbh_xxx.h"
3 
4 #define DEV_FORMAT "/dev/xxx"
5 
6 static struct usbh_xxx g_xxx_class[CONFIG_USBHOST_MAX_CUSTOM_CLASS];
7 static uint32_t g_devinuse = 0;
8 
usbh_xxx_class_alloc(void)9 static struct usbh_xxx *usbh_xxx_class_alloc(void)
10 {
11     int devno;
12 
13     for (devno = 0; devno < CONFIG_USBHOST_MAX_CUSTOM_CLASS; devno++) {
14         if ((g_devinuse & (1 << devno)) == 0) {
15             g_devinuse |= (1 << devno);
16             memset(&g_xxx_class[devno], 0, sizeof(struct usbh_xxx));
17             g_xxx_class[devno].minor = devno;
18             return &g_xxx_class[devno];
19         }
20     }
21     return NULL;
22 }
23 
usbh_xxx_class_free(struct usbh_xxx * xxx_class)24 static void usbh_xxx_class_free(struct usbh_xxx *xxx_class)
25 {
26     int devno = xxx_class->minor;
27 
28     if (devno >= 0 && devno < 32) {
29         g_devinuse &= ~(1 << devno);
30     }
31     memset(xxx_class, 0, sizeof(struct usbh_xxx));
32 }
33 
usbh_xxx_connect(struct usbh_hubport * hport,uint8_t intf)34 static int usbh_xxx_connect(struct usbh_hubport *hport, uint8_t intf)
35 {
36     struct usbh_endpoint_cfg ep_cfg = { 0 };
37     struct usb_endpoint_descriptor *ep_desc;
38     int ret;
39 
40     struct usbh_xxx *xxx_class = usbh_xxx_class_alloc();
41     if (xxx_class == NULL) {
42         USB_LOG_ERR("Fail to alloc xxx_class\r\n");
43         return -ENOMEM;
44     }
45 
46     return ret;
47 }
48 
49 
usbh_xxx_disconnect(struct usbh_hubport * hport,uint8_t intf)50 static int usbh_xxx_disconnect(struct usbh_hubport *hport, uint8_t intf)
51 {
52     int ret = 0;
53 
54     struct usbh_xxx *xxx_class = (struct usbh_xxx *)hport->config.intf[intf].priv;
55 
56     if (xxx_class) {
57         if (xxx_class->bulkin) {
58             usbh_pipe_free(xxx_class->bulkin);
59         }
60 
61         if (xxx_class->bulkout) {
62             usbh_pipe_free(xxx_class->bulkout);
63         }
64 
65         if (hport->config.intf[intf].devname[0] != '\0') {
66             USB_LOG_INFO("Unregister xxx Class:%s\r\n", hport->config.intf[intf].devname);
67             usbh_xxx_stop(xxx_class);
68         }
69 
70         usbh_xxx_class_free(xxx_class);
71     }
72 
73     return ret;
74 }
75 
usbh_xxx_run(struct usbh_xxx * xxx_class)76 __WEAK void usbh_xxx_run(struct usbh_xxx *xxx_class)
77 {
78 }
79 
usbh_xxx_stop(struct usbh_xxx * xxx_class)80 __WEAK void usbh_xxx_stop(struct usbh_xxx *xxx_class)
81 {
82 }
83 
84 static const struct usbh_class_driver xxx_class_driver = {
85     .driver_name = "xxx",
86     .connect = usbh_xxx_connect,
87     .disconnect = usbh_xxx_disconnect
88 };
89 
90 CLASS_INFO_DEFINE const struct usbh_class_info xxx_class_info = {
91     .match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
92     .class = 0,
93     .subclass = 0,
94     .protocol = 0,
95     .vid = 0x00,
96     .pid = 0x00,
97     .class_driver = &xxx_class_driver
98 };
99