fx2usbdfu.h
The fx2usbdfu.h header contains USB DFU interface support code for the Cypress FX2 series. When using this header, the fx2, fx2usb, and fx2usbdfu libraries must be linked in.
Reference
Typedefs
-
typedef struct usb_dfu_iface_state usb_dfu_iface_state_t
Functions
-
bool usb_dfu_setup(usb_dfu_iface_state_t *state, struct usb_req_setup *request)
Handle USB Device Firmware Update interface SETUP packets. This function makes the appropriate changes to the state and returns
trueif a SETUP packet addressed this interface, or returnsfalseotherwise.
-
void usb_dfu_setup_deferred(usb_dfu_iface_state_t *state)
Handle USB Device Firmware Update interface SETUP packets that perform lengthy operations (i.e. actual firmware upload/download).
Variables
-
usb_dfu_iface_state_t usb_dfu_iface_state
The global DFU configuration, defined in the application code. It only makes sense for a single device to expose a single DFU interface at a time.
-
struct usb_dfu_iface_state
- #include <fx2usbdfu.h>
State of an USB Device Firmware Upgrade interface.
Public Members
-
uint8_t interface
The bInterfaceNumber field corresponding to this interface in runtime mode. (In upgrade mode, only one interface must be exported, so this field is ignored.)
-
usb_dfu_status_t (*firmware_upload)(uint32_t offset, uint8_t *data, uint16_t *length)
Firmware upload function. This function reads the firmware block at
offsetof requestedlengthintodata. When end of firmware is reached, this function should report this a block size shorter than providedlengthby changing it.The
offsetargument is maintained internally by this library and is increased after eachfirmware_uploadcall bylength; it is not related to thewBlockNumfield fromDFU_UPLOADrequest.The firmware read out by this function must be in a format identical to that accepted by the
firmware_dnloadfunction to be DFU compliant.This function should return
USB_DFU_STATUS_OKif the firmware could be read, and one of the otherenum usb_dfu_statusvalues otherwise.
-
usb_dfu_status_t (*firmware_dnload)(uint32_t offset, uint8_t *data, uint16_t length)
Firmware download function. This function writes the firmware block at
offsetfromdatathat islengthbytes long, which may be no greater thanwTransferSizefield in the DFU functional descriptor. If this function receives a block lenght of zero, it must validate whether it has received the complete firmware.The
offsetargument is maintained internally by this library and is increased after eachfirmware_dnloadcall bylength; it is not related to thewBlockNumfield fromDFU_DNLOADrequest.This function should return
USB_DFU_STATUS_OKif the firmware could be written (or, in case oflength == 0, if the complete firmware was downloaded), and one of the otherenum usb_dfu_statusvalues otherwise.
-
usb_dfu_status_t (*firmware_manifest)(void)
Firmware manifestation function. This function could perform any application-specific actions required to finish updating firmware, such as changing the boot address.
This function should return
USB_DFU_STATUS_OKif the firmware could be manifested, and one of the otherenum usb_dfu_statusvalues otherwise.If this callback is set to
NULL, the behavior is the same as if the callback was implemented as an empty function returningUSB_DFU_STATUS_OK.
-
enum usb_dfu_state state
State of the DFU interface, as per DFU specification.
-
uint8_t interface