mirror of
https://github.com/ArteryTek/AT32F413_Firmware_Library.git
synced 2026-05-21 09:22:02 +00:00
update version to v2.0.4
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usb_std.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb standard 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
|
||||
* 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,
|
||||
@@ -39,7 +39,7 @@ extern "C" {
|
||||
/** @addtogroup AT32F413_middlewares_usbd_drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_standard
|
||||
* @{
|
||||
*/
|
||||
@@ -130,7 +130,7 @@ typedef enum
|
||||
USB_CONN_STATE_ADDRESSED, /*!< usb device connect state address */
|
||||
USB_CONN_STATE_CONFIGURED, /*!< usb device connect state configured */
|
||||
USB_CONN_STATE_SUSPENDED /*!< usb device connect state suspend */
|
||||
}usbd_conn_state;
|
||||
}usbd_conn_state;
|
||||
|
||||
/**
|
||||
* @brief endpoint 0 state
|
||||
@@ -141,7 +141,7 @@ typedef enum
|
||||
#define USB_EPT0_DATA_OUT 3 /*!< usb endpoint state data out */
|
||||
#define USB_EPT0_STATUS_IN 4 /*!< usb endpoint state status in */
|
||||
#define USB_EPT0_STATUS_OUT 5 /*!< usb endpoint state status out */
|
||||
#define USB_EPT0_STALL 6 /*!< usb endpoint state stall */
|
||||
#define USB_EPT0_STALL 6 /*!< usb endpoint state stall */
|
||||
|
||||
/**
|
||||
* @brief usb descriptor length
|
||||
@@ -209,7 +209,7 @@ typedef enum
|
||||
/**
|
||||
* @brief usb cdc class set line coding struct
|
||||
*/
|
||||
typedef struct
|
||||
typedef struct
|
||||
{
|
||||
uint32_t bitrate; /* line coding baud rate */
|
||||
uint8_t format; /* line coding foramt */
|
||||
@@ -266,7 +266,7 @@ typedef struct
|
||||
/** @defgroup USB_standard_exported_types
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief usb return status
|
||||
*/
|
||||
@@ -279,7 +279,7 @@ typedef enum
|
||||
USB_ERROR, /*!< usb status error */
|
||||
}usb_sts_type;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief format of usb setup data
|
||||
*/
|
||||
typedef struct
|
||||
@@ -287,12 +287,12 @@ typedef struct
|
||||
uint8_t bmRequestType; /*!< characteristics of request */
|
||||
uint8_t bRequest; /*!< specific request */
|
||||
uint16_t wValue; /*!< word-sized field that varies according to request */
|
||||
uint16_t wIndex; /*!< word-sized field that varies according to request
|
||||
uint16_t wIndex; /*!< word-sized field that varies according to request
|
||||
typically used to pass an index or offset */
|
||||
uint16_t wLength; /*!< number of bytes to transfer if there is a data stage */
|
||||
}usb_setup_type;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief format of standard device descriptor
|
||||
*/
|
||||
typedef struct
|
||||
@@ -313,28 +313,28 @@ typedef struct
|
||||
uint8_t bNumConfigurations; /*!< number of possible configurations */
|
||||
}usb_device_desc_type;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief format of standard configuration descriptor
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; /*!< size of this descriptor in bytes */
|
||||
uint8_t bDescriptorType; /*!< configuration descriptor type */
|
||||
uint8_t bDescriptorType; /*!< configuration descriptor type */
|
||||
uint16_t wTotalLength; /*!< total length of data returned for this configuration */
|
||||
uint8_t bNumInterfaces; /*!< number of interfaces supported by this configuration */
|
||||
uint8_t bConfigurationValue; /*!< value to use as an argument to the SetConfiguration() request */
|
||||
uint8_t iConfiguration; /*!< index of string descriptor describing this configuration */
|
||||
uint8_t bmAttributes; /*!< configuration characteristics
|
||||
uint8_t bmAttributes; /*!< configuration characteristics
|
||||
D7 reserved
|
||||
D6 self-powered
|
||||
D5 remote wakeup
|
||||
D4~D0 reserved */
|
||||
D4~D0 reserved */
|
||||
uint8_t bMaxPower; /*!< maximum power consumption of the usb device from the bus */
|
||||
|
||||
|
||||
|
||||
|
||||
}usb_configuration_desc_type;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief format of standard interface descriptor
|
||||
*/
|
||||
typedef struct
|
||||
@@ -343,14 +343,14 @@ typedef struct
|
||||
uint8_t bDescriptorType; /*!< interface descriptor type */
|
||||
uint8_t bInterfaceNumber; /*!< number of this interface */
|
||||
uint8_t bAlternateSetting; /*!< value used to select this alternate setting for the interface */
|
||||
uint8_t bNumEndpoints; /*!< number of endpoints used by this interface */
|
||||
uint8_t bNumEndpoints; /*!< number of endpoints used by this interface */
|
||||
uint8_t bInterfaceClass; /*!< class code (assigned by the usb-if) */
|
||||
uint8_t bInterfaceSubClass; /*!< subclass code (assigned by the usb-if) */
|
||||
uint8_t bInterfaceProtocol; /*!< protocol code (assigned by the usb-if) */
|
||||
uint8_t iInterface; /*!< index of string descriptor describing this interface */
|
||||
}usb_interface_desc_type;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief format of standard endpoint descriptor
|
||||
*/
|
||||
typedef struct
|
||||
@@ -360,10 +360,10 @@ typedef struct
|
||||
uint8_t bEndpointAddress; /*!< the address of the endpoint on the usb device described by this descriptor */
|
||||
uint8_t bmAttributes; /*!< describes the endpoints attributes when it is configured using bConfiguration value */
|
||||
uint16_t wMaxPacketSize; /*!< maximum packet size this endpoint */
|
||||
uint8_t bInterval; /*!< interval for polling endpoint for data transfers */
|
||||
uint8_t bInterval; /*!< interval for polling endpoint for data transfers */
|
||||
}usb_endpoint_desc_type;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief format of header
|
||||
*/
|
||||
typedef struct
|
||||
@@ -380,7 +380,7 @@ typedef struct
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbd_core.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb device core 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
|
||||
* 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,
|
||||
@@ -39,7 +39,7 @@ extern "C" {
|
||||
/** @addtogroup AT32F413_middlewares_usbd_drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USBD_drivers_core
|
||||
* @{
|
||||
*/
|
||||
@@ -61,7 +61,7 @@ typedef enum
|
||||
}usbd_event_type;
|
||||
|
||||
/**
|
||||
* @brief usb device descriptor struct
|
||||
* @brief usb device descriptor struct
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
@@ -70,7 +70,7 @@ typedef struct
|
||||
}usbd_desc_t;
|
||||
|
||||
/**
|
||||
* @brief usb device descriptor handler
|
||||
* @brief usb device descriptor handler
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
@@ -109,23 +109,23 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
usb_reg_type *usb_reg; /*!< usb register pointer */
|
||||
|
||||
|
||||
usbd_class_handler *class_handler; /*!< usb device class handler pointer */
|
||||
usbd_desc_handler *desc_handler; /*!< usb device descriptor handler pointer */
|
||||
|
||||
|
||||
usb_ept_info ept_in[USB_EPT_MAX_NUM]; /*!< usb in endpoint infomation struct */
|
||||
usb_ept_info ept_out[USB_EPT_MAX_NUM]; /*!< usb out endpoint infomation struct */
|
||||
|
||||
|
||||
usb_setup_type setup; /*!< usb setup type struct */
|
||||
uint8_t setup_buffer[12]; /*!< usb setup request buffer */
|
||||
|
||||
|
||||
uint8_t ept0_sts; /*!< usb control endpoint 0 state */
|
||||
uint8_t speed; /*!< usb speed */
|
||||
uint16_t ept0_wlength; /*!< usb endpoint 0 transfer length */
|
||||
|
||||
|
||||
usbd_conn_state conn_state; /*!< usb current connect state */
|
||||
usbd_conn_state old_conn_state; /*!< usb save the previous connect state */
|
||||
|
||||
|
||||
uint8_t device_addr; /*!< device address */
|
||||
uint8_t remote_wakup; /*!< remote wakeup state */
|
||||
uint8_t default_config; /*!< usb default config state */
|
||||
@@ -135,7 +135,7 @@ typedef struct
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_core_exported_functions
|
||||
* @{
|
||||
@@ -161,25 +161,25 @@ uint32_t usbd_get_recv_len(usbd_core_type *udev, uint8_t ept_addr);
|
||||
usbd_conn_state usbd_connect_state_get(usbd_core_type *udev);
|
||||
void usbd_ept_dbuffer_enable(usbd_core_type *udev, uint8_t ept_addr);
|
||||
void usbd_ept_buf_auto_define(usb_ept_info *ept_info);
|
||||
void usbd_ept_buf_custom_define( usbd_core_type *udev, uint8_t ept_addr,
|
||||
void usbd_ept_buf_custom_define( usbd_core_type *udev, uint8_t ept_addr,
|
||||
uint32_t addr);
|
||||
void usbd_ept_defaut_init(usbd_core_type *udev);
|
||||
void usbd_remote_wakeup(usbd_core_type *udev);
|
||||
void usbd_enter_suspend(usbd_core_type *udev);
|
||||
void usbd_core_init(usbd_core_type *udev,
|
||||
usb_reg_type *usb_reg,
|
||||
usbd_class_handler *dev_handler,
|
||||
usbd_class_handler *dev_handler,
|
||||
usbd_desc_handler *desc_handler,
|
||||
uint8_t core_id);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usb_int.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb 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
|
||||
* 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,
|
||||
@@ -39,11 +39,11 @@ extern "C" {
|
||||
/** @addtogroup AT32F413_middlewares_usbd_drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USBD_drivers_interrupt
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_int_exported_functions
|
||||
* @{
|
||||
*/
|
||||
@@ -57,11 +57,11 @@ void usbd_wakeup_handler(usbd_core_type *udev);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbd_sdr.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb standard request 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
|
||||
* 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,
|
||||
@@ -39,7 +39,7 @@ extern "C" {
|
||||
/** @addtogroup AT32F413_middlewares_usbd_drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USBD_drivers_standard_request
|
||||
* @{
|
||||
*/
|
||||
@@ -47,7 +47,7 @@ extern "C" {
|
||||
/** @defgroup USBD_sdr_exported_functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
void usbd_setup_request_parse(usb_setup_type *setup, uint8_t *buf);
|
||||
usb_sts_type usbd_device_request(usbd_core_type *udev);
|
||||
usb_sts_type usbd_interface_request(usbd_core_type *udev);
|
||||
@@ -56,11 +56,11 @@ usb_sts_type usbd_endpoint_request(usbd_core_type *udev);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbd_core.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb driver
|
||||
**************************************************************************
|
||||
* 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
|
||||
* 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,
|
||||
@@ -29,16 +29,16 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_drivers_core
|
||||
* @brief usb device drivers core
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_core_private_functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief usb core in transfer complete handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
@@ -49,20 +49,22 @@ void usbd_core_in_handler(usbd_core_type *udev, uint8_t ept_addr)
|
||||
{
|
||||
/* get endpoint info*/
|
||||
usb_ept_info *ept_info = &udev->ept_in[ept_addr & 0x7F];
|
||||
|
||||
|
||||
if(ept_addr == 0)
|
||||
{
|
||||
/* endpoint 0 */
|
||||
if(udev->ept0_sts == USB_EPT0_DATA_IN)
|
||||
{
|
||||
if(ept_info->ept0_slen > ept_info->maxpacket)
|
||||
if(ept_info->rem0_len > ept_info->maxpacket)
|
||||
{
|
||||
ept_info->ept0_slen -= ept_info->maxpacket;
|
||||
usbd_ept_send(udev, 0, ept_info->trans_buf,
|
||||
MIN(ept_info->ept0_slen, ept_info->maxpacket));
|
||||
ept_info->rem0_len -= ept_info->maxpacket;
|
||||
usbd_ept_send(udev, 0, ept_info->trans_buf,
|
||||
MIN(ept_info->rem0_len, ept_info->maxpacket));
|
||||
}
|
||||
/* endpoint 0 */
|
||||
else if(ept_info->last_len == ept_info->maxpacket
|
||||
&& ept_info->ept0_slen <= udev->ept0_wlength)
|
||||
&& ept_info->ept0_slen >= ept_info->maxpacket
|
||||
&& ept_info->ept0_slen < udev->ept0_wlength)
|
||||
{
|
||||
ept_info->last_len = 0;
|
||||
usbd_ept_send(udev, 0, 0, 0);
|
||||
@@ -70,16 +72,18 @@ void usbd_core_in_handler(usbd_core_type *udev, uint8_t ept_addr)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(udev->class_handler->ept0_tx_handler != 0 &&
|
||||
|
||||
if(udev->class_handler->ept0_tx_handler != 0 &&
|
||||
udev->conn_state == USB_CONN_STATE_CONFIGURED)
|
||||
{
|
||||
udev->class_handler->ept0_tx_handler(udev);
|
||||
}
|
||||
usbd_ctrl_recv_status(udev);
|
||||
{
|
||||
udev->class_handler->ept0_tx_handler(udev);
|
||||
}
|
||||
usbd_ctrl_recv_status(udev);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(udev->class_handler->in_handler != 0 &&
|
||||
else if(udev->class_handler->in_handler != 0 &&
|
||||
udev->conn_state == USB_CONN_STATE_CONFIGURED)
|
||||
{
|
||||
/* other user define endpoint */
|
||||
@@ -97,17 +101,17 @@ void usbd_core_out_handler(usbd_core_type *udev, uint8_t ept_addr)
|
||||
{
|
||||
/* get endpoint info*/
|
||||
usb_ept_info *ept_info = &udev->ept_out[ept_addr & 0x7F];
|
||||
|
||||
|
||||
if(ept_addr == 0)
|
||||
{
|
||||
/* endpoint 0 */
|
||||
if(udev->ept0_sts == USB_EPT0_DATA_OUT)
|
||||
{
|
||||
if(ept_info->ept0_slen > ept_info->maxpacket)
|
||||
if(ept_info->rem0_len > ept_info->maxpacket)
|
||||
{
|
||||
ept_info->ept0_slen -= ept_info->maxpacket;
|
||||
usbd_ept_recv(udev, ept_addr, ept_info->trans_buf,
|
||||
MIN(ept_info->ept0_slen, ept_info->maxpacket));
|
||||
ept_info->rem0_len -= ept_info->maxpacket;
|
||||
usbd_ept_recv(udev, ept_addr, ept_info->trans_buf,
|
||||
MIN(ept_info->rem0_len, ept_info->maxpacket));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -119,7 +123,7 @@ void usbd_core_out_handler(usbd_core_type *udev, uint8_t ept_addr)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(udev->class_handler->out_handler != 0 &&
|
||||
else if(udev->class_handler->out_handler != 0 &&
|
||||
udev->conn_state == USB_CONN_STATE_CONFIGURED)
|
||||
{
|
||||
/* other user define endpoint */
|
||||
@@ -137,11 +141,11 @@ void usbd_core_setup_handler(usbd_core_type *udev, uint8_t ept_num)
|
||||
{
|
||||
/* setup parse */
|
||||
usbd_setup_request_parse(&udev->setup, udev->setup_buffer);
|
||||
|
||||
|
||||
/* set ept0 status */
|
||||
udev->ept0_sts = USB_EPT0_SETUP;
|
||||
udev->ept0_wlength = udev->setup.wLength;
|
||||
|
||||
|
||||
switch(udev->setup.bmRequestType & USB_REQ_RECIPIENT_MASK)
|
||||
{
|
||||
case USB_REQ_RECIPIENT_DEVICE:
|
||||
@@ -172,10 +176,11 @@ void usbd_core_setup_handler(usbd_core_type *udev, uint8_t ept_num)
|
||||
void usbd_ctrl_send(usbd_core_type *udev, uint8_t *buffer, uint16_t len)
|
||||
{
|
||||
usb_ept_info *ept_info = &udev->ept_in[0];
|
||||
|
||||
|
||||
ept_info->ept0_slen = len;
|
||||
ept_info->rem0_len = len;
|
||||
udev->ept0_sts = USB_EPT0_DATA_IN;
|
||||
|
||||
|
||||
usbd_ept_send(udev, 0, buffer, len);
|
||||
}
|
||||
|
||||
@@ -192,8 +197,9 @@ void usbd_ctrl_recv(usbd_core_type *udev, uint8_t *buffer, uint16_t len)
|
||||
usb_ept_info *ept_info = &udev->ept_out[0];
|
||||
|
||||
ept_info->ept0_slen = len;
|
||||
ept_info->rem0_len = len;
|
||||
udev->ept0_sts = USB_EPT0_DATA_OUT;
|
||||
|
||||
|
||||
usbd_ept_recv(udev, 0, buffer, len);
|
||||
}
|
||||
|
||||
@@ -205,7 +211,7 @@ void usbd_ctrl_recv(usbd_core_type *udev, uint8_t *buffer, uint16_t len)
|
||||
void usbd_ctrl_send_status(usbd_core_type *udev)
|
||||
{
|
||||
udev->ept0_sts = USB_EPT0_STATUS_IN;
|
||||
|
||||
|
||||
usbd_ept_send(udev, 0, 0, 0);
|
||||
}
|
||||
|
||||
@@ -217,7 +223,7 @@ void usbd_ctrl_send_status(usbd_core_type *udev)
|
||||
void usbd_ctrl_recv_status(usbd_core_type *udev)
|
||||
{
|
||||
udev->ept0_sts = USB_EPT0_STATUS_OUT;
|
||||
|
||||
|
||||
usbd_ept_recv(udev, 0, 0, 0);
|
||||
}
|
||||
|
||||
@@ -230,8 +236,8 @@ void usbd_ctrl_recv_status(usbd_core_type *udev)
|
||||
void usbd_clear_stall(usbd_core_type *udev, uint8_t ept_addr)
|
||||
{
|
||||
usb_ept_info *ept_info;
|
||||
|
||||
if(ept_addr & 0x80)
|
||||
|
||||
if(ept_addr & 0x80)
|
||||
{
|
||||
/* in endpoint */
|
||||
ept_info = &udev->ept_in[ept_addr & 0x7F];
|
||||
@@ -255,7 +261,7 @@ void usbd_clear_stall(usbd_core_type *udev, uint8_t ept_addr)
|
||||
void usbd_set_stall(usbd_core_type *udev, uint8_t ept_addr)
|
||||
{
|
||||
usb_ept_info *ept_info;
|
||||
|
||||
|
||||
if(ept_addr & 0x80)
|
||||
{
|
||||
/* in endpoint */
|
||||
@@ -268,7 +274,7 @@ void usbd_set_stall(usbd_core_type *udev, uint8_t ept_addr)
|
||||
ept_info = &udev->ept_out[ept_addr & 0x7F];
|
||||
USB_SET_RXSTS(ept_info->eptn, USB_RX_STALL)
|
||||
}
|
||||
|
||||
|
||||
ept_info->stall = 1;
|
||||
}
|
||||
|
||||
@@ -298,12 +304,12 @@ void usbd_ept_send(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint
|
||||
usb_ept_info *ept_info = &udev->ept_in[ept_addr & 0x7F];
|
||||
uint16_t trs_len = 0;
|
||||
usbd_type *usbx = udev->usb_reg;
|
||||
|
||||
|
||||
/* set send data buffer and length */
|
||||
ept_info->trans_buf = buffer;
|
||||
ept_info->total_len = len;
|
||||
ept_info->trans_len = 0;
|
||||
|
||||
|
||||
if(ept_info->total_len > ept_info->maxpacket)
|
||||
{
|
||||
trs_len = ept_info->maxpacket;
|
||||
@@ -314,14 +320,14 @@ void usbd_ept_send(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint
|
||||
trs_len = len;
|
||||
ept_info->total_len = 0;
|
||||
}
|
||||
|
||||
|
||||
ept_info->last_len = trs_len;
|
||||
|
||||
|
||||
if(ept_info->is_double_buffer == 0)
|
||||
{
|
||||
/* write data to endpoint buffer */
|
||||
usb_write_packet(ept_info->trans_buf, ept_info->tx_addr, trs_len);
|
||||
|
||||
|
||||
/* set send data length */
|
||||
USB_SET_TXLEN((ept_addr & 0x7F), trs_len);
|
||||
}
|
||||
@@ -339,7 +345,7 @@ void usbd_ept_send(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint
|
||||
}
|
||||
USB_FREE_DB_USER_BUFFER((ept_addr & 0x7F), DATA_TRANS_IN);
|
||||
}
|
||||
|
||||
|
||||
/* set tx status valid */
|
||||
USB_SET_TXSTS((ept_addr & 0x7F), USB_TX_VALID);
|
||||
}
|
||||
@@ -357,12 +363,12 @@ void usbd_ept_recv(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint
|
||||
/* get endpoint info struct and register */
|
||||
usb_ept_info *ept_info = &udev->ept_out[ept_addr & 0x7F];
|
||||
uint32_t trs_len = 0;
|
||||
|
||||
|
||||
/* set receive data buffer and length */
|
||||
ept_info->trans_buf = buffer;
|
||||
ept_info->total_len = len;
|
||||
ept_info->trans_len = 0;
|
||||
|
||||
|
||||
if(ept_info->total_len > ept_info->maxpacket)
|
||||
{
|
||||
trs_len = ept_info->maxpacket;
|
||||
@@ -373,7 +379,7 @@ void usbd_ept_recv(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint
|
||||
trs_len = len;
|
||||
ept_info->total_len = 0;
|
||||
}
|
||||
|
||||
|
||||
/* set rx status valid */
|
||||
USB_SET_RXSTS((ept_addr & 0x7F), USB_RX_VALID);
|
||||
}
|
||||
@@ -416,7 +422,7 @@ void usbd_ept_dbuffer_enable(usbd_core_type *udev, uint8_t ept_addr)
|
||||
/**
|
||||
* @brief usb auto define endpoint buffer
|
||||
* @param usb_ept_info: endpoint information
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void usbd_ept_buf_auto_define(usb_ept_info *ept_info)
|
||||
{
|
||||
@@ -450,9 +456,9 @@ void usbd_ept_buf_auto_define(usb_ept_info *ept_info)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_addr: endpoint number
|
||||
* @param addr: usb fifo offset address
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void usbd_ept_buf_custom_define(usbd_core_type *udev, uint8_t ept_addr,
|
||||
void usbd_ept_buf_custom_define(usbd_core_type *udev, uint8_t ept_addr,
|
||||
uint32_t addr)
|
||||
{
|
||||
usb_ept_info *ept_info;
|
||||
@@ -466,7 +472,7 @@ void usbd_ept_buf_custom_define(usbd_core_type *udev, uint8_t ept_addr,
|
||||
/* in endpoint info */
|
||||
ept_info = &udev->ept_in[ept_addr & 0x7F];
|
||||
}
|
||||
|
||||
|
||||
if(ept_info->is_double_buffer == 0)
|
||||
{
|
||||
if( ept_info->inout == DATA_TRANS_IN )
|
||||
@@ -498,7 +504,7 @@ void usbd_ept_open(usbd_core_type *udev, uint8_t ept_addr, uint8_t ept_type, uin
|
||||
{
|
||||
usbd_type *usbx = udev->usb_reg;
|
||||
usb_ept_info *ept_info;
|
||||
|
||||
|
||||
if((ept_addr & 0x80) == 0)
|
||||
{
|
||||
/* out endpoint info */
|
||||
@@ -511,11 +517,11 @@ void usbd_ept_open(usbd_core_type *udev, uint8_t ept_addr, uint8_t ept_type, uin
|
||||
ept_info = &udev->ept_in[ept_addr & 0x7F];
|
||||
ept_info->inout = DATA_TRANS_IN;
|
||||
}
|
||||
|
||||
|
||||
/* set endpoint maxpacket and type */
|
||||
ept_info->maxpacket = (maxpacket + 1) & 0xFFFE;
|
||||
ept_info->trans_type = ept_type;
|
||||
|
||||
|
||||
#ifdef USB_EPT_AUTO_MALLOC_BUFFER
|
||||
usbd_ept_buf_auto_define(ept_info);
|
||||
#endif
|
||||
@@ -531,7 +537,7 @@ void usbd_ept_open(usbd_core_type *udev, uint8_t ept_addr, uint8_t ept_type, uin
|
||||
*/
|
||||
void usbd_ept_close(usbd_core_type *udev, uint8_t ept_addr)
|
||||
{
|
||||
usb_ept_info *ept_info;
|
||||
usb_ept_info *ept_info;
|
||||
if(ept_addr & 0x80)
|
||||
{
|
||||
/* in endpoint */
|
||||
@@ -542,7 +548,7 @@ void usbd_ept_close(usbd_core_type *udev, uint8_t ept_addr)
|
||||
/* out endpoint */
|
||||
ept_info = &udev->ept_out[ept_addr & 0x7F];
|
||||
}
|
||||
|
||||
|
||||
/* close endpoint */
|
||||
usb_ept_close(udev->usb_reg, ept_info);
|
||||
}
|
||||
@@ -597,15 +603,15 @@ void usbd_remote_wakeup(usbd_core_type *udev)
|
||||
{
|
||||
/* set connect state */
|
||||
udev->conn_state = udev->old_conn_state;
|
||||
|
||||
|
||||
usb_exit_suspend(udev->usb_reg);
|
||||
|
||||
|
||||
usb_remote_wkup_set(udev->usb_reg);
|
||||
|
||||
|
||||
usb_delay_ms(10);
|
||||
|
||||
|
||||
usb_remote_wkup_clear(udev->usb_reg);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -635,10 +641,10 @@ void usbd_ept_defaut_init(usbd_core_type *udev)
|
||||
udev->ept_in[i_index].maxpacket = 0;
|
||||
udev->ept_in[i_index].trans_buf = 0;
|
||||
udev->ept_in[i_index].total_len = 0;
|
||||
udev->ept_in[i_index].tx_addr = 0;
|
||||
udev->ept_in[i_index].rx_addr = 0;
|
||||
udev->ept_in[i_index].tx_addr = 0;
|
||||
udev->ept_in[i_index].rx_addr = 0;
|
||||
}
|
||||
|
||||
|
||||
/* init out endpoint info structure */
|
||||
for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++)
|
||||
{
|
||||
@@ -648,14 +654,14 @@ void usbd_ept_defaut_init(usbd_core_type *udev)
|
||||
udev->ept_out[i_index].maxpacket = 0;
|
||||
udev->ept_out[i_index].trans_buf = 0;
|
||||
udev->ept_out[i_index].total_len = 0;
|
||||
udev->ept_out[i_index].rx_addr = 0;
|
||||
udev->ept_out[i_index].tx_addr = 0;
|
||||
udev->ept_out[i_index].rx_addr = 0;
|
||||
udev->ept_out[i_index].tx_addr = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief initializes the usb core
|
||||
* @brief initializes the usb core
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param usb_reg: usb register pointer (USB)
|
||||
* @param class_handler: usb class handler
|
||||
@@ -665,42 +671,42 @@ void usbd_ept_defaut_init(usbd_core_type *udev)
|
||||
*/
|
||||
void usbd_core_init(usbd_core_type *udev,
|
||||
usb_reg_type *usb_reg,
|
||||
usbd_class_handler *class_handler,
|
||||
usbd_class_handler *class_handler,
|
||||
usbd_desc_handler *desc_handler,
|
||||
uint8_t core_id)
|
||||
{
|
||||
/* usb class handler */
|
||||
udev->class_handler = class_handler;
|
||||
|
||||
|
||||
/* usb description handler */
|
||||
udev->desc_handler = desc_handler;
|
||||
|
||||
|
||||
/* set usb register type */
|
||||
udev->usb_reg = usb_reg;
|
||||
|
||||
|
||||
/* set usb connect state to default */
|
||||
udev->conn_state = USB_CONN_STATE_DEFAULT;
|
||||
|
||||
|
||||
/* init in endpoint info structure */
|
||||
usbd_ept_defaut_init(udev);
|
||||
|
||||
|
||||
#ifdef USB_BUFFER_SIZE_EX
|
||||
/* usb buffer size extend 768-1280 byte */
|
||||
usb_usbbufs_enable(usb_reg, TRUE);
|
||||
#endif
|
||||
|
||||
|
||||
/*usb register config */
|
||||
usb_dev_init(udev->usb_reg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbd_int.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb interrupt request
|
||||
**************************************************************************
|
||||
* 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
|
||||
* 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,
|
||||
@@ -28,11 +28,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_drivers_interrupt
|
||||
* @brief usb device interrupt
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_int_private_functions
|
||||
* @{
|
||||
@@ -48,55 +48,55 @@ void usbd_irq_handler(usbd_core_type *udev)
|
||||
usbd_type *usbx = udev->usb_reg;
|
||||
uint32_t sts_val = usbx->intsts;
|
||||
uint32_t sts_ien = usbx->ctrl;
|
||||
|
||||
|
||||
if(sts_val & USB_TC_FLAG)
|
||||
{
|
||||
/* endpoint tc interrupt handler */
|
||||
usbd_ept_loop_handler(udev);
|
||||
}
|
||||
|
||||
|
||||
if(sts_val & USB_RST_FLAG)
|
||||
{
|
||||
/* clear reset flag */
|
||||
usb_flag_clear(usbx, USB_RST_FLAG);
|
||||
|
||||
|
||||
/* reset interrupt handler */
|
||||
usbd_reset_handler(udev);
|
||||
}
|
||||
|
||||
if((sts_val & USB_SOF_FLAG) &&
|
||||
|
||||
if((sts_val & USB_SOF_FLAG) &&
|
||||
(sts_ien & USB_SOF_INT))
|
||||
{
|
||||
/* clear sof flag */
|
||||
usb_flag_clear(usbx, USB_SOF_FLAG);
|
||||
|
||||
|
||||
/* sof interrupt handler */
|
||||
usbd_sof_handler(udev);
|
||||
}
|
||||
|
||||
if((sts_val & USB_LSOF_FLAG) &&
|
||||
|
||||
if((sts_val & USB_LSOF_FLAG) &&
|
||||
(sts_ien & USB_LSOF_INT))
|
||||
{
|
||||
/* clear lsof flag */
|
||||
usb_flag_clear(usbx, USB_LSOF_FLAG);
|
||||
}
|
||||
|
||||
if((sts_val & USB_SP_FLAG) &&
|
||||
|
||||
if((sts_val & USB_SP_FLAG) &&
|
||||
(sts_ien & USB_SP_INT))
|
||||
{
|
||||
/* clear suspend flag */
|
||||
usb_flag_clear(usbx, USB_SP_FLAG);
|
||||
|
||||
|
||||
/* usb suspend interrupt handler */
|
||||
usbd_suspend_handler(udev);
|
||||
}
|
||||
|
||||
if((sts_val & USB_WK_FLAG) &&
|
||||
|
||||
if((sts_val & USB_WK_FLAG) &&
|
||||
(sts_ien & USB_WK_INT))
|
||||
{
|
||||
/* usb wakeup interrupt handler */
|
||||
usbd_wakeup_handler(udev);
|
||||
|
||||
|
||||
/* clear wakeup flag */
|
||||
usb_flag_clear(usbx, USB_WK_FLAG);
|
||||
}
|
||||
@@ -114,22 +114,22 @@ void usbd_eptn_handler(usbd_core_type *udev, usb_ept_number_type ept_num)
|
||||
usb_ept_info *ept_info;
|
||||
uint32_t ept_val = usbx->ept[ept_num];
|
||||
uint16_t length;
|
||||
|
||||
|
||||
/* in interrupt request */
|
||||
if(ept_val & USB_TXTC)
|
||||
{
|
||||
/* get endpoint register and in transfer info struct */
|
||||
ept_info = &udev->ept_in[ept_num];
|
||||
|
||||
|
||||
/* clear endpoint tc flag */
|
||||
USB_CLEAR_TXTC(ept_num);
|
||||
|
||||
|
||||
/* get endpoint tx length */
|
||||
ept_info->trans_len = USB_GET_TX_LEN(ept_num);
|
||||
|
||||
|
||||
/* offset the trans buffer */
|
||||
ept_info->trans_buf += ept_info->trans_len;
|
||||
|
||||
|
||||
if(ept_info->total_len == 0 || ept_num == USB_EPT0)
|
||||
{
|
||||
/* in transfer complete */
|
||||
@@ -150,23 +150,23 @@ void usbd_eptn_handler(usbd_core_type *udev, usb_ept_number_type ept_num)
|
||||
else
|
||||
{
|
||||
/* setup and out interrupt request */
|
||||
|
||||
|
||||
/* get endpoint register and out transfer info struct */
|
||||
ept_info = &udev->ept_out[ept_num];
|
||||
|
||||
|
||||
if((ept_val & USB_SETUPTC) != 0)
|
||||
{
|
||||
/* endpoint setup interrupt request */
|
||||
|
||||
|
||||
/* get endpoint received data length */
|
||||
ept_info->trans_len = USB_GET_RX_LEN(ept_num);
|
||||
|
||||
|
||||
/* read endpoint received data */
|
||||
usb_read_packet(udev->setup_buffer, ept_info->rx_addr, ept_info->trans_len);
|
||||
|
||||
|
||||
/* clear endpoint rx tc flag */
|
||||
USB_CLEAR_RXTC(USB_EPT0);
|
||||
|
||||
|
||||
/* endpoint setup complete handler */
|
||||
usbd_core_setup_handler(udev, ept_num);
|
||||
}
|
||||
@@ -174,12 +174,12 @@ void usbd_eptn_handler(usbd_core_type *udev, usb_ept_number_type ept_num)
|
||||
{
|
||||
/* endpoint out interrupt request */
|
||||
USB_CLEAR_RXTC(ept_num);
|
||||
|
||||
|
||||
if(ept_info->is_double_buffer == 0)
|
||||
{
|
||||
/* get endpoint received data length */
|
||||
length = USB_GET_RX_LEN(ept_num);
|
||||
|
||||
|
||||
/* read endpoint received data */
|
||||
usb_read_packet(ept_info->trans_buf, ept_info->rx_addr, length);
|
||||
}
|
||||
@@ -197,11 +197,11 @@ void usbd_eptn_handler(usbd_core_type *udev, usb_ept_number_type ept_num)
|
||||
}
|
||||
USB_FREE_DB_USER_BUFFER(ept_num, DATA_TRANS_OUT);
|
||||
}
|
||||
|
||||
|
||||
/* set received data length */
|
||||
ept_info->trans_len += length;
|
||||
ept_info->trans_buf += length;
|
||||
|
||||
|
||||
if(ept_info->total_len == 0 || length < ept_info->maxpacket || ept_num == USB_EPT0)
|
||||
{
|
||||
/* out transfer complete */
|
||||
@@ -226,12 +226,12 @@ void usbd_ept_loop_handler(usbd_core_type *udev)
|
||||
usbd_type *usbx = udev->usb_reg;
|
||||
usb_ept_number_type ept_num = USB_EPT0;
|
||||
uint32_t sts_val;
|
||||
|
||||
|
||||
while((sts_val = usbx->intsts) & USB_TC_FLAG)
|
||||
{
|
||||
/* get the interrupt endpoint number */
|
||||
/* get the interrupt endpoint number */
|
||||
ept_num = (usb_ept_number_type)(sts_val & USB_EPT_NUM_FLAG);
|
||||
|
||||
|
||||
usbd_eptn_handler(udev, ept_num);
|
||||
}
|
||||
}
|
||||
@@ -245,25 +245,25 @@ void usbd_reset_handler(usbd_core_type *udev)
|
||||
{
|
||||
/* free usb buffer */
|
||||
usb_buffer_free();
|
||||
|
||||
|
||||
usbd_ept_defaut_init(udev);
|
||||
#ifndef USB_EPT_AUTO_MALLOC_BUFFER
|
||||
usbd_ept_buf_custom_define(udev, 0x80, EPT0_TX_ADDR);
|
||||
usbd_ept_buf_custom_define(udev, 0x00, EPT0_RX_ADDR);
|
||||
#endif
|
||||
|
||||
|
||||
/* open endpoint 0 out */
|
||||
usbd_ept_open(udev, 0x00, EPT_CONTROL_TYPE, 0x40);
|
||||
|
||||
|
||||
/* open endpoint 0 in */
|
||||
usbd_ept_open(udev, 0x80, EPT_CONTROL_TYPE, 0x40);
|
||||
|
||||
|
||||
/* set device address to 0 */
|
||||
usb_set_address(udev->usb_reg, 0);
|
||||
|
||||
|
||||
/* usb connect state set to default */
|
||||
udev->conn_state = USB_CONN_STATE_DEFAULT;
|
||||
|
||||
|
||||
/* user define reset event */
|
||||
if(udev->class_handler->event_handler)
|
||||
udev->class_handler->event_handler(udev, USBD_RESET_EVENT);
|
||||
@@ -290,13 +290,13 @@ void usbd_suspend_handler(usbd_core_type *udev)
|
||||
{
|
||||
/* save connect state */
|
||||
udev->old_conn_state = udev->conn_state;
|
||||
|
||||
|
||||
/* set current state to suspend */
|
||||
udev->conn_state = USB_CONN_STATE_SUSPENDED;
|
||||
|
||||
|
||||
/* enter suspend mode */
|
||||
usbd_enter_suspend(udev);
|
||||
|
||||
|
||||
/* user define suspend event */
|
||||
if(udev->class_handler->event_handler)
|
||||
udev->class_handler->event_handler(udev, USBD_SUSPEND_EVENT);
|
||||
@@ -311,10 +311,10 @@ void usbd_wakeup_handler(usbd_core_type *udev)
|
||||
{
|
||||
/* exit suspend mode */
|
||||
usb_exit_suspend(udev->usb_reg);
|
||||
|
||||
|
||||
/* restore connect state */
|
||||
udev->conn_state = udev->old_conn_state;
|
||||
|
||||
|
||||
/* user define wakeup event */
|
||||
if(udev->class_handler->event_handler)
|
||||
udev->class_handler->event_handler(udev, USBD_WAKEUP_EVENT);
|
||||
@@ -322,7 +322,7 @@ void usbd_wakeup_handler(usbd_core_type *udev)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -330,4 +330,4 @@ void usbd_wakeup_handler(usbd_core_type *udev)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbd_sdr.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb standard device request
|
||||
**************************************************************************
|
||||
* 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
|
||||
* 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,
|
||||
@@ -28,11 +28,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_drivers_standard_request
|
||||
* @brief usb device standard_request
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_sdr_private_functions
|
||||
* @{
|
||||
@@ -50,7 +50,7 @@ static usb_sts_type usbd_set_configuration(usbd_core_type *udev);
|
||||
* @brief usb parse standard setup request
|
||||
* @param setup: setup structure
|
||||
* @param buf: setup buffer
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void usbd_setup_request_parse(usb_setup_type *setup, uint8_t *buf)
|
||||
{
|
||||
@@ -64,7 +64,7 @@ void usbd_setup_request_parse(usb_setup_type *setup, uint8_t *buf)
|
||||
/**
|
||||
* @brief get usb standard device description request
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type usbd_get_descriptor(usbd_core_type *udev)
|
||||
{
|
||||
@@ -104,7 +104,7 @@ static usb_sts_type usbd_get_descriptor(usbd_core_type *udev)
|
||||
desc = udev->desc_handler->get_device_interface_string();
|
||||
break;
|
||||
default:
|
||||
usbd_ctrl_unsupport(udev);
|
||||
udev->class_handler->setup_handler(udev, &udev->setup);
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
@@ -119,7 +119,7 @@ static usb_sts_type usbd_get_descriptor(usbd_core_type *udev)
|
||||
usbd_ctrl_unsupport(udev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
if(desc != NULL)
|
||||
{
|
||||
if((desc->length != 0) && (udev->setup.wLength != 0))
|
||||
@@ -134,22 +134,22 @@ static usb_sts_type usbd_get_descriptor(usbd_core_type *udev)
|
||||
/**
|
||||
* @brief this request sets the device address
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type usbd_set_address(usbd_core_type *udev)
|
||||
{
|
||||
usb_sts_type ret = USB_OK;
|
||||
usb_setup_type *setup = &udev->setup;
|
||||
uint8_t dev_addr;
|
||||
|
||||
|
||||
/* if wIndex or wLength are non-zero, then the behavior of
|
||||
the device is not specified
|
||||
*/
|
||||
if(setup->wIndex == 0 && setup->wLength == 0)
|
||||
{
|
||||
dev_addr = (uint8_t)(setup->wValue) & 0x7f;
|
||||
|
||||
/* device behavior when this request is received
|
||||
|
||||
/* device behavior when this request is received
|
||||
while the device is in the configured state is not specified.*/
|
||||
if(udev->conn_state == USB_CONN_STATE_CONFIGURED )
|
||||
{
|
||||
@@ -158,7 +158,7 @@ static usb_sts_type usbd_set_address(usbd_core_type *udev)
|
||||
else
|
||||
{
|
||||
udev->device_addr = dev_addr;
|
||||
|
||||
|
||||
if(dev_addr != 0)
|
||||
{
|
||||
udev->conn_state = USB_CONN_STATE_ADDRESSED;
|
||||
@@ -180,7 +180,7 @@ static usb_sts_type usbd_set_address(usbd_core_type *udev)
|
||||
/**
|
||||
* @brief get usb status request
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type usbd_get_status(usbd_core_type *udev)
|
||||
{
|
||||
@@ -205,7 +205,7 @@ static usb_sts_type usbd_get_status(usbd_core_type *udev)
|
||||
/**
|
||||
* @brief clear usb feature request
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type usbd_clear_feature(usbd_core_type *udev)
|
||||
{
|
||||
@@ -233,7 +233,7 @@ static usb_sts_type usbd_clear_feature(usbd_core_type *udev)
|
||||
/**
|
||||
* @brief set usb feature request
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type usbd_set_feature(usbd_core_type *udev)
|
||||
{
|
||||
@@ -251,7 +251,7 @@ static usb_sts_type usbd_set_feature(usbd_core_type *udev)
|
||||
/**
|
||||
* @brief get usb configuration request
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type usbd_get_configuration(usbd_core_type *udev)
|
||||
{
|
||||
@@ -283,7 +283,7 @@ static usb_sts_type usbd_get_configuration(usbd_core_type *udev)
|
||||
/**
|
||||
* @brief sets the usb device configuration request
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type usbd_set_configuration(usbd_core_type *udev)
|
||||
{
|
||||
@@ -291,7 +291,7 @@ static usb_sts_type usbd_set_configuration(usbd_core_type *udev)
|
||||
static uint8_t config_value;
|
||||
usb_setup_type *setup = &udev->setup;
|
||||
config_value = (uint8_t)setup->wValue;
|
||||
|
||||
|
||||
if(setup->wIndex == 0 && setup->wLength == 0)
|
||||
{
|
||||
switch(udev->conn_state)
|
||||
@@ -308,7 +308,7 @@ static usb_sts_type usbd_set_configuration(usbd_core_type *udev)
|
||||
{
|
||||
usbd_ctrl_send_status(udev);
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case USB_CONN_STATE_CONFIGURED:
|
||||
if(config_value == 0)
|
||||
@@ -316,11 +316,11 @@ static usb_sts_type usbd_set_configuration(usbd_core_type *udev)
|
||||
udev->conn_state = USB_CONN_STATE_ADDRESSED;
|
||||
udev->dev_config = config_value;
|
||||
udev->class_handler->clear_handler(udev);
|
||||
usbd_ctrl_send_status(udev);
|
||||
usbd_ctrl_send_status(udev);
|
||||
}
|
||||
else if(config_value == udev->dev_config)
|
||||
{
|
||||
udev->class_handler->clear_handler(udev);
|
||||
udev->class_handler->clear_handler(udev);
|
||||
udev->dev_config = config_value;
|
||||
udev->class_handler->init_handler(udev);
|
||||
usbd_ctrl_send_status(udev);
|
||||
@@ -345,7 +345,7 @@ static usb_sts_type usbd_set_configuration(usbd_core_type *udev)
|
||||
/**
|
||||
* @brief standard usb device requests
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type usbd_device_request(usbd_core_type *udev)
|
||||
{
|
||||
@@ -389,7 +389,7 @@ usb_sts_type usbd_device_request(usbd_core_type *udev)
|
||||
/**
|
||||
* @brief standard usb interface requests
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type usbd_interface_request(usbd_core_type *udev)
|
||||
{
|
||||
@@ -414,7 +414,7 @@ usb_sts_type usbd_interface_request(usbd_core_type *udev)
|
||||
/**
|
||||
* @brief standard usb endpoint requests
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type usbd_endpoint_request(usbd_core_type *udev)
|
||||
{
|
||||
@@ -422,7 +422,7 @@ usb_sts_type usbd_endpoint_request(usbd_core_type *udev)
|
||||
usb_setup_type *setup = &udev->setup;
|
||||
uint8_t ept_addr = LBYTE(setup->wIndex);
|
||||
usb_ept_info *ept_info;
|
||||
|
||||
|
||||
if((setup->bmRequestType & USB_REQ_TYPE_RESERVED) == USB_REQ_TYPE_CLASS)
|
||||
{
|
||||
udev->class_handler->setup_handler(udev, &udev->setup);
|
||||
@@ -442,11 +442,11 @@ usb_sts_type usbd_endpoint_request(usbd_core_type *udev)
|
||||
{
|
||||
if((ept_addr & 0x80) != 0)
|
||||
{
|
||||
ept_info = &udev->ept_in[ept_addr & 0x7F];
|
||||
ept_info = &udev->ept_in[ept_addr & 0x7F];
|
||||
}
|
||||
else
|
||||
{
|
||||
ept_info = &udev->ept_out[ept_addr & 0x7F];
|
||||
ept_info = &udev->ept_out[ept_addr & 0x7F];
|
||||
}
|
||||
if(ept_info->stall == 1)
|
||||
{
|
||||
@@ -504,7 +504,7 @@ usb_sts_type usbd_endpoint_request(usbd_core_type *udev)
|
||||
if((ept_addr != 0x00) && (ept_addr != 0x80))
|
||||
{
|
||||
usbd_set_stall(udev, ept_addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
udev->class_handler->setup_handler(udev, &udev->setup);
|
||||
usbd_ctrl_send_status(udev);
|
||||
@@ -523,7 +523,7 @@ usb_sts_type usbd_endpoint_request(usbd_core_type *udev)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
Reference in New Issue
Block a user