refactor usb device intf and ep register
This commit is contained in:
@@ -373,8 +373,14 @@ static void audio_notify_handler(uint8_t event, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
struct usbd_interface *usbd_audio_alloc_intf(void)
|
||||
{
|
||||
struct usbd_interface *intf = usb_malloc(sizeof(struct usbd_interface));
|
||||
if (intf == NULL) {
|
||||
USB_LOG_ERR("no mem to alloc intf\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
intf->class_handler = audio_class_request_handler;
|
||||
#if CONFIG_USBDEV_AUDIO_VERSION < 0x0200
|
||||
intf->custom_handler = audio_custom_request_handler;
|
||||
@@ -383,7 +389,8 @@ void usbd_audio_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
#endif
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = audio_notify_handler;
|
||||
usbd_class_add_interface(devclass, intf);
|
||||
|
||||
return intf;
|
||||
}
|
||||
|
||||
void usbd_audio_add_entity(uint8_t entity_id, uint16_t bDescriptorSubtype)
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void usbd_audio_add_interface(usbd_class_t *devclass, usbd_interface_t *intf);
|
||||
/* Alloc audio interface driver */
|
||||
struct usbd_interface *usbd_audio_alloc_intf(void);
|
||||
|
||||
void usbd_audio_open(uint8_t intf);
|
||||
void usbd_audio_close(uint8_t intf);
|
||||
|
||||
@@ -17,7 +17,7 @@ static int cdc_acm_class_request_handler(struct usb_setup_packet *setup, uint8_t
|
||||
|
||||
struct cdc_line_coding line_coding;
|
||||
bool dtr, rts;
|
||||
uint8_t intf = LO_BYTE(setup->wIndex);
|
||||
uint8_t intf_num = LO_BYTE(setup->wIndex);
|
||||
|
||||
switch (setup->bRequest) {
|
||||
case CDC_REQUEST_SET_LINE_CODING:
|
||||
@@ -41,31 +41,31 @@ static int cdc_acm_class_request_handler(struct usb_setup_packet *setup, uint8_t
|
||||
/*******************************************************************************/
|
||||
memcpy(&line_coding, *data, setup->wLength);
|
||||
USB_LOG_DBG("Set intf:%d linecoding <%d %d %s %s>\r\n",
|
||||
intf,
|
||||
intf_num,
|
||||
line_coding.dwDTERate,
|
||||
line_coding.bDataBits,
|
||||
parity_name[line_coding.bParityType],
|
||||
stop_name[line_coding.bCharFormat]);
|
||||
usbd_cdc_acm_set_line_coding(intf, &line_coding);
|
||||
usbd_cdc_acm_set_line_coding(intf_num, &line_coding);
|
||||
break;
|
||||
|
||||
case CDC_REQUEST_SET_CONTROL_LINE_STATE: {
|
||||
dtr = (setup->wValue & 0x0001);
|
||||
rts = (setup->wValue & 0x0002);
|
||||
USB_LOG_DBG("Set intf:%d DTR 0x%x,RTS 0x%x\r\n",
|
||||
intf,
|
||||
intf_num,
|
||||
dtr,
|
||||
rts);
|
||||
usbd_cdc_acm_set_dtr(intf, dtr);
|
||||
usbd_cdc_acm_set_rts(intf, rts);
|
||||
usbd_cdc_acm_set_dtr(intf_num, dtr);
|
||||
usbd_cdc_acm_set_rts(intf_num, rts);
|
||||
} break;
|
||||
|
||||
case CDC_REQUEST_GET_LINE_CODING:
|
||||
usbd_cdc_acm_get_line_coding(intf, &line_coding);
|
||||
usbd_cdc_acm_get_line_coding(intf_num, &line_coding);
|
||||
memcpy(*data, &line_coding, 7);
|
||||
*len = 7;
|
||||
USB_LOG_DBG("Get intf:%d linecoding %d %d %d %d\r\n",
|
||||
intf,
|
||||
intf_num,
|
||||
line_coding.dwDTERate,
|
||||
line_coding.bCharFormat,
|
||||
line_coding.bParityType,
|
||||
@@ -90,13 +90,20 @@ static void cdc_notify_handler(uint8_t event, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_cdc_add_acm_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
struct usbd_interface *usbd_cdc_acm_alloc_intf(void)
|
||||
{
|
||||
struct usbd_interface *intf = usb_malloc(sizeof(struct usbd_interface));
|
||||
if (intf == NULL) {
|
||||
USB_LOG_ERR("no mem to alloc intf\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
intf->class_handler = cdc_acm_class_request_handler;
|
||||
intf->custom_handler = NULL;
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = cdc_notify_handler;
|
||||
usbd_class_add_interface(devclass, intf);
|
||||
|
||||
return intf;
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_acm_set_line_coding(uint8_t intf, struct cdc_line_coding *line_coding)
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Register api */
|
||||
void usbd_cdc_add_acm_interface(usbd_class_t *devclass, usbd_interface_t *intf);
|
||||
/* Alloc cdc acm interface driver */
|
||||
struct usbd_interface *usbd_cdc_acm_alloc_intf(void);
|
||||
|
||||
/* Setup request command callback api */
|
||||
void usbd_cdc_acm_set_line_coding(uint8_t intf, struct cdc_line_coding *line_coding);
|
||||
|
||||
@@ -43,7 +43,6 @@ static void dfu_notify_handler(uint8_t event, void *arg)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -51,12 +50,18 @@ static void dfu_notify_handler(uint8_t event, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_dfu_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
struct usbd_interface *usbd_dfu_alloc_intf(void)
|
||||
{
|
||||
struct usbd_interface *intf = usb_malloc(sizeof(struct usbd_interface));
|
||||
if (intf == NULL) {
|
||||
USB_LOG_ERR("no mem to alloc intf\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
intf->class_handler = dfu_class_request_handler;
|
||||
intf->custom_handler = NULL;
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = dfu_notify_handler;
|
||||
|
||||
usbd_class_add_interface(devclass, intf);
|
||||
}
|
||||
return intf;
|
||||
}
|
||||
@@ -12,7 +12,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void usbd_dfu_add_interface(usbd_class_t *devclass, usbd_interface_t *intf);
|
||||
/* Alloc dfu interface driver */
|
||||
struct usbd_interface *usbd_dfu_alloc_intf(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -6,32 +6,6 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_hid.h"
|
||||
|
||||
struct usbd_hid {
|
||||
const uint8_t *hid_descriptor;
|
||||
const uint8_t *hid_report_descriptor;
|
||||
uint32_t hid_report_descriptor_len;
|
||||
uint8_t intf_num;
|
||||
uint8_t report;
|
||||
uint8_t idle_state;
|
||||
uint8_t protocol;
|
||||
|
||||
usb_slist_t list;
|
||||
};
|
||||
|
||||
static usb_slist_t usbd_hid_head = USB_SLIST_OBJECT_INIT(usbd_hid_head);
|
||||
|
||||
static void usbd_hid_reset(void)
|
||||
{
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_head)
|
||||
{
|
||||
struct usbd_hid *hid_intf = usb_slist_entry(i, struct usbd_hid, list);
|
||||
hid_intf->report = 0;
|
||||
hid_intf->idle_state = 0;
|
||||
hid_intf->protocol = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int hid_custom_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_DBG("HID Custom request: "
|
||||
@@ -43,33 +17,34 @@ static int hid_custom_request_handler(struct usb_setup_packet *setup, uint8_t **
|
||||
uint8_t value = (uint8_t)(setup->wValue >> 8);
|
||||
uint8_t intf_num = (uint8_t)setup->wIndex;
|
||||
|
||||
struct usbd_hid *current_hid_class = NULL;
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_head)
|
||||
{
|
||||
struct usbd_hid *hid_class = usb_slist_entry(i, struct usbd_hid, list);
|
||||
struct usbd_interface *match_intf = NULL;
|
||||
|
||||
if (hid_class->intf_num == intf_num) {
|
||||
current_hid_class = hid_class;
|
||||
usb_slist_for_each(i, &usbd_intf_head)
|
||||
{
|
||||
struct usbd_interface *intf = usb_slist_entry(i, struct usbd_interface, list);
|
||||
|
||||
if (intf->intf_num == intf_num) {
|
||||
match_intf = intf;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (current_hid_class == NULL) {
|
||||
if (match_intf == NULL) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
switch (value) {
|
||||
case HID_DESCRIPTOR_TYPE_HID:
|
||||
USB_LOG_INFO("get HID Descriptor\r\n");
|
||||
*data = (uint8_t *)current_hid_class->hid_descriptor;
|
||||
*len = current_hid_class->hid_descriptor[0];
|
||||
// *data = (uint8_t *)match_intf->hid_descriptor;
|
||||
// *len = match_intf->hid_descriptor[0];
|
||||
break;
|
||||
|
||||
case HID_DESCRIPTOR_TYPE_HID_REPORT:
|
||||
USB_LOG_INFO("get Report Descriptor\r\n");
|
||||
*data = (uint8_t *)current_hid_class->hid_report_descriptor;
|
||||
*len = current_hid_class->hid_report_descriptor_len;
|
||||
*data = (uint8_t *)match_intf->hid_report_descriptor;
|
||||
*len = match_intf->hid_report_descriptor_len;
|
||||
break;
|
||||
|
||||
case HID_DESCRIPTOR_TYPE_HID_PHYSICAL:
|
||||
@@ -93,50 +68,33 @@ static int hid_class_request_handler(struct usb_setup_packet *setup, uint8_t **d
|
||||
"bRequest 0x%02x\r\n",
|
||||
setup->bRequest);
|
||||
|
||||
struct usbd_hid *current_hid_class = NULL;
|
||||
usb_slist_t *i;
|
||||
uint8_t intf = LO_BYTE(setup->wIndex);
|
||||
|
||||
usb_slist_for_each(i, &usbd_hid_head)
|
||||
{
|
||||
struct usbd_hid *hid_class = usb_slist_entry(i, struct usbd_hid, list);
|
||||
if (hid_class->intf_num == intf) {
|
||||
current_hid_class = hid_class;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (current_hid_class == NULL) {
|
||||
return -2;
|
||||
}
|
||||
uint8_t intf_num = LO_BYTE(setup->wIndex);
|
||||
|
||||
switch (setup->bRequest) {
|
||||
case HID_REQUEST_GET_REPORT:
|
||||
current_hid_class->report = usbh_hid_get_report(intf, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue)); /*report id ,report type*/
|
||||
*data = (uint8_t *)¤t_hid_class->report;
|
||||
/* report id ,report type */
|
||||
(*data)[0] = usbh_hid_get_report(intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue));
|
||||
*len = 1;
|
||||
break;
|
||||
case HID_REQUEST_GET_IDLE:
|
||||
current_hid_class->idle_state = usbh_hid_get_idle(intf, LO_BYTE(setup->wValue));
|
||||
*data = (uint8_t *)¤t_hid_class->idle_state;
|
||||
(*data)[0] = usbh_hid_get_idle(intf_num, LO_BYTE(setup->wValue));
|
||||
*len = 1;
|
||||
break;
|
||||
case HID_REQUEST_GET_PROTOCOL:
|
||||
current_hid_class->protocol = usbh_hid_get_protocol(intf);
|
||||
*data = (uint8_t *)¤t_hid_class->protocol;
|
||||
(*data)[0] = usbh_hid_get_protocol(intf_num);
|
||||
*len = 1;
|
||||
break;
|
||||
case HID_REQUEST_SET_REPORT:
|
||||
usbh_hid_set_report(intf, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue), *data, *len); /*report id ,report type,report,report len*/
|
||||
current_hid_class->report = **data;
|
||||
/* report id ,report type, report, report len */
|
||||
usbh_hid_set_report(intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue), *data, *len);
|
||||
break;
|
||||
case HID_REQUEST_SET_IDLE:
|
||||
usbh_hid_set_idle(intf, LO_BYTE(setup->wValue), HI_BYTE(setup->wIndex)); /*report id ,duration*/
|
||||
current_hid_class->idle_state = HI_BYTE(setup->wIndex);
|
||||
/* report id, duration */
|
||||
usbh_hid_set_idle(intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wIndex));
|
||||
break;
|
||||
case HID_REQUEST_SET_PROTOCOL:
|
||||
usbh_hid_set_protocol(intf, LO_BYTE(setup->wValue)); /*protocol*/
|
||||
current_hid_class->protocol = LO_BYTE(setup->wValue);
|
||||
/* protocol */
|
||||
usbh_hid_set_protocol(intf_num, LO_BYTE(setup->wValue));
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -147,60 +105,22 @@ static int hid_class_request_handler(struct usb_setup_packet *setup, uint8_t **d
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void hid_notify_handler(uint8_t event, void *arg)
|
||||
struct usbd_interface *usbd_hid_alloc_intf(const uint8_t *desc, uint32_t desc_len)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
usbd_hid_reset();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int usbd_hid_alloc(uint8_t intf)
|
||||
{
|
||||
struct usbd_hid *hid_class = usb_malloc(sizeof(struct usbd_hid));
|
||||
|
||||
if (hid_class == NULL) {
|
||||
USB_LOG_ERR("no memory to alloc hid_class\r\n");
|
||||
return -1;
|
||||
struct usbd_interface *intf = usb_malloc(sizeof(struct usbd_interface));
|
||||
if (intf == NULL) {
|
||||
USB_LOG_ERR("no mem to alloc intf\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(hid_class, 0, sizeof(struct usbd_hid));
|
||||
hid_class->intf_num = intf;
|
||||
usb_slist_add_tail(&usbd_hid_head, &hid_class->list);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void usbd_hid_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
{
|
||||
intf->class_handler = hid_class_request_handler;
|
||||
intf->custom_handler = hid_custom_request_handler;
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = hid_notify_handler;
|
||||
usbd_class_add_interface(devclass, intf);
|
||||
usbd_hid_alloc(intf->intf_num);
|
||||
}
|
||||
intf->notify_handler = NULL;
|
||||
|
||||
void usbd_hid_descriptor_register(uint8_t intf_num, const uint8_t *desc)
|
||||
{
|
||||
// usbd_hid_cfg.hid_descriptor = desc;
|
||||
}
|
||||
|
||||
void usbd_hid_report_descriptor_register(uint8_t intf_num, const uint8_t *desc, uint32_t desc_len)
|
||||
{
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_head)
|
||||
{
|
||||
struct usbd_hid *hid_class = usb_slist_entry(i, struct usbd_hid, list);
|
||||
|
||||
if (hid_class->intf_num == intf_num) {
|
||||
hid_class->hid_report_descriptor = desc;
|
||||
hid_class->hid_report_descriptor_len = desc_len;
|
||||
return;
|
||||
}
|
||||
}
|
||||
intf->hid_report_descriptor = desc;
|
||||
intf->hid_report_descriptor_len = desc_len;
|
||||
return intf;
|
||||
}
|
||||
|
||||
__WEAK uint8_t usbh_hid_get_report(uint8_t intf, uint8_t report_id, uint8_t report_type)
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Register api */
|
||||
void usbd_hid_add_interface(usbd_class_t *devclass, usbd_interface_t *intf);
|
||||
/* Alloc hid interface driver */
|
||||
struct usbd_interface *usbd_hid_alloc_intf(const uint8_t *desc, uint32_t desc_len);
|
||||
|
||||
/* Register desc api */
|
||||
void usbd_hid_descriptor_register(uint8_t intf_num, const uint8_t *desc);
|
||||
|
||||
@@ -70,13 +70,4 @@ static void hub_notify_handler(uint8_t event, void *arg)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_hub_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
{
|
||||
intf->class_handler = NULL;
|
||||
intf->custom_handler = hub_custom_request_handler;
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = hub_notify_handler;
|
||||
usbd_class_add_interface(devclass, intf);
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void usbd_hub_add_interface(usbd_class_t *devclass, usbd_interface_t *intf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#define MSD_IN_EP_IDX 1
|
||||
|
||||
/* Describe EndPoints configuration */
|
||||
static usbd_endpoint_t mass_ep_data[2];
|
||||
static struct usbd_endpoint mass_ep_data[2];
|
||||
|
||||
/* MSC Bulk-only Stage */
|
||||
enum Stage {
|
||||
@@ -822,7 +822,7 @@ static bool SCSI_CBWDecode(uint32_t nbytes)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void mass_storage_bulk_out(uint8_t ep, uint32_t nbytes)
|
||||
void mass_storage_bulk_out(uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
switch (usbd_msc_cfg.stage) {
|
||||
case MSC_READ_CBW:
|
||||
@@ -849,7 +849,7 @@ static void mass_storage_bulk_out(uint8_t ep, uint32_t nbytes)
|
||||
}
|
||||
}
|
||||
|
||||
static void mass_storage_bulk_in(uint8_t ep, uint32_t nbytes)
|
||||
void mass_storage_bulk_in(uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
switch (usbd_msc_cfg.stage) {
|
||||
case MSC_DATA_IN:
|
||||
@@ -911,23 +911,26 @@ static void usbd_msc_thread(void *argument)
|
||||
}
|
||||
#endif
|
||||
|
||||
static usbd_interface_t msc_intf = {
|
||||
.class_handler = msc_storage_class_request_handler,
|
||||
.vendor_handler = NULL,
|
||||
.notify_handler = msc_storage_notify_handler,
|
||||
};
|
||||
|
||||
void usbd_msc_class_init(uint8_t out_ep, uint8_t in_ep)
|
||||
struct usbd_interface *usbd_msc_alloc_intf(const uint8_t out_ep, const uint8_t in_ep)
|
||||
{
|
||||
usbd_class_add_interface(NULL, &msc_intf);
|
||||
struct usbd_interface *intf = usb_malloc(sizeof(struct usbd_interface));
|
||||
if (intf == NULL) {
|
||||
USB_LOG_ERR("no mem to alloc intf\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mass_ep_data[0].ep_addr = out_ep;
|
||||
mass_ep_data[0].ep_cb = mass_storage_bulk_out;
|
||||
mass_ep_data[1].ep_addr = in_ep;
|
||||
mass_ep_data[1].ep_cb = mass_storage_bulk_in;
|
||||
intf->class_handler = msc_storage_class_request_handler;
|
||||
intf->custom_handler = NULL;
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = msc_storage_notify_handler;
|
||||
|
||||
usbd_interface_add_endpoint(&msc_intf, &mass_ep_data[0]);
|
||||
usbd_interface_add_endpoint(&msc_intf, &mass_ep_data[1]);
|
||||
mass_ep_data[MSD_OUT_EP_IDX].ep_addr = out_ep;
|
||||
mass_ep_data[MSD_OUT_EP_IDX].ep_cb = mass_storage_bulk_out;
|
||||
mass_ep_data[MSD_IN_EP_IDX].ep_addr = in_ep;
|
||||
mass_ep_data[MSD_IN_EP_IDX].ep_cb = mass_storage_bulk_in;
|
||||
|
||||
usbd_add_endpoint(&mass_ep_data[MSD_OUT_EP_IDX]);
|
||||
usbd_add_endpoint(&mass_ep_data[MSD_IN_EP_IDX]);
|
||||
|
||||
memset((uint8_t *)&usbd_msc_cfg, 0, sizeof(struct usbd_msc_cfg_priv));
|
||||
|
||||
@@ -935,7 +938,7 @@ void usbd_msc_class_init(uint8_t out_ep, uint8_t in_ep)
|
||||
|
||||
if (usbd_msc_cfg.scsi_blk_size > CONFIG_USBDEV_MSC_BLOCK_SIZE) {
|
||||
USB_LOG_ERR("msc block buffer overflow\r\n");
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
#ifdef CONFIG_USBDEV_MSC_THREAD
|
||||
msc_sem = usb_osal_sem_create(1);
|
||||
@@ -945,4 +948,6 @@ void usbd_msc_class_init(uint8_t out_ep, uint8_t in_ep)
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return intf;
|
||||
}
|
||||
@@ -12,7 +12,12 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void usbd_msc_class_init(uint8_t out_ep, uint8_t in_ep);
|
||||
/* Alloc msc interface driver */
|
||||
struct usbd_interface *usbd_msc_alloc_intf(const uint8_t out_ep, const uint8_t in_ep);
|
||||
|
||||
void mass_storage_bulk_out(uint8_t ep, uint32_t nbytes);
|
||||
void mass_storage_bulk_in(uint8_t ep, uint32_t nbytes);
|
||||
|
||||
void usbd_msc_get_cap(uint8_t lun, uint32_t *block_num, uint16_t *block_size);
|
||||
int usbd_msc_sector_read(uint32_t sector, uint8_t *buffer, uint32_t length);
|
||||
int usbd_msc_sector_write(uint32_t sector, uint8_t *buffer, uint32_t length);
|
||||
|
||||
@@ -21,7 +21,7 @@ struct mtp_cfg_priv {
|
||||
#define MSD_IN_EP_IDX 1
|
||||
|
||||
/* Describe EndPoints configuration */
|
||||
static usbd_endpoint_t mtp_ep_data[2];
|
||||
static struct usbd_interface mtp_ep_data[2];
|
||||
|
||||
static int mtp_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
|
||||
@@ -46,12 +46,18 @@ static void printer_notify_handler(uint8_t event, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_printer_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
struct usbd_interface *usbd_printer_alloc_intf(void)
|
||||
{
|
||||
struct usbd_interface *intf = usb_malloc(sizeof(struct usbd_interface));
|
||||
if (intf == NULL) {
|
||||
USB_LOG_ERR("no mem to alloc intf\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
intf->class_handler = printer_class_request_handler;
|
||||
intf->custom_handler = NULL;
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = printer_notify_handler;
|
||||
|
||||
usbd_class_add_interface(devclass, intf);
|
||||
}
|
||||
return intf;
|
||||
}
|
||||
@@ -12,7 +12,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void usbd_printer_add_interface(usbd_class_t *devclass, usbd_interface_t *intf);
|
||||
/* Alloc printer interface driver */
|
||||
struct usbd_interface *usbd_printer_alloc_intf(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -17,12 +17,8 @@ struct usbd_video_cfg_priv {
|
||||
struct video_probe_and_commit_controls commit;
|
||||
uint8_t power_mode;
|
||||
uint8_t error_code;
|
||||
uint8_t vcintf;
|
||||
uint8_t vsintf;
|
||||
struct video_entity_info info[3];
|
||||
} usbd_video_cfg = {
|
||||
.vcintf = 0xff,
|
||||
.vsintf = 0xff,
|
||||
.info[0] = { .bDescriptorSubtype = VIDEO_VC_INPUT_TERMINAL_DESCRIPTOR_SUBTYPE, .bEntityId = 0x01, .wTerminalType = VIDEO_ITT_CAMERA },
|
||||
.info[1] = { .bDescriptorSubtype = VIDEO_VC_OUTPUT_TERMINAL_DESCRIPTOR_SUBTYPE, .bEntityId = 0x03, .wTerminalType = 0x00 },
|
||||
.info[2] = { .bDescriptorSubtype = VIDEO_VC_PROCESSING_UNIT_DESCRIPTOR_SUBTYPE, .bEntityId = 0x02, .wTerminalType = 0x00 },
|
||||
@@ -672,13 +668,13 @@ static int video_class_request_handler(struct usb_setup_packet *setup, uint8_t *
|
||||
uint8_t intf_num = (uint8_t)setup->wIndex;
|
||||
uint8_t entity_id = (uint8_t)(setup->wIndex >> 8);
|
||||
|
||||
if (usbd_video_cfg.vcintf == intf_num) { /* Video Control Interface */
|
||||
if (intf_num == 0) { /* Video Control Interface */
|
||||
if (entity_id == 0) {
|
||||
return usbd_video_control_request_handler(setup, data, len); /* Interface Control Requests */
|
||||
} else {
|
||||
return usbd_video_control_unit_terminal_request_handler(setup, data, len); /* Unit and Terminal Requests */
|
||||
}
|
||||
} else if (usbd_video_cfg.vsintf == intf_num) { /* Video Stream Inteface */
|
||||
} else if (intf_num == 1) { /* Video Stream Inteface */
|
||||
return usbd_video_stream_request_handler(setup, data, len); /* Interface Stream Requests */
|
||||
}
|
||||
return -1;
|
||||
@@ -707,21 +703,6 @@ static void video_notify_handler(uint8_t event, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_video_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
{
|
||||
intf->class_handler = video_class_request_handler;
|
||||
intf->custom_handler = NULL;
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = video_notify_handler;
|
||||
usbd_class_add_interface(devclass, intf);
|
||||
|
||||
if (usbd_video_cfg.vcintf == 0xff) {
|
||||
usbd_video_cfg.vcintf = intf->intf_num;
|
||||
} else if (usbd_video_cfg.vsintf == 0xff) {
|
||||
usbd_video_cfg.vsintf = intf->intf_num;
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_video_probe_and_commit_controls_init(uint32_t dwFrameInterval, uint32_t dwMaxVideoFrameSize, uint32_t dwMaxPayloadTransferSize)
|
||||
{
|
||||
usbd_video_cfg.probe.hintUnion.bmHint = 0x01;
|
||||
@@ -761,6 +742,23 @@ void usbd_video_probe_and_commit_controls_init(uint32_t dwFrameInterval, uint32_
|
||||
usbd_video_cfg.commit.bMaxVersion = 0;
|
||||
}
|
||||
|
||||
struct usbd_interface *usbd_video_alloc_intf(uint32_t dwFrameInterval, uint32_t dwMaxVideoFrameSize, uint32_t dwMaxPayloadTransferSize)
|
||||
{
|
||||
struct usbd_interface *intf = usb_malloc(sizeof(struct usbd_interface));
|
||||
if (intf == NULL) {
|
||||
USB_LOG_ERR("no mem to alloc intf\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
intf->class_handler = video_class_request_handler;
|
||||
intf->custom_handler = NULL;
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = video_notify_handler;
|
||||
|
||||
usbd_video_probe_and_commit_controls_init(dwFrameInterval, dwMaxVideoFrameSize, dwMaxPayloadTransferSize);
|
||||
return intf;
|
||||
}
|
||||
|
||||
uint32_t usbd_video_mjpeg_payload_fill(uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len)
|
||||
{
|
||||
uint32_t packets;
|
||||
|
||||
@@ -12,11 +12,13 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void usbd_video_add_interface(usbd_class_t *devclass, usbd_interface_t *intf);
|
||||
/* Alloc video interface driver */
|
||||
struct usbd_interface *usbd_video_alloc_intf(uint32_t dwFrameInterval,
|
||||
uint32_t dwMaxVideoFrameSize,
|
||||
uint32_t dwMaxPayloadTransferSize);
|
||||
|
||||
void usbd_video_open(uint8_t intf);
|
||||
void usbd_video_close(uint8_t intf);
|
||||
void usbd_video_probe_and_commit_controls_init(uint32_t dwFrameInterval, uint32_t dwMaxVideoFrameSize, uint32_t dwMaxPayloadTransferSize);
|
||||
uint32_t usbd_video_mjpeg_payload_fill(uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len);
|
||||
void usbd_video_mjpeg_payload_header_toggle(uint8_t *output, uint32_t packets);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user