Welcome to mirror list, hosted at ThFree Co, Russian Federation.

usbd_composite_desc.h « usb_device « hw « pastilda « emb - github.com/thirdpin/pastilda.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2c09aa0841fd7925c74525bea66d8ab277758e28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
 * This file is part of the pastilda project.
 * hosted at http://github.com/thirdpin/pastilda
 *
 * Copyright (C) 2016  Third Pin LLC
 * Written by Anastasiia Lazareva <a.lazareva@thirdpin.ru>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef USB_COMPOSITE_DESCRIPTORS
#define USB_COMPOSITE_DESCRIPTORS

extern "C"
{
#include <libopencm3/usb/usbd.h>
#include <libopencm3/usb/hid.h>
#include <libopencm3/usb/msc.h>
}

typedef enum {
	I_KEYBOARD     = 0,
	I_MASS_STORAGE = 1
} Interface;

typedef enum : uint8_t {
	E_KEYBOARD = 0x81,
	E_MASS_STORAGE_IN = 0x83,
	E_MASS_STORAGE_OUT = 0x03
} Endpoint;

typedef enum {
	GET_REPORT = 1,
	GET_IDLE = 2,
	GET_PROTOCOL = 3,
	SET_REPORT = 9,
	SET_IDLE = 10,
	SET_PROTOCOL = 11,
} HidRequest;

class UsbCompositeDescriptors
{
public:
	static constexpr uint8_t keyboard_report_descriptor[]  =
	{
			0x05, 0x01, 0x09, 0x06, 0xA1, 0x01, 0x05, 0x07, 0x19, 0xE0, 0x29, 0xE7, 0x15, 0x00, 0x25, 0x01,
			0x75, 0x01, 0x95, 0x08, 0x81, 0x02, 0x95, 0x01, 0x75, 0x08, 0x81, 0x01, 0x95, 0x03, 0x75, 0x01,
			0x05, 0x08, 0x19, 0x01, 0x29, 0x03, 0x91, 0x02, 0x95, 0x05, 0x75, 0x01, 0x91, 0x01, 0x95, 0x06,
			0x75, 0x08, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x05, 0x07, 0x19, 0x00, 0x2A, 0xFF, 0x00, 0x81, 0x00,
			0xC0
	};

	static constexpr char  usb_strings[][30] =
	{
			"Third Pin",
			"Composite Device",
			"Pastilda"
	};

	static constexpr struct usb_device_descriptor dev =
	{
			USB_DT_DEVICE_SIZE, //bLength
			USB_DT_DEVICE,      //bDescriptorType
			0x0110,             //bcdUSB
			0x0,                //bDeviceClass
			0x00,               //bDeviceSubClass
			0x00,               //bDeviceProtocol
			64,                 //bMaxPacketSize0
			0x0483,             //idVendor
			0x5741,             //idProduct
			0x0200,             //bcdDevice
			1,                  //iManufacturer
			2,                  //iProduct
			3,                  //iSerialNumber
			1                   //bNumConfigurations
	};

	typedef struct __attribute__((packed))
	{
		struct usb_hid_descriptor hid_descriptor;
		struct
		{
			uint8_t bReportDescriptorType;
			uint16_t wDescriptorLength;
		} __attribute__((packed)) hid_report;
	} type_hid_function;

	static constexpr type_hid_function  keyboard_hid_function =
	{
		{
			9,          //bLength
			USB_DT_HID, //bDescriptorType
			0x0111,     //bcdHID
			0,          //bCountryCode
			1           //bNumDescriptors
		},

		{
			USB_DT_REPORT,
			sizeof(keyboard_report_descriptor)
		}
	};

	static constexpr struct usb_endpoint_descriptor hid_endpoint =
	{
		USB_DT_ENDPOINT_SIZE,        //bLength
		USB_DT_ENDPOINT,             //bDescriptorType
		Endpoint::E_KEYBOARD,        //bEndpointAddress
		USB_ENDPOINT_ATTR_INTERRUPT, //bmAttributes
		64,                          //wMaxPacketSize
		0x20                         //bInterval
	};

	static constexpr struct usb_endpoint_descriptor msc_endpoint[] =
	{
		{
			USB_DT_ENDPOINT_SIZE,        //bLength
			USB_DT_ENDPOINT,             //bDescriptorType
			Endpoint::E_MASS_STORAGE_IN, //bEndpointAddress
			USB_ENDPOINT_ATTR_BULK,      //bmAttributes
			64,                          //wMaxPacketSize
			0                            //bInterval
		},

		{
			USB_DT_ENDPOINT_SIZE,         //bLength
			USB_DT_ENDPOINT,              //bDescriptorType
			Endpoint::E_MASS_STORAGE_OUT, //bEndpointAddress
			USB_ENDPOINT_ATTR_BULK,       //bmAttributes
			64,                           //wMaxPacketSize
			0                             //bInterval
		}
	};

	static constexpr struct usb_interface_descriptor iface[] =
	{
		{
			USB_DT_INTERFACE_SIZE,   //bLength
			USB_DT_INTERFACE,        //bDescriptorType
			Interface::I_KEYBOARD,   //bInterfaceNumber
			0,                       //bAlternateSetting
			1,                       //bNumEndpoints
			USB_CLASS_HID,           //bInterfaceClass
			1,                       //bInterfaceSubClass
			1,                       //bInterfaceProtocol
			0,                       //iInterface
			&hid_endpoint, &keyboard_hid_function,
			sizeof(keyboard_hid_function)
		},

		{
			USB_DT_INTERFACE_SIZE,     //bLength
			USB_DT_INTERFACE,          //bDescriptorType
			Interface::I_MASS_STORAGE, //bInterfaceNumber
			0,                         //bAlternateSetting
			2,                         //bNumEndpoints
			USB_CLASS_MSC,             //bInterfaceClass
			USB_MSC_SUBCLASS_SCSI,     //bInterfaceSubClass
			USB_MSC_PROTOCOL_BBB,      //bInterfaceProtocol
			0x00,                      //iInterface
			msc_endpoint, 0, 0
		},
	};

	static constexpr struct usb_config_descriptor::usb_interface ifaces[]
	{
		{
			(uint8_t *)0,                   //cur_altsetting
			1,                              //num_altsetting
			(usb_iface_assoc_descriptor*)0, //iface_assoc
			&iface[Interface::I_KEYBOARD]   //altsetting
		},

		{
			(uint8_t *)0,                     //cur_altsetting
			1,                                //num_altsetting
			(usb_iface_assoc_descriptor*)0,   //iface_assoc
			&iface[Interface::I_MASS_STORAGE] //altsetting
		},
	};

	static constexpr struct usb_config_descriptor config_descr =
	{
		USB_DT_CONFIGURATION_SIZE, //bLength
		USB_DT_CONFIGURATION,      //bDescriptorType
		0,                         //wTotalLength
		2,                         //bNumInterfaces
		1,                         //bConfigurationValue
		0,                         //iConfiguration
		0x80,                      //bmAttributes
		0x50,                      //bMaxPower
		ifaces
	};

	UsbCompositeDescriptors() {}
};
#endif