From dd93d2915f79d0b825fc6bbc4edb556a69eac406 Mon Sep 17 00:00:00 2001 From: tmk Date: Tue, 26 Jun 2012 15:55:45 +0900 Subject: [PATCH 01/13] initial attempt for LUFA. Add keyboard/lufa macway keyobard with LUFA. Add new program target to rule.mk; flip, dfu and teensy --- keyboard/lufa/Descriptors.c | 359 ++++++++++++++++++++++++++++++++++++ keyboard/lufa/Descriptors.h | 87 +++++++++ keyboard/lufa/Makefile | 161 ++++++++++++++++ keyboard/lufa/config.h | 70 +++++++ keyboard/lufa/keymap.c | 195 ++++++++++++++++++++ keyboard/lufa/led.c | 24 +++ keyboard/lufa/lufa.c | 243 ++++++++++++++++++++++++ keyboard/lufa/lufa.h | 78 ++++++++ keyboard/lufa/matrix.c | 271 +++++++++++++++++++++++++++ rules.mk | 31 +++- 10 files changed, 1517 insertions(+), 2 deletions(-) create mode 100644 keyboard/lufa/Descriptors.c create mode 100644 keyboard/lufa/Descriptors.h create mode 100644 keyboard/lufa/Makefile create mode 100644 keyboard/lufa/config.h create mode 100644 keyboard/lufa/keymap.c create mode 100644 keyboard/lufa/led.c create mode 100644 keyboard/lufa/lufa.c create mode 100644 keyboard/lufa/lufa.h create mode 100644 keyboard/lufa/matrix.c diff --git a/keyboard/lufa/Descriptors.c b/keyboard/lufa/Descriptors.c new file mode 100644 index 00000000..3195aa77 --- /dev/null +++ b/keyboard/lufa/Descriptors.c @@ -0,0 +1,359 @@ +/* + 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 class report descriptor. This is a special descriptor constructed with values from the + * USBIF HID class specification to describe the reports and capabilities of the HID device. This + * descriptor is parsed by the host and its contents used to determine what data (and in what encoding) + * the device will send, and what it may be sent back from the host. Refer to the HID specification for + * more details on HID report descriptors. + * + * This descriptor describes the mouse HID interface's report structure. + */ +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), +}; + +/** Same as the MouseReport structure, but defines the keyboard HID interface's report structure. */ +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), +}; + +/** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall + * device characteristics, including the supported USB version, control endpoint size and the + * number of device configurations. The descriptor is read out by the USB host when the enumeration + * process begins. + */ +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 = 0x03EB, + .ProductID = 0x204D, + .ReleaseNumber = VERSION_BCD(00.01), + + .ManufacturerStrIndex = 0x01, + .ProductStrIndex = 0x02, + .SerialNumStrIndex = NO_DESCRIPTOR, + + .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS +}; + +/** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage + * of the device in one of its supported configurations, including information about any device interfaces + * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting + * a configuration so that the host may correctly communicate with the USB device. + */ +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 = 2, + + .ConfigurationNumber = 1, + .ConfigurationStrIndex = NO_DESCRIPTOR, + + .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), + + .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) + }, + + .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 + }, + + .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 + } +}; + +/** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests + * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate + * via the language ID table available at USB.org what languages the device supports for its string descriptors. + */ +const USB_Descriptor_String_t PROGMEM LanguageString = +{ + .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String}, + + .UnicodeString = {LANGUAGE_ID_ENG} +}; + +/** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable + * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device + * Descriptor. + */ +const USB_Descriptor_String_t PROGMEM ManufacturerString = +{ + .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, + + .UnicodeString = L"Dean Camera" +}; + +/** Product descriptor string. This is a Unicode string containing the product's details in human readable form, + * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device + * Descriptor. + */ +const USB_Descriptor_String_t PROGMEM ProductString = +{ + .Header = {.Size = USB_STRING_LEN(28), .Type = DTYPE_String}, + + .UnicodeString = L"LUFA Mouse and Keyboard Demo" +}; + +/** 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 DescriptorNumber = (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 (DescriptorNumber) + { + 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: + if (!(wIndex)) + { + Address = &ConfigurationDescriptor.HID1_KeyboardHID; + Size = sizeof(USB_HID_Descriptor_HID_t); + } + else + { + Address = &ConfigurationDescriptor.HID2_MouseHID; + Size = sizeof(USB_HID_Descriptor_HID_t); + } + break; + case HID_DTYPE_Report: + if (!(wIndex)) + { + Address = &KeyboardReport; + Size = sizeof(KeyboardReport); + } + else + { + Address = &MouseReport; + Size = sizeof(MouseReport); + } + + break; + } + + *DescriptorAddress = Address; + return Size; +} + diff --git a/keyboard/lufa/Descriptors.h b/keyboard/lufa/Descriptors.h new file mode 100644 index 00000000..05b2035b --- /dev/null +++ b/keyboard/lufa/Descriptors.h @@ -0,0 +1,87 @@ +/* + 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_ + + /* Includes: */ + #include + + #include + + /* Type Defines: */ + /** Type define for the device configuration descriptor structure. This must be defined in the + * application code, as the configuration descriptor contains several sub-descriptors which + * vary between devices, and which describe the device's usage to the host. + */ + 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; + USB_Descriptor_Endpoint_t HID2_ReportOUTEndpoint; + } USB_Descriptor_Configuration_t; + + /* Macros: */ + /** Endpoint number of the Keyboard HID reporting IN endpoint. */ + #define KEYBOARD_IN_EPNUM 1 + + /** Endpoint number of the Keyboard HID reporting OUT endpoint. */ + #define KEYBOARD_OUT_EPNUM 2 + + /** Endpoint number of the Mouse HID reporting IN endpoint. */ + #define MOUSE_IN_EPNUM 3 + + /** Size in bytes of each of the HID reporting IN and OUT endpoints. */ + #define HID_EPSIZE 8 + + /* Function Prototypes: */ + 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 new file mode 100644 index 00000000..1d2f712d --- /dev/null +++ b/keyboard/lufa/Makefile @@ -0,0 +1,161 @@ +# 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 \ + sendchar_null.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 new file mode 100644 index 00000000..4662e3dd --- /dev/null +++ b/keyboard/lufa/config.h @@ -0,0 +1,70 @@ +/* +Copyright 2011 Jun Wako + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef CONFIG_H +#define CONFIG_H + +/* controller configuration */ +#include "controller_teensy.h" + +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0xBEE1 +#define MANUFACTURER t.m.k. +#define PRODUCT Macway mod(LUFA) +#define DESCRIPTION t.m.k. keyboard firmware for Macway mod(LUFA) + + +/* matrix size */ +#define MATRIX_ROWS 9 +#define MATRIX_COLS 8 +/* define if matrix has ghost */ +#define MATRIX_HAS_GHOST +/* Set 0 if need no debouncing */ +#define DEBOUNCE 5 + + +/* key combination for command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_LCTRL) | MOD_BIT(KB_LALT) | MOD_BIT(KB_LGUI)) || \ + keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT)) \ +) + + +/* layer switching */ +#define LAYER_SWITCH_DELAY 100 +#define LAYER_SEND_FN_TERM 300 + + +/* mouse keys */ +#ifdef MOUSEKEY_ENABLE +# define MOUSEKEY_DELAY_TIME 192 +#endif + + +/* PS/2 mouse */ +#ifdef PS2_MOUSE_ENABLE +# define PS2_CLOCK_PORT PORTF +# define PS2_CLOCK_PIN PINF +# define PS2_CLOCK_DDR DDRF +# define PS2_CLOCK_BIT 0 +# define PS2_DATA_PORT PORTF +# define PS2_DATA_PIN PINF +# define PS2_DATA_DDR DDRF +# define PS2_DATA_BIT 1 +#endif + +#endif diff --git a/keyboard/lufa/keymap.c b/keyboard/lufa/keymap.c new file mode 100644 index 00000000..a223da73 --- /dev/null +++ b/keyboard/lufa/keymap.c @@ -0,0 +1,195 @@ +/* +Copyright 2011 Jun Wako + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/* + * Keymap for Macway mod + */ +#include +#include +#include +#include "usb_keycodes.h" +#include "print.h" +#include "debug.h" +#include "util.h" +#include "keymap.h" + + +// Convert physical keyboard layout to matrix array. +// This is a macro to define keymap easily in keyboard layout form. +#define KEYMAP( \ + K11, K10, K20, K30, K40, K41, K51, K50, K60, K70, K80, K81, K61, K02, \ + K12, K13, K23, K33, K43, K42, K52, K53, K63, K73, K83, K82, K62, K01, \ + K15, K14, K24, K34, K44, K45, K55, K54, K64, K74, K84, K85, K06, \ + K67, K16, K26, K36, K46, K47, K57, K56, K66, K76, K87, K32, K35, \ + K75, K22, K00, K07, K21, K04, K37, K27, K17 \ +) { \ + { KB_##K00, KB_##K01, KB_##K02, KB_NO, KB_##K04, KB_NO, KB_##K06, KB_##K07 }, \ + { KB_##K10, KB_##K11, KB_##K12, KB_##K13, KB_##K14, KB_##K15, KB_##K16, KB_##K17 }, \ + { KB_##K20, KB_##K21, KB_##K22, KB_##K23, KB_##K24, KB_NO, KB_##K26, KB_##K27 }, \ + { KB_##K30, KB_NO, KB_##K32, KB_##K33, KB_##K34, KB_##K35, KB_##K36, KB_##K37 }, \ + { KB_##K40, KB_##K41, KB_##K42, KB_##K43, KB_##K44, KB_##K45, KB_##K46, KB_##K47 }, \ + { KB_##K50, KB_##K51, KB_##K52, KB_##K53, KB_##K54, KB_##K55, KB_##K56, KB_##K57 }, \ + { KB_##K60, KB_##K61, KB_##K62, KB_##K63, KB_##K64, KB_NO, KB_##K66, KB_##K67 }, \ + { KB_##K70, KB_NO, KB_NO, KB_##K73, KB_##K74, KB_##K75, KB_##K76, KB_NO }, \ + { KB_##K80, KB_##K81, KB_##K82, KB_##K83, KB_##K84, KB_##K85, KB_NO, KB_##K87 } \ +} + +#define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)])) + + +// Assign Fn key(0-7) to a layer to which switch with the Fn key pressed. +static const uint8_t PROGMEM fn_layer[] = { + 0, // Fn0 + 1, // Fn1 + 2, // Fn2 + 3, // Fn3 + 4, // Fn4 + 0, // Fn5 + 3, // Fn6 + 3 // Fn7 +}; + +// Assign Fn key(0-7) to a keycode sent when release Fn key without use of the layer. +// See layer.c for details. +static const uint8_t PROGMEM fn_keycode[] = { + KB_NO, // Fn0 + KB_NO, // Fn1 + KB_SLSH, // Fn2 + KB_SCLN, // Fn3 + KB_SPC, // Fn4 + KB_NO, // Fn5 + KB_NO, // Fn6 + KB_NO // Fn7 +}; + +static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + /* Layer 0: Default Layer + * ,-----------------------------------------------------------. + * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | + * |-----------------------------------------------------------| + * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| | + * |-----------------------------------------------------' | + * |Contro| A| S| D| F| G| H| J| K| L|Fn3| '|Return | + * |-----------------------------------------------------------| + * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn1| + * |-----------------------------------------------------------| + * |Fn7|Gui |Alt |Fn4 |Alt |Gui|Fn6|Fn6|Ctr| + * `-----------------------------------------------------------' + */ + KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ + TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ + LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT,ENT, \ + LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \ + FN7, LGUI,LALT,FN4, RALT,BSLS,FN6, FN6, RCTL), + + + /* Layer 1: HHKB mode (HHKB Fn) + * ,-----------------------------------------------------------. + * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete | + * |-----------------------------------------------------------| + * |Caps | | | | | | | |Psc|Slk|Pus|Up | | | + * |-----------------------------------------------------' | + * |Contro|VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter | + * |-----------------------------------------------------------| + * |Shift | | | | | | +| -|End|PgD|Dow|Shift |xxx| + * |-----------------------------------------------------------| + * | |Gui |Alt | |Alt |Gui| | |Ctr| + * `-----------------------------------------------------------' + */ + KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, \ + CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,BRK, UP, NO, NO, \ + LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \ + LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,FN1, \ + NO, LGUI,LALT,SPC, RALT,NO, NO, NO, RCTL), + + + /* Layer 2: Vi mode (Quote/Rmeta) + * ,-----------------------------------------------------------. + * | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| ` | + * |-----------------------------------------------------------| + * | \ |Hom|PgD|Up |PgU|End|Hom|PgD|PgU|End| | | | | + * |-----------------------------------------------------' | + * |Contro| |Lef|Dow|Rig| |Lef|Dow|Up |Rig| | | \ | + * |-----------------------------------------------------------| + * |Shift | | | | | |Hom|PgD|PgU|End|xxx|Shift | | + * |-----------------------------------------------------------| + * | |Gui |Alt |Space |Alt |Gui|Fn6|Fn6|Ctr| + * `-----------------------------------------------------------' + */ + KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, GRV, \ + BSLS,HOME,PGDN,UP, PGUP,END, HOME,PGDN,PGUP,END, NO, NO, NO, NO, \ + LCTL,NO, LEFT,DOWN,RGHT,NO, LEFT,DOWN,UP, RGHT,NO, NO, BSLS, \ + LSFT,NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, FN2, RSFT,NO, \ + NO, LGUI,LALT,SPC, RALT,RGUI,FN6, FN6, RCTL), + + + /* Layer 3: Mouse mode (Semicolon) + * ,-----------------------------------------------------------. + * | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| ` | + * |-----------------------------------------------------------| + * | \ |MwL|MwD|McU|MwU|MwR|MwL|MwD|MwU|MwR| | | | | + * |-----------------------------------------------------' | + * |Contro| |McL|McD|McR| |McL|McD|McU|McR|xxx| | \ | + * |-----------------------------------------------------------| + * |Shift | | |Mb1|Mb2|Mb3|Mb2|Mb1| | | |Shift | | + * |-----------------------------------------------------------| + * |xxx|Gui |Alt |Mb1 |Alt | | | | | + * `-----------------------------------------------------------' + * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel + */ + KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, GRV, \ + BSLS,WH_L,WH_D,MS_U,WH_U,WH_R,WH_L,WH_D,WH_U,WH_R,NO, NO, NO, NO, \ + LCTL,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN3, NO, BSLS, \ + LSFT,NO, NO, BTN1,BTN2,BTN3,BTN2,BTN1,NO, NO, NO, RSFT,NO, \ + FN7, LGUI,LALT,BTN1,RALT,NO, FN6, FN6, NO), + + + /* Layer 4: Matias half keyboard style (Space) + * ,-----------------------------------------------------------. + * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete | + * |-----------------------------------------------------------| + * |Backs| P| O| I| U| Y| T| R| E| W| Q|Tab|Tab| | + * |-----------------------------------------------------' | + * |Contro| ;| L| K| J| H| G| F| D| S| A|Con|Control | + * |-----------------------------------------------------------| + * |Shift | /| .| ,| M| N| B| V| C| X| Z|Shift | | + * |-----------------------------------------------------------| + * | |Gui |Alt |xxxxxxxxxxxxxxxxxxxxxx|Alt |Gui| | |Ctr| + * `-----------------------------------------------------------' + */ + KEYMAP(MINS,0, 9, 8, 7, 6, 5, 4, 3, 2, 1, NO, NO, ESC, \ + BSPC,P, O, I, U, Y, T, R, E, W, Q, TAB, TAB, TAB, \ + LCTL,SCLN,L, K, J, H, G, F, D, S, A, RCTL,RCTL, \ + LSFT,SLSH,DOT, COMM,M, N, B, V, C, X, Z, RSFT,NO, \ + NO, LGUI,LALT,FN4, RALT,RGUI,NO, NO, RCTL), +}; + + +uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col) +{ + return KEYCODE(layer, row, col); +} + +uint8_t keymap_fn_layer(uint8_t fn_bits) +{ + return pgm_read_byte(&fn_layer[biton(fn_bits)]); +} + +uint8_t keymap_fn_keycode(uint8_t fn_bits) +{ + return pgm_read_byte(&fn_keycode[(biton(fn_bits))]); +} diff --git a/keyboard/lufa/led.c b/keyboard/lufa/led.c new file mode 100644 index 00000000..f76545f0 --- /dev/null +++ b/keyboard/lufa/led.c @@ -0,0 +1,24 @@ +/* +Copyright 2011 Jun Wako + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "stdint.h" +#include "led.h" + + +void led_set(uint8_t usb_led) +{ +} diff --git a/keyboard/lufa/lufa.c b/keyboard/lufa/lufa.c new file mode 100644 index 00000000..d7e7c165 --- /dev/null +++ b/keyboard/lufa/lufa.c @@ -0,0 +1,243 @@ +/* + * Copyright 2012 Jun Wako + * This file is based on LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse. + */ + +/* + 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 "report.h" +#include "host.h" +#include "host_driver.h" +#include "keyboard.h" +#include "lufa.h" + +static uint8_t keyboard_led_stats = 0; +report_keyboard_t keyboard_report_sent; +report_mouse_t mouse_report_sent; + +/* Host driver */ +static uint8_t keyboard_leds(void); +static void send_keyboard(report_keyboard_t *report); +static void send_mouse(report_mouse_t *report); +static void send_system(uint16_t data); +static void send_consumer(uint16_t data); +static host_driver_t lufa_driver = { + keyboard_leds, + send_keyboard, + send_mouse, + send_system, + send_consumer +}; + + +int main(void) +{ + SetupHardware(); + sei(); + + keyboard_init(); + host_set_driver(&lufa_driver); + while (1) { + keyboard_proc(); + Keyboard_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 */ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + /* Disable clock division */ + clock_prescale_set(clock_div_1); + + USB_Init(); +} + +/** Event handler for the USB_Connect event. */ +void EVENT_USB_Device_Connect(void) +{ +} + +/** Event handler for the USB_Disconnect event. */ +void EVENT_USB_Device_Disconnect(void) +{ +} + +/** Event handler for the USB_ConfigurationChanged event. + * This is fired when the host sets the current configuration of the USB device after enumeration. + */ +void EVENT_USB_Device_ConfigurationChanged(void) +{ + bool ConfigSuccess = true; + + /* 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); +} + +/** Event handler for the USB_ControlRequest event. + * This is fired before passing along unhandled control requests to the library for processing internally. + */ +void EVENT_USB_Device_ControlRequest(void) +{ + uint8_t* ReportData; + uint8_t ReportSize; + + /* Handle HID Class specific requests */ + switch (USB_ControlRequest.bRequest) + { + case HID_REQ_GetReport: + if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) + { + Endpoint_ClearSETUP(); + + /* Determine if it is the mouse or the keyboard data that is being requested */ + if (!(USB_ControlRequest.wIndex)) + { + ReportData = (uint8_t*)&keyboard_report_sent; + ReportSize = sizeof(keyboard_report_sent); + } + else + { + ReportData = (uint8_t*)&mouse_report_sent; + ReportSize = sizeof(mouse_report_sent); + } + + /* Write the report data to the control endpoint */ + Endpoint_Write_Control_Stream_LE(ReportData, ReportSize); + Endpoint_ClearOUT(); + } + + break; + case HID_REQ_SetReport: + if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) + { + Endpoint_ClearSETUP(); + + /* Wait until the LED report has been sent by the host */ + while (!(Endpoint_IsOUTReceived())) + { + if (USB_DeviceState == DEVICE_STATE_Unattached) + return; + } + + /* Read in the LED report from the host */ + keyboard_led_stats = Endpoint_Read_8(); + + Endpoint_ClearOUT(); + Endpoint_ClearStatusStage(); + } + + break; + } +} + +/** Keyboard task. + * This processes host LED status reports sent to the device via the keyboard OUT reporting endpoint. + */ +void Keyboard_HID_Task(void) +{ + /* 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(); + } +} + + +/******************************************************************************* + * Host driver + ******************************************************************************/ +static uint8_t keyboard_leds(void) +{ + return keyboard_led_stats; +} + +static void send_keyboard(report_keyboard_t *report) +{ + // TODO: handle NKRO report + /* Select the Keyboard Report Endpoint */ + Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM); + + /* Check if Keyboard Endpoint Ready for Read/Write */ + if (Endpoint_IsReadWriteAllowed()) + { + /* Write Keyboard Report Data */ + Endpoint_Write_Stream_LE(report, sizeof(report_keyboard_t), NULL); + + /* Finalize the stream transfer to send the last packet */ + Endpoint_ClearIN(); + } + keyboard_report_sent = *report; +} + +static void send_mouse(report_mouse_t *report) +{ + /* Select the Mouse Report Endpoint */ + Endpoint_SelectEndpoint(MOUSE_IN_EPNUM); + + /* Check if Mouse Endpoint Ready for Read/Write */ + if (Endpoint_IsReadWriteAllowed()) + { + /* Write Mouse Report Data */ + Endpoint_Write_Stream_LE(report, sizeof(report_mouse_t), NULL); + + /* Finalize the stream transfer to send the last packet */ + Endpoint_ClearIN(); + } + mouse_report_sent = *report; +} + +static void send_system(uint16_t data) +{ +} + +static void send_consumer(uint16_t data) +{ +} diff --git a/keyboard/lufa/lufa.h b/keyboard/lufa/lufa.h new file mode 100644 index 00000000..74fe0b72 --- /dev/null +++ b/keyboard/lufa/lufa.h @@ -0,0 +1,78 @@ +/* + 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 Mouse_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 + diff --git a/keyboard/lufa/matrix.c b/keyboard/lufa/matrix.c new file mode 100644 index 00000000..394c3d97 --- /dev/null +++ b/keyboard/lufa/matrix.c @@ -0,0 +1,271 @@ +/* +Copyright 2011 Jun Wako + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/* + * scan matrix + */ +#include +#include +#include +#include +#include "print.h" +#include "debug.h" +#include "util.h" +#include "matrix.h" + + +#if (MATRIX_COLS > 16) +# error "MATRIX_COLS must not exceed 16" +#endif +#if (MATRIX_ROWS > 255) +# error "MATRIX_ROWS must not exceed 255" +#endif + + +#ifndef DEBOUNCE +# define DEBOUNCE 0 +#endif +static uint8_t debouncing = DEBOUNCE; + +// matrix state buffer(1:on, 0:off) +#if (MATRIX_COLS <= 8) +static uint8_t *matrix; +static uint8_t *matrix_prev; +static uint8_t _matrix0[MATRIX_ROWS]; +static uint8_t _matrix1[MATRIX_ROWS]; +#else +static uint16_t *matrix; +static uint16_t *matrix_prev; +static uint16_t _matrix0[MATRIX_ROWS]; +static uint16_t _matrix1[MATRIX_ROWS]; +#endif + +#ifdef MATRIX_HAS_GHOST +static bool matrix_has_ghost_in_row(uint8_t row); +#endif +static uint8_t read_col(void); +static void unselect_rows(void); +static void select_row(uint8_t row); + + +inline +uint8_t matrix_rows(void) +{ + return MATRIX_ROWS; +} + +inline +uint8_t matrix_cols(void) +{ + return MATRIX_COLS; +} + +void matrix_init(void) +{ + // initialize row and col + unselect_rows(); + // Input with pull-up(DDR:0, PORT:1) + DDRB = 0x00; + PORTB = 0xFF; + + // initialize matrix state: all keys off + for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00; + for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00; + matrix = _matrix0; + matrix_prev = _matrix1; +} + +uint8_t matrix_scan(void) +{ + if (!debouncing) { + uint8_t *tmp = matrix_prev; + matrix_prev = matrix; + matrix = tmp; + } + + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + unselect_rows(); + select_row(i); + _delay_us(30); // without this wait read unstable value. + if (matrix[i] != (uint8_t)~read_col()) { + matrix[i] = (uint8_t)~read_col(); + if (debouncing) { + debug("bounce!: "); debug_hex(debouncing); print("\n"); + } + debouncing = DEBOUNCE; + } + } + unselect_rows(); + + if (debouncing) { + debouncing--; + } + + return 1; +} + +bool matrix_is_modified(void) +{ + if (debouncing) return false; + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + if (matrix[i] != matrix_prev[i]) { + return true; + } + } + return false; +} + +inline +bool matrix_has_ghost(void) +{ +#ifdef MATRIX_HAS_GHOST + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + if (matrix_has_ghost_in_row(i)) + return true; + } +#endif + return false; +} + +inline +bool matrix_is_on(uint8_t row, uint8_t col) +{ + return (matrix[row] & (1< Date: Wed, 27 Jun 2012 18:31:33 +0900 Subject: [PATCH 02/13] Add sendchar with Generic HID to support debug print. --- keyboard/lufa/Descriptors.c | 791 ++++++++++++++++++++---------------- keyboard/lufa/Descriptors.h | 71 ++-- keyboard/lufa/Makefile | 3 +- keyboard/lufa/lufa.c | 129 +++++- keyboard/lufa/lufa.h | 2 +- 5 files changed, 586 insertions(+), 410 deletions(-) diff --git a/keyboard/lufa/Descriptors.c b/keyboard/lufa/Descriptors.c index 3195aa77..a4e9defa 100644 --- a/keyboard/lufa/Descriptors.c +++ b/keyboard/lufa/Descriptors.c @@ -1,359 +1,432 @@ -/* - 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 class report descriptor. This is a special descriptor constructed with values from the - * USBIF HID class specification to describe the reports and capabilities of the HID device. This - * descriptor is parsed by the host and its contents used to determine what data (and in what encoding) - * the device will send, and what it may be sent back from the host. Refer to the HID specification for - * more details on HID report descriptors. - * - * This descriptor describes the mouse HID interface's report structure. - */ -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), -}; - -/** Same as the MouseReport structure, but defines the keyboard HID interface's report structure. */ -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), -}; - -/** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall - * device characteristics, including the supported USB version, control endpoint size and the - * number of device configurations. The descriptor is read out by the USB host when the enumeration - * process begins. - */ -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 = 0x03EB, - .ProductID = 0x204D, - .ReleaseNumber = VERSION_BCD(00.01), - - .ManufacturerStrIndex = 0x01, - .ProductStrIndex = 0x02, - .SerialNumStrIndex = NO_DESCRIPTOR, - - .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS -}; - -/** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage - * of the device in one of its supported configurations, including information about any device interfaces - * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting - * a configuration so that the host may correctly communicate with the USB device. - */ -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 = 2, - - .ConfigurationNumber = 1, - .ConfigurationStrIndex = NO_DESCRIPTOR, - - .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), - - .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) - }, - - .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 - }, - - .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 - } -}; - -/** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests - * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate - * via the language ID table available at USB.org what languages the device supports for its string descriptors. - */ -const USB_Descriptor_String_t PROGMEM LanguageString = -{ - .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String}, - - .UnicodeString = {LANGUAGE_ID_ENG} -}; - -/** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable - * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device - * Descriptor. - */ -const USB_Descriptor_String_t PROGMEM ManufacturerString = -{ - .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, - - .UnicodeString = L"Dean Camera" -}; - -/** Product descriptor string. This is a Unicode string containing the product's details in human readable form, - * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device - * Descriptor. - */ -const USB_Descriptor_String_t PROGMEM ProductString = -{ - .Header = {.Size = USB_STRING_LEN(28), .Type = DTYPE_String}, - - .UnicodeString = L"LUFA Mouse and Keyboard Demo" -}; - -/** 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 DescriptorNumber = (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 (DescriptorNumber) - { - 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: - if (!(wIndex)) - { - Address = &ConfigurationDescriptor.HID1_KeyboardHID; - Size = sizeof(USB_HID_Descriptor_HID_t); - } - else - { - Address = &ConfigurationDescriptor.HID2_MouseHID; - Size = sizeof(USB_HID_Descriptor_HID_t); - } - break; - case HID_DTYPE_Report: - if (!(wIndex)) - { - Address = &KeyboardReport; - Size = sizeof(KeyboardReport); - } - else - { - Address = &MouseReport; - Size = sizeof(MouseReport); - } - - break; - } - - *DescriptorAddress = Address; - return Size; -} - +/* + * 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 index 05b2035b..03e2426a 100644 --- a/keyboard/lufa/Descriptors.h +++ b/keyboard/lufa/Descriptors.h @@ -37,51 +37,48 @@ #ifndef _DESCRIPTORS_H_ #define _DESCRIPTORS_H_ - /* Includes: */ - #include +#include +#include - #include - /* Type Defines: */ - /** Type define for the device configuration descriptor structure. This must be defined in the - * application code, as the configuration descriptor contains several sub-descriptors which - * vary between devices, and which describe the device's usage to the host. - */ - typedef struct - { - USB_Descriptor_Configuration_Header_t Config; +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; + // 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; - USB_Descriptor_Endpoint_t HID2_ReportOUTEndpoint; - } USB_Descriptor_Configuration_t; + // Mouse HID Interface + USB_Descriptor_Interface_t HID2_MouseInterface; + USB_HID_Descriptor_HID_t HID2_MouseHID; + USB_Descriptor_Endpoint_t HID2_ReportINEndpoint; - /* Macros: */ - /** Endpoint number of the Keyboard HID reporting IN endpoint. */ - #define KEYBOARD_IN_EPNUM 1 + // 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; - /** Endpoint number of the Keyboard HID reporting OUT endpoint. */ - #define KEYBOARD_OUT_EPNUM 2 - /** Endpoint number of the Mouse HID reporting IN endpoint. */ - #define MOUSE_IN_EPNUM 3 +// 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 - /** Size in bytes of each of the HID reporting IN and OUT endpoints. */ - #define HID_EPSIZE 8 +#define HID_EPSIZE 8 +#define GENERIC_EPSIZE 8 +#define GENERIC_REPORT_SIZE 8 - /* Function Prototypes: */ - 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); + +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 1d2f712d..115c7e6e 100644 --- a/keyboard/lufa/Makefile +++ b/keyboard/lufa/Makefile @@ -128,8 +128,7 @@ LSRC = $(TARGET).c \ SRC = $(subst $(LUFA_PATH)/LUFA/,,$(LSRC)) SRC += keymap.c \ matrix.c \ - led.c \ - sendchar_null.c + led.c CONFIG_H = config.h diff --git a/keyboard/lufa/lufa.c b/keyboard/lufa/lufa.c index d7e7c165..d841f45c 100644 --- a/keyboard/lufa/lufa.c +++ b/keyboard/lufa/lufa.c @@ -1,6 +1,8 @@ /* * Copyright 2012 Jun Wako - * This file is based on LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse. + * This file is based on: + * LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse + * LUFA-120219/Demos/Device/Lowlevel/GenericHID */ /* @@ -38,6 +40,8 @@ #include "host.h" #include "host_driver.h" #include "keyboard.h" +#include "sendchar.h" +#include "debug.h" #include "lufa.h" static uint8_t keyboard_led_stats = 0; @@ -64,11 +68,21 @@ int main(void) SetupHardware(); sei(); + print_enable = true; + debug_enable = true; + debug_matrix = true; + debug_keyboard = true; + debug_mouse = true; + + _delay_ms(3000); + print("abcdefg\n"); + keyboard_init(); host_set_driver(&lufa_driver); while (1) { keyboard_proc(); Keyboard_HID_Task(); + Generic_HID_Task(); USB_USBTask(); } } @@ -112,6 +126,12 @@ void EVENT_USB_Device_ConfigurationChanged(void) /* 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); } /** Event handler for the USB_ControlRequest event. @@ -119,8 +139,8 @@ void EVENT_USB_Device_ConfigurationChanged(void) */ void EVENT_USB_Device_ControlRequest(void) { - uint8_t* ReportData; - uint8_t ReportSize; + uint8_t* ReportData = NULL; + uint8_t ReportSize = 0; /* Handle HID Class specific requests */ switch (USB_ControlRequest.bRequest) @@ -130,16 +150,18 @@ void EVENT_USB_Device_ControlRequest(void) { Endpoint_ClearSETUP(); - /* Determine if it is the mouse or the keyboard data that is being requested */ - if (!(USB_ControlRequest.wIndex)) - { + // Interface + switch (USB_ControlRequest.wIndex) { + case 1: // Keyboard ReportData = (uint8_t*)&keyboard_report_sent; ReportSize = sizeof(keyboard_report_sent); - } - else - { + break; + case 2: // Mouse ReportData = (uint8_t*)&mouse_report_sent; ReportSize = sizeof(mouse_report_sent); + break; + case 3: // Generic + break; } /* Write the report data to the control endpoint */ @@ -160,8 +182,17 @@ void EVENT_USB_Device_ControlRequest(void) return; } - /* Read in the LED report from the host */ - keyboard_led_stats = Endpoint_Read_8(); + // Interface + switch (USB_ControlRequest.wIndex) { + case 1: // Keyboard + /* Read in the LED report from the host */ + keyboard_led_stats = Endpoint_Read_8(); + break; + case 2: // Mouse + break; + case 3: // Generic + break; + } Endpoint_ClearOUT(); Endpoint_ClearStatusStage(); @@ -176,6 +207,10 @@ void EVENT_USB_Device_ControlRequest(void) */ 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); @@ -190,6 +225,40 @@ void Keyboard_HID_Task(void) } } +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 @@ -241,3 +310,41 @@ static void send_system(uint16_t data) static void send_consumer(uint16_t data) { } + + +/******************************************************************************* + * sendchar + ******************************************************************************/ +int8_t sendchar(uint8_t c) +{ + if (USB_DeviceState != DEVICE_STATE_Configured) + return -1; + + Endpoint_SelectEndpoint(GENERIC_IN_EPNUM); + + uint8_t timeout = 10; + uint16_t prevFN = USB_Device_GetFrameNumber(); + while (!Endpoint_IsINReady()) { + switch (USB_DeviceState) { + case DEVICE_STATE_Unattached: + case DEVICE_STATE_Suspended: + return -1; + } + if (Endpoint_IsStalled()) + return -1; + uint16_t currFN = USB_Device_GetFrameNumber(); + if (prevFN != USB_Device_GetFrameNumber()) { + if (!(timeout--)) + return -1; + prevFN = USB_Device_GetFrameNumber(); + } + } + + Endpoint_Write_8(c); + + // send when packet is full + if (!Endpoint_IsReadWriteAllowed()) + Endpoint_ClearIN(); + + return 0; +} diff --git a/keyboard/lufa/lufa.h b/keyboard/lufa/lufa.h index 74fe0b72..3ba14b36 100644 --- a/keyboard/lufa/lufa.h +++ b/keyboard/lufa/lufa.h @@ -65,7 +65,7 @@ void SetupHardware(void); void Keyboard_ProcessLEDReport(const uint8_t LEDStatus); void Keyboard_HID_Task(void); - void Mouse_HID_Task(void); + void Generic_HID_Task(void); void EVENT_USB_Device_Connect(void); void EVENT_USB_Device_Disconnect(void); From effa5914bff71fa7ad6506271c9ba4baa32a1eca Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 28 Jun 2012 12:59:17 +0900 Subject: [PATCH 03/13] 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/Makefile | 320 +++++++++--------- keyboard/lufa/config.h | 6 + keyboard/lufa/{Descriptors.c => descriptor.c} | 78 ++--- keyboard/lufa/{Descriptors.h => descriptor.h} | 170 +++++----- keyboard/lufa/lufa.c | 146 ++++---- keyboard/lufa/lufa.h | 123 +++---- 6 files changed, 397 insertions(+), 446 deletions(-) rename keyboard/lufa/{Descriptors.c => descriptor.c} (89%) rename keyboard/lufa/{Descriptors.h => descriptor.h} (68%) diff --git a/keyboard/lufa/Makefile b/keyboard/lufa/Makefile index 115c7e6e..12af013f 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 4662e3dd..c375a576 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/Descriptors.c b/keyboard/lufa/descriptor.c similarity index 89% rename from keyboard/lufa/Descriptors.c rename to keyboard/lufa/descriptor.c index a4e9defa..6059fd4a 100644 --- a/keyboard/lufa/Descriptors.c +++ b/keyboard/lufa/descriptor.c @@ -36,14 +36,8 @@ 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" +#include "util.h" +#include "descriptor.h" /******************************************************************************* @@ -152,9 +146,9 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, - .VendorID = 0xFEED, - .ProductID = 0x204D, - .ReleaseNumber = VERSION_BCD(00.02), + .VendorID = VENDOR_ID, + .ProductID = PRODUCT_ID, + .ReleaseNumber = DEVICE_VER, .ManufacturerStrIndex = 0x01, .ProductStrIndex = 0x02, @@ -178,7 +172,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .ConfigurationNumber = 1, .ConfigurationStrIndex = NO_DESCRIPTOR, - .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), //TODO: bus powered? + .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_REMOTEWAKEUP), .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) }, @@ -186,14 +180,14 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = /* * Keyboard */ - .HID1_KeyboardInterface = + .HID0_KeyboardInterface = { .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, - .InterfaceNumber = 0x00, + .InterfaceNumber = KEYBOARD_INTERFACE, .AlternateSetting = 0x00, - .TotalEndpoints = 2, + .TotalEndpoints = 1, .Class = HID_CSCP_HIDClass, .SubClass = HID_CSCP_BootSubclass, @@ -202,7 +196,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .InterfaceStrIndex = NO_DESCRIPTOR }, - .HID1_KeyboardHID = + .HID0_KeyboardHID = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, @@ -213,7 +207,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .HIDReportLength = sizeof(KeyboardReport) }, - .HID1_ReportINEndpoint = + .HID0_ReportINEndpoint = { .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, @@ -223,24 +217,14 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .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 = + .HID1_MouseInterface = { .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, - .InterfaceNumber = 0x01, + .InterfaceNumber = MOUSE_INTERFACE, .AlternateSetting = 0x00, .TotalEndpoints = 1, @@ -252,7 +236,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .InterfaceStrIndex = NO_DESCRIPTOR }, - .HID2_MouseHID = + .HID1_MouseHID = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, @@ -263,7 +247,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .HIDReportLength = sizeof(MouseReport) }, - .HID2_ReportINEndpoint = + .HID1_ReportINEndpoint = { .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, @@ -276,11 +260,11 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = /* * Generic */ - .HID3_GenericInterface = + .HID2_GenericInterface = { .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, - .InterfaceNumber = 0x02, + .InterfaceNumber = GENERIC_INTERFACE, .AlternateSetting = 0x00, .TotalEndpoints = 2, @@ -292,7 +276,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .InterfaceStrIndex = NO_DESCRIPTOR }, - .HID3_GenericHID = + .HID2_GenericHID = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, @@ -303,7 +287,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .HIDReportLength = sizeof(GenericReport) }, - .HID3_ReportINEndpoint = + .HID2_ReportINEndpoint = { .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, @@ -313,7 +297,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .PollingIntervalMS = 0x01 }, - .HID3_ReportOUTEndpoint = + .HID2_ReportOUTEndpoint = { .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, @@ -339,14 +323,14 @@ const USB_Descriptor_String_t PROGMEM ManufacturerString = { .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, - .UnicodeString = L"Dean Camera" // TODO: + .UnicodeString = LSTR(MANUFACTURER) }; const USB_Descriptor_String_t PROGMEM ProductString = { .Header = {.Size = USB_STRING_LEN(28), .Type = DTYPE_String}, - .UnicodeString = L"LUFA Mouse and Keyboard Demo" // TODO: + .UnicodeString = LSTR(PRODUCT) }; @@ -395,31 +379,31 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, break; case HID_DTYPE_HID: switch (wIndex) { - case 0: - Address = &ConfigurationDescriptor.HID1_KeyboardHID; + case KEYBOARD_INTERFACE: + Address = &ConfigurationDescriptor.HID0_KeyboardHID; Size = sizeof(USB_HID_Descriptor_HID_t); break; - case 1: - Address = &ConfigurationDescriptor.HID2_MouseHID; + case MOUSE_INTERFACE: + Address = &ConfigurationDescriptor.HID1_MouseHID; Size = sizeof(USB_HID_Descriptor_HID_t); break; - case 2: - Address = &ConfigurationDescriptor.HID3_GenericHID; + case GENERIC_INTERFACE: + Address = &ConfigurationDescriptor.HID2_GenericHID; Size = sizeof(USB_HID_Descriptor_HID_t); break; } break; case HID_DTYPE_Report: switch (wIndex) { - case 0: + case KEYBOARD_INTERFACE: Address = &KeyboardReport; Size = sizeof(KeyboardReport); break; - case 1: + case MOUSE_INTERFACE: Address = &MouseReport; Size = sizeof(MouseReport); break; - case 2: + case GENERIC_INTERFACE: Address = &GenericReport; Size = sizeof(GenericReport); break; diff --git a/keyboard/lufa/Descriptors.h b/keyboard/lufa/descriptor.h similarity index 68% rename from keyboard/lufa/Descriptors.h rename to keyboard/lufa/descriptor.h index 03e2426a..19e24c20 100644 --- a/keyboard/lufa/Descriptors.h +++ b/keyboard/lufa/descriptor.h @@ -1,84 +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 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 +/* + 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 d841f45c..569960e2 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 3ba14b36..efb8c383 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 From a9a3610dd4a168e473d2d6a2eb3fbc37aabb46c9 Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 28 Jun 2012 16:51:56 +0900 Subject: [PATCH 04/13] Add LUFA mouse feature and fix mouse report. - add LUFA boot mouse feature - remove report_id from mouse report - fix LUFA descriptor --- common/report.h | 5 ++--- keyboard/lufa/Makefile | 8 ++++++++ keyboard/lufa/descriptor.c | 36 ++++++++++++++++++------------------ keyboard/lufa/descriptor.h | 22 +++++++++++----------- keyboard/lufa/lufa.c | 38 ++++++++++++++++++++++++++++---------- protocol/vusb/main.c | 16 +++++++++++++--- protocol/vusb/vusb.c | 31 ++++++++++++++++++++++++++++--- 7 files changed, 108 insertions(+), 48 deletions(-) diff --git a/common/report.h b/common/report.h index b85b86c5..45f5c0b8 100644 --- a/common/report.h +++ b/common/report.h @@ -82,15 +82,14 @@ typedef struct { uint8_t mods; uint8_t rserved; uint8_t keys[REPORT_KEYS]; -} report_keyboard_t; +} __attribute__ ((packed)) report_keyboard_t; typedef struct { - uint8_t report_id; uint8_t buttons; int8_t x; int8_t y; int8_t v; int8_t h; -} report_mouse_t; +} __attribute__ ((packed)) report_mouse_t; #endif diff --git a/keyboard/lufa/Makefile b/keyboard/lufa/Makefile index 12af013f..b386fb38 100644 --- a/keyboard/lufa/Makefile +++ b/keyboard/lufa/Makefile @@ -132,6 +132,14 @@ SRC += keymap.c \ CONFIG_H = config.h +# Build Options +# comment out to disable the options. +# +MOUSEKEY_ENABLE = yes # Mouse keys +#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +#EXTRAKEY_ENABLE = yes # Audio control and System control +#NKRO_ENABLE = yes # USB Nkey Rollover + # LUFA library compile-time options and predefined tokens LUFA_OPTS = -D USB_DEVICE_ONLY diff --git a/keyboard/lufa/descriptor.c b/keyboard/lufa/descriptor.c index 6059fd4a..f9ca355a 100644 --- a/keyboard/lufa/descriptor.c +++ b/keyboard/lufa/descriptor.c @@ -111,7 +111,7 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] = HID_RI_END_COLLECTION(0), }; -const USB_Descriptor_HIDReport_Datatype_t PROGMEM GenericReport[] = +const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = { HID_RI_USAGE_PAGE(16, 0xFF00), /* Vendor Page 0 */ HID_RI_USAGE(8, 0x01), /* Vendor Usage 1 */ @@ -180,7 +180,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = /* * Keyboard */ - .HID0_KeyboardInterface = + .Keyboard_Interface = { .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, @@ -196,7 +196,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .InterfaceStrIndex = NO_DESCRIPTOR }, - .HID0_KeyboardHID = + .Keyboard_HID = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, @@ -207,7 +207,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .HIDReportLength = sizeof(KeyboardReport) }, - .HID0_ReportINEndpoint = + .Keyboard_INEndpoint = { .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, @@ -220,7 +220,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = /* * Mouse */ - .HID1_MouseInterface = + .Mouse_Interface = { .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, @@ -236,7 +236,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .InterfaceStrIndex = NO_DESCRIPTOR }, - .HID1_MouseHID = + .Mouse_HID = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, @@ -247,7 +247,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .HIDReportLength = sizeof(MouseReport) }, - .HID1_ReportINEndpoint = + .Mouse_INEndpoint = { .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, @@ -258,9 +258,9 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = }, /* - * Generic + * Console */ - .HID2_GenericInterface = + .Console_Interface = { .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, @@ -276,7 +276,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .InterfaceStrIndex = NO_DESCRIPTOR }, - .HID2_GenericHID = + .Console_HID = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, @@ -284,10 +284,10 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, - .HIDReportLength = sizeof(GenericReport) + .HIDReportLength = sizeof(ConsoleReport) }, - .HID2_ReportINEndpoint = + .Console_INEndpoint = { .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, @@ -297,7 +297,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .PollingIntervalMS = 0x01 }, - .HID2_ReportOUTEndpoint = + .Console_OUTEndpoint = { .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, @@ -380,15 +380,15 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, case HID_DTYPE_HID: switch (wIndex) { case KEYBOARD_INTERFACE: - Address = &ConfigurationDescriptor.HID0_KeyboardHID; + Address = &ConfigurationDescriptor.Keyboard_HID; Size = sizeof(USB_HID_Descriptor_HID_t); break; case MOUSE_INTERFACE: - Address = &ConfigurationDescriptor.HID1_MouseHID; + Address = &ConfigurationDescriptor.Mouse_HID; Size = sizeof(USB_HID_Descriptor_HID_t); break; case GENERIC_INTERFACE: - Address = &ConfigurationDescriptor.HID2_GenericHID; + Address = &ConfigurationDescriptor.Console_HID; Size = sizeof(USB_HID_Descriptor_HID_t); break; } @@ -404,8 +404,8 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, Size = sizeof(MouseReport); break; case GENERIC_INTERFACE: - Address = &GenericReport; - Size = sizeof(GenericReport); + Address = &ConsoleReport; + Size = sizeof(ConsoleReport); break; } break; diff --git a/keyboard/lufa/descriptor.h b/keyboard/lufa/descriptor.h index 19e24c20..d45e905c 100644 --- a/keyboard/lufa/descriptor.h +++ b/keyboard/lufa/descriptor.h @@ -46,20 +46,20 @@ 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; + USB_Descriptor_Interface_t Keyboard_Interface; + USB_HID_Descriptor_HID_t Keyboard_HID; + USB_Descriptor_Endpoint_t Keyboard_INEndpoint; // Mouse HID Interface - USB_Descriptor_Interface_t HID1_MouseInterface; - USB_HID_Descriptor_HID_t HID1_MouseHID; - USB_Descriptor_Endpoint_t HID1_ReportINEndpoint; + USB_Descriptor_Interface_t Mouse_Interface; + USB_HID_Descriptor_HID_t Mouse_HID; + USB_Descriptor_Endpoint_t Mouse_INEndpoint; - // 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; + // Console HID Interface + USB_Descriptor_Interface_t Console_Interface; + USB_HID_Descriptor_HID_t Console_HID; + USB_Descriptor_Endpoint_t Console_INEndpoint; + USB_Descriptor_Endpoint_t Console_OUTEndpoint; } USB_Descriptor_Configuration_t; diff --git a/keyboard/lufa/lufa.c b/keyboard/lufa/lufa.c index 569960e2..a87d8474 100644 --- a/keyboard/lufa/lufa.c +++ b/keyboard/lufa/lufa.c @@ -68,7 +68,7 @@ static host_driver_t lufa_driver = { static void SetupHardware(void); -static void Generic_HID_Task(void); +static void Console_HID_Task(void); int main(void) { @@ -93,7 +93,7 @@ int main(void) while (1) { keyboard_proc(); - Generic_HID_Task(); + Console_HID_Task(); USB_USBTask(); } } @@ -110,7 +110,7 @@ void SetupHardware(void) USB_Init(); } -static void Generic_HID_Task(void) +static void Console_HID_Task(void) { /* Device must be connected and configured for the task to run */ if (USB_DeviceState != DEVICE_STATE_Configured) @@ -126,13 +126,13 @@ static void Generic_HID_Task(void) if (Endpoint_IsReadWriteAllowed()) { /* Create a temporary buffer to hold the read in report from the host */ - uint8_t GenericData[GENERIC_REPORT_SIZE]; + uint8_t ConsoleData[GENERIC_REPORT_SIZE]; - /* Read Generic Report Data */ - Endpoint_Read_Stream_LE(&GenericData, sizeof(GenericData), NULL); + /* Read Console Report Data */ + Endpoint_Read_Stream_LE(&ConsoleData, sizeof(ConsoleData), NULL); - /* Process Generic Report Data */ - //ProcessGenericHIDReport(GenericData); + /* Process Console Report Data */ + //ProcessConsoleHIDReport(ConsoleData); } /* Finalize the stream transfer to send the last packet */ @@ -175,13 +175,26 @@ void EVENT_USB_Device_ConfigurationChanged(void) ConfigSuccess &= Endpoint_ConfigureEndpoint(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, HID_EPSIZE, ENDPOINT_BANK_SINGLE); - /* Setup Generic HID Report Endpoints */ + /* Setup Console 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); } +/* +Appendix G: HID Request Support Requirements + +The following table enumerates the requests that need to be supported by various types of HID class devices. + +Device type GetReport SetReport GetIdle SetIdle GetProtocol SetProtocol +------------------------------------------------------------------------------------------ +Boot Mouse Required Optional Optional Optional Required Required +Non-Boot Mouse Required Optional Optional Optional Optional Optional +Boot Keyboard Required Optional Required Required Required Required +Non-Boot Keybrd Required Optional Required Required Optional Optional +Other Device Required Optional Optional Optional Optional Optional +*/ /** Event handler for the USB_ControlRequest event. * This is fired before passing along unhandled control requests to the library for processing internally. */ @@ -288,7 +301,12 @@ static void send_mouse(report_mouse_t *report) if (Endpoint_IsReadWriteAllowed()) { /* Write Mouse Report Data */ - Endpoint_Write_Stream_LE(report, sizeof(report_mouse_t), NULL); + /* Mouse report data structure + * LUFA: { buttons, x, y } + * tmk: { buttons, x, y, v, h } + */ + //Endpoint_Write_Stream_LE((uint8_t *)report+1, 3, NULL); + Endpoint_Write_Stream_LE(report, 3, NULL); /* Finalize the stream transfer to send the last packet */ Endpoint_ClearIN(); diff --git a/protocol/vusb/main.c b/protocol/vusb/main.c index 1bf9035b..1ba40a27 100644 --- a/protocol/vusb/main.c +++ b/protocol/vusb/main.c @@ -62,6 +62,11 @@ int main(void) debug("initForUsbConnectivity()\n"); initForUsbConnectivity(); + int i; + while(--i){ /* To configured */ + usbPoll(); + _delay_ms(1); + } debug("main loop\n"); while (1) { @@ -90,10 +95,15 @@ int main(void) } } #endif - if (!suspended) + if (!suspended) { usbPoll(); - keyboard_proc(); - if (!suspended) + + // TODO: configuration process is incosistent. it sometime fails. + // To prevent failing to configure NOT scan keyboard during configuration + if (usbConfiguration && usbInterruptIsReady()) { + keyboard_proc(); + } vusb_transfer_keyboard(); + } } } diff --git a/protocol/vusb/vusb.c b/protocol/vusb/vusb.c index 0bfe21e9..1dff5dea 100644 --- a/protocol/vusb/vusb.c +++ b/protocol/vusb/vusb.c @@ -91,23 +91,48 @@ static void send_keyboard(report_keyboard_t *report) } +typedef struct { + uint8_t report_id; + report_mouse_t report; +} __attribute__ ((packed)) vusb_mouse_report_t; + static void send_mouse(report_mouse_t *report) { - report->report_id = REPORT_ID_MOUSE; + vusb_mouse_report_t r = { + .report_id = REPORT_ID_MOUSE, + .report = *report + }; if (usbInterruptIsReady3()) { - usbSetInterrupt3((void *)report, sizeof(*report)); + usbSetInterrupt3((void *)&r, sizeof(vusb_mouse_report_t)); } } +/* +typedef struct { + uint8_t report_id; + uint8_t data0; + uint8_t data1; +} __attribute__ ((packed)) vusb_system_report_t; +*/ + static void send_system(uint16_t data) { +/* // Not need static? static uint8_t report[] = { REPORT_ID_SYSTEM, 0, 0 }; report[1] = data&0xFF; report[2] = (data>>8)&0xFF; +*/ +/* + vusb_system_report_t r = { + .report_id = REPORT_ID_SYSTEM, + .data0 = data&0xFF, + .data1 = (data>>8)&0xFF + }; if (usbInterruptIsReady3()) { - usbSetInterrupt3((void *)&report, sizeof(report)); + usbSetInterrupt3((void *)&r, sizeof(vusb_system_report_t)); } +*/ } static void send_consumer(uint16_t data) From 3d81d5221eac9ca9620ba9043a250dcb8371b22e Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 28 Jun 2012 20:15:56 +0900 Subject: [PATCH 05/13] Add consumer/system control feature to LUFA. --- common/keyboard.c | 17 ++--- common/mousekey.c | 4 +- keyboard/lufa/Makefile | 5 +- keyboard/lufa/config.h | 4 +- keyboard/lufa/descriptor.c | 143 ++++++++++++++++++++++++++++++------- keyboard/lufa/descriptor.h | 26 +++++-- keyboard/lufa/keymap.c | 2 +- keyboard/lufa/lufa.c | 62 +++++++++++----- protocol/vusb/main.c | 5 -- protocol/vusb/vusb.c | 37 ++++------ 10 files changed, 209 insertions(+), 96 deletions(-) diff --git a/common/keyboard.c b/common/keyboard.c index 5c2643c9..25f32eb0 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -49,6 +49,7 @@ void keyboard_proc(void) uint8_t fn_bits = 0; #ifdef EXTRAKEY_ENABLE uint16_t consumer_code = 0; + uint16_t system_code = 0; #endif matrix_scan(); @@ -89,22 +90,13 @@ void keyboard_proc(void) #ifdef HOST_PJRC if (suspend && remote_wakeup) { usb_remote_wakeup(); - } else { - host_system_send(SYSTEM_POWER_DOWN); } -#else - host_system_send(SYSTEM_POWER_DOWN); #endif - host_system_send(0); - _delay_ms(500); + system_code = SYSTEM_POWER_DOWN; } else if (code == KB_SYSTEM_SLEEP) { - host_system_send(SYSTEM_SLEEP); - host_system_send(0); - _delay_ms(500); + system_code = SYSTEM_SLEEP; } else if (code == KB_SYSTEM_WAKE) { - host_system_send(SYSTEM_WAKE_UP); - host_system_send(0); - _delay_ms(500); + system_code = SYSTEM_WAKE_UP; } // Consumer Page else if (code == KB_AUDIO_MUTE) { @@ -173,6 +165,7 @@ void keyboard_proc(void) host_send_keyboard_report(); #ifdef EXTRAKEY_ENABLE host_consumer_send(consumer_code); + host_system_send(system_code); #endif #ifdef DEBUG_LED // LED flash for debug diff --git a/common/mousekey.c b/common/mousekey.c index 76bd0fd3..1d35355b 100644 --- a/common/mousekey.c +++ b/common/mousekey.c @@ -121,12 +121,12 @@ void mousekey_clear_report(void) static void mousekey_debug(void) { if (!debug_mouse) return; - print("mousekey[btn|x y v h]: "); + print("mousekey [btn|x y v h]rep: ["); phex(report.buttons); print("|"); phex(report.x); print(" "); phex(report.y); print(" "); phex(report.v); print(" "); - phex(report.h); + phex(report.h); print("]"); phex(mousekey_repeat); print("\n"); } diff --git a/keyboard/lufa/Makefile b/keyboard/lufa/Makefile index b386fb38..030f4061 100644 --- a/keyboard/lufa/Makefile +++ b/keyboard/lufa/Makefile @@ -128,7 +128,8 @@ LUFA_SRC = $(TARGET).c \ SRC = $(subst $(LUFA_PATH)/LUFA/,,$(LUFA_SRC)) SRC += keymap.c \ matrix.c \ - led.c + led.c \ + pjrc/bootloader_teensy.c CONFIG_H = config.h @@ -137,7 +138,7 @@ CONFIG_H = config.h # MOUSEKEY_ENABLE = yes # Mouse keys #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support -#EXTRAKEY_ENABLE = yes # Audio control and System control +EXTRAKEY_ENABLE = yes # Audio control and System control #NKRO_ENABLE = yes # USB Nkey Rollover diff --git a/keyboard/lufa/config.h b/keyboard/lufa/config.h index c375a576..5368b38d 100644 --- a/keyboard/lufa/config.h +++ b/keyboard/lufa/config.h @@ -24,8 +24,8 @@ along with this program. If not, see . /* USB Device descriptor */ #define VENDOR_ID 0xFEED -#define PRODUCT_ID 0xBEE1 -#define DEVICE_VER 0x0101 +#define PRODUCT_ID 0xBEE6 +#define DEVICE_VER 0x0202 #define MANUFACTURER t.m.k. #define PRODUCT Macway mod(LUFA) diff --git a/keyboard/lufa/descriptor.c b/keyboard/lufa/descriptor.c index f9ca355a..e9925cca 100644 --- a/keyboard/lufa/descriptor.c +++ b/keyboard/lufa/descriptor.c @@ -37,6 +37,7 @@ */ #include "util.h" +#include "report.h" #include "descriptor.h" @@ -86,27 +87,43 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] = 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_USAGE_MINIMUM(8, 0x01), /* Button 1 */ + HID_RI_USAGE_MAXIMUM(8, 0x05), /* Button 5 */ HID_RI_LOGICAL_MINIMUM(8, 0x00), HID_RI_LOGICAL_MAXIMUM(8, 0x01), - HID_RI_REPORT_COUNT(8, 0x03), + HID_RI_REPORT_COUNT(8, 0x05), 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_REPORT_SIZE(8, 0x03), 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_LOGICAL_MINIMUM(8, -127), + HID_RI_LOGICAL_MAXIMUM(8, 127), 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_USAGE(8, 0x38), /* Wheel */ + HID_RI_LOGICAL_MINIMUM(8, -127), + HID_RI_LOGICAL_MAXIMUM(8, 127), + HID_RI_REPORT_COUNT(8, 0x01), + HID_RI_REPORT_SIZE(8, 0x08), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), + + HID_RI_USAGE_PAGE(8, 0x0C), /* Consumer */ + HID_RI_USAGE(16, 0x0238), /* AC Pan (Horizontal wheel) */ + HID_RI_LOGICAL_MINIMUM(8, -127), + HID_RI_LOGICAL_MAXIMUM(8, 127), + HID_RI_REPORT_COUNT(8, 0x01), + 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), }; @@ -115,22 +132,50 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = { 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_COLLECTION(8, 0x01), /* Application */ 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_REPORT_COUNT(8, CONSOLE_EPSIZE), 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_REPORT_COUNT(8, CONSOLE_EPSIZE), HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), HID_RI_END_COLLECTION(0), }; +const USB_Descriptor_HIDReport_Datatype_t PROGMEM ExtraReport[] = +{ + HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ + HID_RI_USAGE(8, 0x80), /* System Control */ + HID_RI_COLLECTION(8, 0x01), /* Application */ + HID_RI_REPORT_ID(8, REPORT_ID_SYSTEM), + HID_RI_LOGICAL_MINIMUM(16, 0x0081), + HID_RI_LOGICAL_MAXIMUM(16, 0x00B7), + HID_RI_USAGE_MINIMUM(16, 0x0081), /* System Power Down */ + HID_RI_USAGE_MAXIMUM(16, 0x00B7), /* System Display LCD Autoscale */ + HID_RI_REPORT_SIZE(8, 16), + HID_RI_REPORT_COUNT(8, 1), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE), + HID_RI_END_COLLECTION(0), + + HID_RI_USAGE_PAGE(8, 0x0C), /* Consumer */ + HID_RI_USAGE(8, 0x01), /* Consumer Control */ + HID_RI_COLLECTION(8, 0x01), /* Application */ + HID_RI_REPORT_ID(8, REPORT_ID_CONSUMER), + HID_RI_LOGICAL_MINIMUM(16, 0x0010), + HID_RI_LOGICAL_MAXIMUM(16, 0x029C), + HID_RI_USAGE_MINIMUM(16, 0x0010), /* +10 */ + HID_RI_USAGE_MAXIMUM(16, 0x029C), /* AC Distribute Vertically */ + HID_RI_REPORT_SIZE(8, 16), + HID_RI_REPORT_COUNT(8, 1), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE), + HID_RI_END_COLLECTION(0), +}; /******************************************************************************* * Device Descriptors @@ -167,7 +212,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), - .TotalInterfaces = 3, + .TotalInterfaces = TOTAL_INTERFACES, .ConfigurationNumber = 1, .ConfigurationStrIndex = NO_DESCRIPTOR, @@ -177,9 +222,9 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) }, - /* - * Keyboard - */ + /* + * Keyboard + */ .Keyboard_Interface = { .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, @@ -213,7 +258,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .EndpointAddress = (ENDPOINT_DIR_IN | KEYBOARD_IN_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = HID_EPSIZE, + .EndpointSize = KEYBOARD_EPSIZE, .PollingIntervalMS = 0x01 }, @@ -253,7 +298,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .EndpointAddress = (ENDPOINT_DIR_IN | MOUSE_IN_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = HID_EPSIZE, + .EndpointSize = MOUSE_EPSIZE, .PollingIntervalMS = 0x01 }, @@ -264,7 +309,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, - .InterfaceNumber = GENERIC_INTERFACE, + .InterfaceNumber = CONSOLE_INTERFACE, .AlternateSetting = 0x00, .TotalEndpoints = 2, @@ -291,9 +336,9 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - .EndpointAddress = (ENDPOINT_DIR_IN | GENERIC_IN_EPNUM), + .EndpointAddress = (ENDPOINT_DIR_IN | CONSOLE_IN_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = GENERIC_EPSIZE, + .EndpointSize = CONSOLE_EPSIZE, .PollingIntervalMS = 0x01 }, @@ -301,11 +346,51 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, - .EndpointAddress = (ENDPOINT_DIR_OUT | GENERIC_OUT_EPNUM), + .EndpointAddress = (ENDPOINT_DIR_OUT | CONSOLE_OUT_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = GENERIC_EPSIZE, + .EndpointSize = CONSOLE_EPSIZE, .PollingIntervalMS = 0x01 - } + }, + + /* + * Extra + */ + .Extra_Interface = + { + .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, + + .InterfaceNumber = EXTRA_INTERFACE, + .AlternateSetting = 0x00, + + .TotalEndpoints = 1, + + .Class = HID_CSCP_HIDClass, + .SubClass = HID_CSCP_NonBootSubclass, + .Protocol = HID_CSCP_NonBootProtocol, + + .InterfaceStrIndex = NO_DESCRIPTOR + }, + + .Extra_HID = + { + .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(ExtraReport) + }, + + .Extra_INEndpoint = + { + .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, + + .EndpointAddress = (ENDPOINT_DIR_IN | EXTRA_IN_EPNUM), + .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), + .EndpointSize = EXTRA_EPSIZE, + .PollingIntervalMS = 0x01 + }, }; @@ -387,10 +472,14 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, Address = &ConfigurationDescriptor.Mouse_HID; Size = sizeof(USB_HID_Descriptor_HID_t); break; - case GENERIC_INTERFACE: + case CONSOLE_INTERFACE: Address = &ConfigurationDescriptor.Console_HID; Size = sizeof(USB_HID_Descriptor_HID_t); break; + case EXTRA_INTERFACE: + Address = &ConfigurationDescriptor.Extra_HID; + Size = sizeof(USB_HID_Descriptor_HID_t); + break; } break; case HID_DTYPE_Report: @@ -403,10 +492,14 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, Address = &MouseReport; Size = sizeof(MouseReport); break; - case GENERIC_INTERFACE: + case CONSOLE_INTERFACE: Address = &ConsoleReport; Size = sizeof(ConsoleReport); break; + case EXTRA_INTERFACE: + Address = &ExtraReport; + Size = sizeof(ExtraReport); + break; } break; } diff --git a/keyboard/lufa/descriptor.h b/keyboard/lufa/descriptor.h index d45e905c..6b1b4d48 100644 --- a/keyboard/lufa/descriptor.h +++ b/keyboard/lufa/descriptor.h @@ -60,22 +60,34 @@ typedef struct USB_HID_Descriptor_HID_t Console_HID; USB_Descriptor_Endpoint_t Console_INEndpoint; USB_Descriptor_Endpoint_t Console_OUTEndpoint; + + // Extra HID Interface + USB_Descriptor_Interface_t Extra_Interface; + USB_HID_Descriptor_HID_t Extra_HID; + USB_Descriptor_Endpoint_t Extra_INEndpoint; } USB_Descriptor_Configuration_t; +/* nubmer of interfaces */ +#define TOTAL_INTERFACES 4 + +/* index of interface */ #define KEYBOARD_INTERFACE 0 #define MOUSE_INTERFACE 1 -#define GENERIC_INTERFACE 2 +#define CONSOLE_INTERFACE 2 +#define EXTRA_INTERFACE 3 -// Endopoint number/size +// Endopoint number and size #define KEYBOARD_IN_EPNUM 1 #define MOUSE_IN_EPNUM 2 -#define GENERIC_IN_EPNUM 3 -#define GENERIC_OUT_EPNUM 4 +#define CONSOLE_IN_EPNUM 3 +#define CONSOLE_OUT_EPNUM 4 +#define EXTRA_IN_EPNUM 5 -#define HID_EPSIZE 8 -#define GENERIC_EPSIZE 8 -#define GENERIC_REPORT_SIZE 8 +#define KEYBOARD_EPSIZE 8 +#define MOUSE_EPSIZE 8 +#define CONSOLE_EPSIZE 8 +#define EXTRA_EPSIZE 8 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, diff --git a/keyboard/lufa/keymap.c b/keyboard/lufa/keymap.c index a223da73..aa563651 100644 --- a/keyboard/lufa/keymap.c +++ b/keyboard/lufa/keymap.c @@ -110,7 +110,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * | |Gui |Alt | |Alt |Gui| | |Ctr| * `-----------------------------------------------------------' */ - KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, \ + KEYMAP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, \ CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,BRK, UP, NO, NO, \ LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \ LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,FN1, \ diff --git a/keyboard/lufa/lufa.c b/keyboard/lufa/lufa.c index a87d8474..09da96b2 100644 --- a/keyboard/lufa/lufa.c +++ b/keyboard/lufa/lufa.c @@ -117,7 +117,7 @@ static void Console_HID_Task(void) return; // TODO: impl receivechar()/recvchar() - Endpoint_SelectEndpoint(GENERIC_OUT_EPNUM); + Endpoint_SelectEndpoint(CONSOLE_OUT_EPNUM); /* Check to see if a packet has been sent from the host */ if (Endpoint_IsOUTReceived()) @@ -126,7 +126,7 @@ static void Console_HID_Task(void) if (Endpoint_IsReadWriteAllowed()) { /* Create a temporary buffer to hold the read in report from the host */ - uint8_t ConsoleData[GENERIC_REPORT_SIZE]; + uint8_t ConsoleData[CONSOLE_EPSIZE]; /* Read Console Report Data */ Endpoint_Read_Stream_LE(&ConsoleData, sizeof(ConsoleData), NULL); @@ -140,7 +140,7 @@ static void Console_HID_Task(void) } /* IN packet */ - Endpoint_SelectEndpoint(GENERIC_IN_EPNUM); + Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM); // send IN packet if (Endpoint_IsINReady()) Endpoint_ClearIN(); @@ -169,17 +169,21 @@ 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); + KEYBOARD_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); + MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE); /* Setup Console 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); + ConfigSuccess &= Endpoint_ConfigureEndpoint(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, + CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); + ConfigSuccess &= Endpoint_ConfigureEndpoint(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, + CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); + + /* Setup Extra HID Report Endpoint */ + ConfigSuccess &= Endpoint_ConfigureEndpoint(EXTRA_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, + EXTRA_EPSIZE, ENDPOINT_BANK_SINGLE); } /* @@ -223,7 +227,9 @@ void EVENT_USB_Device_ControlRequest(void) ReportData = (uint8_t*)&mouse_report_sent; ReportSize = sizeof(mouse_report_sent); break; - case GENERIC_INTERFACE: + case CONSOLE_INTERFACE: + break; + case EXTRA_INTERFACE: break; } @@ -254,7 +260,9 @@ void EVENT_USB_Device_ControlRequest(void) break; case MOUSE_INTERFACE: break; - case GENERIC_INTERFACE: + case CONSOLE_INTERFACE: + break; + case EXTRA_INTERFACE: break; } @@ -301,12 +309,7 @@ static void send_mouse(report_mouse_t *report) if (Endpoint_IsReadWriteAllowed()) { /* Write Mouse Report Data */ - /* Mouse report data structure - * LUFA: { buttons, x, y } - * tmk: { buttons, x, y, v, h } - */ - //Endpoint_Write_Stream_LE((uint8_t *)report+1, 3, NULL); - Endpoint_Write_Stream_LE(report, 3, NULL); + Endpoint_Write_Stream_LE(report, sizeof(report_mouse_t), NULL); /* Finalize the stream transfer to send the last packet */ Endpoint_ClearIN(); @@ -314,12 +317,35 @@ static void send_mouse(report_mouse_t *report) mouse_report_sent = *report; } +typedef struct { + uint8_t report_id; + uint16_t usage; +} __attribute__ ((packed)) report_extra_t; + static void send_system(uint16_t data) { + Endpoint_SelectEndpoint(EXTRA_IN_EPNUM); + if (Endpoint_IsReadWriteAllowed()) { + report_extra_t r = { + .report_id = REPORT_ID_SYSTEM, + .usage = data + }; + Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); + Endpoint_ClearIN(); + } } static void send_consumer(uint16_t data) { + Endpoint_SelectEndpoint(EXTRA_IN_EPNUM); + if (Endpoint_IsReadWriteAllowed()) { + report_extra_t r = { + .report_id = REPORT_ID_CONSUMER, + .usage = data + }; + Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); + Endpoint_ClearIN(); + } } @@ -331,7 +357,7 @@ int8_t sendchar(uint8_t c) if (USB_DeviceState != DEVICE_STATE_Configured) return -1; - Endpoint_SelectEndpoint(GENERIC_IN_EPNUM); + Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM); uint8_t timeout = 10; uint16_t prevFN = USB_Device_GetFrameNumber(); diff --git a/protocol/vusb/main.c b/protocol/vusb/main.c index 1ba40a27..3deb8223 100644 --- a/protocol/vusb/main.c +++ b/protocol/vusb/main.c @@ -62,11 +62,6 @@ int main(void) debug("initForUsbConnectivity()\n"); initForUsbConnectivity(); - int i; - while(--i){ /* To configured */ - usbPoll(); - _delay_ms(1); - } debug("main loop\n"); while (1) { diff --git a/protocol/vusb/vusb.c b/protocol/vusb/vusb.c index 1dff5dea..4e11836e 100644 --- a/protocol/vusb/vusb.c +++ b/protocol/vusb/vusb.c @@ -107,32 +107,25 @@ static void send_mouse(report_mouse_t *report) } } -/* + typedef struct { - uint8_t report_id; - uint8_t data0; - uint8_t data1; -} __attribute__ ((packed)) vusb_system_report_t; -*/ + uint8_t report_id; + uint16_t usage; +} __attribute__ ((packed)) report_extra_t; static void send_system(uint16_t data) { -/* - // Not need static? - static uint8_t report[] = { REPORT_ID_SYSTEM, 0, 0 }; - report[1] = data&0xFF; - report[2] = (data>>8)&0xFF; -*/ -/* - vusb_system_report_t r = { + static uint16_t last_data = 0; + if (data == last_data) return; + last_data = data; + + report_extra_t report = { .report_id = REPORT_ID_SYSTEM, - .data0 = data&0xFF, - .data1 = (data>>8)&0xFF + .usage = data }; if (usbInterruptIsReady3()) { - usbSetInterrupt3((void *)&r, sizeof(vusb_system_report_t)); + usbSetInterrupt3((void *)&report, sizeof(report)); } -*/ } static void send_consumer(uint16_t data) @@ -141,10 +134,10 @@ static void send_consumer(uint16_t data) if (data == last_data) return; last_data = data; - // Not need static? - static uint8_t report[] = { REPORT_ID_CONSUMER, 0, 0 }; - report[1] = data&0xFF; - report[2] = (data>>8)&0xFF; + report_extra_t report = { + .report_id = REPORT_ID_CONSUMER, + .usage = data + }; if (usbInterruptIsReady3()) { usbSetInterrupt3((void *)&report, sizeof(report)); } From cc68adeb5744cba9e8650bab04ff0f0a4033db9f Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 28 Jun 2012 23:05:21 +0900 Subject: [PATCH 06/13] Add protocol/lufa. LUFA supported now. --- common.mk | 23 +- keyboard/hhkb/keymap.c | 2 +- keyboard/lufa/config.h | 76 ----- keyboard/lufa/keymap.c | 195 ------------- keyboard/lufa/led.c | 24 -- keyboard/lufa/matrix.c | 271 ------------------ keyboard/macway/Makefile | 53 ---- .../{lufa/Makefile => macway/Makefile.lufa} | 109 ++----- keyboard/macway/Makefile.pjrc | 96 +++++++ keyboard/macway/config.h | 6 + keyboard/macway/keymap.c | 8 +- protocol/lufa.mk | 34 +++ {keyboard => protocol}/lufa/descriptor.c | 0 {keyboard => protocol}/lufa/descriptor.h | 0 {keyboard => protocol}/lufa/lufa.c | 0 {keyboard => protocol}/lufa/lufa.h | 0 protocol/pjrc.mk | 24 +- rules.mk | 27 +- 18 files changed, 215 insertions(+), 733 deletions(-) delete mode 100644 keyboard/lufa/config.h delete mode 100644 keyboard/lufa/keymap.c delete mode 100644 keyboard/lufa/led.c delete mode 100644 keyboard/lufa/matrix.c delete mode 100644 keyboard/macway/Makefile rename keyboard/{lufa/Makefile => macway/Makefile.lufa} (64%) create mode 100644 keyboard/macway/Makefile.pjrc create mode 100644 protocol/lufa.mk rename {keyboard => protocol}/lufa/descriptor.c (100%) rename {keyboard => protocol}/lufa/descriptor.h (100%) rename {keyboard => protocol}/lufa/lufa.c (100%) rename {keyboard => protocol}/lufa/lufa.h (100%) diff --git a/common.mk b/common.mk index d0e04df8..9bf34f2b 100644 --- a/common.mk +++ b/common.mk @@ -1,22 +1,23 @@ -SRC += host.c \ - keyboard.c \ - command.c \ - layer.c \ - timer.c \ - print.c \ - bootloader.c \ - util.c +COMMON_DIR = common +SRC += $(COMMON_DIR)/host.c \ + $(COMMON_DIR)/keyboard.c \ + $(COMMON_DIR)/command.c \ + $(COMMON_DIR)/layer.c \ + $(COMMON_DIR)/timer.c \ + $(COMMON_DIR)/print.c \ + $(COMMON_DIR)/bootloader.c \ + $(COMMON_DIR)/util.c # Option modules ifdef MOUSEKEY_ENABLE - SRC += mousekey.c + SRC += $(COMMON_DIR)/mousekey.c OPT_DEFS += -DMOUSEKEY_ENABLE endif ifdef PS2_MOUSE_ENABLE - SRC += ps2.c \ - ps2_mouse.c + SRC += $(COMMON_DIR)/ps2.c \ + $(COMMON_DIR)/ps2_mouse.c OPT_DEFS += -DPS2_MOUSE_ENABLE endif diff --git a/keyboard/hhkb/keymap.c b/keyboard/hhkb/keymap.c index 85a7c31b..88a6737b 100644 --- a/keyboard/hhkb/keymap.c +++ b/keyboard/hhkb/keymap.c @@ -110,7 +110,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * |Gui |Alt |Space |Alt |xxx| * `--------------------------------------------' */ - KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \ + KEYMAP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \ CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,BRK, UP, NO, BSPC, \ LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \ LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,FN1, \ diff --git a/keyboard/lufa/config.h b/keyboard/lufa/config.h deleted file mode 100644 index 5368b38d..00000000 --- a/keyboard/lufa/config.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -Copyright 2011 Jun Wako - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#ifndef CONFIG_H -#define CONFIG_H - -/* controller configuration */ -#include "controller_teensy.h" - - -/* USB Device descriptor */ -#define VENDOR_ID 0xFEED -#define PRODUCT_ID 0xBEE6 -#define DEVICE_VER 0x0202 -#define MANUFACTURER t.m.k. -#define PRODUCT Macway mod(LUFA) - - -/* message strings */ -#define DESCRIPTION t.m.k. keyboard firmware for Macway mod(LUFA) - - -/* matrix size */ -#define MATRIX_ROWS 9 -#define MATRIX_COLS 8 -/* define if matrix has ghost */ -#define MATRIX_HAS_GHOST -/* Set 0 if need no debouncing */ -#define DEBOUNCE 5 - - -/* key combination for command */ -#define IS_COMMAND() ( \ - keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_LCTRL) | MOD_BIT(KB_LALT) | MOD_BIT(KB_LGUI)) || \ - keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT)) \ -) - - -/* layer switching */ -#define LAYER_SWITCH_DELAY 100 -#define LAYER_SEND_FN_TERM 300 - - -/* mouse keys */ -#ifdef MOUSEKEY_ENABLE -# define MOUSEKEY_DELAY_TIME 192 -#endif - - -/* PS/2 mouse */ -#ifdef PS2_MOUSE_ENABLE -# define PS2_CLOCK_PORT PORTF -# define PS2_CLOCK_PIN PINF -# define PS2_CLOCK_DDR DDRF -# define PS2_CLOCK_BIT 0 -# define PS2_DATA_PORT PORTF -# define PS2_DATA_PIN PINF -# define PS2_DATA_DDR DDRF -# define PS2_DATA_BIT 1 -#endif - -#endif diff --git a/keyboard/lufa/keymap.c b/keyboard/lufa/keymap.c deleted file mode 100644 index aa563651..00000000 --- a/keyboard/lufa/keymap.c +++ /dev/null @@ -1,195 +0,0 @@ -/* -Copyright 2011 Jun Wako - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -/* - * Keymap for Macway mod - */ -#include -#include -#include -#include "usb_keycodes.h" -#include "print.h" -#include "debug.h" -#include "util.h" -#include "keymap.h" - - -// Convert physical keyboard layout to matrix array. -// This is a macro to define keymap easily in keyboard layout form. -#define KEYMAP( \ - K11, K10, K20, K30, K40, K41, K51, K50, K60, K70, K80, K81, K61, K02, \ - K12, K13, K23, K33, K43, K42, K52, K53, K63, K73, K83, K82, K62, K01, \ - K15, K14, K24, K34, K44, K45, K55, K54, K64, K74, K84, K85, K06, \ - K67, K16, K26, K36, K46, K47, K57, K56, K66, K76, K87, K32, K35, \ - K75, K22, K00, K07, K21, K04, K37, K27, K17 \ -) { \ - { KB_##K00, KB_##K01, KB_##K02, KB_NO, KB_##K04, KB_NO, KB_##K06, KB_##K07 }, \ - { KB_##K10, KB_##K11, KB_##K12, KB_##K13, KB_##K14, KB_##K15, KB_##K16, KB_##K17 }, \ - { KB_##K20, KB_##K21, KB_##K22, KB_##K23, KB_##K24, KB_NO, KB_##K26, KB_##K27 }, \ - { KB_##K30, KB_NO, KB_##K32, KB_##K33, KB_##K34, KB_##K35, KB_##K36, KB_##K37 }, \ - { KB_##K40, KB_##K41, KB_##K42, KB_##K43, KB_##K44, KB_##K45, KB_##K46, KB_##K47 }, \ - { KB_##K50, KB_##K51, KB_##K52, KB_##K53, KB_##K54, KB_##K55, KB_##K56, KB_##K57 }, \ - { KB_##K60, KB_##K61, KB_##K62, KB_##K63, KB_##K64, KB_NO, KB_##K66, KB_##K67 }, \ - { KB_##K70, KB_NO, KB_NO, KB_##K73, KB_##K74, KB_##K75, KB_##K76, KB_NO }, \ - { KB_##K80, KB_##K81, KB_##K82, KB_##K83, KB_##K84, KB_##K85, KB_NO, KB_##K87 } \ -} - -#define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)])) - - -// Assign Fn key(0-7) to a layer to which switch with the Fn key pressed. -static const uint8_t PROGMEM fn_layer[] = { - 0, // Fn0 - 1, // Fn1 - 2, // Fn2 - 3, // Fn3 - 4, // Fn4 - 0, // Fn5 - 3, // Fn6 - 3 // Fn7 -}; - -// Assign Fn key(0-7) to a keycode sent when release Fn key without use of the layer. -// See layer.c for details. -static const uint8_t PROGMEM fn_keycode[] = { - KB_NO, // Fn0 - KB_NO, // Fn1 - KB_SLSH, // Fn2 - KB_SCLN, // Fn3 - KB_SPC, // Fn4 - KB_NO, // Fn5 - KB_NO, // Fn6 - KB_NO // Fn7 -}; - -static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - /* Layer 0: Default Layer - * ,-----------------------------------------------------------. - * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | - * |-----------------------------------------------------------| - * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| | - * |-----------------------------------------------------' | - * |Contro| A| S| D| F| G| H| J| K| L|Fn3| '|Return | - * |-----------------------------------------------------------| - * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn1| - * |-----------------------------------------------------------| - * |Fn7|Gui |Alt |Fn4 |Alt |Gui|Fn6|Fn6|Ctr| - * `-----------------------------------------------------------' - */ - KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ - TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ - LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT,ENT, \ - LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \ - FN7, LGUI,LALT,FN4, RALT,BSLS,FN6, FN6, RCTL), - - - /* Layer 1: HHKB mode (HHKB Fn) - * ,-----------------------------------------------------------. - * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete | - * |-----------------------------------------------------------| - * |Caps | | | | | | | |Psc|Slk|Pus|Up | | | - * |-----------------------------------------------------' | - * |Contro|VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter | - * |-----------------------------------------------------------| - * |Shift | | | | | | +| -|End|PgD|Dow|Shift |xxx| - * |-----------------------------------------------------------| - * | |Gui |Alt | |Alt |Gui| | |Ctr| - * `-----------------------------------------------------------' - */ - KEYMAP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, \ - CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,BRK, UP, NO, NO, \ - LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \ - LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,FN1, \ - NO, LGUI,LALT,SPC, RALT,NO, NO, NO, RCTL), - - - /* Layer 2: Vi mode (Quote/Rmeta) - * ,-----------------------------------------------------------. - * | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| ` | - * |-----------------------------------------------------------| - * | \ |Hom|PgD|Up |PgU|End|Hom|PgD|PgU|End| | | | | - * |-----------------------------------------------------' | - * |Contro| |Lef|Dow|Rig| |Lef|Dow|Up |Rig| | | \ | - * |-----------------------------------------------------------| - * |Shift | | | | | |Hom|PgD|PgU|End|xxx|Shift | | - * |-----------------------------------------------------------| - * | |Gui |Alt |Space |Alt |Gui|Fn6|Fn6|Ctr| - * `-----------------------------------------------------------' - */ - KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, GRV, \ - BSLS,HOME,PGDN,UP, PGUP,END, HOME,PGDN,PGUP,END, NO, NO, NO, NO, \ - LCTL,NO, LEFT,DOWN,RGHT,NO, LEFT,DOWN,UP, RGHT,NO, NO, BSLS, \ - LSFT,NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, FN2, RSFT,NO, \ - NO, LGUI,LALT,SPC, RALT,RGUI,FN6, FN6, RCTL), - - - /* Layer 3: Mouse mode (Semicolon) - * ,-----------------------------------------------------------. - * | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| ` | - * |-----------------------------------------------------------| - * | \ |MwL|MwD|McU|MwU|MwR|MwL|MwD|MwU|MwR| | | | | - * |-----------------------------------------------------' | - * |Contro| |McL|McD|McR| |McL|McD|McU|McR|xxx| | \ | - * |-----------------------------------------------------------| - * |Shift | | |Mb1|Mb2|Mb3|Mb2|Mb1| | | |Shift | | - * |-----------------------------------------------------------| - * |xxx|Gui |Alt |Mb1 |Alt | | | | | - * `-----------------------------------------------------------' - * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel - */ - KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, GRV, \ - BSLS,WH_L,WH_D,MS_U,WH_U,WH_R,WH_L,WH_D,WH_U,WH_R,NO, NO, NO, NO, \ - LCTL,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN3, NO, BSLS, \ - LSFT,NO, NO, BTN1,BTN2,BTN3,BTN2,BTN1,NO, NO, NO, RSFT,NO, \ - FN7, LGUI,LALT,BTN1,RALT,NO, FN6, FN6, NO), - - - /* Layer 4: Matias half keyboard style (Space) - * ,-----------------------------------------------------------. - * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete | - * |-----------------------------------------------------------| - * |Backs| P| O| I| U| Y| T| R| E| W| Q|Tab|Tab| | - * |-----------------------------------------------------' | - * |Contro| ;| L| K| J| H| G| F| D| S| A|Con|Control | - * |-----------------------------------------------------------| - * |Shift | /| .| ,| M| N| B| V| C| X| Z|Shift | | - * |-----------------------------------------------------------| - * | |Gui |Alt |xxxxxxxxxxxxxxxxxxxxxx|Alt |Gui| | |Ctr| - * `-----------------------------------------------------------' - */ - KEYMAP(MINS,0, 9, 8, 7, 6, 5, 4, 3, 2, 1, NO, NO, ESC, \ - BSPC,P, O, I, U, Y, T, R, E, W, Q, TAB, TAB, TAB, \ - LCTL,SCLN,L, K, J, H, G, F, D, S, A, RCTL,RCTL, \ - LSFT,SLSH,DOT, COMM,M, N, B, V, C, X, Z, RSFT,NO, \ - NO, LGUI,LALT,FN4, RALT,RGUI,NO, NO, RCTL), -}; - - -uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col) -{ - return KEYCODE(layer, row, col); -} - -uint8_t keymap_fn_layer(uint8_t fn_bits) -{ - return pgm_read_byte(&fn_layer[biton(fn_bits)]); -} - -uint8_t keymap_fn_keycode(uint8_t fn_bits) -{ - return pgm_read_byte(&fn_keycode[(biton(fn_bits))]); -} diff --git a/keyboard/lufa/led.c b/keyboard/lufa/led.c deleted file mode 100644 index f76545f0..00000000 --- a/keyboard/lufa/led.c +++ /dev/null @@ -1,24 +0,0 @@ -/* -Copyright 2011 Jun Wako - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "stdint.h" -#include "led.h" - - -void led_set(uint8_t usb_led) -{ -} diff --git a/keyboard/lufa/matrix.c b/keyboard/lufa/matrix.c deleted file mode 100644 index 394c3d97..00000000 --- a/keyboard/lufa/matrix.c +++ /dev/null @@ -1,271 +0,0 @@ -/* -Copyright 2011 Jun Wako - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -/* - * scan matrix - */ -#include -#include -#include -#include -#include "print.h" -#include "debug.h" -#include "util.h" -#include "matrix.h" - - -#if (MATRIX_COLS > 16) -# error "MATRIX_COLS must not exceed 16" -#endif -#if (MATRIX_ROWS > 255) -# error "MATRIX_ROWS must not exceed 255" -#endif - - -#ifndef DEBOUNCE -# define DEBOUNCE 0 -#endif -static uint8_t debouncing = DEBOUNCE; - -// matrix state buffer(1:on, 0:off) -#if (MATRIX_COLS <= 8) -static uint8_t *matrix; -static uint8_t *matrix_prev; -static uint8_t _matrix0[MATRIX_ROWS]; -static uint8_t _matrix1[MATRIX_ROWS]; -#else -static uint16_t *matrix; -static uint16_t *matrix_prev; -static uint16_t _matrix0[MATRIX_ROWS]; -static uint16_t _matrix1[MATRIX_ROWS]; -#endif - -#ifdef MATRIX_HAS_GHOST -static bool matrix_has_ghost_in_row(uint8_t row); -#endif -static uint8_t read_col(void); -static void unselect_rows(void); -static void select_row(uint8_t row); - - -inline -uint8_t matrix_rows(void) -{ - return MATRIX_ROWS; -} - -inline -uint8_t matrix_cols(void) -{ - return MATRIX_COLS; -} - -void matrix_init(void) -{ - // initialize row and col - unselect_rows(); - // Input with pull-up(DDR:0, PORT:1) - DDRB = 0x00; - PORTB = 0xFF; - - // initialize matrix state: all keys off - for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00; - for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00; - matrix = _matrix0; - matrix_prev = _matrix1; -} - -uint8_t matrix_scan(void) -{ - if (!debouncing) { - uint8_t *tmp = matrix_prev; - matrix_prev = matrix; - matrix = tmp; - } - - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - unselect_rows(); - select_row(i); - _delay_us(30); // without this wait read unstable value. - if (matrix[i] != (uint8_t)~read_col()) { - matrix[i] = (uint8_t)~read_col(); - if (debouncing) { - debug("bounce!: "); debug_hex(debouncing); print("\n"); - } - debouncing = DEBOUNCE; - } - } - unselect_rows(); - - if (debouncing) { - debouncing--; - } - - return 1; -} - -bool matrix_is_modified(void) -{ - if (debouncing) return false; - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - if (matrix[i] != matrix_prev[i]) { - return true; - } - } - return false; -} - -inline -bool matrix_has_ghost(void) -{ -#ifdef MATRIX_HAS_GHOST - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - if (matrix_has_ghost_in_row(i)) - return true; - } -#endif - return false; -} - -inline -bool matrix_is_on(uint8_t row, uint8_t col) -{ - return (matrix[row] & (1<> 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: # @@ -29,8 +9,11 @@ # # 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 program = Download the hex file to the device. +# Please customize your programmer settings(PROGRAM_CMD) +# +# make teensy = Download the hex file to the device, using teensy_loader_cli. +# (must have teensy_loader_cli installed). # # make dfu = Download the hex file to the device, using dfu-programmer (must # have dfu-programmer installed). @@ -44,10 +27,7 @@ # 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, +# 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. @@ -58,27 +38,29 @@ # To rebuild project do "make clean" then "make all". #---------------------------------------------------------------------------- +# Target file name (without extension). +TARGET = macway_lufa + # Directory common source filess exist TOP_DIR = ../.. # Directory keyboard dependent files exist TARGET_DIR = . + +# List C source files here. (C dependencies are automatically generated.) +SRC += keymap.c \ + matrix.c \ + led.c \ + protocol/pjrc/bootloader_teensy.c + +CONFIG_H = config.h + + # 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 @@ -93,6 +75,12 @@ BOARD = USBKEY F_CPU = 16000000 +# +# LUFA specific +# +# Target architecture (see library "Board Types" documentation). +ARCH = AVR8 + # 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 @@ -107,31 +95,6 @@ F_CPU = 16000000 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 \ - pjrc/bootloader_teensy.c -CONFIG_H = config.h - # Build Options # comment out to disable the options. @@ -142,28 +105,10 @@ EXTRAKEY_ENABLE = yes # Audio control and System control #NKRO_ENABLE = yes # USB Nkey Rollover -# 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 +VPATH += $(TOP_DIR) - -include $(TOP_DIR)/protocol.mk +include $(TOP_DIR)/protocol/lufa.mk include $(TOP_DIR)/common.mk include $(TOP_DIR)/rules.mk - -test: - echo $(SRC) diff --git a/keyboard/macway/Makefile.pjrc b/keyboard/macway/Makefile.pjrc new file mode 100644 index 00000000..d2fb8ff2 --- /dev/null +++ b/keyboard/macway/Makefile.pjrc @@ -0,0 +1,96 @@ +#---------------------------------------------------------------------------- +# 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. +# Please customize your programmer settings(PROGRAM_CMD) +# +# make teensy = Download the hex file to the device, using teensy_loader_cli. +# (must have teensy_loader_cli installed). +# +# 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 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". +#---------------------------------------------------------------------------- + +# Target file name (without extension). +TARGET = macway_pjrc + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# keyboard dependent files +SRC = protocol/pjrc/main.c \ + keymap.c \ + matrix.c \ + led.c + +CONFIG_H = config.h + + +# MCU name, you MUST set this to match the board you are using +# type "make clean" after changing this, so all files will be rebuilt +#MCU = at90usb162 # Teensy 1.0 +MCU = atmega32u4 # Teensy 2.0 +#MCU = at90usb646 # Teensy++ 1.0 +#MCU = at90usb1286 # Teensy++ 2.0 + + +# Processor frequency. +# Normally the first thing your program should do is set the clock prescaler, +# so your program will run at the correct speed. You should also set this +# variable to same clock speed. The _delay_ms() macro uses this, and many +# examples use this variable to calculate timings. Do not add a "UL" here. +F_CPU = 16000000 + + +# Build Options +# comment out to disable the options. +# +MOUSEKEY_ENABLE = yes # Mouse keys +#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +EXTRAKEY_ENABLE = yes # Audio control and System control +#NKRO_ENABLE = yes # USB Nkey Rollover + + + +#---------------- Programming Options -------------------------- +PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex + + + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + +include $(TOP_DIR)/protocol/pjrc.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk diff --git a/keyboard/macway/config.h b/keyboard/macway/config.h index b68ea20d..5503c77e 100644 --- a/keyboard/macway/config.h +++ b/keyboard/macway/config.h @@ -21,10 +21,16 @@ along with this program. If not, see . /* controller configuration */ #include "controller_teensy.h" + +/* USB Device descriptor parameter */ #define VENDOR_ID 0xFEED #define PRODUCT_ID 0xBEE0 +#define DEVICE_VER 0x0202 #define MANUFACTURER t.m.k. #define PRODUCT Macway mod + + +/* message strings */ #define DESCRIPTION t.m.k. keyboard firmware for Macway mod diff --git a/keyboard/macway/keymap.c b/keyboard/macway/keymap.c index 89634e2f..5ecea256 100644 --- a/keyboard/macway/keymap.c +++ b/keyboard/macway/keymap.c @@ -59,7 +59,7 @@ static const uint8_t PROGMEM fn_layer[] = { 3, // Fn3 4, // Fn4 0, // Fn5 - 2, // Fn6 + 3, // Fn6 3 // Fn7 }; @@ -94,7 +94,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT,ENT, \ LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \ - FN7, LGUI,LALT,FN4, RALT,BSLS,GRV, FN6, RCTL), + FN7, LGUI,LALT,FN4, RALT,GRV, FN6, FN6, RCTL), /* Layer 1: HHKB mode (HHKB Fn) @@ -110,7 +110,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * | |Gui |Alt | |Alt |Gui| | |Ctr| * `-----------------------------------------------------------' */ - KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, \ + KEYMAP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, \ CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,BRK, UP, NO, NO, \ LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \ LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,FN1, \ @@ -155,7 +155,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { BSLS,WH_L,WH_D,MS_U,WH_U,WH_R,WH_L,WH_D,WH_U,WH_R,NO, NO, NO, NO, \ LCTL,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN3, NO, BSLS, \ LSFT,NO, NO, BTN1,BTN2,BTN3,BTN2,BTN1,NO, NO, NO, RSFT,NO, \ - FN7, LGUI,LALT,BTN1,RALT,NO, NO, NO, NO), + FN7, LGUI,LALT,BTN1,RALT,NO, FN6, FN6, NO), /* Layer 4: Matias half keyboard style (Space) diff --git a/protocol/lufa.mk b/protocol/lufa.mk new file mode 100644 index 00000000..ad6cab6d --- /dev/null +++ b/protocol/lufa.mk @@ -0,0 +1,34 @@ +LUFA_DIR = protocol/lufa + +# Path to the LUFA library +LUFA_PATH = $(TOP_DIR)/protocol/lufa/LUFA-120219 + +# Create the LUFA source path variables by including the LUFA root makefile +include $(LUFA_PATH)/LUFA/makefile + +LUFA_SRC = $(LUFA_DIR)/lufa.c \ + $(LUFA_DIR)/descriptor.c \ + $(LUFA_SRC_USB) +SRC += $(subst $(LUFA_PATH)/,,$(LUFA_SRC)) + +# Search Path +VPATH += $(LUFA_PATH) + +# Option modules +#ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE) +#endif + +#ifdef EXTRAKEY_ENABLE +#endif + +# 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_USB=$(F_USB)UL +OPT_DEFS += -DARCH=ARCH_$(ARCH) +OPT_DEFS += $(LUFA_OPTS) +OPT_DEFS += -DHOST_LUFA diff --git a/keyboard/lufa/descriptor.c b/protocol/lufa/descriptor.c similarity index 100% rename from keyboard/lufa/descriptor.c rename to protocol/lufa/descriptor.c diff --git a/keyboard/lufa/descriptor.h b/protocol/lufa/descriptor.h similarity index 100% rename from keyboard/lufa/descriptor.h rename to protocol/lufa/descriptor.h diff --git a/keyboard/lufa/lufa.c b/protocol/lufa/lufa.c similarity index 100% rename from keyboard/lufa/lufa.c rename to protocol/lufa/lufa.c diff --git a/keyboard/lufa/lufa.h b/protocol/lufa/lufa.h similarity index 100% rename from keyboard/lufa/lufa.h rename to protocol/lufa/lufa.h diff --git a/protocol/pjrc.mk b/protocol/pjrc.mk index 1ee45e9e..1ceee0ad 100644 --- a/protocol/pjrc.mk +++ b/protocol/pjrc.mk @@ -1,21 +1,21 @@ +PJRC_DIR = protocol/pjrc + OPT_DEFS += -DHOST_PJRC -SRC += pjrc.c \ - usb_keyboard.c \ - usb_debug.c \ - usb.c \ - bootloader_teensy.c - - -# Search Path -VPATH += $(TOP_DIR)/protocol/pjrc - +SRC += $(PJRC_DIR)/pjrc.c \ + $(PJRC_DIR)/usb_keyboard.c \ + $(PJRC_DIR)/usb_debug.c \ + $(PJRC_DIR)/usb.c \ + $(PJRC_DIR)/bootloader_teensy.c # Option modules ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE) - SRC += usb_mouse.c + SRC += $(PJRC_DIR)/usb_mouse.c endif ifdef EXTRAKEY_ENABLE - SRC += usb_extra.c + SRC += $(PJRC_DIR)/usb_extra.c endif + +# Search Path +VPATH += $(TOP_DIR)/$(PJRC_DIR) diff --git a/rules.mk b/rules.mk index 060f660c..a58de2f1 100644 --- a/rules.mk +++ b/rules.mk @@ -25,8 +25,23 @@ # # 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 program = Download the hex file to the device. +# Please customize your programmer settings(PROGRAM_CMD) +# +# make teensy = Download the hex file to the device, using teensy_loader_cli. +# (must have teensy_loader_cli installed). +# +# 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 debug = Start either simulavr or avarice as specified for debugging, # with avr-gdb or avr-insight as the front end for debugging. @@ -567,6 +582,10 @@ clean_list : $(REMOVE) -r .dep $(REMOVE) -r $(OBJDIR) +show_path: + @echo VPATH=$(VPATH) + @echo SRC=$(SRC) + # Create object files directory $(shell mkdir $(OBJDIR) 2>/dev/null) @@ -579,5 +598,5 @@ $(shell mkdir $(OBJDIR) 2>/dev/null) # Listing of phony targets. .PHONY : all begin finish end sizebefore sizeafter gccversion \ build elf hex eep lss sym coff extcoff \ -clean clean_list program debug gdb-config - +clean clean_list debug gdb-config show_path \ +program teensy dfu flip dfu-ee flip-ee From 52011f08c9b4fcfc55817d24bdc4b4ff7b4fe06f Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 28 Jun 2012 23:54:54 +0900 Subject: [PATCH 07/13] Make console compatible with PJRC hid_listen. --- protocol/lufa/descriptor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocol/lufa/descriptor.c b/protocol/lufa/descriptor.c index e9925cca..59adcd18 100644 --- a/protocol/lufa/descriptor.c +++ b/protocol/lufa/descriptor.c @@ -130,8 +130,8 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] = const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = { - HID_RI_USAGE_PAGE(16, 0xFF00), /* Vendor Page 0 */ - HID_RI_USAGE(8, 0x01), /* Vendor Usage 1 */ + HID_RI_USAGE_PAGE(16, 0xFF31), /* Vendor Page(PJRC Teensy compatible) */ + HID_RI_USAGE(8, 0x74), /* Vendor Usage(PJRC Teensy compatible) */ HID_RI_COLLECTION(8, 0x01), /* Application */ HID_RI_USAGE(8, 0x02), /* Vendor Usage 2 */ HID_RI_LOGICAL_MINIMUM(8, 0x00), From f2ebac101d367ee091f54b8d43b39a4d74f3b90e Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 29 Jun 2012 03:33:59 +0900 Subject: [PATCH 08/13] Add conditional compile for MOUSE_ENABLE and EXTRAKEY_ENABLE. --- keyboard/macway/Makefile.lufa | 2 +- protocol/lufa/descriptor.c | 65 ++++++++++++++++++++++++++++++----- protocol/lufa/descriptor.h | 29 ++++++++++++---- protocol/lufa/lufa.c | 32 ++++++++++++----- 4 files changed, 105 insertions(+), 23 deletions(-) diff --git a/keyboard/macway/Makefile.lufa b/keyboard/macway/Makefile.lufa index a3395a2a..8f50776d 100644 --- a/keyboard/macway/Makefile.lufa +++ b/keyboard/macway/Makefile.lufa @@ -100,9 +100,9 @@ F_USB = $(F_CPU) # comment out to disable the options. # MOUSEKEY_ENABLE = yes # Mouse keys -#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support EXTRAKEY_ENABLE = yes # Audio control and System control #NKRO_ENABLE = yes # USB Nkey Rollover +#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support # Search Path diff --git a/protocol/lufa/descriptor.c b/protocol/lufa/descriptor.c index 59adcd18..d3f740bf 100644 --- a/protocol/lufa/descriptor.c +++ b/protocol/lufa/descriptor.c @@ -54,8 +54,8 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = 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_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, 0x08), @@ -69,11 +69,11 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = 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_USAGE_MAXIMUM(8, 0xFF), /* Keyboard Application */ + HID_RI_LOGICAL_MINIMUM(8, 0x00), + HID_RI_LOGICAL_MAXIMUM(8, 0xFF), 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), @@ -133,21 +133,22 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = HID_RI_USAGE_PAGE(16, 0xFF31), /* Vendor Page(PJRC Teensy compatible) */ HID_RI_USAGE(8, 0x74), /* Vendor Usage(PJRC Teensy compatible) */ HID_RI_COLLECTION(8, 0x01), /* Application */ - HID_RI_USAGE(8, 0x02), /* Vendor Usage 2 */ + HID_RI_USAGE(8, 0x75), /* Vendor Usage 0x75 */ HID_RI_LOGICAL_MINIMUM(8, 0x00), HID_RI_LOGICAL_MAXIMUM(8, 0xFF), - HID_RI_REPORT_SIZE(8, 0x08), HID_RI_REPORT_COUNT(8, CONSOLE_EPSIZE), + HID_RI_REPORT_SIZE(8, 0x08), HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), - HID_RI_USAGE(8, 0x03), /* Vendor Usage 3 */ + HID_RI_USAGE(8, 0x76), /* Vendor Usage 0x76 */ HID_RI_LOGICAL_MINIMUM(8, 0x00), HID_RI_LOGICAL_MAXIMUM(8, 0xFF), - HID_RI_REPORT_SIZE(8, 0x08), HID_RI_REPORT_COUNT(8, CONSOLE_EPSIZE), + HID_RI_REPORT_SIZE(8, 0x08), HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), HID_RI_END_COLLECTION(0), }; +#ifdef EXTRAKEY_ENABLE const USB_Descriptor_HIDReport_Datatype_t PROGMEM ExtraReport[] = { HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ @@ -176,6 +177,42 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ExtraReport[] = HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE), HID_RI_END_COLLECTION(0), }; +#endif + +#ifdef NKRO_ENABLE +const USB_Descriptor_HIDReport_Datatype_t PROGMEM NKROReport[] = +{ + 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_COUNT(8, 0x08), + HID_RI_REPORT_SIZE(8, 0x01), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), + + 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_USAGE_PAGE(8, 0x07), /* Key Codes */ + HID_RI_USAGE_MINIMUM(8, 0x00), /* Keyboard 0 */ + HID_RI_USAGE_MAXIMUM(8, NKRO_SIZE*8-1), /* Keyboard Right GUI */ + HID_RI_LOGICAL_MINIMUM(8, 0x00), + HID_RI_LOGICAL_MAXIMUM(8, 0x01), + HID_RI_REPORT_COUNT(8, NKRO_SIZE*8), + HID_RI_REPORT_SIZE(8, 0x01), +}; +#endif /******************************************************************************* * Device Descriptors @@ -265,6 +302,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = /* * Mouse */ +#ifdef MOUSE_ENABLE .Mouse_Interface = { .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, @@ -301,6 +339,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .EndpointSize = MOUSE_EPSIZE, .PollingIntervalMS = 0x01 }, +#endif /* * Console @@ -355,6 +394,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = /* * Extra */ +#ifdef EXTRAKEY_ENABLE .Extra_Interface = { .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, @@ -391,6 +431,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .EndpointSize = EXTRA_EPSIZE, .PollingIntervalMS = 0x01 }, +#endif }; @@ -468,18 +509,22 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, Address = &ConfigurationDescriptor.Keyboard_HID; Size = sizeof(USB_HID_Descriptor_HID_t); break; +#ifdef MOUSE_ENABLE case MOUSE_INTERFACE: Address = &ConfigurationDescriptor.Mouse_HID; Size = sizeof(USB_HID_Descriptor_HID_t); break; +#endif case CONSOLE_INTERFACE: Address = &ConfigurationDescriptor.Console_HID; Size = sizeof(USB_HID_Descriptor_HID_t); break; +#ifdef EXTRAKEY_ENABLE case EXTRA_INTERFACE: Address = &ConfigurationDescriptor.Extra_HID; Size = sizeof(USB_HID_Descriptor_HID_t); break; +#endif } break; case HID_DTYPE_Report: @@ -488,18 +533,22 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, Address = &KeyboardReport; Size = sizeof(KeyboardReport); break; +#ifdef MOUSE_ENABLE case MOUSE_INTERFACE: Address = &MouseReport; Size = sizeof(MouseReport); break; +#endif case CONSOLE_INTERFACE: Address = &ConsoleReport; Size = sizeof(ConsoleReport); break; +#ifdef EXTRAKEY_ENABLE case EXTRA_INTERFACE: Address = &ExtraReport; Size = sizeof(ExtraReport); break; +#endif } break; } diff --git a/protocol/lufa/descriptor.h b/protocol/lufa/descriptor.h index 6b1b4d48..19bce999 100644 --- a/protocol/lufa/descriptor.h +++ b/protocol/lufa/descriptor.h @@ -51,9 +51,11 @@ typedef struct USB_Descriptor_Endpoint_t Keyboard_INEndpoint; // Mouse HID Interface +#ifdef MOUSE_ENABLE USB_Descriptor_Interface_t Mouse_Interface; USB_HID_Descriptor_HID_t Mouse_HID; USB_Descriptor_Endpoint_t Mouse_INEndpoint; +#endif // Console HID Interface USB_Descriptor_Interface_t Console_Interface; @@ -62,20 +64,35 @@ typedef struct USB_Descriptor_Endpoint_t Console_OUTEndpoint; // Extra HID Interface +#ifdef EXTRAKEY_ENABLE USB_Descriptor_Interface_t Extra_Interface; USB_HID_Descriptor_HID_t Extra_HID; USB_Descriptor_Endpoint_t Extra_INEndpoint; +#endif } USB_Descriptor_Configuration_t; -/* nubmer of interfaces */ -#define TOTAL_INTERFACES 4 - /* index of interface */ #define KEYBOARD_INTERFACE 0 -#define MOUSE_INTERFACE 1 -#define CONSOLE_INTERFACE 2 -#define EXTRA_INTERFACE 3 + +#ifdef MOUSE_ENABLE +# define MOUSE_INTERFACE (KEYBOARD_INTERFACE + 1) +#else +# define MOUSE_INTERFACE KEYBOARD_INTERFACE +#endif + +#ifdef EXTRAKEY_ENABLE +# define EXTRA_INTERFACE (MOUSE_INTERFACE + 1) +#else +# define EXTRA_INTERFACE MOUSE_INTERFACE +#endif + +#define CONSOLE_INTERFACE (EXTRA_INTERFACE + 1) + + +/* nubmer of interfaces */ +#define TOTAL_INTERFACES (CONSOLE_INTERFACE + 1) + // Endopoint number and size #define KEYBOARD_IN_EPNUM 1 diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index 09da96b2..f485e24b 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c @@ -50,7 +50,9 @@ static uint8_t keyboard_led_stats = 0; // TODO: impl Control Request GET_REPORT static report_keyboard_t keyboard_report_sent; +#ifdef MOUSE_ENABLE static report_mouse_t mouse_report_sent; +#endif /* Host driver */ static uint8_t keyboard_leds(void); @@ -171,19 +173,23 @@ void EVENT_USB_Device_ConfigurationChanged(void) ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, KEYBOARD_EPSIZE, ENDPOINT_BANK_SINGLE); +#ifdef MOUSE_ENABLE /* Setup Mouse HID Report Endpoint */ ConfigSuccess &= Endpoint_ConfigureEndpoint(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE); +#endif + +#ifdef EXTRAKEY_ENABLE + /* Setup Extra HID Report Endpoint */ + ConfigSuccess &= Endpoint_ConfigureEndpoint(EXTRA_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, + EXTRA_EPSIZE, ENDPOINT_BANK_SINGLE); +#endif /* Setup Console HID Report Endpoints */ ConfigSuccess &= Endpoint_ConfigureEndpoint(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); ConfigSuccess &= Endpoint_ConfigureEndpoint(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); - - /* Setup Extra HID Report Endpoint */ - ConfigSuccess &= Endpoint_ConfigureEndpoint(EXTRA_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, - EXTRA_EPSIZE, ENDPOINT_BANK_SINGLE); } /* @@ -222,15 +228,19 @@ void EVENT_USB_Device_ControlRequest(void) ReportData = (uint8_t*)&keyboard_report_sent; ReportSize = sizeof(keyboard_report_sent); break; +#ifdef MOUSE_ENABLE case MOUSE_INTERFACE: // TODO: test/check ReportData = (uint8_t*)&mouse_report_sent; ReportSize = sizeof(mouse_report_sent); break; - case CONSOLE_INTERFACE: - break; +#endif +#ifdef EXTRAKEY_ENABLE case EXTRA_INTERFACE: break; +#endif + case CONSOLE_INTERFACE: + break; } /* Write the report data to the control endpoint */ @@ -258,12 +268,16 @@ void EVENT_USB_Device_ControlRequest(void) /* Read in the LED report from the host */ keyboard_led_stats = Endpoint_Read_8(); break; +#ifdef MOUSE_ENABLE case MOUSE_INTERFACE: break; - case CONSOLE_INTERFACE: - break; +#endif +#ifdef EXTRAKEY_ENABLE case EXTRA_INTERFACE: break; +#endif + case CONSOLE_INTERFACE: + break; } Endpoint_ClearOUT(); @@ -302,6 +316,7 @@ static void send_keyboard(report_keyboard_t *report) static void send_mouse(report_mouse_t *report) { +#ifdef MOUSE_ENABLE /* Select the Mouse Report Endpoint */ Endpoint_SelectEndpoint(MOUSE_IN_EPNUM); @@ -315,6 +330,7 @@ static void send_mouse(report_mouse_t *report) Endpoint_ClearIN(); } mouse_report_sent = *report; +#endif } typedef struct { From a112f3614e0e3204ce35dcdfbf2723c3382c4c35 Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 29 Jun 2012 16:48:36 +0900 Subject: [PATCH 09/13] confirm SetReport LED. --- common/command.c | 1 + common/host.c | 5 +- keyboard/macway/keymap.c | 2 +- protocol/lufa/descriptor.h | 7 +++ protocol/lufa/lufa.c | 122 +++++++++++++++++++------------------ protocol/lufa/lufa.h | 15 ++++- 6 files changed, 91 insertions(+), 61 deletions(-) diff --git a/common/command.c b/common/command.c index e325a5d8..13d37242 100644 --- a/common/command.c +++ b/common/command.c @@ -138,6 +138,7 @@ static uint8_t command_common(void) } break; case KB_S: + print("host_keyboard_leds:"); phex(host_keyboard_leds()); print("\n"); #ifdef HOST_PJRC print("UDCON: "); phex(UDCON); print("\n"); print("UDIEN: "); phex(UDIEN); print("\n"); diff --git a/common/host.c b/common/host.c index cc26d55c..8dd2abbe 100644 --- a/common/host.c +++ b/common/host.c @@ -168,13 +168,16 @@ void host_mouse_send(report_mouse_t *report) void host_system_send(uint16_t data) { + static uint16_t last_data = 0; + if (data == last_data) return; + last_data = data; + if (!driver) return; (*driver->send_system)(data); } void host_consumer_send(uint16_t data) { - // TODO: this is needed? static uint16_t last_data = 0; if (data == last_data) return; last_data = data; diff --git a/keyboard/macway/keymap.c b/keyboard/macway/keymap.c index 5ecea256..76c0d8b7 100644 --- a/keyboard/macway/keymap.c +++ b/keyboard/macway/keymap.c @@ -111,7 +111,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * `-----------------------------------------------------------' */ KEYMAP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, \ - CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,BRK, UP, NO, NO, \ + CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,BRK, UP, NO, NLCK,\ LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \ LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,FN1, \ NO, LGUI,LALT,SPC, RALT,NO, NO, NO, RCTL), diff --git a/protocol/lufa/descriptor.h b/protocol/lufa/descriptor.h index 19bce999..001e072e 100644 --- a/protocol/lufa/descriptor.h +++ b/protocol/lufa/descriptor.h @@ -1,3 +1,10 @@ +/* + * 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. diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index f485e24b..8fa719bc 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c @@ -46,13 +46,12 @@ #include "descriptor.h" #include "lufa.h" +static uint8_t idle_duration = 0; +static uint8_t protocol_report = 1; static uint8_t keyboard_led_stats = 0; -// TODO: impl Control Request GET_REPORT static report_keyboard_t keyboard_report_sent; -#ifdef MOUSE_ENABLE -static report_mouse_t mouse_report_sent; -#endif + /* Host driver */ static uint8_t keyboard_leds(void); @@ -83,12 +82,8 @@ int main(void) debug_keyboard = true; debug_mouse = true; -/* TODO: can't print here - _delay_ms(5000); - USB_USBTask(); - print("abcdefg\n"); - USB_USBTask(); -*/ + // TODO: can't print here + debug("LUFA init\n"); keyboard_init(); host_set_driver(&lufa_driver); @@ -228,19 +223,6 @@ void EVENT_USB_Device_ControlRequest(void) ReportData = (uint8_t*)&keyboard_report_sent; ReportSize = sizeof(keyboard_report_sent); break; -#ifdef MOUSE_ENABLE - case MOUSE_INTERFACE: - // TODO: test/check - ReportData = (uint8_t*)&mouse_report_sent; - ReportSize = sizeof(mouse_report_sent); - break; -#endif -#ifdef EXTRAKEY_ENABLE - case EXTRA_INTERFACE: - break; -#endif - case CONSOLE_INTERFACE: - break; } /* Write the report data to the control endpoint */ @@ -252,35 +234,65 @@ void EVENT_USB_Device_ControlRequest(void) case HID_REQ_SetReport: if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) { - Endpoint_ClearSETUP(); - - /* Wait until the LED report has been sent by the host */ - while (!(Endpoint_IsOUTReceived())) - { - if (USB_DeviceState == DEVICE_STATE_Unattached) - return; - } // Interface switch (USB_ControlRequest.wIndex) { case KEYBOARD_INTERFACE: - // TODO: test/check - /* Read in the LED report from the host */ + Endpoint_ClearSETUP(); + + while (!(Endpoint_IsOUTReceived())) { + if (USB_DeviceState == DEVICE_STATE_Unattached) + return; + } keyboard_led_stats = Endpoint_Read_8(); - break; -#ifdef MOUSE_ENABLE - case MOUSE_INTERFACE: - break; -#endif -#ifdef EXTRAKEY_ENABLE - case EXTRA_INTERFACE: - break; -#endif - case CONSOLE_INTERFACE: + + Endpoint_ClearOUT(); + Endpoint_ClearStatusStage(); break; } - Endpoint_ClearOUT(); + } + + break; + + case HID_REQ_GetProtocol: + if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) + { + Endpoint_ClearSETUP(); + while (!(Endpoint_IsINReady())); + Endpoint_Write_8(protocol_report); + Endpoint_ClearIN(); + Endpoint_ClearStatusStage(); + } + + break; + case HID_REQ_SetProtocol: + if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) + { + Endpoint_ClearSETUP(); + Endpoint_ClearStatusStage(); + + protocol_report = ((USB_ControlRequest.wValue & 0xFF) != 0x00); + } + + break; + case HID_REQ_SetIdle: + if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) + { + Endpoint_ClearSETUP(); + Endpoint_ClearStatusStage(); + + idle_duration = ((USB_ControlRequest.wValue & 0xFF00) >> 8); + } + + break; + case HID_REQ_GetIdle: + if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) + { + Endpoint_ClearSETUP(); + while (!(Endpoint_IsINReady())); + Endpoint_Write_8(idle_duration); + Endpoint_ClearIN(); Endpoint_ClearStatusStage(); } @@ -329,23 +341,17 @@ static void send_mouse(report_mouse_t *report) /* Finalize the stream transfer to send the last packet */ Endpoint_ClearIN(); } - mouse_report_sent = *report; #endif } -typedef struct { - uint8_t report_id; - uint16_t usage; -} __attribute__ ((packed)) report_extra_t; - static void send_system(uint16_t data) { + report_extra_t r = { + .report_id = REPORT_ID_SYSTEM, + .usage = data + }; Endpoint_SelectEndpoint(EXTRA_IN_EPNUM); if (Endpoint_IsReadWriteAllowed()) { - report_extra_t r = { - .report_id = REPORT_ID_SYSTEM, - .usage = data - }; Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); Endpoint_ClearIN(); } @@ -353,12 +359,12 @@ static void send_system(uint16_t data) static void send_consumer(uint16_t data) { + report_extra_t r = { + .report_id = REPORT_ID_CONSUMER, + .usage = data + }; Endpoint_SelectEndpoint(EXTRA_IN_EPNUM); if (Endpoint_IsReadWriteAllowed()) { - report_extra_t r = { - .report_id = REPORT_ID_CONSUMER, - .usage = data - }; Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); Endpoint_ClearIN(); } diff --git a/protocol/lufa/lufa.h b/protocol/lufa/lufa.h index efb8c383..71c279b0 100644 --- a/protocol/lufa/lufa.h +++ b/protocol/lufa/lufa.h @@ -1,3 +1,10 @@ +/* + * 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. @@ -32,7 +39,6 @@ #ifndef _LUFA_H_ #define _LUFA_H_ - /* Includes: */ #include #include #include @@ -42,4 +48,11 @@ #include #include + +/* extra report structure */ +typedef struct { + uint8_t report_id; + uint16_t usage; +} __attribute__ ((packed)) report_extra_t; + #endif From f427529a30487de45ebfbe6fbba9c290738878ab Mon Sep 17 00:00:00 2001 From: tmk Date: Sat, 30 Jun 2012 11:19:07 +0900 Subject: [PATCH 10/13] Fix bootloader.c --- common/bootloader.c | 72 +++++++++++++++++++++++-------- keyboard/macway/Makefile.lufa | 13 ++++-- protocol/pjrc.mk | 3 +- protocol/pjrc/bootloader_teensy.c | 40 ----------------- 4 files changed, 64 insertions(+), 64 deletions(-) delete mode 100644 protocol/pjrc/bootloader_teensy.c diff --git a/common/bootloader.c b/common/bootloader.c index 5cbfc72e..cb971c70 100644 --- a/common/bootloader.c +++ b/common/bootloader.c @@ -1,22 +1,56 @@ -/* -Copyright 2011 Jun Wako - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - +#include +#include +#include #include "bootloader.h" +/* Start Bootloader from Application + * See + * http://www.pjrc.com/teensy/jump_to_bootloader.html + * http://www.fourwalledcubicle.com/files/LUFA/Doc/120219/html/_page__software_bootloader_start.html + */ -void bootloader_jump(void) __attribute__ ((weak)); -void bootloader_jump(void) {} +/* Boot Section Size in bytes + * Teensy halfKay 512 + * Atmel DFU loader 4096 + * LUFA bootloader 4096 + */ +#ifndef BOOT_SIZE +#define BOOT_SIZE 512 +#endif + +#define FLASH_SIZE (FLASHEND + 1) +#define BOOTLOADER_START (FLASHEND - BOOT_SIZE) + +void bootloader_jump(void) { + cli(); + // disable watchdog, if enabled + // disable all peripherals + UDCON = 1; + USBCON = (1< -#include -#include -#include "bootloader.h" - -void bootloader_jump(void) { - cli(); - // disable watchdog, if enabled - // disable all peripherals - UDCON = 1; - USBCON = (1< Date: Sat, 30 Jun 2012 13:26:09 +0900 Subject: [PATCH 11/13] Add Makefile.lufa to keyboard/hhkb and hbkb. --- common/bootloader.c | 1 + keyboard/hbkb/Makefile | 57 +---------- keyboard/hbkb/Makefile.lufa | 119 ++++++++++++++++++++++ keyboard/hbkb/Makefile.pjrc | 56 ++++++++++ keyboard/hbkb/config.h | 3 + keyboard/hhkb/Makefile.lufa | 119 ++++++++++++++++++++++ keyboard/hhkb/Makefile.pjrc | 7 +- keyboard/hhkb/{config_pjrc.h => config.h} | 5 +- keyboard/hhkb/matrix.c | 10 +- keyboard/macway/Makefile.lufa | 4 +- keyboard/macway/Makefile.pjrc | 3 +- protocol/pjrc.mk | 3 +- rules.mk | 6 +- 13 files changed, 322 insertions(+), 71 deletions(-) mode change 100644 => 120000 keyboard/hbkb/Makefile create mode 100644 keyboard/hbkb/Makefile.lufa create mode 100644 keyboard/hbkb/Makefile.pjrc create mode 100644 keyboard/hhkb/Makefile.lufa rename keyboard/hhkb/{config_pjrc.h => config.h} (97%) diff --git a/common/bootloader.c b/common/bootloader.c index cb971c70..e45295cd 100644 --- a/common/bootloader.c +++ b/common/bootloader.c @@ -9,6 +9,7 @@ * http://www.fourwalledcubicle.com/files/LUFA/Doc/120219/html/_page__software_bootloader_start.html */ +// TODO: support usbasp /* Boot Section Size in bytes * Teensy halfKay 512 * Atmel DFU loader 4096 diff --git a/keyboard/hbkb/Makefile b/keyboard/hbkb/Makefile deleted file mode 100644 index 26be322e..00000000 --- a/keyboard/hbkb/Makefile +++ /dev/null @@ -1,56 +0,0 @@ -# Target file name (without extension). -TARGET = hbk - -# Directory common source filess exist -TOP_DIR = ../.. - -# Directory keyboard dependent files exist -TARGET_DIR = . - -# keyboard dependent files -SRC = main.c \ - keymap.c \ - matrix.c \ - led.c - -CONFIG_H = config.h - - -# MCU name, you MUST set this to match the board you are using -# type "make clean" after changing this, so all files will be rebuilt -#MCU = at90usb162 # Teensy 1.0 -MCU = atmega32u4 # Teensy 2.0 -#MCU = at90usb646 # Teensy++ 1.0 -#MCU = at90usb1286 # Teensy++ 2.0 - - -# Processor frequency. -# Normally the first thing your program should do is set the clock prescaler, -# so your program will run at the correct speed. You should also set this -# variable to same clock speed. The _delay_ms() macro uses this, and many -# examples use this variable to calculate timings. Do not add a "UL" here. -F_CPU = 16000000 - - -# Build Options -# comment out to disable the options. -# -MOUSEKEY_ENABLE = yes # Mouse keys -#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support -EXTRAKEY_ENABLE = yes # Audio control and System control -#NKRO_ENABLE = yes # USB Nkey Rollover - - - -#---------------- Programming Options -------------------------- -#PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex -PROGRAM_CMD = /opt/dfu-programmer-0.5.2/bin/dfu-programmer $(MCU) erase && \ - /opt/dfu-programmer-0.5.2/bin/dfu-programmer $(MCU) flash $(TARGET).hex && \ - /opt/dfu-programmer-0.5.2/bin/dfu-programmer $(MCU) start - - - -include $(TOP_DIR)/protocol/pjrc.mk -include $(TOP_DIR)/protocol.mk -include $(TOP_DIR)/common.mk -include $(TOP_DIR)/rules.mk diff --git a/keyboard/hbkb/Makefile b/keyboard/hbkb/Makefile new file mode 120000 index 00000000..f00d036d --- /dev/null +++ b/keyboard/hbkb/Makefile @@ -0,0 +1 @@ +Makefile.lufa \ No newline at end of file diff --git a/keyboard/hbkb/Makefile.lufa b/keyboard/hbkb/Makefile.lufa new file mode 100644 index 00000000..c73a0ca7 --- /dev/null +++ b/keyboard/hbkb/Makefile.lufa @@ -0,0 +1,119 @@ +#---------------------------------------------------------------------------- +# 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. +# Please customize your programmer settings(PROGRAM_CMD) +# +# make teensy = Download the hex file to the device, using teensy_loader_cli. +# (must have teensy_loader_cli installed). +# +# 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 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". +#---------------------------------------------------------------------------- + +# Target file name (without extension). +TARGET = hbkb_lufa + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + + +# List C source files here. (C dependencies are automatically generated.) +SRC += keymap.c \ + matrix.c \ + led.c + +CONFIG_H = config.h + + +# MCU name +#MCU = at90usb1287 +MCU = atmega32u4 + +# 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 + + +# +# LUFA specific +# +# Target architecture (see library "Board Types" documentation). +ARCH = AVR8 + +# 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) + + +# Build Options +# comment out to disable the options. +# +MOUSEKEY_ENABLE = yes # Mouse keys +EXTRAKEY_ENABLE = yes # Audio control and System control +#NKRO_ENABLE = yes # USB Nkey Rollover +#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support + + +# Boot Section Size in bytes +# Teensy halfKay 512 +# Atmel DFU loader 4096 +# LUFA bootloader 4096 +OPT_DEFS += -DBOOT_SIZE=4096 + + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + +include $(TOP_DIR)/protocol/lufa.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk diff --git a/keyboard/hbkb/Makefile.pjrc b/keyboard/hbkb/Makefile.pjrc new file mode 100644 index 00000000..159f56b4 --- /dev/null +++ b/keyboard/hbkb/Makefile.pjrc @@ -0,0 +1,56 @@ +# Target file name (without extension). +TARGET = hbkb + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# keyboard dependent files +SRC = main.c \ + keymap.c \ + matrix.c \ + led.c + +CONFIG_H = config.h + + +# MCU name, you MUST set this to match the board you are using +# type "make clean" after changing this, so all files will be rebuilt +#MCU = at90usb162 # Teensy 1.0 +MCU = atmega32u4 # Teensy 2.0 +#MCU = at90usb646 # Teensy++ 1.0 +#MCU = at90usb1286 # Teensy++ 2.0 + + +# Processor frequency. +# Normally the first thing your program should do is set the clock prescaler, +# so your program will run at the correct speed. You should also set this +# variable to same clock speed. The _delay_ms() macro uses this, and many +# examples use this variable to calculate timings. Do not add a "UL" here. +F_CPU = 16000000 + + +# Build Options +# comment out to disable the options. +# +MOUSEKEY_ENABLE = yes # Mouse keys +#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +EXTRAKEY_ENABLE = yes # Audio control and System control +#NKRO_ENABLE = yes # USB Nkey Rollover + + + +#---------------- Programming Options -------------------------- +#PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex +PROGRAM_CMD = /opt/dfu-programmer-0.5.2/bin/dfu-programmer $(MCU) erase && \ + /opt/dfu-programmer-0.5.2/bin/dfu-programmer $(MCU) flash $(TARGET).hex && \ + /opt/dfu-programmer-0.5.2/bin/dfu-programmer $(MCU) start + + + +include $(TOP_DIR)/protocol/pjrc.mk +include $(TOP_DIR)/protocol.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk diff --git a/keyboard/hbkb/config.h b/keyboard/hbkb/config.h index 5262399d..deaabb24 100644 --- a/keyboard/hbkb/config.h +++ b/keyboard/hbkb/config.h @@ -24,7 +24,10 @@ along with this program. If not, see . #define VENDOR_ID 0xFEED #define PRODUCT_ID 0xBB00 #define MANUFACTURER t.m.k. +#define DEVICE_VER 0x0100 #define PRODUCT Happy Buckling Keyboard + + #define DESCRIPTION mod version of IBM Model M keyboard diff --git a/keyboard/hhkb/Makefile.lufa b/keyboard/hhkb/Makefile.lufa new file mode 100644 index 00000000..cdd68f40 --- /dev/null +++ b/keyboard/hhkb/Makefile.lufa @@ -0,0 +1,119 @@ +#---------------------------------------------------------------------------- +# 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. +# Please customize your programmer settings(PROGRAM_CMD) +# +# make teensy = Download the hex file to the device, using teensy_loader_cli. +# (must have teensy_loader_cli installed). +# +# 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 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". +#---------------------------------------------------------------------------- + +# Target file name (without extension). +TARGET = hhkb_lufa + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + + +# List C source files here. (C dependencies are automatically generated.) +SRC += keymap.c \ + matrix.c \ + led.c + +CONFIG_H = config.h + + +# MCU name +MCU = at90usb1286 +#MCU = atmega32u4 + +# 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 + + +# +# LUFA specific +# +# Target architecture (see library "Board Types" documentation). +ARCH = AVR8 + +# 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) + + +# Build Options +# comment out to disable the options. +# +MOUSEKEY_ENABLE = yes # Mouse keys +EXTRAKEY_ENABLE = yes # Audio control and System control +#NKRO_ENABLE = yes # USB Nkey Rollover +#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support + + +# Boot Section Size in bytes +# Teensy halfKay 512 +# Atmel DFU loader 4096 +# LUFA bootloader 4096 +#OPT_DEFS += -DBOOT_SIZE=4096 + + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + +include $(TOP_DIR)/protocol/lufa.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk diff --git a/keyboard/hhkb/Makefile.pjrc b/keyboard/hhkb/Makefile.pjrc index f6d133ea..f8836a2c 100644 --- a/keyboard/hhkb/Makefile.pjrc +++ b/keyboard/hhkb/Makefile.pjrc @@ -13,12 +13,11 @@ TOP_DIR = ../.. TARGET_DIR = . # keyboard dependent files -SRC = main.c \ - keymap.c \ +SRC = keymap.c \ matrix.c \ led.c -CONFIG_H = config_pjrc.h +CONFIG_H = config.h # MCU name, you MUST set this to match the board you are using @@ -53,8 +52,8 @@ PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex # Search Path VPATH = $(TARGET_DIR) +VPATH = $(TOP_DIR) include $(TOP_DIR)/protocol/pjrc.mk -include $(TOP_DIR)/protocol.mk include $(TOP_DIR)/common.mk include $(TOP_DIR)/rules.mk diff --git a/keyboard/hhkb/config_pjrc.h b/keyboard/hhkb/config.h similarity index 97% rename from keyboard/hhkb/config_pjrc.h rename to keyboard/hhkb/config.h index fffe3522..91446466 100644 --- a/keyboard/hhkb/config_pjrc.h +++ b/keyboard/hhkb/config.h @@ -21,11 +21,14 @@ along with this program. If not, see . /* controller configuration */ #include "controller_teensy.h" + #define VENDOR_ID 0xFEED -#define PRODUCT_ID 0xCAFE +#define PRODUCT_ID 0xCAFF #define DEVICE_VER 0x0101 #define MANUFACTURER t.m.k. #define PRODUCT HHKB mod + + #define DESCRIPTION t.m.k. keyboard firmware for HHKB mod diff --git a/keyboard/hhkb/matrix.c b/keyboard/hhkb/matrix.c index 350066b9..79d2d987 100644 --- a/keyboard/hhkb/matrix.c +++ b/keyboard/hhkb/matrix.c @@ -68,8 +68,8 @@ static bool matrix_has_ghost_in_row(uint8_t row); // key: on: 0/off: 1 // prev: unknown: output previous key state(negated)? -#ifdef HOST_PJRC -// Ports for Teensy +#if defined(__AVR_AT90USB1286__) +// Ports for Teensy++ // row: PB0-2 // col: PB3-5,6 // key: PE6(pull-uped) @@ -90,7 +90,8 @@ static bool matrix_has_ghost_in_row(uint8_t row); #define KEY_PREV_OFF() (PORTE &= ~(1<<7)) #define KEY_POWER_ON() #define KEY_POWER_OFF() -#else + +#elif defined(__AVR_ATmega328P__) // Ports for V-USB // key: PB0(pull-uped) // prev: PB1 @@ -126,6 +127,9 @@ static bool matrix_has_ghost_in_row(uint8_t row); DDRC &= ~0x0F; \ PORTC &= ~0x0F; \ } while (0) + +#else +# error "define code for matrix scan" #endif diff --git a/keyboard/macway/Makefile.lufa b/keyboard/macway/Makefile.lufa index 2f2b6401..9c9388ee 100644 --- a/keyboard/macway/Makefile.lufa +++ b/keyboard/macway/Makefile.lufa @@ -107,9 +107,7 @@ EXTRAKEY_ENABLE = yes # Audio control and System control # Teensy halfKay 512 # Atmel DFU loader 4096 # LUFA bootloader 4096 -#ifndef BOOT_SIZE -#define BOOT_SIZE 512 -#endif +#OPT_DEFS += -DBOOT_SIZE=4096 # Search Path diff --git a/keyboard/macway/Makefile.pjrc b/keyboard/macway/Makefile.pjrc index d2fb8ff2..ecc236e3 100644 --- a/keyboard/macway/Makefile.pjrc +++ b/keyboard/macway/Makefile.pjrc @@ -48,8 +48,7 @@ TOP_DIR = ../.. TARGET_DIR = . # keyboard dependent files -SRC = protocol/pjrc/main.c \ - keymap.c \ +SRC = keymap.c \ matrix.c \ led.c diff --git a/protocol/pjrc.mk b/protocol/pjrc.mk index 8aff6f28..cccdf620 100644 --- a/protocol/pjrc.mk +++ b/protocol/pjrc.mk @@ -2,7 +2,8 @@ PJRC_DIR = protocol/pjrc OPT_DEFS += -DHOST_PJRC -SRC += $(PJRC_DIR)/pjrc.c \ +SRC += $(PJRC_DIR)/main.c \ + $(PJRC_DIR)/pjrc.c \ $(PJRC_DIR)/usb_keyboard.c \ $(PJRC_DIR)/usb_debug.c \ $(PJRC_DIR)/usb.c diff --git a/rules.mk b/rules.mk index a58de2f1..e561eae6 100644 --- a/rules.mk +++ b/rules.mk @@ -416,6 +416,10 @@ dfu: $(TARGET).hex dfu-programmer $(MCU) erase dfu-programmer $(MCU) flash $(TARGET).hex dfu-programmer $(MCU) reset + +dfu-start: + dfu-programmer $(MCU) reset + dfu-programmer $(MCU) start flip-ee: $(TARGET).hex $(TARGET).eep $(COPY) $(TARGET).eep $(TARGET)eep.hex @@ -599,4 +603,4 @@ $(shell mkdir $(OBJDIR) 2>/dev/null) .PHONY : all begin finish end sizebefore sizeafter gccversion \ build elf hex eep lss sym coff extcoff \ clean clean_list debug gdb-config show_path \ -program teensy dfu flip dfu-ee flip-ee +program teensy dfu flip dfu-ee flip-ee dfu-start From 6d79e6579f1b769f3547856b8af56bd357580adf Mon Sep 17 00:00:00 2001 From: tmk Date: Sat, 30 Jun 2012 14:44:14 +0900 Subject: [PATCH 12/13] Add support of USBasp bootloader. --- common/bootloader.c | 30 ++++++++++++++++++++ protocol/vusb.mk | 12 ++++---- protocol/vusb/bootloader_usbasp.c | 47 ------------------------------- 3 files changed, 37 insertions(+), 52 deletions(-) delete mode 100644 protocol/vusb/bootloader_usbasp.c diff --git a/common/bootloader.c b/common/bootloader.c index e45295cd..612b9496 100644 --- a/common/bootloader.c +++ b/common/bootloader.c @@ -24,12 +24,22 @@ void bootloader_jump(void) { cli(); + + // + //Teensy + // +#if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) // disable watchdog, if enabled // disable all peripherals UDCON = 1; USBCON = (1< - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include -#include -#include "bootloader.h" - - -void bootloader_jump(void) { - cli(); - // This makes custom USBasploader come up. - MCUSR = 0; - - // ATmega168PA - // initialize ports - PORTB = 0; PORTC= 0; PORTD = 0; - DDRB = 0; DDRC= 0; DDRD = 0; - - // disable interrupts - EIMSK = 0; EECR = 0; SPCR = 0; - ACSR = 0; SPMCSR = 0; WDTCSR = 0; PCICR = 0; - TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; - ADCSRA = 0; TWCR = 0; UCSR0B = 0; - - // Boot Loader Section Start Address: - // BOOTSZ Size Address - // (lock bit) (word) (word) (byte) - // '11' 128 0x1F80 0x3F00 - // '10' 256 0x1F00 0x3E00 - // '01' 512 0x1E00 0x3C00 - // '00' 1024 0x1C00 0x3800 - asm volatile("jmp 0x3800"); -} From 2769f09d11a4c45362f2e6137f2469d057d8757e Mon Sep 17 00:00:00 2001 From: tmk Date: Sat, 30 Jun 2012 14:44:59 +0900 Subject: [PATCH 13/13] Fix Makefiles. --- converter/adb_usb/Makefile | 14 ++++---------- converter/m0110_usb/Makefile | 7 +++++-- converter/news_usb/Makefile.pjrc | 7 +++++-- converter/ps2_usb/Makefile | 7 +++++-- converter/ps2_usb/Makefile.pjrc_usart | 7 +++++-- converter/ps2_usb/Makefile.vusb | 15 +++++++++++++-- converter/terminal_usb/Makefile.102_pjrc | 7 +++++-- converter/terminal_usb/Makefile.122_pjrc | 7 +++++-- converter/x68k_usb/Makefile | 7 +++++-- 9 files changed, 52 insertions(+), 26 deletions(-) diff --git a/converter/adb_usb/Makefile b/converter/adb_usb/Makefile index 248261df..e9a90695 100644 --- a/converter/adb_usb/Makefile +++ b/converter/adb_usb/Makefile @@ -8,8 +8,7 @@ TOP_DIR = ../.. TARGET_DIR = . # keyboard dependent files -SRC = main.c \ - keymap.c \ +SRC = keymap.c \ matrix.c \ led.c \ adb.c @@ -42,16 +41,11 @@ EXTRAKEY_ENABLE = yes # Audio control and System control #NKRO_ENABLE = yes # USB Nkey Rollover - -#---------------- Programming Options -------------------------- -PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex - - +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) include $(TOP_DIR)/protocol/pjrc.mk include $(TOP_DIR)/protocol.mk include $(TOP_DIR)/common.mk include $(TOP_DIR)/rules.mk - -dfu: PROGRAM_CMD = dfu-programmer atmega32u4 flash $(TARGET).hex -dfu: program diff --git a/converter/m0110_usb/Makefile b/converter/m0110_usb/Makefile index 4a687b93..1fee258a 100644 --- a/converter/m0110_usb/Makefile +++ b/converter/m0110_usb/Makefile @@ -8,8 +8,7 @@ TOP_DIR = ../.. TARGET_DIR = . # keyboard dependent files -SRC = main.c \ - keymap.c \ +SRC = keymap.c \ matrix.c \ led.c \ m0110.c @@ -47,6 +46,10 @@ EXTRAKEY_ENABLE = yes # Audio control and System control PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + include $(TOP_DIR)/protocol/pjrc.mk include $(TOP_DIR)/protocol.mk diff --git a/converter/news_usb/Makefile.pjrc b/converter/news_usb/Makefile.pjrc index 376133ad..3233463d 100644 --- a/converter/news_usb/Makefile.pjrc +++ b/converter/news_usb/Makefile.pjrc @@ -13,8 +13,7 @@ TOP_DIR = ../.. TARGET_DIR = . # keyboard dependent files -SRC = main.c \ - keymap.c \ +SRC = keymap.c \ matrix.c \ led.c \ news.c @@ -51,6 +50,10 @@ NKRO_ENABLE = yes # USB Nkey Rollover PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + include $(TOP_DIR)/protocol/pjrc.mk include $(TOP_DIR)/protocol.mk diff --git a/converter/ps2_usb/Makefile b/converter/ps2_usb/Makefile index 0bba191a..1278a74b 100644 --- a/converter/ps2_usb/Makefile +++ b/converter/ps2_usb/Makefile @@ -13,8 +13,7 @@ TOP_DIR = ../.. TARGET_DIR = . # keyboard dependent files -SRC = main.c \ - keymap.c \ +SRC = keymap.c \ matrix.c \ led.c \ ps2.c @@ -51,6 +50,10 @@ NKRO_ENABLE = yes # USB Nkey Rollover PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + include $(TOP_DIR)/protocol/pjrc.mk include $(TOP_DIR)/protocol.mk diff --git a/converter/ps2_usb/Makefile.pjrc_usart b/converter/ps2_usb/Makefile.pjrc_usart index 3dad7e2f..dd74712e 100644 --- a/converter/ps2_usb/Makefile.pjrc_usart +++ b/converter/ps2_usb/Makefile.pjrc_usart @@ -13,8 +13,7 @@ TOP_DIR = ../.. TARGET_DIR = . # keyboard dependent files -SRC = main.c \ - keymap.c \ +SRC = keymap.c \ matrix.c \ led.c \ ps2_usart.c @@ -51,6 +50,10 @@ NKRO_ENABLE = yes # USB Nkey Rollover PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + include $(TOP_DIR)/protocol/pjrc.mk include $(TOP_DIR)/protocol.mk diff --git a/converter/ps2_usb/Makefile.vusb b/converter/ps2_usb/Makefile.vusb index 4d5240c3..b08d30d5 100644 --- a/converter/ps2_usb/Makefile.vusb +++ b/converter/ps2_usb/Makefile.vusb @@ -13,8 +13,7 @@ TOP_DIR = ../.. TARGET_DIR = . # keyboard dependent files -SRC = main.c \ - keymap.c \ +SRC = keymap.c \ matrix.c \ led.c \ ps2_usart.c @@ -85,6 +84,18 @@ AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) PROGRAM_CMD = $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) +# Boot Section Size in bytes +# Teensy halfKay 512 +# Atmel DFU loader 4096 +# LUFA bootloader 4096 +# USBasp 2048 +OPT_DEFS += -DBOOT_SIZE=2048 + + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + include $(TOP_DIR)/protocol/vusb.mk include $(TOP_DIR)/protocol.mk diff --git a/converter/terminal_usb/Makefile.102_pjrc b/converter/terminal_usb/Makefile.102_pjrc index e9d14e7a..e2d1a00a 100644 --- a/converter/terminal_usb/Makefile.102_pjrc +++ b/converter/terminal_usb/Makefile.102_pjrc @@ -13,8 +13,7 @@ TOP_DIR = ../.. TARGET_DIR = . # keyboard dependent files -SRC = main.c \ - keymap_102.c \ +SRC = keymap_102.c \ matrix.c \ led.c \ ps2.c @@ -51,6 +50,10 @@ NKRO_ENABLE = yes # USB Nkey Rollover PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + include $(TOP_DIR)/protocol/pjrc.mk include $(TOP_DIR)/protocol.mk diff --git a/converter/terminal_usb/Makefile.122_pjrc b/converter/terminal_usb/Makefile.122_pjrc index bec00510..ee42dd74 100644 --- a/converter/terminal_usb/Makefile.122_pjrc +++ b/converter/terminal_usb/Makefile.122_pjrc @@ -13,8 +13,7 @@ TOP_DIR = ../.. TARGET_DIR = . # keyboard dependent files -SRC = main.c \ - keymap_122.c \ +SRC = keymap_122.c \ matrix.c \ led.c \ ps2.c @@ -51,6 +50,10 @@ F_CPU = 16000000 PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + include $(TOP_DIR)/protocol/pjrc.mk include $(TOP_DIR)/protocol.mk diff --git a/converter/x68k_usb/Makefile b/converter/x68k_usb/Makefile index c3b5fa29..62b976c5 100644 --- a/converter/x68k_usb/Makefile +++ b/converter/x68k_usb/Makefile @@ -13,8 +13,7 @@ TOP_DIR = ../.. TARGET_DIR = . # keyboard dependent files -SRC = main.c \ - keymap.c \ +SRC = keymap.c \ matrix.c \ led.c \ x68k.c @@ -80,6 +79,10 @@ AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) PROGRAM_CMD = dfu-programmer atmega32u4 flash $(TARGET).hex +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + include $(TOP_DIR)/protocol/pjrc.mk include $(TOP_DIR)/protocol.mk