diff options
| -rw-r--r-- | keyboard/lufa/Makefile | 320 | ||||
| -rw-r--r-- | keyboard/lufa/config.h | 6 | ||||
| -rw-r--r-- | keyboard/lufa/descriptor.c (renamed from keyboard/lufa/Descriptors.c) | 78 | ||||
| -rw-r--r-- | keyboard/lufa/descriptor.h (renamed from keyboard/lufa/Descriptors.h) | 170 | ||||
| -rw-r--r-- | keyboard/lufa/lufa.c | 146 | ||||
| -rw-r--r-- | keyboard/lufa/lufa.h | 123 |
6 files changed, 397 insertions, 446 deletions
diff --git a/keyboard/lufa/Makefile b/keyboard/lufa/Makefile index 115c7e6ec..12af013f8 100644 --- a/keyboard/lufa/Makefile +++ b/keyboard/lufa/Makefile | |||
| @@ -1,160 +1,160 @@ | |||
| 1 | # Hey Emacs, this is a -*- makefile -*- | 1 | # Hey Emacs, this is a -*- makefile -*- |
| 2 | #---------------------------------------------------------------------------- | 2 | #---------------------------------------------------------------------------- |
| 3 | # WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al. | 3 | # WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al. |
| 4 | # >> Modified for use with the LUFA project. << | 4 | # >> Modified for use with the LUFA project. << |
| 5 | # | 5 | # |
| 6 | # Released to the Public Domain | 6 | # Released to the Public Domain |
| 7 | # | 7 | # |
| 8 | # Additional material for this makefile was written by: | 8 | # Additional material for this makefile was written by: |
| 9 | # Peter Fleury | 9 | # Peter Fleury |
| 10 | # Tim Henigan | 10 | # Tim Henigan |
| 11 | # Colin O'Flynn | 11 | # Colin O'Flynn |
| 12 | # Reiner Patommel | 12 | # Reiner Patommel |
| 13 | # Markus Pfaff | 13 | # Markus Pfaff |
| 14 | # Sander Pool | 14 | # Sander Pool |
| 15 | # Frederik Rouleau | 15 | # Frederik Rouleau |
| 16 | # Carlos Lamas | 16 | # Carlos Lamas |
| 17 | # Dean Camera | 17 | # Dean Camera |
| 18 | # Opendous Inc. | 18 | # Opendous Inc. |
| 19 | # Denver Gingerich | 19 | # Denver Gingerich |
| 20 | # | 20 | # |
| 21 | #---------------------------------------------------------------------------- | 21 | #---------------------------------------------------------------------------- |
| 22 | # On command line: | 22 | # On command line: |
| 23 | # | 23 | # |
| 24 | # make all = Make software. | 24 | # make all = Make software. |
| 25 | # | 25 | # |
| 26 | # make clean = Clean out built project files. | 26 | # make clean = Clean out built project files. |
| 27 | # | 27 | # |
| 28 | # make coff = Convert ELF to AVR COFF. | 28 | # make coff = Convert ELF to AVR COFF. |
| 29 | # | 29 | # |
| 30 | # make extcoff = Convert ELF to AVR Extended COFF. | 30 | # make extcoff = Convert ELF to AVR Extended COFF. |
| 31 | # | 31 | # |
| 32 | # make program = Download the hex file to the device, using avrdude. | 32 | # make program = Download the hex file to the device, using avrdude. |
| 33 | # Please customize the avrdude settings below first! | 33 | # Please customize the avrdude settings below first! |
| 34 | # | 34 | # |
| 35 | # make dfu = Download the hex file to the device, using dfu-programmer (must | 35 | # make dfu = Download the hex file to the device, using dfu-programmer (must |
| 36 | # have dfu-programmer installed). | 36 | # have dfu-programmer installed). |
| 37 | # | 37 | # |
| 38 | # make flip = Download the hex file to the device, using Atmel FLIP (must | 38 | # make flip = Download the hex file to the device, using Atmel FLIP (must |
| 39 | # have Atmel FLIP installed). | 39 | # have Atmel FLIP installed). |
| 40 | # | 40 | # |
| 41 | # make dfu-ee = Download the eeprom file to the device, using dfu-programmer | 41 | # make dfu-ee = Download the eeprom file to the device, using dfu-programmer |
| 42 | # (must have dfu-programmer installed). | 42 | # (must have dfu-programmer installed). |
| 43 | # | 43 | # |
| 44 | # make flip-ee = Download the eeprom file to the device, using Atmel FLIP | 44 | # make flip-ee = Download the eeprom file to the device, using Atmel FLIP |
| 45 | # (must have Atmel FLIP installed). | 45 | # (must have Atmel FLIP installed). |
| 46 | # | 46 | # |
| 47 | # make doxygen = Generate DoxyGen documentation for the project (must have | 47 | # make doxygen = Generate DoxyGen documentation for the project (must have |
| 48 | # DoxyGen installed) | 48 | # DoxyGen installed) |
| 49 | # | 49 | # |
| 50 | # make debug = Start either simulavr or avarice as specified for debugging, | 50 | # make debug = Start either simulavr or avarice as specified for debugging, |
| 51 | # with avr-gdb or avr-insight as the front end for debugging. | 51 | # with avr-gdb or avr-insight as the front end for debugging. |
| 52 | # | 52 | # |
| 53 | # make filename.s = Just compile filename.c into the assembler code only. | 53 | # make filename.s = Just compile filename.c into the assembler code only. |
| 54 | # | 54 | # |
| 55 | # make filename.i = Create a preprocessed source file for use in submitting | 55 | # make filename.i = Create a preprocessed source file for use in submitting |
| 56 | # bug reports to the GCC project. | 56 | # bug reports to the GCC project. |
| 57 | # | 57 | # |
| 58 | # To rebuild project do "make clean" then "make all". | 58 | # To rebuild project do "make clean" then "make all". |
| 59 | #---------------------------------------------------------------------------- | 59 | #---------------------------------------------------------------------------- |
| 60 | 60 | ||
| 61 | # Directory common source filess exist | 61 | # Directory common source filess exist |
| 62 | TOP_DIR = ../.. | 62 | TOP_DIR = ../.. |
| 63 | 63 | ||
| 64 | # Directory keyboard dependent files exist | 64 | # Directory keyboard dependent files exist |
| 65 | TARGET_DIR = . | 65 | TARGET_DIR = . |
| 66 | 66 | ||
| 67 | # MCU name | 67 | # MCU name |
| 68 | #MCU = at90usb1287 | 68 | #MCU = at90usb1287 |
| 69 | MCU = atmega32u4 | 69 | MCU = atmega32u4 |
| 70 | 70 | ||
| 71 | 71 | ||
| 72 | # Target architecture (see library "Board Types" documentation). | 72 | # Target architecture (see library "Board Types" documentation). |
| 73 | ARCH = AVR8 | 73 | ARCH = AVR8 |
| 74 | 74 | ||
| 75 | 75 | ||
| 76 | # Target board (see library "Board Types" documentation, NONE for projects not requiring | 76 | # Target board (see library "Board Types" documentation, NONE for projects not requiring |
| 77 | # LUFA board drivers). If USER is selected, put custom board drivers in a directory called | 77 | # LUFA board drivers). If USER is selected, put custom board drivers in a directory called |
| 78 | # "Board" inside the application directory. | 78 | # "Board" inside the application directory. |
| 79 | BOARD = USBKEY | 79 | BOARD = USBKEY |
| 80 | 80 | ||
| 81 | 81 | ||
| 82 | # Processor frequency. | 82 | # Processor frequency. |
| 83 | # This will define a symbol, F_CPU, in all source code files equal to the | 83 | # This will define a symbol, F_CPU, in all source code files equal to the |
| 84 | # processor frequency in Hz. You can then use this symbol in your source code to | 84 | # processor frequency in Hz. You can then use this symbol in your source code to |
| 85 | # calculate timings. Do NOT tack on a 'UL' at the end, this will be done | 85 | # calculate timings. Do NOT tack on a 'UL' at the end, this will be done |
| 86 | # automatically to create a 32-bit value in your source code. | 86 | # automatically to create a 32-bit value in your source code. |
| 87 | # | 87 | # |
| 88 | # This will be an integer division of F_USB below, as it is sourced by | 88 | # This will be an integer division of F_USB below, as it is sourced by |
| 89 | # F_USB after it has run through any CPU prescalers. Note that this value | 89 | # F_USB after it has run through any CPU prescalers. Note that this value |
| 90 | # does not *change* the processor frequency - it should merely be updated to | 90 | # does not *change* the processor frequency - it should merely be updated to |
| 91 | # reflect the processor speed set externally so that the code can use accurate | 91 | # reflect the processor speed set externally so that the code can use accurate |
| 92 | # software delays. | 92 | # software delays. |
| 93 | F_CPU = 16000000 | 93 | F_CPU = 16000000 |
| 94 | 94 | ||
| 95 | 95 | ||
| 96 | # Input clock frequency. | 96 | # Input clock frequency. |
| 97 | # This will define a symbol, F_USB, in all source code files equal to the | 97 | # This will define a symbol, F_USB, in all source code files equal to the |
| 98 | # input clock frequency (before any prescaling is performed) in Hz. This value may | 98 | # input clock frequency (before any prescaling is performed) in Hz. This value may |
| 99 | # differ from F_CPU if prescaling is used on the latter, and is required as the | 99 | # differ from F_CPU if prescaling is used on the latter, and is required as the |
| 100 | # raw input clock is fed directly to the PLL sections of the AVR for high speed | 100 | # raw input clock is fed directly to the PLL sections of the AVR for high speed |
| 101 | # clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' | 101 | # clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' |
| 102 | # at the end, this will be done automatically to create a 32-bit value in your | 102 | # at the end, this will be done automatically to create a 32-bit value in your |
| 103 | # source code. | 103 | # source code. |
| 104 | # | 104 | # |
| 105 | # If no clock division is performed on the input clock inside the AVR (via the | 105 | # If no clock division is performed on the input clock inside the AVR (via the |
| 106 | # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. | 106 | # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. |
| 107 | F_USB = $(F_CPU) | 107 | F_USB = $(F_CPU) |
| 108 | 108 | ||
| 109 | 109 | ||
| 110 | # Target file name (without extension). | 110 | # Target file name (without extension). |
| 111 | TARGET = lufa | 111 | TARGET = lufa |
| 112 | 112 | ||
| 113 | 113 | ||
| 114 | # Path to the LUFA library | 114 | # Path to the LUFA library |
| 115 | LUFA_PATH = ../../protocol | 115 | LUFA_PATH = ../../protocol |
| 116 | 116 | ||
| 117 | # Create the LUFA source path variables by including the LUFA root makefile | 117 | # Create the LUFA source path variables by including the LUFA root makefile |
| 118 | include $(LUFA_PATH)/LUFA/makefile | 118 | include $(LUFA_PATH)/LUFA/makefile |
| 119 | 119 | ||
| 120 | 120 | ||
| 121 | 121 | ||
| 122 | # List C source files here. (C dependencies are automatically generated.) | 122 | # List C source files here. (C dependencies are automatically generated.) |
| 123 | LSRC = $(TARGET).c \ | 123 | LUFA_SRC = $(TARGET).c \ |
| 124 | Descriptors.c \ | 124 | descriptor.c \ |
| 125 | $(LUFA_SRC_USB) \ | 125 | $(LUFA_SRC_USB) \ |
| 126 | $(LUFA_SRC_USBCLASS) | 126 | $(LUFA_SRC_USBCLASS) |
| 127 | 127 | ||
| 128 | SRC = $(subst $(LUFA_PATH)/LUFA/,,$(LSRC)) | 128 | SRC = $(subst $(LUFA_PATH)/LUFA/,,$(LUFA_SRC)) |
| 129 | SRC += keymap.c \ | 129 | SRC += keymap.c \ |
| 130 | matrix.c \ | 130 | matrix.c \ |
| 131 | led.c | 131 | led.c |
| 132 | CONFIG_H = config.h | 132 | CONFIG_H = config.h |
| 133 | 133 | ||
| 134 | 134 | ||
| 135 | 135 | ||
| 136 | # LUFA library compile-time options and predefined tokens | 136 | # LUFA library compile-time options and predefined tokens |
| 137 | LUFA_OPTS = -D USB_DEVICE_ONLY | 137 | LUFA_OPTS = -D USB_DEVICE_ONLY |
| 138 | LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8 | 138 | LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8 |
| 139 | LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1 | 139 | LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1 |
| 140 | LUFA_OPTS += -D USE_FLASH_DESCRIPTORS | 140 | LUFA_OPTS += -D USE_FLASH_DESCRIPTORS |
| 141 | LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" | 141 | LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" |
| 142 | 142 | ||
| 143 | OPT_DEFS = -DF_CPU=$(F_CPU)UL | 143 | OPT_DEFS = -DF_CPU=$(F_CPU)UL |
| 144 | OPT_DEFS += -DF_USB=$(F_USB)UL | 144 | OPT_DEFS += -DF_USB=$(F_USB)UL |
| 145 | OPT_DEFS += -DBOARD=BOARD_$(BOARD) -DARCH=ARCH_$(ARCH) | 145 | OPT_DEFS += -DBOARD=BOARD_$(BOARD) -DARCH=ARCH_$(ARCH) |
| 146 | OPT_DEFS += $(LUFA_OPTS) | 146 | OPT_DEFS += $(LUFA_OPTS) |
| 147 | 147 | ||
| 148 | 148 | ||
| 149 | 149 | ||
| 150 | # Search Path | 150 | # Search Path |
| 151 | VPATH += $(TARGET_DIR) | 151 | VPATH += $(TARGET_DIR) |
| 152 | VPATH += $(LUFA_PATH)/LUFA | 152 | VPATH += $(LUFA_PATH)/LUFA |
| 153 | 153 | ||
| 154 | 154 | ||
| 155 | include $(TOP_DIR)/protocol.mk | 155 | include $(TOP_DIR)/protocol.mk |
| 156 | include $(TOP_DIR)/common.mk | 156 | include $(TOP_DIR)/common.mk |
| 157 | include $(TOP_DIR)/rules.mk | 157 | include $(TOP_DIR)/rules.mk |
| 158 | 158 | ||
| 159 | test: | 159 | test: |
| 160 | echo $(SRC) | 160 | echo $(SRC) |
diff --git a/keyboard/lufa/config.h b/keyboard/lufa/config.h index 4662e3dd3..c375a576f 100644 --- a/keyboard/lufa/config.h +++ b/keyboard/lufa/config.h | |||
| @@ -21,10 +21,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 21 | /* controller configuration */ | 21 | /* controller configuration */ |
| 22 | #include "controller_teensy.h" | 22 | #include "controller_teensy.h" |
| 23 | 23 | ||
| 24 | |||
| 25 | /* USB Device descriptor */ | ||
| 24 | #define VENDOR_ID 0xFEED | 26 | #define VENDOR_ID 0xFEED |
| 25 | #define PRODUCT_ID 0xBEE1 | 27 | #define PRODUCT_ID 0xBEE1 |
| 28 | #define DEVICE_VER 0x0101 | ||
| 26 | #define MANUFACTURER t.m.k. | 29 | #define MANUFACTURER t.m.k. |
| 27 | #define PRODUCT Macway mod(LUFA) | 30 | #define PRODUCT Macway mod(LUFA) |
| 31 | |||
| 32 | |||
| 33 | /* message strings */ | ||
| 28 | #define DESCRIPTION t.m.k. keyboard firmware for Macway mod(LUFA) | 34 | #define DESCRIPTION t.m.k. keyboard firmware for Macway mod(LUFA) |
| 29 | 35 | ||
| 30 | 36 | ||
diff --git a/keyboard/lufa/Descriptors.c b/keyboard/lufa/descriptor.c index a4e9defab..6059fd4a8 100644 --- a/keyboard/lufa/Descriptors.c +++ b/keyboard/lufa/descriptor.c | |||
| @@ -36,14 +36,8 @@ | |||
| 36 | this software. | 36 | this software. |
| 37 | */ | 37 | */ |
| 38 | 38 | ||
| 39 | /** \file | 39 | #include "util.h" |
| 40 | * | 40 | #include "descriptor.h" |
| 41 | * USB Device Descriptors, for library use when in USB device mode. Descriptors are special | ||
| 42 | * computer-readable structures which the host requests upon device enumeration, to determine | ||
| 43 | * the device's capabilities and functions. | ||
| 44 | */ | ||
| 45 | |||
| 46 | #include "Descriptors.h" | ||
| 47 | 41 | ||
| 48 | 42 | ||
| 49 | /******************************************************************************* | 43 | /******************************************************************************* |
| @@ -152,9 +146,9 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = | |||
| 152 | 146 | ||
| 153 | .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, | 147 | .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, |
| 154 | 148 | ||
| 155 | .VendorID = 0xFEED, | 149 | .VendorID = VENDOR_ID, |
| 156 | .ProductID = 0x204D, | 150 | .ProductID = PRODUCT_ID, |
| 157 | .ReleaseNumber = VERSION_BCD(00.02), | 151 | .ReleaseNumber = DEVICE_VER, |
| 158 | 152 | ||
| 159 | .ManufacturerStrIndex = 0x01, | 153 | .ManufacturerStrIndex = 0x01, |
| 160 | .ProductStrIndex = 0x02, | 154 | .ProductStrIndex = 0x02, |
| @@ -178,7 +172,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = | |||
| 178 | .ConfigurationNumber = 1, | 172 | .ConfigurationNumber = 1, |
| 179 | .ConfigurationStrIndex = NO_DESCRIPTOR, | 173 | .ConfigurationStrIndex = NO_DESCRIPTOR, |
| 180 | 174 | ||
| 181 | .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), //TODO: bus powered? | 175 | .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_REMOTEWAKEUP), |
| 182 | 176 | ||
| 183 | .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) | 177 | .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) |
| 184 | }, | 178 | }, |
| @@ -186,14 +180,14 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = | |||
| 186 | /* | 180 | /* |
| 187 | * Keyboard | 181 | * Keyboard |
| 188 | */ | 182 | */ |
| 189 | .HID1_KeyboardInterface = | 183 | .HID0_KeyboardInterface = |
| 190 | { | 184 | { |
| 191 | .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, | 185 | .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, |
| 192 | 186 | ||
| 193 | .InterfaceNumber = 0x00, | 187 | .InterfaceNumber = KEYBOARD_INTERFACE, |
| 194 | .AlternateSetting = 0x00, | 188 | .AlternateSetting = 0x00, |
| 195 | 189 | ||
| 196 | .TotalEndpoints = 2, | 190 | .TotalEndpoints = 1, |
| 197 | 191 | ||
| 198 | .Class = HID_CSCP_HIDClass, | 192 | .Class = HID_CSCP_HIDClass, |
| 199 | .SubClass = HID_CSCP_BootSubclass, | 193 | .SubClass = HID_CSCP_BootSubclass, |
| @@ -202,7 +196,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = | |||
| 202 | .InterfaceStrIndex = NO_DESCRIPTOR | 196 | .InterfaceStrIndex = NO_DESCRIPTOR |
| 203 | }, | 197 | }, |
| 204 | 198 | ||
| 205 | .HID1_KeyboardHID = | 199 | .HID0_KeyboardHID = |
| 206 | { | 200 | { |
| 207 | .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, | 201 | .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, |
| 208 | 202 | ||
| @@ -213,7 +207,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = | |||
| 213 | .HIDReportLength = sizeof(KeyboardReport) | 207 | .HIDReportLength = sizeof(KeyboardReport) |
| 214 | }, | 208 | }, |
| 215 | 209 | ||
| 216 | .HID1_ReportINEndpoint = | 210 | .HID0_ReportINEndpoint = |
| 217 | { | 211 | { |
| 218 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, | 212 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, |
| 219 | 213 | ||
| @@ -223,24 +217,14 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = | |||
| 223 | .PollingIntervalMS = 0x01 | 217 | .PollingIntervalMS = 0x01 |
| 224 | }, | 218 | }, |
| 225 | 219 | ||
| 226 | .HID1_ReportOUTEndpoint = | ||
| 227 | { | ||
| 228 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, | ||
| 229 | |||
| 230 | .EndpointAddress = (ENDPOINT_DIR_OUT | KEYBOARD_OUT_EPNUM), | ||
| 231 | .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), | ||
| 232 | .EndpointSize = HID_EPSIZE, | ||
| 233 | .PollingIntervalMS = 0x01 | ||
| 234 | }, | ||
| 235 | |||
| 236 | /* | 220 | /* |
| 237 | * Mouse | 221 | * Mouse |
| 238 | */ | 222 | */ |
| 239 | .HID2_MouseInterface = | 223 | .HID1_MouseInterface = |
| 240 | { | 224 | { |
| 241 | .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, | 225 | .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, |
| 242 | 226 | ||
| 243 | .InterfaceNumber = 0x01, | 227 | .InterfaceNumber = MOUSE_INTERFACE, |
| 244 | .AlternateSetting = 0x00, | 228 | .AlternateSetting = 0x00, |
| 245 | 229 | ||
| 246 | .TotalEndpoints = 1, | 230 | .TotalEndpoints = 1, |
| @@ -252,7 +236,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = | |||
| 252 | .InterfaceStrIndex = NO_DESCRIPTOR | 236 | .InterfaceStrIndex = NO_DESCRIPTOR |
| 253 | }, | 237 | }, |
| 254 | 238 | ||
| 255 | .HID2_MouseHID = | 239 | .HID1_MouseHID = |
| 256 | { | 240 | { |
| 257 | .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, | 241 | .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, |
| 258 | 242 | ||
| @@ -263,7 +247,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = | |||
| 263 | .HIDReportLength = sizeof(MouseReport) | 247 | .HIDReportLength = sizeof(MouseReport) |
| 264 | }, | 248 | }, |
| 265 | 249 | ||
| 266 | .HID2_ReportINEndpoint = | 250 | .HID1_ReportINEndpoint = |
| 267 | { | 251 | { |
| 268 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, | 252 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, |
| 269 | 253 | ||
| @@ -276,11 +260,11 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = | |||
| 276 | /* | 260 | /* |
| 277 | * Generic | 261 | * Generic |
| 278 | */ | 262 | */ |
| 279 | .HID3_GenericInterface = | 263 | .HID2_GenericInterface = |
| 280 | { | 264 | { |
| 281 | .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, | 265 | .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, |
| 282 | 266 | ||
| 283 | .InterfaceNumber = 0x02, | 267 | .InterfaceNumber = GENERIC_INTERFACE, |
| 284 | .AlternateSetting = 0x00, | 268 | .AlternateSetting = 0x00, |
| 285 | 269 | ||
| 286 | .TotalEndpoints = 2, | 270 | .TotalEndpoints = 2, |
| @@ -292,7 +276,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = | |||
| 292 | .InterfaceStrIndex = NO_DESCRIPTOR | 276 | .InterfaceStrIndex = NO_DESCRIPTOR |
| 293 | }, | 277 | }, |
| 294 | 278 | ||
| 295 | .HID3_GenericHID = | 279 | .HID2_GenericHID = |
| 296 | { | 280 | { |
| 297 | .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, | 281 | .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, |
| 298 | 282 | ||
| @@ -303,7 +287,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = | |||
| 303 | .HIDReportLength = sizeof(GenericReport) | 287 | .HIDReportLength = sizeof(GenericReport) |
| 304 | }, | 288 | }, |
| 305 | 289 | ||
| 306 | .HID3_ReportINEndpoint = | 290 | .HID2_ReportINEndpoint = |
| 307 | { | 291 | { |
| 308 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, | 292 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, |
| 309 | 293 | ||
| @@ -313,7 +297,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = | |||
| 313 | .PollingIntervalMS = 0x01 | 297 | .PollingIntervalMS = 0x01 |
| 314 | }, | 298 | }, |
| 315 | 299 | ||
| 316 | .HID3_ReportOUTEndpoint = | 300 | .HID2_ReportOUTEndpoint = |
| 317 | { | 301 | { |
| 318 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, | 302 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, |
| 319 | 303 | ||
| @@ -339,14 +323,14 @@ const USB_Descriptor_String_t PROGMEM ManufacturerString = | |||
| 339 | { | 323 | { |
| 340 | .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, | 324 | .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, |
| 341 | 325 | ||
| 342 | .UnicodeString = L"Dean Camera" // TODO: | 326 | .UnicodeString = LSTR(MANUFACTURER) |
| 343 | }; | 327 | }; |
| 344 | 328 | ||
| 345 | const USB_Descriptor_String_t PROGMEM ProductString = | 329 | const USB_Descriptor_String_t PROGMEM ProductString = |
| 346 | { | 330 | { |
| 347 | .Header = {.Size = USB_STRING_LEN(28), .Type = DTYPE_String}, | 331 | .Header = {.Size = USB_STRING_LEN(28), .Type = DTYPE_String}, |
| 348 | 332 | ||
| 349 | .UnicodeString = L"LUFA Mouse and Keyboard Demo" // TODO: | 333 | .UnicodeString = LSTR(PRODUCT) |
| 350 | }; | 334 | }; |
| 351 | 335 | ||
| 352 | 336 | ||
| @@ -395,31 +379,31 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, | |||
| 395 | break; | 379 | break; |
| 396 | case HID_DTYPE_HID: | 380 | case HID_DTYPE_HID: |
| 397 | switch (wIndex) { | 381 | switch (wIndex) { |
| 398 | case 0: | 382 | case KEYBOARD_INTERFACE: |
| 399 | Address = &ConfigurationDescriptor.HID1_KeyboardHID; | 383 | Address = &ConfigurationDescriptor.HID0_KeyboardHID; |
| 400 | Size = sizeof(USB_HID_Descriptor_HID_t); | 384 | Size = sizeof(USB_HID_Descriptor_HID_t); |
| 401 | break; | 385 | break; |
| 402 | case 1: | 386 | case MOUSE_INTERFACE: |
| 403 | Address = &ConfigurationDescriptor.HID2_MouseHID; | 387 | Address = &ConfigurationDescriptor.HID1_MouseHID; |
| 404 | Size = sizeof(USB_HID_Descriptor_HID_t); | 388 | Size = sizeof(USB_HID_Descriptor_HID_t); |
| 405 | break; | 389 | break; |
| 406 | case 2: | 390 | case GENERIC_INTERFACE: |
| 407 | Address = &ConfigurationDescriptor.HID3_GenericHID; | 391 | Address = &ConfigurationDescriptor.HID2_GenericHID; |
| 408 | Size = sizeof(USB_HID_Descriptor_HID_t); | 392 | Size = sizeof(USB_HID_Descriptor_HID_t); |
| 409 | break; | 393 | break; |
| 410 | } | 394 | } |
| 411 | break; | 395 | break; |
| 412 | case HID_DTYPE_Report: | 396 | case HID_DTYPE_Report: |
| 413 | switch (wIndex) { | 397 | switch (wIndex) { |
| 414 | case 0: | 398 | case KEYBOARD_INTERFACE: |
| 415 | Address = &KeyboardReport; | 399 | Address = &KeyboardReport; |
| 416 | Size = sizeof(KeyboardReport); | 400 | Size = sizeof(KeyboardReport); |
| 417 | break; | 401 | break; |
| 418 | case 1: | 402 | case MOUSE_INTERFACE: |
| 419 | Address = &MouseReport; | 403 | Address = &MouseReport; |
| 420 | Size = sizeof(MouseReport); | 404 | Size = sizeof(MouseReport); |
| 421 | break; | 405 | break; |
| 422 | case 2: | 406 | case GENERIC_INTERFACE: |
| 423 | Address = &GenericReport; | 407 | Address = &GenericReport; |
| 424 | Size = sizeof(GenericReport); | 408 | Size = sizeof(GenericReport); |
| 425 | break; | 409 | break; |
diff --git a/keyboard/lufa/Descriptors.h b/keyboard/lufa/descriptor.h index 03e2426a3..19e24c201 100644 --- a/keyboard/lufa/Descriptors.h +++ b/keyboard/lufa/descriptor.h | |||
| @@ -1,84 +1,86 @@ | |||
| 1 | /* | 1 | /* |
| 2 | LUFA Library | 2 | LUFA Library |
| 3 | Copyright (C) Dean Camera, 2012. | 3 | Copyright (C) Dean Camera, 2012. |
| 4 | 4 | ||
| 5 | dean [at] fourwalledcubicle [dot] com | 5 | dean [at] fourwalledcubicle [dot] com |
| 6 | www.lufa-lib.org | 6 | www.lufa-lib.org |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | /* | 9 | /* |
| 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) | 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) |
| 11 | Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com) | 11 | Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com) |
| 12 | 12 | ||
| 13 | Permission to use, copy, modify, distribute, and sell this | 13 | Permission to use, copy, modify, distribute, and sell this |
| 14 | software and its documentation for any purpose is hereby granted | 14 | software and its documentation for any purpose is hereby granted |
| 15 | without fee, provided that the above copyright notice appear in | 15 | without fee, provided that the above copyright notice appear in |
| 16 | all copies and that both that the copyright notice and this | 16 | all copies and that both that the copyright notice and this |
| 17 | permission notice and warranty disclaimer appear in supporting | 17 | permission notice and warranty disclaimer appear in supporting |
| 18 | documentation, and that the name of the author not be used in | 18 | documentation, and that the name of the author not be used in |
| 19 | advertising or publicity pertaining to distribution of the | 19 | advertising or publicity pertaining to distribution of the |
| 20 | software without specific, written prior permission. | 20 | software without specific, written prior permission. |
| 21 | 21 | ||
| 22 | The author disclaim all warranties with regard to this | 22 | The author disclaim all warranties with regard to this |
| 23 | software, including all implied warranties of merchantability | 23 | software, including all implied warranties of merchantability |
| 24 | and fitness. In no event shall the author be liable for any | 24 | and fitness. In no event shall the author be liable for any |
| 25 | special, indirect or consequential damages or any damages | 25 | special, indirect or consequential damages or any damages |
| 26 | whatsoever resulting from loss of use, data or profits, whether | 26 | whatsoever resulting from loss of use, data or profits, whether |
| 27 | in an action of contract, negligence or other tortious action, | 27 | in an action of contract, negligence or other tortious action, |
| 28 | arising out of or in connection with the use or performance of | 28 | arising out of or in connection with the use or performance of |
| 29 | this software. | 29 | this software. |
| 30 | */ | 30 | */ |
| 31 | 31 | ||
| 32 | /** \file | 32 | /** \file |
| 33 | * | 33 | * |
| 34 | * Header file for Descriptors.c. | 34 | * Header file for Descriptors.c. |
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #ifndef _DESCRIPTORS_H_ | 37 | #ifndef _DESCRIPTORS_H_ |
| 38 | #define _DESCRIPTORS_H_ | 38 | #define _DESCRIPTORS_H_ |
| 39 | 39 | ||
| 40 | #include <LUFA/Drivers/USB/USB.h> | 40 | #include <LUFA/Drivers/USB/USB.h> |
| 41 | #include <avr/pgmspace.h> | 41 | #include <avr/pgmspace.h> |
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | typedef struct | 44 | typedef struct |
| 45 | { | 45 | { |
| 46 | USB_Descriptor_Configuration_Header_t Config; | 46 | USB_Descriptor_Configuration_Header_t Config; |
| 47 | 47 | ||
| 48 | // Keyboard HID Interface | 48 | // Keyboard HID Interface |
| 49 | USB_Descriptor_Interface_t HID1_KeyboardInterface; | 49 | USB_Descriptor_Interface_t HID0_KeyboardInterface; |
| 50 | USB_HID_Descriptor_HID_t HID1_KeyboardHID; | 50 | USB_HID_Descriptor_HID_t HID0_KeyboardHID; |
| 51 | USB_Descriptor_Endpoint_t HID1_ReportINEndpoint; | 51 | USB_Descriptor_Endpoint_t HID0_ReportINEndpoint; |
| 52 | USB_Descriptor_Endpoint_t HID1_ReportOUTEndpoint; | 52 | |
| 53 | 53 | // Mouse HID Interface | |
| 54 | // Mouse HID Interface | 54 | USB_Descriptor_Interface_t HID1_MouseInterface; |
| 55 | USB_Descriptor_Interface_t HID2_MouseInterface; | 55 | USB_HID_Descriptor_HID_t HID1_MouseHID; |
| 56 | USB_HID_Descriptor_HID_t HID2_MouseHID; | 56 | USB_Descriptor_Endpoint_t HID1_ReportINEndpoint; |
| 57 | USB_Descriptor_Endpoint_t HID2_ReportINEndpoint; | 57 | |
| 58 | 58 | // Generic HID Interface | |
| 59 | // Generic HID Interface | 59 | USB_Descriptor_Interface_t HID2_GenericInterface; |
| 60 | USB_Descriptor_Interface_t HID3_GenericInterface; | 60 | USB_HID_Descriptor_HID_t HID2_GenericHID; |
| 61 | USB_HID_Descriptor_HID_t HID3_GenericHID; | 61 | USB_Descriptor_Endpoint_t HID2_ReportINEndpoint; |
| 62 | USB_Descriptor_Endpoint_t HID3_ReportINEndpoint; | 62 | USB_Descriptor_Endpoint_t HID2_ReportOUTEndpoint; |
| 63 | USB_Descriptor_Endpoint_t HID3_ReportOUTEndpoint; | 63 | } USB_Descriptor_Configuration_t; |
| 64 | } USB_Descriptor_Configuration_t; | 64 | |
| 65 | 65 | ||
| 66 | 66 | #define KEYBOARD_INTERFACE 0 | |
| 67 | // Endopoint number/size | 67 | #define MOUSE_INTERFACE 1 |
| 68 | #define KEYBOARD_IN_EPNUM 1 | 68 | #define GENERIC_INTERFACE 2 |
| 69 | #define KEYBOARD_OUT_EPNUM 2 | 69 | |
| 70 | #define MOUSE_IN_EPNUM 3 | 70 | // Endopoint number/size |
| 71 | #define GENERIC_IN_EPNUM 4 | 71 | #define KEYBOARD_IN_EPNUM 1 |
| 72 | #define GENERIC_OUT_EPNUM 5 | 72 | #define MOUSE_IN_EPNUM 2 |
| 73 | 73 | #define GENERIC_IN_EPNUM 3 | |
| 74 | #define HID_EPSIZE 8 | 74 | #define GENERIC_OUT_EPNUM 4 |
| 75 | #define GENERIC_EPSIZE 8 | 75 | |
| 76 | #define GENERIC_REPORT_SIZE 8 | 76 | #define HID_EPSIZE 8 |
| 77 | 77 | #define GENERIC_EPSIZE 8 | |
| 78 | 78 | #define GENERIC_REPORT_SIZE 8 | |
| 79 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, | 79 | |
| 80 | const uint8_t wIndex, | 80 | |
| 81 | const void** const DescriptorAddress) | 81 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, |
| 82 | ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); | 82 | const uint8_t wIndex, |
| 83 | 83 | const void** const DescriptorAddress) | |
| 84 | #endif | 84 | ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); |
| 85 | |||
| 86 | #endif | ||
diff --git a/keyboard/lufa/lufa.c b/keyboard/lufa/lufa.c index d841f45c6..569960e2a 100644 --- a/keyboard/lufa/lufa.c +++ b/keyboard/lufa/lufa.c | |||
| @@ -42,11 +42,15 @@ | |||
| 42 | #include "keyboard.h" | 42 | #include "keyboard.h" |
| 43 | #include "sendchar.h" | 43 | #include "sendchar.h" |
| 44 | #include "debug.h" | 44 | #include "debug.h" |
| 45 | |||
| 46 | #include "descriptor.h" | ||
| 45 | #include "lufa.h" | 47 | #include "lufa.h" |
| 46 | 48 | ||
| 47 | static uint8_t keyboard_led_stats = 0; | 49 | static uint8_t keyboard_led_stats = 0; |
| 48 | report_keyboard_t keyboard_report_sent; | 50 | |
| 49 | report_mouse_t mouse_report_sent; | 51 | // TODO: impl Control Request GET_REPORT |
| 52 | static report_keyboard_t keyboard_report_sent; | ||
| 53 | static report_mouse_t mouse_report_sent; | ||
| 50 | 54 | ||
| 51 | /* Host driver */ | 55 | /* Host driver */ |
| 52 | static uint8_t keyboard_leds(void); | 56 | static uint8_t keyboard_leds(void); |
| @@ -63,6 +67,9 @@ static host_driver_t lufa_driver = { | |||
| 63 | }; | 67 | }; |
| 64 | 68 | ||
| 65 | 69 | ||
| 70 | static void SetupHardware(void); | ||
| 71 | static void Generic_HID_Task(void); | ||
| 72 | |||
| 66 | int main(void) | 73 | int main(void) |
| 67 | { | 74 | { |
| 68 | SetupHardware(); | 75 | SetupHardware(); |
| @@ -74,20 +81,23 @@ int main(void) | |||
| 74 | debug_keyboard = true; | 81 | debug_keyboard = true; |
| 75 | debug_mouse = true; | 82 | debug_mouse = true; |
| 76 | 83 | ||
| 77 | _delay_ms(3000); | 84 | /* TODO: can't print here |
| 85 | _delay_ms(5000); | ||
| 86 | USB_USBTask(); | ||
| 78 | print("abcdefg\n"); | 87 | print("abcdefg\n"); |
| 88 | USB_USBTask(); | ||
| 89 | */ | ||
| 79 | 90 | ||
| 80 | keyboard_init(); | 91 | keyboard_init(); |
| 81 | host_set_driver(&lufa_driver); | 92 | host_set_driver(&lufa_driver); |
| 82 | while (1) { | 93 | while (1) { |
| 83 | keyboard_proc(); | 94 | keyboard_proc(); |
| 84 | Keyboard_HID_Task(); | 95 | |
| 85 | Generic_HID_Task(); | 96 | Generic_HID_Task(); |
| 86 | USB_USBTask(); | 97 | USB_USBTask(); |
| 87 | } | 98 | } |
| 88 | } | 99 | } |
| 89 | 100 | ||
| 90 | /** Configures the board hardware and chip peripherals for the demo's functionality. */ | ||
| 91 | void SetupHardware(void) | 101 | void SetupHardware(void) |
| 92 | { | 102 | { |
| 93 | /* Disable watchdog if enabled by bootloader/fuses */ | 103 | /* Disable watchdog if enabled by bootloader/fuses */ |
| @@ -100,6 +110,46 @@ void SetupHardware(void) | |||
| 100 | USB_Init(); | 110 | USB_Init(); |
| 101 | } | 111 | } |
| 102 | 112 | ||
| 113 | static void Generic_HID_Task(void) | ||
| 114 | { | ||
| 115 | /* Device must be connected and configured for the task to run */ | ||
| 116 | if (USB_DeviceState != DEVICE_STATE_Configured) | ||
| 117 | return; | ||
| 118 | |||
| 119 | // TODO: impl receivechar()/recvchar() | ||
| 120 | Endpoint_SelectEndpoint(GENERIC_OUT_EPNUM); | ||
| 121 | |||
| 122 | /* Check to see if a packet has been sent from the host */ | ||
| 123 | if (Endpoint_IsOUTReceived()) | ||
| 124 | { | ||
| 125 | /* Check to see if the packet contains data */ | ||
| 126 | if (Endpoint_IsReadWriteAllowed()) | ||
| 127 | { | ||
| 128 | /* Create a temporary buffer to hold the read in report from the host */ | ||
| 129 | uint8_t GenericData[GENERIC_REPORT_SIZE]; | ||
| 130 | |||
| 131 | /* Read Generic Report Data */ | ||
| 132 | Endpoint_Read_Stream_LE(&GenericData, sizeof(GenericData), NULL); | ||
| 133 | |||
| 134 | /* Process Generic Report Data */ | ||
| 135 | //ProcessGenericHIDReport(GenericData); | ||
| 136 | } | ||
| 137 | |||
| 138 | /* Finalize the stream transfer to send the last packet */ | ||
| 139 | Endpoint_ClearOUT(); | ||
| 140 | } | ||
| 141 | |||
| 142 | /* IN packet */ | ||
| 143 | Endpoint_SelectEndpoint(GENERIC_IN_EPNUM); | ||
| 144 | // send IN packet | ||
| 145 | if (Endpoint_IsINReady()) | ||
| 146 | Endpoint_ClearIN(); | ||
| 147 | } | ||
| 148 | |||
| 149 | |||
| 150 | /******************************************************************************* | ||
| 151 | * USB Events | ||
| 152 | ******************************************************************************/ | ||
| 103 | /** Event handler for the USB_Connect event. */ | 153 | /** Event handler for the USB_Connect event. */ |
| 104 | void EVENT_USB_Device_Connect(void) | 154 | void EVENT_USB_Device_Connect(void) |
| 105 | { | 155 | { |
| @@ -120,18 +170,16 @@ void EVENT_USB_Device_ConfigurationChanged(void) | |||
| 120 | /* Setup Keyboard HID Report Endpoints */ | 170 | /* Setup Keyboard HID Report Endpoints */ |
| 121 | ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, | 171 | ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, |
| 122 | HID_EPSIZE, ENDPOINT_BANK_SINGLE); | 172 | HID_EPSIZE, ENDPOINT_BANK_SINGLE); |
| 123 | ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, | ||
| 124 | HID_EPSIZE, ENDPOINT_BANK_SINGLE); | ||
| 125 | 173 | ||
| 126 | /* Setup Mouse HID Report Endpoint */ | 174 | /* Setup Mouse HID Report Endpoint */ |
| 127 | ConfigSuccess &= Endpoint_ConfigureEndpoint(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, | 175 | ConfigSuccess &= Endpoint_ConfigureEndpoint(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, |
| 128 | HID_EPSIZE, ENDPOINT_BANK_SINGLE); | 176 | HID_EPSIZE, ENDPOINT_BANK_SINGLE); |
| 129 | 177 | ||
| 130 | /* Setup Generic HID Report Endpoints */ | 178 | /* Setup Generic HID Report Endpoints */ |
| 131 | ConfigSuccess &= Endpoint_ConfigureEndpoint(GENERIC_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, | 179 | ConfigSuccess &= Endpoint_ConfigureEndpoint(GENERIC_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, |
| 132 | GENERIC_EPSIZE, ENDPOINT_BANK_SINGLE); | 180 | GENERIC_EPSIZE, ENDPOINT_BANK_SINGLE); |
| 133 | ConfigSuccess &= Endpoint_ConfigureEndpoint(GENERIC_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, | 181 | ConfigSuccess &= Endpoint_ConfigureEndpoint(GENERIC_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, |
| 134 | GENERIC_EPSIZE, ENDPOINT_BANK_SINGLE); | 182 | GENERIC_EPSIZE, ENDPOINT_BANK_SINGLE); |
| 135 | } | 183 | } |
| 136 | 184 | ||
| 137 | /** Event handler for the USB_ControlRequest event. | 185 | /** Event handler for the USB_ControlRequest event. |
| @@ -152,15 +200,17 @@ void EVENT_USB_Device_ControlRequest(void) | |||
| 152 | 200 | ||
| 153 | // Interface | 201 | // Interface |
| 154 | switch (USB_ControlRequest.wIndex) { | 202 | switch (USB_ControlRequest.wIndex) { |
| 155 | case 1: // Keyboard | 203 | case KEYBOARD_INTERFACE: |
| 204 | // TODO: test/check | ||
| 156 | ReportData = (uint8_t*)&keyboard_report_sent; | 205 | ReportData = (uint8_t*)&keyboard_report_sent; |
| 157 | ReportSize = sizeof(keyboard_report_sent); | 206 | ReportSize = sizeof(keyboard_report_sent); |
| 158 | break; | 207 | break; |
| 159 | case 2: // Mouse | 208 | case MOUSE_INTERFACE: |
| 209 | // TODO: test/check | ||
| 160 | ReportData = (uint8_t*)&mouse_report_sent; | 210 | ReportData = (uint8_t*)&mouse_report_sent; |
| 161 | ReportSize = sizeof(mouse_report_sent); | 211 | ReportSize = sizeof(mouse_report_sent); |
| 162 | break; | 212 | break; |
| 163 | case 3: // Generic | 213 | case GENERIC_INTERFACE: |
| 164 | break; | 214 | break; |
| 165 | } | 215 | } |
| 166 | 216 | ||
| @@ -184,13 +234,14 @@ void EVENT_USB_Device_ControlRequest(void) | |||
| 184 | 234 | ||
| 185 | // Interface | 235 | // Interface |
| 186 | switch (USB_ControlRequest.wIndex) { | 236 | switch (USB_ControlRequest.wIndex) { |
| 187 | case 1: // Keyboard | 237 | case KEYBOARD_INTERFACE: |
| 238 | // TODO: test/check | ||
| 188 | /* Read in the LED report from the host */ | 239 | /* Read in the LED report from the host */ |
| 189 | keyboard_led_stats = Endpoint_Read_8(); | 240 | keyboard_led_stats = Endpoint_Read_8(); |
| 190 | break; | 241 | break; |
| 191 | case 2: // Mouse | 242 | case MOUSE_INTERFACE: |
| 192 | break; | 243 | break; |
| 193 | case 3: // Generic | 244 | case GENERIC_INTERFACE: |
| 194 | break; | 245 | break; |
| 195 | } | 246 | } |
| 196 | 247 | ||
| @@ -202,64 +253,6 @@ void EVENT_USB_Device_ControlRequest(void) | |||
| 202 | } | 253 | } |
| 203 | } | 254 | } |
| 204 | 255 | ||
| 205 | /** Keyboard task. | ||
| 206 | * This processes host LED status reports sent to the device via the keyboard OUT reporting endpoint. | ||
| 207 | */ | ||
| 208 | void Keyboard_HID_Task(void) | ||
| 209 | { | ||
| 210 | /* Device must be connected and configured for the task to run */ | ||
| 211 | if (USB_DeviceState != DEVICE_STATE_Configured) | ||
| 212 | return; | ||
| 213 | |||
| 214 | /* Select the Keyboard LED Report Endpoint */ | ||
| 215 | Endpoint_SelectEndpoint(KEYBOARD_OUT_EPNUM); | ||
| 216 | |||
| 217 | /* Check if Keyboard LED Endpoint Ready for Read/Write */ | ||
| 218 | if (Endpoint_IsReadWriteAllowed()) | ||
| 219 | { | ||
| 220 | /* Read in the LED report from the host */ | ||
| 221 | keyboard_led_stats = Endpoint_Read_8(); | ||
| 222 | |||
| 223 | /* Handshake the OUT Endpoint - clear endpoint and ready for next report */ | ||
| 224 | Endpoint_ClearOUT(); | ||
| 225 | } | ||
| 226 | } | ||
| 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 | } | ||
| 262 | |||
| 263 | /******************************************************************************* | 256 | /******************************************************************************* |
| 264 | * Host driver | 257 | * Host driver |
| 265 | ******************************************************************************/ | 258 | ******************************************************************************/ |
| @@ -332,7 +325,6 @@ int8_t sendchar(uint8_t c) | |||
| 332 | } | 325 | } |
| 333 | if (Endpoint_IsStalled()) | 326 | if (Endpoint_IsStalled()) |
| 334 | return -1; | 327 | return -1; |
| 335 | uint16_t currFN = USB_Device_GetFrameNumber(); | ||
| 336 | if (prevFN != USB_Device_GetFrameNumber()) { | 328 | if (prevFN != USB_Device_GetFrameNumber()) { |
| 337 | if (!(timeout--)) | 329 | if (!(timeout--)) |
| 338 | return -1; | 330 | return -1; |
diff --git a/keyboard/lufa/lufa.h b/keyboard/lufa/lufa.h index 3ba14b360..efb8c3837 100644 --- a/keyboard/lufa/lufa.h +++ b/keyboard/lufa/lufa.h | |||
| @@ -1,78 +1,45 @@ | |||
| 1 | /* | 1 | /* |
| 2 | LUFA Library | 2 | LUFA Library |
| 3 | Copyright (C) Dean Camera, 2012. | 3 | Copyright (C) Dean Camera, 2012. |
| 4 | 4 | ||
| 5 | dean [at] fourwalledcubicle [dot] com | 5 | dean [at] fourwalledcubicle [dot] com |
| 6 | www.lufa-lib.org | 6 | www.lufa-lib.org |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | /* | 9 | /* |
| 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) | 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) |
| 11 | Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com) | 11 | Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com) |
| 12 | 12 | ||
| 13 | Permission to use, copy, modify, distribute, and sell this | 13 | Permission to use, copy, modify, distribute, and sell this |
| 14 | software and its documentation for any purpose is hereby granted | 14 | software and its documentation for any purpose is hereby granted |
| 15 | without fee, provided that the above copyright notice appear in | 15 | without fee, provided that the above copyright notice appear in |
| 16 | all copies and that both that the copyright notice and this | 16 | all copies and that both that the copyright notice and this |
| 17 | permission notice and warranty disclaimer appear in supporting | 17 | permission notice and warranty disclaimer appear in supporting |
| 18 | documentation, and that the name of the author not be used in | 18 | documentation, and that the name of the author not be used in |
| 19 | advertising or publicity pertaining to distribution of the | 19 | advertising or publicity pertaining to distribution of the |
| 20 | software without specific, written prior permission. | 20 | software without specific, written prior permission. |
| 21 | 21 | ||
| 22 | The author disclaim all warranties with regard to this | 22 | The author disclaim all warranties with regard to this |
| 23 | software, including all implied warranties of merchantability | 23 | software, including all implied warranties of merchantability |
| 24 | and fitness. In no event shall the author be liable for any | 24 | and fitness. In no event shall the author be liable for any |
| 25 | special, indirect or consequential damages or any damages | 25 | special, indirect or consequential damages or any damages |
| 26 | whatsoever resulting from loss of use, data or profits, whether | 26 | whatsoever resulting from loss of use, data or profits, whether |
| 27 | in an action of contract, negligence or other tortious action, | 27 | in an action of contract, negligence or other tortious action, |
| 28 | arising out of or in connection with the use or performance of | 28 | arising out of or in connection with the use or performance of |
| 29 | this software. | 29 | this software. |
| 30 | */ | 30 | */ |
| 31 | 31 | ||
| 32 | #ifndef _LUFA_H_ | 32 | #ifndef _LUFA_H_ |
| 33 | #define _LUFA_H_ | 33 | #define _LUFA_H_ |
| 34 | 34 | ||
| 35 | /* Includes: */ | 35 | /* Includes: */ |
| 36 | #include <avr/io.h> | 36 | #include <avr/io.h> |
| 37 | #include <avr/wdt.h> | 37 | #include <avr/wdt.h> |
| 38 | #include <avr/power.h> | 38 | #include <avr/power.h> |
| 39 | #include <avr/interrupt.h> | 39 | #include <avr/interrupt.h> |
| 40 | #include <stdbool.h> | 40 | #include <stdbool.h> |
| 41 | #include <string.h> | 41 | #include <string.h> |
| 42 | 42 | #include <LUFA/Version.h> | |
| 43 | #include "Descriptors.h" | 43 | #include <LUFA/Drivers/USB/USB.h> |
| 44 | 44 | ||
| 45 | #include <LUFA/Version.h> | 45 | #endif |
| 46 | #include <LUFA/Drivers/USB/USB.h> | ||
| 47 | #include <LUFA/Drivers/Board/Joystick.h> | ||
| 48 | #include <LUFA/Drivers/Board/LEDs.h> | ||
| 49 | #include <LUFA/Drivers/Board/Buttons.h> | ||
| 50 | |||
| 51 | /* Macros: */ | ||
| 52 | /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ | ||
| 53 | #define LEDMASK_USB_NOTREADY LEDS_LED1 | ||
| 54 | |||
| 55 | /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ | ||
| 56 | #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) | ||
| 57 | |||
| 58 | /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ | ||
| 59 | #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) | ||
| 60 | |||
| 61 | /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ | ||
| 62 | #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) | ||
| 63 | |||
| 64 | /* Function Prototypes: */ | ||
| 65 | void SetupHardware(void); | ||
| 66 | void Keyboard_ProcessLEDReport(const uint8_t LEDStatus); | ||
| 67 | void Keyboard_HID_Task(void); | ||
| 68 | void Generic_HID_Task(void); | ||
| 69 | |||
| 70 | void EVENT_USB_Device_Connect(void); | ||
| 71 | void EVENT_USB_Device_Disconnect(void); | ||
| 72 | void EVENT_USB_Device_ConfigurationChanged(void); | ||
| 73 | void EVENT_USB_Device_ControlRequest(void); | ||
| 74 | void EVENT_USB_Device_StartOfFrame(void); | ||
| 75 | |||
| 76 | void Keyboard_send(USB_KeyboardReport_Data_t report); | ||
| 77 | #endif | ||
| 78 | |||
