mirror of
https://github.com/ArteryTek/AT32F415_Firmware_Library.git
synced 2026-05-21 01:12:20 +00:00
update version to v2.0.7
This commit is contained in:
532
middlewares/usbh_class/usbh_cdc/usbh_cdc_class.c
Normal file
532
middlewares/usbh_class/usbh_cdc/usbh_cdc_class.c
Normal file
@@ -0,0 +1,532 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_cdc_class.c
|
||||
* @version v2.0.7
|
||||
* @date 2022-08-16
|
||||
* @brief usb host 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
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
#include "usbh_cdc_class.h"
|
||||
#include "usb_conf.h"
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_ctrl.h"
|
||||
#include "string.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbh_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup usbh_cdc_class
|
||||
* @brief usb host class cdc demo
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup usbh_cdc_class_private_functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
static usb_sts_type uhost_init_handler(void *uhost);
|
||||
static usb_sts_type uhost_reset_handler(void *uhost);
|
||||
static usb_sts_type uhost_request_handler(void *uhost);
|
||||
static usb_sts_type uhost_process_handler(void *uhost);
|
||||
static usb_sts_type get_linecoding(usbh_core_type *uhost, cdc_line_coding_type *linecoding);
|
||||
static usb_sts_type set_linecoding(usbh_core_type *uhost, cdc_line_coding_type *linecoding);
|
||||
|
||||
static void cdc_process_transmission(usbh_core_type *uhost);
|
||||
static void cdc_process_reception(usbh_core_type *uhost);
|
||||
usbh_cdc_type usbh_cdc;
|
||||
|
||||
usbh_class_handler_type uhost_cdc_class_handler =
|
||||
{
|
||||
uhost_init_handler,
|
||||
uhost_reset_handler,
|
||||
uhost_request_handler,
|
||||
uhost_process_handler,
|
||||
&usbh_cdc
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief usb host class init handler
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
static usb_sts_type uhost_init_handler(void *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usb_sts_type status = USB_OK;
|
||||
uint8_t if_x;
|
||||
usbh_cdc_type *pcdc = &usbh_cdc;
|
||||
puhost->class_handler->pdata = &usbh_cdc;
|
||||
|
||||
memset((void *)pcdc, 0, sizeof(usbh_cdc_type));
|
||||
if_x = usbh_find_interface(puhost, USB_CLASS_CODE_CDC, ABSTRACT_CONTROL_MODEL, COMMON_AT_COMMAND);
|
||||
if(if_x == 0xFF)
|
||||
{
|
||||
USBH_DEBUG("cannot find the interface for communication interface class!");
|
||||
return USB_NOT_SUPPORT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(if_x < puhost->dev.cfg_desc.cfg.bNumInterfaces)
|
||||
{
|
||||
USBH_DEBUG ("switching to interface (#%d)", if_x);
|
||||
USBH_DEBUG ("class : %xh", puhost->dev.cfg_desc.interface[if_x].interface.bInterfaceClass);
|
||||
USBH_DEBUG ("subclass : %xh", puhost->dev.cfg_desc.interface[if_x].interface.bInterfaceSubClass );
|
||||
USBH_DEBUG ("protocol : %xh", puhost->dev.cfg_desc.interface[if_x].interface.bInterfaceProtocol );
|
||||
if(puhost->dev.cfg_desc.interface[if_x].interface.bInterfaceClass == COMMUNICATION_INTERFACE_CLASS_CODE)
|
||||
{
|
||||
USBH_DEBUG("CDC device!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBH_DEBUG ("cannot select this interface.");
|
||||
}
|
||||
|
||||
/* collect the notification endpoint address and length */
|
||||
if(puhost->dev.cfg_desc.interface[if_x].endpoint[0].bEndpointAddress & 0x80)
|
||||
{
|
||||
pcdc->common_interface.notif_endpoint = puhost->dev.cfg_desc.interface[if_x].endpoint[0].bEndpointAddress;
|
||||
pcdc->common_interface.notif_endpoint_size = puhost->dev.cfg_desc.interface[if_x].endpoint[0].wMaxPacketSize;
|
||||
}
|
||||
/* allocate the length for host channel number in */
|
||||
pcdc->common_interface.notif_channel = usbh_alloc_channel(puhost, pcdc->common_interface.notif_endpoint);
|
||||
|
||||
/* enable channel */
|
||||
usbh_hc_open(puhost,
|
||||
pcdc->common_interface.notif_channel,
|
||||
pcdc->common_interface.notif_endpoint,
|
||||
puhost->dev.address,
|
||||
EPT_INT_TYPE,
|
||||
pcdc->common_interface.notif_endpoint_size,
|
||||
puhost->dev.speed);
|
||||
|
||||
usbh_set_toggle(puhost, pcdc->common_interface.notif_channel, 0);
|
||||
|
||||
|
||||
if_x = usbh_find_interface(puhost, DATA_INTERFACE_CLASS_CODE, RESERVED, NO_CLASS_SPECIFIC_PROTOCOL_CODE);
|
||||
if(if_x == 0xFF)
|
||||
{
|
||||
USBH_DEBUG("cannot find the interface for data interface class!");
|
||||
return USB_NOT_SUPPORT;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* collect the class specific endpoint address and length */
|
||||
if(puhost->dev.cfg_desc.interface[if_x].endpoint[0].bEndpointAddress & 0x80)
|
||||
{
|
||||
pcdc->data_interface.in_endpoint = puhost->dev.cfg_desc.interface[if_x].endpoint[0].bEndpointAddress;
|
||||
pcdc->data_interface.in_endpoint_size = puhost->dev.cfg_desc.interface[if_x].endpoint[0].wMaxPacketSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
pcdc->data_interface.out_endpoint = puhost->dev.cfg_desc.interface[if_x].endpoint[0].bEndpointAddress;
|
||||
pcdc->data_interface.out_endpoint_size = puhost->dev.cfg_desc.interface[if_x].endpoint[0].wMaxPacketSize;
|
||||
}
|
||||
|
||||
if(puhost->dev.cfg_desc.interface[if_x].endpoint[1].bEndpointAddress & 0x80)
|
||||
{
|
||||
pcdc->data_interface.in_endpoint = puhost->dev.cfg_desc.interface[if_x].endpoint[1].bEndpointAddress;
|
||||
pcdc->data_interface.in_endpoint_size = puhost->dev.cfg_desc.interface[if_x].endpoint[1].wMaxPacketSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
pcdc->data_interface.out_endpoint = puhost->dev.cfg_desc.interface[if_x].endpoint[1].bEndpointAddress;
|
||||
pcdc->data_interface.out_endpoint_size = puhost->dev.cfg_desc.interface[if_x].endpoint[1].wMaxPacketSize;
|
||||
}
|
||||
|
||||
/* allocate the length for host channel number in */
|
||||
pcdc->data_interface.in_channel = usbh_alloc_channel(puhost, pcdc->data_interface.in_endpoint);
|
||||
/* allocate the length for host channel number out */
|
||||
pcdc->data_interface.out_channel = usbh_alloc_channel(puhost, pcdc->data_interface.out_endpoint);
|
||||
|
||||
/* enable in channel */
|
||||
usbh_hc_open(puhost,
|
||||
pcdc->data_interface.in_channel,
|
||||
pcdc->data_interface.in_endpoint,
|
||||
puhost->dev.address,
|
||||
EPT_BULK_TYPE,
|
||||
pcdc->data_interface.in_endpoint_size,
|
||||
puhost->dev.speed);
|
||||
|
||||
/* enable out channel */
|
||||
usbh_hc_open(puhost,
|
||||
pcdc->data_interface.out_channel,
|
||||
pcdc->data_interface.out_endpoint,
|
||||
puhost->dev.address,
|
||||
EPT_BULK_TYPE,
|
||||
pcdc->data_interface.out_endpoint_size,
|
||||
puhost->dev.speed);
|
||||
|
||||
usbh_set_toggle(puhost, pcdc->data_interface.in_channel, 0);
|
||||
usbh_set_toggle(puhost, pcdc->data_interface.out_channel, 0);
|
||||
|
||||
pcdc->state = CDC_IDLE_STATE;
|
||||
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host class reset handler
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
static usb_sts_type uhost_reset_handler(void *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_cdc_type *pcdc = (usbh_cdc_type *)puhost->class_handler->pdata;
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
if(puhost->class_handler->pdata == NULL)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
if(pcdc->common_interface.notif_channel != 0 )
|
||||
{
|
||||
usbh_free_channel(puhost, pcdc->common_interface.notif_channel);
|
||||
usbh_ch_disable(puhost, pcdc->common_interface.notif_channel);
|
||||
pcdc->common_interface.notif_channel = 0;
|
||||
}
|
||||
|
||||
if(pcdc->data_interface.in_channel != 0 )
|
||||
{
|
||||
usbh_free_channel(puhost, pcdc->data_interface.in_channel);
|
||||
usbh_ch_disable(puhost, pcdc->data_interface.in_channel);
|
||||
pcdc->data_interface.in_channel = 0;
|
||||
}
|
||||
|
||||
if(pcdc->data_interface.out_channel != 0 )
|
||||
{
|
||||
usbh_free_channel(puhost, pcdc->data_interface.out_channel);
|
||||
usbh_ch_disable(puhost, pcdc->data_interface.out_channel);
|
||||
pcdc->data_interface.out_channel = 0;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host cdc class request handler
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
static usb_sts_type uhost_request_handler(void *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_cdc_type *pcdc = (usbh_cdc_type *)puhost->class_handler->pdata;
|
||||
usb_sts_type status = USB_WAIT;
|
||||
|
||||
status = get_linecoding(uhost, &pcdc->linecoding);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host cdc get linecoding handler
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @param linecoding: pointer to the structure of cdc_line_coding_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
static usb_sts_type get_linecoding(usbh_core_type *uhost, cdc_line_coding_type *linecoding)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usb_sts_type status = USB_WAIT;
|
||||
if(puhost->ctrl.state == CONTROL_IDLE )
|
||||
{
|
||||
uhost->ctrl.setup.bmRequestType = USB_DIR_D2H | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE;
|
||||
uhost->ctrl.setup.bRequest = CDC_GET_LINE_CODING;
|
||||
uhost->ctrl.setup.wValue = 0;
|
||||
uhost->ctrl.setup.wLength = LINE_CODING_STRUCTURE_SIZE;
|
||||
uhost->ctrl.setup.wIndex = 0;
|
||||
|
||||
usbh_ctrl_request(uhost, linecoding->array, LINE_CODING_STRUCTURE_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = usbh_ctrl_result_check(puhost, CONTROL_IDLE, ENUM_IDLE);
|
||||
if(status == USB_OK || status == USB_NOT_SUPPORT)
|
||||
{
|
||||
status = USB_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host cdc set linecoding handler
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @param linecoding: pointer to the structure of cdc_line_coding_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
static usb_sts_type set_linecoding(usbh_core_type *uhost, cdc_line_coding_type *linecoding)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usb_sts_type status = USB_WAIT;
|
||||
|
||||
if(puhost->ctrl.state == CONTROL_IDLE )
|
||||
{
|
||||
uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE;
|
||||
uhost->ctrl.setup.bRequest = CDC_SET_LINE_CODING;
|
||||
uhost->ctrl.setup.wValue = 0;
|
||||
uhost->ctrl.setup.wLength = LINE_CODING_STRUCTURE_SIZE;
|
||||
uhost->ctrl.setup.wIndex = 0;
|
||||
|
||||
status = usbh_ctrl_request(uhost, linecoding->array, LINE_CODING_STRUCTURE_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = usbh_ctrl_result_check(puhost, CONTROL_IDLE, ENUM_IDLE);
|
||||
if(status == USB_OK || status == USB_NOT_SUPPORT)
|
||||
{
|
||||
status = USB_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host class process handler
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
static usb_sts_type uhost_process_handler(void *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_cdc_type *pcdc = (usbh_cdc_type *)puhost->class_handler->pdata;
|
||||
usb_sts_type status;
|
||||
|
||||
switch(pcdc->state)
|
||||
{
|
||||
case CDC_IDLE_STATE:
|
||||
status = USB_OK;
|
||||
break;
|
||||
|
||||
case CDC_SET_LINE_CODING_STATE:
|
||||
status = set_linecoding(puhost, pcdc->puserlinecoding);
|
||||
if(status == USB_OK)
|
||||
pcdc->state = CDC_GET_LAST_LINE_CODING_STATE;
|
||||
break;
|
||||
|
||||
case CDC_GET_LAST_LINE_CODING_STATE:
|
||||
status = get_linecoding(puhost, &(pcdc->linecoding));
|
||||
if(status == USB_OK)
|
||||
{
|
||||
pcdc->state = CDC_IDLE_STATE;
|
||||
if((pcdc->linecoding.line_coding_b.char_format == pcdc->puserlinecoding->line_coding_b.char_format)&&
|
||||
(pcdc->linecoding.line_coding_b.data_bits == pcdc->puserlinecoding->line_coding_b.data_bits)&&
|
||||
(pcdc->linecoding.line_coding_b.parity_type == pcdc->puserlinecoding->line_coding_b.parity_type)&&
|
||||
(pcdc->linecoding.line_coding_b.data_baudrate == pcdc->puserlinecoding->line_coding_b.data_baudrate))
|
||||
{
|
||||
/* line coding changed */
|
||||
}
|
||||
}
|
||||
pcdc->state = CDC_IDLE_STATE;
|
||||
break;
|
||||
|
||||
case CDC_TRANSFER_DATA:
|
||||
cdc_process_transmission(puhost);
|
||||
cdc_process_reception(puhost);
|
||||
break;
|
||||
|
||||
case CDC_ERROR_STATE:
|
||||
status = usbh_clear_ept_feature(puhost, 0, pcdc->common_interface.notif_channel);
|
||||
if(status == USB_OK)
|
||||
pcdc->state = CDC_IDLE_STATE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host cdc class process transmission handler
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
static void cdc_process_transmission(usbh_core_type *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_cdc_type *pcdc = (usbh_cdc_type *)puhost->class_handler->pdata;
|
||||
|
||||
switch(pcdc->data_tx_state)
|
||||
{
|
||||
case CDC_SEND_DATA:
|
||||
if(pcdc->tx_len > pcdc->data_interface.out_endpoint_size)
|
||||
{
|
||||
usbh_bulk_send(puhost, pcdc->data_interface.out_channel, (uint8_t*)pcdc->tx_data, pcdc->data_interface.out_endpoint_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbh_bulk_send(puhost, pcdc->data_interface.out_channel, (uint8_t*)pcdc->tx_data, pcdc->tx_len);
|
||||
}
|
||||
pcdc->data_tx_state = CDC_SEND_DATA_WAIT;
|
||||
break;
|
||||
|
||||
case CDC_SEND_DATA_WAIT:
|
||||
if(uhost->urb_state[pcdc->data_interface.out_channel] == URB_DONE)
|
||||
{
|
||||
if(pcdc->tx_len > pcdc->data_interface.out_endpoint_size)
|
||||
{
|
||||
pcdc->tx_len -= pcdc->data_interface.out_endpoint_size;
|
||||
pcdc->tx_data += pcdc->data_interface.out_endpoint_size;
|
||||
pcdc->data_tx_state = CDC_SEND_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
pcdc->tx_len = 0;
|
||||
pcdc->data_tx_state = CDC_IDLE;
|
||||
cdc_transmit_complete(uhost);
|
||||
}
|
||||
}
|
||||
else if( uhost->urb_state[pcdc->data_interface.out_channel] == URB_NOTREADY)
|
||||
{
|
||||
pcdc->data_tx_state = CDC_SEND_DATA;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host cdc class start transmission handler
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @param data: tx data pointer
|
||||
* @param len: tx data len
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
void cdc_start_transmission(usbh_core_type *uhost, uint8_t *data, uint32_t len)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_cdc_type *pcdc = (usbh_cdc_type *)puhost->class_handler->pdata;
|
||||
if(pcdc->data_tx_state == CDC_IDLE)
|
||||
{
|
||||
pcdc->data_tx_state = CDC_SEND_DATA;
|
||||
pcdc->state = CDC_TRANSFER_DATA;
|
||||
pcdc->tx_data = data;
|
||||
pcdc->tx_len = len;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief usb host cdc class transmit complete
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
__weak void cdc_transmit_complete(usbh_core_type *uhost)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host cdc class process reception handler
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
static void cdc_process_reception(usbh_core_type *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_cdc_type *pcdc = (usbh_cdc_type *)puhost->class_handler->pdata;
|
||||
uint32_t len = 0;
|
||||
|
||||
switch(pcdc->data_rx_state)
|
||||
{
|
||||
case CDC_RECEIVE_DATA:
|
||||
usbh_bulk_recv(puhost, pcdc->data_interface.in_channel, (uint8_t*)pcdc->rx_data, pcdc->data_interface.in_endpoint_size);
|
||||
pcdc->data_rx_state = CDC_RECEIVE_DATA_WAIT;
|
||||
break;
|
||||
|
||||
case CDC_RECEIVE_DATA_WAIT:
|
||||
if(uhost->urb_state[pcdc->data_interface.in_channel] == URB_DONE)
|
||||
{
|
||||
len = uhost->hch[pcdc->data_interface.in_channel].trans_count;
|
||||
if(pcdc->rx_len > len && len > pcdc->data_interface.in_endpoint_size)
|
||||
{
|
||||
pcdc->rx_len -= len;
|
||||
pcdc->rx_data += len;
|
||||
pcdc->data_rx_state = CDC_RECEIVE_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
pcdc->data_rx_state = CDC_IDLE;
|
||||
cdc_receive_complete(uhost);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host cdc class start reception handler
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @param data: receive data pointer
|
||||
* @param len: receive data len
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
void cdc_start_reception(usbh_core_type *uhost, uint8_t *data, uint32_t len)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_cdc_type *pcdc = (usbh_cdc_type *)puhost->class_handler->pdata;
|
||||
|
||||
if(pcdc->data_rx_state == CDC_IDLE)
|
||||
{
|
||||
pcdc->data_rx_state = CDC_RECEIVE_DATA;
|
||||
pcdc->state = CDC_TRANSFER_DATA;
|
||||
pcdc->rx_data = data;
|
||||
pcdc->rx_len = len;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host cdc class reception complete
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
__weak void cdc_receive_complete(usbh_core_type *uhost)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
281
middlewares/usbh_class/usbh_cdc/usbh_cdc_class.h
Normal file
281
middlewares/usbh_class/usbh_cdc/usbh_cdc_class.h
Normal file
@@ -0,0 +1,281 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_cdc_class.h
|
||||
* @version v2.0.7
|
||||
* @date 2022-08-16
|
||||
* @brief usb host cdc class header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBH_MSC_CLASS_H
|
||||
#define __USBH_MSC_CLASS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "usbh_core.h"
|
||||
#include "usb_conf.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbh_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_cdc_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_cdc_class_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*Communication Class codes*/
|
||||
#define USB_CDC_CLASS 0x02
|
||||
#define COMMUNICATION_INTERFACE_CLASS_CODE 0x02
|
||||
|
||||
/*Data Interface Class Codes*/
|
||||
#define DATA_INTERFACE_CLASS_CODE 0x0A
|
||||
|
||||
/*Communication sub class codes*/
|
||||
#define RESERVED 0x00
|
||||
#define DIRECT_LINE_CONTROL_MODEL 0x01
|
||||
#define ABSTRACT_CONTROL_MODEL 0x02
|
||||
#define TELEPHONE_CONTROL_MODEL 0x03
|
||||
#define MULTICHANNEL_CONTROL_MODEL 0x04
|
||||
#define CAPI_CONTROL_MODEL 0x05
|
||||
#define ETHERNET_NETWORKING_CONTROL_MODEL 0x06
|
||||
#define ATM_NETWORKING_CONTROL_MODEL 0x07
|
||||
|
||||
|
||||
/*Communication Interface Class Control Protocol Codes*/
|
||||
#define NO_CLASS_SPECIFIC_PROTOCOL_CODE 0x00
|
||||
#define COMMON_AT_COMMAND 0x01
|
||||
#define VENDOR_SPECIFIC 0xFF
|
||||
|
||||
|
||||
#define CS_INTERFACE 0x24
|
||||
#define CDC_PAGE_SIZE_64 0x40
|
||||
|
||||
/*Class-Specific Request Codes*/
|
||||
#define CDC_SEND_ENCAPSULATED_COMMAND 0x00
|
||||
#define CDC_GET_ENCAPSULATED_RESPONSE 0x01
|
||||
#define CDC_SET_COMM_FEATURE 0x02
|
||||
#define CDC_GET_COMM_FEATURE 0x03
|
||||
#define CDC_CLEAR_COMM_FEATURE 0x04
|
||||
|
||||
#define CDC_SET_AUX_LINE_STATE 0x10
|
||||
#define CDC_SET_HOOK_STATE 0x11
|
||||
#define CDC_PULSE_SETUP 0x12
|
||||
#define CDC_SEND_PULSE 0x13
|
||||
#define CDC_SET_PULSE_TIME 0x14
|
||||
#define CDC_RING_AUX_JACK 0x15
|
||||
|
||||
#define CDC_SET_LINE_CODING 0x20
|
||||
#define CDC_GET_LINE_CODING 0x21
|
||||
#define CDC_SET_CONTROL_LINE_STATE 0x22
|
||||
#define CDC_SEND_BREAK 0x23
|
||||
|
||||
#define CDC_SET_RINGER_PARMS 0x30
|
||||
#define CDC_GET_RINGER_PARMS 0x31
|
||||
#define CDC_SET_OPERATION_PARMS 0x32
|
||||
#define CDC_GET_OPERATION_PARMS 0x33
|
||||
#define CDC_SET_LINE_PARMS 0x34
|
||||
#define CDC_GET_LINE_PARMS 0x35
|
||||
#define CDC_DIAL_DIGITS 0x36
|
||||
#define CDC_SET_UNIT_PARAMETER 0x37
|
||||
#define CDC_GET_UNIT_PARAMETER 0x38
|
||||
#define CDC_CLEAR_UNIT_PARAMETER 0x39
|
||||
#define CDC_GET_PROFILE 0x3A
|
||||
|
||||
#define CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40
|
||||
#define CDC_SET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER 0x41
|
||||
#define CDC_GET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER 0x42
|
||||
#define CDC_SET_ETHERNET_PACKET_FILTER 0x43
|
||||
#define CDC_GET_ETHERNET_STATISTIC 0x44
|
||||
|
||||
#define CDC_SET_ATM_DATA_FORMAT 0x50
|
||||
#define CDC_GET_ATM_DEVICE_STATISTICS 0x51
|
||||
#define CDC_SET_ATM_DEFAULT_VC 0x52
|
||||
#define CDC_GET_ATM_VC_STATISTICS 0x53
|
||||
|
||||
|
||||
/* wValue for SetControlLineState*/
|
||||
#define CDC_ACTIVATE_CARRIER_SIGNAL_RTS 0x0002
|
||||
#define CDC_DEACTIVATE_CARRIER_SIGNAL_RTS 0x0000
|
||||
#define CDC_ACTIVATE_SIGNAL_DTR 0x0001
|
||||
#define CDC_DEACTIVATE_SIGNAL_DTR 0x0000
|
||||
|
||||
#define LINE_CODING_STRUCTURE_SIZE 0x07
|
||||
|
||||
/* states for cdc state machine */
|
||||
typedef enum
|
||||
{
|
||||
CDC_IDLE = 0x0,
|
||||
CDC_SEND_DATA = 0x1,
|
||||
CDC_SEND_DATA_WAIT = 0x2,
|
||||
CDC_RECEIVE_DATA = 0x3,
|
||||
CDC_RECEIVE_DATA_WAIT = 0x4,
|
||||
} cdc_data_state_type;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CDC_IDLE_STATE = 0x0,
|
||||
CDC_SET_LINE_CODING_STATE = 0x1,
|
||||
CDC_GET_LAST_LINE_CODING_STATE = 0x2,
|
||||
CDC_TRANSFER_DATA = 0x3,
|
||||
CDC_ERROR_STATE = 0x4,
|
||||
} cdc_state_type;
|
||||
|
||||
|
||||
/*line coding structure*/
|
||||
typedef union _cdc_line_coding_structure
|
||||
{
|
||||
uint8_t array[LINE_CODING_STRUCTURE_SIZE];
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t data_baudrate; /*data terminal rate, in bits per second*/
|
||||
uint8_t char_format; /* Stop bits
|
||||
0 - 1 Stop bit
|
||||
1 - 1.5 Stop bits
|
||||
2 - 2 Stop bits*/
|
||||
uint8_t parity_type; /* parity
|
||||
0 - none
|
||||
1 - odd
|
||||
2 - even
|
||||
3 - mark
|
||||
4 - space*/
|
||||
uint8_t data_bits; /* data bits (5, 6, 7, 8 or 16). */
|
||||
}line_coding_b;
|
||||
} cdc_line_coding_type;
|
||||
|
||||
|
||||
|
||||
/* header functional descriptor */
|
||||
typedef struct _functional_descriptor_header
|
||||
{
|
||||
uint8_t bfunctionlength; /* size of this descriptor. */
|
||||
uint8_t bdescriptortype; /* cs_interface (0x24) */
|
||||
uint8_t bdescriptorsubtype; /* header functional descriptor subtype as */
|
||||
uint16_t bcdcdc; /* usb class definitions for communication
|
||||
devices specification release number in
|
||||
binary-coded decimal. */
|
||||
} cdc_headerfuncdesc_type;
|
||||
|
||||
/* call management functional descriptor */
|
||||
typedef struct _callmgmt_functional_descriptor
|
||||
{
|
||||
uint8_t blength; /* size of this functional descriptor, in bytes */
|
||||
uint8_t bdescriptortype; /* cs_interface (0x24) */
|
||||
uint8_t bdescriptorsubtype; /* call management functional descriptor subtype */
|
||||
uint8_t bmcapabilities; /* bmcapabilities: d0+d1 */
|
||||
uint8_t bdatainterface; /* bdatainterface: 1 */
|
||||
} cdc_callmgmtfuncdesc_type;
|
||||
|
||||
/* abstract control management functional descriptor */
|
||||
typedef struct _abstractcntrlmgmt_functional_descriptor
|
||||
{
|
||||
uint8_t blength; /* size of this functional descriptor, in bytes */
|
||||
uint8_t bdescriptortype; /* cs_interface (0x24) */
|
||||
uint8_t bdescriptorsubtype; /* abstract control management functional
|
||||
descriptor subtype */
|
||||
uint8_t bmcapabilities; /* the capabilities that this configuration supports */
|
||||
} cdc_abstcntrlmgmtfuncdesc_type;
|
||||
|
||||
/* union functional descriptor */
|
||||
typedef struct _union_functional_descriptor
|
||||
{
|
||||
uint8_t blength; /* size of this functional descriptor, in bytes */
|
||||
uint8_t bdescriptortype; /* cs_interface (0x24) */
|
||||
uint8_t bdescriptorsubtype; /* union functional descriptor subtype */
|
||||
uint8_t bmasterinterface; /* the interface number of the communication or
|
||||
data class interface */
|
||||
uint8_t bslaveinterface0; /* interface number of first slave */
|
||||
} cdc_unionfuncdesc_type;
|
||||
|
||||
|
||||
typedef struct _usbh_cdcinterfacedesc
|
||||
{
|
||||
cdc_headerfuncdesc_type cdc_headerfuncdesc;
|
||||
cdc_callmgmtfuncdesc_type cdc_callmgmtfuncdesc;
|
||||
cdc_abstcntrlmgmtfuncdesc_type cdc_abstcntrlmgmtfuncdesc;
|
||||
cdc_unionfuncdesc_type cdc_unionfuncdesc;
|
||||
} cdc_interfacedesc_type;
|
||||
|
||||
|
||||
/* structure for cdc process */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t notif_channel;
|
||||
uint8_t notif_endpoint;
|
||||
uint8_t buff[8];
|
||||
uint16_t notif_endpoint_size;
|
||||
} cdc_common_interface_type;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t in_channel;
|
||||
uint8_t out_channel;
|
||||
uint8_t out_endpoint;
|
||||
uint8_t in_endpoint;
|
||||
uint8_t buff[8];
|
||||
uint16_t out_endpoint_size;
|
||||
uint16_t in_endpoint_size;
|
||||
} cdc_data_interface_type;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cdc_common_interface_type common_interface;
|
||||
cdc_data_interface_type data_interface;
|
||||
cdc_interfacedesc_type cdc_desc;
|
||||
cdc_line_coding_type linecoding;
|
||||
cdc_line_coding_type *puserlinecoding;
|
||||
cdc_state_type state;
|
||||
cdc_data_state_type data_tx_state;
|
||||
cdc_data_state_type data_rx_state;
|
||||
|
||||
uint8_t *rx_data;
|
||||
uint8_t *tx_data;
|
||||
uint32_t rx_len;
|
||||
uint32_t tx_len;
|
||||
}usbh_cdc_type;
|
||||
|
||||
extern usbh_class_handler_type uhost_cdc_class_handler;
|
||||
extern usbh_cdc_type usbh_cdc;
|
||||
void cdc_start_transmission(usbh_core_type *phost, uint8_t *data, uint32_t len);
|
||||
void cdc_start_reception(usbh_core_type *uhost, uint8_t *data, uint32_t len);
|
||||
__weak void cdc_transmit_complete(usbh_core_type *uhost);
|
||||
__weak void cdc_receive_complete(usbh_core_type *uhost);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_class.c
|
||||
* @version v2.0.6
|
||||
* @date 2022-06-28
|
||||
* @version v2.0.7
|
||||
* @date 2022-08-16
|
||||
* @brief usb host hid class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_class.h
|
||||
* @version v2.0.6
|
||||
* @date 2022-06-28
|
||||
* @version v2.0.7
|
||||
* @date 2022-08-16
|
||||
* @brief usb host hid class header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_keyboard.c
|
||||
* @version v2.0.6
|
||||
* @date 2022-06-28
|
||||
* @version v2.0.7
|
||||
* @date 2022-08-16
|
||||
* @brief usb host hid keyboard type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_keyboard.h
|
||||
* @version v2.0.6
|
||||
* @date 2022-06-28
|
||||
* @version v2.0.7
|
||||
* @date 2022-08-16
|
||||
* @brief usb host hid keyboard header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_mouse.c
|
||||
* @version v2.0.6
|
||||
* @date 2022-06-28
|
||||
* @version v2.0.7
|
||||
* @date 2022-08-16
|
||||
* @brief usb host hid mouse type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_mouse.h
|
||||
* @version v2.0.6
|
||||
* @date 2022-06-28
|
||||
* @version v2.0.7
|
||||
* @date 2022-08-16
|
||||
* @brief usb host hid mouse header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_msc_bot_scsi.c
|
||||
* @version v2.0.6
|
||||
* @date 2022-06-28
|
||||
* @version v2.0.7
|
||||
* @date 2022-08-16
|
||||
* @brief usb host msc bulk-only transfer and scsi type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_msc_bot_scsi.h
|
||||
* @version v2.0.6
|
||||
* @date 2022-06-28
|
||||
* @version v2.0.7
|
||||
* @date 2022-08-16
|
||||
* @brief usb host msc bulk-only transfer and scsi header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_msc_class.c
|
||||
* @version v2.0.6
|
||||
* @date 2022-06-28
|
||||
* @version v2.0.7
|
||||
* @date 2022-08-16
|
||||
* @brief usb host msc class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -132,7 +132,7 @@ static usb_sts_type uhost_reset_handler(void *uhost)
|
||||
usb_sts_type status = USB_OK;
|
||||
uint8_t i_index = 0;
|
||||
|
||||
if(puhost->class_handler->pdata)
|
||||
if(puhost->class_handler->pdata == NULL)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_msc_class.h
|
||||
* @version v2.0.6
|
||||
* @date 2022-06-28
|
||||
* @version v2.0.7
|
||||
* @date 2022-08-16
|
||||
* @brief usb host msc class header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
Reference in New Issue
Block a user