From c7c3a3526b723b7793f0d4dcbf49f69ea73f3794 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 1 Jan 2012 23:42:02 +0100 Subject: import initial dfu implementation (incomplete) --- usb/device/dfu/dfu.h | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 usb/device/dfu/dfu.h (limited to 'usb/device/dfu/dfu.h') diff --git a/usb/device/dfu/dfu.h b/usb/device/dfu/dfu.h new file mode 100644 index 0000000..00a0622 --- /dev/null +++ b/usb/device/dfu/dfu.h @@ -0,0 +1,110 @@ +#ifndef _USB_DFU_DESC_H +#define _USB_DFU_DESC_H + +#include +#include +#include +#include +#include + +#if 0 +/* This is valid for CCID */ +#define CONFIG_DFU_NUM_APP_IF 1 +#define CONFIG_DFU_NUM_APP_STR 4 +#else +/* This is valid for CDC-Serial */ +#define CONFIG_DFU_NUM_APP_IF 2 +#define CONFIG_DFU_NUM_APP_STR 2 +#endif + +struct USBStringDescriptor { + USBGenericDescriptor hdr; + unsigned short wData[]; +} __attribute__((packed)); + + +#ifdef BOARD_USB_DFU + +#define DFU_NUM_IF 3 + +#define DFU_IF_DESCRIPTORS_STRUCT \ + USBInterfaceDescriptor dfu_interface[DFU_NUM_IF]; + +#define DFU_IF_DESCRIPTORS { \ + { \ + .bLength = sizeof(USBInterfaceDescriptor), \ + .bDescriptorType = USBGenericDescriptor_INTERFACE, \ + .bInterfaceNumber = CONFIG_DFU_NUM_APP_IF, \ + .bAlternateSetting = 0, \ + .bNumEndpoints = 0, \ + .bInterfaceClass = 0xFE, \ + .bInterfaceSubClass = 0x01, \ + .bInterfaceProtocol = 0x01, \ + .iInterface = CONFIG_DFU_NUM_APP_STR, \ + }, \ + { \ + .bLength = sizeof(USBInterfaceDescriptor), \ + .bDescriptorType = USBGenericDescriptor_INTERFACE, \ + .bInterfaceNumber = CONFIG_DFU_NUM_APP_IF+1, \ + .bAlternateSetting = 0, \ + .bNumEndpoints = 0, \ + .bInterfaceClass = 0xFE, \ + .bInterfaceSubClass = 0x01, \ + .bInterfaceProtocol = 0x01, \ + .iInterface = CONFIG_DFU_NUM_APP_STR+1, \ + }, \ + { \ + .bLength = sizeof(USBInterfaceDescriptor), \ + .bDescriptorType = USBGenericDescriptor_INTERFACE, \ + .bInterfaceNumber = CONFIG_DFU_NUM_APP_IF+2, \ + .bAlternateSetting = 0, \ + .bNumEndpoints = 0, \ + .bInterfaceClass = 0xFE, \ + .bInterfaceSubClass = 0x01, \ + .bInterfaceProtocol = 0x01, \ + .iInterface = CONFIG_DFU_NUM_APP_STR+2, \ + }, \ +} + +extern const struct USBStringDescriptor USBDFU_string1; +extern const struct USBStringDescriptor USBDFU_string2; +extern const struct USBStringDescriptor USBDFU_string3; + +#define DFU_NUM_STRINGS 3 +#define DFU_STRING_DESCRIPTORS \ + (const unsigned char *) &USBDFU_string1, \ + (const unsigned char *) &USBDFU_string2, \ + (const unsigned char *) &USBDFU_string3, + +#else /* BOARD_USB_DFU */ + +/* no DFU bootloader is being used */ +#define DFU_NUM_IF 0 +#define DFU_IF_DESCRIPTORS_STRUCT +#define DFU_IF_DESCRIPTORS + +#define DFU_NUM_STRINGS 0 +#define DFU_STRING_DESCRIPTORS + +#endif /* BOARD_USB_DFU */ + +/* The API between the core DFU handler and the board/soc specific code */ + +struct dfu { + uint8_t status; + uint32_t state; + int past_manifest; +}; + +extern struct dfu dfu; + +/* call-backs by the board/SOC */ +extern int USBDFU_handle_dnload(uint16_t val, uint16_t len, int first); +static int USBDFU_handle_upload(uint16_t val, uint16_t len, int first); + +void USBDFU_Runtime_RequestHandler(USBDDriver *pDriver, const USBGenericRequest *request); +void USBDFU_DFU_RequestHandler(USBDDriver *pDriver, const USBGenericRequest *request); + +void USBDFU_Initialize(const USBDDriverDescriptors *pDescriptors, unsigned char *pInterfaces); + +#endif -- cgit v1.2.3