Open FFBoard
Open source force feedback firmware
usb_descriptors.cpp
Go to the documentation of this file.
1/*
2 * usb_descriptors.c
3 *
4 * Created on: 16.02.2021
5 * Author: Yannick
6 */
7#include "tusb.h"
8#include "usb_descriptors.h"
9#include "usbd.h"
10#include "stm32f4xx_hal.h"
11#include "main.h"
12#include "usb_hid_ffb_desc.h"
13
14//--------------------------------------------------------------------+
15// Device Descriptors
16//--------------------------------------------------------------------+
17#define USBD_VID 0x1209
18#define USBD_PID 0xFFB0
20{
21 .bLength = sizeof(tusb_desc_device_t),
22 .bDescriptorType = TUSB_DESC_DEVICE,
23 .bcdUSB = 0x0200,
24
25 // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
26 .bDeviceClass = TUSB_CLASS_MISC,
27 .bDeviceSubClass = MISC_SUBCLASS_COMMON,
28 .bDeviceProtocol = MISC_PROTOCOL_IAD,
29 .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
30
31 .idVendor = USBD_VID,
32 .idProduct = USBD_PID,
33 .bcdDevice = 0x0100,
34
35 .iManufacturer = 0x01,
36 .iProduct = 0x02,
37 .iSerialNumber = 0x03,
38
39 .bNumConfigurations = 0x01
40};
41
42
43/*--------------------------------------------------------------------
44 * Configuration descriptors
45 * String index starts at 4 (interfaces field)
46----------------------------------------------------------------------*/
47
48const uint8_t usb_cdc_conf[] =
49{
50 // Config number, interface count, string index, total length, attribute, power in mA
51 TUD_CONFIG_DESCRIPTOR(1, 2, 0, (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN), TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
52
53 // 1st CDC: Interface number, string index, EP notification address and size, EP data address (out, in) and size.
54 TUD_CDC_DESCRIPTOR(0, 4, 0x82, 8, 0x01, 0x81, 64),
55};
56
57// Composite CDC and HID
58#ifdef AXIS1_FFB_HID_DESC
59const uint8_t usb_cdc_hid_conf_1axis[] =
60{
61 // Config number, interface count, string index, total length, attribute, power in mA
62 TUD_CONFIG_DESCRIPTOR(1, 3, 0, (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_HID_INOUT_DESC_LEN), TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
63
64 // 1st CDC: Interface number, string index, EP notification address and size, EP data address (out, in) and size.
65 TUD_CDC_DESCRIPTOR(0, 4, 0x82, 8, 0x01, 0x81, 64),
66
67 // HID Descriptor. EP 83 and 2
68 TUD_HID_INOUT_DESCRIPTOR(2, 5, HID_ITF_PROTOCOL_NONE, USB_HID_1FFB_REPORT_DESC_SIZE, 0x83, 0x02, 64, HID_BINTERVAL),
69};
70#endif
71
72// Composite CDC and HID
73#ifdef AXIS2_FFB_HID_DESC
74const uint8_t usb_cdc_hid_conf_2axis[] =
75{
76 // Config number, interface count, string index, total length, attribute, power in mA
77 TUD_CONFIG_DESCRIPTOR(1, 3, 0, (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_HID_INOUT_DESC_LEN), TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
78
79 // 1st CDC: Interface number, string index, EP notification address and size, EP data address (out, in) and size.
80 TUD_CDC_DESCRIPTOR(0, 4, 0x82, 8, 0x01, 0x81, 64),
81
82 // HID Descriptor. EP 83 and 2
83 TUD_HID_INOUT_DESCRIPTOR(2, 5, HID_ITF_PROTOCOL_NONE, USB_HID_2FFB_REPORT_DESC_SIZE, 0x83, 0x02, 64, HID_BINTERVAL),
84};
85#endif
86
87// Composite CDC and HID
88#ifdef FFB_HID_DESC_GAMEPAD
89const uint8_t usb_cdc_hid_conf_gamepad[] =
90{
91 // Config number, interface count, string index, total length, attribute, power in mA
92 TUD_CONFIG_DESCRIPTOR(1, 3, 0, (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_HID_INOUT_DESC_LEN), TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
93
94 // 1st CDC: Interface number, string index, EP notification address and size, EP data address (out, in) and size.
95 TUD_CDC_DESCRIPTOR(0, 4, 0x82, 8, 0x01, 0x81, 64),
96
97 // HID Descriptor. EP 83 and 2
98 TUD_HID_INOUT_DESCRIPTOR(2, 5, HID_ITF_PROTOCOL_NONE, USB_HID_GAMEPAD_REPORT_DESC_SIZE, 0x83, 0x02, 64, HID_BINTERVAL),
99};
100#endif
101
102// Composite CDC and MIDI
103uint8_t const usb_cdc_midi_conf[] =
104{
105 // Config number, interface count, string index, total length, attribute, power in mA
106 TUD_CONFIG_DESCRIPTOR(1, 4, 0, TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_MIDI_DESC_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
107 // 1st CDC: Interface number, string index, EP notification address and size, EP data address (out, in) and size.
108 TUD_CDC_DESCRIPTOR(0, 4, 0x82, 8, 0x01, 0x81, 64),
109 // Interface number, string index, EP Out & EP In address, EP size
110 TUD_MIDI_DESCRIPTOR(2, 6, 0x02, 0x83, 64)
111};
112
113//--------------------------------------------------------------------+
114// String Descriptors
115//--------------------------------------------------------------------+
116
117// Default ffboard names
119 .langId = 0x0409,
120 .manufacturer = "Open FFBoard",
121 .product = "FFBoard",
122 // Interfaces start at index 4
123 .interfaces = {"FFBoard CDC", "FFBoard HID","FFBoard MIDI"}
124};
125
126
@ HID_ITF_PROTOCOL_NONE
None.
Definition: hid.h:70
const uint16_t langId
@ MISC_SUBCLASS_COMMON
Definition: tusb_types.h:186
@ TUSB_CLASS_MISC
Definition: tusb_types.h:179
@ TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP
Definition: tusb_types.h:218
TU_ATTR_PACKED_BEGIN TU_ATTR_BIT_FIELD_ORDER_BEGIN struct TU_ATTR_PACKED tusb_desc_device_t
USB Device Descriptor.
@ MISC_PROTOCOL_IAD
Definition: tusb_types.h:190
@ TUSB_DESC_DEVICE
Definition: tusb_types.h:93
const uint8_t usb_cdc_conf[]
const uint8_t usb_cdc_hid_conf_2axis[]
const uint8_t usb_cdc_hid_conf_gamepad[]
const tusb_desc_device_t usb_devdesc_ffboard_composite
const usb_string_desc_t usb_ffboard_strings_default
const uint8_t usb_cdc_hid_conf_1axis[]
uint8_t const usb_cdc_midi_conf[]