diff options
| author | tmk <nobody@nowhere> | 2014-11-24 13:50:33 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2014-11-24 13:50:33 +0900 |
| commit | 363950982a291c3bfa03ac6362061b1d37dc06b0 (patch) | |
| tree | c46fc53fe00137ced3c8edd3d0766ee844f77516 /protocol/mbed | |
| parent | eb90ed6238426db9367e294abfaefb5de07564f5 (diff) | |
| parent | 60096e11c77980ca6b54674c5b68248e8aa15d8d (diff) | |
| download | qmk_firmware-363950982a291c3bfa03ac6362061b1d37dc06b0.tar.gz qmk_firmware-363950982a291c3bfa03ac6362061b1d37dc06b0.zip | |
Merge branch 'rn42' into merge_rn42
Conflicts:
.gitignore
common.mk
common/debug_config.h
common/print.h
Diffstat (limited to 'protocol/mbed')
| -rw-r--r-- | protocol/mbed/HIDKeyboard.cpp | 271 | ||||
| -rw-r--r-- | protocol/mbed/HIDKeyboard.h | 31 | ||||
| -rw-r--r-- | protocol/mbed/mbed_driver.cpp | 41 | ||||
| -rw-r--r-- | protocol/mbed/mbed_driver.h | 3 |
4 files changed, 346 insertions, 0 deletions
diff --git a/protocol/mbed/HIDKeyboard.cpp b/protocol/mbed/HIDKeyboard.cpp new file mode 100644 index 000000000..947077cd2 --- /dev/null +++ b/protocol/mbed/HIDKeyboard.cpp | |||
| @@ -0,0 +1,271 @@ | |||
| 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 | uint8_t HIDKeyboard::leds() { | ||
| 21 | return led_state; | ||
| 22 | } | ||
| 23 | |||
| 24 | bool HIDKeyboard::USBCallback_setConfiguration(uint8_t configuration) { | ||
| 25 | if (configuration != DEFAULT_CONFIGURATION) { | ||
| 26 | return false; | ||
| 27 | } | ||
| 28 | |||
| 29 | // Configure endpoints > 0 | ||
| 30 | addEndpoint(EPINT_IN, MAX_PACKET_SIZE_EPINT); | ||
| 31 | //addEndpoint(EPINT_OUT, MAX_PACKET_SIZE_EPINT); | ||
| 32 | |||
| 33 | // We activate the endpoint to be able to recceive data | ||
| 34 | //readStart(EPINT_OUT, MAX_PACKET_SIZE_EPINT); | ||
| 35 | return true; | ||
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | uint8_t * HIDKeyboard::stringImanufacturerDesc() { | ||
| 40 | static uint8_t stringImanufacturerDescriptor[] = { | ||
| 41 | 0x18, /*bLength*/ | ||
| 42 | 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*/ | ||
| 44 | }; | ||
| 45 | return stringImanufacturerDescriptor; | ||
| 46 | } | ||
| 47 | |||
| 48 | uint8_t * HIDKeyboard::stringIproductDesc() { | ||
| 49 | static uint8_t stringIproductDescriptor[] = { | ||
| 50 | 0x0a, /*bLength*/ | ||
| 51 | STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ | ||
| 52 | 'm',0,'b',0,'e',0,'d',0 /*bString iProduct*/ | ||
| 53 | }; | ||
| 54 | return stringIproductDescriptor; | ||
| 55 | } | ||
| 56 | |||
| 57 | uint8_t * HIDKeyboard::stringIserialDesc() { | ||
| 58 | static uint8_t stringIserialDescriptor[] = { | ||
| 59 | 0x04, /*bLength*/ | ||
| 60 | STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ | ||
| 61 | '0',0 /*bString iSerial*/ | ||
| 62 | }; | ||
| 63 | return stringIserialDescriptor; | ||
| 64 | } | ||
| 65 | |||
| 66 | uint8_t * HIDKeyboard::reportDesc() { | ||
| 67 | static uint8_t reportDescriptor[] = { | ||
| 68 | USAGE_PAGE(1), 0x01, // Generic Desktop | ||
| 69 | USAGE(1), 0x06, // Keyboard | ||
| 70 | 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 | |||
| 81 | REPORT_COUNT(1), 0x01, | ||
| 82 | REPORT_SIZE(1), 0x08, | ||
| 83 | INPUT(1), 0x01, // Constant | ||
| 84 | |||
| 85 | REPORT_COUNT(1), 0x05, | ||
| 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 | |||
| 92 | REPORT_COUNT(1), 0x01, | ||
| 93 | REPORT_SIZE(1), 0x03, | ||
| 94 | OUTPUT(1), 0x01, // Constant | ||
| 95 | |||
| 96 | |||
| 97 | REPORT_COUNT(1), 0x06, | ||
| 98 | REPORT_SIZE(1), 0x08, | ||
| 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), | ||
| 106 | }; | ||
| 107 | reportLength = sizeof(reportDescriptor); | ||
| 108 | return reportDescriptor; | ||
| 109 | } | ||
| 110 | |||
| 111 | uint16_t HIDKeyboard::reportDescLength() { | ||
| 112 | reportDesc(); | ||
| 113 | return reportLength; | ||
| 114 | } | ||
| 115 | |||
| 116 | #define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \ | ||
| 117 | + (1 * INTERFACE_DESCRIPTOR_LENGTH) \ | ||
| 118 | + (1 * HID_DESCRIPTOR_LENGTH) \ | ||
| 119 | + (1 * ENDPOINT_DESCRIPTOR_LENGTH)) | ||
| 120 | uint8_t * HIDKeyboard::configurationDesc() { | ||
| 121 | static uint8_t configurationDescriptor[] = { | ||
| 122 | CONFIGURATION_DESCRIPTOR_LENGTH,// bLength | ||
| 123 | CONFIGURATION_DESCRIPTOR, // bDescriptorType | ||
| 124 | LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB) | ||
| 125 | MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB) | ||
| 126 | 0x01, // bNumInterfaces | ||
| 127 | DEFAULT_CONFIGURATION, // bConfigurationValue | ||
| 128 | 0x00, // iConfiguration | ||
| 129 | C_RESERVED | C_REMOTE_WAKEUP, // bmAttributes | ||
| 130 | C_POWER(100), // bMaxPowerHello World from Mbed | ||
| 131 | |||
| 132 | INTERFACE_DESCRIPTOR_LENGTH, // bLength | ||
| 133 | INTERFACE_DESCRIPTOR, // bDescriptorType | ||
| 134 | 0x00, // bInterfaceNumber | ||
| 135 | 0x00, // bAlternateSetting | ||
| 136 | 0x01, // bNumEndpoints | ||
| 137 | HID_CLASS, // bInterfaceClass | ||
| 138 | 1, // bInterfaceSubClass (boot) | ||
| 139 | 1, // bInterfaceProtocol (keyboard) | ||
| 140 | 0x00, // iInterface | ||
| 141 | |||
| 142 | HID_DESCRIPTOR_LENGTH, // bLength | ||
| 143 | HID_DESCRIPTOR, // bDescriptorType | ||
| 144 | LSB(HID_VERSION_1_11), // bcdHID (LSB) | ||
| 145 | MSB(HID_VERSION_1_11), // bcdHID (MSB) | ||
| 146 | 0x00, // bCountryCode | ||
| 147 | 0x01, // bNumDescriptors | ||
| 148 | REPORT_DESCRIPTOR, // bDescriptorType | ||
| 149 | (uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB) | ||
| 150 | (uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB) | ||
| 151 | |||
| 152 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength | ||
| 153 | ENDPOINT_DESCRIPTOR, // bDescriptorType | ||
| 154 | PHY_TO_DESC(EP1IN), // bEndpointAddress | ||
| 155 | E_INTERRUPT, // bmAttributes | ||
| 156 | LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) | ||
| 157 | MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) | ||
| 158 | 1, // bInterval (milliseconds) | ||
| 159 | }; | ||
| 160 | return configurationDescriptor; | ||
| 161 | } | ||
| 162 | |||
| 163 | #if 0 | ||
| 164 | uint8_t * HIDKeyboard::deviceDesc() { | ||
| 165 | static uint8_t deviceDescriptor[] = { | ||
| 166 | DEVICE_DESCRIPTOR_LENGTH, /* bLength */ | ||
| 167 | DEVICE_DESCRIPTOR, /* bDescriptorType */ | ||
| 168 | LSB(USB_VERSION_2_0), /* bcdUSB (LSB) */ | ||
| 169 | MSB(USB_VERSION_2_0), /* bcdUSB (MSB) */ | ||
| 170 | 0x00, /* bDeviceClass */ | ||
| 171 | 0x00, /* bDeviceSubClass */ | ||
| 172 | 0x00, /* bDeviceprotocol */ | ||
| 173 | MAX_PACKET_SIZE_EP0, /* bMaxPacketSize0 */ | ||
| 174 | (uint8_t)(LSB(0xfeed)), /* idVendor (LSB) */ | ||
| 175 | (uint8_t)(MSB(0xfeed)), /* idVendor (MSB) */ | ||
| 176 | (uint8_t)(LSB(0x1bed)), /* idProduct (LSB) */ | ||
| 177 | (uint8_t)(MSB(0x1bed)), /* idProduct (MSB) */ | ||
| 178 | (uint8_t)(LSB(0x0002)), /* bcdDevice (LSB) */ | ||
| 179 | (uint8_t)(MSB(0x0002)), /* bcdDevice (MSB) */ | ||
| 180 | 0, /* iManufacturer */ | ||
| 181 | 0, /* iProduct */ | ||
| 182 | 0, /* iSerialNumber */ | ||
| 183 | 0x01 /* bNumConfigurations */ | ||
| 184 | }; | ||
| 185 | return deviceDescriptor; | ||
| 186 | } | ||
| 187 | #endif | ||
| 188 | |||
| 189 | bool HIDKeyboard::USBCallback_request() { | ||
| 190 | bool success = false; | ||
| 191 | CONTROL_TRANSFER * transfer = getTransferPtr(); | ||
| 192 | uint8_t *hidDescriptor; | ||
| 193 | |||
| 194 | // Process additional standard requests | ||
| 195 | |||
| 196 | if ((transfer->setup.bmRequestType.Type == STANDARD_TYPE)) | ||
| 197 | { | ||
| 198 | switch (transfer->setup.bRequest) | ||
| 199 | { | ||
| 200 | case GET_DESCRIPTOR: | ||
| 201 | switch (DESCRIPTOR_TYPE(transfer->setup.wValue)) | ||
| 202 | { | ||
| 203 | case REPORT_DESCRIPTOR: | ||
| 204 | if ((reportDesc() != NULL) \ | ||
| 205 | && (reportDescLength() != 0)) | ||
| 206 | { | ||
| 207 | transfer->remaining = reportDescLength(); | ||
| 208 | transfer->ptr = reportDesc(); | ||
| 209 | transfer->direction = DEVICE_TO_HOST; | ||
| 210 | success = true; | ||
| 211 | } | ||
| 212 | break; | ||
| 213 | case HID_DESCRIPTOR: | ||
| 214 | // Find the HID descriptor, after the configuration descriptor | ||
| 215 | hidDescriptor = findDescriptor(HID_DESCRIPTOR); | ||
| 216 | if (hidDescriptor != NULL) | ||
| 217 | { | ||
| 218 | transfer->remaining = HID_DESCRIPTOR_LENGTH; | ||
| 219 | transfer->ptr = hidDescriptor; | ||
| 220 | transfer->direction = DEVICE_TO_HOST; | ||
| 221 | success = true; | ||
| 222 | } | ||
| 223 | break; | ||
| 224 | |||
| 225 | default: | ||
| 226 | break; | ||
| 227 | } | ||
| 228 | break; | ||
| 229 | default: | ||
| 230 | break; | ||
| 231 | } | ||
| 232 | } | ||
| 233 | |||
| 234 | // Process class-specific requests | ||
| 235 | if (transfer->setup.bmRequestType.Type == CLASS_TYPE) | ||
| 236 | { | ||
| 237 | switch (transfer->setup.bRequest) { | ||
| 238 | case SET_REPORT: | ||
| 239 | // LED indicator | ||
| 240 | // TODO: check Interface and Report length? | ||
| 241 | // if (transfer->setup.wIndex == INTERFACE_KEYBOAD) { } | ||
| 242 | // if (transfer->setup.wLength == 1) | ||
| 243 | |||
| 244 | transfer->remaining = 1; | ||
| 245 | //transfer->ptr = ?? what ptr should be set when OUT(not used?) | ||
| 246 | transfer->direction = HOST_TO_DEVICE; | ||
| 247 | transfer->notify = true; /* notify with USBCallback_requestCompleted */ | ||
| 248 | success = true; | ||
| 249 | default: | ||
| 250 | break; | ||
| 251 | } | ||
| 252 | } | ||
| 253 | |||
| 254 | return success; | ||
| 255 | } | ||
| 256 | |||
| 257 | void HIDKeyboard::USBCallback_requestCompleted(uint8_t * buf, uint32_t length) | ||
| 258 | { | ||
| 259 | if (length > 0) { | ||
| 260 | CONTROL_TRANSFER *transfer = getTransferPtr(); | ||
| 261 | if (transfer->setup.bmRequestType.Type == CLASS_TYPE) { | ||
| 262 | switch (transfer->setup.bRequest) { | ||
| 263 | case SET_REPORT: | ||
| 264 | led_state = buf[0]; | ||
| 265 | break; | ||
| 266 | default: | ||
| 267 | break; | ||
| 268 | } | ||
| 269 | } | ||
| 270 | } | ||
| 271 | } | ||
diff --git a/protocol/mbed/HIDKeyboard.h b/protocol/mbed/HIDKeyboard.h new file mode 100644 index 000000000..c537e5ece --- /dev/null +++ b/protocol/mbed/HIDKeyboard.h | |||
| @@ -0,0 +1,31 @@ | |||
| 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 | uint8_t leds(void); | ||
| 15 | protected: | ||
| 16 | uint16_t reportLength; | ||
| 17 | virtual bool USBCallback_setConfiguration(uint8_t configuration); | ||
| 18 | virtual uint8_t * stringImanufacturerDesc(); | ||
| 19 | virtual uint8_t * stringIproductDesc(); | ||
| 20 | virtual uint8_t * stringIserialDesc(); | ||
| 21 | virtual uint16_t reportDescLength(); | ||
| 22 | virtual uint8_t * reportDesc(); | ||
| 23 | virtual uint8_t * configurationDesc(); | ||
| 24 | //virtual uint8_t * deviceDesc(); | ||
| 25 | virtual bool USBCallback_request(); | ||
| 26 | virtual void USBCallback_requestCompleted(uint8_t * buf, uint32_t length); | ||
| 27 | private: | ||
| 28 | uint8_t led_state; | ||
| 29 | }; | ||
| 30 | |||
| 31 | #endif | ||
diff --git a/protocol/mbed/mbed_driver.cpp b/protocol/mbed/mbed_driver.cpp new file mode 100644 index 000000000..6c7b16e23 --- /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 keyboard.leds(); | ||
| 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; | ||
