usbh_xxx.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "usbh_core.h"
  2. #include "usbh_xxx.h"
  3. #define DEV_FORMAT "/dev/xxx"
  4. #define CONFIG_USBHOST_MAX_CUSTOM_CLASS 1
  5. static struct usbh_xxx g_xxx_class[CONFIG_USBHOST_MAX_CUSTOM_CLASS];
  6. static uint32_t g_devinuse = 0;
  7. static struct usbh_xxx *usbh_xxx_class_alloc(void)
  8. {
  9. uint8_t devno;
  10. for (devno = 0; devno < CONFIG_USBHOST_MAX_CUSTOM_CLASS; devno++) {
  11. if ((g_devinuse & (1U << devno)) == 0) {
  12. g_devinuse |= (1U << devno);
  13. memset(&g_xxx_class[devno], 0, sizeof(struct usbh_xxx));
  14. g_xxx_class[devno].minor = devno;
  15. return &g_xxx_class[devno];
  16. }
  17. }
  18. return NULL;
  19. }
  20. static void usbh_xxx_class_free(struct usbh_xxx *xxx_class)
  21. {
  22. uint8_t devno = xxx_class->minor;
  23. if (devno < 32) {
  24. g_devinuse &= ~(1U << devno);
  25. }
  26. memset(xxx_class, 0, sizeof(struct usbh_xxx));
  27. }
  28. static int usbh_xxx_connect(struct usbh_hubport *hport, uint8_t intf)
  29. {
  30. struct usb_endpoint_descriptor *ep_desc;
  31. int ret;
  32. struct usbh_xxx *xxx_class = usbh_xxx_class_alloc();
  33. if (xxx_class == NULL) {
  34. USB_LOG_ERR("Fail to alloc xxx_class\r\n");
  35. return -USB_ERR_NOMEM;
  36. }
  37. return ret;
  38. }
  39. static int usbh_xxx_disconnect(struct usbh_hubport *hport, uint8_t intf)
  40. {
  41. int ret = 0;
  42. struct usbh_xxx *xxx_class = (struct usbh_xxx *)hport->config.intf[intf].priv;
  43. if (xxx_class) {
  44. if (xxx_class->xxxin) {
  45. usbh_kill_urb(&xxx_class->xxxin_urb);
  46. }
  47. if (xxx_class->xxxout) {
  48. usbh_kill_urb(&xxx_class->xxxout_urb);
  49. }
  50. if (hport->config.intf[intf].devname[0] != '\0') {
  51. USB_LOG_INFO("Unregister xxx Class:%s\r\n", hport->config.intf[intf].devname);
  52. usbh_xxx_stop(xxx_class);
  53. }
  54. usbh_xxx_class_free(xxx_class);
  55. }
  56. return ret;
  57. }
  58. __WEAK void usbh_xxx_run(struct usbh_xxx *xxx_class)
  59. {
  60. }
  61. __WEAK void usbh_xxx_stop(struct usbh_xxx *xxx_class)
  62. {
  63. }
  64. static const struct usbh_class_driver xxx_class_driver = {
  65. .driver_name = "xxx",
  66. .connect = usbh_xxx_connect,
  67. .disconnect = usbh_xxx_disconnect
  68. };
  69. CLASS_INFO_DEFINE const struct usbh_class_info xxx_class_info = {
  70. .match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
  71. .bInterfaceClass = 0,
  72. .bInterfaceSubClass = 0,
  73. .bInterfaceProtocol = 0,
  74. .id_table = NULL,
  75. .class_driver = &xxx_class_driver
  76. };