fx2usb.h¶
The fx2usb.h
header contains USB support code for the Cypress FX2 series. When using this header, the fx2
and fx2usb
libraries must be linked in.
Callback resolution¶
This header defines a number of callback functions, which requests the linker to locate a implementation for every of them. If you provide a callback explicitly, this callback will be used; if you do not, the linker will use the default one from the fx2usb
library. Not all callbacks have default implementations.
Reference¶
Defines
-
SETUP_EP0_IN_DESC(addr)¶
Configure EP0 for an IN transfer from RAM of an USB descriptor of the following types:
Device
Device Qualifier
Configuration
Other Speed Configuration
String
Note that
addr
must be word-aligned.
-
SETUP_EP0_IN_DATA(addr, length)¶
Configure EP0 for an IN transfer from RAM of data of arbitrary length. Note that
addr
must be word-aligned.
-
SETUP_EP0_BUF(length)¶
Configure EP0 for an IN or OUT transfer from or to
EP0BUF
. For an OUT transfer, specifylength
as0
.
-
ACK_EP0()¶
Acknowledge an EP0 SETUP or OUT transfer.
-
STALL_EP0()¶
Indicate an error in response to a EP0 transfer.
Typedefs
-
typedef const char *const usb_ascii_string_c¶
-
typedef const struct usb_configuration usb_configuration_c¶
-
typedef const struct usb_configuration *const usb_configuration_set_c¶
-
typedef const struct usb_descriptor_set usb_descriptor_set_c¶
Functions
-
void usb_init(bool disconnect)¶
Initialize the firmware USB stack. This performs the following:
enables USB interrupts handled by the support code,
takes EP0 under software control,
disconnects (if requested) and connects (if necessary).
-
uint8_t *EPnCS_for_n(uint8_t n)¶
Return a EPnCS register for given USB endpoint index, or 0 if no such endpoint exists.
-
void usb_serve_descriptor(usb_descriptor_set_c *set, enum usb_descriptor type, uint8_t index)¶
Helper function for returning descriptors from a set of C structure definitions. This function relaxes all hardware restrictions on descriptor layout by copying the requested descriptor(s) into the scratch RAM. Sets up an EP0 IN transfer if a descriptor is found, stalls EP0 otherwise.
-
void usb_reset_data_toggles(usb_descriptor_set_c *set, uint8_t interface, uint8_t alt_setting)¶
Helper function for resetting the endpoint data toggles for a subset of endpoints defined by the configuration value or interface number and alternate setting, which is necessary when processing a Set Configuration or Set Interface request. This function resets the endpoint toggles for the configuration value
usb_config_value
, and (ifinterface == 0xff && alt_setting == 0xff
) all endpoints, or (otherwise) all endpoints assigned to interface with fieldsbInterfaceNumber == interface && bAlternateSetting == alt_setting
.
-
void handle_usb_get_descriptor(enum usb_descriptor type, uint8_t index)¶
Callback for the standard Get Descriptor request. This callback has a default implementation that returns descriptors from a global
const struct usb_descriptor_set usb_descriptor_set = { ... };
. Seeusb_serve_descriptor
.
-
bool handle_usb_set_configuration(uint8_t config_value)¶
Callback for the standard Set Configuration request. This callback has a default implementation that sets
usb_config_value
toconfig_value
and returnstrue
ifconfig_value
is 0 or 1, and returnsfalse
otherwise.The default implementation resets the data toggles using
usb_reset_data_toggles
and the global descriptor set; seehandle_usb_get_descriptor
.
-
void handle_usb_get_configuration()¶
Callback for the standard Get Configuration request. This callback has a default implementation that sets up an EP0 IN transfer with value
usb_config_value
.
-
bool handle_usb_set_interface(uint8_t interface, uint8_t alt_setting)¶
Callback for the standard Set Interface request. This callback has a default implementation that returns
true
ifalt_setting == 0
, and returnsfalse
otherwise.The default implementation resets the data toggles using
usb_reset_data_toggles
and the global descriptor set; seehandle_usb_get_descriptor
.
-
void handle_usb_get_interface(uint8_t interface)¶
Callback for the standard Get Interface request. This callback has a default implementation that sets up an EP0 IN transfer with alternate setting number
0
.
-
bool handle_usb_clear_endpoint_halt(uint8_t endpoint)¶
Callback for the standard Clear Feature - Endpoint - Endpoint Halt request. This callback has a default implementation that acknowledges the transfer and returns
true
.The data toggle and the stall bit are reset by the interrupt handler if the handler returns
true
.
-
void handle_usb_setup(struct usb_req_setup *request)¶
Callback for non-standard setup requests. This callback has a default implementation that stalls EP0.
Variables
-
bool usb_self_powered¶
Status variable indicating whether the device is currently self-powered. The value of this variable is returned via the standard Get Status - Device request.
-
bool usb_remote_wakeup¶
Status variable indicating whether the device is configured for remote wakeup. The value of this variable is returned via the standard Get Status - Device request.
-
uint8_t usb_config_value¶
Status variable indicating whether the device is in Address state (if the value is 0) or Configured state (the value corresponds to
bConfigurationValue
field of the descriptor of the selected configuration).
-
struct usb_configuration¶
- #include <fx2usb.h>
An USB configuration descriptor. The USB configuration descriptor is followed by the interface, endpoint, and functional descriptors; these are laid out in the way they should be returned in response to the Get Configuration request.
Public Members
-
struct usb_desc_configuration desc¶
-
union usb_configuration::usb_config_item items[]¶
-
union usb_config_item¶
- #include <fx2usb.h>
Public Members
-
usb_desc_generic_c *generic¶
-
usb_desc_interface_c *interface¶
-
usb_desc_endpoint_c *endpoint¶
-
usb_desc_generic_c *generic¶
-
struct usb_desc_configuration desc¶
-
struct usb_descriptor_set¶
- #include <fx2usb.h>
A group of USB descriptors for a single device.
Public Members
-
usb_desc_device_c *device¶
-
usb_desc_device_qualifier_c *device_qualifier¶
-
uint8_t config_count¶
-
usb_configuration_set_c *configs¶
-
uint8_t string_count¶
-
usb_ascii_string_c *strings¶
-
usb_desc_device_c *device¶