#define USB_SET_VENDOR_NO_DATA (0x0000U)
#define USB_SET_VENDOR (0x0100U)
#define USB_GET_VENDOR (0x0200U)
#define SET_VENDOR_NO_DATA (USB_SET_VENDOR_NO_DATA | USB_HOST_TO_DEV | USB_VENDOR | USB_INTERFACE)
#define SET_VENDOR (USB_SET_VENDOR | USB_HOST_TO_DEV | USB_VENDOR | USB_INTERFACE)
#define GET_VENDOR (USB_GET_VENDOR | USB_DEV_TO_HOST | USB_VENDOR | USB_INTERFACE)
#if (BSP_CFG_RTOS == 2)
void usb_apl_callback (usb_event_info_t * p_api_event, usb_hdl_t cur_task,
usb_onoff_t usb_state)
{
(void) usb_state;
(void) cur_task;
xQueueSend(g_apl_mbx_hdl, (const void *) &p_api_event, (TickType_t) (0));
}
#endif
void usb_pvnd_example (void)
{
#if (BSP_CFG_RTOS == 2)
usb_event_info_t * p_mess;
#endif
usb_event_info_t event_info;
uint8_t bulk_out_pipe = 0;
uint8_t bulk_in_pipe = 0;
uint8_t int_out_pipe = 0;
uint8_t int_in_pipe = 0;
uint16_t buf_type = 0;
uint8_t pipe = 0;
uint8_t is_zlp[2] = {0, 0};
uint16_t used_pipe = 0;
usb_pipe_t pipe_info;
g_usb_on_usb.
open(&g_basic0_ctrl, &g_basic0_cfg);
while (1)
{
#if (BSP_CFG_RTOS == 2)
xQueueReceive(g_apl_mbx_hdl, (void *) &p_mess, portMAX_DELAY);
event_info = *p_mess;
event = event_info.event;
#else
g_usb_on_usb.
eventGet(&event_info, &event);
#endif
switch (event)
{
{
buffer_init();
is_zlp[0] = 0;
is_zlp[1] = 0;
g_usb_on_usb.
usedPipesGet(&g_basic0_ctrl, &used_pipe, ADDRESS1);
for (pipe = START_PIPE; pipe < END_PIPE; pipe++)
{
if (0 != (used_pipe & (1 << pipe)))
{
g_usb_on_usb.
pipeInfoGet(&g_basic0_ctrl, &pipe_info, pipe);
{
{
buf_type = BUF_BULK;
bulk_out_pipe = pipe;
}
else
{
buf_type = BUF_INT;
int_out_pipe = pipe;
}
}
else
{
{
buf_type = BUF_BULK;
bulk_in_pipe = pipe;
}
else
{
buf_type = BUF_INT;
int_in_pipe = pipe;
}
}
}
}
class_request_set_vendor_no_data(&g_basic0_ctrl, event_info.device_address);
break;
}
{
if (FSP_ERR_USB_FAILED != event_info.status)
{
if (bulk_in_pipe == event_info.pipe)
{
buf_type = BUF_BULK;
pipe = bulk_out_pipe;
}
else if (int_in_pipe == event_info.pipe)
{
buf_type = BUF_INT;
pipe = int_out_pipe;
}
else
{
while (1)
{
;
}
}
buffer_check(buf_type, event_info.data_size);
g_usb_on_usb.
pipeWrite(&g_basic0_ctrl, &g_buf[buf_type][0], event_info.data_size, pipe);
}
break;
}
{
if (bulk_out_pipe == event_info.pipe)
{
buf_type = BUF_BULK;
if (1 == is_zlp[buf_type])
{
pipe = bulk_in_pipe;
}
}
else if (int_out_pipe == event_info.pipe)
{
buf_type = BUF_INT;
if (1 == is_zlp[buf_type])
{
pipe = int_in_pipe;
}
}
else
{
}
if (1 == is_zlp[buf_type])
{
is_zlp[buf_type] = 0;
buffer_clear(buf_type);
g_usb_on_usb.
pipeRead(&g_basic0_ctrl, &g_buf[buf_type][0], BUF_SIZE, pipe);
}
else
{
is_zlp[buf_type] = 1;
g_usb_on_usb.
pipeWrite(&g_basic0_ctrl, 0, 0, event_info.pipe);
}
break;
}
{
if (USB_SET_VENDOR_NO_DATA == (event_info.setup.request_type &
USB_BREQUEST))
{
class_request_set_vendor(&g_basic0_ctrl, event_info.device_address);
}
else if (USB_SET_VENDOR == (event_info.setup.request_type &
USB_BREQUEST))
{
class_request_get_vendor(&g_basic0_ctrl, event_info.device_address);
}
else if (USB_GET_VENDOR == (event_info.setup.request_type &
USB_BREQUEST))
{
buffer_init();
g_usb_on_usb.
pipeWrite(&g_basic0_ctrl, &g_buf[BUF_BULK][0], (BUF_SIZE - USB_APL_MXPS),
bulk_out_pipe);
g_usb_on_usb.
pipeWrite(&g_basic0_ctrl, &g_buf[BUF_INT][0], (BUF_SIZE - USB_APL_MXPS), int_out_pipe);
}
else
{
}
break;
}
{
break;
}
default:
{
break;
}
}
}
}
{
usb_setup_t setup;
uint16_t i;
for (i = 0; i < REQ_SIZE; i++)
{
g_request_buf[i] = (uint8_t) i;
}
setup.request_type = SET_VENDOR;
setup.request_value = 0x0000;
setup.request_index = 0x0000;
setup.request_length = REQ_SIZE;
}
static void class_request_set_vendor_no_data (
usb_instance_ctrl_t * p_ctrl, uint8_t device_address)
{
usb_setup_t setup;
uint16_t i;
for (i = 0; i < REQ_SIZE; i++)
{
g_request_buf[i] = (uint8_t) i;
}
setup.request_type = SET_VENDOR_NO_DATA;
setup.request_value = 0x0000;
setup.request_index = 0x0000;
setup.request_length = 0x0000;
}
{
usb_setup_t setup;
uint16_t i;
for (i = 0; i < REQ_SIZE; i++)
{
g_request_buf[i] = 0;
}
setup.request_type = GET_VENDOR;
setup.request_value = 0x0000;
setup.request_index = 0x0000;
setup.request_length = REQ_SIZE;
}
static void buffer_init (void)
{
uint16_t i;
uint16_t j;
for (j = 0; j < 2; j++)
{
for (i = 0; i < BUF_SIZE; i++)
{
g_buf[j][i] = (uint8_t) i;
}
}
}
static void buffer_check (uint16_t buf_type, uint32_t size)
{
uint16_t i;
for (i = 0; i < (uint16_t) size; i++)
{
if ((uint8_t) (i & USB_VALUE_FF) != g_buf[buf_type][i])
{
while (1)
{
;
}
}
}
}
static void buffer_clear (uint16_t buf_type)
{
uint16_t i;
for (i = 0; i < BUF_SIZE; i++)
{
g_buf[buf_type][i] = 0;
}
}