-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUSBconstant.c
More file actions
124 lines (103 loc) · 4.93 KB
/
USBconstant.c
File metadata and controls
124 lines (103 loc) · 4.93 KB
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
#include "USBconstant.h"
//Device descriptor
__code uint8_t DevDesc[] = {
0x12, 0x01,
0x00, 0x02, //USB spec release number in BCD format, USB1.1 (0x10, 0x01).
0x00, 0x00, 0x00, //bDeviceClass, bDeviceSubClass, bDeviceProtocol
0x40, //bNumConfigurations
0x0D, 0x0F, 0x92, 0x00, // VID PID
0x00, 0x01, //version
0x01, 0x02, 0x03, //bString
0x01 //bNumConfigurations
};
__code uint16_t DevDescLen = sizeof(DevDesc);
__code uint8_t CfgDesc[] = {
0x09, 0x02, sizeof(CfgDesc) & 0xff, sizeof(CfgDesc) >> 8,
0x02, 0x01, 0x00, 0xA0, 0xFA, //Configuration descriptor (1 interface)
0x09, 0x04, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, // HID Keyboard, 2 endpoints
0x09, 0x21, 0x01, 0x01, 0x00, 0x01, 0x22, sizeof(GamepadDesc) & 0xff, sizeof(GamepadDesc) >> 8, //HID Descriptor
0x07, 0x05, 0x82, 0x03, 0x40, 0x00, 0x01, //endpoint descriptor
0x09, 0x04, 0x01, 0x00, 0x01, 0x03, 0x01, 0x01, 0x00, // HID Keyboard, 2 endpoints
0x09, 0x21, 0x11, 0x01, 0x00, 0x01, 0x22, sizeof(KeyboardDesc) & 0xff, sizeof(KeyboardDesc) >> 8, //HID Descriptor
0x07, 0x05, 0x81, 0x03, 0x40, 0x00, 0x01,
};
__code uint8_t HidDesc[] = {
// HID Keyboard, 2 endpoints
0x09, 0x21, 0x11, 0x01, 0x00, 0x01, 0x22, sizeof(KeyboardDesc) & 0xff, sizeof(KeyboardDesc) >> 8, //HID Descriptor //endpoint descriptor
};
__code uint16_t HidDescLen = sizeof(HidDesc);
__code uint16_t KeyboardDescLen = sizeof(KeyboardDesc);
__code uint8_t KeyboardDesc[] = {
// Keyboard
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) 47 */
0x09, 0x06, /* USAGE (Keyboard) */
0xa1, 0x01, /* COLLECTION (Application) */
0x05, 0x07, /* USAGE_PAGE (Keyboard) */
/* Keyboard Modifiers (shift, alt, ...) */
0x19, 0xe0, /* USAGE_MINIMUM (Keyboard LeftControl) */
0x29, 0xe7, /* USAGE_MAXIMUM (Keyboard Right GUI) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x08, /* REPORT_COUNT (8) */
0x81, 0x02, /* INPUT (Data,Var,Abs) */
/* Reserved byte, used for consumer reports, only works with linux */
0x05, 0x0C, /* Usage Page (Consumer) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x75, 0x08, /* REPORT_SIZE (8) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x26, 0xFF, 0x00, /* LOGICAL_MAXIMUM (255) */
0x19, 0x00, /* USAGE_MINIMUM (0) */
0x29, 0xFF, /* USAGE_MAXIMUM (255) */
0x81, 0x00, /* INPUT (Data,Ary,Abs) */
/* 5 LEDs for num lock etc, 3 left for advanced, custom usage */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x19, 0x01, /* USAGE_MINIMUM (Num Lock) */
0x29, 0x08, /* USAGE_MAXIMUM (Kana + 3 custom)*/
0x95, 0x08, /* REPORT_COUNT (8) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
/* 6 Keyboard keys */
0x05, 0x07, /* USAGE_PAGE (Keyboard) */
0x95, 0x06, /* REPORT_COUNT (6) */
0x75, 0x08, /* REPORT_SIZE (8) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x26, 0xE7, 0x00, /* LOGICAL_MAXIMUM (231) */
0x19, 0x00, /* USAGE_MINIMUM (Reserved (no event indicated)) */
0x29, 0xE7, /* USAGE_MAXIMUM (Keyboard Right GUI) */
0x81, 0x00, /* INPUT (Data,Ary,Abs) */
/* End */
0xc0 /* END_COLLECTION */
};
__code uint16_t GamepadDescLen = sizeof(GamepadDesc);
__code uint8_t GamepadDesc[] = {
0x05, 0x01, 0x09, 0x05, 0xa1, 0x01, 0x15, 0x00, 0x25, 0x01, 0x35, 0x00,
0x45, 0x01, 0x75, 0x01, 0x95, 0x10, 0x05, 0x09, 0x19, 0x01, 0x29, 0x10,
0x81, 0x02, 0x05, 0x01, 0x25, 0x07, 0x46, 0x3b, 0x01, 0x75, 0x04, 0x95,
0x01, 0x65, 0x14, 0x09, 0x39, 0x81, 0x42, 0x65, 0x00, 0x95, 0x01, 0x81,
0x01, 0x26, 0xff, 0x00, 0x46, 0xff, 0x00, 0x09, 0x30, 0x09, 0x31, 0x09,
0x32, 0x09, 0x35, 0x75, 0x08, 0x95, 0x04, 0x81, 0x02, 0x06, 0x00, 0xff,
0x09, 0x20, 0x95, 0x01, 0x81, 0x02, 0x0a, 0x21, 0x26, 0x95, 0x08, 0x91,
0x02, 0xc0
};
__code uint16_t CfgDescLen = sizeof(CfgDesc);
//String Descriptors
__code uint8_t LangDes[] = { 0x04, 0x03, 0x09, 0x04 }; //Language Descriptor
__code uint16_t LangDesLen = sizeof(LangDes);
__code uint8_t Prod_Des[] = { //Produce String Descriptor
0x24, 0x03,
'P', 0x00, 'O', 0x00, 'K', 0x00, 'K', 0x00, 'E', 0x00, 'N', 0x00, ' ', 0x00,
'C', 0x00, 'O', 0x00, 'N', 0x00, 'T', 0x00, 'R', 0x00, 'O', 0x00, 'L', 0x00, 'L', 0x00, 'E', 0x00, 'R', 0x00
};
__code uint16_t Prod_DesLen = sizeof(Prod_Des);
__code uint8_t Manuf_Des[] = {
0x1C, 0x03,
'H', 0x00, 'O', 0x00, 'R', 0x00, 'I', 0x00, ' ', 0x00,
'C', 0x00, 'O', 0x00, '.', 0x00, ',', 0x00, 'L', 0x00, 'T', 0x00, 'D', 0x00, '.', 0x00
};
__code uint16_t Manuf_DesLen = sizeof(Manuf_Des);
__code uint8_t Seri_Des[] = {
0x4, 0x03,
'0', 0x00
};
__code uint16_t Seri_DesLen = sizeof(Seri_Des);