add initial printer、mtp、template class driver
This commit is contained in:
4
class/template/usb_xxx.h
Normal file
4
class/template/usb_xxx.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#ifndef _USB_XXX_H
|
||||
#define _USB_XXX_H
|
||||
|
||||
#endif
|
||||
46
class/template/usbd_xxx.c
Normal file
46
class/template/usbd_xxx.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_xxx.h"
|
||||
|
||||
static int xxx_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_WRN("XXX Class request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
setup->bRequest);
|
||||
|
||||
switch (setup->bRequest) {
|
||||
default:
|
||||
USB_LOG_WRN("Unhandled XXX Class bRequest 0x%02x\r\n", setup->bRequest);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void xxx_notify_handler(uint8_t event, void *arg)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_xxx_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
{
|
||||
static usbd_class_t *last_class = NULL;
|
||||
|
||||
if (last_class != devclass) {
|
||||
last_class = devclass;
|
||||
usbd_class_register(devclass);
|
||||
}
|
||||
|
||||
intf->class_handler = xxx_class_request_handler;
|
||||
intf->custom_handler = NULL;
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = xxx_notify_handler;
|
||||
|
||||
usbd_class_add_interface(devclass, intf);
|
||||
}
|
||||
16
class/template/usbd_xxx.h
Normal file
16
class/template/usbd_xxx.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef _USBD_XXX_H_
|
||||
#define _USBD_XXX_H_
|
||||
|
||||
#include "usb_xxx.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void usbd_xxx_add_interface(usbd_class_t *devclass, usbd_interface_t *intf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _USBD_XXX_H_ */
|
||||
93
class/template/usbh_xxx.c
Normal file
93
class/template/usbh_xxx.c
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_xxx.h"
|
||||
|
||||
#define DEV_FORMAT "/dev/xxx"
|
||||
|
||||
static int usbh_xxx_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
struct usbh_endpoint_cfg ep_cfg = { 0 };
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
int ret;
|
||||
|
||||
struct usbh_xxx *xxx_class = usb_malloc(sizeof(struct usbh_xxx));
|
||||
if (xxx_class == NULL) {
|
||||
USB_LOG_ERR("Fail to alloc xxx_class\r\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memset(xxx_class, 0, sizeof(struct usbh_xxx));
|
||||
|
||||
xxx_class->hport = hport;
|
||||
xxx_class->intf = intf;
|
||||
|
||||
hport->config.intf[intf].priv = xxx_class;
|
||||
strncpy(hport->config.intf[intf].devname, DEV_FORMAT, CONFIG_USBHOST_DEV_NAMELEN);
|
||||
|
||||
for (uint8_t i = 0; i < hport->config.intf[intf + 1].intf_desc.bNumEndpoints; i++) {
|
||||
ep_desc = &hport->config.intf[intf + 1].ep[i].ep_desc;
|
||||
|
||||
ep_cfg.ep_addr = ep_desc->bEndpointAddress;
|
||||
ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK;
|
||||
ep_cfg.ep_mps = ep_desc->wMaxPacketSize;
|
||||
ep_cfg.ep_interval = ep_desc->bInterval;
|
||||
ep_cfg.hport = hport;
|
||||
if (ep_desc->bEndpointAddress & 0x80) {
|
||||
usbh_ep_alloc(&rndis_class->bulkin, &ep_cfg);
|
||||
} else {
|
||||
usbh_ep_alloc(&rndis_class->bulkout, &ep_cfg);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static int usbh_xxx_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct usbh_xxx *xxx_class = (struct usbh_xxx *)hport->config.intf[intf].priv;
|
||||
|
||||
if (xxx_class) {
|
||||
if (xxx_class->bulkin) {
|
||||
ret = usb_ep_cancel(xxx_class->bulkin);
|
||||
if (ret < 0) {
|
||||
}
|
||||
usbh_ep_free(xxx_class->bulkin);
|
||||
}
|
||||
|
||||
if (xxx_class->bulkout) {
|
||||
ret = usb_ep_cancel(xxx_class->bulkout);
|
||||
if (ret < 0) {
|
||||
}
|
||||
usbh_ep_free(xxx_class->bulkout);
|
||||
}
|
||||
|
||||
usb_free(xxx_class);
|
||||
|
||||
USB_LOG_INFO("Unregister xxx Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
memset(hport->config.intf[intf].devname, 0, CONFIG_USBHOST_DEV_NAMELEN);
|
||||
|
||||
hport->config.intf[intf].priv = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static const struct usbh_class_driver xxx_class_driver = {
|
||||
.driver_name = "xxx",
|
||||
.connect = usbh_xxx_connect,
|
||||
.disconnect = usbh_xxx_disconnect
|
||||
};
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info xxx_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = 0,
|
||||
.subclass = 0,
|
||||
.protocol = 0,
|
||||
.vid = 0x00,
|
||||
.pid = 0x00,
|
||||
.class_driver = &xxx_class_driver
|
||||
};
|
||||
14
class/template/usbh_xxx.h
Normal file
14
class/template/usbh_xxx.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef _USBH_XXX_H
|
||||
#define _USBH_XXX_H
|
||||
|
||||
#include "usb_xxx.h"
|
||||
|
||||
struct usbh_xxx {
|
||||
struct usbh_hubport *hport;
|
||||
|
||||
uint8_t intf; /* interface number */
|
||||
usbh_epinfo_t intin; /* INTR IN endpoint */
|
||||
usbh_epinfo_t intout; /* INTR OUT endpoint */
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user