aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/protocol/mbed/HIDKeyboard.cpp
diff options
context:
space:
mode:
authorskullY <skullydazed@gmail.com>2019-08-30 11:19:03 -0700
committerskullydazed <skullydazed@users.noreply.github.com>2019-08-30 15:01:52 -0700
commitb624f32f944acdc59dcb130674c09090c5c404cb (patch)
treebc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /tmk_core/protocol/mbed/HIDKeyboard.cpp
parent61af76a10d00aba185b8338604171de490a13e3b (diff)
downloadqmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz
qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip
clang-format changes
Diffstat (limited to 'tmk_core/protocol/mbed/HIDKeyboard.cpp')
-rw-r--r--tmk_core/protocol/mbed/HIDKeyboard.cpp241
1 files changed, 115 insertions, 126 deletions
diff --git a/tmk_core/protocol/mbed/HIDKeyboard.cpp b/tmk_core/protocol/mbed/HIDKeyboard.cpp
index 947077cd2..dbaf108fa 100644
--- a/tmk_core/protocol/mbed/HIDKeyboard.cpp
+++ b/tmk_core/protocol/mbed/HIDKeyboard.cpp
@@ -6,20 +6,14 @@
6 6
7#define DEFAULT_CONFIGURATION (1) 7#define DEFAULT_CONFIGURATION (1)
8 8
9 9HIDKeyboard::HIDKeyboard(uint16_t vendor_id, uint16_t product_id, uint16_t product_release) : USBDevice(vendor_id, product_id, product_release) { USBDevice::connect(); }
10HIDKeyboard::HIDKeyboard(uint16_t vendor_id, uint16_t product_id, uint16_t product_release): USBDevice(vendor_id, product_id, product_release)
11{
12 USBDevice::connect();
13}
14 10
15bool HIDKeyboard::sendReport(report_keyboard_t report) { 11bool HIDKeyboard::sendReport(report_keyboard_t report) {
16 USBDevice::write(EP1IN, report.raw, sizeof(report), MAX_PACKET_SIZE_EP1); 12 USBDevice::write(EP1IN, report.raw, sizeof(report), MAX_PACKET_SIZE_EP1);
17 return true; 13 return true;
18} 14}
19 15
20uint8_t HIDKeyboard::leds() { 16uint8_t HIDKeyboard::leds() { return led_state; }
21 return led_state;
22}
23 17
24bool HIDKeyboard::USBCallback_setConfiguration(uint8_t configuration) { 18bool HIDKeyboard::USBCallback_setConfiguration(uint8_t configuration) {
25 if (configuration != DEFAULT_CONFIGURATION) { 19 if (configuration != DEFAULT_CONFIGURATION) {
@@ -28,80 +22,86 @@ bool HIDKeyboard::USBCallback_setConfiguration(uint8_t configuration) {
28 22
29 // Configure endpoints > 0 23 // Configure endpoints > 0
30 addEndpoint(EPINT_IN, MAX_PACKET_SIZE_EPINT); 24 addEndpoint(EPINT_IN, MAX_PACKET_SIZE_EPINT);
31 //addEndpoint(EPINT_OUT, MAX_PACKET_SIZE_EPINT); 25 // addEndpoint(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
32 26
33 // We activate the endpoint to be able to recceive data 27 // We activate the endpoint to be able to recceive data
34 //readStart(EPINT_OUT, MAX_PACKET_SIZE_EPINT); 28 // readStart(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
35 return true; 29 return true;
36} 30}
37 31
38 32uint8_t *HIDKeyboard::stringImanufacturerDesc() {
39uint8_t * HIDKeyboard::stringImanufacturerDesc() {
40 static uint8_t stringImanufacturerDescriptor[] = { 33 static uint8_t stringImanufacturerDescriptor[] = {
41 0x18, /*bLength*/ 34 0x18, /*bLength*/
42 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ 35 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
43 't',0,'m',0,'k',0,'-',0,'k',0,'b',0,'d',0,'.',0,'c',0,'o',0,'m',0 /*bString iManufacturer*/ 36 't',
37 0,
38 'm',
39 0,
40 'k',
41 0,
42 '-',
43 0,
44 'k',
45 0,
46 'b',
47 0,
48 'd',
49 0,
50 '.',
51 0,
52 'c',
53 0,
54 'o',
55 0,
56 'm',
57 0 /*bString iManufacturer*/
44 }; 58 };
45 return stringImanufacturerDescriptor; 59 return stringImanufacturerDescriptor;
46} 60}
47 61
48uint8_t * HIDKeyboard::stringIproductDesc() { 62uint8_t *HIDKeyboard::stringIproductDesc() {
49 static uint8_t stringIproductDescriptor[] = { 63 static uint8_t stringIproductDescriptor[] = {
50 0x0a, /*bLength*/ 64 0x0a, /*bLength*/
51 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ 65 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
52 'm',0,'b',0,'e',0,'d',0 /*bString iProduct*/ 66 'm',
67 0,
68 'b',
69 0,
70 'e',
71 0,
72 'd',
73 0 /*bString iProduct*/
53 }; 74 };
54 return stringIproductDescriptor; 75 return stringIproductDescriptor;
55} 76}
56 77
57uint8_t * HIDKeyboard::stringIserialDesc() { 78uint8_t *HIDKeyboard::stringIserialDesc() {
58 static uint8_t stringIserialDescriptor[] = { 79 static uint8_t stringIserialDescriptor[] = {
59 0x04, /*bLength*/ 80 0x04, /*bLength*/
60 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ 81 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
61 '0',0 /*bString iSerial*/ 82 '0', 0 /*bString iSerial*/
62 }; 83 };
63 return stringIserialDescriptor; 84 return stringIserialDescriptor;
64} 85}
65 86
66uint8_t * HIDKeyboard::reportDesc() { 87uint8_t *HIDKeyboard::reportDesc() {
67 static uint8_t reportDescriptor[] = { 88 static uint8_t reportDescriptor[] = {
68 USAGE_PAGE(1), 0x01, // Generic Desktop 89 USAGE_PAGE(1), 0x01, // Generic Desktop
69 USAGE(1), 0x06, // Keyboard 90 USAGE(1), 0x06, // Keyboard
70 COLLECTION(1), 0x01, // Application 91 COLLECTION(1), 0x01, // Application
71
72 USAGE_PAGE(1), 0x07, // Key Codes
73 USAGE_MINIMUM(1), 0xE0,
74 USAGE_MAXIMUM(1), 0xE7,
75 LOGICAL_MINIMUM(1), 0x00,
76 LOGICAL_MAXIMUM(1), 0x01,
77 REPORT_SIZE(1), 0x01,
78 REPORT_COUNT(1), 0x08,
79 INPUT(1), 0x02, // Data, Variable, Absolute
80 92
81 REPORT_COUNT(1), 0x01, 93 USAGE_PAGE(1), 0x07, // Key Codes
82 REPORT_SIZE(1), 0x08, 94 USAGE_MINIMUM(1), 0xE0, USAGE_MAXIMUM(1), 0xE7, LOGICAL_MINIMUM(1), 0x00, LOGICAL_MAXIMUM(1), 0x01, REPORT_SIZE(1), 0x01, REPORT_COUNT(1), 0x08, INPUT(1), 0x02, // Data, Variable, Absolute
83 INPUT(1), 0x01, // Constant
84 95
85 REPORT_COUNT(1), 0x05, 96 REPORT_COUNT(1), 0x01, REPORT_SIZE(1), 0x08, INPUT(1), 0x01, // Constant
86 REPORT_SIZE(1), 0x01,
87 USAGE_PAGE(1), 0x08, // LEDs
88 USAGE_MINIMUM(1), 0x01,
89 USAGE_MAXIMUM(1), 0x05,
90 OUTPUT(1), 0x02, // Data, Variable, Absolute
91 97
92 REPORT_COUNT(1), 0x01, 98 REPORT_COUNT(1), 0x05, REPORT_SIZE(1), 0x01, USAGE_PAGE(1), 0x08, // LEDs
93 REPORT_SIZE(1), 0x03, 99 USAGE_MINIMUM(1), 0x01, USAGE_MAXIMUM(1), 0x05, OUTPUT(1), 0x02, // Data, Variable, Absolute
94 OUTPUT(1), 0x01, // Constant
95 100
101 REPORT_COUNT(1), 0x01, REPORT_SIZE(1), 0x03, OUTPUT(1), 0x01, // Constant
96 102
97 REPORT_COUNT(1), 0x06, 103 REPORT_COUNT(1), 0x06, REPORT_SIZE(1), 0x08, LOGICAL_MINIMUM(1), 0x00, LOGICAL_MAXIMUM(1), 0xFF, USAGE_PAGE(1), 0x07, // Key Codes
98 REPORT_SIZE(1), 0x08, 104 USAGE_MINIMUM(1), 0x00, USAGE_MAXIMUM(1), 0xFF, INPUT(1), 0x00, // Data, Array
99 LOGICAL_MINIMUM(1), 0x00,
100 LOGICAL_MAXIMUM(1), 0xFF,
101 USAGE_PAGE(1), 0x07, // Key Codes
102 USAGE_MINIMUM(1), 0x00,
103 USAGE_MAXIMUM(1), 0xFF,
104 INPUT(1), 0x00, // Data, Array
105 END_COLLECTION(0), 105 END_COLLECTION(0),
106 }; 106 };
107 reportLength = sizeof(reportDescriptor); 107 reportLength = sizeof(reportDescriptor);
@@ -113,48 +113,45 @@ uint16_t HIDKeyboard::reportDescLength() {
113 return reportLength; 113 return reportLength;
114} 114}
115 115
116#define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \ 116#define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) + (1 * INTERFACE_DESCRIPTOR_LENGTH) + (1 * HID_DESCRIPTOR_LENGTH) + (1 * ENDPOINT_DESCRIPTOR_LENGTH))
117 + (1 * INTERFACE_DESCRIPTOR_LENGTH) \ 117uint8_t *HIDKeyboard::configurationDesc() {
118 + (1 * HID_DESCRIPTOR_LENGTH) \
119 + (1 * ENDPOINT_DESCRIPTOR_LENGTH))
120uint8_t * HIDKeyboard::configurationDesc() {
121 static uint8_t configurationDescriptor[] = { 118 static uint8_t configurationDescriptor[] = {
122 CONFIGURATION_DESCRIPTOR_LENGTH,// bLength 119 CONFIGURATION_DESCRIPTOR_LENGTH, // bLength
123 CONFIGURATION_DESCRIPTOR, // bDescriptorType 120 CONFIGURATION_DESCRIPTOR, // bDescriptorType
124 LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB) 121 LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
125 MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB) 122 MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB)
126 0x01, // bNumInterfaces 123 0x01, // bNumInterfaces
127 DEFAULT_CONFIGURATION, // bConfigurationValue 124 DEFAULT_CONFIGURATION, // bConfigurationValue
128 0x00, // iConfiguration 125 0x00, // iConfiguration
129 C_RESERVED | C_REMOTE_WAKEUP, // bmAttributes 126 C_RESERVED | C_REMOTE_WAKEUP, // bmAttributes
130 C_POWER(100), // bMaxPowerHello World from Mbed 127 C_POWER(100), // bMaxPowerHello World from Mbed
131 128
132 INTERFACE_DESCRIPTOR_LENGTH, // bLength 129 INTERFACE_DESCRIPTOR_LENGTH, // bLength
133 INTERFACE_DESCRIPTOR, // bDescriptorType 130 INTERFACE_DESCRIPTOR, // bDescriptorType
134 0x00, // bInterfaceNumber 131 0x00, // bInterfaceNumber
135 0x00, // bAlternateSetting 132 0x00, // bAlternateSetting
136 0x01, // bNumEndpoints 133 0x01, // bNumEndpoints
137 HID_CLASS, // bInterfaceClass 134 HID_CLASS, // bInterfaceClass
138 1, // bInterfaceSubClass (boot) 135 1, // bInterfaceSubClass (boot)
139 1, // bInterfaceProtocol (keyboard) 136 1, // bInterfaceProtocol (keyboard)
140 0x00, // iInterface 137 0x00, // iInterface
141 138
142 HID_DESCRIPTOR_LENGTH, // bLength 139 HID_DESCRIPTOR_LENGTH, // bLength
143 HID_DESCRIPTOR, // bDescriptorType 140 HID_DESCRIPTOR, // bDescriptorType
144 LSB(HID_VERSION_1_11), // bcdHID (LSB) 141 LSB(HID_VERSION_1_11), // bcdHID (LSB)
145 MSB(HID_VERSION_1_11), // bcdHID (MSB) 142 MSB(HID_VERSION_1_11), // bcdHID (MSB)
146 0x00, // bCountryCode 143 0x00, // bCountryCode
147 0x01, // bNumDescriptors 144 0x01, // bNumDescriptors
148 REPORT_DESCRIPTOR, // bDescriptorType 145 REPORT_DESCRIPTOR, // bDescriptorType
149 (uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB) 146 (uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB)
150 (uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB) 147 (uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB)
151 148
152 ENDPOINT_DESCRIPTOR_LENGTH, // bLength 149 ENDPOINT_DESCRIPTOR_LENGTH, // bLength
153 ENDPOINT_DESCRIPTOR, // bDescriptorType 150 ENDPOINT_DESCRIPTOR, // bDescriptorType
154 PHY_TO_DESC(EP1IN), // bEndpointAddress 151 PHY_TO_DESC(EP1IN), // bEndpointAddress
155 E_INTERRUPT, // bmAttributes 152 E_INTERRUPT, // bmAttributes
156 LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) 153 LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
157 MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) 154 MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
158 1, // bInterval (milliseconds) 155 1, // bInterval (milliseconds)
159 }; 156 };
160 return configurationDescriptor; 157 return configurationDescriptor;
@@ -187,41 +184,35 @@ uint8_t * HIDKeyboard::deviceDesc() {
187#endif 184#endif
188 185
189bool HIDKeyboard::USBCallback_request() { 186bool HIDKeyboard::USBCallback_request() {
190 bool success = false; 187 bool success = false;
191 CONTROL_TRANSFER * transfer = getTransferPtr(); 188 CONTROL_TRANSFER *transfer = getTransferPtr();
192 uint8_t *hidDescriptor; 189 uint8_t * hidDescriptor;
193 190
194 // Process additional standard requests 191 // Process additional standard requests
195 192
196 if ((transfer->setup.bmRequestType.Type == STANDARD_TYPE)) 193 if ((transfer->setup.bmRequestType.Type == STANDARD_TYPE)) {
197 { 194 switch (transfer->setup.bRequest) {
198 switch (transfer->setup.bRequest)
199 {
200 case GET_DESCRIPTOR: 195 case GET_DESCRIPTOR:
201 switch (DESCRIPTOR_TYPE(transfer->setup.wValue)) 196 switch (DESCRIPTOR_TYPE(transfer->setup.wValue)) {
202 {
203 case REPORT_DESCRIPTOR: 197 case REPORT_DESCRIPTOR:
204 if ((reportDesc() != NULL) \ 198 if ((reportDesc() != NULL) && (reportDescLength() != 0)) {
205 && (reportDescLength() != 0))
206 {
207 transfer->remaining = reportDescLength(); 199 transfer->remaining = reportDescLength();
208 transfer->ptr = reportDesc(); 200 transfer->ptr = reportDesc();
209 transfer->direction = DEVICE_TO_HOST; 201 transfer->direction = DEVICE_TO_HOST;
210 success = true; 202 success = true;
211 } 203 }
212 break; 204 break;
213 case HID_DESCRIPTOR: 205 case HID_DESCRIPTOR:
214 // Find the HID descriptor, after the configuration descriptor 206 // Find the HID descriptor, after the configuration descriptor
215 hidDescriptor = findDescriptor(HID_DESCRIPTOR); 207 hidDescriptor = findDescriptor(HID_DESCRIPTOR);
216 if (hidDescriptor != NULL) 208 if (hidDescriptor != NULL) {
217 { 209 transfer->remaining = HID_DESCRIPTOR_LENGTH;
218 transfer->remaining = HID_DESCRIPTOR_LENGTH; 210 transfer->ptr = hidDescriptor;
219 transfer->ptr = hidDescriptor; 211 transfer->direction = DEVICE_TO_HOST;
220 transfer->direction = DEVICE_TO_HOST; 212 success = true;
221 success = true; 213 }
222 } 214 break;
223 break; 215
224
225 default: 216 default:
226 break; 217 break;
227 } 218 }
@@ -232,8 +223,7 @@ bool HIDKeyboard::USBCallback_request() {
232 } 223 }
233 224
234 // Process class-specific requests 225 // Process class-specific requests
235 if (transfer->setup.bmRequestType.Type == CLASS_TYPE) 226 if (transfer->setup.bmRequestType.Type == CLASS_TYPE) {
236 {
237 switch (transfer->setup.bRequest) { 227 switch (transfer->setup.bRequest) {
238 case SET_REPORT: 228 case SET_REPORT:
239 // LED indicator 229 // LED indicator
@@ -242,10 +232,10 @@ bool HIDKeyboard::USBCallback_request() {
242 // if (transfer->setup.wLength == 1) 232 // if (transfer->setup.wLength == 1)
243 233
244 transfer->remaining = 1; 234 transfer->remaining = 1;
245 //transfer->ptr = ?? what ptr should be set when OUT(not used?) 235 // transfer->ptr = ?? what ptr should be set when OUT(not used?)
246 transfer->direction = HOST_TO_DEVICE; 236 transfer->direction = HOST_TO_DEVICE;
247 transfer->notify = true; /* notify with USBCallback_requestCompleted */ 237 transfer->notify = true; /* notify with USBCallback_requestCompleted */
248 success = true; 238 success = true;
249 default: 239 default:
250 break; 240 break;
251 } 241 }
@@ -254,8 +244,7 @@ bool HIDKeyboard::USBCallback_request() {
254 return success; 244 return success;
255} 245}
256 246
257void HIDKeyboard::USBCallback_requestCompleted(uint8_t * buf, uint32_t length) 247void HIDKeyboard::USBCallback_requestCompleted(uint8_t *buf, uint32_t length) {
258{
259 if (length > 0) { 248 if (length > 0) {
260 CONTROL_TRANSFER *transfer = getTransferPtr(); 249 CONTROL_TRANSFER *transfer = getTransferPtr();
261 if (transfer->setup.bmRequestType.Type == CLASS_TYPE) { 250 if (transfer->setup.bmRequestType.Type == CLASS_TYPE) {