From effa5914bff71fa7ad6506271c9ba4baa32a1eca Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 28 Jun 2012 12:59:17 +0900 Subject: clean descriptor setting. Remove keyboard OUT Endpoint. - to make descriptor get VID/PID/Version from config.h. - remove keyboard out endpoint. Instead host can use control request. --- keyboard/lufa/Descriptors.c | 432 -------------------------------------------- keyboard/lufa/Descriptors.h | 84 --------- keyboard/lufa/Makefile | 320 ++++++++++++++++---------------- keyboard/lufa/config.h | 6 + keyboard/lufa/descriptor.c | 416 ++++++++++++++++++++++++++++++++++++++++++ keyboard/lufa/descriptor.h | 86 +++++++++ keyboard/lufa/lufa.c | 146 +++++++-------- keyboard/lufa/lufa.h | 123 +++++-------- 8 files changed, 782 insertions(+), 831 deletions(-) delete mode 100644 keyboard/lufa/Descriptors.c delete mode 100644 keyboard/lufa/Descriptors.h create mode 100644 keyboard/lufa/descriptor.c create mode 100644 keyboard/lufa/descriptor.h diff --git a/keyboard/lufa/Descriptors.c b/keyboard/lufa/Descriptors.c deleted file mode 100644 index a4e9defab4..0000000000 --- a/keyboard/lufa/Descriptors.c +++ /dev/null @@ -1,432 +0,0 @@ -/* - * Copyright 2012 Jun Wako - * This file is based on: - * LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse - * LUFA-120219/Demos/Device/Lowlevel/GenericHID - */ - -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * USB Device Descriptors, for library use when in USB device mode. Descriptors are special - * computer-readable structures which the host requests upon device enumeration, to determine - * the device's capabilities and functions. - */ - -#include "Descriptors.h" - - -/******************************************************************************* - * HID Report Descriptors - ******************************************************************************/ -const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = -{ - HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ - HID_RI_USAGE(8, 0x06), /* Keyboard */ - HID_RI_COLLECTION(8, 0x01), /* Application */ - HID_RI_USAGE_PAGE(8, 0x07), /* Key Codes */ - HID_RI_USAGE_MINIMUM(8, 0xE0), /* Keyboard Left Control */ - HID_RI_USAGE_MAXIMUM(8, 0xE7), /* Keyboard Right GUI */ - HID_RI_LOGICAL_MINIMUM(8, 0x00), - HID_RI_LOGICAL_MAXIMUM(8, 0x01), - HID_RI_REPORT_SIZE(8, 0x01), - HID_RI_REPORT_COUNT(8, 0x08), - HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), - HID_RI_REPORT_COUNT(8, 0x01), - HID_RI_REPORT_SIZE(8, 0x08), - HID_RI_INPUT(8, HID_IOF_CONSTANT), - HID_RI_USAGE_PAGE(8, 0x08), /* LEDs */ - HID_RI_USAGE_MINIMUM(8, 0x01), /* Num Lock */ - HID_RI_USAGE_MAXIMUM(8, 0x05), /* Kana */ - HID_RI_REPORT_COUNT(8, 0x05), - HID_RI_REPORT_SIZE(8, 0x01), - HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), - HID_RI_REPORT_COUNT(8, 0x01), - HID_RI_REPORT_SIZE(8, 0x03), - HID_RI_OUTPUT(8, HID_IOF_CONSTANT), - HID_RI_LOGICAL_MINIMUM(8, 0x00), - HID_RI_LOGICAL_MAXIMUM(8, 0x65), - HID_RI_USAGE_PAGE(8, 0x07), /* Keyboard */ - HID_RI_USAGE_MINIMUM(8, 0x00), /* Reserved (no event indicated) */ - HID_RI_USAGE_MAXIMUM(8, 0x65), /* Keyboard Application */ - HID_RI_REPORT_COUNT(8, 0x06), - HID_RI_REPORT_SIZE(8, 0x08), - HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE), - HID_RI_END_COLLECTION(0), -}; - -const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] = -{ - HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ - HID_RI_USAGE(8, 0x02), /* Mouse */ - HID_RI_COLLECTION(8, 0x01), /* Application */ - HID_RI_USAGE(8, 0x01), /* Pointer */ - HID_RI_COLLECTION(8, 0x00), /* Physical */ - HID_RI_USAGE_PAGE(8, 0x09), /* Button */ - HID_RI_USAGE_MINIMUM(8, 0x01), - HID_RI_USAGE_MAXIMUM(8, 0x03), - HID_RI_LOGICAL_MINIMUM(8, 0x00), - HID_RI_LOGICAL_MAXIMUM(8, 0x01), - HID_RI_REPORT_COUNT(8, 0x03), - HID_RI_REPORT_SIZE(8, 0x01), - HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), - HID_RI_REPORT_COUNT(8, 0x01), - HID_RI_REPORT_SIZE(8, 0x05), - HID_RI_INPUT(8, HID_IOF_CONSTANT), - HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ - HID_RI_USAGE(8, 0x30), /* Usage X */ - HID_RI_USAGE(8, 0x31), /* Usage Y */ - HID_RI_LOGICAL_MINIMUM(8, -1), - HID_RI_LOGICAL_MAXIMUM(8, 1), - HID_RI_PHYSICAL_MINIMUM(8, -1), - HID_RI_PHYSICAL_MAXIMUM(8, 1), - HID_RI_REPORT_COUNT(8, 0x02), - HID_RI_REPORT_SIZE(8, 0x08), - HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), - HID_RI_END_COLLECTION(0), - HID_RI_END_COLLECTION(0), -}; - -const USB_Descriptor_HIDReport_Datatype_t PROGMEM GenericReport[] = -{ - HID_RI_USAGE_PAGE(16, 0xFF00), /* Vendor Page 0 */ - HID_RI_USAGE(8, 0x01), /* Vendor Usage 1 */ - HID_RI_COLLECTION(8, 0x01), /* Vendor Usage 1 */ - HID_RI_USAGE(8, 0x02), /* Vendor Usage 2 */ - HID_RI_LOGICAL_MINIMUM(8, 0x00), - HID_RI_LOGICAL_MAXIMUM(8, 0xFF), - HID_RI_REPORT_SIZE(8, 0x08), - HID_RI_REPORT_COUNT(8, GENERIC_REPORT_SIZE), - HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), - HID_RI_USAGE(8, 0x03), /* Vendor Usage 3 */ - HID_RI_LOGICAL_MINIMUM(8, 0x00), - HID_RI_LOGICAL_MAXIMUM(8, 0xFF), - HID_RI_REPORT_SIZE(8, 0x08), - HID_RI_REPORT_COUNT(8, GENERIC_REPORT_SIZE), - HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), - HID_RI_END_COLLECTION(0), -}; - - -/******************************************************************************* - * Device Descriptors - ******************************************************************************/ -const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = -{ - .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, - - .USBSpecification = VERSION_BCD(01.10), - .Class = USB_CSCP_NoDeviceClass, - .SubClass = USB_CSCP_NoDeviceSubclass, - .Protocol = USB_CSCP_NoDeviceProtocol, - - .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, - - .VendorID = 0xFEED, - .ProductID = 0x204D, - .ReleaseNumber = VERSION_BCD(00.02), - - .ManufacturerStrIndex = 0x01, - .ProductStrIndex = 0x02, - .SerialNumStrIndex = NO_DESCRIPTOR, - - .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS -}; - -/******************************************************************************* - * Configuration Descriptors - ******************************************************************************/ -const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = -{ - .Config = - { - .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, - - .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), - .TotalInterfaces = 3, - - .ConfigurationNumber = 1, - .ConfigurationStrIndex = NO_DESCRIPTOR, - - .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), //TODO: bus powered? - - .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) - }, - - /* - * Keyboard - */ - .HID1_KeyboardInterface = - { - .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, - - .InterfaceNumber = 0x00, - .AlternateSetting = 0x00, - - .TotalEndpoints = 2, - - .Class = HID_CSCP_HIDClass, - .SubClass = HID_CSCP_BootSubclass, - .Protocol = HID_CSCP_KeyboardBootProtocol, - - .InterfaceStrIndex = NO_DESCRIPTOR - }, - - .HID1_KeyboardHID = - { - .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, - - .HIDSpec = VERSION_BCD(01.11), - .CountryCode = 0x00, - .TotalReportDescriptors = 1, - .HIDReportType = HID_DTYPE_Report, - .HIDReportLength = sizeof(KeyboardReport) - }, - - .HID1_ReportINEndpoint = - { - .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - - .EndpointAddress = (ENDPOINT_DIR_IN | KEYBOARD_IN_EPNUM), - .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = HID_EPSIZE, - .PollingIntervalMS = 0x01 - }, - - .HID1_ReportOUTEndpoint = - { - .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - - .EndpointAddress = (ENDPOINT_DIR_OUT | KEYBOARD_OUT_EPNUM), - .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = HID_EPSIZE, - .PollingIntervalMS = 0x01 - }, - - /* - * Mouse - */ - .HID2_MouseInterface = - { - .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, - - .InterfaceNumber = 0x01, - .AlternateSetting = 0x00, - - .TotalEndpoints = 1, - - .Class = HID_CSCP_HIDClass, - .SubClass = HID_CSCP_BootSubclass, - .Protocol = HID_CSCP_MouseBootProtocol, - - .InterfaceStrIndex = NO_DESCRIPTOR - }, - - .HID2_MouseHID = - { - .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, - - .HIDSpec = VERSION_BCD(01.11), - .CountryCode = 0x00, - .TotalReportDescriptors = 1, - .HIDReportType = HID_DTYPE_Report, - .HIDReportLength = sizeof(MouseReport) - }, - - .HID2_ReportINEndpoint = - { - .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - - .EndpointAddress = (ENDPOINT_DIR_IN | MOUSE_IN_EPNUM), - .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = HID_EPSIZE, - .PollingIntervalMS = 0x01 - }, - - /* - * Generic - */ - .HID3_GenericInterface = - { - .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, - - .InterfaceNumber = 0x02, - .AlternateSetting = 0x00, - - .TotalEndpoints = 2, - - .Class = HID_CSCP_HIDClass, - .SubClass = HID_CSCP_NonBootSubclass, - .Protocol = HID_CSCP_NonBootProtocol, - - .InterfaceStrIndex = NO_DESCRIPTOR - }, - - .HID3_GenericHID = - { - .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, - - .HIDSpec = VERSION_BCD(01.11), - .CountryCode = 0x00, - .TotalReportDescriptors = 1, - .HIDReportType = HID_DTYPE_Report, - .HIDReportLength = sizeof(GenericReport) - }, - - .HID3_ReportINEndpoint = - { - .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - - .EndpointAddress = (ENDPOINT_DIR_IN | GENERIC_IN_EPNUM), - .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = GENERIC_EPSIZE, - .PollingIntervalMS = 0x01 - }, - - .HID3_ReportOUTEndpoint = - { - .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - - .EndpointAddress = (ENDPOINT_DIR_OUT | GENERIC_OUT_EPNUM), - .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = GENERIC_EPSIZE, - .PollingIntervalMS = 0x01 - } -}; - - -/******************************************************************************* - * String Descriptors - ******************************************************************************/ -const USB_Descriptor_String_t PROGMEM LanguageString = -{ - .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String}, - - .UnicodeString = {LANGUAGE_ID_ENG} -}; - -const USB_Descriptor_String_t PROGMEM ManufacturerString = -{ - .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, - - .UnicodeString = L"Dean Camera" // TODO: -}; - -const USB_Descriptor_String_t PROGMEM ProductString = -{ - .Header = {.Size = USB_STRING_LEN(28), .Type = DTYPE_String}, - - .UnicodeString = L"LUFA Mouse and Keyboard Demo" // TODO: -}; - - -/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" - * documentation) by the application code so that the address and size of a requested descriptor can be given - * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function - * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the - * USB host. - */ -uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, - const uint8_t wIndex, - const void** const DescriptorAddress) -{ - const uint8_t DescriptorType = (wValue >> 8); - const uint8_t DescriptorIndex = (wValue & 0xFF); - - const void* Address = NULL; - uint16_t Size = NO_DESCRIPTOR; - - switch (DescriptorType) - { - case DTYPE_Device: - Address = &DeviceDescriptor; - Size = sizeof(USB_Descriptor_Device_t); - break; - case DTYPE_Configuration: - Address = &ConfigurationDescriptor; - Size = sizeof(USB_Descriptor_Configuration_t); - break; - case DTYPE_String: - switch (DescriptorIndex ) - { - case 0x00: - Address = &LanguageString; - Size = pgm_read_byte(&LanguageString.Header.Size); - break; - case 0x01: - Address = &ManufacturerString; - Size = pgm_read_byte(&ManufacturerString.Header.Size); - break; - case 0x02: - Address = &ProductString; - Size = pgm_read_byte(&ProductString.Header.Size); - break; - } - break; - case HID_DTYPE_HID: - switch (wIndex) { - case 0: - Address = &ConfigurationDescriptor.HID1_KeyboardHID; - Size = sizeof(USB_HID_Descriptor_HID_t); - break; - case 1: - Address = &ConfigurationDescriptor.HID2_MouseHID; - Size = sizeof(USB_HID_Descriptor_HID_t); - break; - case 2: - Address = &ConfigurationDescriptor.HID3_GenericHID; - Size = sizeof(USB_HID_Descriptor_HID_t); - break; - } - break; - case HID_DTYPE_Report: - switch (wIndex) { - case 0: - Address = &KeyboardReport; - Size = sizeof(KeyboardReport); - break; - case 1: - Address = &MouseReport; - Size = sizeof(MouseReport); - break; - case 2: - Address = &GenericReport; - Size = sizeof(GenericReport); - break; - } - break; - } - - *DescriptorAddress = Address; - return Size; -} diff --git a/keyboard/lufa/Descriptors.h b/keyboard/lufa/Descriptors.h deleted file mode 100644 index 03e2426a37..0000000000 --- a/keyboard/lufa/Descriptors.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Header file for Descriptors.c. - */ - -#ifndef _DESCRIPTORS_H_ -#define _DESCRIPTORS_H_ - -#include -#include - - -typedef struct -{ - USB_Descriptor_Configuration_Header_t Config; - - // Keyboard HID Interface - USB_Descriptor_Interface_t HID1_KeyboardInterface; - USB_HID_Descriptor_HID_t HID1_KeyboardHID; - USB_Descriptor_Endpoint_t HID1_ReportINEndpoint; - USB_Descriptor_Endpoint_t HID1_ReportOUTEndpoint; - - // Mouse HID Interface - USB_Descriptor_Interface_t HID2_MouseInterface; - USB_HID_Descriptor_HID_t HID2_MouseHID; - USB_Descriptor_Endpoint_t HID2_ReportINEndpoint; - - // Generic HID Interface - USB_Descriptor_Interface_t HID3_GenericInterface; - USB_HID_Descriptor_HID_t HID3_GenericHID; - USB_Descriptor_Endpoint_t HID3_ReportINEndpoint; - USB_Descriptor_Endpoint_t HID3_ReportOUTEndpoint; -} USB_Descriptor_Configuration_t; - - -// Endopoint number/size -#define KEYBOARD_IN_EPNUM 1 -#define KEYBOARD_OUT_EPNUM 2 -#define MOUSE_IN_EPNUM 3 -#define GENERIC_IN_EPNUM 4 -#define GENERIC_OUT_EPNUM 5 - -#define HID_EPSIZE 8 -#define GENERIC_EPSIZE 8 -#define GENERIC_REPORT_SIZE 8 - - -uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, - const uint8_t wIndex, - const void** const DescriptorAddress) - ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); - -#endif diff --git a/keyboard/lufa/Makefile b/keyboard/lufa/Makefile index 115c7e6ec6..12af013f89 100644 --- a/keyboard/lufa/Makefile +++ b/keyboard/lufa/Makefile @@ -1,160 +1,160 @@ -# Hey Emacs, this is a -*- makefile -*- -#---------------------------------------------------------------------------- -# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al. -# >> Modified for use with the LUFA project. << -# -# Released to the Public Domain -# -# Additional material for this makefile was written by: -# Peter Fleury -# Tim Henigan -# Colin O'Flynn -# Reiner Patommel -# Markus Pfaff -# Sander Pool -# Frederik Rouleau -# Carlos Lamas -# Dean Camera -# Opendous Inc. -# Denver Gingerich -# -#---------------------------------------------------------------------------- -# On command line: -# -# make all = Make software. -# -# make clean = Clean out built project files. -# -# make coff = Convert ELF to AVR COFF. -# -# make extcoff = Convert ELF to AVR Extended COFF. -# -# make program = Download the hex file to the device, using avrdude. -# Please customize the avrdude settings below first! -# -# make dfu = Download the hex file to the device, using dfu-programmer (must -# have dfu-programmer installed). -# -# make flip = Download the hex file to the device, using Atmel FLIP (must -# have Atmel FLIP installed). -# -# make dfu-ee = Download the eeprom file to the device, using dfu-programmer -# (must have dfu-programmer installed). -# -# make flip-ee = Download the eeprom file to the device, using Atmel FLIP -# (must have Atmel FLIP installed). -# -# make doxygen = Generate DoxyGen documentation for the project (must have -# DoxyGen installed) -# -# make debug = Start either simulavr or avarice as specified for debugging, -# with avr-gdb or avr-insight as the front end for debugging. -# -# make filename.s = Just compile filename.c into the assembler code only. -# -# make filename.i = Create a preprocessed source file for use in submitting -# bug reports to the GCC project. -# -# To rebuild project do "make clean" then "make all". -#---------------------------------------------------------------------------- - -# Directory common source filess exist -TOP_DIR = ../.. - -# Directory keyboard dependent files exist -TARGET_DIR = . - -# MCU name -#MCU = at90usb1287 -MCU = atmega32u4 - - -# Target architecture (see library "Board Types" documentation). -ARCH = AVR8 - - -# Target board (see library "Board Types" documentation, NONE for projects not requiring -# LUFA board drivers). If USER is selected, put custom board drivers in a directory called -# "Board" inside the application directory. -BOARD = USBKEY - - -# Processor frequency. -# This will define a symbol, F_CPU, in all source code files equal to the -# processor frequency in Hz. You can then use this symbol in your source code to -# calculate timings. Do NOT tack on a 'UL' at the end, this will be done -# automatically to create a 32-bit value in your source code. -# -# This will be an integer division of F_USB below, as it is sourced by -# F_USB after it has run through any CPU prescalers. Note that this value -# does not *change* the processor frequency - it should merely be updated to -# reflect the processor speed set externally so that the code can use accurate -# software delays. -F_CPU = 16000000 - - -# Input clock frequency. -# This will define a symbol, F_USB, in all source code files equal to the -# input clock frequency (before any prescaling is performed) in Hz. This value may -# differ from F_CPU if prescaling is used on the latter, and is required as the -# raw input clock is fed directly to the PLL sections of the AVR for high speed -# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' -# at the end, this will be done automatically to create a 32-bit value in your -# source code. -# -# If no clock division is performed on the input clock inside the AVR (via the -# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. -F_USB = $(F_CPU) - - -# Target file name (without extension). -TARGET = lufa - - -# Path to the LUFA library -LUFA_PATH = ../../protocol - -# Create the LUFA source path variables by including the LUFA root makefile -include $(LUFA_PATH)/LUFA/makefile - - - -# List C source files here. (C dependencies are automatically generated.) -LSRC = $(TARGET).c \ - Descriptors.c \ - $(LUFA_SRC_USB) \ - $(LUFA_SRC_USBCLASS) - -SRC = $(subst $(LUFA_PATH)/LUFA/,,$(LSRC)) -SRC += keymap.c \ - matrix.c \ - led.c -CONFIG_H = config.h - - - -# LUFA library compile-time options and predefined tokens -LUFA_OPTS = -D USB_DEVICE_ONLY -LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8 -LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1 -LUFA_OPTS += -D USE_FLASH_DESCRIPTORS -LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" - -OPT_DEFS = -DF_CPU=$(F_CPU)UL -OPT_DEFS += -DF_USB=$(F_USB)UL -OPT_DEFS += -DBOARD=BOARD_$(BOARD) -DARCH=ARCH_$(ARCH) -OPT_DEFS += $(LUFA_OPTS) - - - -# Search Path -VPATH += $(TARGET_DIR) -VPATH += $(LUFA_PATH)/LUFA - - -include $(TOP_DIR)/protocol.mk -include $(TOP_DIR)/common.mk -include $(TOP_DIR)/rules.mk - -test: - echo $(SRC) +# Hey Emacs, this is a -*- makefile -*- +#---------------------------------------------------------------------------- +# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al. +# >> Modified for use with the LUFA project. << +# +# Released to the Public Domain +# +# Additional material for this makefile was written by: +# Peter Fleury +# Tim Henigan +# Colin O'Flynn +# Reiner Patommel +# Markus Pfaff +# Sander Pool +# Frederik Rouleau +# Carlos Lamas +# Dean Camera +# Opendous Inc. +# Denver Gingerich +# +#---------------------------------------------------------------------------- +# On command line: +# +# make all = Make software. +# +# make clean = Clean out built project files. +# +# make coff = Convert ELF to AVR COFF. +# +# make extcoff = Convert ELF to AVR Extended COFF. +# +# make program = Download the hex file to the device, using avrdude. +# Please customize the avrdude settings below first! +# +# make dfu = Download the hex file to the device, using dfu-programmer (must +# have dfu-programmer installed). +# +# make flip = Download the hex file to the device, using Atmel FLIP (must +# have Atmel FLIP installed). +# +# make dfu-ee = Download the eeprom file to the device, using dfu-programmer +# (must have dfu-programmer installed). +# +# make flip-ee = Download the eeprom file to the device, using Atmel FLIP +# (must have Atmel FLIP installed). +# +# make doxygen = Generate DoxyGen documentation for the project (must have +# DoxyGen installed) +# +# make debug = Start either simulavr or avarice as specified for debugging, +# with avr-gdb or avr-insight as the front end for debugging. +# +# make filename.s = Just compile filename.c into the assembler code only. +# +# make filename.i = Create a preprocessed source file for use in submitting +# bug reports to the GCC project. +# +# To rebuild project do "make clean" then "make all". +#---------------------------------------------------------------------------- + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# MCU name +#MCU = at90usb1287 +MCU = atmega32u4 + + +# Target architecture (see library "Board Types" documentation). +ARCH = AVR8 + + +# Target board (see library "Board Types" documentation, NONE for projects not requiring +# LUFA board drivers). If USER is selected, put custom board drivers in a directory called +# "Board" inside the application directory. +BOARD = USBKEY + + +# Processor frequency. +# This will define a symbol, F_CPU, in all source code files equal to the +# processor frequency in Hz. You can then use this symbol in your source code to +# calculate timings. Do NOT tack on a 'UL' at the end, this will be done +# automatically to create a 32-bit value in your source code. +# +# This will be an integer division of F_USB below, as it is sourced by +# F_USB after it has run through any CPU prescalers. Note that this value +# does not *change* the processor frequency - it should merely be updated to +# reflect the processor speed set externally so that the code can use accurate +# software delays. +F_CPU = 16000000 + + +# Input clock frequency. +# This will define a symbol, F_USB, in all source code files equal to the +# input clock frequency (before any prescaling is performed) in Hz. This value may +# differ from F_CPU if prescaling is used on the latter, and is required as the +# raw input clock is fed directly to the PLL sections of the AVR for high speed +# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' +# at the end, this will be done automatically to create a 32-bit value in your +# source code. +# +# If no clock division is performed on the input clock inside the AVR (via the +# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. +F_USB = $(F_CPU) + + +# Target file name (without extension). +TARGET = lufa + + +# Path to the LUFA library +LUFA_PATH = ../../protocol + +# Create the LUFA source path variables by including the LUFA root makefile +include $(LUFA_PATH)/LUFA/makefile + + + +# List C source files here. (C dependencies are automatically generated.) +LUFA_SRC = $(TARGET).c \ + descriptor.c \ + $(LUFA_SRC_USB) \ + $(LUFA_SRC_USBCLASS) + +SRC = $(subst $(LUFA_PATH)/LUFA/,,$(LUFA_SRC)) +SRC += keymap.c \ + matrix.c \ + led.c +CONFIG_H = config.h + + + +# LUFA library compile-time options and predefined tokens +LUFA_OPTS = -D USB_DEVICE_ONLY +LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8 +LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1 +LUFA_OPTS += -D USE_FLASH_DESCRIPTORS +LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" + +OPT_DEFS = -DF_CPU=$(F_CPU)UL +OPT_DEFS += -DF_USB=$(F_USB)UL +OPT_DEFS += -DBOARD=BOARD_$(BOARD) -DARCH=ARCH_$(ARCH) +OPT_DEFS += $(LUFA_OPTS) + + + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(LUFA_PATH)/LUFA + + +include $(TOP_DIR)/protocol.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk + +test: + echo $(SRC) diff --git a/keyboard/lufa/config.h b/keyboard/lufa/config.h index 4662e3dd39..c375a576f5 100644 --- a/keyboard/lufa/config.h +++ b/keyboard/lufa/config.h @@ -21,10 +21,16 @@ along with this program. If not, see . /* controller configuration */ #include "controller_teensy.h" + +/* USB Device descriptor */ #define VENDOR_ID 0xFEED #define PRODUCT_ID 0xBEE1 +#define DEVICE_VER 0x0101 #define MANUFACTURER t.m.k. #define PRODUCT Macway mod(LUFA) + + +/* message strings */ #define DESCRIPTION t.m.k. keyboard firmware for Macway mod(LUFA) diff --git a/keyboard/lufa/descriptor.c b/keyboard/lufa/descriptor.c new file mode 100644 index 0000000000..6059fd4a82 --- /dev/null +++ b/keyboard/lufa/descriptor.c @@ -0,0 +1,416 @@ +/* + * Copyright 2012 Jun Wako + * This file is based on: + * LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse + * LUFA-120219/Demos/Device/Lowlevel/GenericHID + */ + +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#include "util.h" +#include "descriptor.h" + + +/******************************************************************************* + * HID Report Descriptors + ******************************************************************************/ +const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = +{ + HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ + HID_RI_USAGE(8, 0x06), /* Keyboard */ + HID_RI_COLLECTION(8, 0x01), /* Application */ + HID_RI_USAGE_PAGE(8, 0x07), /* Key Codes */ + HID_RI_USAGE_MINIMUM(8, 0xE0), /* Keyboard Left Control */ + HID_RI_USAGE_MAXIMUM(8, 0xE7), /* Keyboard Right GUI */ + HID_RI_LOGICAL_MINIMUM(8, 0x00), + HID_RI_LOGICAL_MAXIMUM(8, 0x01), + HID_RI_REPORT_SIZE(8, 0x01), + HID_RI_REPORT_COUNT(8, 0x08), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), + HID_RI_REPORT_COUNT(8, 0x01), + HID_RI_REPORT_SIZE(8, 0x08), + HID_RI_INPUT(8, HID_IOF_CONSTANT), + HID_RI_USAGE_PAGE(8, 0x08), /* LEDs */ + HID_RI_USAGE_MINIMUM(8, 0x01), /* Num Lock */ + HID_RI_USAGE_MAXIMUM(8, 0x05), /* Kana */ + HID_RI_REPORT_COUNT(8, 0x05), + HID_RI_REPORT_SIZE(8, 0x01), + HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), + HID_RI_REPORT_COUNT(8, 0x01), + HID_RI_REPORT_SIZE(8, 0x03), + HID_RI_OUTPUT(8, HID_IOF_CONSTANT), + HID_RI_LOGICAL_MINIMUM(8, 0x00), + HID_RI_LOGICAL_MAXIMUM(8, 0x65), + HID_RI_USAGE_PAGE(8, 0x07), /* Keyboard */ + HID_RI_USAGE_MINIMUM(8, 0x00), /* Reserved (no event indicated) */ + HID_RI_USAGE_MAXIMUM(8, 0x65), /* Keyboard Application */ + HID_RI_REPORT_COUNT(8, 0x06), + HID_RI_REPORT_SIZE(8, 0x08), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE), + HID_RI_END_COLLECTION(0), +}; + +const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] = +{ + HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ + HID_RI_USAGE(8, 0x02), /* Mouse */ + HID_RI_COLLECTION(8, 0x01), /* Application */ + HID_RI_USAGE(8, 0x01), /* Pointer */ + HID_RI_COLLECTION(8, 0x00), /* Physical */ + HID_RI_USAGE_PAGE(8, 0x09), /* Button */ + HID_RI_USAGE_MINIMUM(8, 0x01), + HID_RI_USAGE_MAXIMUM(8, 0x03), + HID_RI_LOGICAL_MINIMUM(8, 0x00), + HID_RI_LOGICAL_MAXIMUM(8, 0x01), + HID_RI_REPORT_COUNT(8, 0x03), + HID_RI_REPORT_SIZE(8, 0x01), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), + HID_RI_REPORT_COUNT(8, 0x01), + HID_RI_REPORT_SIZE(8, 0x05), + HID_RI_INPUT(8, HID_IOF_CONSTANT), + HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ + HID_RI_USAGE(8, 0x30), /* Usage X */ + HID_RI_USAGE(8, 0x31), /* Usage Y */ + HID_RI_LOGICAL_MINIMUM(8, -1), + HID_RI_LOGICAL_MAXIMUM(8, 1), + HID_RI_PHYSICAL_MINIMUM(8, -1), + HID_RI_PHYSICAL_MAXIMUM(8, 1), + HID_RI_REPORT_COUNT(8, 0x02), + HID_RI_REPORT_SIZE(8, 0x08), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), + HID_RI_END_COLLECTION(0), + HID_RI_END_COLLECTION(0), +}; + +const USB_Descriptor_HIDReport_Datatype_t PROGMEM GenericReport[] = +{ + HID_RI_USAGE_PAGE(16, 0xFF00), /* Vendor Page 0 */ + HID_RI_USAGE(8, 0x01), /* Vendor Usage 1 */ + HID_RI_COLLECTION(8, 0x01), /* Vendor Usage 1 */ + HID_RI_USAGE(8, 0x02), /* Vendor Usage 2 */ + HID_RI_LOGICAL_MINIMUM(8, 0x00), + HID_RI_LOGICAL_MAXIMUM(8, 0xFF), + HID_RI_REPORT_SIZE(8, 0x08), + HID_RI_REPORT_COUNT(8, GENERIC_REPORT_SIZE), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), + HID_RI_USAGE(8, 0x03), /* Vendor Usage 3 */ + HID_RI_LOGICAL_MINIMUM(8, 0x00), + HID_RI_LOGICAL_MAXIMUM(8, 0xFF), + HID_RI_REPORT_SIZE(8, 0x08), + HID_RI_REPORT_COUNT(8, GENERIC_REPORT_SIZE), + HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), + HID_RI_END_COLLECTION(0), +}; + + +/******************************************************************************* + * Device Descriptors + ******************************************************************************/ +const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = +{ + .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, + + .USBSpecification = VERSION_BCD(01.10), + .Class = USB_CSCP_NoDeviceClass, + .SubClass = USB_CSCP_NoDeviceSubclass, + .Protocol = USB_CSCP_NoDeviceProtocol, + + .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, + + .VendorID = VENDOR_ID, + .ProductID = PRODUCT_ID, + .ReleaseNumber = DEVICE_VER, + + .ManufacturerStrIndex = 0x01, + .ProductStrIndex = 0x02, + .SerialNumStrIndex = NO_DESCRIPTOR, + + .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS +}; + +/******************************************************************************* + * Configuration Descriptors + ******************************************************************************/ +const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = +{ + .Config = + { + .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, + + .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), + .TotalInterfaces = 3, + + .ConfigurationNumber = 1, + .ConfigurationStrIndex = NO_DESCRIPTOR, + + .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_REMOTEWAKEUP), + + .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) + }, + + /* + * Keyboard + */ + .HID0_KeyboardInterface = + { + .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, + + .InterfaceNumber = KEYBOARD_INTERFACE, + .AlternateSetting = 0x00, + + .TotalEndpoints = 1, + + .Class = HID_CSCP_HIDClass, + .SubClass = HID_CSCP_BootSubclass, + .Protocol = HID_CSCP_KeyboardBootProtocol, + + .InterfaceStrIndex = NO_DESCRIPTOR + }, + + .HID0_KeyboardHID = + { + .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, + + .HIDSpec = VERSION_BCD(01.11), + .CountryCode = 0x00, + .TotalReportDescriptors = 1, + .HIDReportType = HID_DTYPE_Report, + .HIDReportLength = sizeof(KeyboardReport) + }, + + .HID0_ReportINEndpoint = + { + .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, + + .EndpointAddress = (ENDPOINT_DIR_IN | KEYBOARD_IN_EPNUM), + .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), + .EndpointSize = HID_EPSIZE, + .PollingIntervalMS = 0x01 + }, + + /* + * Mouse + */ + .HID1_MouseInterface = + { + .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, + + .InterfaceNumber = MOUSE_INTERFACE, + .AlternateSetting = 0x00, + + .TotalEndpoints = 1, + + .Class = HID_CSCP_HIDClass, + .SubClass = HID_CSCP_BootSubclass, + .Protocol = HID_CSCP_MouseBootProtocol, + + .InterfaceStrIndex = NO_DESCRIPTOR + }, + + .HID1_MouseHID = + { + .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, + + .HIDSpec = VERSION_BCD(01.11), + .CountryCode = 0x00, + .TotalReportDescriptors = 1, + .HIDReportType = HID_DTYPE_Report, + .HIDReportLength = sizeof(MouseReport) + }, + + .HID1_ReportINEndpoint = + { + .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, + + .EndpointAddress = (ENDPOINT_DIR_IN | MOUSE_IN_EPNUM), + .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), + .EndpointSize = HID_EPSIZE, + .PollingIntervalMS = 0x01 + }, + + /* + * Generic + */ + .HID2_GenericInterface = + { + .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, + + .InterfaceNumber = GENERIC_INTERFACE, + .AlternateSetting = 0x00, + + .TotalEndpoints = 2, + + .Class = HID_CSCP_HIDClass, + .SubClass = HID_CSCP_NonBootSubclass, + .Protocol = HID_CSCP_NonBootProtocol, + + .InterfaceStrIndex = NO_DESCRIPTOR + }, + + .HID2_GenericHID = + { + .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, + + .HIDSpec = VERSION_BCD(01.11), + .CountryCode = 0x00, + .TotalReportDescriptors = 1, + .HIDReportType = HID_DTYPE_Report, + .HIDReportLength = sizeof(GenericReport) + }, + + .HID2_ReportINEndpoint = + { + .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, + + .EndpointAddress = (ENDPOINT_DIR_IN | GENERIC_IN_EPNUM), + .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), + .EndpointSize = GENERIC_EPSIZE, + .PollingIntervalMS = 0x01 + }, + + .HID2_ReportOUTEndpoint = + { + .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, + + .EndpointAddress = (ENDPOINT_DIR_OUT | GENERIC_OUT_EPNUM), + .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), + .EndpointSize = GENERIC_EPSIZE, + .PollingIntervalMS = 0x01 + } +}; + + +/******************************************************************************* + * String Descriptors + ******************************************************************************/ +const USB_Descriptor_String_t PROGMEM LanguageString = +{ + .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String}, + + .UnicodeString = {LANGUAGE_ID_ENG} +}; + +const USB_Descriptor_String_t PROGMEM ManufacturerString = +{ + .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, + + .UnicodeString = LSTR(MANUFACTURER) +}; + +const USB_Descriptor_String_t PROGMEM ProductString = +{ + .Header = {.Size = USB_STRING_LEN(28), .Type = DTYPE_String}, + + .UnicodeString = LSTR(PRODUCT) +}; + + +/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" + * documentation) by the application code so that the address and size of a requested descriptor can be given + * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function + * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the + * USB host. + */ +uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, + const uint8_t wIndex, + const void** const DescriptorAddress) +{ + const uint8_t DescriptorType = (wValue >> 8); + const uint8_t DescriptorIndex = (wValue & 0xFF); + + const void* Address = NULL; + uint16_t Size = NO_DESCRIPTOR; + + switch (DescriptorType) + { + case DTYPE_Device: + Address = &DeviceDescriptor; + Size = sizeof(USB_Descriptor_Device_t); + break; + case DTYPE_Configuration: + Address = &ConfigurationDescriptor; + Size = sizeof(USB_Descriptor_Configuration_t); + break; + case DTYPE_String: + switch (DescriptorIndex ) + { + case 0x00: + Address = &LanguageString; + Size = pgm_read_byte(&LanguageString.Header.Size); + break; + case 0x01: + Address = &ManufacturerString; + Size = pgm_read_byte(&ManufacturerString.Header.Size); + break; + case 0x02: + Address = &ProductString; + Size = pgm_read_byte(&ProductString.Header.Size); + break; + } + break; + case HID_DTYPE_HID: + switch (wIndex) { + case KEYBOARD_INTERFACE: + Address = &ConfigurationDescriptor.HID0_KeyboardHID; + Size = sizeof(USB_HID_Descriptor_HID_t); + break; + case MOUSE_INTERFACE: + Address = &ConfigurationDescriptor.HID1_MouseHID; + Size = sizeof(USB_HID_Descriptor_HID_t); + break; + case GENERIC_INTERFACE: + Address = &ConfigurationDescriptor.HID2_GenericHID; + Size = sizeof(USB_HID_Descriptor_HID_t); + break; + } + break; + case HID_DTYPE_Report: + switch (wIndex) { + case KEYBOARD_INTERFACE: + Address = &KeyboardReport; + Size = sizeof(KeyboardReport); + break; + case MOUSE_INTERFACE: + Address = &MouseReport; + Size = sizeof(MouseReport); + break; + case GENERIC_INTERFACE: + Address = &GenericReport; + Size = sizeof(GenericReport); + break; + } + break; + } + + *DescriptorAddress = Address; + return Size; +} diff --git a/keyboard/lufa/descriptor.h b/keyboard/lufa/descriptor.h new file mode 100644 index 0000000000..19e24c2013 --- /dev/null +++ b/keyboard/lufa/descriptor.h @@ -0,0 +1,86 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Header file for Descriptors.c. + */ + +#ifndef _DESCRIPTORS_H_ +#define _DESCRIPTORS_H_ + +#include +#include + + +typedef struct +{ + USB_Descriptor_Configuration_Header_t Config; + + // Keyboard HID Interface + USB_Descriptor_Interface_t HID0_KeyboardInterface; + USB_HID_Descriptor_HID_t HID0_KeyboardHID; + USB_Descriptor_Endpoint_t HID0_ReportINEndpoint; + + // Mouse HID Interface + USB_Descriptor_Interface_t HID1_MouseInterface; + USB_HID_Descriptor_HID_t HID1_MouseHID; + USB_Descriptor_Endpoint_t HID1_ReportINEndpoint; + + // Generic HID Interface + USB_Descriptor_Interface_t HID2_GenericInterface; + USB_HID_Descriptor_HID_t HID2_GenericHID; + USB_Descriptor_Endpoint_t HID2_ReportINEndpoint; + USB_Descriptor_Endpoint_t HID2_ReportOUTEndpoint; +} USB_Descriptor_Configuration_t; + + +#define KEYBOARD_INTERFACE 0 +#define MOUSE_INTERFACE 1 +#define GENERIC_INTERFACE 2 + +// Endopoint number/size +#define KEYBOARD_IN_EPNUM 1 +#define MOUSE_IN_EPNUM 2 +#define GENERIC_IN_EPNUM 3 +#define GENERIC_OUT_EPNUM 4 + +#define HID_EPSIZE 8 +#define GENERIC_EPSIZE 8 +#define GENERIC_REPORT_SIZE 8 + + +uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, + const uint8_t wIndex, + const void** const DescriptorAddress) + ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); + +#endif diff --git a/keyboard/lufa/lufa.c b/keyboard/lufa/lufa.c index d841f45c6a..569960e2a9 100644 --- a/keyboard/lufa/lufa.c +++ b/keyboard/lufa/lufa.c @@ -42,11 +42,15 @@ #include "keyboard.h" #include "sendchar.h" #include "debug.h" + +#include "descriptor.h" #include "lufa.h" static uint8_t keyboard_led_stats = 0; -report_keyboard_t keyboard_report_sent; -report_mouse_t mouse_report_sent; + +// TODO: impl Control Request GET_REPORT +static report_keyboard_t keyboard_report_sent; +static report_mouse_t mouse_report_sent; /* Host driver */ static uint8_t keyboard_leds(void); @@ -63,6 +67,9 @@ static host_driver_t lufa_driver = { }; +static void SetupHardware(void); +static void Generic_HID_Task(void); + int main(void) { SetupHardware(); @@ -74,20 +81,23 @@ int main(void) debug_keyboard = true; debug_mouse = true; - _delay_ms(3000); +/* TODO: can't print here + _delay_ms(5000); + USB_USBTask(); print("abcdefg\n"); + USB_USBTask(); +*/ keyboard_init(); host_set_driver(&lufa_driver); while (1) { keyboard_proc(); - Keyboard_HID_Task(); + Generic_HID_Task(); USB_USBTask(); } } -/** Configures the board hardware and chip peripherals for the demo's functionality. */ void SetupHardware(void) { /* Disable watchdog if enabled by bootloader/fuses */ @@ -100,6 +110,46 @@ void SetupHardware(void) USB_Init(); } +static void Generic_HID_Task(void) +{ + /* Device must be connected and configured for the task to run */ + if (USB_DeviceState != DEVICE_STATE_Configured) + return; + + // TODO: impl receivechar()/recvchar() + Endpoint_SelectEndpoint(GENERIC_OUT_EPNUM); + + /* Check to see if a packet has been sent from the host */ + if (Endpoint_IsOUTReceived()) + { + /* Check to see if the packet contains data */ + if (Endpoint_IsReadWriteAllowed()) + { + /* Create a temporary buffer to hold the read in report from the host */ + uint8_t GenericData[GENERIC_REPORT_SIZE]; + + /* Read Generic Report Data */ + Endpoint_Read_Stream_LE(&GenericData, sizeof(GenericData), NULL); + + /* Process Generic Report Data */ + //ProcessGenericHIDReport(GenericData); + } + + /* Finalize the stream transfer to send the last packet */ + Endpoint_ClearOUT(); + } + + /* IN packet */ + Endpoint_SelectEndpoint(GENERIC_IN_EPNUM); + // send IN packet + if (Endpoint_IsINReady()) + Endpoint_ClearIN(); +} + + +/******************************************************************************* + * USB Events + ******************************************************************************/ /** Event handler for the USB_Connect event. */ void EVENT_USB_Device_Connect(void) { @@ -120,18 +170,16 @@ void EVENT_USB_Device_ConfigurationChanged(void) /* Setup Keyboard HID Report Endpoints */ ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, HID_EPSIZE, ENDPOINT_BANK_SINGLE); - ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, - HID_EPSIZE, ENDPOINT_BANK_SINGLE); /* Setup Mouse HID Report Endpoint */ ConfigSuccess &= Endpoint_ConfigureEndpoint(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, HID_EPSIZE, ENDPOINT_BANK_SINGLE); - /* Setup Generic HID Report Endpoints */ - ConfigSuccess &= Endpoint_ConfigureEndpoint(GENERIC_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, - GENERIC_EPSIZE, ENDPOINT_BANK_SINGLE); - ConfigSuccess &= Endpoint_ConfigureEndpoint(GENERIC_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, - GENERIC_EPSIZE, ENDPOINT_BANK_SINGLE); + /* Setup Generic HID Report Endpoints */ + ConfigSuccess &= Endpoint_ConfigureEndpoint(GENERIC_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, + GENERIC_EPSIZE, ENDPOINT_BANK_SINGLE); + ConfigSuccess &= Endpoint_ConfigureEndpoint(GENERIC_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, + GENERIC_EPSIZE, ENDPOINT_BANK_SINGLE); } /** Event handler for the USB_ControlRequest event. @@ -152,15 +200,17 @@ void EVENT_USB_Device_ControlRequest(void) // Interface switch (USB_ControlRequest.wIndex) { - case 1: // Keyboard + case KEYBOARD_INTERFACE: + // TODO: test/check ReportData = (uint8_t*)&keyboard_report_sent; ReportSize = sizeof(keyboard_report_sent); break; - case 2: // Mouse + case MOUSE_INTERFACE: + // TODO: test/check ReportData = (uint8_t*)&mouse_report_sent; ReportSize = sizeof(mouse_report_sent); break; - case 3: // Generic + case GENERIC_INTERFACE: break; } @@ -184,13 +234,14 @@ void EVENT_USB_Device_ControlRequest(void) // Interface switch (USB_ControlRequest.wIndex) { - case 1: // Keyboard + case KEYBOARD_INTERFACE: + // TODO: test/check /* Read in the LED report from the host */ keyboard_led_stats = Endpoint_Read_8(); break; - case 2: // Mouse + case MOUSE_INTERFACE: break; - case 3: // Generic + case GENERIC_INTERFACE: break; } @@ -202,64 +253,6 @@ void EVENT_USB_Device_ControlRequest(void) } } -/** Keyboard task. - * This processes host LED status reports sent to the device via the keyboard OUT reporting endpoint. - */ -void Keyboard_HID_Task(void) -{ - /* Device must be connected and configured for the task to run */ - if (USB_DeviceState != DEVICE_STATE_Configured) - return; - - /* Select the Keyboard LED Report Endpoint */ - Endpoint_SelectEndpoint(KEYBOARD_OUT_EPNUM); - - /* Check if Keyboard LED Endpoint Ready for Read/Write */ - if (Endpoint_IsReadWriteAllowed()) - { - /* Read in the LED report from the host */ - keyboard_led_stats = Endpoint_Read_8(); - - /* Handshake the OUT Endpoint - clear endpoint and ready for next report */ - Endpoint_ClearOUT(); - } -} - -void Generic_HID_Task(void) -{ - /* Device must be connected and configured for the task to run */ - if (USB_DeviceState != DEVICE_STATE_Configured) - return; - - Endpoint_SelectEndpoint(GENERIC_OUT_EPNUM); - - /* Check to see if a packet has been sent from the host */ - if (Endpoint_IsOUTReceived()) - { - /* Check to see if the packet contains data */ - if (Endpoint_IsReadWriteAllowed()) - { - /* Create a temporary buffer to hold the read in report from the host */ - uint8_t GenericData[GENERIC_REPORT_SIZE]; - - /* Read Generic Report Data */ - Endpoint_Read_Stream_LE(&GenericData, sizeof(GenericData), NULL); - - /* Process Generic Report Data */ - //TODO: ProcessGenericHIDReport(GenericData); - } - - /* Finalize the stream transfer to send the last packet */ - Endpoint_ClearOUT(); - } - - /* IN packet */ - Endpoint_SelectEndpoint(GENERIC_IN_EPNUM); - // send IN packet - if (Endpoint_IsINReady()) - Endpoint_ClearIN(); -} - /******************************************************************************* * Host driver ******************************************************************************/ @@ -332,7 +325,6 @@ int8_t sendchar(uint8_t c) } if (Endpoint_IsStalled()) return -1; - uint16_t currFN = USB_Device_GetFrameNumber(); if (prevFN != USB_Device_GetFrameNumber()) { if (!(timeout--)) return -1; diff --git a/keyboard/lufa/lufa.h b/keyboard/lufa/lufa.h index 3ba14b360b..efb8c38378 100644 --- a/keyboard/lufa/lufa.h +++ b/keyboard/lufa/lufa.h @@ -1,78 +1,45 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2012. - - dean [at] fourwalledcubicle [dot] com - www.lufa-lib.org -*/ - -/* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com) - - Permission to use, copy, modify, distribute, and sell this - software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in - all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#ifndef _LUFA_H_ -#define _LUFA_H_ - - /* Includes: */ - #include - #include - #include - #include - #include - #include - - #include "Descriptors.h" - - #include - #include - #include - #include - #include - - /* Macros: */ - /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ - #define LEDMASK_USB_NOTREADY LEDS_LED1 - - /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ - #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) - - /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ - #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) - - /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ - #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) - - /* Function Prototypes: */ - void SetupHardware(void); - void Keyboard_ProcessLEDReport(const uint8_t LEDStatus); - void Keyboard_HID_Task(void); - void Generic_HID_Task(void); - - void EVENT_USB_Device_Connect(void); - void EVENT_USB_Device_Disconnect(void); - void EVENT_USB_Device_ConfigurationChanged(void); - void EVENT_USB_Device_ControlRequest(void); - void EVENT_USB_Device_StartOfFrame(void); - - void Keyboard_send(USB_KeyboardReport_Data_t report); -#endif - +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#ifndef _LUFA_H_ +#define _LUFA_H_ + + /* Includes: */ +#include +#include +#include +#include +#include +#include +#include +#include + +#endif -- cgit v1.2.3