AN050
GD32 USBFS&USBHS Firmware Library User Guide
28
usb_class_core usbd_hid_cb
=
{
.
command
=
NO_CMD
,
.
alter_set
=
0U
,
.
init
=
hid_init
,
.
deinit
=
hid_deinit
,
.
req_proc
=
hid_req
,
.
data_in
=
hid_data_in
};
The above initialization could implement initialization, deinitialization, device class request
and data transfer of device class.
5.6.
Data transmission process
After enumeration completed, USB could receive and send data, the process is controlled by
host. Host receive data through sending IN packet to device, and send data through sending
OUT packet. In the follow article, CDC routine briefly describe the data transfer process of
USB data in GD FS library.
5.6.1.
IN direction
In data transfer phase, non-zero endpoint data of IN direction is processed in usbd_in_transc
function. In following figure, data_in callback function actually call the cdc_acm_in function.
Once enter in cdc_acm_in function, it is indicated that some data are sent from device to host,
and then call send function cdc_acm_data_send, so as to send next data packet.
uint8_t
usbd_in_transc
(
usb_core_driver
*
udev
,
uint8_t
ep_num
)
{
if
(
0U
==
ep_num
)
{
usb_transc
*
transc
=
&
udev
->
dev
.
transc_in
[
0
];
/* ...... */
}
else
{
if
((
udev
->
dev
.
cur_status
==
(
uint8_t
)
USBD_CONFIGURED
)
&&
(
udev
->
dev
.
class_core
->
data_in
!=
NULL
))
{
(
void
)
udev
->
dev
.
class_core
->
data_in
(
udev
,
ep_num
);
}
}
return
(
uint8_t
)
USBD_OK
;
}
5.6.2.
OUT direction
In data transfer phase, non-zero endpoint data of OUT direction is processed in