dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_usb_defs.h
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #ifndef PIOS_USB_DEFS_H
29 #define PIOS_USB_DEFS_H
30 
31 #include "board_usb_ids.h"
32 #include <stdint.h> /* uint*_t */
33 
35  USB_DESC_TYPE_DEVICE = 0x01,
37  USB_DESC_TYPE_STRING = 0x03,
40  USB_DESC_TYPE_IAD = 0x0B,
44 } __attribute__((packed));
45 
50 } __attribute__((packed));
51 
57 } __attribute__((packed));
58 
62  USB_EP_ATTR_TT_BULK = 0x02,
64 } __attribute__((packed));
65 
66 /* Standard macros to convert from host endian to USB endian (ie. little endian) */
67 #if __BIG_ENDIAN__
68 #define htousbs(v) ((uint16_t)(\
69  ((((v) >> 0) & 0xFF) << 8) | \
70  ((((v) >> 8) & 0xFF) << 0)))
71 #define htousbl(v) ((uint32_t)(\
72  ((((v) >> 0) & 0xFF) << 24) | \
73  ((((v) >> 8) & 0xFF) << 16) | \
74  ((((v) >> 16) & 0xFF) << 8) | \
75  ((((v) >> 24) & 0xFF) << 0)))
76 #else
77 #define htousbs(v) (v)
78 #define htousbl(v) (v)
79 #endif
80 
81 #define USB_EP_IN(ep) ((uint8_t) (0x80 | ((ep) & 0xF)))
82 #define USB_EP_OUT(ep) ((uint8_t) (0x00 | ((ep) & 0xF)))
83 
84 #define HID_ITEM_TYPE_MAIN 0x0
85 #define HID_ITEM_TYPE_GLOBAL 0x1
86 #define HID_ITEM_TYPE_LOCAL 0x2
87 #define HID_ITEM_TYPE_RSVD 0x3
88 
89 #define HID_TAG_GLOBAL_USAGE_PAGE 0x0 /* 0b0000 */
90 #define HID_TAG_GLOBAL_LOGICAL_MIN 0x1 /* 0b0001 */
91 #define HID_TAG_GLOBAL_LOGICAL_MAX 0x2 /* 0b0010 */
92 #define HID_TAG_GLOBAL_PHYS_MIN 0x3 /* 0b0011 */
93 #define HID_TAG_GLOBAL_PHYS_MAX 0x4 /* 0b0100 */
94 #define HID_TAG_GLOBAL_UNIT_EXP 0x5 /* 0b0101 */
95 #define HID_TAG_GLOBAL_UNIT 0x6 /* 0b0110 */
96 #define HID_TAG_GLOBAL_REPORT_SIZE 0x7 /* 0b0111 */
97 #define HID_TAG_GLOBAL_REPORT_ID 0x8 /* 0b1000 */
98 #define HID_TAG_GLOBAL_REPORT_CNT 0x9 /* 0b1001 */
99 #define HID_TAG_GLOBAL_PUSH 0xA /* 0b1010 */
100 #define HID_TAG_GLOBAL_POP 0xB /* 0b1011 */
101 
102 #define HID_TAG_MAIN_INPUT 0x8 /* 0b1000 */
103 #define HID_TAG_MAIN_OUTPUT 0x9 /* 0b1001 */
104 #define HID_TAG_MAIN_COLLECTION 0xA /* 0b1010 */
105 #define HID_TAG_MAIN_FEATURE 0xB /* 0b1011 */
106 #define HID_TAG_MAIN_ENDCOLLECTION 0xC /* 0b1100 */
107 
108 #define HID_TAG_LOCAL_USAGE 0x0 /* 0b0000 */
109 #define HID_TAG_LOCAL_USAGE_MIN 0x1 /* 0b0001 */
110 #define HID_TAG_LOCAL_USAGE_MAX 0x2 /* 0b0010 */
111 #define HID_TAG_LOCAL_DESIG_INDEX 0x3 /* 0b0011 */
112 #define HID_TAG_LOCAL_DESIG_MIN 0x4 /* 0b0100 */
113 #define HID_TAG_LOCAL_DESIG_MAX 0x5 /* 0b0101 */
114 /* There is no value defined for 0x6 */
115 #define HID_TAG_LOCAL_STRING_INDEX 0x7 /* 0b0111 */
116 #define HID_TAG_LOCAL_STRING_MIN 0x8 /* 0b1000 */
117 #define HID_TAG_LOCAL_STRING_MAX 0x9 /* 0b1001 */
118 #define HID_TAG_LOCAL_DELIMITER 0xA /* 0b1010 */
119 
120 #define HID_TAG_RSVD 0xF /* 0b1111 */
121 
122 #define HID_ITEM_SIZE_0 0
123 #define HID_ITEM_SIZE_1 1
124 #define HID_ITEM_SIZE_2 2
125 #define HID_ITEM_SIZE_4 3 /* Yes, 4 bytes is represented with a size field = 3 */
126 
127 #define HID_SHORT_ITEM(tag,type,size) (\
128  (((tag) & 0xF) << 4) | \
129  (((type) & 0x3) << 2) | \
130  (((size) & 0x3) << 0))
131 
132 /* Long items have a fixed prefix */
133 #define HID_LONG_ITEM HID_SHORT_ITEM(HID_TAG_RSVD, HID_ITEM_TYPE_RSVD, HID_ITEM_SIZE_2)
134 
135 #define HID_MAIN_ITEM_0(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_MAIN, HID_ITEM_SIZE_0)
136 #define HID_MAIN_ITEM_1(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_MAIN, HID_ITEM_SIZE_1)
137 #define HID_MAIN_ITEM_2(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_MAIN, HID_ITEM_SIZE_2)
138 #define HID_MAIN_ITEM_4(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_MAIN, HID_ITEM_SIZE_4)
139 
140 #define HID_GLOBAL_ITEM_0(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_GLOBAL, HID_ITEM_SIZE_0)
141 #define HID_GLOBAL_ITEM_1(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_GLOBAL, HID_ITEM_SIZE_1)
142 #define HID_GLOBAL_ITEM_2(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_GLOBAL, HID_ITEM_SIZE_2)
143 #define HID_GLOBAL_ITEM_4(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_GLOBAL, HID_ITEM_SIZE_4)
144 
145 #define HID_LOCAL_ITEM_0(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_LOCAL, HID_ITEM_SIZE_0)
146 #define HID_LOCAL_ITEM_1(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_LOCAL, HID_ITEM_SIZE_1)
147 #define HID_LOCAL_ITEM_2(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_LOCAL, HID_ITEM_SIZE_2)
148 #define HID_LOCAL_ITEM_4(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_LOCAL, HID_ITEM_SIZE_4)
149 
151  uint8_t bLength;
153  uint16_t bcdUSB;
154  uint8_t bDeviceClass;
158  uint16_t idVendor;
159  uint16_t idProduct;
160  uint16_t bcdDevice;
161  uint8_t iManufacturer;
162  uint8_t iProduct;
163  uint8_t iSerialNumber;
165 } __attribute__((packed));
166 
168  uint8_t bLength;
170  uint16_t wTotalLength;
171  uint8_t bNumInterfaces;
173  uint8_t iConfiguration;
174  uint8_t bmAttributes;
175  uint8_t bMaxPower;
176 } __attribute__((packed));
177 
179  uint8_t bLength;
183  uint8_t bFunctionClass;
186  uint8_t iInterface;
187 } __attribute__((packed));
188 
190  uint8_t bLength;
194  uint8_t bNumEndpoints;
198  uint8_t iInterface;
199 } __attribute__((packed));
200 
201 struct usb_hid_desc {
202  uint8_t bLength;
204  uint16_t bcdHID;
205  uint8_t bCountryCode;
208  uint16_t wItemLength;
209 } __attribute__((packed));
210 
212  uint8_t bLength;
215  uint8_t bmAttributes;
216  uint16_t wMaxPacketSize;
217  uint8_t bInterval;
218 } __attribute__((packed));
219 
221  uint8_t bmRequestType;
222  uint8_t bRequest;
223  uint16_t wValue;
224  uint16_t wIndex;
225  uint16_t wLength;
226 } __attribute__((packed));
227 
228 #define USB_REQ_TYPE_STANDARD 0x00
229 #define USB_REQ_TYPE_CLASS 0x20
230 #define USB_REQ_TYPE_VENDOR 0x40
231 #define USB_REQ_TYPE_MASK 0x60
232 
233 #define USB_REQ_RECIPIENT_DEVICE 0x00
234 #define USB_REQ_RECIPIENT_INTERFACE 0x01
235 #define USB_REQ_RECIPIENT_ENDPOINT 0x02
236 #define USB_REQ_RECIPIENT_MASK 0x03
237 
241  /* what is 0x02? */
243  /* what is 0x04? */
252 };
253 
258  /* 0x04-0x08 Reserved */
262 };
263 
267 
269 };
270 
272  uint8_t bLength;
275  uint16_t bcdCDC;
276 } __attribute__((packed));
277 
279  uint8_t bLength;
282  uint8_t bmCapabilities;
283  uint8_t bDataInterface;
284 } __attribute__((packed));
285 
287  uint8_t bLength;
290  uint8_t bmCapabilities;
291 } __attribute__((packed));
292 
294  uint8_t bLength;
299 } __attribute__((packed));
300 
301 #define USB_LANGID_ENGLISH_US 0x0409
302 
304  uint8_t bLength;
306  uint16_t bLangID;
307 } __attribute__((packed));
308 
310  uint32_t dwDTERate;
311  uint8_t bCharFormat;
312  uint8_t bParityType;
313  uint8_t bDataBits;
314 } __attribute__((packed));
315 
320 } __attribute__((packed));
321 
328 } __attribute__((packed));
329 
331  uint8_t bmRequestType;
332  uint8_t bNotification;
333  uint16_t wValue;
334  uint16_t wIndex;
335  uint16_t wLength;
336  uint16_t bmUartState;
337 } __attribute__((packed));
338 
341 } __attribute__((packed));
342 
344  /* OpenPilot Boards */
346  /* Board ID 2 may be unused or AHRS */
351 } __attribute__((packed));
352 
357 } __attribute__((packed));
358 
359 #define USB_OP_DEVICE_VER(board_id, board_mode) (\
360  ((board_id & 0xFF) << 8) | \
361  ((board_mode & 0xFF) << 0))
362 
363 #endif /* PIOS_USB_DEFS_H */
usb_desc_types
Definition: pios_usb_defs.h:34
USB_CDC_DESC_SUBTYPE_ABSTRACT_CTRL
Definition: pios_usb_defs.h:43
USB_DESC_TYPE_STRING
Definition: pios_usb_defs.h:43
USB_CDC_LINE_CODING_STOP_1
Definition: pios_usb_defs.h:41
uint8_t bDescriptorType
uint8_t bNumDescriptors
USB_INTERFACE_CLASS_CDC
Definition: pios_usb_defs.h:41
USB_DESC_TYPE_CLASS_SPECIFIC
Definition: pios_usb_defs.h:49
uint16_t idProduct
USB_DESC_TYPE_IAD
Definition: pios_usb_defs.h:46
usb_cdc_notification
usb_standard_requests
USB_CDC_NOTIFICATION_SERIAL_STATE
Definition: pios_usb_defs.h:41
usb_op_board_ids
USB_CDC_LINE_CODING_PARITY_SPACE
Definition: pios_usb_defs.h:45
USB_CDC_LINE_CODING_STOP_1_5
Definition: pios_usb_defs.h:42
uint8_t bNumConfigurations
USB_EP_ATTR_TT_ISOCHRONOUS
Definition: pios_usb_defs.h:42
USB_CDC_DESC_SUBTYPE_HEADER
Definition: pios_usb_defs.h:41
uint8_t bDescriptorType
USB_OP_BOARD_ID_OPENPILOT_MAIN
Definition: pios_usb_defs.h:42
USB_OP_BOARD_ID_PIPXTREME
Definition: pios_usb_defs.h:44
USB_EP_ATTR_TT_BULK
Definition: pios_usb_defs.h:43
USB_EP_ATTR_TT_CONTROL
Definition: pios_usb_defs.h:41
USB_CDC_LINE_CODING_PARITY_ODD
Definition: pios_usb_defs.h:42
USB_EP_ATTR_TT_INTERRUPT
Definition: pios_usb_defs.h:44
USB_OP_BOARD_MODE_UP
Definition: pios_usb_defs.h:43
USB_CDC_LINE_CODING_PARITY_MARK
Definition: pios_usb_defs.h:44
uint8_t iSerialNumber
enum usb_standard_requests __attribute__
USB_OP_BOARD_ID_REVOLUTION
Definition: pios_usb_defs.h:46
USB_OP_BOARD_ID_COPTERCONTROL
Definition: pios_usb_defs.h:45
uint8_t bEndpointAddress
USB_CDC_DESC_SUBTYPE_CALLMGMT
Definition: pios_usb_defs.h:42
USB_DESC_TYPE_CONFIGURATION
Definition: pios_usb_defs.h:42
uint8_t bInterfaceSubClass
uint16_t bcdHID
USB_DESC_TYPE_REPORT
Definition: pios_usb_defs.h:48
USB_CDC_DESC_SUBTYPE_UNION
Definition: pios_usb_defs.h:44
uint8_t nInterfaceProtocol
usb_ep_attr
Definition: pios_usb_defs.h:59
USB_DESC_TYPE_HID
Definition: pios_usb_defs.h:47
usb_cdc_line_coding_parity
USB_INTERFACE_CLASS_HID
Definition: pios_usb_defs.h:42
uint8_t bDeviceClass
USB_CDC_LINE_CODING_PARITY_EVEN
Definition: pios_usb_defs.h:43
uint8_t bClassDescriptorType
USB_OP_BOARD_MODE_FW
Definition: pios_usb_defs.h:42
usb_cdc_requests
uint16_t wItemLength
uint8_t bCountryCode
USB_INTERFACE_CLASS_DATA
Definition: pios_usb_defs.h:43
uint8_t bDeviceProtocol
USB_OP_BOARD_MODE_BL
Definition: pios_usb_defs.h:41
uint8_t iManufacturer
uint8_t bDeviceSubClass
USB_CDC_LINE_CODING_STOP_2
Definition: pios_usb_defs.h:43
USB_DESC_TYPE_DEVICE
Definition: pios_usb_defs.h:41
usb_hid_requests
USB_OP_BOARD_ID_OSD
Definition: pios_usb_defs.h:47
uint8_t bMaxPacketSize0
usb_op_board_modes
USB_DESC_TYPE_INTERFACE
Definition: pios_usb_defs.h:44
USB_DESC_TYPE_ENDPOINT
Definition: pios_usb_defs.h:45
uint16_t wMaxPacketSize
usb_cdc_line_coding_stop
USB_CDC_LINE_CODING_PARITY_NONE
Definition: pios_usb_defs.h:41
usb_interface_class
Definition: pios_usb_defs.h:46
usb_cdc_desc_subtypes
Definition: pios_usb_defs.h:52
uint16_t bcdDevice
uint8_t bLength