comparison Bootloader/usb.h @ 308:ab4515606277

Fix whitespace Use a consistent standard - Tabs in front for indenting, spaces after for anything else. This way everything stays nice and lined up while also letting users change there prefered indent level. Most of the new files from Haata where already in this format.
author Rowan Decker <Smasher816@gmail.com>
date Sun, 08 Mar 2015 18:40:01 -0700
parents b091bb09c55f
children 66eccdd9ced5
comparison
equal deleted inserted replaced
305:4617ef5e06f1 308:ab4515606277
35 35
36 #define USB_CTRL_REQ_DIR_SHIFT 0 36 #define USB_CTRL_REQ_DIR_SHIFT 0
37 #define USB_CTRL_REQ_TYPE_SHIFT 1 37 #define USB_CTRL_REQ_TYPE_SHIFT 1
38 #define USB_CTRL_REQ_RECP_SHIFT 3 38 #define USB_CTRL_REQ_RECP_SHIFT 3
39 #define USB_CTRL_REQ_CODE_SHIFT 8 39 #define USB_CTRL_REQ_CODE_SHIFT 8
40 #define USB_CTRL_REQ(req_inout, req_type, req_code) \ 40 #define USB_CTRL_REQ(req_inout, req_type, req_code) \
41 (uint16_t) \ 41 (uint16_t) \
42 ((USB_CTRL_REQ_##req_inout << USB_CTRL_REQ_DIR_SHIFT) \ 42 ((USB_CTRL_REQ_##req_inout << USB_CTRL_REQ_DIR_SHIFT) \
43 |(USB_CTRL_REQ_##req_type << USB_CTRL_REQ_TYPE_SHIFT) \ 43 |(USB_CTRL_REQ_##req_type << USB_CTRL_REQ_TYPE_SHIFT) \
44 |(USB_CTRL_REQ_##req_code << USB_CTRL_REQ_CODE_SHIFT)) 44 |(USB_CTRL_REQ_##req_code << USB_CTRL_REQ_CODE_SHIFT))
45 45
46 46
47 47
48 // ----- Macros ----- 48 // ----- Macros -----
49 49
50 #define USB_DESC_STRING(s) \ 50 #define USB_DESC_STRING(s) \
51 (const void *)&(const struct { \ 51 (const void *)&(const struct { \
52 struct usb_desc_string_t dsc; \ 52 struct usb_desc_string_t dsc; \
53 char16_t str[sizeof(s) / 2 - 1]; \ 53 char16_t str[sizeof(s) / 2 - 1]; \
54 }) {{ \ 54 }) {{ \
55 .bLength = sizeof(struct usb_desc_string_t) + \ 55 .bLength = sizeof(struct usb_desc_string_t) + \
56 sizeof(s) - 2, \ 56 sizeof(s) - 2, \
57 .bDescriptorType = USB_DESC_STRING, \ 57 .bDescriptorType = USB_DESC_STRING, \
58 }, \ 58 }, \
59 s \ 59 s \
60 } 60 }
61 #define USB_DESC_STRING_LANG_ENUS USB_DESC_STRING(u"\x0409") 61 #define USB_DESC_STRING_LANG_ENUS USB_DESC_STRING(u"\x0409")
62 #define USB_DESC_STRING_SERIALNO ((const void *)1) 62 #define USB_DESC_STRING_SERIALNO ((const void *)1)
63 63
64 #define USB_FUNCTION_IFACE(iface, iface_off, tx_ep_off, rx_ep_off) \ 64 #define USB_FUNCTION_IFACE(iface, iface_off, tx_ep_off, rx_ep_off) \
65 ((iface_off) + (iface)) 65 ((iface_off) + (iface))
66 #define USB_FUNCTION_TX_EP(ep, iface_off, tx_ep_off, rx_ep_off) \ 66 #define USB_FUNCTION_TX_EP(ep, iface_off, tx_ep_off, rx_ep_off) \
67 ((tx_ep_off) + (ep)) 67 ((tx_ep_off) + (ep))
68 #define USB_FUNCTION_RX_EP(ep, iface_off, tx_ep_off, rx_ep_off) \ 68 #define USB_FUNCTION_RX_EP(ep, iface_off, tx_ep_off, rx_ep_off) \
69 ((rx_ep_off) + (ep)) 69 ((rx_ep_off) + (ep))
70 70
71 71
72 #define USB__INCREMENT(i, _0) (i + 1) 72 #define USB__INCREMENT(i, _0) (i + 1)
73 #define USB__COUNT_IFACE_EP(i, e) \ 73 #define USB__COUNT_IFACE_EP(i, e) \
74 __DEFER(USB__COUNT_IFACE_EP_)(__EXPAND i, e) 74 __DEFER(USB__COUNT_IFACE_EP_)(__EXPAND i, e)
75 #define USB__COUNT_IFACE_EP_(iface, tx_ep, rx_ep, func) \ 75 #define USB__COUNT_IFACE_EP_(iface, tx_ep, rx_ep, func) \
76 (iface + USB_FUNCTION_ ## func ## _IFACE_COUNT, \ 76 (iface + USB_FUNCTION_ ## func ## _IFACE_COUNT, \
77 tx_ep + USB_FUNCTION_ ## func ## _TX_EP_COUNT, \ 77 tx_ep + USB_FUNCTION_ ## func ## _TX_EP_COUNT, \
78 rx_ep + USB_FUNCTION_ ## func ## _RX_EP_COUNT) 78 rx_ep + USB_FUNCTION_ ## func ## _RX_EP_COUNT)
79 #define USB__GET_FUNCTION_IFACE_COUNT(iter, func) \ 79 #define USB__GET_FUNCTION_IFACE_COUNT(iter, func) \
80 USB_FUNCTION_ ## func ## _IFACE_COUNT + 80 USB_FUNCTION_ ## func ## _IFACE_COUNT +
81 81
82 #define USB__DEFINE_FUNCTION_DESC(iter, func) \ 82 #define USB__DEFINE_FUNCTION_DESC(iter, func) \
83 USB_FUNCTION_DESC_ ## func ## _DECL __CAT(__usb_func_desc, __COUNTER__); 83 USB_FUNCTION_DESC_ ## func ## _DECL __CAT(__usb_func_desc, __COUNTER__);
84 #define USB__INIT_FUNCTION_DESC(iter, func) \ 84 #define USB__INIT_FUNCTION_DESC(iter, func) \
85 USB_FUNCTION_DESC_ ## func iter, 85 USB_FUNCTION_DESC_ ## func iter,
86 86
87 #define USB__DEFINE_CONFIG_DESC(confignum, name, ...) \ 87 #define USB__DEFINE_CONFIG_DESC(confignum, name, ...) \
88 &((const struct name { \ 88 &((const struct name { \
89 struct usb_desc_config_t config; \ 89 struct usb_desc_config_t config; \
90 __REPEAT_INNER(, __EAT, USB__DEFINE_FUNCTION_DESC, __VA_ARGS__) \ 90 __REPEAT_INNER(, __EAT, USB__DEFINE_FUNCTION_DESC, __VA_ARGS__) \
91 }){ \ 91 }){ \
92 .config = { \ 92 .config = { \
93 .bLength = sizeof(struct usb_desc_config_t), \ 93 .bLength = sizeof(struct usb_desc_config_t), \
94 .bDescriptorType = USB_DESC_CONFIG, \ 94 .bDescriptorType = USB_DESC_CONFIG, \
95 .wTotalLength = sizeof(struct name), \ 95 .wTotalLength = sizeof(struct name), \
96 .bNumInterfaces = __REPEAT_INNER(, __EAT, USB__GET_FUNCTION_IFACE_COUNT, __VA_ARGS__) 0, \ 96 .bNumInterfaces = __REPEAT_INNER(, __EAT, USB__GET_FUNCTION_IFACE_COUNT, __VA_ARGS__) 0, \
97 .bConfigurationValue = confignum, \ 97 .bConfigurationValue = confignum, \
98 .iConfiguration = 0, \ 98 .iConfiguration = 0, \
99 .one = 1, \ 99 .one = 1, \
100 .bMaxPower = 50 \ 100 .bMaxPower = 50 \
101 }, \ 101 }, \
102 __REPEAT_INNER((0, 0, 0), USB__COUNT_IFACE_EP, USB__INIT_FUNCTION_DESC, __VA_ARGS__) \ 102 __REPEAT_INNER((0, 0, 0), USB__COUNT_IFACE_EP, USB__INIT_FUNCTION_DESC, __VA_ARGS__) \
103 }).config 103 }).config
104 104
105 105
106 #define USB__DEFINE_CONFIG(iter, args) \ 106 #define USB__DEFINE_CONFIG(iter, args) \
107 __DEFER(USB__DEFINE_CONFIG_)(iter, __EXPAND args) 107 __DEFER(USB__DEFINE_CONFIG_)(iter, __EXPAND args)
108 108
109 #define USB__DEFINE_CONFIG_(confignum, initfun, ...) \ 109 #define USB__DEFINE_CONFIG_(confignum, initfun, ...) \
110 &(const struct usbd_config){ \ 110 &(const struct usbd_config){ \
111 .init = initfun, \ 111 .init = initfun, \
112 .desc = USB__DEFINE_CONFIG_DESC( \ 112 .desc = USB__DEFINE_CONFIG_DESC( \
113 confignum, \ 113 confignum, \
114 __CAT(__usb_desc, __COUNTER__), \ 114 __CAT(__usb_desc, __COUNTER__), \
115 __VA_ARGS__) \ 115 __VA_ARGS__) \
116 }, 116 },
117 117
118 #define USB_INIT_DEVICE(vid, pid, manuf, product, ...) \ 118 #define USB_INIT_DEVICE(vid, pid, manuf, product, ...) \
119 { \ 119 { \
120 .dev_desc = &(const struct usb_desc_dev_t){ \ 120 .dev_desc = &(const struct usb_desc_dev_t){ \
121 .bLength = sizeof(struct usb_desc_dev_t), \ 121 .bLength = sizeof(struct usb_desc_dev_t), \
122 .bDescriptorType = USB_DESC_DEV, \ 122 .bDescriptorType = USB_DESC_DEV, \
123 .bcdUSB = { .maj = 2 }, \ 123 .bcdUSB = { .maj = 2 }, \
124 .bDeviceClass = USB_DEV_CLASS_SEE_IFACE, \ 124 .bDeviceClass = USB_DEV_CLASS_SEE_IFACE, \
125 .bDeviceSubClass = USB_DEV_SUBCLASS_SEE_IFACE, \ 125 .bDeviceSubClass = USB_DEV_SUBCLASS_SEE_IFACE, \
126 .bDeviceProtocol = USB_DEV_PROTO_SEE_IFACE, \ 126 .bDeviceProtocol = USB_DEV_PROTO_SEE_IFACE, \
127 .bMaxPacketSize0 = EP0_BUFSIZE, \ 127 .bMaxPacketSize0 = EP0_BUFSIZE, \
128 .idVendor = vid, \ 128 .idVendor = vid, \
129 .idProduct = pid, \ 129 .idProduct = pid, \
130 .bcdDevice = { .raw = 0 }, \ 130 .bcdDevice = { .raw = 0 }, \
131 .iManufacturer = 1, \ 131 .iManufacturer = 1, \
132 .iProduct = 2, \ 132 .iProduct = 2, \
133 .iSerialNumber = 3, \ 133 .iSerialNumber = 3, \
134 .bNumConfigurations = __PP_NARG(__VA_ARGS__), \ 134 .bNumConfigurations = __PP_NARG(__VA_ARGS__), \
135 }, \ 135 }, \
136 .string_descs = (const struct usb_desc_string_t * const []){ \ 136 .string_descs = (const struct usb_desc_string_t * const []){ \
137 USB_DESC_STRING_LANG_ENUS, \ 137 USB_DESC_STRING_LANG_ENUS, \
138 USB_DESC_STRING(manuf), \ 138 USB_DESC_STRING(manuf), \
139 USB_DESC_STRING(product), \ 139 USB_DESC_STRING(product), \
140 USB_DESC_STRING_SERIALNO, \ 140 USB_DESC_STRING_SERIALNO, \
141 NULL \ 141 NULL \
142 }, \ 142 }, \
143 .configs = { \ 143 .configs = { \
144 __REPEAT(1, USB__INCREMENT, USB__DEFINE_CONFIG, __VA_ARGS__) \ 144 __REPEAT(1, USB__INCREMENT, USB__DEFINE_CONFIG, __VA_ARGS__) \
145 NULL \ 145 NULL \
146 } \ 146 } \
147 } 147 }
148 148
149 149
150 150
151 // ----- Structs & Enumerations ----- 151 // ----- Structs & Enumerations -----
218 CTASSERT_SIZE_BYTE(struct usb_desc_generic_t, 2); 218 CTASSERT_SIZE_BYTE(struct usb_desc_generic_t, 2);
219 219
220 struct usb_desc_dev_t { 220 struct usb_desc_dev_t {
221 uint8_t bLength; 221 uint8_t bLength;
222 enum usb_desc_type bDescriptorType : 8; /* = USB_DESC_DEV */ 222 enum usb_desc_type bDescriptorType : 8; /* = USB_DESC_DEV */
223 struct usb_bcd_t bcdUSB; /* = 0x0200 */ 223 struct usb_bcd_t bcdUSB; /* = 0x0200 */
224 enum usb_dev_class bDeviceClass : 8; 224 enum usb_dev_class bDeviceClass : 8;
225 enum usb_dev_subclass bDeviceSubClass : 8; 225 enum usb_dev_subclass bDeviceSubClass : 8;
226 enum usb_dev_proto bDeviceProtocol : 8; 226 enum usb_dev_proto bDeviceProtocol : 8;
227 uint8_t bMaxPacketSize0; 227 uint8_t bMaxPacketSize0;
228 uint16_t idVendor; 228 uint16_t idVendor;
288 CTASSERT_SIZE_BYTE(struct usb_desc_iface_t, 9); 288 CTASSERT_SIZE_BYTE(struct usb_desc_iface_t, 9);
289 289
290 struct usb_desc_config_t { 290 struct usb_desc_config_t {
291 uint8_t bLength; 291 uint8_t bLength;
292 enum usb_desc_type bDescriptorType : 8; /* = USB_DESC_CONFIG */ 292 enum usb_desc_type bDescriptorType : 8; /* = USB_DESC_CONFIG */
293 uint16_t wTotalLength; /* size of config, iface, ep */ 293 uint16_t wTotalLength; /* size of config, iface, ep */
294 uint8_t bNumInterfaces; 294 uint8_t bNumInterfaces;
295 uint8_t bConfigurationValue; 295 uint8_t bConfigurationValue;
296 uint8_t iConfiguration; 296 uint8_t iConfiguration;
297 struct { 297 struct {
298 uint8_t _rsvd0 : 5; 298 uint8_t _rsvd0 : 5;
299 uint8_t remote_wakeup : 1; 299 uint8_t remote_wakeup : 1;
300 uint8_t self_powered : 1; 300 uint8_t self_powered : 1;
301 uint8_t one : 1; /* = 1 for historical reasons */ 301 uint8_t one : 1; /* = 1 for historical reasons */
302 }; 302 };
303 uint8_t bMaxPower; /* units of 2mA */ 303 uint8_t bMaxPower; /* units of 2mA */
304 } __packed; 304 } __packed;
305 CTASSERT_SIZE_BYTE(struct usb_desc_config_t, 9); 305 CTASSERT_SIZE_BYTE(struct usb_desc_config_t, 9);
306 306
307 struct usb_desc_string_t { 307 struct usb_desc_string_t {
308 uint8_t bLength; 308 uint8_t bLength;