diff options
Diffstat (limited to 'keyboard')
| -rw-r--r-- | keyboard/lufa/Descriptors.c | 791 | ||||
| -rw-r--r-- | keyboard/lufa/Descriptors.h | 89 | ||||
| -rw-r--r-- | keyboard/lufa/Makefile | 3 | ||||
| -rw-r--r-- | keyboard/lufa/lufa.c | 129 | ||||
| -rw-r--r-- | keyboard/lufa/lufa.h | 2 |
5 files changed, 595 insertions, 419 deletions
diff --git a/keyboard/lufa/Descriptors.c b/keyboard/lufa/Descriptors.c index 3195aa77a..a4e9defab 100644 --- a/keyboard/lufa/Descriptors.c +++ b/keyboard/lufa/Descriptors.c | |||
| @@ -1,359 +1,432 @@ | |||
| 1 | /* | 1 | /* |
| 2 | LUFA Library | 2 | * Copyright 2012 Jun Wako <wakojun@gmail.com> |
| 3 | Copyright (C) Dean Camera, 2012. | 3 | * This file is based on: |
| 4 | 4 | * LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse | |
| 5 | dean [at] fourwalledcubicle [dot] com | 5 | * LUFA-120219/Demos/Device/Lowlevel/GenericHID |
| 6 | www.lufa-lib.org | 6 | */ |
| 7 | */ | 7 | |
| 8 | 8 | /* | |
| 9 | /* | 9 | LUFA Library |
| 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) | 10 | Copyright (C) Dean Camera, 2012. |
| 11 | Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com) | 11 | |
| 12 | 12 | dean [at] fourwalledcubicle [dot] com | |
| 13 | Permission to use, copy, modify, distribute, and sell this | 13 | www.lufa-lib.org |
| 14 | software and its documentation for any purpose is hereby granted | 14 | */ |
| 15 | without fee, provided that the above copyright notice appear in | 15 | |
| 16 | all copies and that both that the copyright notice and this | 16 | /* |
| 17 | permission notice and warranty disclaimer appear in supporting | 17 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) |
| 18 | documentation, and that the name of the author not be used in | 18 | Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com) |
| 19 | advertising or publicity pertaining to distribution of the | 19 | |
| 20 | software without specific, written prior permission. | 20 | Permission to use, copy, modify, distribute, and sell this |
| 21 | 21 | software and its documentation for any purpose is hereby granted | |
| 22 | The author disclaim all warranties with regard to this | 22 | without fee, provided that the above copyright notice appear in |
| 23 | software, including all implied warranties of merchantability | 23 | all copies and that both that the copyright notice and this |
| 24 | and fitness. In no event shall the author be liable for any | 24 | permission notice and warranty disclaimer appear in supporting |
| 25 | special, indirect or consequential damages or any damages | 25 | documentation, and that the name of the author not be used in |
| 26 | whatsoever resulting from loss of use, data or profits, whether | 26 | advertising or publicity pertaining to distribution of the |
| 27 | in an action of contract, negligence or other tortious action, | 27 | software without specific, written prior permission. |
| 28 | arising out of or in connection with the use or performance of | 28 | |
| 29 | this software. | 29 | The author disclaim all warranties with regard to this |
| 30 | */ | 30 | software, including all implied warranties of merchantability |
| 31 | 31 | and fitness. In no event shall the author be liable for any | |
| 32 | /** \file | 32 | special, indirect or consequential damages or any damages |
| 33 | * | 33 | whatsoever resulting from loss of use, data or profits, whether |
| 34 | * USB Device Descriptors, for library use when in USB device mode. Descriptors are special | 34 | in an action of contract, negligence or other tortious action, |
| 35 | * computer-readable structures which the host requests upon device enumeration, to determine | 35 | arising out of or in connection with the use or performance of |
| 36 | * the device's capabilities and functions. | 36 | this software. |
| 37 | */ | 37 | */ |
| 38 | 38 | ||
| 39 | #include "Descriptors.h" | 39 | /** \file |
| 40 | 40 | * | |
| 41 | /** HID class report descriptor. This is a special descriptor constructed with values from the | 41 | * USB Device Descriptors, for library use when in USB device mode. Descriptors are special |
| 42 | * USBIF HID class specification to describe the reports and capabilities of the HID device. This | 42 | * computer-readable structures which the host requests upon device enumeration, to determine |
| 43 | * descriptor is parsed by the host and its contents used to determine what data (and in what encoding) | 43 | * the device's capabilities and functions. |
| 44 | * the device will send, and what it may be sent back from the host. Refer to the HID specification for | 44 | */ |
| 45 | * more details on HID report descriptors. | 45 | |
| 46 | * | 46 | #include "Descriptors.h" |
| 47 | * This descriptor describes the mouse HID interface's report structure. | 47 | |
| 48 | */ | 48 | |
| 49 | const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] = | 49 | /******************************************************************************* |
| 50 | { | 50 | * HID Report Descriptors |
| 51 | HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ | 51 | ******************************************************************************/ |
| 52 | HID_RI_USAGE(8, 0x02), /* Mouse */ | 52 | const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = |
| 53 | HID_RI_COLLECTION(8, 0x01), /* Application */ | 53 | { |
| 54 | HID_RI_USAGE(8, 0x01), /* Pointer */ | 54 | HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ |
| 55 | HID_RI_COLLECTION(8, 0x00), /* Physical */ | 55 | HID_RI_USAGE(8, 0x06), /* Keyboard */ |
| 56 | HID_RI_USAGE_PAGE(8, 0x09), /* Button */ | 56 | HID_RI_COLLECTION(8, 0x01), /* Application */ |
| 57 | HID_RI_USAGE_MINIMUM(8, 0x01), | 57 | HID_RI_USAGE_PAGE(8, 0x07), /* Key Codes */ |
| 58 | HID_RI_USAGE_MAXIMUM(8, 0x03), | 58 | HID_RI_USAGE_MINIMUM(8, 0xE0), /* Keyboard Left Control */ |
| 59 | HID_RI_LOGICAL_MINIMUM(8, 0x00), | 59 | HID_RI_USAGE_MAXIMUM(8, 0xE7), /* Keyboard Right GUI */ |
| 60 | HID_RI_LOGICAL_MAXIMUM(8, 0x01), | 60 | HID_RI_LOGICAL_MINIMUM(8, 0x00), |
| 61 | HID_RI_REPORT_COUNT(8, 0x03), | 61 | HID_RI_LOGICAL_MAXIMUM(8, 0x01), |
| 62 | HID_RI_REPORT_SIZE(8, 0x01), | 62 | HID_RI_REPORT_SIZE(8, 0x01), |
| 63 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), | 63 | HID_RI_REPORT_COUNT(8, 0x08), |
| 64 | HID_RI_REPORT_COUNT(8, 0x01), | 64 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), |
| 65 | HID_RI_REPORT_SIZE(8, 0x05), | 65 | HID_RI_REPORT_COUNT(8, 0x01), |
| 66 | HID_RI_INPUT(8, HID_IOF_CONSTANT), | 66 | HID_RI_REPORT_SIZE(8, 0x08), |
| 67 | HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ | 67 | HID_RI_INPUT(8, HID_IOF_CONSTANT), |
| 68 | HID_RI_USAGE(8, 0x30), /* Usage X */ | 68 | HID_RI_USAGE_PAGE(8, 0x08), /* LEDs */ |
| 69 | HID_RI_USAGE(8, 0x31), /* Usage Y */ | 69 | HID_RI_USAGE_MINIMUM(8, 0x01), /* Num Lock */ |
| 70 | HID_RI_LOGICAL_MINIMUM(8, -1), | 70 | HID_RI_USAGE_MAXIMUM(8, 0x05), /* Kana */ |
| 71 | HID_RI_LOGICAL_MAXIMUM(8, 1), | 71 | HID_RI_REPORT_COUNT(8, 0x05), |
| 72 | HID_RI_PHYSICAL_MINIMUM(8, -1), | 72 | HID_RI_REPORT_SIZE(8, 0x01), |
| 73 | HID_RI_PHYSICAL_MAXIMUM(8, 1), | 73 | HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), |
| 74 | HID_RI_REPORT_COUNT(8, 0x02), | 74 | HID_RI_REPORT_COUNT(8, 0x01), |
| 75 | HID_RI_REPORT_SIZE(8, 0x08), | 75 | HID_RI_REPORT_SIZE(8, 0x03), |
| 76 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), | 76 | HID_RI_OUTPUT(8, HID_IOF_CONSTANT), |
| 77 | HID_RI_END_COLLECTION(0), | 77 | HID_RI_LOGICAL_MINIMUM(8, 0x00), |
| 78 | HID_RI_END_COLLECTION(0), | 78 | HID_RI_LOGICAL_MAXIMUM(8, 0x65), |
| 79 | }; | 79 | HID_RI_USAGE_PAGE(8, 0x07), /* Keyboard */ |
| 80 | 80 | HID_RI_USAGE_MINIMUM(8, 0x00), /* Reserved (no event indicated) */ | |
| 81 | /** Same as the MouseReport structure, but defines the keyboard HID interface's report structure. */ | 81 | HID_RI_USAGE_MAXIMUM(8, 0x65), /* Keyboard Application */ |
| 82 | const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = | 82 | HID_RI_REPORT_COUNT(8, 0x06), |
| 83 | { | 83 | HID_RI_REPORT_SIZE(8, 0x08), |
| 84 | HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ | 84 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE), |
| 85 | HID_RI_USAGE(8, 0x06), /* Keyboard */ | 85 | HID_RI_END_COLLECTION(0), |
| 86 | HID_RI_COLLECTION(8, 0x01), /* Application */ | 86 | }; |
| 87 | HID_RI_USAGE_PAGE(8, 0x07), /* Key Codes */ | 87 | |
| 88 | HID_RI_USAGE_MINIMUM(8, 0xE0), /* Keyboard Left Control */ | 88 | const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] = |
| 89 | HID_RI_USAGE_MAXIMUM(8, 0xE7), /* Keyboard Right GUI */ | 89 | { |
| 90 | HID_RI_LOGICAL_MINIMUM(8, 0x00), | 90 | HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ |
| 91 | HID_RI_LOGICAL_MAXIMUM(8, 0x01), | 91 | HID_RI_USAGE(8, 0x02), /* Mouse */ |
| 92 | HID_RI_REPORT_SIZE(8, 0x01), | 92 | HID_RI_COLLECTION(8, 0x01), /* Application */ |
| 93 | HID_RI_REPORT_COUNT(8, 0x08), | 93 | HID_RI_USAGE(8, 0x01), /* Pointer */ |
| 94 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), | 94 | HID_RI_COLLECTION(8, 0x00), /* Physical */ |
| 95 | HID_RI_REPORT_COUNT(8, 0x01), | 95 | HID_RI_USAGE_PAGE(8, 0x09), /* Button */ |
| 96 | HID_RI_REPORT_SIZE(8, 0x08), | 96 | HID_RI_USAGE_MINIMUM(8, 0x01), |
| 97 | HID_RI_INPUT(8, HID_IOF_CONSTANT), | 97 | HID_RI_USAGE_MAXIMUM(8, 0x03), |
| 98 | HID_RI_USAGE_PAGE(8, 0x08), /* LEDs */ | 98 | HID_RI_LOGICAL_MINIMUM(8, 0x00), |
| 99 | HID_RI_USAGE_MINIMUM(8, 0x01), /* Num Lock */ | 99 | HID_RI_LOGICAL_MAXIMUM(8, 0x01), |
| 100 | HID_RI_USAGE_MAXIMUM(8, 0x05), /* Kana */ | 100 | HID_RI_REPORT_COUNT(8, 0x03), |
| 101 | HID_RI_REPORT_COUNT(8, 0x05), | 101 | HID_RI_REPORT_SIZE(8, 0x01), |
| 102 | HID_RI_REPORT_SIZE(8, 0x01), | 102 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), |
| 103 | HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), | 103 | HID_RI_REPORT_COUNT(8, 0x01), |
| 104 | HID_RI_REPORT_COUNT(8, 0x01), | 104 | HID_RI_REPORT_SIZE(8, 0x05), |
| 105 | HID_RI_REPORT_SIZE(8, 0x03), | 105 | HID_RI_INPUT(8, HID_IOF_CONSTANT), |
| 106 | HID_RI_OUTPUT(8, HID_IOF_CONSTANT), | 106 | HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ |
| 107 | HID_RI_LOGICAL_MINIMUM(8, 0x00), | 107 | HID_RI_USAGE(8, 0x30), /* Usage X */ |
| 108 | HID_RI_LOGICAL_MAXIMUM(8, 0x65), | 108 | HID_RI_USAGE(8, 0x31), /* Usage Y */ |
| 109 | HID_RI_USAGE_PAGE(8, 0x07), /* Keyboard */ | 109 | HID_RI_LOGICAL_MINIMUM(8, -1), |
| 110 | HID_RI_USAGE_MINIMUM(8, 0x00), /* Reserved (no event indicated) */ | 110 | HID_RI_LOGICAL_MAXIMUM(8, 1), |
| 111 | HID_RI_USAGE_MAXIMUM(8, 0x65), /* Keyboard Application */ | 111 | HID_RI_PHYSICAL_MINIMUM(8, -1), |
| 112 | HID_RI_REPORT_COUNT(8, 0x06), | 112 | HID_RI_PHYSICAL_MAXIMUM(8, 1), |
| 113 | HID_RI_REPORT_SIZE(8, 0x08), | 113 | HID_RI_REPORT_COUNT(8, 0x02), |
| 114 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE), | 114 | HID_RI_REPORT_SIZE(8, 0x08), |
| 115 | HID_RI_END_COLLECTION(0), | 115 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), |
| 116 | }; | 116 | HID_RI_END_COLLECTION(0), |
| 117 | 117 | HID_RI_END_COLLECTION(0), | |
| 118 | /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall | 118 | }; |
| 119 | * device characteristics, including the supported USB version, control endpoint size and the | 119 | |
| 120 | * number of device configurations. The descriptor is read out by the USB host when the enumeration | 120 | const USB_Descriptor_HIDReport_Datatype_t PROGMEM GenericReport[] = |
| 121 | * process begins. | 121 | { |
| 122 | */ | 122 | HID_RI_USAGE_PAGE(16, 0xFF00), /* Vendor Page 0 */ |
| 123 | const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = | 123 | HID_RI_USAGE(8, 0x01), /* Vendor Usage 1 */ |
| 124 | { | 124 | HID_RI_COLLECTION(8, 0x01), /* Vendor Usage 1 */ |
| 125 | .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, | 125 | HID_RI_USAGE(8, 0x02), /* Vendor Usage 2 */ |
| 126 | 126 | HID_RI_LOGICAL_MINIMUM(8, 0x00), | |
| 127 | .USBSpecification = VERSION_BCD(01.10), | 127 | HID_RI_LOGICAL_MAXIMUM(8, 0xFF), |
| 128 | .Class = USB_CSCP_NoDeviceClass, | 128 | HID_RI_REPORT_SIZE(8, 0x08), |
| 129 | .SubClass = USB_CSCP_NoDeviceSubclass, | 129 | HID_RI_REPORT_COUNT(8, GENERIC_REPORT_SIZE), |
| 130 | .Protocol = USB_CSCP_NoDeviceProtocol, | 130 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), |
| 131 | 131 | HID_RI_USAGE(8, 0x03), /* Vendor Usage 3 */ | |
| 132 | .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, | 132 | HID_RI_LOGICAL_MINIMUM(8, 0x00), |
| 133 | 133 | HID_RI_LOGICAL_MAXIMUM(8, 0xFF), | |
| 134 | .VendorID = 0x03EB, | 134 | HID_RI_REPORT_SIZE(8, 0x08), |
| 135 | .ProductID = 0x204D, | 135 | HID_RI_REPORT_COUNT(8, GENERIC_REPORT_SIZE), |
| 136 | .ReleaseNumber = VERSION_BCD(00.01), | 136 | HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), |
| 137 | 137 | HID_RI_END_COLLECTION(0), | |
| 138 | .ManufacturerStrIndex = 0x01, | 138 | }; |
| 139 | .ProductStrIndex = 0x02, | 139 | |
| 140 | .SerialNumStrIndex = NO_DESCRIPTOR, | 140 | |
| 141 | 141 | /******************************************************************************* | |
| 142 | .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS | 142 | * Device Descriptors |
| 143 | }; | 143 | ******************************************************************************/ |
| 144 | 144 | const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = | |
| 145 | /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage | 145 | { |
| 146 | * of the device in one of its supported configurations, including information about any device interfaces | 146 | .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, |
| 147 | * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting | 147 | |
| 148 | * a configuration so that the host may correctly communicate with the USB device. | 148 | .USBSpecification = VERSION_BCD(01.10), |
| 149 | */ | 149 | .Class = USB_CSCP_NoDeviceClass, |
| 150 | const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = | 150 | .SubClass = USB_CSCP_NoDeviceSubclass, |
| 151 | { | 151 | .Protocol = USB_CSCP_NoDeviceProtocol, |
| 152 | .Config = | 152 | |
| 153 | { | 153 | .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, |
| 154 | .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, | 154 | |
| 155 | 155 | .VendorID = 0xFEED, | |
| 156 | .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), | 156 | .ProductID = 0x204D, |
| 157 | .TotalInterfaces = 2, | 157 | .ReleaseNumber = VERSION_BCD(00.02), |
| 158 | 158 | ||
| 159 | .ConfigurationNumber = 1, | 159 | .ManufacturerStrIndex = 0x01, |
| 160 | .ConfigurationStrIndex = NO_DESCRIPTOR, | 160 | .ProductStrIndex = 0x02, |
| 161 | 161 | .SerialNumStrIndex = NO_DESCRIPTOR, | |
| 162 | .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), | 162 | |
| 163 | 163 | .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS | |
| 164 | .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) | 164 | }; |
| 165 | }, | 165 | |
| 166 | 166 | /******************************************************************************* | |
| 167 | .HID1_KeyboardInterface = | 167 | * Configuration Descriptors |
| 168 | { | 168 | ******************************************************************************/ |
| 169 | .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, | 169 | const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = |
| 170 | 170 | { | |
| 171 | .InterfaceNumber = 0x00, | 171 | .Config = |
| 172 | .AlternateSetting = 0x00, | 172 | { |
| 173 | 173 | .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, | |
| 174 | .TotalEndpoints = 2, | 174 | |
| 175 | 175 | .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), | |
| 176 | .Class = HID_CSCP_HIDClass, | 176 | .TotalInterfaces = 3, |
| 177 | .SubClass = HID_CSCP_BootSubclass, | 177 | |
| 178 | .Protocol = HID_CSCP_KeyboardBootProtocol, | 178 | .ConfigurationNumber = 1, |
| 179 | 179 | .ConfigurationStrIndex = NO_DESCRIPTOR, | |
| 180 | .InterfaceStrIndex = NO_DESCRIPTOR | 180 | |
| 181 | }, | 181 | .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), //TODO: bus powered? |
| 182 | 182 | ||
| 183 | .HID1_KeyboardHID = | 183 | .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) |
| 184 | { | 184 | }, |
| 185 | .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, | 185 | |
| 186 | 186 | /* | |
| 187 | .HIDSpec = VERSION_BCD(01.11), | 187 | * Keyboard |
| 188 | .CountryCode = 0x00, | 188 | */ |
| 189 | .TotalReportDescriptors = 1, | 189 | .HID1_KeyboardInterface = |
| 190 | .HIDReportType = HID_DTYPE_Report, | 190 | { |
| 191 | .HIDReportLength = sizeof(KeyboardReport) | 191 | .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, |
| 192 | }, | 192 | |
| 193 | 193 | .InterfaceNumber = 0x00, | |
| 194 | .HID1_ReportINEndpoint = | 194 | .AlternateSetting = 0x00, |
| 195 | { | 195 | |
| 196 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, | 196 | .TotalEndpoints = 2, |
| 197 | 197 | ||
| 198 | .EndpointAddress = (ENDPOINT_DIR_IN | KEYBOARD_IN_EPNUM), | 198 | .Class = HID_CSCP_HIDClass, |
| 199 | .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), | 199 | .SubClass = HID_CSCP_BootSubclass, |
| 200 | .EndpointSize = HID_EPSIZE, | 200 | .Protocol = HID_CSCP_KeyboardBootProtocol, |
| 201 | .PollingIntervalMS = 0x01 | 201 | |
| 202 | }, | 202 | .InterfaceStrIndex = NO_DESCRIPTOR |
| 203 | 203 | }, | |
| 204 | .HID1_ReportOUTEndpoint = | 204 | |
| 205 | { | 205 | .HID1_KeyboardHID = |
| 206 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, | 206 | { |
| 207 | 207 | .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, | |
| 208 | .EndpointAddress = (ENDPOINT_DIR_OUT | KEYBOARD_OUT_EPNUM), | 208 | |
| 209 | .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), | 209 | .HIDSpec = VERSION_BCD(01.11), |
| 210 | .EndpointSize = HID_EPSIZE, | 210 | .CountryCode = 0x00, |
| 211 | .PollingIntervalMS = 0x01 | 211 | .TotalReportDescriptors = 1, |
| 212 | }, | 212 | .HIDReportType = HID_DTYPE_Report, |
| 213 | 213 | .HIDReportLength = sizeof(KeyboardReport) | |
| 214 | .HID2_MouseInterface = | 214 | }, |
| 215 | { | 215 | |
| 216 | .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, | 216 | .HID1_ReportINEndpoint = |
| 217 | 217 | { | |
| 218 | .InterfaceNumber = 0x01, | 218 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, |
| 219 | .AlternateSetting = 0x00, | 219 | |
| 220 | 220 | .EndpointAddress = (ENDPOINT_DIR_IN | KEYBOARD_IN_EPNUM), | |
| 221 | .TotalEndpoints = 1, | 221 | .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), |
| 222 | 222 | .EndpointSize = HID_EPSIZE, | |
| 223 | .Class = HID_CSCP_HIDClass, | 223 | .PollingIntervalMS = 0x01 |
| 224 | .SubClass = HID_CSCP_BootSubclass, | 224 | }, |
| 225 | .Protocol = HID_CSCP_MouseBootProtocol, | 225 | |
| 226 | 226 | .HID1_ReportOUTEndpoint = | |
| 227 | .InterfaceStrIndex = NO_DESCRIPTOR | 227 | { |
| 228 | }, | 228 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, |
| 229 | 229 | ||
| 230 | .HID2_MouseHID = | 230 | .EndpointAddress = (ENDPOINT_DIR_OUT | KEYBOARD_OUT_EPNUM), |
| 231 | { | 231 | .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), |
| 232 | .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, | 232 | .EndpointSize = HID_EPSIZE, |
| 233 | 233 | .PollingIntervalMS = 0x01 | |
| 234 | .HIDSpec = VERSION_BCD(01.11), | 234 | }, |
| 235 | .CountryCode = 0x00, | 235 | |
| 236 | .TotalReportDescriptors = 1, | 236 | /* |
| 237 | .HIDReportType = HID_DTYPE_Report, | 237 | * Mouse |
| 238 | .HIDReportLength = sizeof(MouseReport) | 238 | */ |
| 239 | }, | 239 | .HID2_MouseInterface = |
| 240 | 240 | { | |
| 241 | .HID2_ReportINEndpoint = | 241 | .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, |
| 242 | { | 242 | |
| 243 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, | 243 | .InterfaceNumber = 0x01, |
| 244 | 244 | .AlternateSetting = 0x00, | |
| 245 | .EndpointAddress = (ENDPOINT_DIR_IN | MOUSE_IN_EPNUM), | 245 | |
| 246 | .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), | 246 | .TotalEndpoints = 1, |
| 247 | .EndpointSize = HID_EPSIZE, | 247 | |
| 248 | .PollingIntervalMS = 0x01 | 248 | .Class = HID_CSCP_HIDClass, |
| 249 | } | 249 | .SubClass = HID_CSCP_BootSubclass, |
| 250 | }; | 250 | .Protocol = HID_CSCP_MouseBootProtocol, |
| 251 | 251 | ||
| 252 | /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests | 252 | .InterfaceStrIndex = NO_DESCRIPTOR |
| 253 | * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate | 253 | }, |
| 254 | * via the language ID table available at USB.org what languages the device supports for its string descriptors. | 254 | |
| 255 | */ | 255 | .HID2_MouseHID = |
| 256 | const USB_Descriptor_String_t PROGMEM LanguageString = | 256 | { |
| 257 | { | 257 | .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, |
| 258 | .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String}, | 258 | |
| 259 | 259 | .HIDSpec = VERSION_BCD(01.11), | |
| 260 | .UnicodeString = {LANGUAGE_ID_ENG} | 260 | .CountryCode = 0x00, |
| 261 | }; | 261 | .TotalReportDescriptors = 1, |
| 262 | 262 | .HIDReportType = HID_DTYPE_Report, | |
| 263 | /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable | 263 | .HIDReportLength = sizeof(MouseReport) |
| 264 | * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device | 264 | }, |
| 265 | * Descriptor. | 265 | |
| 266 | */ | 266 | .HID2_ReportINEndpoint = |
| 267 | const USB_Descriptor_String_t PROGMEM ManufacturerString = | 267 | { |
| 268 | { | 268 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, |
| 269 | .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, | 269 | |
| 270 | 270 | .EndpointAddress = (ENDPOINT_DIR_IN | MOUSE_IN_EPNUM), | |
| 271 | .UnicodeString = L"Dean Camera" | 271 | .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), |
| 272 | }; | 272 | .EndpointSize = HID_EPSIZE, |
| 273 | 273 | .PollingIntervalMS = 0x01 | |
| 274 | /** Product descriptor string. This is a Unicode string containing the product's details in human readable form, | 274 | }, |
| 275 | * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device | 275 | |
| 276 | * Descriptor. | 276 | /* |
| 277 | */ | 277 | * Generic |
| 278 | const USB_Descriptor_String_t PROGMEM ProductString = | 278 | */ |
| 279 | { | 279 | .HID3_GenericInterface = |
| 280 | .Header = {.Size = USB_STRING_LEN(28), .Type = DTYPE_String}, | 280 | { |
| 281 | 281 | .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, | |
| 282 | .UnicodeString = L"LUFA Mouse and Keyboard Demo" | 282 | |
| 283 | }; | 283 | .InterfaceNumber = 0x02, |
| 284 | 284 | .AlternateSetting = 0x00, | |
| 285 | /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" | 285 | |
| 286 | * documentation) by the application code so that the address and size of a requested descriptor can be given | 286 | .TotalEndpoints = 2, |
| 287 | * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function | 287 | |
| 288 | * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the | 288 | .Class = HID_CSCP_HIDClass, |
| 289 | * USB host. | 289 | .SubClass = HID_CSCP_NonBootSubclass, |
| 290 | */ | 290 | .Protocol = HID_CSCP_NonBootProtocol, |
| 291 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, | 291 | |
| 292 | const uint8_t wIndex, | 292 | .InterfaceStrIndex = NO_DESCRIPTOR |
| 293 | const void** const DescriptorAddress) | 293 | }, |
| 294 | { | 294 | |
| 295 | const uint8_t DescriptorType = (wValue >> 8); | 295 | .HID3_GenericHID = |
| 296 | const uint8_t DescriptorNumber = (wValue & 0xFF); | 296 | { |
| 297 | 297 | .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, | |
| 298 | const void* Address = NULL; | 298 | |
| 299 | uint16_t Size = NO_DESCRIPTOR; | 299 | .HIDSpec = VERSION_BCD(01.11), |
| 300 | 300 | .CountryCode = 0x00, | |
| 301 | switch (DescriptorType) | 301 | .TotalReportDescriptors = 1, |
| 302 | { | 302 | .HIDReportType = HID_DTYPE_Report, |
| 303 | case DTYPE_Device: | 303 | .HIDReportLength = sizeof(GenericReport) |
| 304 | Address = &DeviceDescriptor; | 304 | }, |
| 305 | Size = sizeof(USB_Descriptor_Device_t); | 305 | |
| 306 | break; | 306 | .HID3_ReportINEndpoint = |
| 307 | case DTYPE_Configuration: | 307 | { |
| 308 | Address = &ConfigurationDescriptor; | 308 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, |
| 309 | Size = sizeof(USB_Descriptor_Configuration_t); | 309 | |
| 310 | break; | 310 | .EndpointAddress = (ENDPOINT_DIR_IN | GENERIC_IN_EPNUM), |
| 311 | case DTYPE_String: | 311 | .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), |
| 312 | switch (DescriptorNumber) | 312 | .EndpointSize = GENERIC_EPSIZE, |
| 313 | { | 313 | .PollingIntervalMS = 0x01 |
| 314 | case 0x00: | 314 | }, |
| 315 | Address = &LanguageString; | 315 | |
| 316 | Size = pgm_read_byte(&LanguageString.Header.Size); | 316 | .HID3_ReportOUTEndpoint = |
| 317 | break; | 317 | { |
| 318 | case 0x01: | 318 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, |
| 319 | Address = &ManufacturerString; | 319 | |
| 320 | Size = pgm_read_byte(&ManufacturerString.Header.Size); | 320 | .EndpointAddress = (ENDPOINT_DIR_OUT | GENERIC_OUT_EPNUM), |
| 321 | break; | 321 | .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), |
| 322 | case 0x02: | 322 | .EndpointSize = GENERIC_EPSIZE, |
| 323 | Address = &ProductString; | 323 | .PollingIntervalMS = 0x01 |
| 324 | Size = pgm_read_byte(&ProductString.Header.Size); | 324 | } |
| 325 | break; | 325 | }; |
| 326 | } | 326 | |
| 327 | 327 | ||
| 328 | break; | 328 | /******************************************************************************* |
| 329 | case HID_DTYPE_HID: | 329 | * String Descriptors |
| 330 | if (!(wIndex)) | 330 | ******************************************************************************/ |
| 331 | { | 331 | const USB_Descriptor_String_t PROGMEM LanguageString = |
| 332 | Address = &ConfigurationDescriptor.HID1_KeyboardHID; | 332 | { |
| 333 | Size = sizeof(USB_HID_Descriptor_HID_t); | 333 | .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String}, |
| 334 | } | 334 | |
| 335 | else | 335 | .UnicodeString = {LANGUAGE_ID_ENG} |
| 336 | { | 336 | }; |
| 337 | Address = &ConfigurationDescriptor.HID2_MouseHID; | 337 | |
| 338 | Size = sizeof(USB_HID_Descriptor_HID_t); | 338 | const USB_Descriptor_String_t PROGMEM ManufacturerString = |
| 339 | } | 339 | { |
| 340 | break; | 340 | .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, |
| 341 | case HID_DTYPE_Report: | 341 | |
| 342 | if (!(wIndex)) | 342 | .UnicodeString = L"Dean Camera" // TODO: |
| 343 | { | 343 | }; |
| 344 | Address = &KeyboardReport; | 344 | |
| 345 | Size = sizeof(KeyboardReport); | 345 | const USB_Descriptor_String_t PROGMEM ProductString = |
| 346 | } | 346 | { |
| 347 | else | 347 | .Header = {.Size = USB_STRING_LEN(28), .Type = DTYPE_String}, |
| 348 | { | 348 | |
| 349 | Address = &MouseReport; | 349 | .UnicodeString = L"LUFA Mouse and Keyboard Demo" // TODO: |
| 350 | Size = sizeof(MouseReport); | 350 | }; |
| 351 | } | 351 | |
| 352 | 352 | ||
| 353 | break; | 353 | /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" |
| 354 | } | 354 | * documentation) by the application code so that the address and size of a requested descriptor can be given |
| 355 | 355 | * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function | |
| 356 | *DescriptorAddress = Address; | 356 | * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the |
| 357 | return Size; | 357 | * USB host. |
| 358 | } | 358 | */ |
| 359 | 359 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, | |
| 360 | const uint8_t wIndex, | ||
| 361 | const void** const DescriptorAddress) | ||
| 362 | { | ||
| 363 | const uint8_t DescriptorType = (wValue >> 8); | ||
| 364 | const uint8_t DescriptorIndex = (wValue & 0xFF); | ||
| 365 | |||
| 366 | const void* Address = NULL; | ||
| 367 | uint16_t Size = NO_DESCRIPTOR; | ||
| 368 | |||
| 369 | switch (DescriptorType) | ||
| 370 | { | ||
| 371 | case DTYPE_Device: | ||
| 372 | Address = &DeviceDescriptor; | ||
| 373 | Size = sizeof(USB_Descriptor_Device_t); | ||
| 374 | break; | ||
| 375 | case DTYPE_Configuration: | ||
| 376 | Address = &ConfigurationDescriptor; | ||
| 377 | Size = sizeof(USB_Descriptor_Configuration_t); | ||
| 378 | break; | ||
| 379 | case DTYPE_String: | ||
| 380 | switch (DescriptorIndex ) | ||
| 381 | { | ||
| 382 | case 0x00: | ||
| 383 | Address = &LanguageString; | ||
| 384 | Size = pgm_read_byte(&LanguageString.Header.Size); | ||
| 385 | break; | ||
| 386 | case 0x01: | ||
| 387 | Address = &ManufacturerString; | ||
| 388 | Size = pgm_read_byte(&ManufacturerString.Header.Size); | ||
| 389 | break; | ||
| 390 | case 0x02: | ||
| 391 | Address = &ProductString; | ||
| 392 | Size = pgm_read_byte(&ProductString.Header.Size); | ||
| 393 | break; | ||
| 394 | } | ||
| 395 | break; | ||
| 396 | case HID_DTYPE_HID: | ||
| 397 | switch (wIndex) { | ||
| 398 | case 0: | ||
| 399 | Address = &ConfigurationDescriptor.HID1_KeyboardHID; | ||
| 400 | Size = sizeof(USB_HID_Descriptor_HID_t); | ||
| 401 | break; | ||
| 402 | case 1: | ||
| 403 | Address = &ConfigurationDescriptor.HID2_MouseHID; | ||
| 404 | Size = sizeof(USB_HID_Descriptor_HID_t); | ||
| 405 | break; | ||
| 406 | case 2: | ||
| 407 | Address = &ConfigurationDescriptor.HID3_GenericHID; | ||
| 408 | Size = sizeof(USB_HID_Descriptor_HID_t); | ||
| 409 | break; | ||
| 410 | } | ||
| 411 | break; | ||
| 412 | case HID_DTYPE_Report: | ||
| 413 | switch (wIndex) { | ||
| 414 | case 0: | ||
| 415 | Address = &KeyboardReport; | ||
| 416 | Size = sizeof(KeyboardReport); | ||
| 417 | break; | ||
| 418 | case 1: | ||
| 419 | Address = &MouseReport; | ||
| 420 | Size = sizeof(MouseReport); | ||
| 421 | break; | ||
| 422 | case 2: | ||
| 423 | Address = &GenericReport; | ||
| 424 | Size = sizeof(GenericReport); | ||
| 425 | break; | ||
| 426 | } | ||
| 427 | break; | ||
| 428 | } | ||
| 429 | |||
| 430 | *DescriptorAddress = Address; | ||
| 431 | return Size; | ||
| 432 | } | ||
diff --git a/keyboard/lufa/Descriptors.h b/keyboard/lufa/Descriptors.h index 05b2035bb..03e2426a3 100644 --- a/keyboard/lufa/Descriptors.h +++ b/keyboard/lufa/Descriptors.h | |||
| @@ -37,51 +37,48 @@ | |||
| 37 | #ifndef _DESCRIPTORS_H_ | 37 | #ifndef _DESCRIPTORS_H_ |
| 38 | #define _DESCRIPTORS_H_ | 38 | #define _DESCRIPTORS_H_ |
| 39 | 39 | ||
| 40 | /* Includes: */ | 40 | #include <LUFA/Drivers/USB/USB.h> |
| 41 | #include <LUFA/Drivers/USB/USB.h> | 41 | #include <avr/pgmspace.h> |
| 42 | 42 | ||
| 43 | #include <avr/pgmspace.h> | 43 | |
| 44 | 44 | typedef struct | |
| 45 | /* Type Defines: */ | 45 | { |
| 46 | /** Type define for the device configuration descriptor structure. This must be defined in the | 46 | USB_Descriptor_Configuration_Header_t Config; |
| 47 | * application code, as the configuration descriptor contains several sub-descriptors which | 47 | |
| 48 | * vary between devices, and which describe the device's usage to the host. | 48 | // Keyboard HID Interface |
| 49 | */ | 49 | USB_Descriptor_Interface_t HID1_KeyboardInterface; |
| 50 | typedef struct | 50 | USB_HID_Descriptor_HID_t HID1_KeyboardHID; |
| 51 | { | 51 | USB_Descriptor_Endpoint_t HID1_ReportINEndpoint; |
| 52 | USB_Descriptor_Configuration_Header_t Config; | 52 | USB_Descriptor_Endpoint_t HID1_ReportOUTEndpoint; |
| 53 | 53 | ||
| 54 | // Keyboard HID Interface | 54 | // Mouse HID Interface |
| 55 | USB_Descriptor_Interface_t HID1_KeyboardInterface; | 55 | USB_Descriptor_Interface_t HID2_MouseInterface; |
| 56 | USB_HID_Descriptor_HID_t HID1_KeyboardHID; | 56 | USB_HID_Descriptor_HID_t HID2_MouseHID; |
| 57 | USB_Descriptor_Endpoint_t HID1_ReportINEndpoint; | 57 | USB_Descriptor_Endpoint_t HID2_ReportINEndpoint; |
| 58 | USB_Descriptor_Endpoint_t HID1_ReportOUTEndpoint; | 58 | |
| 59 | 59 | // Generic HID Interface | |
| 60 | // Mouse HID Interface | 60 | USB_Descriptor_Interface_t HID3_GenericInterface; |
| 61 | USB_Descriptor_Interface_t HID2_MouseInterface; | 61 | USB_HID_Descriptor_HID_t HID3_GenericHID; |
| 62 | USB_HID_Descriptor_HID_t HID2_MouseHID; | 62 | USB_Descriptor_Endpoint_t HID3_ReportINEndpoint; |
| 63 | USB_Descriptor_Endpoint_t HID2_ReportINEndpoint; | 63 | USB_Descriptor_Endpoint_t HID3_ReportOUTEndpoint; |
| 64 | USB_Descriptor_Endpoint_t HID2_ReportOUTEndpoint; | 64 | } USB_Descriptor_Configuration_t; |
| 65 | } USB_Descriptor_Configuration_t; | ||
| 66 | |||
| 67 | /* Macros: */ | ||
| 68 | /** Endpoint number of the Keyboard HID reporting IN endpoint. */ | ||
| 69 | #define KEYBOARD_IN_EPNUM 1 | ||
| 70 | |||
| 71 | /** Endpoint number of the Keyboard HID reporting OUT endpoint. */ | ||
| 72 | #define KEYBOARD_OUT_EPNUM 2 | ||
| 73 | |||
| 74 | /** Endpoint number of the Mouse HID reporting IN endpoint. */ | ||
| 75 | #define MOUSE_IN_EPNUM 3 | ||
| 76 | |||
| 77 | /** Size in bytes of each of the HID reporting IN and OUT endpoints. */ | ||
| 78 | #define HID_EPSIZE 8 | ||
| 79 | |||
| 80 | /* Function Prototypes: */ | ||
| 81 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, | ||
| 82 | const uint8_t wIndex, | ||
| 83 | const void** const DescriptorAddress) | ||
| 84 | ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); | ||
| 85 | 65 | ||
| 86 | #endif | ||
| 87 | 66 | ||
| 67 | // Endopoint number/size | ||
| 68 | #define KEYBOARD_IN_EPNUM 1 | ||
| 69 | #define KEYBOARD_OUT_EPNUM 2 | ||
| 70 | #define MOUSE_IN_EPNUM 3 | ||
| 71 | #define GENERIC_IN_EPNUM 4 | ||
| 72 | #define GENERIC_OUT_EPNUM 5 | ||
| 73 | |||
| 74 | #define HID_EPSIZE 8 | ||
| 75 | #define GENERIC_EPSIZE 8 | ||
| 76 | #define GENERIC_REPORT_SIZE 8 | ||
| 77 | |||
| 78 | |||
| 79 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, | ||
| 80 | const uint8_t wIndex, | ||
| 81 | const void** const DescriptorAddress) | ||
| 82 | ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); | ||
| 83 | |||
| 84 | #endif | ||
diff --git a/keyboard/lufa/Makefile b/keyboard/lufa/Makefile index 1d2f712d4..115c7e6ec 100644 --- a/keyboard/lufa/Makefile +++ b/keyboard/lufa/Makefile | |||
| @@ -128,8 +128,7 @@ LSRC = $(TARGET).c \ | |||
| 128 | SRC = $(subst $(LUFA_PATH)/LUFA/,,$(LSRC)) | 128 | SRC = $(subst $(LUFA_PATH)/LUFA/,,$(LSRC)) |
| 129 | SRC += keymap.c \ | 129 | SRC += keymap.c \ |
| 130 | matrix.c \ | 130 | matrix.c \ |
| 131 | led.c \ | 131 | led.c |
| 132 | sendchar_null.c | ||
| 133 | CONFIG_H = config.h | 132 | CONFIG_H = config.h |
| 134 | 133 | ||
| 135 | 134 | ||
diff --git a/keyboard/lufa/lufa.c b/keyboard/lufa/lufa.c index d7e7c1654..d841f45c6 100644 --- a/keyboard/lufa/lufa.c +++ b/keyboard/lufa/lufa.c | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright 2012 Jun Wako <wakojun@gmail.com> | 2 | * Copyright 2012 Jun Wako <wakojun@gmail.com> |
| 3 | * This file is based on LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse. | 3 | * This file is based on: |
| 4 | * LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse | ||
| 5 | * LUFA-120219/Demos/Device/Lowlevel/GenericHID | ||
| 4 | */ | 6 | */ |
| 5 | 7 | ||
| 6 | /* | 8 | /* |
| @@ -38,6 +40,8 @@ | |||
| 38 | #include "host.h" | 40 | #include "host.h" |
| 39 | #include "host_driver.h" | 41 | #include "host_driver.h" |
| 40 | #include "keyboard.h" | 42 | #include "keyboard.h" |
| 43 | #include "sendchar.h" | ||
| 44 | #include "debug.h" | ||
| 41 | #include "lufa.h" | 45 | #include "lufa.h" |
| 42 | 46 | ||
| 43 | static uint8_t keyboard_led_stats = 0; | 47 | static uint8_t keyboard_led_stats = 0; |
| @@ -64,11 +68,21 @@ int main(void) | |||
| 64 | SetupHardware(); | 68 | SetupHardware(); |
| 65 | sei(); | 69 | sei(); |
| 66 | 70 | ||
| 71 | print_enable = true; | ||
| 72 | debug_enable = true; | ||
| 73 | debug_matrix = true; | ||
| 74 | debug_keyboard = true; | ||
| 75 | debug_mouse = true; | ||
| 76 | |||
| 77 | _delay_ms(3000); | ||
| 78 | print("abcdefg\n"); | ||
| 79 | |||
| 67 | keyboard_init(); | 80 | keyboard_init(); |
| 68 | host_set_driver(&lufa_driver); | 81 | host_set_driver(&lufa_driver); |
| 69 | while (1) { | 82 | while (1) { |
| 70 | keyboard_proc(); | 83 | keyboard_proc(); |
| 71 | Keyboard_HID_Task(); | 84 | Keyboard_HID_Task(); |
| 85 | Generic_HID_Task(); | ||
| 72 | USB_USBTask(); | 86 | USB_USBTask(); |
| 73 | } | 87 | } |
| 74 | } | 88 | } |
| @@ -112,6 +126,12 @@ void EVENT_USB_Device_ConfigurationChanged(void) | |||
| 112 | /* Setup Mouse HID Report Endpoint */ | 126 | /* Setup Mouse HID Report Endpoint */ |
| 113 | ConfigSuccess &= Endpoint_ConfigureEndpoint(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, | 127 | ConfigSuccess &= Endpoint_ConfigureEndpoint(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, |
| 114 | HID_EPSIZE, ENDPOINT_BANK_SINGLE); | 128 | HID_EPSIZE, ENDPOINT_BANK_SINGLE); |
| 129 | |||
| 130 | /* Setup Generic HID Report Endpoints */ | ||
| 131 | ConfigSuccess &= Endpoint_ConfigureEndpoint(GENERIC_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, | ||
| 132 | GENERIC_EPSIZE, ENDPOINT_BANK_SINGLE); | ||
| 133 | ConfigSuccess &= Endpoint_ConfigureEndpoint(GENERIC_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, | ||
| 134 | GENERIC_EPSIZE, ENDPOINT_BANK_SINGLE); | ||
| 115 | } | 135 | } |
| 116 | 136 | ||
| 117 | /** Event handler for the USB_ControlRequest event. | 137 | /** Event handler for the USB_ControlRequest event. |
| @@ -119,8 +139,8 @@ void EVENT_USB_Device_ConfigurationChanged(void) | |||
| 119 | */ | 139 | */ |
| 120 | void EVENT_USB_Device_ControlRequest(void) | 140 | void EVENT_USB_Device_ControlRequest(void) |
| 121 | { | 141 | { |
| 122 | uint8_t* ReportData; | 142 | uint8_t* ReportData = NULL; |
| 123 | uint8_t ReportSize; | 143 | uint8_t ReportSize = 0; |
| 124 | 144 | ||
| 125 | /* Handle HID Class specific requests */ | 145 | /* Handle HID Class specific requests */ |
| 126 | switch (USB_ControlRequest.bRequest) | 146 | switch (USB_ControlRequest.bRequest) |
| @@ -130,16 +150,18 @@ void EVENT_USB_Device_ControlRequest(void) | |||
| 130 | { | 150 | { |
| 131 | Endpoint_ClearSETUP(); | 151 | Endpoint_ClearSETUP(); |
| 132 | 152 | ||
| 133 | /* Determine if it is the mouse or the keyboard data that is being requested */ | 153 | // Interface |
| 134 | if (!(USB_ControlRequest.wIndex)) | 154 | switch (USB_ControlRequest.wIndex) { |
| 135 | { | 155 | case 1: // Keyboard |
| 136 | ReportData = (uint8_t*)&keyboard_report_sent; | 156 | ReportData = (uint8_t*)&keyboard_report_sent; |
| 137 | ReportSize = sizeof(keyboard_report_sent); | 157 | ReportSize = sizeof(keyboard_report_sent); |
| 138 | } | 158 | break; |
| 139 | else | 159 | case 2: // Mouse |
| 140 | { | ||
| 141 | ReportData = (uint8_t*)&mouse_report_sent; | 160 | ReportData = (uint8_t*)&mouse_report_sent; |
| 142 | ReportSize = sizeof(mouse_report_sent); | 161 | ReportSize = sizeof(mouse_report_sent); |
| 162 | break; | ||
| 163 | case 3: // Generic | ||
| 164 | break; | ||
| 143 | } | 165 | } |
| 144 | 166 | ||
| 145 | /* Write the report data to the control endpoint */ | 167 | /* Write the report data to the control endpoint */ |
| @@ -160,8 +182,17 @@ void EVENT_USB_Device_ControlRequest(void) | |||
| 160 | return; | 182 | return; |
| 161 | } | 183 | } |
| 162 | 184 | ||
| 163 | /* Read in the LED report from the host */ | 185 | // Interface |
| 164 | keyboard_led_stats = Endpoint_Read_8(); | 186 | switch (USB_ControlRequest.wIndex) { |
| 187 | case 1: // Keyboard | ||
| 188 | /* Read in the LED report from the host */ | ||
| 189 | keyboard_led_stats = Endpoint_Read_8(); | ||
| 190 | break; | ||
| 191 | case 2: // Mouse | ||
| 192 | break; | ||
| 193 | case 3: // Generic | ||
| 194 | break; | ||
| 195 | } | ||
| 165 | 196 | ||
| 166 | Endpoint_ClearOUT(); | 197 | Endpoint_ClearOUT(); |
| 167 | Endpoint_ClearStatusStage(); | 198 | Endpoint_ClearStatusStage(); |
| @@ -176,6 +207,10 @@ void EVENT_USB_Device_ControlRequest(void) | |||
| 176 | */ | 207 | */ |
| 177 | void Keyboard_HID_Task(void) | 208 | void Keyboard_HID_Task(void) |
| 178 | { | 209 | { |
| 210 | /* Device must be connected and configured for the task to run */ | ||
| 211 | if (USB_DeviceState != DEVICE_STATE_Configured) | ||
| 212 | return; | ||
| 213 | |||
| 179 | /* Select the Keyboard LED Report Endpoint */ | 214 | /* Select the Keyboard LED Report Endpoint */ |
| 180 | Endpoint_SelectEndpoint(KEYBOARD_OUT_EPNUM); | 215 | Endpoint_SelectEndpoint(KEYBOARD_OUT_EPNUM); |
| 181 | 216 | ||
| @@ -190,6 +225,40 @@ void Keyboard_HID_Task(void) | |||
| 190 | } | 225 | } |
| 191 | } | 226 | } |
| 192 | 227 | ||
| 228 | void Generic_HID_Task(void) | ||
| 229 | { | ||
| 230 | /* Device must be connected and configured for the task to run */ | ||
| 231 | if (USB_DeviceState != DEVICE_STATE_Configured) | ||
| 232 | return; | ||
| 233 | |||
| 234 | Endpoint_SelectEndpoint(GENERIC_OUT_EPNUM); | ||
| 235 | |||
| 236 | /* Check to see if a packet has been sent from the host */ | ||
| 237 | if (Endpoint_IsOUTReceived()) | ||
| 238 | { | ||
| 239 | /* Check to see if the packet contains data */ | ||
| 240 | if (Endpoint_IsReadWriteAllowed()) | ||
| 241 | { | ||
| 242 | /* Create a temporary buffer to hold the read in report from the host */ | ||
| 243 | uint8_t GenericData[GENERIC_REPORT_SIZE]; | ||
| 244 | |||
| 245 | /* Read Generic Report Data */ | ||
| 246 | Endpoint_Read_Stream_LE(&GenericData, sizeof(GenericData), NULL); | ||
| 247 | |||
| 248 | /* Process Generic Report Data */ | ||
| 249 | //TODO: ProcessGenericHIDReport(GenericData); | ||
| 250 | } | ||
| 251 | |||
| 252 | /* Finalize the stream transfer to send the last packet */ | ||
| 253 | Endpoint_ClearOUT(); | ||
| 254 | } | ||
| 255 | |||
| 256 | /* IN packet */ | ||
| 257 | Endpoint_SelectEndpoint(GENERIC_IN_EPNUM); | ||
| 258 | // send IN packet | ||
| 259 | if (Endpoint_IsINReady()) | ||
| 260 | Endpoint_ClearIN(); | ||
| 261 | } | ||
| 193 | 262 | ||
| 194 | /******************************************************************************* | 263 | /******************************************************************************* |
| 195 | * Host driver | 264 | * Host driver |
| @@ -241,3 +310,41 @@ static void send_system(uint16_t data) | |||
| 241 | static void send_consumer(uint16_t data) | 310 | static void send_consumer(uint16_t data) |
| 242 | { | 311 | { |
| 243 | } | 312 | } |
| 313 | |||
| 314 | |||
| 315 | /******************************************************************************* | ||
| 316 | * sendchar | ||
| 317 | ******************************************************************************/ | ||
| 318 | int8_t sendchar(uint8_t c) | ||
| 319 | { | ||
| 320 | if (USB_DeviceState != DEVICE_STATE_Configured) | ||
| 321 | return -1; | ||
| 322 | |||
| 323 | Endpoint_SelectEndpoint(GENERIC_IN_EPNUM); | ||
| 324 | |||
| 325 | uint8_t timeout = 10; | ||
| 326 | uint16_t prevFN = USB_Device_GetFrameNumber(); | ||
| 327 | while (!Endpoint_IsINReady()) { | ||
| 328 | switch (USB_DeviceState) { | ||
| 329 | case DEVICE_STATE_Unattached: | ||
| 330 | case DEVICE_STATE_Suspended: | ||
| 331 | return -1; | ||
| 332 | } | ||
| 333 | if (Endpoint_IsStalled()) | ||
| 334 | return -1; | ||
| 335 | uint16_t currFN = USB_Device_GetFrameNumber(); | ||
| 336 | if (prevFN != USB_Device_GetFrameNumber()) { | ||
| 337 | if (!(timeout--)) | ||
| 338 | return -1; | ||
| 339 | prevFN = USB_Device_GetFrameNumber(); | ||
| 340 | } | ||
| 341 | } | ||
| 342 | |||
| 343 | Endpoint_Write_8(c); | ||
| 344 | |||
| 345 | // send when packet is full | ||
| 346 | if (!Endpoint_IsReadWriteAllowed()) | ||
| 347 | Endpoint_ClearIN(); | ||
| 348 | |||
| 349 | return 0; | ||
| 350 | } | ||
diff --git a/keyboard/lufa/lufa.h b/keyboard/lufa/lufa.h index 74fe0b72f..3ba14b360 100644 --- a/keyboard/lufa/lufa.h +++ b/keyboard/lufa/lufa.h | |||
| @@ -65,7 +65,7 @@ | |||
| 65 | void SetupHardware(void); | 65 | void SetupHardware(void); |
| 66 | void Keyboard_ProcessLEDReport(const uint8_t LEDStatus); | 66 | void Keyboard_ProcessLEDReport(const uint8_t LEDStatus); |
| 67 | void Keyboard_HID_Task(void); | 67 | void Keyboard_HID_Task(void); |
| 68 | void Mouse_HID_Task(void); | 68 | void Generic_HID_Task(void); |
| 69 | 69 | ||
| 70 | void EVENT_USB_Device_Connect(void); | 70 | void EVENT_USB_Device_Connect(void); |
| 71 | void EVENT_USB_Device_Disconnect(void); | 71 | void EVENT_USB_Device_Disconnect(void); |
