diff options
| author | tmk <nobody@nowhere> | 2014-06-18 02:22:59 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2014-07-30 14:07:43 +0900 |
| commit | 80c3ff5fa03429f1e4ea15032f665ceb88c9b8c3 (patch) | |
| tree | 803fe5b419419607146b6ba1db69d24486b1494e /protocol | |
| parent | e81c70149ecf73256f8bb7d77cefc07f2b91d2be (diff) | |
| download | qmk_firmware-80c3ff5fa03429f1e4ea15032f665ceb88c9b8c3.tar.gz qmk_firmware-80c3ff5fa03429f1e4ea15032f665ceb88c9b8c3.zip | |
Fix build files for mbed
Diffstat (limited to 'protocol')
| -rw-r--r-- | protocol/mbed/HIDKeyboard.cpp | 256 | ||||
| -rw-r--r-- | protocol/mbed/HIDKeyboard.h | 27 | ||||
| -rw-r--r-- | protocol/mbed/mbed_driver.cpp | 41 | ||||
| -rw-r--r-- | protocol/mbed/mbed_driver.h | 3 |
4 files changed, 327 insertions, 0 deletions
diff --git a/protocol/mbed/HIDKeyboard.cpp b/protocol/mbed/HIDKeyboard.cpp new file mode 100644 index 000000000..f40c2d2f2 --- /dev/null +++ b/protocol/mbed/HIDKeyboard.cpp | |||
| @@ -0,0 +1,256 @@ | |||
| 1 | #include <stdint.h> | ||
| 2 | #include "USBHID.h" | ||
| 3 | #include "USBHID_Types.h" | ||
| 4 | #include "USBDescriptor.h" | ||
| 5 | #include "HIDKeyboard.h" | ||
| 6 | |||
| 7 | #define DEFAULT_CONFIGURATION (1) | ||
| 8 | |||
| 9 | |||
| 10 | HIDKeyboard::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 | |||
| 15 | bool HIDKeyboard::sendReport(report_keyboard_t report) { | ||
| 16 | USBDevice::write(EP1IN, report.raw, sizeof(report), MAX_PACKET_SIZE_EP1); | ||
| 17 | return true; | ||
| 18 | } | ||
| 19 | |||
| 20 | bool HIDKeyboard::USBCallback_setConfiguration(uint8_t configuration) { | ||
| 21 | if (configuration != DEFAULT_CONFIGURATION) { | ||
| 22 | return false; | ||
| 23 | } | ||
| 24 | |||
| 25 | // Configure endpoints > 0 | ||
| 26 | addEndpoint(EPINT_IN, MAX_PACKET_SIZE_EPINT); | ||
| 27 | //addEndpoint(EPINT_OUT, MAX_PACKET_SIZE_EPINT); | ||
| 28 | |||
| 29 | // We activate the endpoint to be able to recceive data | ||
| 30 | //readStart(EPINT_OUT, MAX_PACKET_SIZE_EPINT); | ||
| 31 | return true; | ||
| 32 | } | ||
| 33 | |||
| 34 | |||
| 35 | uint8_t * HIDKeyboard::stringImanufacturerDesc() { | ||
| 36 | static uint8_t stringImanufacturerDescriptor[] = { | ||
| 37 | 0x18, /*bLength*/ | ||
| 38 | STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ | ||
| 39 | 't',0,'m',0,'k',0,'-',0,'k',0,'b',0,'d',0,'.',0,'c',0,'o',0,'m',0 /*bString iManufacturer*/ | ||
| 40 | }; | ||
| 41 | return stringImanufacturerDescriptor; | ||
| 42 | } | ||
| 43 | |||
| 44 | uint8_t * HIDKeyboard::stringIproductDesc() { | ||
| 45 | static uint8_t stringIproductDescriptor[] = { | ||
| 46 | 0x0a, /*bLength*/ | ||
| 47 | STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ | ||
| 48 | 'm',0,'b',0,'e',0,'d',0 /*bString iProduct*/ | ||
| 49 | }; | ||
| 50 | return stringIproductDescriptor; | ||
| 51 | } | ||
| 52 | |||
| 53 | uint8_t * HIDKeyboard::stringIserialDesc() { | ||
| 54 | static uint8_t stringIserialDescriptor[] = { | ||
| 55 | 0x04, /*bLength*/ | ||
| 56 | STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ | ||
| 57 | '0',0 /*bString iSerial*/ | ||
| 58 | }; | ||
| 59 | return stringIserialDescriptor; | ||
| 60 | } | ||
| 61 | |||
| 62 | uint8_t * HIDKeyboard::reportDesc() { | ||
| 63 | static uint8_t reportDescriptor[] = { | ||
| 64 | USAGE_PAGE(1), 0x01, // Generic Desktop | ||
| 65 | USAGE(1), 0x06, // Keyboard | ||
| 66 | COLLECTION(1), 0x01, // Application | ||
| 67 | |||
| 68 | USAGE_PAGE(1), 0x07, // Key Codes | ||
| 69 | USAGE_MINIMUM(1), 0xE0, | ||
| 70 | USAGE_MAXIMUM(1), 0xE7, | ||
| 71 | LOGICAL_MINIMUM(1), 0x00, | ||
| 72 | LOGICAL_MAXIMUM(1), 0x01, | ||
| 73 | REPORT_SIZE(1), 0x01, | ||
| 74 | REPORT_COUNT(1), 0x08, | ||
| 75 | INPUT(1), 0x02, // Data, Variable, Absolute | ||
| 76 | |||
| 77 | REPORT_COUNT(1), 0x01, | ||
| 78 | REPORT_SIZE(1), 0x08, | ||
| 79 | INPUT(1), 0x01, // Constant | ||
| 80 | |||
| 81 | REPORT_COUNT(1), 0x05, | ||
| 82 | REPORT_SIZE(1), 0x01, | ||
| 83 | USAGE_PAGE(1), 0x08, // LEDs | ||
| 84 | USAGE_MINIMUM(1), 0x01, | ||
| 85 | USAGE_MAXIMUM(1), 0x05, | ||
| 86 | OUTPUT(1), 0x02, // Data, Variable, Absolute | ||
| 87 | |||
| 88 | REPORT_COUNT(1), 0x01, | ||
| 89 | REPORT_SIZE(1), 0x03, | ||
| 90 | OUTPUT(1), 0x01, // Constant | ||
| 91 | |||
| 92 | |||
| 93 | REPORT_COUNT(1), 0x06, | ||
| 94 | REPORT_SIZE(1), 0x08, | ||
| 95 | LOGICAL_MINIMUM(1), 0x00, | ||
| 96 | LOGICAL_MAXIMUM(1), 0xFF, | ||
| 97 | USAGE_PAGE(1), 0x07, // Key Codes | ||
| 98 | USAGE_MINIMUM(1), 0x00, | ||
| 99 | USAGE_MAXIMUM(1), 0xFF, | ||
| 100 | INPUT(1), 0x00, // Data, Array | ||
| 101 | END_COLLECTION(0), | ||
| 102 | }; | ||
| 103 | reportLength = sizeof(reportDescriptor); | ||
| 104 | return reportDescriptor; | ||
| 105 | } | ||
| 106 | |||
| 107 | uint16_t HIDKeyboard::reportDescLength() { | ||
| 108 | reportDesc(); | ||
| 109 | return reportLength; | ||
| 110 | } | ||
| 111 | |||
| 112 | #define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \ | ||
| 113 | + (1 * INTERFACE_DESCRIPTOR_LENGTH) \ | ||
| 114 | + (1 * HID_DESCRIPTOR_LENGTH) \ | ||
| 115 | + (1 * ENDPOINT_DESCRIPTOR_LENGTH)) | ||
| 116 | uint8_t * HIDKeyboard::configurationDesc() { | ||
| 117 | static uint8_t configurationDescriptor[] = { | ||
| 118 | CONFIGURATION_DESCRIPTOR_LENGTH,// bLength | ||
| 119 | CONFIGURATION_DESCRIPTOR, // bDescriptorType | ||
| 120 | LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB) | ||
| 121 | MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB) | ||
| 122 | 0x01, // bNumInterfaces | ||
| 123 | DEFAULT_CONFIGURATION, // bConfigurationValue | ||
| 124 | 0x00, // iConfiguration | ||
| 125 | C_RESERVED | C_REMOTE_WAKEUP, // bmAttributes | ||
| 126 | C_POWER(100), // bMaxPowerHello World from Mbed | ||
| 127 | |||
| 128 | INTERFACE_DESCRIPTOR_LENGTH, // bLength | ||
| 129 | INTERFACE_DESCRIPTOR, // bDescriptorType | ||
| 130 | 0x00, // bInterfaceNumber | ||
| 131 | 0x00, // bAlternateSetting | ||
| 132 | 0x01, // bNumEndpoints | ||
| 133 | HID_CLASS, // bInterfaceClass | ||
| 134 | 1, // bInterfaceSubClass (boot) | ||
| 135 | 1, // bInterfaceProtocol (keyboard) | ||
| 136 | 0x00, // iInterface | ||
| 137 | |||
| 138 | HID_DESCRIPTOR_LENGTH, // bLength | ||
| 139 | HID_DESCRIPTOR, // bDescriptorType | ||
| 140 | LSB(HID_VERSION_1_11), // bcdHID (LSB) | ||
| 141 | MSB(HID_VERSION_1_11), // bcdHID (MSB) | ||
| 142 | 0x00, // bCountryCode | ||
| 143 | 0x01, // bNumDescriptors | ||
| 144 | REPORT_DESCRIPTOR, // bDescriptorType | ||
| 145 | (uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB) | ||
| 146 | (uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB) | ||
| 147 | |||
| 148 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength | ||
| 149 | ENDPOINT_DESCRIPTOR, // bDescriptorType | ||
| 150 | PHY_TO_DESC(EP1IN), // bEndpointAddress | ||
| 151 | E_INTERRUPT, // bmAttributes | ||
| 152 | LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) | ||
| 153 | MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) | ||
| 154 | 1, // bInterval (milliseconds) | ||
| 155 | }; | ||
| 156 | return configurationDescriptor; | ||
| 157 | } | ||
| 158 | |||
| 159 | #if 0 | ||
| 160 | uint8_t * HIDKeyboard::deviceDesc() { | ||
| 161 | static uint8_t deviceDescriptor[] = { | ||
| 162 | DEVICE_DESCRIPTOR_LENGTH, /* bLength */ | ||
| 163 | DEVICE_DESCRIPTOR, /* bDescriptorType */ | ||
| 164 | LSB(USB_VERSION_2_0), /* bcdUSB (LSB) */ | ||
| 165 | MSB(USB_VERSION_2_0), /* bcdUSB (MSB) */ | ||
| 166 | 0x00, /* bDeviceClass */ | ||
| 167 | 0x00, /* bDeviceSubClass */ | ||
| 168 | 0x00, /* bDeviceprotocol */ | ||
| 169 | MAX_PACKET_SIZE_EP0, /* bMaxPacketSize0 */ | ||
| 170 | (uint8_t)(LSB(0xfeed)), /* idVendor (LSB) */ | ||
| 171 | (uint8_t)(MSB(0xfeed)), /* idVendor (MSB) */ | ||
| 172 | (uint8_t)(LSB(0x1bed)), /* idProduct (LSB) */ | ||
| 173 | (uint8_t)(MSB(0x1bed)), /* idProduct (MSB) */ | ||
| 174 | (uint8_t)(LSB(0x0002)), /* bcdDevice (LSB) */ | ||
| 175 | (uint8_t)(MSB(0x0002)), /* bcdDevice (MSB) */ | ||
| 176 | 0, /* iManufacturer */ | ||
| 177 | 0, /* iProduct */ | ||
| 178 | 0, /* iSerialNumber */ | ||
| 179 | 0x01 /* bNumConfigurations */ | ||
| 180 | }; | ||
| 181 | return deviceDescriptor; | ||
| 182 | } | ||
| 183 | #endif | ||
| 184 | |||
| 185 | bool HIDKeyboard::USBCallback_request() { | ||
| 186 | bool success = false; | ||
| 187 | CONTROL_TRANSFER * transfer = getTransferPtr(); | ||
| 188 | uint8_t *hidDescriptor; | ||
| 189 | |||
| 190 | // Process additional standard requests | ||
| 191 | |||
| 192 | if ((transfer->setup.bmRequestType.Type == STANDARD_TYPE)) | ||
| 193 | { | ||
| 194 | switch (transfer->setup.bRequest) | ||
| 195 | { | ||
| 196 | case GET_DESCRIPTOR: | ||
| 197 | switch (DESCRIPTOR_TYPE(transfer->setup.wValue)) | ||
| 198 | { | ||
| 199 | case REPORT_DESCRIPTOR: | ||
| 200 | if ((reportDesc() != NULL) \ | ||
| 201 | && (reportDescLength() != 0)) | ||
| 202 | { | ||
| 203 | transfer->remaining = reportDescLength(); | ||
| 204 | transfer->ptr = reportDesc(); | ||
| 205 | transfer->direction = DEVICE_TO_HOST; | ||
| 206 | success = true; | ||
| 207 | } | ||
| 208 | break; | ||
| 209 | case HID_DESCRIPTOR: | ||
| 210 | // Find the HID descriptor, after the configuration descriptor | ||
| 211 | hidDescriptor = findDescriptor(HID_DESCRIPTOR); | ||
| 212 | if (hidDescriptor != NULL) | ||
| 213 | { | ||
| 214 | transfer->remaining = HID_DESCRIPTOR_LENGTH; | ||
| 215 | transfer->ptr = hidDescriptor; | ||
| 216 | transfer->direction = DEVICE_TO_HOST; | ||
| 217 | success = true; | ||
| 218 | } | ||
| 219 | break; | ||
| 220 | |||
| 221 | default: | ||
| 222 | break; | ||
| 223 | } | ||
| 224 | break; | ||
| 225 | default: | ||
| 226 | break; | ||
| 227 | } | ||
| 228 | } | ||
| 229 | |||
| 230 | // Process class-specific requests | ||
| 231 | /* | ||
| 232 | if (transfer->setup.bmRequestType.Type == CLASS_TYPE) | ||
| 233 | { | ||
| 234 | switch (transfer->setup.bRequest) | ||
| 235 | { | ||
| 236 | case SET_REPORT: | ||
| 237 | // First byte will be used for report ID | ||
| 238 | //outputReport.data[0] = transfer->setup.wValue & 0xff; | ||
| 239 | //outputReport.length = transfer->setup.wLength + 1; | ||
| 240 | outputReport.length = transfer->setup.wLength; | ||
| 241 | |||
| 242 | //transfer->remaining = sizeof(outputReport.data) - 1; | ||
| 243 | //transfer->ptr = &outputReport.data[1]; | ||
| 244 | transfer->remaining = sizeof(outputReport.data); | ||
| 245 | transfer->ptr = &outputReport.data[0]; | ||
| 246 | transfer->direction = HOST_TO_DEVICE; | ||
| 247 | transfer->notify = true; | ||
| 248 | success = true; | ||
| 249 | default: | ||
| 250 | break; | ||
| 251 | } | ||
| 252 | } | ||
| 253 | */ | ||
| 254 | |||
| 255 | return success; | ||
| 256 | } | ||
diff --git a/protocol/mbed/HIDKeyboard.h b/protocol/mbed/HIDKeyboard.h new file mode 100644 index 000000000..4ebe610a6 --- /dev/null +++ b/protocol/mbed/HIDKeyboard.h | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | #ifndef HIDKEYBOARD_H | ||
| 2 | |||
| 3 | #include "stdint.h" | ||
| 4 | #include "stdbool.h" | ||
| 5 | #include "USBHID.h" | ||
| 6 | #include "report.h" | ||
| 7 | |||
| 8 | |||
| 9 | class HIDKeyboard : public USBDevice { | ||
| 10 | public: | ||
| 11 | HIDKeyboard(uint16_t vendor_id = 0xFEED, uint16_t product_id = 0xabed, uint16_t product_release = 0x0001); | ||
| 12 | |||
| 13 | bool sendReport(report_keyboard_t report); | ||
| 14 | protected: | ||
| 15 | uint16_t reportLength; | ||
| 16 | virtual bool USBCallback_setConfiguration(uint8_t configuration); | ||
| 17 | virtual uint8_t * stringImanufacturerDesc(); | ||
| 18 | virtual uint8_t * stringIproductDesc(); | ||
| 19 | virtual uint8_t * stringIserialDesc(); | ||
| 20 | virtual uint16_t reportDescLength(); | ||
| 21 | virtual uint8_t * reportDesc(); | ||
| 22 | virtual uint8_t * configurationDesc(); | ||
| 23 | //virtual uint8_t * deviceDesc(); | ||
| 24 | virtual bool USBCallback_request(); | ||
| 25 | }; | ||
| 26 | |||
| 27 | #endif | ||
diff --git a/protocol/mbed/mbed_driver.cpp b/protocol/mbed/mbed_driver.cpp new file mode 100644 index 000000000..333f8e378 --- /dev/null +++ b/protocol/mbed/mbed_driver.cpp | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | #include "HIDKeyboard.h" | ||
| 2 | #include "host.h" | ||
| 3 | #include "host_driver.h" | ||
| 4 | #include "mbed_driver.h" | ||
| 5 | |||
| 6 | HIDKeyboard keyboard; | ||
| 7 | |||
| 8 | |||
| 9 | /* Host driver */ | ||
| 10 | static uint8_t keyboard_leds(void); | ||
| 11 | static void send_keyboard(report_keyboard_t *report); | ||
| 12 | static void send_mouse(report_mouse_t *report); | ||
| 13 | static void send_system(uint16_t data); | ||
| 14 | static void send_consumer(uint16_t data); | ||
| 15 | |||
| 16 | host_driver_t mbed_driver = { | ||
| 17 | keyboard_leds, | ||
| 18 | send_keyboard, | ||
| 19 | send_mouse, | ||
| 20 | send_system, | ||
| 21 | send_consumer | ||
| 22 | }; | ||
| 23 | |||
| 24 | |||
| 25 | static uint8_t keyboard_leds(void) | ||
| 26 | { | ||
| 27 | return 0; | ||
| 28 | } | ||
| 29 | static void send_keyboard(report_keyboard_t *report) | ||
| 30 | { | ||
| 31 | keyboard.sendReport(*report); | ||
| 32 | } | ||
| 33 | static void send_mouse(report_mouse_t *report) | ||
| 34 | { | ||
| 35 | } | ||
| 36 | static void send_system(uint16_t data) | ||
| 37 | { | ||
| 38 | } | ||
| 39 | static void send_consumer(uint16_t data) | ||
| 40 | { | ||
| 41 | } | ||
diff --git a/protocol/mbed/mbed_driver.h b/protocol/mbed/mbed_driver.h new file mode 100644 index 000000000..dd1153b43 --- /dev/null +++ b/protocol/mbed/mbed_driver.h | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | #include "host_driver.h" | ||
| 2 | |||
| 3 | extern host_driver_t mbed_driver; | ||
