change endpoint and class handler
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2475 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
405977d3ca
commit
834355c76b
@ -9,9 +9,13 @@
|
|||||||
*
|
*
|
||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2012-10-01 Yi Qiu first version
|
* 2012-10-01 Yi Qiu first version
|
||||||
|
* 2012-12-12 heyuanjie87 change endpoint and class handler
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef __USB_DEVICE_H__
|
||||||
|
#define __USB_DEVICE_H__
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include "usb_common.h"
|
#include "usb_common.h"
|
||||||
|
|
||||||
@ -20,8 +24,9 @@
|
|||||||
|
|
||||||
#define USB_VENDOR_ID 0x0483 /* Vendor ID */
|
#define USB_VENDOR_ID 0x0483 /* Vendor ID */
|
||||||
#define USB_BCD_DEVICE 0x0200 /* USB Specification Release Number in Binary-Coded Decimal */
|
#define USB_BCD_DEVICE 0x0200 /* USB Specification Release Number in Binary-Coded Decimal */
|
||||||
#define USB_BCD_VERSION 0x0200 /* USB 2.0 */
|
#define USB_BCD_VERSION 0x0200 /* USB 2.0 */
|
||||||
|
|
||||||
|
struct uclass;
|
||||||
struct udevice;
|
struct udevice;
|
||||||
struct uendpoint;
|
struct uendpoint;
|
||||||
|
|
||||||
@ -29,14 +34,14 @@ struct udcd_ops
|
|||||||
{
|
{
|
||||||
rt_err_t (*set_address)(rt_uint8_t value);
|
rt_err_t (*set_address)(rt_uint8_t value);
|
||||||
rt_err_t (*clear_feature)(rt_uint8_t value);
|
rt_err_t (*clear_feature)(rt_uint8_t value);
|
||||||
rt_err_t (*set_feature)(rt_uint8_t value);
|
rt_err_t (*set_feature)(rt_uint8_t value);
|
||||||
rt_err_t (*ep_alloc)(struct uendpoint* ep);
|
rt_err_t (*ep_alloc)(struct uendpoint* ep);
|
||||||
rt_err_t (*ep_free)(struct uendpoint* ep);
|
rt_err_t (*ep_free)(struct uendpoint* ep);
|
||||||
rt_err_t (*ep_stall)(struct uendpoint* ep);
|
rt_err_t (*ep_stall)(struct uendpoint* ep);
|
||||||
rt_err_t (*ep_run)(struct uendpoint* ep);
|
rt_err_t (*ep_run)(struct uendpoint* ep);
|
||||||
rt_err_t (*ep_stop)(struct uendpoint* ep);
|
rt_err_t (*ep_stop)(struct uendpoint* ep);
|
||||||
rt_err_t (*ep_read)(struct uendpoint* ep, void *buffer, rt_size_t size);
|
rt_err_t (*ep_read)(struct uendpoint* ep, void *buffer, rt_size_t size);
|
||||||
rt_size_t (*ep_write)(struct uendpoint* ep, void *buffer, rt_size_t size);
|
rt_size_t (*ep_write)(struct uendpoint* ep, void *buffer, rt_size_t size);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct udcd
|
struct udcd
|
||||||
@ -47,12 +52,14 @@ struct udcd
|
|||||||
};
|
};
|
||||||
typedef struct udcd* udcd_t;
|
typedef struct udcd* udcd_t;
|
||||||
|
|
||||||
|
typedef rt_err_t (*udep_handler_t)(struct udevice* device, struct uclass* cls, rt_size_t size);
|
||||||
|
|
||||||
struct uendpoint
|
struct uendpoint
|
||||||
{
|
{
|
||||||
rt_list_t list;
|
rt_list_t list;
|
||||||
rt_uint8_t* buffer;
|
rt_uint8_t* buffer;
|
||||||
uep_desc_t ep_desc;
|
uep_desc_t ep_desc;
|
||||||
rt_err_t (*handler)(struct udevice* device, rt_size_t size);
|
udep_handler_t handler;
|
||||||
rt_bool_t is_stall;
|
rt_bool_t is_stall;
|
||||||
void* user_data;
|
void* user_data;
|
||||||
};
|
};
|
||||||
@ -79,9 +86,9 @@ typedef struct uinterface* uintf_t;
|
|||||||
|
|
||||||
struct uclass_ops
|
struct uclass_ops
|
||||||
{
|
{
|
||||||
rt_err_t (*run)(struct udevice* device);
|
rt_err_t (*run)(struct udevice* device, struct uclass* cls);
|
||||||
rt_err_t (*stop)(struct udevice* device);
|
rt_err_t (*stop)(struct udevice* device, struct uclass* cls);
|
||||||
rt_err_t (*sof_handler)(struct udevice* device);
|
rt_err_t (*sof_handler)(struct udevice* device, struct uclass* cls);
|
||||||
};
|
};
|
||||||
typedef struct uclass_ops* uclass_ops_t;
|
typedef struct uclass_ops* uclass_ops_t;
|
||||||
|
|
||||||
@ -89,10 +96,10 @@ struct uclass
|
|||||||
{
|
{
|
||||||
rt_list_t list;
|
rt_list_t list;
|
||||||
uclass_ops_t ops;
|
uclass_ops_t ops;
|
||||||
|
void* eps;
|
||||||
struct udevice* device;
|
struct udevice* device;
|
||||||
udev_desc_t dev_desc;
|
udev_desc_t dev_desc;
|
||||||
#ifdef RT_USB_DEVICE_COMPOSITE
|
#ifdef RT_USB_DEVICE_COMPOSITE
|
||||||
uiad_desc_t iad_desc;
|
uiad_desc_t iad_desc;
|
||||||
#endif
|
#endif
|
||||||
rt_list_t intf_list;
|
rt_list_t intf_list;
|
||||||
@ -108,16 +115,16 @@ struct uconfig
|
|||||||
typedef struct uconfig* uconfig_t;
|
typedef struct uconfig* uconfig_t;
|
||||||
|
|
||||||
struct udevice
|
struct udevice
|
||||||
{
|
{
|
||||||
rt_list_t list;
|
rt_list_t list;
|
||||||
struct udevice_descriptor dev_desc;
|
struct udevice_descriptor dev_desc;
|
||||||
const char** str;
|
const char** str;
|
||||||
|
|
||||||
rt_list_t cfg_list;
|
rt_list_t cfg_list;
|
||||||
uconfig_t curr_cfg;
|
uconfig_t curr_cfg;
|
||||||
rt_uint8_t nr_intf;
|
rt_uint8_t nr_intf;
|
||||||
|
|
||||||
udcd_t dcd;
|
udcd_t dcd;
|
||||||
};
|
};
|
||||||
typedef struct udevice* udevice_t;
|
typedef struct udevice* udevice_t;
|
||||||
|
|
||||||
@ -131,31 +138,30 @@ typedef enum udev_msg_type udev_msg_type;
|
|||||||
|
|
||||||
struct udev_msg
|
struct udev_msg
|
||||||
{
|
{
|
||||||
udev_msg_type type;
|
udev_msg_type type;
|
||||||
udcd_t dcd;
|
udcd_t dcd;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
rt_size_t size;
|
rt_size_t size;
|
||||||
rt_uint8_t ep_addr;
|
rt_uint8_t ep_addr;
|
||||||
}ep_msg;
|
} ep_msg;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
rt_uint32_t* packet;
|
rt_uint32_t* packet;
|
||||||
}setup_msg;
|
} setup_msg;
|
||||||
}content;
|
} content;
|
||||||
};
|
};
|
||||||
typedef struct udev_msg* udev_msg_t;
|
typedef struct udev_msg* udev_msg_t;
|
||||||
|
|
||||||
udevice_t rt_usbd_device_create(const char** str);
|
udevice_t rt_usbd_device_create(const char** str);
|
||||||
uconfig_t rt_usbd_config_create(void);
|
uconfig_t rt_usbd_config_create(void);
|
||||||
uclass_t rt_usbd_class_create(udevice_t device, udev_desc_t dev_desc,
|
uclass_t rt_usbd_class_create(udevice_t device, udev_desc_t dev_desc,
|
||||||
uclass_ops_t ops);
|
uclass_ops_t ops);
|
||||||
uintf_t rt_usbd_interface_create(udevice_t device,
|
uintf_t rt_usbd_interface_create(udevice_t device,
|
||||||
rt_err_t (*handler)(struct udevice*, ureq_t setup));
|
rt_err_t (*handler)(struct udevice*, ureq_t setup));
|
||||||
uep_t rt_usbd_endpoint_create(uep_desc_t ep_desc,
|
uep_t rt_usbd_endpoint_create(uep_desc_t ep_desc, udep_handler_t handler);
|
||||||
rt_err_t (*handler)(udevice_t device, rt_size_t size));
|
|
||||||
ualtsetting_t rt_usbd_altsetting_create(uintf_desc_t intf_desc, rt_size_t desc_size);
|
ualtsetting_t rt_usbd_altsetting_create(uintf_desc_t intf_desc, rt_size_t desc_size);
|
||||||
|
|
||||||
rt_err_t rt_usbd_core_init(void);
|
rt_err_t rt_usbd_core_init(void);
|
||||||
@ -175,7 +181,7 @@ rt_err_t rt_usbd_set_altsetting(uintf_t intf, rt_uint8_t value);
|
|||||||
udevice_t rt_usbd_find_device(udcd_t dcd);
|
udevice_t rt_usbd_find_device(udcd_t dcd);
|
||||||
uconfig_t rt_usbd_find_config(udevice_t device, rt_uint8_t value);
|
uconfig_t rt_usbd_find_config(udevice_t device, rt_uint8_t value);
|
||||||
uintf_t rt_usbd_find_interface(udevice_t device, rt_uint8_t value);
|
uintf_t rt_usbd_find_interface(udevice_t device, rt_uint8_t value);
|
||||||
uep_t rt_usbd_find_endpoint(udevice_t device, rt_uint8_t ep_addr);
|
uep_t rt_usbd_find_endpoint(udevice_t device, uclass_t* pcls, rt_uint8_t ep_addr);
|
||||||
|
|
||||||
uclass_t rt_usbd_class_mstorage_create(udevice_t device);
|
uclass_t rt_usbd_class_mstorage_create(udevice_t device);
|
||||||
uclass_t rt_usbd_class_cdc_create(udevice_t device);
|
uclass_t rt_usbd_class_cdc_create(udevice_t device);
|
||||||
@ -187,21 +193,21 @@ rt_err_t rt_usbd_class_set_iad(uclass_t cls, uiad_desc_t iad_desc);
|
|||||||
rt_inline rt_err_t dcd_set_address(udcd_t dcd, rt_uint8_t value)
|
rt_inline rt_err_t dcd_set_address(udcd_t dcd, rt_uint8_t value)
|
||||||
{
|
{
|
||||||
RT_ASSERT(dcd != RT_NULL);
|
RT_ASSERT(dcd != RT_NULL);
|
||||||
|
|
||||||
return dcd->ops->set_address(value);
|
return dcd->ops->set_address(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
rt_inline rt_err_t dcd_clear_feature(udcd_t dcd, rt_uint8_t value)
|
rt_inline rt_err_t dcd_clear_feature(udcd_t dcd, rt_uint8_t value)
|
||||||
{
|
{
|
||||||
RT_ASSERT(dcd != RT_NULL);
|
RT_ASSERT(dcd != RT_NULL);
|
||||||
|
|
||||||
return dcd->ops->clear_feature(value);
|
return dcd->ops->clear_feature(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
rt_inline rt_err_t dcd_set_feature(udcd_t dcd, rt_uint8_t value)
|
rt_inline rt_err_t dcd_set_feature(udcd_t dcd, rt_uint8_t value)
|
||||||
{
|
{
|
||||||
RT_ASSERT(dcd != RT_NULL);
|
RT_ASSERT(dcd != RT_NULL);
|
||||||
|
|
||||||
return dcd->ops->set_feature(value);
|
return dcd->ops->set_feature(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,19 +246,20 @@ rt_inline rt_err_t dcd_ep_stop(udcd_t dcd, uep_t ep)
|
|||||||
return dcd->ops->ep_stop(ep);
|
return dcd->ops->ep_stop(ep);
|
||||||
}
|
}
|
||||||
|
|
||||||
rt_inline rt_err_t dcd_ep_read(udcd_t dcd, uep_t ep, void *buffer,
|
rt_inline rt_err_t dcd_ep_read(udcd_t dcd, uep_t ep, void *buffer,
|
||||||
rt_size_t size)
|
rt_size_t size)
|
||||||
{
|
{
|
||||||
RT_ASSERT(dcd != RT_NULL);
|
RT_ASSERT(dcd != RT_NULL);
|
||||||
|
|
||||||
return dcd->ops->ep_read(ep, buffer, size);
|
return dcd->ops->ep_read(ep, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
rt_inline rt_size_t dcd_ep_write(udcd_t dcd, uep_t ep, void *buffer,
|
rt_inline rt_size_t dcd_ep_write(udcd_t dcd, uep_t ep, void *buffer,
|
||||||
rt_size_t size)
|
rt_size_t size)
|
||||||
{
|
{
|
||||||
RT_ASSERT(dcd != RT_NULL);
|
RT_ASSERT(dcd != RT_NULL);
|
||||||
|
|
||||||
return dcd->ops->ep_write(ep, buffer, size);
|
return dcd->ops->ep_write(ep, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user