update version to v2.0.7

This commit is contained in:
Artery-MCU
2022-03-03 19:28:16 +08:00
parent e1d3f6e2c9
commit eb00682e95
2098 changed files with 11432 additions and 6380 deletions

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file printer_class.c
* @version v2.0.6
* @date 2021-12-31
* @version v2.0.7
* @date 2022-02-11
* @brief usb printer class type
**************************************************************************
* Copyright notice & Disclaimer
@@ -40,31 +40,25 @@
* @{
*/
usb_sts_type class_init_handler(void *udev);
usb_sts_type class_clear_handler(void *udev);
usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup);
usb_sts_type class_ept0_tx_handler(void *udev);
usb_sts_type class_ept0_rx_handler(void *udev);
usb_sts_type class_in_handler(void *udev, uint8_t ept_num);
usb_sts_type class_out_handler(void *udev, uint8_t ept_num);
usb_sts_type class_sof_handler(void *udev);
usb_sts_type class_event_handler(void *udev, usbd_event_type event);
static usb_sts_type class_init_handler(void *udev);
static usb_sts_type class_clear_handler(void *udev);
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup);
static usb_sts_type class_ept0_tx_handler(void *udev);
static usb_sts_type class_ept0_rx_handler(void *udev);
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num);
static usb_sts_type class_out_handler(void *udev, uint8_t ept_num);
static usb_sts_type class_sof_handler(void *udev);
static usb_sts_type class_event_handler(void *udev, usbd_event_type event);
/* usb rx and tx buffer */
static uint32_t alt_setting = 0;
static uint8_t g_rx_buff[USBD_OUT_MAXPACKET_SIZE];
static uint16_t g_rxlen;
__IO uint8_t g_tx_completed = 1, g_rx_completed = 0;
uint8_t PRINTER_DEVICE_ID[PRINTER_DEVICE_ID_LEN] =
ALIGNED_HEAD static uint8_t printer_device_id[PRINTER_DEVICE_ID_LEN] ALIGNED_TAIL=
{
0x00, 0x16,
'M', 'F', 'G',':','A','r','t','e', 'r', 'y' ,' ',
'C','M', 'D', ':', 'E', 'S', 'C', 'P', 'O', 'S',' ',
};
static uint32_t g_printer_port_status = 0x18;
uint8_t g_printer_data[USBD_OUT_MAXPACKET_SIZE];
/* static variable */
printer_type printer_struct;
/* usb device class handler */
usbd_class_handler printer_class_handler =
@@ -78,6 +72,7 @@ usbd_class_handler printer_class_handler =
class_out_handler,
class_sof_handler,
class_event_handler,
&printer_struct
};
/**
@@ -85,21 +80,23 @@ usbd_class_handler printer_class_handler =
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
*/
usb_sts_type class_init_handler(void *udev)
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_OUT_MAXPACKET_SIZE);
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_OUT_MAXPACKET_SIZE);
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, g_rx_buff, USBD_OUT_MAXPACKET_SIZE);
usbd_ept_recv(pudev, USBD_PRINTER_BULK_OUT_EPT, pprter->g_rx_buff, USBD_PRINTER_OUT_MAXPACKET_SIZE);
g_tx_completed = 1;
pprter->g_tx_completed = 1;
pprter->g_printer_port_status = 0x18;
return status;
}
@@ -109,7 +106,7 @@ usb_sts_type class_init_handler(void *udev)
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
*/
usb_sts_type class_clear_handler(void *udev)
static usb_sts_type class_clear_handler(void *udev)
{
usb_sts_type status = USB_OK;
usbd_core_type *pudev = (usbd_core_type *)udev;
@@ -129,10 +126,11 @@ usb_sts_type class_clear_handler(void *udev)
* @param setup: setup packet
* @retval status of usb_sts_type
*/
usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
{
usb_sts_type status = USB_OK;
usbd_core_type *pudev = (usbd_core_type *)udev;
printer_type *pprter = (printer_type *)pudev->class_handler->pdata;
switch(setup->bmRequestType & USB_REQ_TYPE_RESERVED)
{
@@ -141,13 +139,13 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
switch(setup->bRequest)
{
case PRINTER_REQ_GET_DEVICE_ID:
usbd_ctrl_send(pudev, PRINTER_DEVICE_ID, PRINTER_DEVICE_ID_LEN);
usbd_ctrl_send(pudev, printer_device_id, PRINTER_DEVICE_ID_LEN);
break;
case PRINTER_REQ_GET_PORT_STATUS:
usbd_ctrl_send(pudev, (uint8_t *)&g_printer_port_status, 1);
usbd_ctrl_send(pudev, (uint8_t *)&pprter->g_printer_port_status, 1);
break;
case PRINTER_REQ_GET_SOFT_RESET:
usbd_ctrl_recv(pudev, g_printer_data, USBD_OUT_MAXPACKET_SIZE);
usbd_ctrl_recv(pudev, pprter->g_printer_data, USBD_PRINTER_OUT_MAXPACKET_SIZE);
break;
default:
usbd_ctrl_unsupport(pudev);
@@ -162,10 +160,10 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
usbd_ctrl_unsupport(pudev);
break;
case USB_STD_REQ_GET_INTERFACE:
usbd_ctrl_send(pudev, (uint8_t *)&alt_setting, 1);
usbd_ctrl_send(pudev, (uint8_t *)&pprter->alt_setting, 1);
break;
case USB_STD_REQ_SET_INTERFACE:
alt_setting = setup->wValue;
pprter->alt_setting = setup->wValue;
break;
default:
break;
@@ -183,7 +181,7 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
*/
usb_sts_type class_ept0_tx_handler(void *udev)
static usb_sts_type class_ept0_tx_handler(void *udev)
{
usb_sts_type status = USB_OK;
@@ -197,7 +195,7 @@ usb_sts_type class_ept0_tx_handler(void *udev)
* @param udev: usb device core handler type
* @retval status of usb_sts_type
*/
usb_sts_type class_ept0_rx_handler(void *udev)
static usb_sts_type class_ept0_rx_handler(void *udev)
{
usb_sts_type status = USB_OK;
@@ -212,14 +210,16 @@ usb_sts_type class_ept0_rx_handler(void *udev)
* @param ept_num: endpoint number
* @retval status of usb_sts_type
*/
usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
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
*/
g_tx_completed = 1;
pprter->g_tx_completed = 1;
return status;
}
@@ -230,16 +230,16 @@ usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
* @param ept_num: endpoint number
* @retval status of usb_sts_type
*/
usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
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;
printer_type *pprter = (printer_type *)pudev->class_handler->pdata;
/* get endpoint receive data length */
g_rxlen = usbd_get_recv_len(pudev, ept_num);
pprter->g_rxlen = usbd_get_recv_len(pudev, ept_num);
/*set recv flag*/
g_rx_completed = 1;
pprter->g_rx_completed = 1;
return status;
}
@@ -249,7 +249,7 @@ usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
* @param udev: to the structure of usbd_core_type
* @retval status of usb_sts_type
*/
usb_sts_type class_sof_handler(void *udev)
static usb_sts_type class_sof_handler(void *udev)
{
usb_sts_type status = USB_OK;
@@ -264,7 +264,7 @@ usb_sts_type class_sof_handler(void *udev)
* @param event: usb device event
* @retval status of usb_sts_type
*/
usb_sts_type class_event_handler(void *udev, usbd_event_type event)
static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
{
usb_sts_type status = USB_OK;
switch(event)
@@ -300,20 +300,21 @@ uint16_t usb_printer_get_rxdata(void *udev, uint8_t *recv_data)
{
uint16_t i_index = 0;
usbd_core_type *pudev = (usbd_core_type *)udev;
uint16_t tmp_len = g_rxlen;
printer_type *pprter = (printer_type *)pudev->class_handler->pdata;
uint16_t tmp_len = 0;
if(g_rx_completed == 0)
if(pprter->g_rx_completed == 0)
{
return 0;
}
g_rx_completed = 0;
tmp_len = g_rxlen;
for(i_index = 0; i_index < g_rxlen; i_index ++)
pprter->g_rx_completed = 0;
tmp_len = pprter->g_rxlen;
for(i_index = 0; i_index < pprter->g_rxlen; i_index ++)
{
recv_data[i_index] = g_rx_buff[i_index];
recv_data[i_index] = pprter->g_rx_buff[i_index];
}
usbd_ept_recv(pudev, USBD_PRINTER_BULK_OUT_EPT, g_rx_buff, USBD_OUT_MAXPACKET_SIZE);
usbd_ept_recv(pudev, USBD_PRINTER_BULK_OUT_EPT, pprter->g_rx_buff, USBD_PRINTER_OUT_MAXPACKET_SIZE);
return tmp_len;
}
@@ -329,9 +330,10 @@ error_status usb_printer_send_data(void *udev, uint8_t *send_data, uint16_t len)
{
error_status status = SUCCESS;
usbd_core_type *pudev = (usbd_core_type *)udev;
if(g_tx_completed)
printer_type *pprter = (printer_type *)pudev->class_handler->pdata;
if(pprter->g_tx_completed)
{
g_tx_completed = 0;
pprter->g_tx_completed = 0;
usbd_ept_send(pudev, USBD_PRINTER_BULK_IN_EPT, send_data, len);
}
else