| 881 |
theseven |
1 |
#include "global.h"
|
|
|
2 |
#include "app/umsboot/usbglue.h"
|
|
|
3 |
#include "app/umsboot/ums.h"
|
|
|
4 |
#include "sys/util.h"
|
|
|
5 |
#include UMSBOOT_USB_DRIVER_HEADER
|
|
|
6 |
|
|
|
7 |
static const struct usb_devicedescriptor usb_devicedescriptor __attribute__((section(".dmarodata.usb_devicedescriptor"),aligned(CACHEALIGN_SIZE))) =
|
|
|
8 |
{
|
|
|
9 |
.bLength = sizeof(struct usb_devicedescriptor),
|
|
|
10 |
.bDescriptorType = USB_DESCRIPTOR_TYPE_DEVICE,
|
|
|
11 |
.bcdUSB = 0x0200,
|
|
|
12 |
.bDeviceClass = 0,
|
|
|
13 |
.bDeviceSubClass = 0,
|
|
|
14 |
.bDeviceProtocol = 0,
|
|
|
15 |
.bMaxPacketSize0 = 64,
|
|
|
16 |
.idVendor = UMSBOOT_USB_VENDORID,
|
|
|
17 |
.idProduct = UMSBOOT_USB_PRODUCTID,
|
|
|
18 |
.bcdDevice = UMSBOOT_USB_DEVICEREVISION,
|
|
|
19 |
.iManufacturer = 1,
|
|
|
20 |
.iProduct = 2,
|
|
|
21 |
.iSerialNumber = 0,
|
|
|
22 |
.bNumConfigurations = 1,
|
|
|
23 |
};
|
|
|
24 |
|
|
|
25 |
static struct __attribute__((packed)) _usb_config1_descriptors
|
|
|
26 |
{
|
|
|
27 |
struct usb_configurationdescriptor c1;
|
|
|
28 |
struct usb_interfacedescriptor c1_i0_a0;
|
|
|
29 |
struct usb_endpointdescriptor c1_i0_a0_e1out;
|
|
|
30 |
struct usb_endpointdescriptor c1_i0_a0_e1in;
|
|
|
31 |
} usb_config1_descriptors __attribute__((section(".dmadata.usb_config1_descriptors"),aligned(CACHEALIGN_SIZE))) =
|
|
|
32 |
{
|
|
|
33 |
.c1 =
|
|
|
34 |
{
|
|
|
35 |
.bLength = sizeof(struct usb_configurationdescriptor),
|
|
|
36 |
.bDescriptorType = USB_DESCRIPTOR_TYPE_CONFIGURATION,
|
|
|
37 |
.wTotalLength = sizeof(struct _usb_config1_descriptors),
|
|
|
38 |
.bNumInterfaces = 1,
|
|
|
39 |
.bConfigurationValue = 1,
|
|
|
40 |
.iConfiguration = 0,
|
|
|
41 |
.bmAttributes = { .buspowered = 1, .selfpowered = 1 },
|
|
|
42 |
.bMaxPower = UMSBOOT_USB_MAXCURRENT / 2,
|
|
|
43 |
},
|
|
|
44 |
.c1_i0_a0 =
|
|
|
45 |
{
|
|
|
46 |
.bLength = sizeof(struct usb_interfacedescriptor),
|
|
|
47 |
.bDescriptorType = USB_DESCRIPTOR_TYPE_INTERFACE,
|
|
|
48 |
.bInterfaceNumber = 0,
|
|
|
49 |
.bAlternateSetting = 0,
|
|
|
50 |
.bNumEndpoints = 2,
|
|
|
51 |
.bInterfaceClass = 0x08,
|
|
|
52 |
.bInterfaceSubClass = 0x06,
|
|
|
53 |
.bInterfaceProtocol = 0x50,
|
|
|
54 |
.iInterface = 0,
|
|
|
55 |
},
|
|
|
56 |
.c1_i0_a0_e1out =
|
|
|
57 |
{
|
|
|
58 |
.bLength = sizeof(struct usb_endpointdescriptor),
|
|
|
59 |
.bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT,
|
|
|
60 |
.bEndpointAddress = { .number = UMSBOOT_ENDPOINT_OUT, .direction = USB_ENDPOINT_DIRECTION_OUT },
|
|
|
61 |
.bmAttributes = { .type = USB_ENDPOINT_ATTRIBUTE_TYPE_BULK },
|
|
|
62 |
.wMaxPacketSize = 512,
|
|
|
63 |
.bInterval = 1,
|
|
|
64 |
},
|
|
|
65 |
.c1_i0_a0_e1in =
|
|
|
66 |
{
|
|
|
67 |
.bLength = sizeof(struct usb_endpointdescriptor),
|
|
|
68 |
.bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT,
|
|
|
69 |
.bEndpointAddress = { .number = UMSBOOT_ENDPOINT_IN, .direction = USB_ENDPOINT_DIRECTION_IN },
|
|
|
70 |
.bmAttributes = { .type = USB_ENDPOINT_ATTRIBUTE_TYPE_BULK },
|
|
|
71 |
.wMaxPacketSize = 512,
|
|
|
72 |
.bInterval = 1,
|
|
|
73 |
},
|
|
|
74 |
};
|
|
|
75 |
|
|
|
76 |
static const struct usb_stringdescriptor usb_string_language __attribute__((section(".dmarodata.usb_string_language"),aligned(CACHEALIGN_SIZE))) =
|
|
|
77 |
{
|
|
|
78 |
.bLength = sizeof(usb_string_language) + sizeof(*usb_string_language.wString),
|
|
|
79 |
.bDescriptorType = USB_DESCRIPTOR_TYPE_STRING,
|
|
|
80 |
.wString = { 0x0409 },
|
|
|
81 |
};
|
|
|
82 |
|
|
|
83 |
static const struct usb_stringdescriptor usb_string_vendor __attribute__((section(".dmarodata.usb_string_vendor"),aligned(CACHEALIGN_SIZE))) =
|
|
|
84 |
{
|
|
|
85 |
.bLength = sizeof(usb_string_vendor) + sizeof(*usb_string_vendor.wString) * UMSBOOT_USB_VENDORSTRING_LEN,
|
|
|
86 |
.bDescriptorType = USB_DESCRIPTOR_TYPE_STRING,
|
|
|
87 |
.wString = UMSBOOT_USB_VENDORSTRING,
|
|
|
88 |
};
|
|
|
89 |
|
|
|
90 |
static const struct usb_stringdescriptor usb_string_product __attribute__((section(".dmarodata.usb_string_product"),aligned(CACHEALIGN_SIZE))) =
|
|
|
91 |
{
|
|
|
92 |
.bLength = sizeof(usb_string_product) + sizeof(*usb_string_product.wString) * UMSBOOT_USB_PRODUCTSTRING_LEN,
|
|
|
93 |
.bDescriptorType = USB_DESCRIPTOR_TYPE_STRING,
|
|
|
94 |
.wString = UMSBOOT_USB_PRODUCTSTRING,
|
|
|
95 |
};
|
|
|
96 |
|
|
|
97 |
static const struct usb_stringdescriptor* usb_stringdescriptors[] =
|
|
|
98 |
{
|
|
|
99 |
&usb_string_language,
|
|
|
100 |
&usb_string_vendor,
|
|
|
101 |
&usb_string_product,
|
|
|
102 |
};
|
|
|
103 |
|
|
|
104 |
static const struct usb_endpoint usb_c1_i0_a0_ep1out =
|
|
|
105 |
{
|
|
|
106 |
.number = { .number = UMSBOOT_ENDPOINT_OUT, .direction = USB_ENDPOINT_DIRECTION_OUT },
|
|
|
107 |
.ctrl_request = ums_ep_ctrl_request,
|
|
|
108 |
.xfer_complete = ums_xfer_complete,
|
|
|
109 |
.setup_received = NULL,
|
|
|
110 |
};
|
|
|
111 |
|
|
|
112 |
static const struct usb_endpoint usb_c1_i0_a0_ep1in =
|
|
|
113 |
{
|
|
|
114 |
.number = { .number = UMSBOOT_ENDPOINT_IN, .direction = USB_ENDPOINT_DIRECTION_IN },
|
| 894 |
theseven |
115 |
.ctrl_request = ums_ep_ctrl_request,
|
| 881 |
theseven |
116 |
.xfer_complete = ums_xfer_complete,
|
|
|
117 |
.timeout = ums_timeout,
|
|
|
118 |
};
|
|
|
119 |
|
|
|
120 |
static const struct usb_altsetting usb_c1_i0_a0 =
|
|
|
121 |
{
|
|
|
122 |
.set_altsetting = ums_set_altsetting,
|
|
|
123 |
.unset_altsetting = ums_unset_altsetting,
|
|
|
124 |
.endpoint_count = 2,
|
|
|
125 |
.endpoints =
|
|
|
126 |
{
|
|
|
127 |
&usb_c1_i0_a0_ep1out,
|
|
|
128 |
&usb_c1_i0_a0_ep1in,
|
|
|
129 |
},
|
|
|
130 |
};
|
|
|
131 |
|
|
|
132 |
static void usbglue_bus_reset(const struct usb_instance* data, int highspeed)
|
|
|
133 |
{
|
|
|
134 |
usb_config1_descriptors.c1_i0_a0_e1out.wMaxPacketSize = highspeed ? 512 : 64;
|
|
|
135 |
usb_config1_descriptors.c1_i0_a0_e1in.wMaxPacketSize = highspeed ? 512 : 64;
|
|
|
136 |
}
|
|
|
137 |
|
| 889 |
theseven |
138 |
static const struct usb_interface usb_c1_i0 =
|
| 881 |
theseven |
139 |
{
|
|
|
140 |
.bus_reset = ums_bus_reset,
|
|
|
141 |
.ctrl_request = ums_ctrl_request,
|
|
|
142 |
.altsetting_count = 1,
|
|
|
143 |
.altsettings =
|
|
|
144 |
{
|
|
|
145 |
&usb_c1_i0_a0,
|
|
|
146 |
},
|
|
|
147 |
};
|
|
|
148 |
|
|
|
149 |
static const struct usb_configuration usb_c1 =
|
|
|
150 |
{
|
|
|
151 |
.descriptor = &usb_config1_descriptors.c1,
|
|
|
152 |
.set_configuration = NULL,
|
|
|
153 |
.unset_configuration = NULL,
|
|
|
154 |
.interface_count = 1,
|
|
|
155 |
.interfaces =
|
|
|
156 |
{
|
|
|
157 |
&usb_c1_i0,
|
|
|
158 |
},
|
|
|
159 |
};
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
static UMSBOOT_USB_DRIVER_CONFIG_TYPE usb_driver_config = UMSBOOT_USB_DRIVER_CONFIG;
|
|
|
163 |
|
|
|
164 |
static UMSBOOT_USB_DRIVER_STATE_TYPE usb_driver_state = UMSBOOT_USB_DRIVER_STATE;
|
|
|
165 |
|
| 889 |
theseven |
166 |
static struct usb_state usb_state =
|
|
|
167 |
{
|
|
|
168 |
.interface_altsetting = { 0 },
|
|
|
169 |
};
|
| 881 |
theseven |
170 |
|
|
|
171 |
static union usb_ep0_buffer usb_buffer __attribute__((section(".dmabss.usb_buffer"),aligned(CACHEALIGN_SIZE)));
|
|
|
172 |
|
|
|
173 |
const struct usb_instance usb_data =
|
|
|
174 |
{
|
|
|
175 |
.driver = &UMSBOOT_USB_DRIVER,
|
|
|
176 |
.driver_config = &usb_driver_config,
|
|
|
177 |
.driver_state = &usb_driver_state,
|
|
|
178 |
.state = &usb_state,
|
|
|
179 |
.buffer = &usb_buffer,
|
|
|
180 |
.bus_reset = usbglue_bus_reset,
|
|
|
181 |
.ep0_setup_hook = NULL,
|
|
|
182 |
.configuration_count = 1,
|
|
|
183 |
.stringdescriptor_count = 3,
|
|
|
184 |
.devicedescriptor = &usb_devicedescriptor,
|
|
|
185 |
.stringdescriptors = usb_stringdescriptors,
|
|
|
186 |
.configurations =
|
|
|
187 |
{
|
|
|
188 |
&usb_c1,
|
|
|
189 |
},
|
|
|
190 |
};
|