mirror of
https://github.com/ArteryTek/AT32F415_Firmware_Library.git
synced 2026-05-21 01:12:20 +00:00
update version to v2.1.2
This commit is contained in:
@@ -105,6 +105,7 @@ extern "C" {
|
||||
#define USB_SERIAL_STRING 3 /*!< usb standard string type serial */
|
||||
#define USB_CONFIG_STRING 4 /*!< usb standard string type config */
|
||||
#define USB_INTERFACE_STRING 5 /*!< usb standard string type interface */
|
||||
#define USB_WINUSB_OS_STRING 0xEE /*!< usb microsoft os string */
|
||||
|
||||
/**
|
||||
* @brief usb configuration attributes
|
||||
@@ -119,6 +120,12 @@ extern "C" {
|
||||
#define USB_FEATURE_REMOTE_WAKEUP 1 /*!< usb standard feature selectors remote wakeup */
|
||||
#define USB_FEATURE_TEST_MODE 2 /*!< usb standard feature selectors test mode */
|
||||
|
||||
/**
|
||||
* @brief usb winusb feature id
|
||||
*/
|
||||
#define USB_WINUSB_COMPAT_ID 0x04 /*!< usb winusb compat id os descriptor */
|
||||
#define USB_WINUSB_PROPERTIES_ID 0x05 /*!< usb winusb properties id os descriptor */
|
||||
|
||||
/**
|
||||
* @brief usb device connect state
|
||||
*/
|
||||
|
||||
@@ -87,6 +87,11 @@ typedef struct
|
||||
usbd_desc_t *(*get_device_serial_string)(void); /*!< get device serial callback */
|
||||
usbd_desc_t *(*get_device_interface_string)(void); /*!< get device interface string callback */
|
||||
usbd_desc_t *(*get_device_config_string)(void); /*!< get device device config callback */
|
||||
#if (USBD_SUPPORT_WINUSB == 1)
|
||||
usbd_desc_t *(*get_device_winusb_os_string)(void); /*!< get winusb os string */
|
||||
usbd_desc_t *(*get_device_winusb_os_feature)(void); /*!< get winusb os feature */
|
||||
usbd_desc_t *(*get_device_winusb_os_property)(void); /*!< get winusb os property */
|
||||
#endif
|
||||
}usbd_desc_handler;
|
||||
|
||||
/**
|
||||
|
||||
@@ -101,6 +101,20 @@ static usb_sts_type usbd_get_descriptor(usbd_core_type *udev)
|
||||
case USB_INTERFACE_STRING:
|
||||
desc = udev->desc_handler->get_device_interface_string();
|
||||
break;
|
||||
case USB_WINUSB_OS_STRING:
|
||||
#if (USBD_SUPPORT_WINUSB == 1)
|
||||
if(udev->desc_handler->get_device_winusb_os_string != NULL)
|
||||
{
|
||||
desc = udev->desc_handler->get_device_winusb_os_string();
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_ctrl_unsupport(udev);
|
||||
}
|
||||
#else
|
||||
usbd_ctrl_unsupport(udev);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
udev->class_handler->setup_handler(udev, &udev->setup);
|
||||
return ret;
|
||||
@@ -244,6 +258,10 @@ static usb_sts_type usbd_set_feature(usbd_core_type *udev)
|
||||
udev->class_handler->setup_handler(udev, &udev->setup);
|
||||
usbd_ctrl_send_status(udev);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_ctrl_unsupport(udev);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -277,13 +277,18 @@ static usb_sts_type class_hid_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
len = MIN(USBD_AUHID_HID_SIZ_REPORT_DESC, setup->wLength);
|
||||
buf = (uint8_t *)g_usbd_audio_hid_report;
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
}
|
||||
else if(setup->wValue >> 8 == HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
len = MIN(9, setup->wLength);
|
||||
buf = (uint8_t *)g_audio_hid_usb_desc;
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
}
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
break;
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&paudio_hid->alt_setting, 1);
|
||||
|
||||
@@ -415,13 +415,18 @@ static usb_sts_type keyboard_class_setup_handler(void *udev, usb_setup_type *set
|
||||
{
|
||||
len = MIN(USBD_VCPKYBRD_HID_SIZ_REPORT_DESC, setup->wLength);
|
||||
buf = (uint8_t *)g_usbd_vcpkybrd_hid_report;
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
}
|
||||
else if(setup->wValue >> 8 == HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
len = MIN(9, setup->wLength);
|
||||
buf = (uint8_t *)g_vcpkybrd_hid_usb_desc;
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
}
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
break;
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&vcpkybrd->alt_setting, 1);
|
||||
|
||||
@@ -160,13 +160,18 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
len = MIN(USBD_CUSHID_SIZ_REPORT_DESC, setup->wLength);
|
||||
buf = (uint8_t *)g_usbd_custom_hid_report;
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
}
|
||||
else if(setup->wValue >> 8 == HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
len = MIN(9, setup->wLength);
|
||||
buf = (uint8_t *)g_custom_hid_usb_desc;
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
}
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
break;
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&pcshid->alt_setting, 1);
|
||||
|
||||
@@ -157,13 +157,18 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
len = MIN(USBD_HIDIAP_SIZ_REPORT_DESC, setup->wLength);
|
||||
buf = (uint8_t *)g_usbd_hidiap_report;
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
}
|
||||
else if(setup->wValue >> 8 == HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
len = MIN(9, setup->wLength);
|
||||
buf = (uint8_t *)g_hidiap_usb_desc;
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
}
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
break;
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&piap->alt_setting, 1);
|
||||
|
||||
@@ -283,13 +283,18 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
len = MIN(USBD_KEYBOARD_SIZ_REPORT_DESC, setup->wLength);
|
||||
buf = (uint8_t *)g_usbd_keyboard_report;
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
}
|
||||
else if(setup->wValue >> 8 == HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
len = MIN(9, setup->wLength);
|
||||
buf = (uint8_t *)g_keyboard_usb_desc;
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
}
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
break;
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&pkeyboard->alt_setting, 1);
|
||||
|
||||
@@ -147,13 +147,18 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
len = MIN(USBD_MOUSE_SIZ_REPORT_DESC, setup->wLength);
|
||||
buf = (uint8_t *)g_usbd_mouse_report;
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
}
|
||||
else if(setup->wValue >> 8 == HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
len = MIN(9, setup->wLength);
|
||||
buf = (uint8_t *)g_mouse_usb_desc;
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
}
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
break;
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&pmouse->alt_setting, 1);
|
||||
|
||||
412
middlewares/usbd_class/winusb/winusb_class.c
Normal file
412
middlewares/usbd_class/winusb/winusb_class.c
Normal file
@@ -0,0 +1,412 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file winusb_class.c
|
||||
* @brief usb winusb class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
#include "usbd_core.h"
|
||||
#include "winusb_class.h"
|
||||
#include "winusb_desc.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_winusb_class
|
||||
* @brief usb device class win usb
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_winusb_class_private_functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
static usb_sts_type class_init_handler(void *udev);
|
||||
static usb_sts_type class_clear_handler(void *udev);
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup);
|
||||
static usb_sts_type class_ept0_tx_handler(void *udev);
|
||||
static usb_sts_type class_ept0_rx_handler(void *udev);
|
||||
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num);
|
||||
static usb_sts_type class_out_handler(void *udev, uint8_t ept_num);
|
||||
static usb_sts_type class_sof_handler(void *udev);
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event);
|
||||
#if (USBD_SUPPORT_WINUSB == 1)
|
||||
static usb_sts_type usbd_get_winusb_descriptor(usbd_core_type *udev);
|
||||
#endif
|
||||
static usb_sts_type winusb_struct_init(winusb_struct_type *p_winusb);
|
||||
|
||||
/* winusb data struct */
|
||||
winusb_struct_type winusb_struct;
|
||||
|
||||
/*winusb receive buffer define*/
|
||||
static uint32_t g_winusb_rx_buffer[16];
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler winusb_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
class_setup_handler,
|
||||
class_ept0_tx_handler,
|
||||
class_ept0_rx_handler,
|
||||
class_in_handler,
|
||||
class_out_handler,
|
||||
class_sof_handler,
|
||||
class_event_handler,
|
||||
&winusb_struct
|
||||
};
|
||||
/**
|
||||
* @brief initialize usb endpoint
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_init_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
winusb_struct_type *p_winusb = (winusb_struct_type *)pudev->class_handler->pdata;
|
||||
|
||||
/* init winusb struct */
|
||||
winusb_struct_init(p_winusb);
|
||||
|
||||
p_winusb->maxpacket = USBD_FS_WINUSB_MAXPACKET_SIZE;
|
||||
|
||||
/* open out endpoint */
|
||||
usbd_ept_open(pudev, USBD_WINUSB_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_WINUSB_OUT_MAXPACKET_SIZE);
|
||||
|
||||
/* open in endpoint */
|
||||
usbd_ept_open(pudev, USBD_WINUSB_BULK_IN_EPT, EPT_BULK_TYPE, USBD_WINUSB_IN_MAXPACKET_SIZE);
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_WINUSB_BULK_OUT_EPT, p_winusb->g_rx_buff, USBD_WINUSB_OUT_MAXPACKET_SIZE);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief clear endpoint or other state
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_clear_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
|
||||
/* close in endpoint */
|
||||
usbd_ept_close(pudev, USBD_WINUSB_BULK_IN_EPT);
|
||||
|
||||
/* close out endpoint */
|
||||
usbd_ept_close(pudev, USBD_WINUSB_BULK_OUT_EPT);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class setup request handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param setup: setup packet
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
winusb_struct_type *p_winusb = (winusb_struct_type *)pudev->class_handler->pdata;
|
||||
|
||||
switch(setup->bmRequestType & USB_REQ_TYPE_RESERVED)
|
||||
{
|
||||
/* class request */
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
/* standard request */
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch(setup->bRequest)
|
||||
{
|
||||
case USB_STD_REQ_GET_DESCRIPTOR:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&p_winusb->alt_setting, 1);
|
||||
break;
|
||||
case USB_STD_REQ_SET_INTERFACE:
|
||||
p_winusb->alt_setting = setup->wValue;
|
||||
break;
|
||||
case USB_STD_REQ_CLEAR_FEATURE:
|
||||
break;
|
||||
case USB_STD_REQ_SET_FEATURE:
|
||||
break;
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
#if (USBD_SUPPORT_WINUSB == 1)
|
||||
case USB_REQ_TYPE_VENDOR:
|
||||
if(setup->bRequest == WINUSB_BMS_VENDOR_CODE)
|
||||
{
|
||||
usbd_get_winusb_descriptor(pudev);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
#if (USBD_SUPPORT_WINUSB == 1)
|
||||
static usb_sts_type usbd_get_winusb_descriptor(usbd_core_type *udev)
|
||||
{
|
||||
usb_sts_type ret = USB_OK;
|
||||
uint16_t len = 0;
|
||||
usbd_desc_t *desc = NULL;
|
||||
uint8_t desc_type = udev->setup.wIndex;
|
||||
|
||||
switch(desc_type)
|
||||
{
|
||||
case USB_WINUSB_COMPAT_ID:
|
||||
desc = udev->desc_handler->get_device_winusb_os_feature();
|
||||
break;
|
||||
case USB_WINUSB_PROPERTIES_ID:
|
||||
desc = udev->desc_handler->get_device_winusb_os_property();
|
||||
break;
|
||||
default:
|
||||
usbd_ctrl_unsupport(udev);
|
||||
return ret;
|
||||
}
|
||||
if(desc != NULL)
|
||||
{
|
||||
if((desc->length != 0) && (udev->setup.wLength != 0))
|
||||
{
|
||||
len = MIN(desc->length , udev->setup.wLength);
|
||||
usbd_ctrl_send(udev, desc->descriptor, len);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief usb device endpoint 0 in status stage complete
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_ept0_tx_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device endpoint 0 out status stage complete
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device transmision complete handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
winusb_struct_type *p_winusb = (winusb_struct_type *)pudev->class_handler->pdata;
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
usbd_flush_tx_fifo(pudev, ept_num);
|
||||
p_winusb->g_tx_completed = 1;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device endpoint receive data
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
winusb_struct_type *p_winusb = (winusb_struct_type *)pudev->class_handler->pdata;
|
||||
|
||||
/* get endpoint receive data length */
|
||||
p_winusb->g_rxlen = usbd_get_recv_len(pudev, ept_num);
|
||||
|
||||
/*set recv flag*/
|
||||
p_winusb->g_rx_completed = 1;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device sof handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_sof_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device event handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param event: usb device event
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
break;
|
||||
case USBD_WAKEUP_EVENT:
|
||||
/* ...user code... */
|
||||
|
||||
break;
|
||||
case USBD_INISOINCOM_EVENT:
|
||||
break;
|
||||
case USBD_OUTISOINCOM_EVENT:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device winusb init
|
||||
* @param p_winusb: to the structure of winusb_struct
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type winusb_struct_init(winusb_struct_type *p_winusb)
|
||||
{
|
||||
p_winusb->g_tx_completed = 1;
|
||||
p_winusb->g_rx_completed = 0;
|
||||
p_winusb->alt_setting = 0;
|
||||
p_winusb->g_rx_buff = (uint8_t *)g_winusb_rx_buffer;
|
||||
return USB_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class rx data process
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param recv_data: receive buffer
|
||||
* @retval receive data len
|
||||
*/
|
||||
uint16_t usb_winusb_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
{
|
||||
uint16_t i_index = 0;
|
||||
uint16_t tmp_len = 0;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
winusb_struct_type *p_winusb = (winusb_struct_type *)pudev->class_handler->pdata;
|
||||
|
||||
if(p_winusb->g_rx_completed == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
p_winusb->g_rx_completed = 0;
|
||||
tmp_len = p_winusb->g_rxlen;
|
||||
for(i_index = 0; i_index < p_winusb->g_rxlen; i_index ++)
|
||||
{
|
||||
recv_data[i_index] = p_winusb->g_rx_buff[i_index];
|
||||
}
|
||||
|
||||
usbd_ept_recv(pudev, USBD_WINUSB_BULK_OUT_EPT, p_winusb->g_rx_buff, p_winusb->maxpacket);
|
||||
|
||||
return tmp_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class send data
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param send_data: send data buffer
|
||||
* @param len: send length
|
||||
* @retval error status
|
||||
*/
|
||||
error_status usb_winusb_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
{
|
||||
error_status status = SUCCESS;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
winusb_struct_type *p_winusb = (winusb_struct_type *)pudev->class_handler->pdata;
|
||||
if(p_winusb->g_tx_completed)
|
||||
{
|
||||
p_winusb->g_tx_completed = 0;
|
||||
usbd_ept_send(pudev, USBD_WINUSB_BULK_IN_EPT, send_data, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ERROR;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
115
middlewares/usbd_class/winusb/winusb_class.h
Normal file
115
middlewares/usbd_class/winusb/winusb_class.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file winusb_class.h
|
||||
* @brief usb winusb class file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __WINUSB_CLASS_H
|
||||
#define __WINUSB_CLASS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "usb_std.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USB_winusb_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_winusb_class_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief usb use endpoint define
|
||||
*/
|
||||
#define USBD_WINUSB_BULK_IN_EPT 0x81
|
||||
#define USBD_WINUSB_BULK_OUT_EPT 0x01
|
||||
|
||||
/**
|
||||
* @brief usb in and out max packet size define
|
||||
*/
|
||||
|
||||
#define USBD_FS_WINUSB_MAXPACKET_SIZE 0x40
|
||||
#define USBD_WINUSB_IN_MAXPACKET_SIZE USBD_FS_WINUSB_MAXPACKET_SIZE
|
||||
#define USBD_WINUSB_OUT_MAXPACKET_SIZE USBD_FS_WINUSB_MAXPACKET_SIZE
|
||||
|
||||
#define WINUSB_BMS_VENDOR_CODE 0xA0
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_winusb_class_exported_types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief usb winusb class struct
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t alt_setting;
|
||||
uint8_t *g_rx_buff;
|
||||
uint16_t g_len, g_rxlen;
|
||||
__IO uint8_t g_tx_completed, g_rx_completed;
|
||||
uint32_t maxpacket;
|
||||
}winusb_struct_type;
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_winusb_class_exported_functions
|
||||
* @{
|
||||
*/
|
||||
extern usbd_class_handler winusb_class_handler;
|
||||
uint16_t usb_winusb_get_rxdata(void *udev, uint8_t *recv_data);
|
||||
error_status usb_winusb_send_data(void *udev, uint8_t *send_data, uint16_t len);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
527
middlewares/usbd_class/winusb/winusb_desc.c
Normal file
527
middlewares/usbd_class/winusb/winusb_desc.c
Normal file
@@ -0,0 +1,527 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file winusb_desc.c
|
||||
* @brief usb winusb device descriptor
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
#include "stdio.h"
|
||||
#include "usb_std.h"
|
||||
#include "usbd_sdr.h"
|
||||
#include "usbd_core.h"
|
||||
#include "winusb_desc.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_winusb_desc
|
||||
* @brief usb device winusb descriptor
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_winusb_desc_private_functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
static usbd_desc_t *get_device_descriptor(void);
|
||||
static usbd_desc_t *get_device_qualifier(void);
|
||||
static usbd_desc_t *get_device_configuration(void);
|
||||
static usbd_desc_t *get_device_other_speed(void);
|
||||
static usbd_desc_t *get_device_lang_id(void);
|
||||
static usbd_desc_t *get_device_manufacturer_string(void);
|
||||
static usbd_desc_t *get_device_product_string(void);
|
||||
static usbd_desc_t *get_device_serial_string(void);
|
||||
static usbd_desc_t *get_device_interface_string(void);
|
||||
static usbd_desc_t *get_device_config_string(void);
|
||||
|
||||
static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf);
|
||||
static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len);
|
||||
static void get_serial_num(void);
|
||||
|
||||
#if (USBD_SUPPORT_WINUSB == 1)
|
||||
static usbd_desc_t *get_device_winusb_os_string(void);
|
||||
static usbd_desc_t *get_device_winusb_os_feature(void);
|
||||
static usbd_desc_t *get_device_winusb_os_property(void);
|
||||
#endif
|
||||
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD static uint8_t g_usbd_desc_buffer[256] ALIGNED_TAIL;
|
||||
|
||||
/**
|
||||
* @brief device descriptor handler structure
|
||||
*/
|
||||
usbd_desc_handler winusb_desc_handler =
|
||||
{
|
||||
get_device_descriptor,
|
||||
get_device_qualifier,
|
||||
get_device_configuration,
|
||||
get_device_other_speed,
|
||||
get_device_lang_id,
|
||||
get_device_manufacturer_string,
|
||||
get_device_product_string,
|
||||
get_device_serial_string,
|
||||
get_device_interface_string,
|
||||
get_device_config_string,
|
||||
#if (USBD_SUPPORT_WINUSB == 1)
|
||||
get_device_winusb_os_string,
|
||||
get_device_winusb_os_feature,
|
||||
get_device_winusb_os_property
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief usb device standard descriptor
|
||||
*/
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD static uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN] ALIGNED_TAIL =
|
||||
{
|
||||
USB_DEVICE_DESC_LEN, /* bLength */
|
||||
USB_DESCIPTOR_TYPE_DEVICE, /* bDescriptorType */
|
||||
0x00, /* bcdUSB */
|
||||
0x02,
|
||||
0x00, /* bDeviceClass */
|
||||
0x00, /* bDeviceSubClass */
|
||||
0x00, /* bDeviceProtocol */
|
||||
USB_MAX_EP0_SIZE, /* bMaxPacketSize */
|
||||
LBYTE(USBD_WINUSB_VENDOR_ID), /* idVendor */
|
||||
HBYTE(USBD_WINUSB_VENDOR_ID), /* idVendor */
|
||||
LBYTE(USBD_WINUSB_PRODUCT_ID), /* idProduct */
|
||||
HBYTE(USBD_WINUSB_PRODUCT_ID), /* idProduct */
|
||||
0x00, /* bcdDevice rel. 2.00 */
|
||||
0x02,
|
||||
USB_MFC_STRING, /* Index of manufacturer string */
|
||||
USB_PRODUCT_STRING, /* Index of product string */
|
||||
USB_SERIAL_STRING, /* Index of serial number string */
|
||||
1 /* bNumConfigurations */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief usb configuration standard descriptor
|
||||
*/
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_WINUSB_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
{
|
||||
USB_DEVICE_CFG_DESC_LEN, /* bLength: configuration descriptor size */
|
||||
USB_DESCIPTOR_TYPE_CONFIGURATION, /* bDescriptorType: configuration */
|
||||
LBYTE(USBD_WINUSB_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
HBYTE(USBD_WINUSB_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
0x01, /* bNumInterfaces: 1 interface */
|
||||
0x01, /* bConfigurationValue: configuration value */
|
||||
0x00, /* iConfiguration: index of string descriptor describing
|
||||
the configuration */
|
||||
0xC0, /* bmAttributes: self powered */
|
||||
0x32, /* MaxPower 100 mA: this current is used for detecting vbus */
|
||||
|
||||
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: number of interface */
|
||||
0x00, /* bAlternateSetting: alternate set */
|
||||
0x02, /* bNumEndpoints: number of endpoints */
|
||||
0xff, /* bInterfaceClass: Vendor specific*/
|
||||
0x00, /* bInterfaceSubClass: subclass code */
|
||||
0x00, /* bInterfaceProtocol: protocol code */
|
||||
0x00, /* iInterface: index of string descriptor */
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_WINUSB_BULK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_WINUSB_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_WINUSB_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_WINUSB_BULK_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_WINUSB_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_WINUSB_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief usb string lang id
|
||||
*/
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD static uint8_t g_string_lang_id[USBD_WINUSB_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_WINUSB_SIZ_STRING_LANGID,
|
||||
USB_DESCIPTOR_TYPE_STRING,
|
||||
0x09,
|
||||
0x04,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief usb string serial
|
||||
*/
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD static uint8_t g_string_serial[USBD_WINUSB_SIZ_STRING_SERIAL] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_WINUSB_SIZ_STRING_SERIAL,
|
||||
USB_DESCIPTOR_TYPE_STRING,
|
||||
};
|
||||
|
||||
|
||||
/* device descriptor */
|
||||
static usbd_desc_t device_descriptor =
|
||||
{
|
||||
USB_DEVICE_DESC_LEN,
|
||||
g_usbd_descriptor
|
||||
};
|
||||
|
||||
/* config descriptor */
|
||||
static usbd_desc_t config_descriptor =
|
||||
{
|
||||
USBD_WINUSB_CONFIG_DESC_SIZE,
|
||||
g_usbd_configuration
|
||||
};
|
||||
|
||||
/* langid descriptor */
|
||||
static usbd_desc_t langid_descriptor =
|
||||
{
|
||||
USBD_WINUSB_SIZ_STRING_LANGID,
|
||||
g_string_lang_id
|
||||
};
|
||||
|
||||
/* serial descriptor */
|
||||
static usbd_desc_t serial_descriptor =
|
||||
{
|
||||
USBD_WINUSB_SIZ_STRING_SERIAL,
|
||||
g_string_serial
|
||||
};
|
||||
|
||||
static usbd_desc_t vp_desc;
|
||||
|
||||
/**
|
||||
* @brief standard usb unicode convert
|
||||
* @param string: source string
|
||||
* @param unicode_buf: unicode buffer
|
||||
* @retval length
|
||||
*/
|
||||
static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
{
|
||||
uint16_t str_len = 0, id_pos = 2;
|
||||
uint8_t *tmp_str = string;
|
||||
|
||||
while(*tmp_str != '\0')
|
||||
{
|
||||
str_len ++;
|
||||
unicode_buf[id_pos ++] = *tmp_str ++;
|
||||
unicode_buf[id_pos ++] = 0x00;
|
||||
}
|
||||
|
||||
str_len = str_len * 2 + 2;
|
||||
unicode_buf[0] = (uint8_t)str_len;
|
||||
unicode_buf[1] = USB_DESCIPTOR_TYPE_STRING;
|
||||
|
||||
return str_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb int convert to unicode
|
||||
* @param value: int value
|
||||
* @param pbus: unicode buffer
|
||||
* @param len: length
|
||||
* @retval none
|
||||
*/
|
||||
static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
{
|
||||
uint8_t idx = 0;
|
||||
|
||||
for( idx = 0 ; idx < len ; idx ++)
|
||||
{
|
||||
if( ((value >> 28)) < 0xA )
|
||||
{
|
||||
pbuf[ 2 * idx] = (value >> 28) + '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
}
|
||||
|
||||
value = value << 4;
|
||||
|
||||
pbuf[2 * idx + 1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb get serial number
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
static void get_serial_num(void)
|
||||
{
|
||||
uint32_t serial0, serial1, serial2;
|
||||
|
||||
serial0 = *(uint32_t*)MCU_ID1;
|
||||
serial1 = *(uint32_t*)MCU_ID2;
|
||||
serial2 = *(uint32_t*)MCU_ID3;
|
||||
|
||||
serial0 += serial2;
|
||||
|
||||
if (serial0 != 0)
|
||||
{
|
||||
usbd_int_to_unicode (serial0, &g_string_serial[2] ,8);
|
||||
usbd_int_to_unicode (serial1, &g_string_serial[18] ,4);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get device descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_descriptor(void)
|
||||
{
|
||||
return &device_descriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get device qualifier
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t * get_device_qualifier(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_configuration(void)
|
||||
{
|
||||
return &config_descriptor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get other speed descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_other_speed(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get lang id descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_lang_id(void)
|
||||
{
|
||||
return &langid_descriptor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get manufacturer descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
{
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_WINUSB_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get product descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_product_string(void)
|
||||
{
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_WINUSB_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get serial descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_serial_string(void)
|
||||
{
|
||||
get_serial_num();
|
||||
return &serial_descriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get interface descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_interface_string(void)
|
||||
{
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_WINUSB_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get device config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_config_string(void)
|
||||
{
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_WINUSB_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
#if (USBD_SUPPORT_WINUSB == 1)
|
||||
|
||||
#define USB_LEN_OS_FEATURE_DESC 0x28
|
||||
#define USB_LEN_OS_PROPERTY_DESC 0x8E
|
||||
|
||||
/* os string descriptor fields */
|
||||
const uint8_t winusb_os_string[8] = {
|
||||
'M','S','F','T','1','0','0',
|
||||
WINUSB_BMS_VENDOR_CODE,
|
||||
};
|
||||
|
||||
#define U32TO8C(v) ((v & 0xFF), ((v >> 8) & 0xFF), ((v >> 16) & 0xFF), ((v >> 24) & 0xFF))
|
||||
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD static uint8_t g_usbd_winusb_os_feature[USB_LEN_OS_FEATURE_DESC] ALIGNED_TAIL =
|
||||
{
|
||||
USB_LEN_OS_FEATURE_DESC, 0x00, 0x00, 0x00, /*dwlength: 4 byte*/
|
||||
0x00, 0x01, /* bcd version 1.0 */
|
||||
0x04, 0x00, /* windex: extended compat ID descritor*/
|
||||
0x01, /* bcount the number of custom property sections */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* reserved */
|
||||
/* function section */
|
||||
0x00, /* first interface number */
|
||||
0x00, /* reserved */
|
||||
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, /* 8 byte: the function compatible id */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* 8 byte: the function subcompatible id */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* reserved 6 bytes */
|
||||
};
|
||||
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD static uint8_t g_usbd_winusb_os_property[USB_LEN_OS_PROPERTY_DESC] ALIGNED_TAIL =
|
||||
{
|
||||
USB_LEN_OS_PROPERTY_DESC, 0x00, 0x00, 0x00,/* dwlength: 4 byte*/
|
||||
0x00, 0x01, /* bcd version 1.0 */
|
||||
0x05, 0x00, /* property descriptor index(5) */
|
||||
0x01, 0x00, /* wcount: number of section (1) */
|
||||
|
||||
/* custom property section */
|
||||
0x84, 0x00, 0x00, 0x00, /* dwsize: size of property section */
|
||||
0x01, 0x00, 0x00, 0x00, /* property data type */
|
||||
0x28, 0x00, /* property name length */
|
||||
/* property name: DeviceinterfaceGUID */
|
||||
'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00,
|
||||
'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, 'r', 0x00, 'f', 0x00,
|
||||
'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00,
|
||||
'D', 0x00, 0x00, 0x00,
|
||||
|
||||
0x4E, 0x00, 0x00, 0x00, /* property data length */
|
||||
/*property data: {13eb360b-bc1e-46cb-ac8b-ef3da47b4062} */
|
||||
'{', 0x00, '1', 0x00, '3', 0x00, 'E', 0x00, 'B', 0x00, '3', 0x00,
|
||||
'6', 0x00, '0', 0x00, 'B', 0x00, '-', 0x00, 'B', 0x00, 'C', 0x00,
|
||||
'1', 0x00, 'E', 0x00, '-', 0x00, '4', 0x00, '6', 0x00, 'C', 0x00,
|
||||
'B', 0x00, '-', 0x00, 'A', 0x00, 'C', 0x00, '8', 0x00, 'B', 0x00,
|
||||
'-', 0x00, 'E', 0x00, 'F', 0x00, '3', 0x00, 'D', 0x00, 'A', 0x00,
|
||||
'4', 0x00, '7', 0x00, 'B', 0x00, '4', 0x00, '0', 0x00, '6', 0x00,
|
||||
'2', 0x00, '}', 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
static usbd_desc_t winusb_os_feature_descriptor =
|
||||
{
|
||||
USB_LEN_OS_FEATURE_DESC,
|
||||
g_usbd_winusb_os_feature
|
||||
};
|
||||
|
||||
static usbd_desc_t winusb_os_property_descriptor =
|
||||
{
|
||||
USB_LEN_OS_PROPERTY_DESC,
|
||||
g_usbd_winusb_os_property
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief get winusb os sring
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_winusb_os_string(void)
|
||||
{
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)winusb_os_string, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get winusb os feature
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_winusb_os_feature(void)
|
||||
{
|
||||
return &winusb_os_feature_descriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get winusb os property
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_winusb_os_property(void)
|
||||
{
|
||||
return &winusb_os_property_descriptor;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
92
middlewares/usbd_class/winusb/winusb_desc.h
Normal file
92
middlewares/usbd_class/winusb/winusb_desc.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file winusb_desc.h
|
||||
* @brief usb winusb descriptor header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __WINUSB_DESC_H
|
||||
#define __WINUSB_DESC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "winusb_class.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USB_winusb_desc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_winusb_desc_definition
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief usb vendor id and product id define
|
||||
*/
|
||||
#define USBD_WINUSB_VENDOR_ID 0x2E3C
|
||||
#define USBD_WINUSB_PRODUCT_ID 0x5780
|
||||
|
||||
/**
|
||||
* @brief usb descriptor size define
|
||||
*/
|
||||
#define USBD_WINUSB_CONFIG_DESC_SIZE 32
|
||||
#define USBD_WINUSB_SIZ_STRING_LANGID 4
|
||||
#define USBD_WINUSB_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
/**
|
||||
* @brief usb string define(vendor, product configuration, interface)
|
||||
*/
|
||||
#define USBD_WINUSB_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_WINUSB_DESC_PRODUCT_STRING "AT32 WinUSB"
|
||||
#define USBD_WINUSB_DESC_CONFIGURATION_STRING "WinUSB Config"
|
||||
#define USBD_WINUSB_DESC_INTERFACE_STRING "WinUSB Interface"
|
||||
|
||||
/**
|
||||
* @brief usb mcu id address deine
|
||||
*/
|
||||
#define MCU_ID1 (0x1FFFF7E8)
|
||||
#define MCU_ID2 (0x1FFFF7EC)
|
||||
#define MCU_ID3 (0x1FFFF7F0)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
extern usbd_desc_handler winusb_desc_handler;
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user