mirror of
https://github.com/ArteryTek/AT32F413_Firmware_Library.git
synced 2026-05-21 01:12:01 +00:00
update version to v2.0.4
This commit is contained in:
@@ -65,7 +65,7 @@ typedef struct corCoRoutineControlBlock
|
||||
* crCOROUTINE_CODE pxCoRoutineCode,
|
||||
* UBaseType_t uxPriority,
|
||||
* UBaseType_t uxIndex
|
||||
* );
|
||||
* );
|
||||
* </pre>
|
||||
*
|
||||
* Create a new co-routine and add it to the list of co-routines that are
|
||||
|
||||
@@ -2758,7 +2758,7 @@ void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
|
||||
* // spent in the Blocked state does not exceed MAX_TIME_TO_WAIT. This
|
||||
* // continues until either the buffer contains at least uxWantedBytes bytes,
|
||||
* // or the total amount of time spent in the Blocked state reaches
|
||||
* // MAX_TIME_TO_WAIT – at which point the task reads however many bytes are
|
||||
* // MAX_TIME_TO_WAIT �at which point the task reads however many bytes are
|
||||
* // available up to a maximum of uxWantedBytes.
|
||||
*
|
||||
* size_t xUART_Receive( uint8_t *pucBuffer, size_t uxWantedBytes )
|
||||
|
||||
@@ -1329,10 +1329,10 @@ BaseType_t xTimerGenericCommand( TimerHandle_t xTimer,
|
||||
/**
|
||||
* task.h
|
||||
* <pre>void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, StackType_t ** ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize ) </pre>
|
||||
*
|
||||
* This function is used to provide a statically allocated block of memory to FreeRTOS to hold the Timer Task TCB. This function is required when
|
||||
*
|
||||
* This function is used to provide a statically allocated block of memory to FreeRTOS to hold the Timer Task TCB. This function is required when
|
||||
* configSUPPORT_STATIC_ALLOCATION is set. For more information see this URI: https://www.FreeRTOS.org/a00110.html#configSUPPORT_STATIC_ALLOCATION
|
||||
*
|
||||
*
|
||||
* @param ppxTimerTaskTCBBuffer A handle to a statically allocated TCB buffer
|
||||
* @param ppxTimerTaskStackBuffer A handle to a statically allocated Stack buffer for thie idle task
|
||||
* @param pulTimerTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer
|
||||
|
||||
@@ -80,8 +80,8 @@ void * pvPortMalloc( size_t xWantedSize )
|
||||
if ( (xWantedSize + ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) )) > xWantedSize )
|
||||
{
|
||||
xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
xWantedSize = 0;
|
||||
}
|
||||
|
||||
@@ -133,13 +133,13 @@ void * pvPortMalloc( size_t xWantedSize )
|
||||
|
||||
/* The wanted size must be increased so it can contain a BlockLink_t
|
||||
* structure in addition to the requested amount of bytes. */
|
||||
if( ( xWantedSize > 0 ) &&
|
||||
if( ( xWantedSize > 0 ) &&
|
||||
( ( xWantedSize + heapSTRUCT_SIZE ) > xWantedSize ) ) /* Overflow check */
|
||||
{
|
||||
xWantedSize += heapSTRUCT_SIZE;
|
||||
|
||||
/* Byte alignment required. Check for overflow. */
|
||||
if( ( xWantedSize + ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ) )
|
||||
if( ( xWantedSize + ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ) )
|
||||
> xWantedSize )
|
||||
{
|
||||
xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
|
||||
@@ -148,11 +148,11 @@ void * pvPortMalloc( size_t xWantedSize )
|
||||
else
|
||||
{
|
||||
xWantedSize = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
xWantedSize = 0;
|
||||
xWantedSize = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ void * pvPortMalloc( size_t xWantedSize )
|
||||
{
|
||||
/* The wanted size must be increased so it can contain a BlockLink_t
|
||||
* structure in addition to the requested amount of bytes. */
|
||||
if( ( xWantedSize > 0 ) &&
|
||||
if( ( xWantedSize > 0 ) &&
|
||||
( ( xWantedSize + xHeapStructSize ) > xWantedSize ) ) /* Overflow check */
|
||||
{
|
||||
xWantedSize += xHeapStructSize;
|
||||
@@ -147,7 +147,7 @@ void * pvPortMalloc( size_t xWantedSize )
|
||||
if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0x00 )
|
||||
{
|
||||
/* Byte alignment required. Check for overflow. */
|
||||
if( ( xWantedSize + ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ) )
|
||||
if( ( xWantedSize + ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ) )
|
||||
> xWantedSize )
|
||||
{
|
||||
xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
|
||||
@@ -156,14 +156,14 @@ void * pvPortMalloc( size_t xWantedSize )
|
||||
else
|
||||
{
|
||||
xWantedSize = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
xWantedSize = 0;
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ void * pvPortMalloc( size_t xWantedSize )
|
||||
{
|
||||
/* The wanted size is increased so it can contain a BlockLink_t
|
||||
* structure in addition to the requested amount of bytes. */
|
||||
if( ( xWantedSize > 0 ) &&
|
||||
if( ( xWantedSize > 0 ) &&
|
||||
( ( xWantedSize + xHeapStructSize ) > xWantedSize ) ) /* Overflow check */
|
||||
{
|
||||
xWantedSize += xHeapStructSize;
|
||||
@@ -162,8 +162,8 @@ void * pvPortMalloc( size_t xWantedSize )
|
||||
xWantedSize )
|
||||
{
|
||||
xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
xWantedSize = 0;
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
|
||||
{
|
||||
pucAllocatedMemory = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if( pucAllocatedMemory != NULL )
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file i2c_application.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief i2c application libray 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,
|
||||
@@ -38,8 +38,8 @@ extern "C" {
|
||||
/** @addtogroup AT32F413_middlewares_i2c_application_library
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/** @defgroup I2C_library_event_check_flag
|
||||
* @{
|
||||
*/
|
||||
@@ -56,7 +56,7 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
typedef enum
|
||||
{
|
||||
I2C_INT_MA_TX = 0,
|
||||
I2C_INT_MA_RX,
|
||||
@@ -65,7 +65,7 @@ typedef enum
|
||||
I2C_DMA_MA_TX,
|
||||
I2C_DMA_MA_RX,
|
||||
I2C_DMA_SLA_TX,
|
||||
I2C_DMA_SLA_RX,
|
||||
I2C_DMA_SLA_RX,
|
||||
} i2c_mode_type;
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ typedef enum
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
typedef enum
|
||||
{
|
||||
I2C_OK = 0, /*!< no error */
|
||||
I2C_ERR_STEP_1, /*!< step 1 error */
|
||||
@@ -99,7 +99,7 @@ typedef enum
|
||||
I2C_ERR_ACKFAIL, /*!< ackfail error */
|
||||
I2C_ERR_TIMEOUT, /*!< timeout error */
|
||||
I2C_ERR_INTERRUPT, /*!< interrupt error */
|
||||
|
||||
|
||||
} i2c_status_type;
|
||||
|
||||
/**
|
||||
@@ -110,14 +110,14 @@ typedef enum
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
typedef struct
|
||||
{
|
||||
i2c_type *i2cx; /*!< i2c registers base address */
|
||||
uint8_t *pbuff; /*!< pointer to i2c transfer buffer */
|
||||
__IO uint16_t psize; /*!< i2c transfer size */
|
||||
__IO uint16_t pcount; /*!< i2c transfer counter */
|
||||
__IO uint32_t mode; /*!< i2c communication mode */
|
||||
__IO uint32_t timeout; /*!< i2c wait time */
|
||||
__IO uint32_t timeout; /*!< i2c wait time */
|
||||
__IO uint32_t status; /*!< i2c communication status */
|
||||
__IO i2c_status_type error_code; /*!< i2c error code */
|
||||
dma_channel_type *dma_tx_channel; /*!< dma transmit channel */
|
||||
@@ -138,29 +138,29 @@ void i2c_lowlevel_init (i2c_handle_type* hi2c);
|
||||
void i2c_reset_ctrl2_register (i2c_handle_type* hi2c);
|
||||
i2c_status_type i2c_wait_end (i2c_handle_type* hi2c, uint32_t timeout);
|
||||
i2c_status_type i2c_wait_flag (i2c_handle_type* hi2c, uint32_t flag, flag_status status, uint32_t event_check, uint32_t timeout);
|
||||
|
||||
|
||||
i2c_status_type i2c_master_transmit (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_master_receive (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_slave_transmit (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_slave_receive (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
|
||||
|
||||
i2c_status_type i2c_master_transmit_int (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_master_receive_int (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_slave_transmit_int (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_slave_receive_int (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
|
||||
|
||||
i2c_status_type i2c_master_transmit_dma (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_master_receive_dma (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_slave_transmit_dma (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_slave_receive_dma (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
|
||||
|
||||
i2c_status_type i2c_memory_write (i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_write_int (i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_write_dma (i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_read (i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_read_int (i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_read_dma (i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
|
||||
|
||||
void i2c_evt_irq_handler (i2c_handle_type* hi2c);
|
||||
void i2c_err_irq_handler (i2c_handle_type* hi2c);
|
||||
void i2c_dma_tx_irq_handler (i2c_handle_type* hi2c);
|
||||
@@ -172,7 +172,7 @@ void i2c_dma_rx_irq_handler (i2c_handle_type* hi2c);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_class.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb audio 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
|
||||
* 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,
|
||||
@@ -31,11 +31,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_audio_class
|
||||
* @brief usb device class audio demo
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_audio_class_private_functions
|
||||
* @{
|
||||
@@ -62,7 +62,7 @@ static void audio_set_interface(void *udev, usb_setup_type *setup);
|
||||
usb_audio_type audio_struct = {0, 0, 0, 0, 0, 0x1400, 0, 0, 0, {0x0000, 0x1400, 0x33}, {0x0000, 0x1400, 0x33}, 0, 0};
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler audio_class_handler =
|
||||
usbd_class_handler audio_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
@@ -79,7 +79,7 @@ usbd_class_handler audio_class_handler =
|
||||
/**
|
||||
* @brief initialize usb custom hid endpoint
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_init_handler(void *udev)
|
||||
{
|
||||
@@ -88,47 +88,47 @@ static usb_sts_type class_init_handler(void *udev)
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
/* enable microphone in endpoint double buffer mode */
|
||||
usbd_ept_dbuffer_enable(pudev, USBD_AUDIO_MIC_IN_EPT);
|
||||
|
||||
|
||||
/* open microphone in endpoint */
|
||||
usbd_ept_open(pudev, USBD_AUDIO_MIC_IN_EPT, EPT_ISO_TYPE, AUDIO_MIC_IN_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* enable speaker out endpoint double buffer mode */
|
||||
usbd_ept_dbuffer_enable(pudev, USBD_AUDIO_SPK_OUT_EPT);
|
||||
|
||||
|
||||
/* open speaker out endpoint */
|
||||
usbd_ept_open(pudev, USBD_AUDIO_SPK_OUT_EPT, EPT_ISO_TYPE, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
|
||||
/* enable speaker feedback endpoint double buffer mode */
|
||||
usbd_ept_dbuffer_enable(pudev, USBD_AUDIO_FEEDBACK_EPT);
|
||||
|
||||
|
||||
/* open speaker feedback endpoint */
|
||||
usbd_ept_open(pudev, USBD_AUDIO_FEEDBACK_EPT, EPT_ISO_TYPE, AUDIO_FEEDBACK_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* start receive speaker out data */
|
||||
usbd_ept_recv(pudev, USBD_AUDIO_SPK_OUT_EPT, paudio->audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief clear endpoint or other state
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_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_AUDIO_MIC_IN_EPT);
|
||||
|
||||
|
||||
/* close in endpoint */
|
||||
usbd_ept_close(pudev, USBD_AUDIO_FEEDBACK_EPT);
|
||||
|
||||
|
||||
/* close out endpoint */
|
||||
usbd_ept_close(pudev, USBD_AUDIO_SPK_OUT_EPT);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ static usb_sts_type class_clear_handler(void *udev)
|
||||
* @brief usb device class setup request handler
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup packet
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -153,23 +153,23 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
case AUDIO_REQ_GET_CUR:
|
||||
audio_req_get_cur(pudev, setup);
|
||||
break;
|
||||
|
||||
|
||||
case AUDIO_REQ_SET_CUR:
|
||||
audio_req_set_cur(pudev, setup);
|
||||
break;
|
||||
|
||||
|
||||
case AUDIO_REQ_GET_MIN:
|
||||
audio_req_get_min(pudev, setup);
|
||||
break;
|
||||
|
||||
|
||||
case AUDIO_REQ_GET_MAX:
|
||||
audio_req_get_max(pudev, setup);
|
||||
break;
|
||||
|
||||
|
||||
case AUDIO_REQ_GET_RES:
|
||||
audio_req_get_res(pudev, setup);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
@@ -194,17 +194,17 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
audio_get_interface(udev, setup);
|
||||
break;
|
||||
|
||||
|
||||
case USB_STD_REQ_SET_INTERFACE:
|
||||
audio_set_interface(udev, setup);
|
||||
usbd_ctrl_send_status(pudev);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
@@ -215,21 +215,21 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
/**
|
||||
* @brief usb device endpoint 0 in status stage complete
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
{
|
||||
@@ -246,16 +246,16 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
case AUDIO_VOLUME_CONTROL:
|
||||
if( paudio->interface == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
paudio->spk_volume = (uint16_t)( paudio->g_audio_cur[0] |
|
||||
paudio->spk_volume = (uint16_t)( paudio->g_audio_cur[0] |
|
||||
( paudio->g_audio_cur[1] << 8));
|
||||
/* set volume */
|
||||
audio_codec_set_spk_volume(paudio->spk_volume*100/paudio->spk_volume_limits[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
paudio->mic_volume = (uint16_t)(paudio->g_audio_cur[0] |
|
||||
paudio->mic_volume = (uint16_t)(paudio->g_audio_cur[0] |
|
||||
(paudio->g_audio_cur[1] << 8));
|
||||
|
||||
|
||||
audio_codec_set_mic_volume(paudio->mic_volume*256/paudio->mic_volume_limits[1]);
|
||||
}
|
||||
break;
|
||||
@@ -270,19 +270,19 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
paudio->mic_mute = paudio->g_audio_cur[0];
|
||||
audio_codec_set_mic_mute(paudio->mic_mute);
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case AUDIO_FREQ_SET_CONTROL:
|
||||
if(paudio->enpd == USBD_AUDIO_MIC_IN_EPT)
|
||||
{
|
||||
paudio->mic_freq = (paudio->g_audio_cur[0] |
|
||||
paudio->mic_freq = (paudio->g_audio_cur[0] |
|
||||
(paudio->g_audio_cur[1] << 8) |
|
||||
(paudio->g_audio_cur[2] << 16));
|
||||
audio_codec_set_mic_freq(paudio->mic_freq);
|
||||
}
|
||||
else
|
||||
{
|
||||
paudio->spk_freq = (paudio->g_audio_cur[0] |
|
||||
paudio->spk_freq = (paudio->g_audio_cur[0] |
|
||||
(paudio->g_audio_cur[1] << 8) |
|
||||
(paudio->g_audio_cur[2] << 16));
|
||||
audio_codec_set_spk_freq(paudio->spk_freq);
|
||||
@@ -292,7 +292,7 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
* @brief usb device transmision complete handler
|
||||
* @param udev: usb device core handler type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
@@ -308,7 +308,7 @@ static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
uint32_t len = 0;
|
||||
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
@@ -317,13 +317,13 @@ static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
len = audio_codec_mic_get_data(paudio->audio_mic_data);
|
||||
usbd_ept_send(udev, USBD_AUDIO_MIC_IN_EPT, paudio->audio_mic_data, len);
|
||||
}
|
||||
|
||||
|
||||
else if((ept_num & 0x7F) == (USBD_AUDIO_FEEDBACK_EPT & 0x7F))
|
||||
{
|
||||
len = audio_codec_spk_feedback(paudio->audio_feed_back);
|
||||
usbd_ept_send(udev, USBD_AUDIO_FEEDBACK_EPT, paudio->audio_feed_back, len);
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
* @brief usb device endpoint receive data
|
||||
* @param udev: usb device core handler type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
@@ -339,15 +339,15 @@ static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
uint16_t g_rxlen;
|
||||
|
||||
|
||||
/* get endpoint receive data length */
|
||||
g_rxlen = usbd_get_recv_len(pudev, ept_num);
|
||||
|
||||
|
||||
if((ept_num & 0x7F) == (USBD_AUDIO_SPK_OUT_EPT & 0x7F))
|
||||
{
|
||||
/* speaker data*/
|
||||
audio_codec_spk_fifo_write(paudio->audio_spk_data, g_rxlen);
|
||||
|
||||
|
||||
/* get next data */
|
||||
usbd_ept_recv(pudev, USBD_AUDIO_SPK_OUT_EPT, paudio->audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
}
|
||||
@@ -358,14 +358,14 @@ static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
/**
|
||||
* @brief usb device sof handler
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_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;
|
||||
}
|
||||
|
||||
@@ -373,7 +373,7 @@ static usb_sts_type class_sof_handler(void *udev)
|
||||
* @brief usb device event handler
|
||||
* @param udev: usb device core handler type
|
||||
* @param event: usb device event
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
{
|
||||
@@ -383,9 +383,9 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
paudio->spk_alt_setting = 0;
|
||||
@@ -393,11 +393,11 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
paudio->mic_alt_setting = 0;
|
||||
audio_codec_mic_alt_setting(paudio->spk_alt_setting);
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_WAKEUP_EVENT:
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -409,7 +409,7 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
* @brief usb audio request get cur
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void audio_req_get_cur(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -440,7 +440,7 @@ static void audio_req_get_cur(void *udev, usb_setup_type *setup)
|
||||
*((uint16_t *)paudio->g_audio_cur) = paudio->mic_volume;
|
||||
usbd_ctrl_send(pudev, paudio->g_audio_cur, setup->wLength);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,7 +448,7 @@ static void audio_req_get_cur(void *udev, usb_setup_type *setup)
|
||||
* @brief usb audio request set cur
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void audio_req_set_cur(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -457,10 +457,10 @@ static void audio_req_set_cur(void *udev, usb_setup_type *setup)
|
||||
if(setup->wLength > 0)
|
||||
{
|
||||
usbd_ctrl_recv(pudev, paudio->g_audio_cur, setup->wLength);
|
||||
|
||||
|
||||
paudio->audio_cmd = AUDIO_REQ_SET_CUR;
|
||||
paudio->audio_cmd_len = setup->wLength;
|
||||
|
||||
|
||||
switch(setup->bmRequestType & AUDIO_REQ_CONTROL_MASK)
|
||||
{
|
||||
case AUDIO_REQ_CONTROL_INTERFACE:
|
||||
@@ -488,7 +488,7 @@ static void audio_req_set_cur(void *udev, usb_setup_type *setup)
|
||||
* @brief usb audio request get min
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void audio_req_get_min(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -510,7 +510,7 @@ static void audio_req_get_min(void *udev, usb_setup_type *setup)
|
||||
* @brief usb audio request get max
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void audio_req_get_max(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -532,7 +532,7 @@ static void audio_req_get_max(void *udev, usb_setup_type *setup)
|
||||
* @brief usb audio request get res
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void audio_req_get_res(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -554,7 +554,7 @@ static void audio_req_get_res(void *udev, usb_setup_type *setup)
|
||||
* @brief usb audio set interface
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void audio_set_interface(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -569,9 +569,9 @@ static void audio_set_interface(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
int len = audio_codec_spk_feedback(paudio->audio_feed_back);
|
||||
usbd_ept_recv(pudev, USBD_AUDIO_SPK_OUT_EPT, paudio->audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_FEEDBACK_EPT, paudio->audio_feed_back, len);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_FEEDBACK_EPT, paudio->audio_feed_back, len);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if(LBYTE(setup->wIndex) == AUDIO_MIC_INTERFACE_NUMBER)
|
||||
{
|
||||
@@ -583,7 +583,7 @@ static void audio_set_interface(void *udev, usb_setup_type *setup)
|
||||
usbd_ept_send(pudev, USBD_AUDIO_MIC_IN_EPT, paudio->audio_mic_data, len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -591,7 +591,7 @@ static void audio_set_interface(void *udev, usb_setup_type *setup)
|
||||
* @brief usb audio get interface
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void audio_get_interface(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -605,13 +605,13 @@ static void audio_get_interface(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&paudio->mic_alt_setting, 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_class.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb audio 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
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AUDIO_CLASS_H
|
||||
#define __AUDIO_CLASS_H
|
||||
@@ -31,7 +31,7 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "usb_std.h"
|
||||
#include "usbd_core.h"
|
||||
#include "audio_conf.h"
|
||||
@@ -39,12 +39,12 @@ extern "C" {
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_audio_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_audio_class_definition
|
||||
/** @defgroup USB_audio_class_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -99,7 +99,7 @@ typedef struct
|
||||
uint32_t mic_freq;
|
||||
uint16_t spk_volume_limits[3]; /*[0] is mininum value, [1] is maxnum value, [2] is volume resolution */
|
||||
uint16_t mic_volume_limits[3]; /*[0] is mininum value, [1] is maxnum value, [2] is volume resolution */
|
||||
|
||||
|
||||
uint8_t audio_cmd;
|
||||
uint32_t audio_cmd_len;
|
||||
uint32_t spk_alt_setting;
|
||||
@@ -119,7 +119,7 @@ extern usbd_class_handler audio_class_handler;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_conf.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb audio config
|
||||
**************************************************************************
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AUDIO_CONF_H
|
||||
#define __AUDIO_CONF_H
|
||||
@@ -31,17 +31,17 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_audio_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_device_audio_config_definition
|
||||
|
||||
/** @defgroup USB_device_audio_config_definition
|
||||
* @{
|
||||
*/
|
||||
#define AUDIO_SUPPORT_SPK 1
|
||||
@@ -55,7 +55,7 @@ extern "C" {
|
||||
#define AUDIO_SUPPORT_FREQ (AUDIO_SUPPORT_FREQ_16K + \
|
||||
AUDIO_SUPPORT_FREQ_48K \
|
||||
)
|
||||
|
||||
|
||||
#define AUDIO_FREQ_16K 16000
|
||||
#define AUDIO_FREQ_48K 48000
|
||||
#define AUDIO_BITW_16 16
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_desc.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb audio 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
|
||||
* 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,
|
||||
@@ -31,11 +31,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_audio_desc
|
||||
* @brief usb device audio descriptor
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_audio_desc_private_functions
|
||||
* @{
|
||||
@@ -119,7 +119,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
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 */
|
||||
@@ -129,7 +129,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
AUDIO_SUBCLASS_AUDIOCONTROL, /* bInterfaceSubClass: audio control */
|
||||
AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol: undefined */
|
||||
0x00, /* iInterface: index of string descriptor */
|
||||
|
||||
|
||||
0x08+AUDIO_INTERFACE_NUM, /* bLength: size of this descriptor, in bytes 8+n */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: cs interface descriptor type */
|
||||
AUDIO_AC_HEADER, /* bDescriptorSubtype: Header function Descriptor*/
|
||||
@@ -164,7 +164,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
0x00, /* wChannelConfig */
|
||||
0x00, /* iChannelNames: unused */
|
||||
0x00, /* iTerminal: unused */
|
||||
|
||||
|
||||
AUDIO_FEATURE_UNIT_SIZE, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: configuration */
|
||||
AUDIO_AC_FEATURE_UNIT, /* bDescriptorSubtype: feature unit type*/
|
||||
@@ -174,7 +174,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
0x01, /* bmaControls0: mute */
|
||||
0x02, /* bmaControls1: volume */
|
||||
0x00, /* iFeature: unused */
|
||||
|
||||
|
||||
AUDIO_OUTPUT_TERMINAL_SIZE, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: configuration */
|
||||
AUDIO_AC_OUTPUT_TERMINAL, /* bDescriptorSubtype: output_terminal type*/
|
||||
@@ -184,8 +184,8 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
0x00, /* bAssocTerminal: unused */
|
||||
AUDIO_MIC_FEATURE_UNIT_ID, /* bSourceID: from feature unit terminal */
|
||||
0x00, /* iTerminal: unused */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if (AUDIO_SUPPORT_SPK == 1)
|
||||
/* speaker config */
|
||||
AUDIO_INPUT_TERMINAL_SIZE, /* bLength: descriptor size */
|
||||
@@ -205,7 +205,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
0x00, /* wChannelConfig */
|
||||
0x00, /* iChannelNames: unused */
|
||||
0x00, /* iTerminal: unused */
|
||||
|
||||
|
||||
AUDIO_FEATURE_UNIT_SIZE, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: configuration */
|
||||
AUDIO_AC_FEATURE_UNIT, /* bDescriptorSubtype: feature unit type*/
|
||||
@@ -215,7 +215,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
0x01, /* bmaControls0: mute*/
|
||||
0x02, /* bmaControls1: volume */
|
||||
0x00, /* iFeature: unused */
|
||||
|
||||
|
||||
AUDIO_OUTPUT_TERMINAL_SIZE, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: configuration */
|
||||
AUDIO_AC_OUTPUT_TERMINAL, /* bDescriptorSubtype: output_terminal type*/
|
||||
@@ -237,8 +237,8 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
USB_CLASS_CODE_AUDIO, /* bInterfaceClass: audio */
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubclass: audio streaming */
|
||||
0x00, /* bInterfaceProtocol: unused */
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x09, /* bLength: descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_MIC_INTERFACE_NUMBER, /* bInterfaceNumber: index of this interface */
|
||||
@@ -247,8 +247,8 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
USB_CLASS_CODE_AUDIO, /* bInterfaceClass: audio */
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubclass: audio streaming */
|
||||
0x00, /* bInterfaceProtocol: unused */
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x07, /* bLength: configuration descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_AS_GENERAL, /* bDescriptorSubtype: general sub type*/
|
||||
@@ -256,7 +256,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
0x01, /* bDelay: interface delay */
|
||||
0x01, /* wFormatTag: pcm format*/
|
||||
0x00, /* wFormatTag: pcm format*/
|
||||
|
||||
|
||||
0x08 + AUDIO_MIC_FREQ_SIZE * 3, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_AS_FORMAT_TYPE, /* bDescriptorSubtype: format subtype */
|
||||
@@ -265,10 +265,10 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
AUDIO_MIC_BITW / 8, /* bSubFrameSize: per audio subframe */
|
||||
AUDIO_MIC_BITW, /* bBitResolution: n bits per sample */
|
||||
AUDIO_MIC_FREQ_SIZE, /* bSamFreqType: n frequency supported */
|
||||
#if (AUDIO_SUPPORT_FREQ_16K == 1)
|
||||
#if (AUDIO_SUPPORT_FREQ_16K == 1)
|
||||
SAMPLE_FREQ(AT32_AUDIO_FREQ_16K), /* tSamFreq: 16000hz */
|
||||
#endif
|
||||
#if (AUDIO_SUPPORT_FREQ_48K == 1)
|
||||
#if (AUDIO_SUPPORT_FREQ_48K == 1)
|
||||
SAMPLE_FREQ(AT32_AUDIO_FREQ_48K), /* tSamFreq: 48000hz */
|
||||
#endif
|
||||
|
||||
@@ -281,7 +281,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
AUDIO_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
0x00, /* bRefresh: unused */
|
||||
0x00, /* bSynchAddress: unused */
|
||||
|
||||
|
||||
0x07, /* bLength: size of endpoint descriptor in bytes */
|
||||
AUDIO_CS_ENDPOINT, /* bDescriptorType: cs endpoint descriptor type */
|
||||
0x01, /* bDescriptorSubtype: general subtype */
|
||||
@@ -302,7 +302,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubclass: audio streaming */
|
||||
0x00, /* bInterfaceProtocol: unused */
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
|
||||
0x09, /* bLength: descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_SPK_INTERFACE_NUMBER, /* bInterfaceNumber: index of this interface */
|
||||
@@ -311,8 +311,8 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
USB_CLASS_CODE_AUDIO, /* bInterfaceClass: audio */
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubclass: audio streaming */
|
||||
0x00, /* bInterfaceProtocol: unused */
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x07, /* bLength: configuration descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_AS_GENERAL, /* bDescriptorSubtype: general sub type*/
|
||||
@@ -320,7 +320,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
0x01, /* bDelay: interface delay */
|
||||
0x01, /* wFormatTag: pcm format*/
|
||||
0x00, /* wFormatTag: pcm format*/
|
||||
|
||||
|
||||
0x08 + AUDIO_SPK_FREQ_SIZE * 3, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_AS_FORMAT_TYPE, /* bDescriptorSubtype: format subtype */
|
||||
@@ -329,13 +329,13 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
AUDIO_SPK_BITW / 8, /* bSubFrameSize: per audio subframe */
|
||||
AUDIO_SPK_BITW, /* bBitResolution: n bits per sample */
|
||||
AUDIO_SPK_FREQ_SIZE, /* bSamFreqType: n frequency supported */
|
||||
#if (AUDIO_SUPPORT_FREQ_16K == 1)
|
||||
#if (AUDIO_SUPPORT_FREQ_16K == 1)
|
||||
SAMPLE_FREQ(AT32_AUDIO_FREQ_16K), /* tSamFreq: 16000hz */
|
||||
#endif
|
||||
#if (AUDIO_SUPPORT_FREQ_48K == 1)
|
||||
#if (AUDIO_SUPPORT_FREQ_48K == 1)
|
||||
SAMPLE_FREQ(AT32_AUDIO_FREQ_48K), /* tSamFreq: 48000hz */
|
||||
#endif
|
||||
|
||||
|
||||
0x09, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_AUDIO_SPK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
@@ -357,7 +357,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
0x00, /* bLockDelayUnits: unused */
|
||||
0x00, /* wLockDelay: unused */
|
||||
0x00, /* wLockDelay: unused */
|
||||
|
||||
|
||||
#if (AUDIO_SUPPORT_FEEDBACK == 1)
|
||||
0x09, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
@@ -368,11 +368,11 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUDIO_CONFIG_DESC_SIZE] AL
|
||||
1, /* bInterval: interval for polling endpoint for data transfers */
|
||||
FEEDBACK_REFRESH_TIME, /* bRefresh: this field indicates the rate at which an iso syncronization
|
||||
pipe provides new syncronization feedback data. this rate must be a power of
|
||||
2, therefore only the power is reported back and the range of this field is from
|
||||
2, therefore only the power is reported back and the range of this field is from
|
||||
1(2ms) to 9(512ms) */
|
||||
0x00 /* bSynchAddress: 0x00*/
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -437,24 +437,24 @@ static usbd_desc_t vp_desc;
|
||||
* @brief standard usb unicode convert
|
||||
* @param string: source string
|
||||
* @param unicode_buf: unicode buffer
|
||||
* @retval length
|
||||
* @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] = str_len;
|
||||
unicode_buf[1] = USB_DESCIPTOR_TYPE_STRING;
|
||||
|
||||
|
||||
return str_len;
|
||||
}
|
||||
|
||||
@@ -463,12 +463,12 @@ static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
* @param value: int value
|
||||
* @param pbus: unicode buffer
|
||||
* @param len: length
|
||||
* @retval none
|
||||
* @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 )
|
||||
@@ -477,11 +477,11 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
}
|
||||
|
||||
|
||||
value = value << 4;
|
||||
|
||||
|
||||
pbuf[2 * idx + 1] = 0;
|
||||
}
|
||||
}
|
||||
@@ -489,18 +489,18 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
/**
|
||||
* @brief usb get serial number
|
||||
* @param none
|
||||
* @retval 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);
|
||||
@@ -511,7 +511,7 @@ static void get_serial_num(void)
|
||||
/**
|
||||
* @brief get device descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_descriptor(void)
|
||||
{
|
||||
@@ -521,7 +521,7 @@ static usbd_desc_t *get_device_descriptor(void)
|
||||
/**
|
||||
* @brief get device qualifier
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t * get_device_qualifier(void)
|
||||
{
|
||||
@@ -531,7 +531,7 @@ static usbd_desc_t * get_device_qualifier(void)
|
||||
/**
|
||||
* @brief get config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_configuration(void)
|
||||
{
|
||||
@@ -541,7 +541,7 @@ static usbd_desc_t *get_device_configuration(void)
|
||||
/**
|
||||
* @brief get other speed descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_other_speed(void)
|
||||
{
|
||||
@@ -551,7 +551,7 @@ static usbd_desc_t *get_device_other_speed(void)
|
||||
/**
|
||||
* @brief get lang id descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_lang_id(void)
|
||||
{
|
||||
@@ -562,7 +562,7 @@ static usbd_desc_t *get_device_lang_id(void)
|
||||
/**
|
||||
* @brief get manufacturer descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
{
|
||||
@@ -574,7 +574,7 @@ static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
/**
|
||||
* @brief get product descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_product_string(void)
|
||||
{
|
||||
@@ -586,7 +586,7 @@ static usbd_desc_t *get_device_product_string(void)
|
||||
/**
|
||||
* @brief get serial descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_serial_string(void)
|
||||
{
|
||||
@@ -597,7 +597,7 @@ static usbd_desc_t *get_device_serial_string(void)
|
||||
/**
|
||||
* @brief get interface descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_interface_string(void)
|
||||
{
|
||||
@@ -609,7 +609,7 @@ static usbd_desc_t *get_device_interface_string(void)
|
||||
/**
|
||||
* @brief get device config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_config_string(void)
|
||||
{
|
||||
@@ -620,7 +620,7 @@ static usbd_desc_t *get_device_config_string(void)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_desc.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb audio 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
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AUDIO_DESC_H
|
||||
#define __AUDIO_DESC_H
|
||||
@@ -31,7 +31,7 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "audio_class.h"
|
||||
#include "usbd_core.h"
|
||||
#include "audio_conf.h"
|
||||
@@ -39,12 +39,12 @@ extern "C" {
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_audio_desc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_audio_desc_definition
|
||||
/** @defgroup USB_audio_desc_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -70,7 +70,7 @@ extern "C" {
|
||||
#define AUDIO_SUBCLASS_MIDISTREMING 0x03
|
||||
|
||||
/**
|
||||
* @brief audio class-specific descriptor types
|
||||
* @brief audio class-specific descriptor types
|
||||
*/
|
||||
#define AUDIO_CS_INTERFACE 0x24
|
||||
#define AUDIO_CS_ENDPOINT 0x25
|
||||
@@ -98,7 +98,7 @@ extern "C" {
|
||||
#define AUDIO_AC_EXTENSION_UNIT 0x08
|
||||
|
||||
/**
|
||||
* @brief audio class-specific as interface descriptor subtypes
|
||||
* @brief audio class-specific as interface descriptor subtypes
|
||||
*/
|
||||
#define AUDIO_AS_DESCRIPTOR_UNDEFINED 0x00
|
||||
#define AUDIO_AS_GENERAL 0x01
|
||||
@@ -221,11 +221,11 @@ extern usbd_desc_handler audio_desc_handler;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_conf.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb audio config
|
||||
**************************************************************************
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AUDIO_CONF_H
|
||||
#define __AUDIO_CONF_H
|
||||
@@ -31,17 +31,17 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_audio_hid_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_device_audio_hid_config_definition
|
||||
|
||||
/** @defgroup USB_device_audio_hid_config_definition
|
||||
* @{
|
||||
*/
|
||||
#define AUDIO_SUPPORT_SPK 1
|
||||
@@ -55,7 +55,7 @@ extern "C" {
|
||||
#define AUDIO_SUPPORT_FREQ (AUDIO_SUPPORT_FREQ_16K + \
|
||||
AUDIO_SUPPORT_FREQ_48K \
|
||||
)
|
||||
|
||||
|
||||
#define AUDIO_FREQ_16K 16000
|
||||
#define AUDIO_FREQ_48K 48000
|
||||
#define AUDIO_BITW_16 16
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_class.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb audio 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
|
||||
* 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,
|
||||
@@ -31,11 +31,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_audio_hid_class
|
||||
* @brief usb device class audio hid demo
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_audio_hid_class_private_functions
|
||||
* @{
|
||||
@@ -61,7 +61,7 @@ static void audio_set_interface(void *udev, usb_setup_type *setup);
|
||||
static void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len);
|
||||
usb_audio_hid_type audio_hid_struct = {0, 0, 0, 0, 0, 0x1400, 0, 0, 0, {0x0000, 0x1400, 0x33}, {0x0000, 0x1400, 0x33}, 0, 0};
|
||||
|
||||
usbd_class_handler audio_hid_class_handler =
|
||||
usbd_class_handler audio_hid_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
@@ -78,7 +78,7 @@ usbd_class_handler audio_hid_class_handler =
|
||||
/**
|
||||
* @brief initialize usb custom hid endpoint
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_init_handler(void *udev)
|
||||
{
|
||||
@@ -87,66 +87,66 @@ static usb_sts_type class_init_handler(void *udev)
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
/* enable microphone in endpoint double buffer mode */
|
||||
usbd_ept_dbuffer_enable(pudev, USBD_AUHID_AUDIO_MIC_IN_EPT);
|
||||
|
||||
|
||||
/* open microphone in endpoint */
|
||||
usbd_ept_open(pudev, USBD_AUHID_AUDIO_MIC_IN_EPT, EPT_ISO_TYPE, AUDIO_MIC_IN_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* enable speaker out endpoint double buffer mode */
|
||||
usbd_ept_dbuffer_enable(pudev, USBD_AUHID_AUDIO_SPK_OUT_EPT);
|
||||
|
||||
|
||||
/* open speaker out endpoint */
|
||||
usbd_ept_open(pudev, USBD_AUHID_AUDIO_SPK_OUT_EPT, EPT_ISO_TYPE, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
#if AUDIO_SUPPORT_FEEDBACK
|
||||
#if AUDIO_SUPPORT_FEEDBACK
|
||||
/* enable speaker feedback endpoint double buffer mode */
|
||||
usbd_ept_dbuffer_enable(pudev, USBD_AUHID_AUDIO_FEEDBACK_EPT);
|
||||
|
||||
|
||||
/* open speaker feedback endpoint */
|
||||
usbd_ept_open(pudev, USBD_AUHID_AUDIO_FEEDBACK_EPT, EPT_ISO_TYPE, AUDIO_FEEDBACK_MAXPACKET_SIZE);
|
||||
#endif
|
||||
#endif
|
||||
/* start receive speaker out data */
|
||||
usbd_ept_recv(pudev, USBD_AUHID_AUDIO_SPK_OUT_EPT, paudio_hid->audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/*open hid endpoint */
|
||||
|
||||
|
||||
/* open custom hid in endpoint */
|
||||
usbd_ept_open(pudev, USBD_AUHID_HID_IN_EPT, EPT_INT_TYPE, USBD_AUHID_IN_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* open custom hid out endpoint */
|
||||
usbd_ept_open(pudev, USBD_AUHID_HID_OUT_EPT, EPT_INT_TYPE, USBD_AUHID_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_AUHID_HID_OUT_EPT, paudio_hid->g_rxhid_buff, USBD_AUHID_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief clear endpoint or other state
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_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_AUHID_AUDIO_MIC_IN_EPT);
|
||||
|
||||
#if AUDIO_SUPPORT_FEEDBACK
|
||||
|
||||
#if AUDIO_SUPPORT_FEEDBACK
|
||||
/* close in endpoint */
|
||||
usbd_ept_close(pudev, USBD_AUHID_AUDIO_FEEDBACK_EPT);
|
||||
#endif
|
||||
|
||||
|
||||
/* close out endpoint */
|
||||
usbd_ept_close(pudev, USBD_AUHID_AUDIO_SPK_OUT_EPT);
|
||||
|
||||
|
||||
/* close custom hid in endpoint */
|
||||
usbd_ept_close(pudev, USBD_AUHID_HID_IN_EPT);
|
||||
|
||||
|
||||
/* close custom hid out endpoint */
|
||||
usbd_ept_close(pudev, USBD_AUHID_HID_OUT_EPT);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ static usb_sts_type class_clear_handler(void *udev)
|
||||
* @brief usb device class setup request handler
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup packet
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_audio_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -171,23 +171,23 @@ usb_sts_type class_audio_setup_handler(void *udev, usb_setup_type *setup)
|
||||
case AUDIO_REQ_GET_CUR:
|
||||
audio_req_get_cur(pudev, setup);
|
||||
break;
|
||||
|
||||
|
||||
case AUDIO_REQ_SET_CUR:
|
||||
audio_req_set_cur(pudev, setup);
|
||||
break;
|
||||
|
||||
|
||||
case AUDIO_REQ_GET_MIN:
|
||||
audio_req_get_min(pudev, setup);
|
||||
break;
|
||||
|
||||
|
||||
case AUDIO_REQ_GET_MAX:
|
||||
audio_req_get_max(pudev, setup);
|
||||
break;
|
||||
|
||||
|
||||
case AUDIO_REQ_GET_RES:
|
||||
audio_req_get_res(pudev, setup);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
@@ -212,30 +212,30 @@ usb_sts_type class_audio_setup_handler(void *udev, usb_setup_type *setup)
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
audio_get_interface(udev, setup);
|
||||
break;
|
||||
|
||||
|
||||
case USB_STD_REQ_SET_INTERFACE:
|
||||
audio_set_interface(udev, setup);
|
||||
usbd_ctrl_send_status(pudev);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class setup request handler
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup packet
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_hid_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -309,7 +309,7 @@ usb_sts_type class_hid_setup_handler(void *udev, usb_setup_type *setup)
|
||||
* @brief usb device class setup request handler
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup packet
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -330,31 +330,31 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
case USB_REQ_RECIPIENT_ENDPOINT:
|
||||
class_audio_setup_handler(pudev, setup);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
return status;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device endpoint 0 in status stage complete
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
{
|
||||
@@ -363,7 +363,7 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
usb_setup_type *setup = &pudev->setup;
|
||||
uint32_t recv_len = usbd_get_recv_len(pudev, 0);
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
if(setup->wIndex == HID_INTERFACE_NUMBER)
|
||||
{
|
||||
@@ -385,16 +385,16 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
case AUDIO_VOLUME_CONTROL:
|
||||
if(paudio_hid->interface == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
paudio_hid->spk_volume = (uint16_t)(paudio_hid->g_audio_cur[0] |
|
||||
paudio_hid->spk_volume = (uint16_t)(paudio_hid->g_audio_cur[0] |
|
||||
(paudio_hid->g_audio_cur[1] << 8));
|
||||
/* set volume */
|
||||
audio_codec_set_spk_volume(paudio_hid->spk_volume*100/paudio_hid->spk_volume_limits[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
paudio_hid->mic_volume = (uint16_t)(paudio_hid->g_audio_cur[0] |
|
||||
paudio_hid->mic_volume = (uint16_t)(paudio_hid->g_audio_cur[0] |
|
||||
(paudio_hid->g_audio_cur[1] << 8));
|
||||
|
||||
|
||||
audio_codec_set_mic_volume(paudio_hid->mic_volume*256/paudio_hid->mic_volume_limits[1]);
|
||||
}
|
||||
break;
|
||||
@@ -409,19 +409,19 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
paudio_hid->mic_mute = paudio_hid->g_audio_cur[0];
|
||||
audio_codec_set_mic_mute(paudio_hid->mic_mute);
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case AUDIO_FREQ_SET_CONTROL:
|
||||
if(paudio_hid->enpd == USBD_AUHID_AUDIO_MIC_IN_EPT)
|
||||
{
|
||||
paudio_hid->mic_freq = (paudio_hid->g_audio_cur[0] |
|
||||
paudio_hid->mic_freq = (paudio_hid->g_audio_cur[0] |
|
||||
(paudio_hid->g_audio_cur[1] << 8) |
|
||||
(paudio_hid->g_audio_cur[2] << 16));
|
||||
audio_codec_set_mic_freq(paudio_hid->mic_freq);
|
||||
}
|
||||
else
|
||||
{
|
||||
paudio_hid->spk_freq = (paudio_hid->g_audio_cur[0] |
|
||||
paudio_hid->spk_freq = (paudio_hid->g_audio_cur[0] |
|
||||
(paudio_hid->g_audio_cur[1] << 8) |
|
||||
(paudio_hid->g_audio_cur[2] << 16));
|
||||
audio_codec_set_spk_freq(paudio_hid->spk_freq);
|
||||
@@ -432,7 +432,7 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -440,7 +440,7 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
* @brief usb device transmision complete handler
|
||||
* @param udev: usb device core handler type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
@@ -448,7 +448,7 @@ usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
uint32_t len = 0;
|
||||
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
@@ -457,18 +457,18 @@ usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
len = audio_codec_mic_get_data(paudio_hid->audio_mic_data);
|
||||
usbd_ept_send(udev, USBD_AUHID_AUDIO_MIC_IN_EPT, paudio_hid->audio_mic_data, len);
|
||||
}
|
||||
#if AUDIO_SUPPORT_FEEDBACK
|
||||
#if AUDIO_SUPPORT_FEEDBACK
|
||||
else if((ept_num & 0x7F) == (USBD_AUHID_AUDIO_FEEDBACK_EPT & 0x7F))
|
||||
{
|
||||
len = audio_codec_spk_feedback(paudio_hid->audio_feed_back);
|
||||
usbd_ept_send(udev, USBD_AUHID_AUDIO_FEEDBACK_EPT, paudio_hid->audio_feed_back, len);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
else if((ept_num & 0x7F) == (USBD_AUHID_HID_IN_EPT & 0x7F))
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -476,7 +476,7 @@ usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
* @brief usb device endpoint receive data
|
||||
* @param udev: usb device core handler type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
@@ -484,15 +484,15 @@ static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
uint16_t g_rxlen;
|
||||
|
||||
|
||||
/* get endpoint receive data length */
|
||||
g_rxlen = usbd_get_recv_len(pudev, ept_num);
|
||||
|
||||
|
||||
if((ept_num & 0x7F) == (USBD_AUHID_AUDIO_SPK_OUT_EPT & 0x7F))
|
||||
{
|
||||
/* speaker data*/
|
||||
audio_codec_spk_fifo_write(paudio_hid->audio_spk_data, g_rxlen);
|
||||
|
||||
|
||||
/* get next data */
|
||||
usbd_ept_recv(pudev, USBD_AUHID_AUDIO_SPK_OUT_EPT, paudio_hid->audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
}
|
||||
@@ -500,7 +500,7 @@ static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
/* hid buffer process */
|
||||
usb_hid_buf_process(udev, paudio_hid->g_rxhid_buff, g_rxlen);
|
||||
|
||||
|
||||
/* start receive next packet */
|
||||
usbd_ept_recv(pudev, USBD_AUHID_HID_OUT_EPT, paudio_hid->g_rxhid_buff, USBD_AUHID_OUT_MAXPACKET_SIZE);
|
||||
}
|
||||
@@ -510,14 +510,14 @@ static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
/**
|
||||
* @brief usb device sof handler
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_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;
|
||||
}
|
||||
|
||||
@@ -525,7 +525,7 @@ static usb_sts_type class_sof_handler(void *udev)
|
||||
* @brief usb device event handler
|
||||
* @param udev: usb device core handler type
|
||||
* @param event: usb device event
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
{
|
||||
@@ -535,9 +535,9 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
paudio_hid->spk_alt_setting = 0;
|
||||
@@ -545,11 +545,11 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
paudio_hid->mic_alt_setting = 0;
|
||||
audio_codec_mic_alt_setting(paudio_hid->spk_alt_setting);
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_WAKEUP_EVENT:
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -561,7 +561,7 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
* @brief usb audio request get cur
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void audio_req_get_cur(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -592,7 +592,7 @@ static void audio_req_get_cur(void *udev, usb_setup_type *setup)
|
||||
*((uint16_t *)paudio_hid->g_audio_cur) = paudio_hid->mic_volume;
|
||||
usbd_ctrl_send(pudev, paudio_hid->g_audio_cur, setup->wLength);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -600,7 +600,7 @@ static void audio_req_get_cur(void *udev, usb_setup_type *setup)
|
||||
* @brief usb audio request set cur
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void audio_req_set_cur(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -609,10 +609,10 @@ static void audio_req_set_cur(void *udev, usb_setup_type *setup)
|
||||
if(setup->wLength > 0)
|
||||
{
|
||||
usbd_ctrl_recv(pudev, paudio_hid->g_audio_cur, setup->wLength);
|
||||
|
||||
|
||||
paudio_hid->audio_cmd = AUDIO_REQ_SET_CUR;
|
||||
paudio_hid->audio_cmd_len = setup->wLength;
|
||||
|
||||
|
||||
switch(setup->bmRequestType & AUDIO_REQ_CONTROL_MASK)
|
||||
{
|
||||
case AUDIO_REQ_CONTROL_INTERFACE:
|
||||
@@ -640,7 +640,7 @@ static void audio_req_set_cur(void *udev, usb_setup_type *setup)
|
||||
* @brief usb audio request get min
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void audio_req_get_min(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -662,7 +662,7 @@ static void audio_req_get_min(void *udev, usb_setup_type *setup)
|
||||
* @brief usb audio request get max
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void audio_req_get_max(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -684,7 +684,7 @@ static void audio_req_get_max(void *udev, usb_setup_type *setup)
|
||||
* @brief usb audio request get res
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void audio_req_get_res(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -706,7 +706,7 @@ static void audio_req_get_res(void *udev, usb_setup_type *setup)
|
||||
* @brief usb audio set interface
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void audio_set_interface(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -721,9 +721,9 @@ static void audio_set_interface(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
int len = audio_codec_spk_feedback(paudio_hid->audio_feed_back);
|
||||
usbd_ept_recv(pudev, USBD_AUHID_AUDIO_SPK_OUT_EPT, paudio_hid->audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_send(pudev, USBD_AUHID_AUDIO_FEEDBACK_EPT, paudio_hid->audio_feed_back, len);
|
||||
usbd_ept_send(pudev, USBD_AUHID_AUDIO_FEEDBACK_EPT, paudio_hid->audio_feed_back, len);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if(LBYTE(setup->wIndex) == AUDIO_MIC_INTERFACE_NUMBER)
|
||||
{
|
||||
@@ -735,7 +735,7 @@ static void audio_set_interface(void *udev, usb_setup_type *setup)
|
||||
usbd_ept_send(pudev, USBD_AUHID_AUDIO_MIC_IN_EPT, paudio_hid->audio_mic_data, len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -743,7 +743,7 @@ static void audio_set_interface(void *udev, usb_setup_type *setup)
|
||||
* @brief usb audio get interface
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void audio_get_interface(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -757,7 +757,7 @@ static void audio_get_interface(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&paudio_hid->mic_alt_setting, 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -765,7 +765,7 @@ static void audio_get_interface(void *udev, usb_setup_type *setup)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param report: report buffer
|
||||
* @param len: report length
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type audio_hid_class_send_report(void *udev, uint8_t *report, uint16_t len)
|
||||
{
|
||||
@@ -774,7 +774,7 @@ usb_sts_type audio_hid_class_send_report(void *udev, uint8_t *report, uint16_t l
|
||||
|
||||
if(usbd_connect_state_get(pudev) == USB_CONN_STATE_CONFIGURED)
|
||||
usbd_ept_send(pudev, USBD_AUHID_HID_IN_EPT, report, len);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -784,14 +784,14 @@ usb_sts_type audio_hid_class_send_report(void *udev, uint8_t *report, uint16_t l
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param report: report buffer
|
||||
* @param len: report length
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
|
||||
{
|
||||
uint32_t i_index;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
switch(report[0])
|
||||
{
|
||||
case HID_REPORT_ID_2:
|
||||
@@ -831,15 +831,15 @@ static void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
|
||||
}
|
||||
usbd_ept_send(pudev, USBD_AUHID_HID_IN_EPT, paudio_hid->g_txhid_buff, len);
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_class.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb audio 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
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AUDIO_HID_CLASS_H
|
||||
#define __AUDIO_HID_CLASS_H
|
||||
@@ -31,7 +31,7 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "usb_std.h"
|
||||
#include "usbd_core.h"
|
||||
#include "audio_conf.h"
|
||||
@@ -39,12 +39,12 @@ extern "C" {
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_audio_hid_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_audio_hid_class_definition
|
||||
/** @defgroup USB_audio_hid_class_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -122,7 +122,7 @@ typedef struct
|
||||
uint32_t mic_freq;
|
||||
uint16_t spk_volume_limits[3]; /*[0] is mininum value, [1] is maxnum value, [2] is volume resolution */
|
||||
uint16_t mic_volume_limits[3]; /*[0] is mininum value, [1] is maxnum value, [2] is volume resolution */
|
||||
|
||||
|
||||
uint8_t audio_cmd;
|
||||
uint32_t audio_cmd_len;
|
||||
uint32_t spk_alt_setting;
|
||||
@@ -131,8 +131,8 @@ typedef struct
|
||||
uint8_t audio_spk_data[AUDIO_SPK_OUT_MAXPACKET_SIZE];
|
||||
uint8_t audio_mic_data[AUDIO_MIC_IN_MAXPACKET_SIZE];
|
||||
uint8_t audio_feed_back[AUDIO_FEEDBACK_MAXPACKET_SIZE+1];
|
||||
|
||||
|
||||
|
||||
|
||||
/* hid */
|
||||
uint32_t hid_protocol;
|
||||
uint32_t hid_set_idle;
|
||||
@@ -154,7 +154,7 @@ usb_sts_type audio_hid_class_send_report(void *udev, uint8_t *report, uint16_t l
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_desc.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb audio 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
|
||||
* 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,
|
||||
@@ -31,11 +31,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_audio_hid_desc
|
||||
* @brief usb device audio hid descriptor
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_audio_hid_desc_private_functions
|
||||
* @{
|
||||
@@ -121,7 +121,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
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 */
|
||||
@@ -131,7 +131,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
AUDIO_SUBCLASS_AUDIOCONTROL, /* bInterfaceSubClass: audio control */
|
||||
AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol: undefined */
|
||||
0x00, /* iInterface: index of string descriptor */
|
||||
|
||||
|
||||
0x08+AUDIO_INTERFACE_NUM, /* bLength: size of this descriptor, in bytes 8+n */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: cs interface descriptor type */
|
||||
AUDIO_AC_HEADER, /* bDescriptorSubtype: Header function Descriptor*/
|
||||
@@ -166,7 +166,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
0x00, /* wChannelConfig */
|
||||
0x00, /* iChannelNames: unused */
|
||||
0x00, /* iTerminal: unused */
|
||||
|
||||
|
||||
AUDIO_FEATURE_UNIT_SIZE, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: configuration */
|
||||
AUDIO_AC_FEATURE_UNIT, /* bDescriptorSubtype: feature unit type*/
|
||||
@@ -176,7 +176,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
0x01, /* bmaControls0: mute */
|
||||
0x02, /* bmaControls1: volume */
|
||||
0x00, /* iFeature: unused */
|
||||
|
||||
|
||||
AUDIO_OUTPUT_TERMINAL_SIZE, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: configuration */
|
||||
AUDIO_AC_OUTPUT_TERMINAL, /* bDescriptorSubtype: output_terminal type*/
|
||||
@@ -186,8 +186,8 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
AUDIO_MIC_INPUT_TERMINAL_ID, /* bAssocTerminal: unused */
|
||||
AUDIO_MIC_FEATURE_UNIT_ID, /* bSourceID: from feature unit terminal */
|
||||
0x00, /* iTerminal: unused */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if (AUDIO_SUPPORT_SPK == 1)
|
||||
/* speaker config */
|
||||
AUDIO_INPUT_TERMINAL_SIZE, /* bLength: descriptor size */
|
||||
@@ -207,7 +207,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
0x00, /* wChannelConfig */
|
||||
0x00, /* iChannelNames: unused */
|
||||
0x00, /* iTerminal: unused */
|
||||
|
||||
|
||||
AUDIO_FEATURE_UNIT_SIZE, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: configuration */
|
||||
AUDIO_AC_FEATURE_UNIT, /* bDescriptorSubtype: feature unit type*/
|
||||
@@ -217,7 +217,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
0x01, /* bmaControls0: mute*/
|
||||
0x02, /* bmaControls1: volume */
|
||||
0x00, /* iFeature: unused */
|
||||
|
||||
|
||||
AUDIO_OUTPUT_TERMINAL_SIZE, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: configuration */
|
||||
AUDIO_AC_OUTPUT_TERMINAL, /* bDescriptorSubtype: output_terminal type*/
|
||||
@@ -239,8 +239,8 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
USB_CLASS_CODE_AUDIO, /* bInterfaceClass: audio */
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubclass: audio streaming */
|
||||
0x00, /* bInterfaceProtocol: unused */
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x09, /* bLength: descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_MIC_INTERFACE_NUMBER, /* bInterfaceNumber: index of this interface */
|
||||
@@ -249,8 +249,8 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
USB_CLASS_CODE_AUDIO, /* bInterfaceClass: audio */
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubclass: audio streaming */
|
||||
0x00, /* bInterfaceProtocol: unused */
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x07, /* bLength: configuration descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_AS_GENERAL, /* bDescriptorSubtype: general sub type*/
|
||||
@@ -258,7 +258,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
0x01, /* bDelay: interface delay */
|
||||
0x01, /* wFormatTag: pcm format*/
|
||||
0x00, /* wFormatTag: pcm format*/
|
||||
|
||||
|
||||
0x08 + AUDIO_MIC_FREQ_SIZE * 3, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_AS_FORMAT_TYPE, /* bDescriptorSubtype: format subtype */
|
||||
@@ -267,10 +267,10 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
AUDIO_MIC_BITW / 8, /* bSubFrameSize: per audio subframe */
|
||||
AUDIO_MIC_BITW, /* bBitResolution: n bits per sample */
|
||||
AUDIO_MIC_FREQ_SIZE, /* bSamFreqType: n frequency supported */
|
||||
#if (AUDIO_SUPPORT_FREQ_16K == 1)
|
||||
#if (AUDIO_SUPPORT_FREQ_16K == 1)
|
||||
SAMPLE_FREQ(AT32_AUDIO_FREQ_16K), /* tSamFreq: 16000hz */
|
||||
#endif
|
||||
#if (AUDIO_SUPPORT_FREQ_48K == 1)
|
||||
#if (AUDIO_SUPPORT_FREQ_48K == 1)
|
||||
SAMPLE_FREQ(AT32_AUDIO_FREQ_48K), /* tSamFreq: 48000hz */
|
||||
#endif
|
||||
|
||||
@@ -283,7 +283,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
AUHID_HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
0x00, /* bRefresh: unused */
|
||||
0x00, /* bSynchAddress: unused */
|
||||
|
||||
|
||||
0x07, /* bLength: size of endpoint descriptor in bytes */
|
||||
AUDIO_CS_ENDPOINT, /* bDescriptorType: cs endpoint descriptor type */
|
||||
0x01, /* bDescriptorSubtype: general subtype */
|
||||
@@ -304,7 +304,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubclass: audio streaming */
|
||||
0x00, /* bInterfaceProtocol: unused */
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
|
||||
0x09, /* bLength: descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_SPK_INTERFACE_NUMBER, /* bInterfaceNumber: index of this interface */
|
||||
@@ -313,8 +313,8 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
USB_CLASS_CODE_AUDIO, /* bInterfaceClass: audio */
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubclass: audio streaming */
|
||||
0x00, /* bInterfaceProtocol: unused */
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x07, /* bLength: configuration descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_AS_GENERAL, /* bDescriptorSubtype: general sub type*/
|
||||
@@ -322,7 +322,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
0x01, /* bDelay: interface delay */
|
||||
0x01, /* wFormatTag: pcm format*/
|
||||
0x00, /* wFormatTag: pcm format*/
|
||||
|
||||
|
||||
0x08 + AUDIO_SPK_FREQ_SIZE * 3, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_AS_FORMAT_TYPE, /* bDescriptorSubtype: format subtype */
|
||||
@@ -331,13 +331,13 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
AUDIO_SPK_BITW / 8, /* bSubFrameSize: per audio subframe */
|
||||
AUDIO_SPK_BITW, /* bBitResolution: n bits per sample */
|
||||
AUDIO_SPK_FREQ_SIZE, /* bSamFreqType: n frequency supported */
|
||||
#if (AUDIO_SUPPORT_FREQ_16K == 1)
|
||||
#if (AUDIO_SUPPORT_FREQ_16K == 1)
|
||||
SAMPLE_FREQ(AT32_AUDIO_FREQ_16K), /* tSamFreq: 16000hz */
|
||||
#endif
|
||||
#if (AUDIO_SUPPORT_FREQ_48K == 1)
|
||||
#if (AUDIO_SUPPORT_FREQ_48K == 1)
|
||||
SAMPLE_FREQ(AT32_AUDIO_FREQ_48K), /* tSamFreq: 48000hz */
|
||||
#endif
|
||||
|
||||
|
||||
0x09, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_AUHID_AUDIO_SPK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
@@ -359,7 +359,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
0x00, /* bLockDelayUnits: unused */
|
||||
0x00, /* wLockDelay: unused */
|
||||
0x00, /* wLockDelay: unused */
|
||||
|
||||
|
||||
#if (AUDIO_SUPPORT_FEEDBACK == 1)
|
||||
0x09, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
@@ -370,11 +370,11 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
1, /* bInterval: interval for polling endpoint for data transfers */
|
||||
FEEDBACK_REFRESH_TIME, /* bRefresh: this field indicates the rate at which an iso syncronization
|
||||
pipe provides new syncronization feedback data. this rate must be a power of
|
||||
2, therefore only the power is reported back and the range of this field is from
|
||||
2, therefore only the power is reported back and the range of this field is from
|
||||
1(2ms) to 9(512ms) */
|
||||
0x00, /* bSynchAddress: 0x00*/
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
|
||||
@@ -386,7 +386,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
0x00, /* bInterfaceSubClass: subclass code */
|
||||
0x00, /* bInterfaceProtocol: protocol code */
|
||||
0x00, /* iInterface: index of string descriptor */
|
||||
|
||||
|
||||
0x09, /* bLength: size of HID descriptor in bytes */
|
||||
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
|
||||
LBYTE(AUHID_HID_BCD_NUM),
|
||||
@@ -396,7 +396,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
HID_CLASS_DESC_REPORT, /* bDescriptorType: report descriptor type */
|
||||
LBYTE(sizeof(g_usbd_audio_hid_report)),
|
||||
HBYTE(sizeof(g_usbd_audio_hid_report)), /* wDescriptorLength: total length of reprot descriptor */
|
||||
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_AUHID_HID_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
@@ -404,12 +404,12 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
LBYTE(USBD_AUHID_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_AUHID_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
AUHID_HID_BINTERVAL_TIME, /* 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_AUHID_HID_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_INTERRUPT, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_AUHID_OUT_MAXPACKET_SIZE),
|
||||
LBYTE(USBD_AUHID_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_AUHID_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
AUHID_HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
};
|
||||
@@ -420,94 +420,94 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_AUHID_CONFIG_DESC_SIZE] AL
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_usbd_audio_hid_report[USBD_AUHID_HID_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_usbd_audio_hid_report[USBD_AUHID_HID_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
{
|
||||
0x06, 0xFF, 0x00, /* USAGE_PAGE(Vendor Page:0xFF00) */
|
||||
0x09, 0x01, /* USAGE (Demo Kit) */
|
||||
0xa1, 0x01, /* COLLECTION (Application) */
|
||||
0x06, 0xFF, 0x00, /* USAGE_PAGE(Vendor Page:0xFF00) */
|
||||
0x09, 0x01, /* USAGE (Demo Kit) */
|
||||
0xa1, 0x01, /* COLLECTION (Application) */
|
||||
/* 7 */
|
||||
|
||||
|
||||
/* Led 2 */
|
||||
0x85, HID_REPORT_ID_2, /* REPORT_ID 2 */
|
||||
0x09, 0x02, /* USAGE (LED 2) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (1) */
|
||||
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (1) */
|
||||
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
|
||||
0x85, 0x02, /* REPORT_ID (2) */
|
||||
0x09, 0x02, /* USAGE (LED 2) */
|
||||
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
|
||||
/* 27 */
|
||||
|
||||
/* Led 3 */
|
||||
|
||||
/* Led 3 */
|
||||
0x85, HID_REPORT_ID_3, /* REPORT_ID (3) */
|
||||
0x09, 0x03, /* USAGE (LED 3) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (1) */
|
||||
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (1) */
|
||||
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
|
||||
0x85, 0x03, /* REPORT_ID (3) */
|
||||
0x09, 0x03, /* USAGE (LED 3) */
|
||||
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
|
||||
/* 47 */
|
||||
|
||||
|
||||
/* Led 4 */
|
||||
0x85, HID_REPORT_ID_4, /* REPORT_ID 4) */
|
||||
0x09, 0x04, /* USAGE (LED 4) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (1) */
|
||||
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (1) */
|
||||
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
|
||||
0x85, 0x04, /* REPORT_ID (4) */
|
||||
0x09, 0x04, /* USAGE (LED 4) */
|
||||
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
|
||||
/* 67 */
|
||||
|
||||
/* key Push Button */
|
||||
|
||||
/* key Push Button */
|
||||
0x85, HID_REPORT_ID_5, /* REPORT_ID (5) */
|
||||
0x09, 0x05, /* USAGE (Push Button) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */
|
||||
0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */
|
||||
|
||||
0x09, 0x05, /* USAGE (Push Button) */
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */
|
||||
0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
|
||||
0x75, 0x07, /* REPORT_SIZE (7) */
|
||||
0x81, 0x83, /* INPUT (Cnst,Var,Abs,Vol) */
|
||||
0x85, 0x05, /* REPORT_ID (5) */
|
||||
|
||||
0x75, 0x07, /* REPORT_SIZE (7) */
|
||||
0xb1, 0x83, /* FEATURE (Cnst,Var,Abs,Vol) */
|
||||
0x09, 0x05, /* USAGE (Push Button) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */
|
||||
0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */
|
||||
|
||||
0x09, 0x05, /* USAGE (Push Button) */
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */
|
||||
0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
|
||||
0x75, 0x07, /* REPORT_SIZE (7) */
|
||||
0x81, 0x83, /* INPUT (Cnst,Var,Abs,Vol) */
|
||||
0x85, 0x05, /* REPORT_ID (5) */
|
||||
|
||||
0x75, 0x07, /* REPORT_SIZE (7) */
|
||||
0xb1, 0x83, /* FEATURE (Cnst,Var,Abs,Vol) */
|
||||
/* 95 */
|
||||
|
||||
/* Data OUT */
|
||||
0x85, HID_REPORT_ID_6, /* REPORT_ID (0xF0) */
|
||||
0x09, 0x06, /* USAGE */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x26, 0x00,0xff, /* LOGICAL_MAXIMUM (255) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (64) */
|
||||
0x91, 0x02, /* OUTPUT(Data,Var,Abs,Vol) */
|
||||
|
||||
/* Data OUT */
|
||||
0x85, HID_REPORT_ID_6, /* REPORT_ID (0xF0) */
|
||||
0x09, 0x06, /* USAGE */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x26, 0x00,0xff, /* LOGICAL_MAXIMUM (255) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (64) */
|
||||
0x91, 0x02, /* OUTPUT(Data,Var,Abs,Vol) */
|
||||
/* 110 */
|
||||
|
||||
/* Data IN */
|
||||
0x85, HID_REPORT_ID_6, /* REPORT_ID (0xF0) */
|
||||
0x09, 0x07, /* USAGE */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x26, 0x00,0xff, /* LOGICAL_MAXIMUM (255) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (64) */
|
||||
0x81, 0x82, /* INPUT(Data,Var,Abs,Vol) */
|
||||
|
||||
|
||||
/* Data IN */
|
||||
0x85, HID_REPORT_ID_6, /* REPORT_ID (0xF0) */
|
||||
0x09, 0x07, /* USAGE */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x26, 0x00,0xff, /* LOGICAL_MAXIMUM (255) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (64) */
|
||||
0x81, 0x82, /* INPUT(Data,Var,Abs,Vol) */
|
||||
|
||||
/* 125 */
|
||||
0xc0 /* END_COLLECTION */
|
||||
};
|
||||
@@ -518,7 +518,7 @@ ALIGNED_HEAD uint8_t g_usbd_audio_hid_report[USBD_AUHID_HID_SIZ_REPORT_DESC] ALI
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_audio_hid_usb_desc[9] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_audio_hid_usb_desc[9] ALIGNED_TAIL =
|
||||
{
|
||||
0x09, /* bLength: size of HID descriptor in bytes */
|
||||
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
|
||||
@@ -592,24 +592,24 @@ static usbd_desc_t vp_desc;
|
||||
* @brief standard usb unicode convert
|
||||
* @param string: source string
|
||||
* @param unicode_buf: unicode buffer
|
||||
* @retval length
|
||||
* @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] = str_len;
|
||||
unicode_buf[1] = USB_DESCIPTOR_TYPE_STRING;
|
||||
|
||||
|
||||
return str_len;
|
||||
}
|
||||
|
||||
@@ -618,12 +618,12 @@ static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
* @param value: int value
|
||||
* @param pbus: unicode buffer
|
||||
* @param len: length
|
||||
* @retval none
|
||||
* @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 )
|
||||
@@ -632,11 +632,11 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
}
|
||||
|
||||
|
||||
value = value << 4;
|
||||
|
||||
|
||||
pbuf[2 * idx + 1] = 0;
|
||||
}
|
||||
}
|
||||
@@ -644,18 +644,18 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
/**
|
||||
* @brief usb get serial number
|
||||
* @param none
|
||||
* @retval 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);
|
||||
@@ -666,7 +666,7 @@ static void get_serial_num(void)
|
||||
/**
|
||||
* @brief get device descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_descriptor(void)
|
||||
{
|
||||
@@ -676,7 +676,7 @@ static usbd_desc_t *get_device_descriptor(void)
|
||||
/**
|
||||
* @brief get device qualifier
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t * get_device_qualifier(void)
|
||||
{
|
||||
@@ -686,7 +686,7 @@ static usbd_desc_t * get_device_qualifier(void)
|
||||
/**
|
||||
* @brief get config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_configuration(void)
|
||||
{
|
||||
@@ -696,7 +696,7 @@ static usbd_desc_t *get_device_configuration(void)
|
||||
/**
|
||||
* @brief get other speed descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_other_speed(void)
|
||||
{
|
||||
@@ -706,7 +706,7 @@ static usbd_desc_t *get_device_other_speed(void)
|
||||
/**
|
||||
* @brief get lang id descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_lang_id(void)
|
||||
{
|
||||
@@ -717,7 +717,7 @@ static usbd_desc_t *get_device_lang_id(void)
|
||||
/**
|
||||
* @brief get manufacturer descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
{
|
||||
@@ -729,7 +729,7 @@ static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
/**
|
||||
* @brief get product descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_product_string(void)
|
||||
{
|
||||
@@ -741,7 +741,7 @@ static usbd_desc_t *get_device_product_string(void)
|
||||
/**
|
||||
* @brief get serial descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_serial_string(void)
|
||||
{
|
||||
@@ -752,7 +752,7 @@ static usbd_desc_t *get_device_serial_string(void)
|
||||
/**
|
||||
* @brief get interface descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_interface_string(void)
|
||||
{
|
||||
@@ -764,7 +764,7 @@ static usbd_desc_t *get_device_interface_string(void)
|
||||
/**
|
||||
* @brief get device config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_config_string(void)
|
||||
{
|
||||
@@ -775,7 +775,7 @@ static usbd_desc_t *get_device_config_string(void)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_desc.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb audio 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
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AUDIO_HID_DESC_H
|
||||
#define __AUDIO_HID_DESC_H
|
||||
@@ -31,7 +31,7 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "audio_hid_class.h"
|
||||
#include "usbd_core.h"
|
||||
#include "audio_conf.h"
|
||||
@@ -39,15 +39,15 @@ extern "C" {
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_audio_hid_desc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_audio_hid_desc_definition
|
||||
/** @defgroup USB_audio_hid_desc_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
#define AUHID_BCD_NUM 0x0100
|
||||
|
||||
#define USBD_AUHID_VENDOR_ID 0x2E3C
|
||||
@@ -69,7 +69,7 @@ extern "C" {
|
||||
#define AUDIO_SUBCLASS_MIDISTREMING 0x03
|
||||
|
||||
/**
|
||||
* @brief audio class-specific descriptor types
|
||||
* @brief audio class-specific descriptor types
|
||||
*/
|
||||
#define AUDIO_CS_INTERFACE 0x24
|
||||
#define AUDIO_CS_ENDPOINT 0x25
|
||||
@@ -97,7 +97,7 @@ extern "C" {
|
||||
#define AUDIO_AC_EXTENSION_UNIT 0x08
|
||||
|
||||
/**
|
||||
* @brief audio class-specific as interface descriptor subtypes
|
||||
* @brief audio class-specific as interface descriptor subtypes
|
||||
*/
|
||||
#define AUDIO_AS_DESCRIPTOR_UNDEFINED 0x00
|
||||
#define AUDIO_AS_GENERAL 0x01
|
||||
@@ -217,7 +217,7 @@ extern "C" {
|
||||
#define HID_CLASS_DESC_PHYSICAL 0x23
|
||||
|
||||
/**
|
||||
* @brief usb hid report id define
|
||||
* @brief usb hid report id define
|
||||
*/
|
||||
#define HID_REPORT_ID_1 0x01
|
||||
#define HID_REPORT_ID_2 0x02
|
||||
@@ -249,11 +249,11 @@ extern usbd_desc_handler audio_hid_desc_handler;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_class.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb cdc 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
|
||||
* 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,
|
||||
@@ -30,11 +30,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_cdc_class
|
||||
* @brief usb device class cdc demo
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_cdc_class_private_functions
|
||||
* @{
|
||||
@@ -54,7 +54,7 @@ static usb_sts_type cdc_struct_init(cdc_struct_type *pcdc);
|
||||
extern void usb_usart_config( linecoding_type linecoding);
|
||||
static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len);
|
||||
|
||||
linecoding_type linecoding =
|
||||
linecoding_type linecoding =
|
||||
{
|
||||
115200,
|
||||
0,
|
||||
@@ -66,7 +66,7 @@ linecoding_type linecoding =
|
||||
cdc_struct_type cdc_struct;
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler cdc_class_handler =
|
||||
usbd_class_handler cdc_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
@@ -83,57 +83,57 @@ usbd_class_handler cdc_class_handler =
|
||||
/**
|
||||
* @brief initialize usb endpoint
|
||||
* @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 class_init_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
#ifndef USB_EPT_AUTO_MALLOC_BUFFER
|
||||
/* use user define buffer address */
|
||||
usbd_ept_buf_custom_define(pudev, USBD_CDC_INT_EPT, EPT2_TX_ADDR);
|
||||
usbd_ept_buf_custom_define(pudev, USBD_CDC_BULK_IN_EPT, EPT1_TX_ADDR);
|
||||
usbd_ept_buf_custom_define(pudev, USBD_CDC_BULK_OUT_EPT, EPT1_RX_ADDR);
|
||||
#endif
|
||||
|
||||
|
||||
/* open in endpoint */
|
||||
usbd_ept_open(pudev, USBD_CDC_INT_EPT, EPT_INT_TYPE, USBD_CDC_CMD_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* open in endpoint */
|
||||
usbd_ept_open(pudev, USBD_CDC_BULK_IN_EPT, EPT_BULK_TYPE, USBD_CDC_IN_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* open out endpoint */
|
||||
usbd_ept_open(pudev, USBD_CDC_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_CDC_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, pcdc->g_rx_buff, USBD_CDC_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
cdc_struct_init(pcdc);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief clear endpoint or other state
|
||||
* @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 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_CDC_INT_EPT);
|
||||
|
||||
|
||||
/* close in endpoint */
|
||||
usbd_ept_close(pudev, USBD_CDC_BULK_IN_EPT);
|
||||
|
||||
|
||||
/* close out endpoint */
|
||||
usbd_ept_close(pudev, USBD_CDC_BULK_OUT_EPT);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ static usb_sts_type class_clear_handler(void *udev)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -165,7 +165,7 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
pcdc->g_req = setup->bRequest;
|
||||
pcdc->g_len = setup->wLength;
|
||||
usbd_ctrl_recv(pudev, pcdc->g_cmd, pcdc->g_len);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -196,21 +196,21 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
/**
|
||||
* @brief usb device class endpoint 0 in status stage complete
|
||||
* @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 class_ept0_tx_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class endpoint 0 out status stage complete
|
||||
* @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 class_ept0_rx_handler(void *udev)
|
||||
{
|
||||
@@ -224,7 +224,7 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
/* class process */
|
||||
usb_vcp_cmd_process(udev, pcdc->g_req, pcdc->g_cmd, recv_len);
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -232,19 +232,19 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
* @brief usb device class transmision complete handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @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;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
pcdc->g_tx_completed = 1;
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -252,34 +252,34 @@ static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
* @brief usb device class endpoint receive data
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @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;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
/* get endpoint receive data length */
|
||||
pcdc->g_rxlen = usbd_get_recv_len(pudev, ept_num);
|
||||
|
||||
|
||||
/*set recv flag*/
|
||||
pcdc->g_rx_completed = 1;
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class sof handler
|
||||
* @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 class_sof_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ static usb_sts_type class_sof_handler(void *udev)
|
||||
* @brief usb device class event handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param event: usb device event
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
{
|
||||
@@ -295,18 +295,18 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_WAKEUP_EVENT:
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -317,7 +317,7 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
/**
|
||||
* @brief usb device cdc init
|
||||
* @param pcdc: to the structure of cdc_struct
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type cdc_struct_init(cdc_struct_type *pcdc)
|
||||
{
|
||||
@@ -335,7 +335,7 @@ static usb_sts_type cdc_struct_init(cdc_struct_type *pcdc)
|
||||
* @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
|
||||
* @retval receive data len
|
||||
*/
|
||||
uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
{
|
||||
@@ -343,7 +343,7 @@ uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
uint16_t tmp_len = 0;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
if(pcdc->g_rx_completed == 0)
|
||||
{
|
||||
return 0;
|
||||
@@ -354,9 +354,9 @@ uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
{
|
||||
recv_data[i_index] = pcdc->g_rx_buff[i_index];
|
||||
}
|
||||
|
||||
|
||||
usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, pcdc->g_rx_buff, USBD_CDC_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
return tmp_len;
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param send_data: send data buffer
|
||||
* @param len: send length
|
||||
* @retval error status
|
||||
* @retval error status
|
||||
*/
|
||||
error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
{
|
||||
@@ -391,7 +391,7 @@ error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
* @param cmd: request number
|
||||
* @param buff: request buffer
|
||||
* @param len: buffer length
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len)
|
||||
{
|
||||
@@ -409,7 +409,7 @@ static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t
|
||||
usb_usart_config(pcdc->linecoding);
|
||||
#endif
|
||||
break;
|
||||
|
||||
|
||||
case GET_LINE_CODING:
|
||||
buff[0] = (uint8_t)pcdc->linecoding.bitrate;
|
||||
buff[1] = (uint8_t)(pcdc->linecoding.bitrate >> 8);
|
||||
@@ -419,7 +419,7 @@ static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t
|
||||
buff[5] = (uint8_t)(pcdc->linecoding.parity);
|
||||
buff[6] = (uint8_t)(pcdc->linecoding.data);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -427,7 +427,7 @@ static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_class.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb cdc 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
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __CDC_CLASS_H
|
||||
#define __CDC_CLASS_H
|
||||
@@ -31,19 +31,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "usb_std.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_cdc_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_cdc_class_definition
|
||||
/** @defgroup USB_cdc_class_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -102,7 +102,7 @@ error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_desc.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb cdc 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
|
||||
* 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,
|
||||
@@ -31,11 +31,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_cdc_desc
|
||||
* @brief usb device cdc descriptor
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_cdc_desc_private_functions
|
||||
* @{
|
||||
@@ -120,7 +120,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_CDC_CONFIG_DESC_SIZE] ALIG
|
||||
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 */
|
||||
@@ -130,30 +130,30 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_CDC_CONFIG_DESC_SIZE] ALIG
|
||||
0x02, /* bInterfaceSubClass: subclass code, Abstract Control Model*/
|
||||
0x01, /* bInterfaceProtocol: protocol code, AT Command */
|
||||
0x00, /* iInterface: index of string descriptor */
|
||||
|
||||
|
||||
0x05, /* bFunctionLength: size of this descriptor in bytes */
|
||||
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
|
||||
USBD_CDC_SUBTYPE_HEADER, /* bDescriptorSubtype: Header function Descriptor 0x00*/
|
||||
LBYTE(CDC_BCD_NUM),
|
||||
HBYTE(CDC_BCD_NUM), /* bcdCDC: USB class definitions for communications */
|
||||
|
||||
|
||||
0x05, /* bFunctionLength: size of this descriptor in bytes */
|
||||
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
|
||||
USBD_CDC_SUBTYPE_CMF, /* bDescriptorSubtype: Call Management function descriptor subtype 0x01 */
|
||||
0x00, /* bmCapabilities: 0x00*/
|
||||
0x01, /* bDataInterface: interface number of data class interface optionally used for call management */
|
||||
|
||||
|
||||
0x04, /* bFunctionLength: size of this descriptor in bytes */
|
||||
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
|
||||
USBD_CDC_SUBTYPE_ACM, /* bDescriptorSubtype: Abstract Control Management functional descriptor subtype 0x02 */
|
||||
0x02, /* bmCapabilities: Support Set_Line_Coding and Get_Line_Coding 0x02 */
|
||||
|
||||
|
||||
0x05, /* bFunctionLength: size of this descriptor in bytes */
|
||||
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
|
||||
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
|
||||
USBD_CDC_SUBTYPE_UFD, /* bDescriptorSubtype: Union Function Descriptor subtype 0x06 */
|
||||
0x00, /* bControlInterface: The interface number of the communications or data class interface 0x00 */
|
||||
0x01, /* bSubordinateInterface0: interface number of first subordinate interface in the union */
|
||||
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_CDC_INT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
@@ -161,8 +161,8 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_CDC_CONFIG_DESC_SIZE] ALIG
|
||||
LBYTE(USBD_CDC_CMD_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_CDC_CMD_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
CDC_HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
|
||||
|
||||
|
||||
|
||||
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
0x01, /* bInterfaceNumber: number of interface */
|
||||
@@ -172,22 +172,22 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_CDC_CONFIG_DESC_SIZE] ALIG
|
||||
0x00, /* bInterfaceSubClass: Data interface subclass code 0x00*/
|
||||
0x00, /* bInterfaceProtocol: data class protocol code 0x00 */
|
||||
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_CDC_BULK_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_CDC_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_CDC_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
|
||||
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_CDC_BULK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_CDC_OUT_MAXPACKET_SIZE),
|
||||
LBYTE(USBD_CDC_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_CDC_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -251,24 +251,24 @@ static usbd_desc_t vp_desc;
|
||||
* @brief standard usb unicode convert
|
||||
* @param string: source string
|
||||
* @param unicode_buf: unicode buffer
|
||||
* @retval length
|
||||
* @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;
|
||||
}
|
||||
|
||||
@@ -277,12 +277,12 @@ static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
* @param value: int value
|
||||
* @param pbus: unicode buffer
|
||||
* @param len: length
|
||||
* @retval none
|
||||
* @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 )
|
||||
@@ -291,11 +291,11 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
}
|
||||
|
||||
|
||||
value = value << 4;
|
||||
|
||||
|
||||
pbuf[2 * idx + 1] = 0;
|
||||
}
|
||||
}
|
||||
@@ -303,18 +303,18 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
/**
|
||||
* @brief usb get serial number
|
||||
* @param none
|
||||
* @retval 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);
|
||||
@@ -325,7 +325,7 @@ static void get_serial_num(void)
|
||||
/**
|
||||
* @brief get device descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_descriptor(void)
|
||||
{
|
||||
@@ -335,7 +335,7 @@ static usbd_desc_t *get_device_descriptor(void)
|
||||
/**
|
||||
* @brief get device qualifier
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t * get_device_qualifier(void)
|
||||
{
|
||||
@@ -345,7 +345,7 @@ static usbd_desc_t * get_device_qualifier(void)
|
||||
/**
|
||||
* @brief get config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_configuration(void)
|
||||
{
|
||||
@@ -355,7 +355,7 @@ static usbd_desc_t *get_device_configuration(void)
|
||||
/**
|
||||
* @brief get other speed descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_other_speed(void)
|
||||
{
|
||||
@@ -365,7 +365,7 @@ static usbd_desc_t *get_device_other_speed(void)
|
||||
/**
|
||||
* @brief get lang id descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_lang_id(void)
|
||||
{
|
||||
@@ -376,7 +376,7 @@ static usbd_desc_t *get_device_lang_id(void)
|
||||
/**
|
||||
* @brief get manufacturer descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
{
|
||||
@@ -388,7 +388,7 @@ static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
/**
|
||||
* @brief get product descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_product_string(void)
|
||||
{
|
||||
@@ -400,7 +400,7 @@ static usbd_desc_t *get_device_product_string(void)
|
||||
/**
|
||||
* @brief get serial descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_serial_string(void)
|
||||
{
|
||||
@@ -411,7 +411,7 @@ static usbd_desc_t *get_device_serial_string(void)
|
||||
/**
|
||||
* @brief get interface descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_interface_string(void)
|
||||
{
|
||||
@@ -423,7 +423,7 @@ static usbd_desc_t *get_device_interface_string(void)
|
||||
/**
|
||||
* @brief get device config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_config_string(void)
|
||||
{
|
||||
@@ -434,7 +434,7 @@ static usbd_desc_t *get_device_config_string(void)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_desc.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb cdc 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
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __CDC_DESC_H
|
||||
#define __CDC_DESC_H
|
||||
@@ -31,19 +31,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "cdc_class.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_cdc_desc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_cdc_desc_definition
|
||||
/** @defgroup USB_cdc_desc_definition
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
@@ -55,7 +55,7 @@ extern "C" {
|
||||
* @brief usb vendor id and product id define
|
||||
*/
|
||||
#define USBD_CDC_VENDOR_ID 0x2E3C
|
||||
#define USBD_CDC_PRODUCT_ID 0x5740
|
||||
#define USBD_CDC_PRODUCT_ID 0x5740
|
||||
|
||||
/**
|
||||
* @brief usb descriptor size define
|
||||
@@ -73,7 +73,7 @@ extern "C" {
|
||||
#define USBD_CDC_DESC_INTERFACE_STRING "Virtual ComPort Interface"
|
||||
|
||||
/**
|
||||
* @brief usb endpoint interval define
|
||||
* @brief usb endpoint interval define
|
||||
*/
|
||||
#define CDC_HID_BINTERVAL_TIME 0xFF
|
||||
|
||||
@@ -86,14 +86,14 @@ extern "C" {
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
extern usbd_desc_handler cdc_desc_handler;
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_keyboard_class.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb cdc and keyboard 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
|
||||
* 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,
|
||||
@@ -30,11 +30,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_cdc_keyboard_class
|
||||
* @brief usb device class composite cdc and keyboard
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_cdc_keyboard_class_private_functions
|
||||
* @{
|
||||
@@ -70,7 +70,7 @@ const static unsigned char _asciimap[128] =
|
||||
0x2A,// BS Backspace
|
||||
0x2B,// TAB Tab
|
||||
0x28,// LF Enter
|
||||
0x00,// VT
|
||||
0x00,// VT
|
||||
0x00,// FF
|
||||
0x00,// CR
|
||||
0x00,// SO
|
||||
@@ -202,7 +202,7 @@ linecoding_type linecoding_vcpkybrd =
|
||||
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler cdc_keyboard_class_handler =
|
||||
usbd_class_handler cdc_keyboard_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
@@ -219,7 +219,7 @@ usbd_class_handler cdc_keyboard_class_handler =
|
||||
/**
|
||||
* @brief initialize usb endpoint
|
||||
* @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 class_init_handler(void *udev)
|
||||
{
|
||||
@@ -233,25 +233,25 @@ static usb_sts_type class_init_handler(void *udev)
|
||||
usbd_ept_buf_custom_define(pudev, USBD_VCPKYBRD_CDC_BULK_OUT_EPT, EPT1_RX_ADDR);
|
||||
usbd_ept_buf_custom_define(pudev, USBD_VCPKYBRD_HID_IN_EPT, EPT3_TX_ADDR);
|
||||
#endif
|
||||
|
||||
|
||||
/* open in endpoint */
|
||||
usbd_ept_open(pudev, USBD_VCPKYBRD_CDC_INT_EPT, EPT_INT_TYPE, USBD_VCPKYBRD_CMD_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* open in endpoint */
|
||||
usbd_ept_open(pudev, USBD_VCPKYBRD_CDC_BULK_IN_EPT, EPT_BULK_TYPE, USBD_VCPKYBRD_IN_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* open out endpoint */
|
||||
usbd_ept_open(pudev, USBD_VCPKYBRD_CDC_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_VCPKYBRD_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* open hid in endpoint */
|
||||
usbd_ept_open(pudev, USBD_VCPKYBRD_HID_IN_EPT, EPT_INT_TYPE, USBD_VCPKYBRD_IN_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_VCPKYBRD_CDC_BULK_OUT_EPT, vcpkybrd->g_rx_buff, USBD_VCPKYBRD_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
vcpkybrd->g_tx_completed = 1;
|
||||
vcpkybrd->g_keyboard_tx_completed = 1;
|
||||
|
||||
|
||||
vcpkybrd->linecoding.bitrate = linecoding_vcpkybrd.bitrate;
|
||||
vcpkybrd->linecoding.data = linecoding_vcpkybrd.data;
|
||||
vcpkybrd->linecoding.format = linecoding_vcpkybrd.format;
|
||||
@@ -262,25 +262,25 @@ static usb_sts_type class_init_handler(void *udev)
|
||||
/**
|
||||
* @brief clear endpoint or other state
|
||||
* @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 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_VCPKYBRD_CDC_INT_EPT);
|
||||
|
||||
|
||||
/* close in endpoint */
|
||||
usbd_ept_close(pudev, USBD_VCPKYBRD_CDC_BULK_IN_EPT);
|
||||
|
||||
|
||||
/* close out endpoint */
|
||||
usbd_ept_close(pudev, USBD_VCPKYBRD_CDC_BULK_OUT_EPT);
|
||||
|
||||
|
||||
/* close in endpoint */
|
||||
usbd_ept_close(pudev, USBD_VCPKYBRD_HID_IN_EPT);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ static usb_sts_type class_clear_handler(void *udev)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -308,7 +308,7 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
break;
|
||||
case USB_REQ_RECIPIENT_ENDPOINT:
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
return status;
|
||||
}
|
||||
@@ -317,7 +317,7 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -341,7 +341,7 @@ static usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
vcpkybrd->g_req = setup->bRequest;
|
||||
vcpkybrd->g_len = setup->wLength;
|
||||
usbd_ctrl_recv(pudev, vcpkybrd->g_cmd, vcpkybrd->g_len);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -373,7 +373,7 @@ static usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type keyboard_class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -447,21 +447,21 @@ static usb_sts_type keyboard_class_setup_handler(void *udev, usb_setup_type *set
|
||||
/**
|
||||
* @brief usb device class endpoint 0 in status stage complete
|
||||
* @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 class_ept0_tx_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class endpoint 0 out status stage complete
|
||||
* @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 class_ept0_rx_handler(void *udev)
|
||||
{
|
||||
@@ -475,7 +475,7 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
/* class process */
|
||||
usb_vcp_cmd_process(udev, vcpkybrd->g_req, vcpkybrd->g_cmd, recv_len);
|
||||
}
|
||||
|
||||
|
||||
if( vcpkybrd->hid_state == HID_REQ_SET_REPORT)
|
||||
{
|
||||
/* hid buffer process */
|
||||
@@ -488,14 +488,14 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
* @brief usb device class transmision complete handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
@@ -507,8 +507,8 @@ static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
vcpkybrd->g_keyboard_tx_completed = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -516,34 +516,34 @@ static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
* @brief usb device class endpoint receive data
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @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;
|
||||
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
/* get endpoint receive data length */
|
||||
vcpkybrd->g_rxlen = usbd_get_recv_len(pudev, ept_num);
|
||||
|
||||
|
||||
/*set recv flag*/
|
||||
vcpkybrd->g_rx_completed = 1;
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class sof handler
|
||||
* @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 class_sof_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -551,7 +551,7 @@ static usb_sts_type class_sof_handler(void *udev)
|
||||
* @brief usb device class event handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param event: usb device event
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
{
|
||||
@@ -559,18 +559,18 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_WAKEUP_EVENT:
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -582,7 +582,7 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
* @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
|
||||
* @retval receive data len
|
||||
*/
|
||||
uint16_t usb_vcpkybrd_vcp_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
{
|
||||
@@ -590,21 +590,21 @@ uint16_t usb_vcpkybrd_vcp_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
|
||||
uint16_t tmp_len = 0;
|
||||
|
||||
|
||||
if(vcpkybrd->g_rx_completed == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
vcpkybrd->g_rx_completed = 0;
|
||||
|
||||
|
||||
tmp_len = vcpkybrd->g_rxlen;
|
||||
for(i_index = 0; i_index < vcpkybrd->g_rxlen; i_index ++)
|
||||
{
|
||||
recv_data[i_index] = vcpkybrd->g_rx_buff[i_index];
|
||||
}
|
||||
|
||||
|
||||
usbd_ept_recv(pudev, USBD_VCPKYBRD_CDC_BULK_OUT_EPT, vcpkybrd->g_rx_buff, USBD_VCPKYBRD_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
return tmp_len;
|
||||
}
|
||||
|
||||
@@ -613,7 +613,7 @@ uint16_t usb_vcpkybrd_vcp_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param send_data: send data buffer
|
||||
* @param len: send length
|
||||
* @retval error status
|
||||
* @retval error status
|
||||
*/
|
||||
error_status usb_vcpkybrd_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
{
|
||||
@@ -639,7 +639,7 @@ error_status usb_vcpkybrd_vcp_send_data(void *udev, uint8_t *send_data, uint16_t
|
||||
* @param cmd: request number
|
||||
* @param buff: request buffer
|
||||
* @param len: buffer length
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len)
|
||||
{
|
||||
@@ -653,7 +653,7 @@ static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t
|
||||
vcpkybrd->linecoding.parity = buff[5];
|
||||
vcpkybrd->linecoding.data = buff[6];
|
||||
break;
|
||||
|
||||
|
||||
case GET_LINE_CODING:
|
||||
buff[0] = (uint8_t)vcpkybrd->linecoding.bitrate;
|
||||
buff[1] = (uint8_t)(vcpkybrd->linecoding.bitrate >> 8);
|
||||
@@ -663,7 +663,7 @@ static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t
|
||||
buff[5] = (uint8_t)(vcpkybrd->linecoding.parity);
|
||||
buff[6] = (uint8_t)(vcpkybrd->linecoding.data);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -674,7 +674,7 @@ static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param report: report buffer
|
||||
* @param len: report length
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type usb_vcpkybrd_class_send_report(void *udev, uint8_t *report, uint16_t len)
|
||||
{
|
||||
@@ -683,7 +683,7 @@ usb_sts_type usb_vcpkybrd_class_send_report(void *udev, uint8_t *report, uint16_
|
||||
|
||||
if(usbd_connect_state_get(pudev) == USB_CONN_STATE_CONFIGURED)
|
||||
usbd_ept_send(pudev, USBD_VCPKYBRD_HID_IN_EPT, report, len);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -692,14 +692,14 @@ usb_sts_type usb_vcpkybrd_class_send_report(void *udev, uint8_t *report, uint16_
|
||||
* @brief usb keyoard send char
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param op: operation
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void usb_vcpkybrd_keyboard_send_char(void *udev, uint8_t ascii_code)
|
||||
{
|
||||
uint8_t key_data = 0;
|
||||
static uint8_t temp = 0;
|
||||
static uint8_t keyboard_buf[8] = {0, 0, 6, 0, 0, 0, 0, 0};
|
||||
|
||||
|
||||
if(ascii_code > 128)
|
||||
{
|
||||
ascii_code = 0;
|
||||
@@ -711,14 +711,14 @@ void usb_vcpkybrd_keyboard_send_char(void *udev, uint8_t ascii_code)
|
||||
{
|
||||
ascii_code = 0;
|
||||
}
|
||||
|
||||
|
||||
if(ascii_code & SHIFT)
|
||||
{
|
||||
key_data = 0x2;
|
||||
ascii_code &= 0x7F;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if((temp == ascii_code) && (ascii_code != 0))
|
||||
{
|
||||
keyboard_buf[0] = 0;
|
||||
@@ -735,7 +735,7 @@ void usb_vcpkybrd_keyboard_send_char(void *udev, uint8_t ascii_code)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_keyboard_class.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb cdc and keyboard 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
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __CDC_KEYBOARD_CLASS_H
|
||||
#define __CDC_KEYBOARD_CLASS_H
|
||||
@@ -31,19 +31,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "usb_std.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_cdc_keyboard_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_cdc_keyboard_class_definition
|
||||
/** @defgroup USB_cdc_keyboard_class_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -83,10 +83,10 @@ typedef struct
|
||||
uint8_t g_req;
|
||||
uint8_t hid_state;
|
||||
uint16_t g_len, g_rxlen;
|
||||
__IO uint8_t g_tx_completed;
|
||||
__IO uint8_t g_tx_completed;
|
||||
__IO uint8_t g_rx_completed;
|
||||
__IO uint8_t g_keyboard_tx_completed;
|
||||
|
||||
|
||||
linecoding_type linecoding;
|
||||
}vcp_keyboard_type;
|
||||
|
||||
@@ -110,7 +110,7 @@ void usb_vcpkybrd_keyboard_send_char(void *udev, uint8_t ascii_code);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_keyboard_desc.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb cdc and keyboard 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
|
||||
* 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,
|
||||
@@ -30,11 +30,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_cdc_keyboard_desc
|
||||
* @brief usb device cdc keyboard descriptor
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_cdc_keyboard_desc_private_functions
|
||||
* @{
|
||||
@@ -119,7 +119,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_VCPKYBRD_CONFIG_DESC_SIZE]
|
||||
the configuration */
|
||||
0xC0, /* bmAttributes: self powered */
|
||||
0x32, /* MaxPower 100 mA: this current is used for detecting vbus */
|
||||
|
||||
|
||||
0x08, /* bLength */
|
||||
0x0B, /* bDescriptorType */
|
||||
0x00, /* bFirstInterface */
|
||||
@@ -128,7 +128,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_VCPKYBRD_CONFIG_DESC_SIZE]
|
||||
0x02, /* bFunctionSubClass */
|
||||
0x01, /* bFunctionProtocol */
|
||||
0x00, /* iFunction (Index of string descriptor describing this function) */
|
||||
|
||||
|
||||
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
VCPKYBRD_CDC_INTERFACE, /* bInterfaceNumber: number of interface */
|
||||
@@ -138,30 +138,30 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_VCPKYBRD_CONFIG_DESC_SIZE]
|
||||
0x02, /* bInterfaceSubClass: subclass code, Abstract Control Model*/
|
||||
0x01, /* bInterfaceProtocol: protocol code, AT Command */
|
||||
0x00, /* iInterface: index of string descriptor */
|
||||
|
||||
|
||||
0x05, /* bFunctionLength: size of this descriptor in bytes */
|
||||
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
|
||||
USBD_CDC_SUBTYPE_HEADER, /* bDescriptorSubtype: Header function Descriptor 0x00*/
|
||||
LBYTE(VCPKYBRD_BCD_NUM),
|
||||
HBYTE(VCPKYBRD_BCD_NUM), /* bcdCDC: USB class definitions for communications */
|
||||
|
||||
|
||||
0x05, /* bFunctionLength: size of this descriptor in bytes */
|
||||
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
|
||||
USBD_CDC_SUBTYPE_CMF, /* bDescriptorSubtype: Call Management function descriptor subtype 0x01 */
|
||||
0x00, /* bmCapabilities: 0x00*/
|
||||
0x01, /* bDataInterface: interface number of data class interface optionally used for call management */
|
||||
|
||||
|
||||
0x04, /* bFunctionLength: size of this descriptor in bytes */
|
||||
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
|
||||
USBD_CDC_SUBTYPE_ACM, /* bDescriptorSubtype: Abstract Control Management functional descriptor subtype 0x02 */
|
||||
0x02, /* bmCapabilities: Support Set_Line_Coding and Get_Line_Coding 0x02 */
|
||||
|
||||
|
||||
0x05, /* bFunctionLength: size of this descriptor in bytes */
|
||||
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
|
||||
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
|
||||
USBD_CDC_SUBTYPE_UFD, /* bDescriptorSubtype: Union Function Descriptor subtype 0x06 */
|
||||
0x00, /* bControlInterface: The interface number of the communications or data class interface 0x00 */
|
||||
0x01, /* bSubordinateInterface0: interface number of first subordinate interface in the union */
|
||||
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_VCPKYBRD_CDC_INT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
@@ -169,8 +169,8 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_VCPKYBRD_CONFIG_DESC_SIZE]
|
||||
LBYTE(USBD_VCPKYBRD_CMD_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_VCPKYBRD_CMD_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
VCPKYBRD_HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
|
||||
|
||||
|
||||
|
||||
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
VCPKYBRD_CDC_DATA_INTERFACE, /* bInterfaceNumber: number of interface */
|
||||
@@ -180,7 +180,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_VCPKYBRD_CONFIG_DESC_SIZE]
|
||||
0x00, /* bInterfaceSubClass: Data interface subclass code 0x00*/
|
||||
0x00, /* bInterfaceProtocol: data class protocol code 0x00 */
|
||||
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_VCPKYBRD_CDC_BULK_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
@@ -188,15 +188,15 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_VCPKYBRD_CONFIG_DESC_SIZE]
|
||||
LBYTE(USBD_VCPKYBRD_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_VCPKYBRD_IN_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_VCPKYBRD_CDC_BULK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_VCPKYBRD_OUT_MAXPACKET_SIZE),
|
||||
LBYTE(USBD_VCPKYBRD_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_VCPKYBRD_OUT_MAXPACKET_SIZE),/* wMaxPacketSize: maximum packe size this endpoint */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
|
||||
|
||||
0x08, /* bLength */
|
||||
0x0B, /* bDescriptorType */
|
||||
0x02, /* bFirstInterface */
|
||||
@@ -205,7 +205,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_VCPKYBRD_CONFIG_DESC_SIZE]
|
||||
0x00, /* bFunctionSubClass */
|
||||
0x01, /* bFunctionProtocol */
|
||||
0x00, /* iFunction (Index of string descriptor describing this function) */
|
||||
|
||||
|
||||
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
VCPKYBRD_KEYBOARD_INTERFACE, /* bInterfaceNumber: number of interface */
|
||||
@@ -215,7 +215,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_VCPKYBRD_CONFIG_DESC_SIZE]
|
||||
0x01, /* bInterfaceSubClass: subclass code */
|
||||
0x01, /* bInterfaceProtocol: protocol code */
|
||||
0x00, /* iInterface: index of string descriptor */
|
||||
|
||||
|
||||
0x09, /* bLength: size of HID descriptor in bytes */
|
||||
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
|
||||
LBYTE(VCPKYBRD_BCD_NUM),
|
||||
@@ -225,7 +225,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_VCPKYBRD_CONFIG_DESC_SIZE]
|
||||
HID_CLASS_DESC_REPORT, /* bDescriptorType: report descriptor type */
|
||||
LBYTE(sizeof(g_usbd_vcpkybrd_hid_report)),
|
||||
HBYTE(sizeof(g_usbd_vcpkybrd_hid_report)), /* wDescriptorLength: total length of reprot descriptor */
|
||||
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_VCPKYBRD_HID_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
@@ -241,7 +241,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_VCPKYBRD_CONFIG_DESC_SIZE]
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_vcpkybrd_hid_usb_desc[9] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_vcpkybrd_hid_usb_desc[9] ALIGNED_TAIL =
|
||||
{
|
||||
0x09, /* bLength: size of HID descriptor in bytes */
|
||||
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
|
||||
@@ -260,7 +260,7 @@ ALIGNED_HEAD uint8_t g_vcpkybrd_hid_usb_desc[9] ALIGNED_TAIL =
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_usbd_vcpkybrd_hid_report[USBD_VCPKYBRD_HID_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_usbd_vcpkybrd_hid_report[USBD_VCPKYBRD_HID_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
{
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
0x09, 0x06, // USAGE (Keyboard)
|
||||
@@ -293,7 +293,7 @@ ALIGNED_HEAD uint8_t g_usbd_vcpkybrd_hid_report[USBD_VCPKYBRD_HID_SIZ_REPORT_DES
|
||||
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
|
||||
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
|
||||
0x81, 0x00, // INPUT (Data,Ary,Abs)
|
||||
0xc0 // END_COLLECTION
|
||||
0xc0 // END_COLLECTION
|
||||
};
|
||||
/**
|
||||
* @brief usb string lang id
|
||||
@@ -356,24 +356,24 @@ static usbd_desc_t vp_desc;
|
||||
* @brief standard usb unicode convert
|
||||
* @param string: source string
|
||||
* @param unicode_buf: unicode buffer
|
||||
* @retval length
|
||||
* @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] = str_len;
|
||||
unicode_buf[1] = USB_DESCIPTOR_TYPE_STRING;
|
||||
|
||||
|
||||
return str_len;
|
||||
}
|
||||
|
||||
@@ -382,12 +382,12 @@ static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
* @param value: int value
|
||||
* @param pbus: unicode buffer
|
||||
* @param len: length
|
||||
* @retval none
|
||||
* @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 )
|
||||
@@ -396,11 +396,11 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
}
|
||||
|
||||
|
||||
value = value << 4;
|
||||
|
||||
|
||||
pbuf[2 * idx + 1] = 0;
|
||||
}
|
||||
}
|
||||
@@ -408,18 +408,18 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
/**
|
||||
* @brief usb get serial number
|
||||
* @param none
|
||||
* @retval 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);
|
||||
@@ -430,7 +430,7 @@ static void get_serial_num(void)
|
||||
/**
|
||||
* @brief get device descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_descriptor(void)
|
||||
{
|
||||
@@ -440,7 +440,7 @@ static usbd_desc_t *get_device_descriptor(void)
|
||||
/**
|
||||
* @brief get device qualifier
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t * get_device_qualifier(void)
|
||||
{
|
||||
@@ -450,7 +450,7 @@ static usbd_desc_t * get_device_qualifier(void)
|
||||
/**
|
||||
* @brief get config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_configuration(void)
|
||||
{
|
||||
@@ -460,7 +460,7 @@ static usbd_desc_t *get_device_configuration(void)
|
||||
/**
|
||||
* @brief get other speed descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_other_speed(void)
|
||||
{
|
||||
@@ -470,7 +470,7 @@ static usbd_desc_t *get_device_other_speed(void)
|
||||
/**
|
||||
* @brief get lang id descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_lang_id(void)
|
||||
{
|
||||
@@ -481,7 +481,7 @@ static usbd_desc_t *get_device_lang_id(void)
|
||||
/**
|
||||
* @brief get manufacturer descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
{
|
||||
@@ -493,7 +493,7 @@ static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
/**
|
||||
* @brief get product descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_product_string(void)
|
||||
{
|
||||
@@ -505,7 +505,7 @@ static usbd_desc_t *get_device_product_string(void)
|
||||
/**
|
||||
* @brief get serial descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_serial_string(void)
|
||||
{
|
||||
@@ -516,7 +516,7 @@ static usbd_desc_t *get_device_serial_string(void)
|
||||
/**
|
||||
* @brief get interface descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_interface_string(void)
|
||||
{
|
||||
@@ -528,7 +528,7 @@ static usbd_desc_t *get_device_interface_string(void)
|
||||
/**
|
||||
* @brief get device config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_config_string(void)
|
||||
{
|
||||
@@ -539,7 +539,7 @@ static usbd_desc_t *get_device_config_string(void)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_keyboard_desc.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb cdc and keyboard 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
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __CDC_KEYBOARD_DESC_H
|
||||
#define __CDC_KEYBOARD_DESC_H
|
||||
@@ -31,19 +31,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "cdc_keyboard_class.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_cdc_keyboard_desc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_cdc_keyboard_desc_definition
|
||||
/** @defgroup USB_cdc_keyboard_desc_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -56,7 +56,7 @@ extern "C" {
|
||||
* @brief usb vendor id and product id define
|
||||
*/
|
||||
#define USBD_VCPKYBRD_VENDOR_ID 0x2E3C
|
||||
#define USBD_VCPKYBRD_PRODUCT_ID 0x5750
|
||||
#define USBD_VCPKYBRD_PRODUCT_ID 0x5750
|
||||
|
||||
|
||||
/**
|
||||
@@ -76,7 +76,7 @@ extern "C" {
|
||||
#define USBD_VCPKYBRD_DESC_INTERFACE_STRING "Composite VCP and Keyboard Interface"
|
||||
|
||||
/**
|
||||
* @brief usb endpoint interval define
|
||||
* @brief usb endpoint interval define
|
||||
*/
|
||||
#define VCPKYBRD_HID_BINTERVAL_TIME 0x0A
|
||||
|
||||
@@ -105,7 +105,7 @@ extern usbd_desc_handler cdc_keyboard_desc_handler;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file custom_hid_class.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb custom hid 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
|
||||
* 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,
|
||||
@@ -30,11 +30,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_custom_hid_class
|
||||
* @brief usb device custom hid demo
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_custom_hid_class_private_functions
|
||||
* @{
|
||||
@@ -54,7 +54,7 @@ static void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len);
|
||||
custom_hid_type custom_hid_struct;
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler custom_hid_class_handler =
|
||||
usbd_class_handler custom_hid_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
@@ -71,7 +71,7 @@ usbd_class_handler custom_hid_class_handler =
|
||||
/**
|
||||
* @brief initialize usb endpoint
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_init_handler(void *udev)
|
||||
{
|
||||
@@ -83,35 +83,35 @@ usb_sts_type class_init_handler(void *udev)
|
||||
usbd_ept_buf_custom_define(pudev, USBD_CUSTOM_HID_IN_EPT, EPT1_TX_ADDR);
|
||||
usbd_ept_buf_custom_define(pudev, USBD_CUSTOM_HID_OUT_EPT, EPT1_RX_ADDR);
|
||||
#endif
|
||||
|
||||
|
||||
/* open custom hid in endpoint */
|
||||
usbd_ept_open(pudev, USBD_CUSTOM_HID_IN_EPT, EPT_INT_TYPE, USBD_CUSTOM_IN_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* open custom hid out endpoint */
|
||||
usbd_ept_open(pudev, USBD_CUSTOM_HID_OUT_EPT, EPT_INT_TYPE, USBD_CUSTOM_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_CUSTOM_HID_OUT_EPT, pcshid->g_rxhid_buff, USBD_CUSTOM_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
|
||||
* @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 custom hid in endpoint */
|
||||
usbd_ept_close(pudev, USBD_CUSTOM_HID_IN_EPT);
|
||||
|
||||
|
||||
/* close custom hid out endpoint */
|
||||
usbd_ept_close(pudev, USBD_CUSTOM_HID_OUT_EPT);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ static usb_sts_type class_clear_handler(void *udev)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -193,21 +193,21 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
/**
|
||||
* @brief usb device class endpoint 0 in status stage complete
|
||||
* @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 class_ept0_tx_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class endpoint 0 out status stage complete
|
||||
* @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 class_ept0_rx_handler(void *udev)
|
||||
{
|
||||
@@ -222,7 +222,7 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
usb_hid_buf_process(udev, pcshid->hid_set_report, recv_len);
|
||||
pcshid->hid_state = 0;
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -230,16 +230,16 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
* @brief usb device class transmision complete handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -247,37 +247,37 @@ static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
* @brief usb device class endpoint receive data
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @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;
|
||||
custom_hid_type *pcshid = (custom_hid_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
/* get endpoint receive data length */
|
||||
uint32_t recv_len = usbd_get_recv_len(pudev, ept_num);
|
||||
|
||||
|
||||
/* hid buffer process */
|
||||
usb_hid_buf_process(udev, pcshid->g_rxhid_buff, recv_len);
|
||||
|
||||
|
||||
/* start receive next packet */
|
||||
usbd_ept_recv(pudev, USBD_CUSTOM_HID_OUT_EPT, pcshid->g_rxhid_buff, recv_len);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class sof handler
|
||||
* @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 class_sof_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ static usb_sts_type class_sof_handler(void *udev)
|
||||
* @brief usb device class event handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param event: usb device event
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
{
|
||||
@@ -293,18 +293,18 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_WAKEUP_EVENT:
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -317,7 +317,7 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param report: report buffer
|
||||
* @param len: report length
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type custom_hid_class_send_report(void *udev, uint8_t *report, uint16_t len)
|
||||
{
|
||||
@@ -326,7 +326,7 @@ usb_sts_type custom_hid_class_send_report(void *udev, uint8_t *report, uint16_t
|
||||
|
||||
if(usbd_connect_state_get(pudev) == USB_CONN_STATE_CONFIGURED)
|
||||
usbd_ept_send(pudev, USBD_CUSTOM_HID_IN_EPT, report, len);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -335,14 +335,14 @@ usb_sts_type custom_hid_class_send_report(void *udev, uint8_t *report, uint16_t
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param report: report buffer
|
||||
* @param len: report length
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
static void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
|
||||
{
|
||||
uint32_t i_index;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
custom_hid_type *pcshid = (custom_hid_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
switch(report[0])
|
||||
{
|
||||
case HID_REPORT_ID_2:
|
||||
@@ -382,14 +382,14 @@ static void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
|
||||
}
|
||||
usbd_ept_send(pudev, USBD_CUSTOM_HID_IN_EPT, pcshid->g_txhid_buff, len);
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file custom_hid_class.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb custom hid 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __CUSTOM_HID_CLASS_H
|
||||
#define __CUSTOM_HID_CLASS_H
|
||||
@@ -31,19 +31,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "usb_std.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_custom_hid_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_custom_hid_class_endpoint_definition
|
||||
/** @defgroup USB_custom_hid_class_endpoint_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -63,10 +63,10 @@ extern "C" {
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_custom_hid_class_request_code_definition
|
||||
/** @defgroup USB_custom_hid_class_request_code_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t g_rxhid_buff[USBD_CUSTOM_OUT_MAXPACKET_SIZE];
|
||||
@@ -95,7 +95,7 @@ usb_sts_type custom_hid_class_send_report(void *udev, uint8_t *report, uint16_t
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file custom_hid_desc.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb hid 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
|
||||
* 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,
|
||||
@@ -31,11 +31,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_custom_hid_desc
|
||||
* @brief usb device custom_hid descriptor
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_custom_hid_desc_private_functions
|
||||
* @{
|
||||
@@ -119,7 +119,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_CUSHID_CONFIG_DESC_SIZE] A
|
||||
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 */
|
||||
@@ -129,7 +129,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_CUSHID_CONFIG_DESC_SIZE] A
|
||||
0x00, /* bInterfaceSubClass: subclass code */
|
||||
0x00, /* bInterfaceProtocol: protocol code */
|
||||
0x00, /* iInterface: index of string descriptor */
|
||||
|
||||
|
||||
0x09, /* bLength: size of HID descriptor in bytes */
|
||||
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
|
||||
LBYTE(CUSHID_BCD_NUM),
|
||||
@@ -139,7 +139,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_CUSHID_CONFIG_DESC_SIZE] A
|
||||
HID_CLASS_DESC_REPORT, /* bDescriptorType: report descriptor type */
|
||||
LBYTE(sizeof(g_usbd_custom_hid_report)),
|
||||
HBYTE(sizeof(g_usbd_custom_hid_report)), /* wDescriptorLength: total length of reprot descriptor */
|
||||
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_CUSTOM_HID_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
@@ -147,12 +147,12 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_CUSHID_CONFIG_DESC_SIZE] A
|
||||
LBYTE(USBD_CUSTOM_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_CUSTOM_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
CUSHID_BINTERVAL_TIME, /* 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_CUSTOM_HID_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_INTERRUPT, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_CUSTOM_OUT_MAXPACKET_SIZE),
|
||||
LBYTE(USBD_CUSTOM_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_CUSTOM_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
CUSHID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
};
|
||||
@@ -163,94 +163,94 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_CUSHID_CONFIG_DESC_SIZE] A
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_usbd_custom_hid_report[USBD_CUSHID_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_usbd_custom_hid_report[USBD_CUSHID_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
{
|
||||
0x06, 0xFF, 0x00, /* USAGE_PAGE(Vendor Page:0xFF00) */
|
||||
0x09, 0x01, /* USAGE (Demo Kit) */
|
||||
0xa1, 0x01, /* COLLECTION (Application) */
|
||||
0x06, 0xFF, 0x00, /* USAGE_PAGE(Vendor Page:0xFF00) */
|
||||
0x09, 0x01, /* USAGE (Demo Kit) */
|
||||
0xa1, 0x01, /* COLLECTION (Application) */
|
||||
/* 7 */
|
||||
|
||||
|
||||
/* Led 2 */
|
||||
0x85, HID_REPORT_ID_2, /* REPORT_ID 2 */
|
||||
0x09, 0x02, /* USAGE (LED 2) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (1) */
|
||||
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (1) */
|
||||
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
|
||||
0x85, 0x02, /* REPORT_ID (2) */
|
||||
0x09, 0x02, /* USAGE (LED 2) */
|
||||
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
|
||||
/* 27 */
|
||||
|
||||
/* Led 3 */
|
||||
|
||||
/* Led 3 */
|
||||
0x85, HID_REPORT_ID_3, /* REPORT_ID (3) */
|
||||
0x09, 0x03, /* USAGE (LED 3) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (1) */
|
||||
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (1) */
|
||||
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
|
||||
0x85, 0x03, /* REPORT_ID (3) */
|
||||
0x09, 0x03, /* USAGE (LED 3) */
|
||||
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
|
||||
/* 47 */
|
||||
|
||||
|
||||
/* Led 4 */
|
||||
0x85, HID_REPORT_ID_4, /* REPORT_ID 4) */
|
||||
0x09, 0x04, /* USAGE (LED 4) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (1) */
|
||||
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (1) */
|
||||
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
|
||||
0x85, 0x04, /* REPORT_ID (4) */
|
||||
0x09, 0x04, /* USAGE (LED 4) */
|
||||
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
|
||||
/* 67 */
|
||||
|
||||
/* key Push Button */
|
||||
|
||||
/* key Push Button */
|
||||
0x85, HID_REPORT_ID_5, /* REPORT_ID (5) */
|
||||
0x09, 0x05, /* USAGE (Push Button) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */
|
||||
0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */
|
||||
|
||||
0x09, 0x05, /* USAGE (Push Button) */
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */
|
||||
0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
|
||||
0x75, 0x07, /* REPORT_SIZE (7) */
|
||||
0x81, 0x83, /* INPUT (Cnst,Var,Abs,Vol) */
|
||||
0x85, 0x05, /* REPORT_ID (5) */
|
||||
|
||||
0x75, 0x07, /* REPORT_SIZE (7) */
|
||||
0xb1, 0x83, /* FEATURE (Cnst,Var,Abs,Vol) */
|
||||
0x09, 0x05, /* USAGE (Push Button) */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */
|
||||
0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */
|
||||
|
||||
0x09, 0x05, /* USAGE (Push Button) */
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */
|
||||
0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
|
||||
|
||||
0x75, 0x07, /* REPORT_SIZE (7) */
|
||||
0x81, 0x83, /* INPUT (Cnst,Var,Abs,Vol) */
|
||||
0x85, 0x05, /* REPORT_ID (5) */
|
||||
|
||||
0x75, 0x07, /* REPORT_SIZE (7) */
|
||||
0xb1, 0x83, /* FEATURE (Cnst,Var,Abs,Vol) */
|
||||
/* 95 */
|
||||
|
||||
/* Data OUT */
|
||||
0x85, HID_REPORT_ID_6, /* REPORT_ID (0xF0) */
|
||||
0x09, 0x06, /* USAGE */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x26, 0x00,0xff, /* LOGICAL_MAXIMUM (255) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (64) */
|
||||
0x91, 0x02, /* OUTPUT(Data,Var,Abs,Vol) */
|
||||
|
||||
/* Data OUT */
|
||||
0x85, HID_REPORT_ID_6, /* REPORT_ID (0xF0) */
|
||||
0x09, 0x06, /* USAGE */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x26, 0x00,0xff, /* LOGICAL_MAXIMUM (255) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (64) */
|
||||
0x91, 0x02, /* OUTPUT(Data,Var,Abs,Vol) */
|
||||
/* 110 */
|
||||
|
||||
/* Data IN */
|
||||
0x85, HID_REPORT_ID_6, /* REPORT_ID (0xF0) */
|
||||
0x09, 0x07, /* USAGE */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x26, 0x00,0xff, /* LOGICAL_MAXIMUM (255) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (64) */
|
||||
0x81, 0x82, /* INPUT(Data,Var,Abs,Vol) */
|
||||
|
||||
|
||||
/* Data IN */
|
||||
0x85, HID_REPORT_ID_6, /* REPORT_ID (0xF0) */
|
||||
0x09, 0x07, /* USAGE */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x26, 0x00,0xff, /* LOGICAL_MAXIMUM (255) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x3F, /* REPORT_COUNT (64) */
|
||||
0x81, 0x82, /* INPUT(Data,Var,Abs,Vol) */
|
||||
|
||||
/* 125 */
|
||||
0xc0 /* END_COLLECTION */
|
||||
};
|
||||
@@ -261,7 +261,7 @@ ALIGNED_HEAD uint8_t g_usbd_custom_hid_report[USBD_CUSHID_SIZ_REPORT_DESC] ALIGN
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_custom_hid_usb_desc[9] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_custom_hid_usb_desc[9] ALIGNED_TAIL =
|
||||
{
|
||||
0x09, /* bLength: size of HID descriptor in bytes */
|
||||
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
|
||||
@@ -336,24 +336,24 @@ static usbd_desc_t vp_desc;
|
||||
* @brief standard usb unicode convert
|
||||
* @param string: source string
|
||||
* @param unicode_buf: unicode buffer
|
||||
* @retval length
|
||||
* @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] = str_len;
|
||||
unicode_buf[1] = USB_DESCIPTOR_TYPE_STRING;
|
||||
|
||||
|
||||
return str_len;
|
||||
}
|
||||
|
||||
@@ -362,12 +362,12 @@ static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
* @param value: int value
|
||||
* @param pbus: unicode buffer
|
||||
* @param len: length
|
||||
* @retval none
|
||||
* @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 )
|
||||
@@ -376,11 +376,11 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
}
|
||||
|
||||
|
||||
value = value << 4;
|
||||
|
||||
|
||||
pbuf[2 * idx + 1] = 0;
|
||||
}
|
||||
}
|
||||
@@ -388,18 +388,18 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
/**
|
||||
* @brief usb get serial number
|
||||
* @param none
|
||||
* @retval 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);
|
||||
@@ -410,7 +410,7 @@ static void get_serial_num(void)
|
||||
/**
|
||||
* @brief get device descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_descriptor(void)
|
||||
{
|
||||
@@ -420,7 +420,7 @@ static usbd_desc_t *get_device_descriptor(void)
|
||||
/**
|
||||
* @brief get device qualifier
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t * get_device_qualifier(void)
|
||||
{
|
||||
@@ -430,7 +430,7 @@ static usbd_desc_t * get_device_qualifier(void)
|
||||
/**
|
||||
* @brief get config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_configuration(void)
|
||||
{
|
||||
@@ -440,7 +440,7 @@ static usbd_desc_t *get_device_configuration(void)
|
||||
/**
|
||||
* @brief get other speed descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_other_speed(void)
|
||||
{
|
||||
@@ -450,7 +450,7 @@ static usbd_desc_t *get_device_other_speed(void)
|
||||
/**
|
||||
* @brief get lang id descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_lang_id(void)
|
||||
{
|
||||
@@ -461,7 +461,7 @@ static usbd_desc_t *get_device_lang_id(void)
|
||||
/**
|
||||
* @brief get manufacturer descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
{
|
||||
@@ -473,7 +473,7 @@ static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
/**
|
||||
* @brief get product descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_product_string(void)
|
||||
{
|
||||
@@ -485,7 +485,7 @@ static usbd_desc_t *get_device_product_string(void)
|
||||
/**
|
||||
* @brief get serial descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_serial_string(void)
|
||||
{
|
||||
@@ -496,7 +496,7 @@ static usbd_desc_t *get_device_serial_string(void)
|
||||
/**
|
||||
* @brief get interface descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_interface_string(void)
|
||||
{
|
||||
@@ -508,7 +508,7 @@ static usbd_desc_t *get_device_interface_string(void)
|
||||
/**
|
||||
* @brief get device config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_config_string(void)
|
||||
{
|
||||
@@ -519,7 +519,7 @@ static usbd_desc_t *get_device_config_string(void)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file custom_hid_desc.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb custom hid 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
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __CUSTOM_HID_DESC_H
|
||||
#define __CUSTOM_HID_DESC_H
|
||||
@@ -31,23 +31,23 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "custom_hid_class.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_custom_hid_desc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_custom_hid_desc_definition
|
||||
/** @defgroup USB_custom_hid_desc_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief usb bcd number define
|
||||
*/
|
||||
@@ -57,7 +57,7 @@ extern "C" {
|
||||
* @brief usb vendor id and product id define
|
||||
*/
|
||||
#define USBD_CUSHID_VENDOR_ID 0x2E3C
|
||||
#define USBD_CUSHID_PRODUCT_ID 0x5745
|
||||
#define USBD_CUSHID_PRODUCT_ID 0x5745
|
||||
|
||||
/**
|
||||
* @brief usb descriptor size define
|
||||
@@ -78,10 +78,10 @@ extern "C" {
|
||||
#define CUSHID_BINTERVAL_TIME 0x0A
|
||||
|
||||
/**
|
||||
* @brief usb hid report id define
|
||||
* @brief usb hid report id define
|
||||
*/
|
||||
/**
|
||||
* @brief usb hid report id define
|
||||
* @brief usb hid report id define
|
||||
*/
|
||||
#define HID_REPORT_ID_1 0x01
|
||||
#define HID_REPORT_ID_2 0x02
|
||||
@@ -107,7 +107,7 @@ extern usbd_desc_handler custom_hid_desc_handler;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file hid_iap_class.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb hid iap 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
|
||||
* 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,
|
||||
@@ -30,11 +30,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_hid_iap_class
|
||||
* @brief usb device class hid iap demo
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_hid_iap_class_private_functions
|
||||
* @{
|
||||
@@ -54,7 +54,7 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event);
|
||||
iap_info_type iap_info;
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler hid_iap_class_handler =
|
||||
usbd_class_handler hid_iap_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
@@ -71,7 +71,7 @@ usbd_class_handler hid_iap_class_handler =
|
||||
/**
|
||||
* @brief initialize usb custom hid endpoint
|
||||
* @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 class_init_handler(void *udev)
|
||||
{
|
||||
@@ -80,32 +80,32 @@ static usb_sts_type class_init_handler(void *udev)
|
||||
iap_info_type *piap = (iap_info_type *)pudev->class_handler->pdata;
|
||||
/* open hid iap in endpoint */
|
||||
usbd_ept_open(pudev, USBD_HIDIAP_IN_EPT, EPT_INT_TYPE, USBD_HIDIAP_IN_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* open hid iap out endpoint */
|
||||
usbd_ept_open(pudev, USBD_HIDIAP_OUT_EPT, EPT_INT_TYPE, USBD_HIDIAP_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_HIDIAP_OUT_EPT, piap->g_rxhid_buff, USBD_HIDIAP_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
|
||||
* @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 hid iap in endpoint */
|
||||
usbd_ept_close(pudev, USBD_HIDIAP_IN_EPT);
|
||||
|
||||
|
||||
/* close hid iap out endpoint */
|
||||
usbd_ept_close(pudev, USBD_HIDIAP_OUT_EPT);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ static usb_sts_type class_clear_handler(void *udev)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -187,21 +187,21 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
/**
|
||||
* @brief usb device endpoint 0 in status stage complete
|
||||
* @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 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: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
{
|
||||
@@ -215,7 +215,7 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
/* hid buffer process */
|
||||
piap->hid_state = 0;
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -223,17 +223,17 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
usbd_hid_iap_in_complete(udev);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -241,37 +241,37 @@ static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
* @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
|
||||
* @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;
|
||||
iap_info_type *piap = (iap_info_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
/* get endpoint receive data length */
|
||||
uint32_t recv_len = usbd_get_recv_len(pudev, ept_num);
|
||||
|
||||
|
||||
/* hid iap process */
|
||||
usbd_hid_iap_process(udev, piap->g_rxhid_buff, recv_len);
|
||||
|
||||
|
||||
/* start receive next packet */
|
||||
usbd_ept_recv(pudev, USBD_HIDIAP_OUT_EPT, piap->g_rxhid_buff, USBD_HIDIAP_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device sof handler
|
||||
* @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 class_sof_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ static usb_sts_type class_sof_handler(void *udev)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
{
|
||||
@@ -287,18 +287,18 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_WAKEUP_EVENT:
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -311,7 +311,7 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param report: report buffer
|
||||
* @param len: report length
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type usb_iap_class_send_report(void *udev, uint8_t *report, uint16_t len)
|
||||
{
|
||||
@@ -320,13 +320,13 @@ usb_sts_type usb_iap_class_send_report(void *udev, uint8_t *report, uint16_t len
|
||||
|
||||
if(usbd_connect_state_get(pudev) == USB_CONN_STATE_CONFIGURED)
|
||||
usbd_ept_send(pudev, USBD_HIDIAP_IN_EPT, report, len);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file hid_iap_class.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb hid iap 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __HID_IAP_CLASS_H
|
||||
#define __HID_IAP_CLASS_H
|
||||
@@ -31,7 +31,7 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "usb_std.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
@@ -39,12 +39,12 @@ extern "C" {
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_hid_iap_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_hid_iap_class_definition
|
||||
/** @defgroup USB_hid_iap_class_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -103,33 +103,33 @@ typedef enum
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
|
||||
uint8_t iap_fifo[HID_IAP_BUFFER_LEN];
|
||||
uint8_t iap_rx[USBD_HIDIAP_OUT_MAXPACKET_SIZE];
|
||||
uint8_t iap_tx[USBD_HIDIAP_IN_MAXPACKET_SIZE];
|
||||
|
||||
|
||||
uint32_t fifo_length;
|
||||
uint32_t tx_length;
|
||||
|
||||
|
||||
uint32_t app_address;
|
||||
uint32_t iap_address;
|
||||
uint32_t flag_address;
|
||||
|
||||
|
||||
uint32_t flash_start_address;
|
||||
uint32_t flash_end_address;
|
||||
|
||||
|
||||
uint32_t sector_size;
|
||||
uint32_t flash_size;
|
||||
|
||||
|
||||
uint32_t respond_flag;
|
||||
|
||||
|
||||
uint8_t g_rxhid_buff[USBD_HIDIAP_OUT_MAXPACKET_SIZE];
|
||||
uint32_t hid_protocol;
|
||||
uint32_t hid_set_idle;
|
||||
uint32_t alt_setting;
|
||||
uint32_t hid_state;
|
||||
uint8_t hid_set_report[64];
|
||||
|
||||
|
||||
iap_machine_state_type state;
|
||||
}iap_info_type;
|
||||
|
||||
@@ -146,7 +146,7 @@ void usbd_hid_iap_in_complete(void *udev);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file hid_iap_desc.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb hid 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
|
||||
* 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,
|
||||
@@ -32,11 +32,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_hid_iap_desc
|
||||
* @brief usb device hid_iap descriptor
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_hid_iap_desc_private_functions
|
||||
* @{
|
||||
@@ -122,7 +122,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_HIDIAP_CONFIG_DESC_SIZE] A
|
||||
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 */
|
||||
@@ -132,7 +132,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_HIDIAP_CONFIG_DESC_SIZE] A
|
||||
0x00, /* bInterfaceSubClass: subclass code */
|
||||
0x00, /* bInterfaceProtocol: protocol code */
|
||||
0x00, /* iInterface: index of string descriptor */
|
||||
|
||||
|
||||
0x09, /* bLength: size of HID descriptor in bytes */
|
||||
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
|
||||
LBYTE(HIDIAP_BCD_NUM),
|
||||
@@ -142,7 +142,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_HIDIAP_CONFIG_DESC_SIZE] A
|
||||
HID_CLASS_DESC_REPORT, /* bDescriptorType: report descriptor type */
|
||||
LBYTE(sizeof(g_usbd_hidiap_report)),
|
||||
HBYTE(sizeof(g_usbd_hidiap_report)), /* wDescriptorLength: total length of reprot descriptor */
|
||||
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_HIDIAP_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
@@ -150,12 +150,12 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_HIDIAP_CONFIG_DESC_SIZE] A
|
||||
LBYTE(USBD_HIDIAP_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_HIDIAP_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HIDIAP_BINTERVAL_TIME, /* 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_HIDIAP_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_INTERRUPT, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_HIDIAP_OUT_MAXPACKET_SIZE),
|
||||
LBYTE(USBD_HIDIAP_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_HIDIAP_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HIDIAP_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
};
|
||||
@@ -166,27 +166,27 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_HIDIAP_CONFIG_DESC_SIZE] A
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_usbd_hidiap_report[USBD_HIDIAP_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_usbd_hidiap_report[USBD_HIDIAP_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
{
|
||||
0x06, 0xFF, 0x00, /* USAGE_PAGE(Vendor Page:0xFF00) */
|
||||
0x09, 0x01, /* USAGE (Demo Kit) */
|
||||
0xa1, 0x01, /* COLLECTION (Application) */
|
||||
|
||||
0x06, 0xFF, 0x00, /* USAGE_PAGE(Vendor Page:0xFF00) */
|
||||
0x09, 0x01, /* USAGE (Demo Kit) */
|
||||
0xa1, 0x01, /* COLLECTION (Application) */
|
||||
|
||||
/* 6 */
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0xFF, /* LOGICAL_MAXIMUM (255) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x40, /* REPORT_COUNT (64) */
|
||||
|
||||
0x09, 0x01,
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||
0x25, 0xFF, /* LOGICAL_MAXIMUM (255) */
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||
0x95, 0x40, /* REPORT_COUNT (64) */
|
||||
|
||||
0x09, 0x01,
|
||||
0x81, 0x02,
|
||||
0x95, 0x40,
|
||||
|
||||
0x09, 0x01,
|
||||
|
||||
0x09, 0x01,
|
||||
0x91, 0x02,
|
||||
0x95, 0x01,
|
||||
|
||||
0x09, 0x01,
|
||||
0x09, 0x01,
|
||||
0xB1, 0x02,
|
||||
0xC0
|
||||
};
|
||||
@@ -197,7 +197,7 @@ ALIGNED_HEAD uint8_t g_usbd_hidiap_report[USBD_HIDIAP_SIZ_REPORT_DESC] ALIGNED_T
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_hidiap_usb_desc[9] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_hidiap_usb_desc[9] ALIGNED_TAIL =
|
||||
{
|
||||
0x09, /* bLength: size of HID descriptor in bytes */
|
||||
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
|
||||
@@ -272,24 +272,24 @@ static usbd_desc_t vp_desc;
|
||||
* @brief standard usb unicode convert
|
||||
* @param string: source string
|
||||
* @param unicode_buf: unicode buffer
|
||||
* @retval length
|
||||
* @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] = str_len;
|
||||
unicode_buf[1] = USB_DESCIPTOR_TYPE_STRING;
|
||||
|
||||
|
||||
return str_len;
|
||||
}
|
||||
|
||||
@@ -298,12 +298,12 @@ static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
* @param value: int value
|
||||
* @param pbus: unicode buffer
|
||||
* @param len: length
|
||||
* @retval none
|
||||
* @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 )
|
||||
@@ -312,11 +312,11 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
}
|
||||
|
||||
|
||||
value = value << 4;
|
||||
|
||||
|
||||
pbuf[2 * idx + 1] = 0;
|
||||
}
|
||||
}
|
||||
@@ -324,18 +324,18 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
/**
|
||||
* @brief usb get serial number
|
||||
* @param none
|
||||
* @retval 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);
|
||||
@@ -346,7 +346,7 @@ static void get_serial_num(void)
|
||||
/**
|
||||
* @brief get device descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_descriptor(void)
|
||||
{
|
||||
@@ -356,7 +356,7 @@ static usbd_desc_t *get_device_descriptor(void)
|
||||
/**
|
||||
* @brief get device qualifier
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t * get_device_qualifier(void)
|
||||
{
|
||||
@@ -366,7 +366,7 @@ static usbd_desc_t * get_device_qualifier(void)
|
||||
/**
|
||||
* @brief get config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_configuration(void)
|
||||
{
|
||||
@@ -376,7 +376,7 @@ static usbd_desc_t *get_device_configuration(void)
|
||||
/**
|
||||
* @brief get other speed descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_other_speed(void)
|
||||
{
|
||||
@@ -386,7 +386,7 @@ static usbd_desc_t *get_device_other_speed(void)
|
||||
/**
|
||||
* @brief get lang id descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_lang_id(void)
|
||||
{
|
||||
@@ -397,7 +397,7 @@ static usbd_desc_t *get_device_lang_id(void)
|
||||
/**
|
||||
* @brief get manufacturer descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
{
|
||||
@@ -409,7 +409,7 @@ static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
/**
|
||||
* @brief get product descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_product_string(void)
|
||||
{
|
||||
@@ -421,7 +421,7 @@ static usbd_desc_t *get_device_product_string(void)
|
||||
/**
|
||||
* @brief get serial descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_serial_string(void)
|
||||
{
|
||||
@@ -432,7 +432,7 @@ static usbd_desc_t *get_device_serial_string(void)
|
||||
/**
|
||||
* @brief get interface descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_interface_string(void)
|
||||
{
|
||||
@@ -444,7 +444,7 @@ static usbd_desc_t *get_device_interface_string(void)
|
||||
/**
|
||||
* @brief get device config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_config_string(void)
|
||||
{
|
||||
@@ -455,7 +455,7 @@ static usbd_desc_t *get_device_config_string(void)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file hid_iap_desc.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb hid 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
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __HID_IAP_DESC_H
|
||||
#define __HID_IAP_DESC_H
|
||||
@@ -31,19 +31,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "hid_iap_class.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_hid_iap_desc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_hid_iap_desc_definition
|
||||
/** @defgroup USB_hid_iap_desc_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -51,7 +51,7 @@ extern "C" {
|
||||
#define HIDIAP_BCD_NUM 0x0110
|
||||
|
||||
#define USBD_HIDIAP_VENDOR_ID 0x2E3C
|
||||
#define USBD_HIDIAP_PRODUCT_ID 0xAF01
|
||||
#define USBD_HIDIAP_PRODUCT_ID 0xAF01
|
||||
|
||||
#define USBD_HIDIAP_CONFIG_DESC_SIZE 41
|
||||
#define USBD_HIDIAP_SIZ_REPORT_DESC 32
|
||||
@@ -77,12 +77,12 @@ extern usbd_desc_handler hid_iap_desc_handler;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file keyboard_class.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb hid keyboard 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
|
||||
* 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,
|
||||
@@ -30,11 +30,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_keyboard_class
|
||||
* @brief usb device keyboard demo
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_keyboard_class_private_functions
|
||||
* @{
|
||||
@@ -65,7 +65,7 @@ const static unsigned char _asciimap[128] =
|
||||
0x2A,// BS Backspace
|
||||
0x2B,// TAB Tab
|
||||
0x28,// LF Enter
|
||||
0x00,// VT
|
||||
0x00,// VT
|
||||
0x00,// FF
|
||||
0x00,// CR
|
||||
0x00,// SO
|
||||
@@ -186,7 +186,7 @@ const static unsigned char _asciimap[128] =
|
||||
};
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler keyboard_class_handler =
|
||||
usbd_class_handler keyboard_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
@@ -203,7 +203,7 @@ usbd_class_handler keyboard_class_handler =
|
||||
/**
|
||||
* @brief initialize usb endpoint
|
||||
* @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 class_init_handler(void *udev)
|
||||
{
|
||||
@@ -214,28 +214,28 @@ static usb_sts_type class_init_handler(void *udev)
|
||||
/* use user define buffer address */
|
||||
usbd_ept_buf_custom_define(pudev, USBD_KEYBOARD_IN_EPT, EPT1_TX_ADDR);
|
||||
#endif
|
||||
|
||||
|
||||
/* open hid in endpoint */
|
||||
usbd_ept_open(pudev, USBD_KEYBOARD_IN_EPT, EPT_INT_TYPE, USBD_KEYBOARD_IN_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
pkeyboard->g_u8tx_completed = 1;
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief clear endpoint or other state
|
||||
* @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 class_clear_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
|
||||
|
||||
/* close hid in endpoint */
|
||||
usbd_ept_close(pudev, USBD_KEYBOARD_IN_EPT);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ static usb_sts_type class_clear_handler(void *udev)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -317,21 +317,21 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
/**
|
||||
* @brief usb device class endpoint 0 in status stage complete
|
||||
* @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 class_ept0_tx_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class endpoint 0 out status stage complete
|
||||
* @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 class_ept0_rx_handler(void *udev)
|
||||
{
|
||||
@@ -345,7 +345,7 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
/* hid buffer process */
|
||||
pkeyboard->hid_state = 0;
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -353,19 +353,19 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
* @brief usb device class transmision complete handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
keyboard_type *pkeyboard = (keyboard_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
pkeyboard->g_u8tx_completed = 1;
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -373,26 +373,26 @@ static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
* @brief usb device class endpoint receive data
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @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;
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class sof handler
|
||||
* @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 class_sof_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ static usb_sts_type class_sof_handler(void *udev)
|
||||
* @brief usb device class event handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param event: usb device event
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
{
|
||||
@@ -410,18 +410,18 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
pkeyboard->hid_suspend_flag = 1;
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_WAKEUP_EVENT:
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -434,7 +434,7 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param report: report buffer
|
||||
* @param len: report length
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type usb_keyboard_class_send_report(void *udev, uint8_t *report, uint16_t len)
|
||||
{
|
||||
@@ -443,7 +443,7 @@ usb_sts_type usb_keyboard_class_send_report(void *udev, uint8_t *report, uint16_
|
||||
|
||||
if(usbd_connect_state_get(pudev) == USB_CONN_STATE_CONFIGURED)
|
||||
usbd_ept_send(pudev, USBD_KEYBOARD_IN_EPT, report, len);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -452,14 +452,14 @@ usb_sts_type usb_keyboard_class_send_report(void *udev, uint8_t *report, uint16_
|
||||
* @brief usb device class report function
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param op: operation
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void usb_hid_keyboard_send_char(void *udev, uint8_t ascii_code)
|
||||
{
|
||||
uint8_t key_data = 0;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
keyboard_type *pkeyboard = (keyboard_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
if(ascii_code > 128)
|
||||
{
|
||||
ascii_code = 0;
|
||||
@@ -471,14 +471,14 @@ void usb_hid_keyboard_send_char(void *udev, uint8_t ascii_code)
|
||||
{
|
||||
ascii_code = 0;
|
||||
}
|
||||
|
||||
|
||||
if(ascii_code & SHIFT)
|
||||
{
|
||||
key_data = 0x2;
|
||||
ascii_code &= 0x7F;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if((pkeyboard->temp == ascii_code) && (ascii_code != 0))
|
||||
{
|
||||
pkeyboard->keyboard_buf[0] = 0;
|
||||
@@ -496,7 +496,7 @@ void usb_hid_keyboard_send_char(void *udev, uint8_t ascii_code)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file keyboard_class.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb hid keyboard 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __KEYBOARD_CLASS_H
|
||||
#define __KEYBOARD_CLASS_H
|
||||
@@ -31,19 +31,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "usb_std.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_keyboard_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_keyboard_class_endpoint_definition
|
||||
/** @defgroup USB_keyboard_class_endpoint_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -70,12 +70,12 @@ typedef struct
|
||||
uint32_t alt_setting;
|
||||
uint8_t hid_set_report[64];
|
||||
uint8_t keyboard_buf[8];
|
||||
|
||||
|
||||
__IO uint8_t hid_suspend_flag;
|
||||
__IO uint8_t g_u8tx_completed;
|
||||
uint8_t hid_state;
|
||||
uint8_t temp;
|
||||
|
||||
|
||||
}keyboard_type;
|
||||
|
||||
/** @defgroup USB_hid_class_exported_functions
|
||||
@@ -92,7 +92,7 @@ void usb_hid_keyboard_send_char(void *udev, uint8_t ascii_code);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file keyboard_desc.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb hid keyboard 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
|
||||
* 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,
|
||||
@@ -31,11 +31,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_keyboard_desc
|
||||
* @brief usb device keyboard descriptor
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_keyboard_desc_private_functions
|
||||
* @{
|
||||
@@ -120,7 +120,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_KEYBOARD_CONFIG_DESC_SIZE]
|
||||
the configuration */
|
||||
0xE0, /* bmAttributes: self powered and support remote wakeup*/
|
||||
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 */
|
||||
@@ -130,7 +130,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_KEYBOARD_CONFIG_DESC_SIZE]
|
||||
0x01, /* bInterfaceSubClass: subclass code */
|
||||
0x01, /* bInterfaceProtocol: protocol code */
|
||||
0x00, /* iInterface: index of string descriptor */
|
||||
|
||||
|
||||
0x09, /* bLength: size of HID descriptor in bytes */
|
||||
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
|
||||
LBYTE(KEYBOARD_BCD_NUM),
|
||||
@@ -140,7 +140,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_KEYBOARD_CONFIG_DESC_SIZE]
|
||||
HID_CLASS_DESC_REPORT, /* bDescriptorType: report descriptor type */
|
||||
LBYTE(sizeof(g_usbd_keyboard_report)),
|
||||
HBYTE(sizeof(g_usbd_keyboard_report)), /* wDescriptorLength: total length of reprot descriptor */
|
||||
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_KEYBOARD_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
@@ -156,7 +156,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_KEYBOARD_CONFIG_DESC_SIZE]
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_usbd_keyboard_report[USBD_KEYBOARD_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_usbd_keyboard_report[USBD_KEYBOARD_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
{
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
0x09, 0x06, // USAGE (Keyboard)
|
||||
@@ -189,7 +189,7 @@ ALIGNED_HEAD uint8_t g_usbd_keyboard_report[USBD_KEYBOARD_SIZ_REPORT_DESC] ALIGN
|
||||
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
|
||||
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
|
||||
0x81, 0x00, // INPUT (Data,Ary,Abs)
|
||||
0xc0 // END_COLLECTION
|
||||
0xc0 // END_COLLECTION
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -198,7 +198,7 @@ ALIGNED_HEAD uint8_t g_usbd_keyboard_report[USBD_KEYBOARD_SIZ_REPORT_DESC] ALIGN
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_keyboard_usb_desc[9] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_keyboard_usb_desc[9] ALIGNED_TAIL =
|
||||
{
|
||||
0x09, /* bLength: size of HID descriptor in bytes */
|
||||
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
|
||||
@@ -273,24 +273,24 @@ static usbd_desc_t vp_desc;
|
||||
* @brief standard usb unicode convert
|
||||
* @param string: source string
|
||||
* @param unicode_buf: unicode buffer
|
||||
* @retval length
|
||||
* @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] = str_len;
|
||||
unicode_buf[1] = USB_DESCIPTOR_TYPE_STRING;
|
||||
|
||||
|
||||
return str_len;
|
||||
}
|
||||
|
||||
@@ -299,12 +299,12 @@ static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
* @param value: int value
|
||||
* @param pbus: unicode buffer
|
||||
* @param len: length
|
||||
* @retval none
|
||||
* @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 )
|
||||
@@ -313,11 +313,11 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
}
|
||||
|
||||
|
||||
value = value << 4;
|
||||
|
||||
|
||||
pbuf[2 * idx + 1] = 0;
|
||||
}
|
||||
}
|
||||
@@ -325,18 +325,18 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
/**
|
||||
* @brief usb get serial number
|
||||
* @param none
|
||||
* @retval 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);
|
||||
@@ -347,7 +347,7 @@ static void get_serial_num(void)
|
||||
/**
|
||||
* @brief get device descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_descriptor(void)
|
||||
{
|
||||
@@ -357,7 +357,7 @@ static usbd_desc_t *get_device_descriptor(void)
|
||||
/**
|
||||
* @brief get device qualifier
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t * get_device_qualifier(void)
|
||||
{
|
||||
@@ -367,7 +367,7 @@ static usbd_desc_t * get_device_qualifier(void)
|
||||
/**
|
||||
* @brief get config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_configuration(void)
|
||||
{
|
||||
@@ -377,7 +377,7 @@ static usbd_desc_t *get_device_configuration(void)
|
||||
/**
|
||||
* @brief get other speed descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_other_speed(void)
|
||||
{
|
||||
@@ -387,7 +387,7 @@ static usbd_desc_t *get_device_other_speed(void)
|
||||
/**
|
||||
* @brief get lang id descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_lang_id(void)
|
||||
{
|
||||
@@ -398,7 +398,7 @@ static usbd_desc_t *get_device_lang_id(void)
|
||||
/**
|
||||
* @brief get manufacturer descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
{
|
||||
@@ -410,7 +410,7 @@ static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
/**
|
||||
* @brief get product descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_product_string(void)
|
||||
{
|
||||
@@ -422,7 +422,7 @@ static usbd_desc_t *get_device_product_string(void)
|
||||
/**
|
||||
* @brief get serial descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_serial_string(void)
|
||||
{
|
||||
@@ -433,7 +433,7 @@ static usbd_desc_t *get_device_serial_string(void)
|
||||
/**
|
||||
* @brief get interface descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_interface_string(void)
|
||||
{
|
||||
@@ -445,7 +445,7 @@ static usbd_desc_t *get_device_interface_string(void)
|
||||
/**
|
||||
* @brief get device config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_config_string(void)
|
||||
{
|
||||
@@ -456,7 +456,7 @@ static usbd_desc_t *get_device_config_string(void)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file keyboard_desc.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb keyboard 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
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __KEYBOARD_DESC_H
|
||||
#define __KEYBOARD_DESC_H
|
||||
@@ -31,19 +31,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "keyboard_class.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_keyboard_desc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_keyboard_desc_definition
|
||||
/** @defgroup USB_keyboard_desc_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -56,7 +56,7 @@ extern "C" {
|
||||
* @brief usb vendor id and product id define
|
||||
*/
|
||||
#define USBD_KEYBOARD_VENDOR_ID 0x2E3C
|
||||
#define USBD_KEYBOARD_PRODUCT_ID 0x6040
|
||||
#define USBD_KEYBOARD_PRODUCT_ID 0x6040
|
||||
|
||||
/**
|
||||
* @brief usb descriptor size define
|
||||
@@ -75,7 +75,7 @@ extern "C" {
|
||||
#define USBD_KEYBOARD_DESC_INTERFACE_STRING "Keyboard Interface"
|
||||
|
||||
/**
|
||||
* @brief usb hid endpoint interval define
|
||||
* @brief usb hid endpoint interval define
|
||||
*/
|
||||
#define KEYBOARD_BINTERVAL_TIME 0x0A
|
||||
|
||||
@@ -96,7 +96,7 @@ extern usbd_desc_handler keyboard_desc_handler;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file mouse_class.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb hid mouse 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
|
||||
* 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,
|
||||
@@ -30,11 +30,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_mouse_class
|
||||
* @brief usb device mouse demo
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_mouse_class_private_functions
|
||||
* @{
|
||||
@@ -53,7 +53,7 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event);
|
||||
mouse_type mouse_struct;
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler mouse_class_handler =
|
||||
usbd_class_handler mouse_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
@@ -70,37 +70,37 @@ usbd_class_handler mouse_class_handler =
|
||||
/**
|
||||
* @brief initialize usb endpoint
|
||||
* @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 class_init_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
|
||||
|
||||
#ifndef USB_EPT_AUTO_MALLOC_BUFFER
|
||||
/* use user define buffer address */
|
||||
usbd_ept_buf_custom_define(pudev, USBD_MOUSE_IN_EPT, EPT1_TX_ADDR);
|
||||
#endif
|
||||
|
||||
|
||||
/* open hid in endpoint */
|
||||
usbd_ept_open(pudev, USBD_MOUSE_IN_EPT, EPT_INT_TYPE, USBD_MOUSE_IN_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
|
||||
* @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 hid in endpoint */
|
||||
usbd_ept_close(pudev, USBD_MOUSE_IN_EPT);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ static usb_sts_type class_clear_handler(void *udev)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -183,21 +183,21 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
/**
|
||||
* @brief usb device class endpoint 0 in status stage complete
|
||||
* @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 class_ept0_tx_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class endpoint 0 out status stage complete
|
||||
* @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 class_ept0_rx_handler(void *udev)
|
||||
{
|
||||
@@ -211,7 +211,7 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
/* hid buffer process */
|
||||
pmouse->hid_state = 0;
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -219,16 +219,16 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
* @brief usb device class transmision complete handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -236,26 +236,26 @@ static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
* @brief usb device class endpoint receive data
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @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;
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class sof handler
|
||||
* @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 class_sof_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ static usb_sts_type class_sof_handler(void *udev)
|
||||
* @brief usb device class event handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param event: usb device event
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
{
|
||||
@@ -273,18 +273,18 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
pmouse->hid_suspend_flag = 1;
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_WAKEUP_EVENT:
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -297,7 +297,7 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param report: report buffer
|
||||
* @param len: report length
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type usb_mouse_class_send_report(void *udev, uint8_t *report, uint16_t len)
|
||||
{
|
||||
@@ -306,7 +306,7 @@ usb_sts_type usb_mouse_class_send_report(void *udev, uint8_t *report, uint16_t l
|
||||
|
||||
if(usbd_connect_state_get(pudev) == USB_CONN_STATE_CONFIGURED)
|
||||
usbd_ept_send(pudev, USBD_MOUSE_IN_EPT, report, len);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ usb_sts_type usb_mouse_class_send_report(void *udev, uint8_t *report, uint16_t l
|
||||
* @brief usb device class report function
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param op: operation
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void usb_hid_mouse_send(void *udev, uint8_t op)
|
||||
{
|
||||
@@ -326,40 +326,40 @@ void usb_hid_mouse_send(void *udev, uint8_t op)
|
||||
case LEFT_BUTTON:
|
||||
button = 0x01;
|
||||
break;
|
||||
|
||||
|
||||
case RIGHT_BUTTON:
|
||||
button = 0x2;
|
||||
break;
|
||||
|
||||
|
||||
case UP_MOVE:
|
||||
posy -= MOVE_STEP;
|
||||
break;
|
||||
|
||||
|
||||
case DOWN_MOVE:
|
||||
posy += MOVE_STEP;
|
||||
break;
|
||||
|
||||
|
||||
case LEFT_MOVE:
|
||||
posx -= MOVE_STEP;
|
||||
posx -= MOVE_STEP;
|
||||
break;
|
||||
|
||||
|
||||
case RIGHT_MOVE:
|
||||
posx += MOVE_STEP;
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
pmouse->mouse_buffer[0] = button;
|
||||
pmouse->mouse_buffer[1] = posx;
|
||||
pmouse->mouse_buffer[2] = posy;
|
||||
|
||||
|
||||
usb_mouse_class_send_report(udev, pmouse->mouse_buffer, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file mouse_class.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb hid mouse 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MOUSE_CLASS_H
|
||||
#define __MOUSE_CLASS_H
|
||||
@@ -31,19 +31,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "usb_std.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_mouse_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_mouse_class_endpoint_definition
|
||||
/** @defgroup USB_mouse_class_endpoint_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -61,10 +61,10 @@ extern "C" {
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_mouse_class_request_code_definition
|
||||
/** @defgroup USB_mouse_class_request_code_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief usb hid mouse operation
|
||||
@@ -84,7 +84,7 @@ typedef struct
|
||||
uint32_t hid_protocol;
|
||||
uint32_t hid_set_idle;
|
||||
uint32_t alt_setting;
|
||||
|
||||
|
||||
uint8_t hid_set_report[64];
|
||||
uint8_t mouse_buffer[4];
|
||||
uint8_t hid_state;
|
||||
@@ -104,11 +104,11 @@ void usb_hid_mouse_send(void *udev, uint8_t op);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file mouse_desc.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb hid mouse 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
|
||||
* 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,
|
||||
@@ -31,11 +31,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_mouse_desc
|
||||
* @brief usb device mouse descriptor
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_mouse_desc_private_functions
|
||||
* @{
|
||||
@@ -120,7 +120,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_MOUSE_CONFIG_DESC_SIZE] AL
|
||||
the configuration */
|
||||
0xE0, /* bmAttributes: self powered and support remote wakeup*/
|
||||
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 */
|
||||
@@ -130,7 +130,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_MOUSE_CONFIG_DESC_SIZE] AL
|
||||
0x01, /* bInterfaceSubClass: subclass code */
|
||||
0x02, /* bInterfaceProtocol: protocol code */
|
||||
0x00, /* iInterface: index of string descriptor */
|
||||
|
||||
|
||||
0x09, /* bLength: size of HID descriptor in bytes */
|
||||
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
|
||||
LBYTE(MOUSE_BCD_NUM),
|
||||
@@ -140,7 +140,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_MOUSE_CONFIG_DESC_SIZE] AL
|
||||
HID_CLASS_DESC_REPORT, /* bDescriptorType: report descriptor type */
|
||||
LBYTE(sizeof(g_usbd_mouse_report)),
|
||||
HBYTE(sizeof(g_usbd_mouse_report)), /* wDescriptorLength: total length of reprot descriptor */
|
||||
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_MOUSE_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
@@ -156,7 +156,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_MOUSE_CONFIG_DESC_SIZE] AL
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_usbd_mouse_report[USBD_MOUSE_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_usbd_mouse_report[USBD_MOUSE_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
{
|
||||
0x05,0x01,
|
||||
0x09,0x02,
|
||||
@@ -212,7 +212,7 @@ ALIGNED_HEAD uint8_t g_usbd_mouse_report[USBD_MOUSE_SIZ_REPORT_DESC] ALIGNED_TAI
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_mouse_usb_desc[9] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_mouse_usb_desc[9] ALIGNED_TAIL =
|
||||
{
|
||||
0x09, /* bLength: size of HID descriptor in bytes */
|
||||
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
|
||||
@@ -287,24 +287,24 @@ static usbd_desc_t vp_desc;
|
||||
* @brief standard usb unicode convert
|
||||
* @param string: source string
|
||||
* @param unicode_buf: unicode buffer
|
||||
* @retval length
|
||||
* @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] = str_len;
|
||||
unicode_buf[1] = USB_DESCIPTOR_TYPE_STRING;
|
||||
|
||||
|
||||
return str_len;
|
||||
}
|
||||
|
||||
@@ -313,12 +313,12 @@ static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
* @param value: int value
|
||||
* @param pbus: unicode buffer
|
||||
* @param len: length
|
||||
* @retval none
|
||||
* @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 )
|
||||
@@ -327,11 +327,11 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
}
|
||||
|
||||
|
||||
value = value << 4;
|
||||
|
||||
|
||||
pbuf[2 * idx + 1] = 0;
|
||||
}
|
||||
}
|
||||
@@ -339,18 +339,18 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
/**
|
||||
* @brief usb get serial number
|
||||
* @param none
|
||||
* @retval 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);
|
||||
@@ -361,7 +361,7 @@ static void get_serial_num(void)
|
||||
/**
|
||||
* @brief get device descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_descriptor(void)
|
||||
{
|
||||
@@ -371,7 +371,7 @@ static usbd_desc_t *get_device_descriptor(void)
|
||||
/**
|
||||
* @brief get device qualifier
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t * get_device_qualifier(void)
|
||||
{
|
||||
@@ -381,7 +381,7 @@ static usbd_desc_t * get_device_qualifier(void)
|
||||
/**
|
||||
* @brief get config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_configuration(void)
|
||||
{
|
||||
@@ -391,7 +391,7 @@ static usbd_desc_t *get_device_configuration(void)
|
||||
/**
|
||||
* @brief get other speed descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_other_speed(void)
|
||||
{
|
||||
@@ -401,7 +401,7 @@ static usbd_desc_t *get_device_other_speed(void)
|
||||
/**
|
||||
* @brief get lang id descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_lang_id(void)
|
||||
{
|
||||
@@ -412,7 +412,7 @@ static usbd_desc_t *get_device_lang_id(void)
|
||||
/**
|
||||
* @brief get manufacturer descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
{
|
||||
@@ -424,7 +424,7 @@ static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
/**
|
||||
* @brief get product descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_product_string(void)
|
||||
{
|
||||
@@ -436,7 +436,7 @@ static usbd_desc_t *get_device_product_string(void)
|
||||
/**
|
||||
* @brief get serial descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_serial_string(void)
|
||||
{
|
||||
@@ -447,7 +447,7 @@ static usbd_desc_t *get_device_serial_string(void)
|
||||
/**
|
||||
* @brief get interface descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_interface_string(void)
|
||||
{
|
||||
@@ -459,7 +459,7 @@ static usbd_desc_t *get_device_interface_string(void)
|
||||
/**
|
||||
* @brief get device config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_config_string(void)
|
||||
{
|
||||
@@ -470,7 +470,7 @@ static usbd_desc_t *get_device_config_string(void)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file mouse_desc.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb mouse 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
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MOUSE_DESC_H
|
||||
#define __MOUSE_DESC_H
|
||||
@@ -31,19 +31,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "mouse_class.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_mouse_desc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_mouse_desc_definition
|
||||
/** @defgroup USB_mouse_desc_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -56,7 +56,7 @@ extern "C" {
|
||||
* @brief usb vendor id and product id define
|
||||
*/
|
||||
#define USBD_MOUSE_VENDOR_ID 0x2E3C
|
||||
#define USBD_MOUSE_PRODUCT_ID 0x5710
|
||||
#define USBD_MOUSE_PRODUCT_ID 0x5710
|
||||
|
||||
/**
|
||||
* @brief usb descriptor size define
|
||||
@@ -75,7 +75,7 @@ extern "C" {
|
||||
#define USBD_MOUSE_DESC_INTERFACE_STRING "Mouse Interface"
|
||||
|
||||
/**
|
||||
* @brief usb hid endpoint interval define
|
||||
* @brief usb hid endpoint interval define
|
||||
*/
|
||||
#define MOUSE_BINTERVAL_TIME 0x0A
|
||||
|
||||
@@ -96,7 +96,7 @@ extern usbd_desc_handler mouse_desc_handler;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_bot_scsi.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb mass storage bulk-only transport and scsi command
|
||||
**************************************************************************
|
||||
* 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,
|
||||
@@ -33,7 +33,7 @@
|
||||
/** @defgroup USB_msc_bot_scsi
|
||||
* @brief usb device class mass storage demo
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_msc_bot_functions
|
||||
* @{
|
||||
@@ -44,11 +44,11 @@
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t page00_inquiry_data[] ALIGNED_TAIL = {
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
|
||||
};
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
@@ -70,7 +70,7 @@ ALIGNED_HEAD sense_type sense_data ALIGNED_TAIL =
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t mode_sense6_data[8] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t mode_sense6_data[8] ALIGNED_TAIL =
|
||||
{
|
||||
0x00,
|
||||
0x00,
|
||||
@@ -85,7 +85,7 @@ ALIGNED_HEAD uint8_t mode_sense6_data[8] ALIGNED_TAIL =
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t mode_sense10_data[8] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t mode_sense10_data[8] ALIGNED_TAIL =
|
||||
{
|
||||
0x00,
|
||||
0x06,
|
||||
@@ -99,7 +99,7 @@ ALIGNED_HEAD uint8_t mode_sense10_data[8] ALIGNED_TAIL =
|
||||
/**
|
||||
* @brief initialize bulk-only transport and scsi
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_init(void *udev)
|
||||
{
|
||||
@@ -108,13 +108,13 @@ void bot_scsi_init(void *udev)
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_IDLE;
|
||||
pmsc->bot_status = MSC_BOT_STATE_IDLE;
|
||||
pmsc->max_lun = MSC_SUPPORT_MAX_LUN - 1;
|
||||
|
||||
|
||||
pmsc->csw_struct.dCSWSignature = CSW_DCSWSIGNATURE;
|
||||
pmsc->csw_struct.dCSWDataResidue = 0;
|
||||
pmsc->csw_struct.dCSWSignature = 0;
|
||||
pmsc->csw_struct.dCSWTag = CSW_BCSWSTATUS_PASS;
|
||||
|
||||
|
||||
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
|
||||
}
|
||||
@@ -122,7 +122,7 @@ void bot_scsi_init(void *udev)
|
||||
/**
|
||||
* @brief reset bulk-only transport and scsi
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_reset(void *udev)
|
||||
{
|
||||
@@ -131,7 +131,7 @@ void bot_scsi_reset(void *udev)
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_IDLE;
|
||||
pmsc->bot_status = MSC_BOT_STATE_RECOVERY;
|
||||
pmsc->max_lun = MSC_SUPPORT_MAX_LUN - 1;
|
||||
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
|
||||
}
|
||||
@@ -140,7 +140,7 @@ void bot_scsi_reset(void *udev)
|
||||
* @brief bulk-only transport data in handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_datain_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
@@ -154,12 +154,12 @@ void bot_scsi_datain_handler(void *udev, uint8_t ept_num)
|
||||
bot_scsi_send_csw(udev, CSW_BCSWSTATUS_FAILED);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case MSC_STATE_MACHINE_LAST_DATA:
|
||||
case MSC_STATE_MACHINE_SEND_DATA:
|
||||
bot_scsi_send_csw(udev, CSW_BCSWSTATUS_PASS);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -169,7 +169,7 @@ void bot_scsi_datain_handler(void *udev, uint8_t ept_num)
|
||||
* @brief bulk-only transport data out handler
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_dataout_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
@@ -180,7 +180,7 @@ void bot_scsi_dataout_handler(void *udev, uint8_t ept_num)
|
||||
case MSC_STATE_MACHINE_IDLE:
|
||||
bot_cbw_decode(udev);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_STATE_MACHINE_DATA_OUT:
|
||||
if(bot_scsi_cmd_process(udev) != USB_OK)
|
||||
{
|
||||
@@ -193,16 +193,16 @@ void bot_scsi_dataout_handler(void *udev, uint8_t ept_num)
|
||||
/**
|
||||
* @brief bulk-only cbw decode
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_cbw_decode(void *udev)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
pmsc->csw_struct.dCSWTag = pmsc->cbw_struct.dCBWTage;
|
||||
pmsc->csw_struct.dCSWDataResidue = pmsc->cbw_struct.dCBWDataTransferLength;
|
||||
|
||||
|
||||
/* check param */
|
||||
if((pmsc->cbw_struct.dCBWSignature != CBW_DCBWSIGNATURE) ||
|
||||
(usbd_get_recv_len(pudev, USBD_MSC_BULK_OUT_EPT) != CBW_CMD_LENGTH)
|
||||
@@ -240,20 +240,20 @@ void bot_cbw_decode(void *udev)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param buffer: data buffer
|
||||
* @param len: data len
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_send_data(void *udev, uint8_t *buffer, uint32_t len)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint32_t data_len = MIN(len, pmsc->cbw_struct.dCBWDataTransferLength);
|
||||
|
||||
|
||||
pmsc->csw_struct.dCSWDataResidue -= data_len;
|
||||
pmsc->csw_struct.bCSWStatus = CSW_BCSWSTATUS_PASS;
|
||||
|
||||
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_SEND_DATA;
|
||||
|
||||
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT,
|
||||
|
||||
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT,
|
||||
buffer, data_len);
|
||||
}
|
||||
|
||||
@@ -261,20 +261,20 @@ void bot_scsi_send_data(void *udev, uint8_t *buffer, uint32_t len)
|
||||
* @brief send command status
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param status: csw status
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_send_csw(void *udev, uint8_t status)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
pmsc->csw_struct.bCSWStatus = status;
|
||||
pmsc->csw_struct.dCSWSignature = CSW_DCSWSIGNATURE;
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_IDLE;
|
||||
|
||||
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT,
|
||||
|
||||
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT,
|
||||
(uint8_t *)&pmsc->csw_struct, CSW_CMD_LENGTH);
|
||||
|
||||
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT,
|
||||
(uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
|
||||
}
|
||||
@@ -285,7 +285,7 @@ void bot_scsi_send_csw(void *udev, uint8_t status)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param sense_key: sense key
|
||||
* @param asc: asc
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_sense_code(void *udev, uint8_t sense_key, uint8_t asc)
|
||||
{
|
||||
@@ -300,7 +300,7 @@ void bot_scsi_sense_code(void *udev, uint8_t sense_key, uint8_t asc)
|
||||
* @param lun: logical units number
|
||||
* @param blk_offset: blk offset address
|
||||
* @param blk_count: blk number
|
||||
* @retval usb_sts_type
|
||||
* @retval usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_check_address(void *udev, uint8_t lun, uint32_t blk_offset, uint32_t blk_count)
|
||||
{
|
||||
@@ -317,13 +317,13 @@ usb_sts_type bot_scsi_check_address(void *udev, uint8_t lun, uint32_t blk_offset
|
||||
/**
|
||||
* @brief bot endpoint stall
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval none
|
||||
* @retval none
|
||||
*/
|
||||
void bot_scsi_stall(void *udev)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
if((pmsc->cbw_struct.dCBWDataTransferLength != 0) &&
|
||||
(pmsc->cbw_struct.bmCBWFlags == 0) &&
|
||||
pmsc->bot_status == MSC_BOT_STATE_IDLE)
|
||||
@@ -331,10 +331,10 @@ void bot_scsi_stall(void *udev)
|
||||
usbd_set_stall(pudev, USBD_MSC_BULK_OUT_EPT);
|
||||
}
|
||||
usbd_set_stall(pudev, USBD_MSC_BULK_IN_EPT);
|
||||
|
||||
|
||||
if(pmsc->bot_status == MSC_BOT_STATE_ERROR)
|
||||
{
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT,
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT,
|
||||
(uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
|
||||
}
|
||||
}
|
||||
@@ -343,20 +343,20 @@ void bot_scsi_stall(void *udev)
|
||||
* @brief bulk-only transport scsi command test unit
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_test_unit(void *udev, uint8_t lun)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
if(pmsc->cbw_struct.dCBWDataTransferLength != 0)
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->data_len = 0;
|
||||
return status;
|
||||
}
|
||||
@@ -365,7 +365,7 @@ usb_sts_type bot_scsi_test_unit(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command inquiry
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_inquiry(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -374,7 +374,7 @@ usb_sts_type bot_scsi_inquiry(void *udev, uint8_t lun)
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
if(pmsc->cbw_struct.CBWCB[1] & 0x01)
|
||||
{
|
||||
pdata = page00_inquiry_data;
|
||||
@@ -392,7 +392,7 @@ usb_sts_type bot_scsi_inquiry(void *udev, uint8_t lun)
|
||||
trans_len = SCSI_INQUIRY_DATA_LENGTH;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pmsc->data_len = trans_len;
|
||||
while(trans_len)
|
||||
{
|
||||
@@ -406,7 +406,7 @@ usb_sts_type bot_scsi_inquiry(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command start stop
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_start_stop(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -420,7 +420,7 @@ usb_sts_type bot_scsi_start_stop(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command meidum removal
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_allow_medium_removal(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -434,7 +434,7 @@ usb_sts_type bot_scsi_allow_medium_removal(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command mode sense6
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_mode_sense6(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -454,7 +454,7 @@ usb_sts_type bot_scsi_mode_sense6(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command mode sense10
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_mode_sense10(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -474,7 +474,7 @@ usb_sts_type bot_scsi_mode_sense10(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command capacity
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_capacity(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -482,17 +482,17 @@ usb_sts_type bot_scsi_capacity(void *udev, uint8_t lun)
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *pdata = pmsc->data;
|
||||
msc_disk_capacity(lun, &pmsc->blk_nbr[lun], &pmsc->blk_size[lun]);
|
||||
|
||||
|
||||
pdata[0] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 24);
|
||||
pdata[1] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 16);
|
||||
pdata[2] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 8);
|
||||
pdata[3] = (uint8_t)((pmsc->blk_nbr[lun] - 1));
|
||||
|
||||
|
||||
pdata[4] = (uint8_t)((pmsc->blk_size[lun]) >> 24);
|
||||
pdata[5] = (uint8_t)((pmsc->blk_size[lun]) >> 16);
|
||||
pdata[6] = (uint8_t)((pmsc->blk_size[lun]) >> 8);
|
||||
pdata[7] = (uint8_t)((pmsc->blk_size[lun]));
|
||||
|
||||
|
||||
pmsc->data_len = 8;
|
||||
return USB_OK;
|
||||
}
|
||||
@@ -501,34 +501,34 @@ usb_sts_type bot_scsi_capacity(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command format capacity
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_format_capacity(void *udev, uint8_t lun)
|
||||
{
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *pdata = pmsc->data;
|
||||
|
||||
|
||||
pdata[0] = 0;
|
||||
pdata[1] = 0;
|
||||
pdata[2] = 0;
|
||||
pdata[3] = 0x08;
|
||||
|
||||
|
||||
msc_disk_capacity(lun, &pmsc->blk_nbr[lun], &pmsc->blk_size[lun]);
|
||||
|
||||
|
||||
pdata[4] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 24);
|
||||
pdata[5] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 16);
|
||||
pdata[6] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 8);
|
||||
pdata[7] = (uint8_t)((pmsc->blk_nbr[lun] - 1));
|
||||
|
||||
|
||||
pdata[8] = 0x02;
|
||||
|
||||
|
||||
pdata[9] = (uint8_t)((pmsc->blk_size[lun]) >> 16);
|
||||
pdata[10] = (uint8_t)((pmsc->blk_size[lun]) >> 8);
|
||||
pdata[11] = (uint8_t)((pmsc->blk_size[lun]));
|
||||
|
||||
|
||||
pmsc->data_len = 12;
|
||||
|
||||
|
||||
return USB_OK;
|
||||
}
|
||||
|
||||
@@ -536,7 +536,7 @@ usb_sts_type bot_scsi_format_capacity(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command request sense
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_request_sense(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -545,13 +545,13 @@ usb_sts_type bot_scsi_request_sense(void *udev, uint8_t lun)
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *pdata = pmsc->data;
|
||||
uint8_t *sdata = (uint8_t *)&sense_data;
|
||||
|
||||
|
||||
while(trans_len)
|
||||
{
|
||||
trans_len --;
|
||||
pdata[trans_len] = sdata[trans_len];
|
||||
}
|
||||
|
||||
|
||||
if(pmsc->cbw_struct.dCBWDataTransferLength < REQ_SENSE_STANDARD_DATA_LEN)
|
||||
{
|
||||
pmsc->data_len = pmsc->cbw_struct.dCBWDataTransferLength;
|
||||
@@ -567,7 +567,7 @@ usb_sts_type bot_scsi_request_sense(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command verify
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_verify(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -579,10 +579,10 @@ usb_sts_type bot_scsi_verify(void *udev, uint8_t lun)
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->blk_addr = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
|
||||
pmsc->blk_len = cmd[7] << 8 | cmd[8];
|
||||
|
||||
|
||||
if(bot_scsi_check_address(udev, lun, pmsc->blk_addr, pmsc->blk_len) != USB_OK)
|
||||
{
|
||||
return USB_FAIL;
|
||||
@@ -595,7 +595,7 @@ usb_sts_type bot_scsi_verify(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command read10
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_read10(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -603,7 +603,7 @@ usb_sts_type bot_scsi_read10(void *udev, uint8_t lun)
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *cmd = pmsc->cbw_struct.CBWCB;
|
||||
uint32_t len;
|
||||
|
||||
|
||||
if(pmsc->msc_state == MSC_STATE_MACHINE_IDLE)
|
||||
{
|
||||
if((pmsc->cbw_struct.bmCBWFlags & 0x80) != 0x80)
|
||||
@@ -611,18 +611,18 @@ usb_sts_type bot_scsi_read10(void *udev, uint8_t lun)
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->blk_addr = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
|
||||
pmsc->blk_len = cmd[7] << 8 | cmd[8];
|
||||
|
||||
|
||||
if(bot_scsi_check_address(udev, lun, pmsc->blk_addr, pmsc->blk_len) != USB_OK)
|
||||
{
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->blk_addr *= pmsc->blk_size[lun];
|
||||
pmsc->blk_len *= pmsc->blk_size[lun];
|
||||
|
||||
|
||||
if(pmsc->cbw_struct.dCBWDataTransferLength != pmsc->blk_len)
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
@@ -631,7 +631,7 @@ usb_sts_type bot_scsi_read10(void *udev, uint8_t lun)
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_DATA_IN;
|
||||
}
|
||||
pmsc->data_len = MSC_MAX_DATA_BUF_LEN;
|
||||
|
||||
|
||||
len = MIN(pmsc->blk_len, MSC_MAX_DATA_BUF_LEN);
|
||||
if( msc_disk_read(lun, pmsc->blk_addr, pmsc->data, len) != USB_OK)
|
||||
{
|
||||
@@ -641,13 +641,13 @@ usb_sts_type bot_scsi_read10(void *udev, uint8_t lun)
|
||||
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT, pmsc->data, len);
|
||||
pmsc->blk_addr += len;
|
||||
pmsc->blk_len -= len;
|
||||
|
||||
|
||||
pmsc->csw_struct.dCSWDataResidue -= len;
|
||||
if(pmsc->blk_len == 0)
|
||||
{
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_LAST_DATA;
|
||||
}
|
||||
|
||||
|
||||
return USB_OK;
|
||||
}
|
||||
|
||||
@@ -656,7 +656,7 @@ usb_sts_type bot_scsi_read10(void *udev, uint8_t lun)
|
||||
* @brief bulk-only transport scsi command write10
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param lun: logical units number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_write10(void *udev, uint8_t lun)
|
||||
{
|
||||
@@ -664,7 +664,7 @@ usb_sts_type bot_scsi_write10(void *udev, uint8_t lun)
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *cmd = pmsc->cbw_struct.CBWCB;
|
||||
uint32_t len;
|
||||
|
||||
|
||||
if(pmsc->msc_state == MSC_STATE_MACHINE_IDLE)
|
||||
{
|
||||
if((pmsc->cbw_struct.bmCBWFlags & 0x80) == 0x80)
|
||||
@@ -672,28 +672,28 @@ usb_sts_type bot_scsi_write10(void *udev, uint8_t lun)
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->blk_addr = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
|
||||
pmsc->blk_len = cmd[7] << 8 | cmd[8];
|
||||
|
||||
|
||||
if(bot_scsi_check_address(udev, lun, pmsc->blk_addr, pmsc->blk_len) != USB_OK)
|
||||
{
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->blk_addr *= pmsc->blk_size[lun];
|
||||
pmsc->blk_len *= pmsc->blk_size[lun];
|
||||
|
||||
|
||||
if(pmsc->cbw_struct.dCBWDataTransferLength != pmsc->blk_len)
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_DATA_OUT;
|
||||
len = MIN(pmsc->blk_len, MSC_MAX_DATA_BUF_LEN);
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)pmsc->data, len);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -703,12 +703,12 @@ usb_sts_type bot_scsi_write10(void *udev, uint8_t lun)
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_HARDWARE_ERROR, MEDIUM_NOT_PRESENT);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
|
||||
pmsc->blk_addr += len;
|
||||
pmsc->blk_len -= len;
|
||||
|
||||
|
||||
pmsc->csw_struct.dCSWDataResidue -= len;
|
||||
|
||||
|
||||
if(pmsc->blk_len == 0)
|
||||
{
|
||||
bot_scsi_send_csw(udev, CSW_BCSWSTATUS_PASS);
|
||||
@@ -726,7 +726,7 @@ usb_sts_type bot_scsi_write10(void *udev, uint8_t lun)
|
||||
* @brief clear feature
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param etp_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
void bot_scsi_clear_feature(void *udev, uint8_t ept_num)
|
||||
{
|
||||
@@ -746,7 +746,7 @@ void bot_scsi_clear_feature(void *udev, uint8_t ept_num)
|
||||
/**
|
||||
* @brief bulk-only transport scsi command process
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_cmd_process(void *udev)
|
||||
{
|
||||
@@ -758,51 +758,51 @@ usb_sts_type bot_scsi_cmd_process(void *udev)
|
||||
case MSC_CMD_INQUIRY:
|
||||
status = bot_scsi_inquiry(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_START_STOP:
|
||||
status = bot_scsi_start_stop(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
break;
|
||||
|
||||
case MSC_CMD_MODE_SENSE6:
|
||||
status = bot_scsi_mode_sense6(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_MODE_SENSE10:
|
||||
status = bot_scsi_mode_sense10(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_ALLOW_MEDIUM_REMOVAL:
|
||||
status = bot_scsi_allow_medium_removal(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_READ_10:
|
||||
status = bot_scsi_read10(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_READ_CAPACITY:
|
||||
status = bot_scsi_capacity(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_REQUEST_SENSE:
|
||||
status = bot_scsi_request_sense(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_TEST_UNIT:
|
||||
status = bot_scsi_test_unit(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_VERIFY:
|
||||
status = bot_scsi_verify(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_WRITE_10:
|
||||
status = bot_scsi_write10(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
case MSC_CMD_READ_FORMAT_CAPACITY:
|
||||
status = bot_scsi_format_capacity(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
status = USB_FAIL;
|
||||
@@ -813,7 +813,7 @@ usb_sts_type bot_scsi_cmd_process(void *udev)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_bot_scsi.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb mass storage bulk-only transport and scsi command 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,
|
||||
@@ -22,7 +22,7 @@
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
*/
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MSC_BOT_SCSI_H
|
||||
#define __MSC_BOT_SCSI_H
|
||||
@@ -30,7 +30,7 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "msc_class.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
@@ -41,8 +41,8 @@ extern "C" {
|
||||
/** @addtogroup USB_msc_bot_scsi
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_msc_bot_scsi_definition
|
||||
|
||||
/** @defgroup USB_msc_bot_scsi_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -195,21 +195,21 @@ typedef struct
|
||||
uint8_t msc_state;
|
||||
uint8_t bot_status;
|
||||
uint32_t max_lun;
|
||||
|
||||
|
||||
uint32_t blk_nbr[MSC_SUPPORT_MAX_LUN];
|
||||
uint32_t blk_size[MSC_SUPPORT_MAX_LUN];
|
||||
|
||||
|
||||
uint32_t blk_addr;
|
||||
uint32_t blk_len;
|
||||
|
||||
|
||||
uint32_t data_len;
|
||||
uint8_t data[MSC_MAX_DATA_BUF_LEN];
|
||||
|
||||
|
||||
uint32_t alt_setting;
|
||||
|
||||
|
||||
cbw_type cbw_struct;
|
||||
csw_type csw_struct;
|
||||
|
||||
|
||||
}msc_type;
|
||||
|
||||
void bot_scsi_init(void *udev);
|
||||
@@ -241,11 +241,11 @@ void bot_scsi_clear_feature(void *udev, uint8_t ept_num);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_class.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb msc 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
|
||||
* 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,
|
||||
@@ -22,7 +22,7 @@
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
*/
|
||||
#include "usbd_core.h"
|
||||
#include "msc_class.h"
|
||||
#include "msc_desc.h"
|
||||
@@ -31,11 +31,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_msc_class
|
||||
* @brief usb device class msc demo
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_msc_class_private_functions
|
||||
* @{
|
||||
@@ -54,7 +54,7 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event);
|
||||
msc_type msc_struct;
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler msc_class_handler =
|
||||
usbd_class_handler msc_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
@@ -71,40 +71,40 @@ usbd_class_handler msc_class_handler =
|
||||
/**
|
||||
* @brief initialize usb endpoint
|
||||
* @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 class_init_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
|
||||
|
||||
/* open in endpoint */
|
||||
usbd_ept_open(pudev, USBD_MSC_BULK_IN_EPT, EPT_BULK_TYPE, USBD_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* open out endpoint */
|
||||
usbd_ept_open(pudev, USBD_MSC_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
bot_scsi_init(udev);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief clear endpoint or other state
|
||||
* @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 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_MSC_BULK_IN_EPT);
|
||||
|
||||
|
||||
/* close out endpoint */
|
||||
usbd_ept_close(pudev, USBD_MSC_BULK_OUT_EPT);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ static usb_sts_type class_clear_handler(void *udev)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -123,7 +123,7 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
/* class request */
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
|
||||
|
||||
switch(setup->bRequest)
|
||||
{
|
||||
case MSC_REQ_GET_MAX_LUN:
|
||||
@@ -136,12 +136,12 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
/* standard request */
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
|
||||
|
||||
switch(setup->bRequest)
|
||||
{
|
||||
case USB_STD_REQ_GET_DESCRIPTOR:
|
||||
@@ -155,7 +155,7 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
break;
|
||||
case USB_STD_REQ_CLEAR_FEATURE:
|
||||
usbd_ept_close(pudev, (uint8_t)setup->wIndex);
|
||||
|
||||
|
||||
if((setup->wIndex & 0x80) == 0x80)
|
||||
{
|
||||
usbd_ept_open(pudev, (uint8_t)setup->wIndex, EPT_BULK_TYPE, USBD_IN_MAXPACKET_SIZE);
|
||||
@@ -180,21 +180,21 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
/**
|
||||
* @brief usb device endpoint 0 in status stage complete
|
||||
* @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 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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
{
|
||||
@@ -209,7 +209,7 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
@@ -223,7 +223,7 @@ static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
@@ -235,14 +235,14 @@ static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
/**
|
||||
* @brief usb device sof handler
|
||||
* @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 class_sof_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ static usb_sts_type class_sof_handler(void *udev)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
{
|
||||
@@ -258,20 +258,20 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_WAKEUP_EVENT:
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -279,7 +279,7 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_class.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb msc 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
|
||||
* 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,
|
||||
@@ -22,7 +22,7 @@
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
*/
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MSC_CLASS_H
|
||||
#define __MSC_CLASS_H
|
||||
@@ -30,19 +30,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "usb_std.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_msc_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_msc_class_definition
|
||||
/** @defgroup USB_msc_class_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -61,7 +61,7 @@ extern usbd_class_handler msc_class_handler;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_desc.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb msc 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
|
||||
* 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,
|
||||
@@ -22,7 +22,7 @@
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
*/
|
||||
#include "stdio.h"
|
||||
#include "usb_std.h"
|
||||
#include "usbd_sdr.h"
|
||||
@@ -32,11 +32,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_msc_desc
|
||||
* @brief usb device msc descriptor
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_msc_desc_private_functions
|
||||
* @{
|
||||
@@ -121,7 +121,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_MSC_CONFIG_DESC_SIZE] ALIG
|
||||
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 */
|
||||
@@ -131,7 +131,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_MSC_CONFIG_DESC_SIZE] ALIG
|
||||
0x06, /* bInterfaceSubClass: subclass code scsi */
|
||||
0x50, /* bInterfaceProtocol: protocol code BBB */
|
||||
0x05, /* 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_MSC_BULK_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
@@ -139,12 +139,12 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_MSC_CONFIG_DESC_SIZE] ALIG
|
||||
LBYTE(USBD_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_IN_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_MSC_BULK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_OUT_MAXPACKET_SIZE),
|
||||
LBYTE(USBD_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
};
|
||||
@@ -210,24 +210,24 @@ static usbd_desc_t vp_desc;
|
||||
* @brief standard usb unicode convert
|
||||
* @param string: source string
|
||||
* @param unicode_buf: unicode buffer
|
||||
* @retval length
|
||||
* @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;
|
||||
}
|
||||
|
||||
@@ -236,12 +236,12 @@ static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
* @param value: int value
|
||||
* @param pbus: unicode buffer
|
||||
* @param len: length
|
||||
* @retval none
|
||||
* @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 )
|
||||
@@ -250,11 +250,11 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
}
|
||||
|
||||
|
||||
value = value << 4;
|
||||
|
||||
|
||||
pbuf[2 * idx + 1] = 0;
|
||||
}
|
||||
}
|
||||
@@ -262,18 +262,18 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
/**
|
||||
* @brief usb get serial number
|
||||
* @param none
|
||||
* @retval 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);
|
||||
@@ -284,7 +284,7 @@ static void get_serial_num(void)
|
||||
/**
|
||||
* @brief get device descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_descriptor(void)
|
||||
{
|
||||
@@ -294,7 +294,7 @@ static usbd_desc_t *get_device_descriptor(void)
|
||||
/**
|
||||
* @brief get device qualifier
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t * get_device_qualifier(void)
|
||||
{
|
||||
@@ -304,7 +304,7 @@ static usbd_desc_t * get_device_qualifier(void)
|
||||
/**
|
||||
* @brief get config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_configuration(void)
|
||||
{
|
||||
@@ -314,7 +314,7 @@ static usbd_desc_t *get_device_configuration(void)
|
||||
/**
|
||||
* @brief get other speed descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_other_speed(void)
|
||||
{
|
||||
@@ -324,7 +324,7 @@ static usbd_desc_t *get_device_other_speed(void)
|
||||
/**
|
||||
* @brief get lang id descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_lang_id(void)
|
||||
{
|
||||
@@ -335,7 +335,7 @@ static usbd_desc_t *get_device_lang_id(void)
|
||||
/**
|
||||
* @brief get manufacturer descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
{
|
||||
@@ -347,7 +347,7 @@ static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
/**
|
||||
* @brief get product descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_product_string(void)
|
||||
{
|
||||
@@ -359,7 +359,7 @@ static usbd_desc_t *get_device_product_string(void)
|
||||
/**
|
||||
* @brief get serial descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_serial_string(void)
|
||||
{
|
||||
@@ -370,7 +370,7 @@ static usbd_desc_t *get_device_serial_string(void)
|
||||
/**
|
||||
* @brief get interface descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_interface_string(void)
|
||||
{
|
||||
@@ -382,7 +382,7 @@ static usbd_desc_t *get_device_interface_string(void)
|
||||
/**
|
||||
* @brief get device config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_config_string(void)
|
||||
{
|
||||
@@ -393,7 +393,7 @@ static usbd_desc_t *get_device_config_string(void)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_desc.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb msc 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
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MSC_DESC_H
|
||||
#define __MSC_DESC_H
|
||||
@@ -31,19 +31,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "msc_class.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_msc_desc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_msc_desc_definition
|
||||
/** @defgroup USB_msc_desc_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -70,11 +70,11 @@ extern usbd_desc_handler msc_desc_handler;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file printer_class.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb printer 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
|
||||
* 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,
|
||||
@@ -30,11 +30,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_printer_class
|
||||
* @brief usb device class printer demo
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_printer_class_private_functions
|
||||
* @{
|
||||
@@ -61,7 +61,7 @@ ALIGNED_HEAD static uint8_t printer_device_id[PRINTER_DEVICE_ID_LEN] ALIGNED_TAI
|
||||
printer_type printer_struct;
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler printer_class_handler =
|
||||
usbd_class_handler printer_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
@@ -78,45 +78,45 @@ usbd_class_handler printer_class_handler =
|
||||
/**
|
||||
* @brief initialize usb custom hid endpoint
|
||||
* @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 class_init_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
printer_type *pprter = (printer_type *)pudev->class_handler->pdata;
|
||||
|
||||
|
||||
/* open in endpoint */
|
||||
usbd_ept_open(pudev, USBD_PRINTER_BULK_IN_EPT, EPT_BULK_TYPE, USBD_PRINTER_IN_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* open out endpoint */
|
||||
usbd_ept_open(pudev, USBD_PRINTER_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_PRINTER_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_PRINTER_BULK_OUT_EPT, pprter->g_rx_buff, USBD_PRINTER_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
pprter->g_tx_completed = 1;
|
||||
pprter->g_printer_port_status = 0x18;
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief clear endpoint or other state
|
||||
* @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 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_PRINTER_BULK_IN_EPT);
|
||||
|
||||
|
||||
/* close out endpoint */
|
||||
usbd_ept_close(pudev, USBD_PRINTER_BULK_OUT_EPT);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ static usb_sts_type class_clear_handler(void *udev)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
@@ -179,28 +179,28 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
/**
|
||||
* @brief usb device endpoint 0 in status stage complete
|
||||
* @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 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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -208,19 +208,19 @@ static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
* @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
|
||||
* @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;
|
||||
printer_type *pprter = (printer_type *)pudev->class_handler->pdata;
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
pprter->g_tx_completed = 1;
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
@@ -237,24 +237,24 @@ static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
printer_type *pprter = (printer_type *)pudev->class_handler->pdata;
|
||||
/* get endpoint receive data length */
|
||||
pprter->g_rxlen = usbd_get_recv_len(pudev, ept_num);
|
||||
|
||||
|
||||
/*set recv flag*/
|
||||
pprter->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
|
||||
* @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;
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ static usb_sts_type class_sof_handler(void *udev)
|
||||
* @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
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
{
|
||||
@@ -270,20 +270,20 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
case USBD_WAKEUP_EVENT:
|
||||
/* ...user code... */
|
||||
|
||||
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -294,7 +294,7 @@ static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
* @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
|
||||
* @retval receive data len
|
||||
*/
|
||||
uint16_t usb_printer_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
{
|
||||
@@ -302,7 +302,7 @@ uint16_t usb_printer_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
printer_type *pprter = (printer_type *)pudev->class_handler->pdata;
|
||||
uint16_t tmp_len = 0;
|
||||
|
||||
|
||||
if(pprter->g_rx_completed == 0)
|
||||
{
|
||||
return 0;
|
||||
@@ -313,9 +313,9 @@ uint16_t usb_printer_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
{
|
||||
recv_data[i_index] = pprter->g_rx_buff[i_index];
|
||||
}
|
||||
|
||||
|
||||
usbd_ept_recv(pudev, USBD_PRINTER_BULK_OUT_EPT, pprter->g_rx_buff, USBD_PRINTER_OUT_MAXPACKET_SIZE);
|
||||
|
||||
|
||||
return tmp_len;
|
||||
}
|
||||
|
||||
@@ -324,7 +324,7 @@ uint16_t usb_printer_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @param send_data: send data buffer
|
||||
* @param len: send length
|
||||
* @retval error status
|
||||
* @retval error status
|
||||
*/
|
||||
error_status usb_printer_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
{
|
||||
@@ -346,7 +346,7 @@ error_status usb_printer_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file printer_class.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb printer 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
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __PRINTER_CLASS_H
|
||||
#define __PRINTER_CLASS_H
|
||||
@@ -31,19 +31,19 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "usb_std.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_printer_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_printer_class_definition
|
||||
/** @defgroup USB_printer_class_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -85,7 +85,7 @@ error_status usb_printer_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file printer_desc.c
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb printer 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
|
||||
* 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,
|
||||
@@ -32,11 +32,11 @@
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USB_printer_desc
|
||||
* @brief usb device printer descriptor
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USB_printer_desc_private_functions
|
||||
* @{
|
||||
@@ -121,7 +121,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_PRINTER_CONFIG_DESC_SIZE]
|
||||
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 */
|
||||
@@ -131,7 +131,7 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_PRINTER_CONFIG_DESC_SIZE]
|
||||
0x01, /* bInterfaceSubClass: subclass code*/
|
||||
PRINTER_PROTOCOL_BI_DIRECTIONAL, /* bInterfaceProtocol: printer interface type */
|
||||
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_PRINTER_BULK_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
@@ -139,12 +139,12 @@ ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_PRINTER_CONFIG_DESC_SIZE]
|
||||
LBYTE(USBD_PRINTER_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_PRINTER_IN_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_PRINTER_BULK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_PRINTER_OUT_MAXPACKET_SIZE),
|
||||
LBYTE(USBD_PRINTER_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_PRINTER_OUT_MAXPACKET_SIZE),/* wMaxPacketSize: maximum packe size this endpoint */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
};
|
||||
@@ -210,24 +210,24 @@ static usbd_desc_t vp_desc;
|
||||
* @brief standard usb unicode convert
|
||||
* @param string: source string
|
||||
* @param unicode_buf: unicode buffer
|
||||
* @retval length
|
||||
* @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;
|
||||
}
|
||||
|
||||
@@ -236,12 +236,12 @@ static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
* @param value: int value
|
||||
* @param pbus: unicode buffer
|
||||
* @param len: length
|
||||
* @retval none
|
||||
* @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 )
|
||||
@@ -250,11 +250,11 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
}
|
||||
|
||||
|
||||
value = value << 4;
|
||||
|
||||
|
||||
pbuf[2 * idx + 1] = 0;
|
||||
}
|
||||
}
|
||||
@@ -262,18 +262,18 @@ static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
/**
|
||||
* @brief usb get serial number
|
||||
* @param none
|
||||
* @retval 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);
|
||||
@@ -284,7 +284,7 @@ static void get_serial_num(void)
|
||||
/**
|
||||
* @brief get device descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_descriptor(void)
|
||||
{
|
||||
@@ -294,7 +294,7 @@ static usbd_desc_t *get_device_descriptor(void)
|
||||
/**
|
||||
* @brief get device qualifier
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t * get_device_qualifier(void)
|
||||
{
|
||||
@@ -304,7 +304,7 @@ static usbd_desc_t * get_device_qualifier(void)
|
||||
/**
|
||||
* @brief get config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_configuration(void)
|
||||
{
|
||||
@@ -314,7 +314,7 @@ static usbd_desc_t *get_device_configuration(void)
|
||||
/**
|
||||
* @brief get other speed descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_other_speed(void)
|
||||
{
|
||||
@@ -324,7 +324,7 @@ static usbd_desc_t *get_device_other_speed(void)
|
||||
/**
|
||||
* @brief get lang id descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_lang_id(void)
|
||||
{
|
||||
@@ -335,7 +335,7 @@ static usbd_desc_t *get_device_lang_id(void)
|
||||
/**
|
||||
* @brief get manufacturer descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
{
|
||||
@@ -347,7 +347,7 @@ static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
/**
|
||||
* @brief get product descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_product_string(void)
|
||||
{
|
||||
@@ -359,7 +359,7 @@ static usbd_desc_t *get_device_product_string(void)
|
||||
/**
|
||||
* @brief get serial descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_serial_string(void)
|
||||
{
|
||||
@@ -370,7 +370,7 @@ static usbd_desc_t *get_device_serial_string(void)
|
||||
/**
|
||||
* @brief get interface descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_interface_string(void)
|
||||
{
|
||||
@@ -382,7 +382,7 @@ static usbd_desc_t *get_device_interface_string(void)
|
||||
/**
|
||||
* @brief get device config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_config_string(void)
|
||||
{
|
||||
@@ -393,7 +393,7 @@ static usbd_desc_t *get_device_config_string(void)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file printer_desc.h
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @version v2.0.4
|
||||
* @date 2022-04-02
|
||||
* @brief usb printer 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
|
||||
* 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,
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __PRINTER_DESC_H
|
||||
#define __PRINTER_DESC_H
|
||||
@@ -31,26 +31,26 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "printer_class.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup AT32F413_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup USB_printer_desc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_printer_desc_definition
|
||||
/** @defgroup USB_printer_desc_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define PRINTER_BCD_NUM 0x0110
|
||||
|
||||
#define USBD_PRINTER_VENDOR_ID 0x2E3C
|
||||
#define USBD_PRINTER_PRODUCT_ID 0x57FF
|
||||
#define USBD_PRINTER_PRODUCT_ID 0x57FF
|
||||
|
||||
#define USBD_PRINTER_CONFIG_DESC_SIZE 32
|
||||
#define USBD_PRINTER_SIZ_STRING_LANGID 4
|
||||
@@ -81,7 +81,7 @@ extern usbd_desc_handler printer_desc_handler;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -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