dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_usb_desc_hid_only.c
Go to the documentation of this file.
1 
15 /*
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful, but
22  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24  * for more details.
25  *
26  * You should have received a copy of the GNU General Public License along
27  * with this program; if not, see <http://www.gnu.org/licenses/>
28  */
29 
30 #include "pios_usb_desc_hid_only_priv.h" /* exported API */
31 #include "pios_usb_defs.h" /* struct usb_*, USB_* */
32 #include "pios_usb_board_data.h" /* PIOS_USB_BOARD_* */
33 #include "pios_usbhook.h" /* PIOS_USBHOOK_Register* */
34 #include "pios_usb_hid.h" /* PIOS_USB_HID_Register* */
35 
36 static const struct usb_device_desc device_desc = {
37  .bLength = sizeof(struct usb_device_desc),
38  .bDescriptorType = USB_DESC_TYPE_DEVICE,
39  .bcdUSB = htousbs(0x0200),
40  .bDeviceClass = 0x00,
41  .bDeviceSubClass = 0x00,
42  .bDeviceProtocol = 0x00,
43  .bMaxPacketSize0 = 64, /* Must be 64 for high-speed devices */
44  .idVendor = htousbs(PIOS_USB_BOARD_VENDOR_ID),
45  .idProduct = htousbs(PIOS_USB_BOARD_PRODUCT_ID),
46  .bcdDevice = htousbs(PIOS_USB_BOARD_DEVICE_VER),
47  .iManufacturer = 1,
48  .iProduct = 2,
49  .iSerialNumber = 3,
50  .bNumConfigurations = 1,
51 };
52 
53 static const uint8_t hid_report_desc[36] = {
55  0x9C, 0xFF, /* Usage Page 0xFF9C (Vendor Defined) */
57  0x01, /* Usage ID 0x0001 (0x01-0x1F uaually for top-level collections) */
58 
60  0x01, /* Application */
61 
62  /* Device -> Host emulated serial channel */
64  0x01, /* OpenPilot emulated serial channel (Device -> Host) */
66  0x02,
68  0x00, /* Values range from min = 0x00 */
70  0xFF, /* Values range to max = 0xFF */
72  0x08, /* 8 bits wide */
74  PIOS_USB_BOARD_HID_DATA_LENGTH-1, /* Need to leave room for a report ID */
76  0x03, /* Variable, Constant (read-only) */
77 
78  /* Host -> Device emulated serial channel */
80  0x02, /* OpenPilot emulated Serial Channel (Host -> Device) */
82  0x02,
84  0x00, /* Values range from min = 0x00 */
86  0xFF, /* Values range to max = 0xFF */
88  0x08, /* 8 bits wide */
90  PIOS_USB_BOARD_HID_DATA_LENGTH-1, /* Need to leave room for a report ID */
92  0x82, /* Volatile, Variable */
93 
95 };
96 
103 } __attribute__((packed));
104 
106  .config = {
107  .bLength = sizeof(struct usb_configuration_desc),
108  .bDescriptorType = USB_DESC_TYPE_CONFIGURATION,
109  .wTotalLength = htousbs(sizeof(struct usb_config_hid_only)),
110  .bNumInterfaces = 1,
111  .bConfigurationValue = 1,
112  .iConfiguration = 0,
113  .bmAttributes = 0xC0,
114  .bMaxPower = 250/2, /* in units of 2ma */
115  },
116  .hid_if = {
117  .bLength = sizeof(struct usb_interface_desc),
118  .bDescriptorType = USB_DESC_TYPE_INTERFACE,
119  .bInterfaceNumber = 0,
120  .bAlternateSetting = 0,
121  .bNumEndpoints = 2,
122  .bInterfaceClass = USB_INTERFACE_CLASS_HID,
123  .bInterfaceSubClass = 0, /* no boot */
124  .nInterfaceProtocol = 0, /* none */
125  .iInterface = 0,
126  },
127  .hid = {
128  .bLength = sizeof(struct usb_hid_desc),
129  .bDescriptorType = USB_DESC_TYPE_HID,
130  .bcdHID = htousbs(0x0110),
131  .bCountryCode = 0,
132  .bNumDescriptors = 1,
133  .bClassDescriptorType = USB_DESC_TYPE_REPORT,
134  .wItemLength = htousbs(sizeof(hid_report_desc)),
135  },
136  .hid_in = {
137  .bLength = sizeof(struct usb_endpoint_desc),
138  .bDescriptorType = USB_DESC_TYPE_ENDPOINT,
139  .bEndpointAddress = USB_EP_IN(1),
140  .bmAttributes = USB_EP_ATTR_TT_INTERRUPT,
141  .wMaxPacketSize = htousbs(PIOS_USB_BOARD_HID_DATA_LENGTH),
142  .bInterval = 4, /* ms */
143  },
144  .hid_out = {
145  .bLength = sizeof(struct usb_endpoint_desc),
146  .bDescriptorType = USB_DESC_TYPE_ENDPOINT,
147  .bEndpointAddress = USB_EP_OUT(1),
148  .bmAttributes = USB_EP_ATTR_TT_INTERRUPT,
149  .wMaxPacketSize = htousbs(PIOS_USB_BOARD_HID_DATA_LENGTH),
150  .bInterval = 4, /* ms */
151  },
152 };
153 
155 {
156  PIOS_USBHOOK_RegisterConfig(1, (uint8_t *)&config_hid_only, sizeof(config_hid_only));
157 
158  PIOS_USBHOOK_RegisterDevice((uint8_t *)&device_desc, sizeof(device_desc));
159 
160  PIOS_USB_HID_RegisterHidDescriptor((uint8_t *)&(config_hid_only.hid), sizeof(config_hid_only.hid));
162 
163  return 0;
164 }
static const struct usb_device_desc device_desc
#define HID_TAG_GLOBAL_REPORT_ID
Definition: pios_usb_defs.h:97
#define PIOS_USB_BOARD_VENDOR_ID
#define USB_EP_OUT(ep)
Definition: pios_usb_defs.h:82
struct usb_endpoint_desc hid_out
APIs for PIOS_USBHOOK layer.
#define HID_TAG_LOCAL_USAGE
#define HID_TAG_GLOBAL_LOGICAL_MAX
Definition: pios_usb_defs.h:91
struct usb_hid_desc hid
USB HID layer functions header.
#define USB_EP_IN(ep)
Definition: pios_usb_defs.h:81
#define PIOS_USB_BOARD_DEVICE_VER
#define HID_LOCAL_ITEM_1(tag)
USB_EP_ATTR_TT_INTERRUPT
Definition: pios_usb_defs.h:44
static const uint8_t hid_report_desc[36]
#define htousbs(v)
Definition: pios_usb_defs.h:77
#define HID_TAG_MAIN_INPUT
#define HID_TAG_GLOBAL_REPORT_SIZE
Definition: pios_usb_defs.h:96
USB_DESC_TYPE_CONFIGURATION
Definition: pios_usb_defs.h:42
USB_DESC_TYPE_REPORT
Definition: pios_usb_defs.h:48
USB_DESC_TYPE_HID
Definition: pios_usb_defs.h:47
USB_INTERFACE_CLASS_HID
Definition: pios_usb_defs.h:42
#define HID_GLOBAL_ITEM_2(tag)
void PIOS_USBHOOK_RegisterConfig(uint8_t config_id, const uint8_t *desc, uint16_t desc_size)
Definition: pios_usbhook.c:52
int32_t PIOS_USB_DESC_HID_ONLY_Init(void)
#define PIOS_USB_BOARD_PRODUCT_ID
#define HID_TAG_GLOBAL_LOGICAL_MIN
Definition: pios_usb_defs.h:90
#define HID_GLOBAL_ITEM_1(tag)
void PIOS_USBHOOK_RegisterDevice(const uint8_t *desc, uint16_t desc_size)
Definition: pios_usbhook.c:44
#define HID_TAG_MAIN_COLLECTION
Defines the API to set up the HID-only USB descriptor config.
#define PIOS_USB_BOARD_HID_DATA_LENGTH
void PIOS_USB_HID_RegisterHidReport(const uint8_t *desc, uint16_t length)
Definition: pios_usbhook.c:78
#define HID_TAG_MAIN_OUTPUT
#define HID_MAIN_ITEM_1(tag)
const struct usb_config_hid_only config_hid_only
struct usb_interface_desc hid_if
void PIOS_USB_HID_RegisterHidDescriptor(const uint8_t *desc, uint16_t length)
Definition: pios_usbhook.c:70
USB_DESC_TYPE_DEVICE
Definition: pios_usb_defs.h:41
#define HID_TAG_GLOBAL_REPORT_CNT
Definition: pios_usb_defs.h:98
struct usb_configuration_desc config
struct usb_endpoint_desc hid_in
USB_DESC_TYPE_INTERFACE
Definition: pios_usb_defs.h:44
USB_DESC_TYPE_ENDPOINT
Definition: pios_usb_defs.h:45
#define HID_TAG_MAIN_ENDCOLLECTION
#define HID_TAG_GLOBAL_USAGE_PAGE
Definition: pios_usb_defs.h:89
#define HID_MAIN_ITEM_0(tag)
typedef __attribute__
Definition: serial_4way.h:43