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

usbd_composite_desc.h « usb_device « usb « pastilda « emb - github.com/thirdpin/pastilda.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b4d01818adfbe6f78545bcb996f318804ba2c651 (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
/*
 * 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>
 *	Dmitrii Lisin <mrlisdim@ya.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,
			USB_DT_DEVICE,
			0x0110,
			0x0,
			0x00, 0x00, 64,
			0x0483, 0x5741, 0x0200,
			1, 2, 3, 1
	};

	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,
					USB_DT_HID,
					0x0111, 0, 1
			},

			{
					USB_DT_REPORT,
					sizeof(keyboard_report_descriptor)
			}
	};

	static constexpr struct usb_endpoint_descriptor hid_endpoint =
	{
			USB_DT_ENDPOINT_SIZE,
			USB_DT_ENDPOINT, Endpoint::E_KEYBOARD,
			USB_ENDPOINT_ATTR_INTERRUPT,
			64, 0x10
	};

	static constexpr struct usb_endpoint_descriptor msc_endpoint[] =
	{
			{
					USB_DT_ENDPOINT_SIZE,
					USB_DT_ENDPOINT,
					Endpoint::E_MASS_STORAGE_IN, USB_ENDPOINT_ATTR_BULK,
					64, 0
			},

			{
					USB_DT_ENDPOINT_SIZE,
					USB_DT_ENDPOINT,
					Endpoint::E_MASS_STORAGE_OUT, USB_ENDPOINT_ATTR_BULK,
					64, 0
			}
	};

	static constexpr struct usb_interface_descriptor iface[] =
	{
			{
					USB_DT_INTERFACE_SIZE,
					USB_DT_INTERFACE,
					Interface::I_KEYBOARD, 0, 1,
					USB_CLASS_HID,
					1, 1, 0,
					&hid_endpoint, &keyboard_hid_function,
					sizeof(keyboard_hid_function)
			},

			{
					USB_DT_INTERFACE_SIZE,
					USB_DT_INTERFACE,
					Interface::I_MASS_STORAGE, 0, 2,
					USB_CLASS_MSC,
					USB_MSC_SUBCLASS_SCSI, USB_MSC_PROTOCOL_BBB, 0x00,
					msc_endpoint, 0, 0
			},

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

																				{
																						(uint8_t *)0,
																						1,
																						(usb_iface_assoc_descriptor*)0,
																						&iface[Interface::I_MASS_STORAGE]
																				},

																		};

	static constexpr struct usb_config_descriptor config_descr =
	{
			USB_DT_CONFIGURATION_SIZE,
			USB_DT_CONFIGURATION,
			0,
			2, 1, 0, 0x80, 0x50,
			ifaces
	};

	UsbCompositeDescriptors() {}
};
#endif