![FTDI FT51A Application Note Download Page 159](http://html1.mh-extra.com/html/ftdi/ft51a/ft51a_application-note_2341158159.webp)
Application Note
AN_289 FT51A Programming Guide
Version 1.0
Document Reference No.: FT_000962 Clearance No.: FTDI# 483
158
Copyright © 2015 Future Technology Devices International Limited
Endpoint creation is best placed in this function, as the host will reset a USB device during
enumeration. This allows us to disable and then re-enable an endpoint during a reset or when the
device is first powered up.
This is an example of making an interrupt IN endpoint with a maximum packet size of 8.
void
reset_cb
(uint8_t status)
{
(
void
) status;
USB_free_endpoint(1,
USB_DIR_IN
);
USB_set_state(
DEFAULT
);
/* Make application specific BULK, INTERRUPT or
* ISOCHRONOUS endpoints. */
int_in = USB_create_endpoint(
USB_EP_1
,
USB_EP_INT
,
USB_DIR_IN
,
USB_EP_SIZE_8
);
return
;
}
3.2.5.2
Suspend Call-back
The suspend call-back is used when either the host puts the device into suspend mode or the
device is self-powered and is disconnected from the host.
Any special programming required to handle suspend states should be placed in here.
3.2.5.3
Resume Call-back
The resume call-back is used when either the host moves the device from suspend to resume
mode or the device is self-powered and is reconnected to the host.
Any special programming required for handling resume states should be placed in here.
3.2.6
Main Function
The main function needs to initialise the device then call USB_process() periodically to handle
SETUP requests.
void
main
(
void
)
{
// Initialise FT51
device_initialise();
// Initialise USB function
usb_setup();
// Endless loop.
while
(1)
{
// Check control endpoints and handle SETUPs
USB_process();
};
}
Code required to send data or receive data from non-control endpoints is placed within the while
loop.
The only requirement for the main loop is the that USB_process() is called periodically. The
periodicity of the call must ensure that any SETUP packet received is responded to within the time
limits defined for the call in the USB specification or the class or vendor specification applicable.