![FTDI FT51A Скачать руководство пользователя страница 151](http://html1.mh-extra.com/html/ftdi/ft51a/ft51a_application-note_2341158151.webp)
Application Note
AN_289 FT51A Programming Guide
Version 1.0
Document Reference No.: FT_000962 Clearance No.: FTDI# 483
150
Copyright © 2015 Future Technology Devices International Limited
3.2
USB Applications
An application which implements a USB device with the FTDI USB Library on the FT51A must
include the following parts of the FT51A libraries:
-
Include the ft51_interrupt.c file from the top-level of the library. This is required to
implement the interrupt handler for the USB device.
-
Add the general_config_device_initialise.c file from the Configuration Library.
-
Add the following files from the USB Library:
o
usb_address.c
o
usb_configuration.c
o
usb_endpoint_features.c
o
usb_endpoint.c
o
usb_initialise.c
o
usb_isr.c
o
usb_process.c
o
usb_state.c
o
usb_transfer.c
The application must perform the following operations:
-
Call device_initialise() from the Configuration Library to initialise the FT51A device.
-
Initialise the device, configuration and string descriptors.
-
Call USB_initialise() function to start the USB device function
o
Provide callback functions for standard SETUP requests from the host.
-
Call the USB_process() function periodically.
If vendor or class SETUP requests are required by the host driver then additional handlers must be
implemented for these.
The examples in this section are given in such a way that the descriptors defined in section 3.2.2
can be used in the call-back code in section 3.2.2.
3.2.1
Initialising USB Device
The USB Library provides a USB_initialise() function which will setup the USB device for use by an
application. The call-backs are nominated, interrupt handler setup and control endpoints created.
A setup routine for a typical USB device may look like this:
void
usb_setup
(
void
)
{
USB_ctx usb_ctx;
memset
(&usb_ctx, 0,
sizeof
(usb_ctx));
usb_ctx.standard_req = standard_req_cb;
// required
usb_ctx.class_req = class_req_cb;
// optional
usb_ctx.vendor_req = vendor_req_cb;
// optional
usb_ctx.suspend = suspend_cb;
// optional
usb_ctx.resume = resume_cb;
// optional
usb_ctx.reset = reset_cb;
// optional
usb_ctx.lpm = NULL;
// Hub disabled
usb_ctx.hub_en.mask.hub_enable = 0;
usb_ctx.hub_en.mask.hub_CompdDev = 1;
usb_ctx.hub_en.mask.hub_RmtWkUpEn = 0;
// Initialise the USB device with a control endpoint size
// of 8 bytes. This must match the size for bMaxPacketSize0
// defined in the device descriptor.
usb_ctx.ep_size =
USB_EP_SIZE_8
;