diff --git a/.gitignore b/.gitignore index c25d41d2..36d378de 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ *.map *.sym tags +*.swp diff --git a/.gitmodules b/.gitmodules index 3e34a635..17a20dec 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "protocol/usb_hid/USB_Host_Shield_2.0"] path = protocol/usb_hid/USB_Host_Shield_2.0 url = git@github.com:tmk/USB_Host_Shield_2.0.git +[submodule "protocol/lufa/LUFA-git"] + path = protocol/lufa/LUFA-git + url = https://github.com/abcminiuser/lufa.git diff --git a/README.md b/README.md index a561b38e..6596dc33 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ You can find some keyboard specific projects under `converter` and `keyboard` di * [IIgs_Standard](keyboard/IIgs/) - Apple [IIGS] keyboard mod(by JeffreySung) * [macway](keyboard/macway/) - [Compact keyboard mod][GH_macway] [retired] * [KMAC](keyboard/kmac/) - Korean custom keyboard +* [Lightsaber](keyboard/lightsaber/) - Korean custom keyboard [GH_macway]: http://geekhack.org/showwiki.php?title=Island:11930 [GH_hhkb]: http://geekhack.org/showwiki.php?title=Island:12047 diff --git a/common.mk b/common.mk index fb4ca939..06f57465 100644 --- a/common.mk +++ b/common.mk @@ -22,7 +22,7 @@ ifdef BOOTMAGIC_ENABLE OPT_DEFS += -DBOOTMAGIC_ENABLE endif -ifdef MOUSEKEY_ENABLE +ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE) SRC += $(COMMON_DIR)/mousekey.c OPT_DEFS += -DMOUSEKEY_ENABLE OPT_DEFS += -DMOUSE_ENABLE @@ -54,6 +54,11 @@ ifdef SLEEP_LED_ENABLE OPT_DEFS += -DNO_SUSPEND_POWER_DOWN endif +ifdef BREATHING_LED_ENABLE + SRC += $(COMMON_DIR)/breathing_led.c + OPT_DEFS += -DBREATHING_LED_ENABLE +endif + ifdef BACKLIGHT_ENABLE SRC += $(COMMON_DIR)/backlight.c OPT_DEFS += -DBACKLIGHT_ENABLE @@ -69,6 +74,11 @@ ifdef KEYMAP_IN_EEPROM_ENABLE OPT_DEFS += -DKEYMAP_IN_EEPROM_ENABLE endif +ifdef LED_MATRIX_ENABLE + SRC += $(COMMON_DIR)/led_matrix.c + OPT_DEFS += -DLED_MATRIX_ENABLE +endif + # Version string OPT_DEFS += -DVERSION=$(shell (git describe --always --dirty || echo 'unknown') 2> /dev/null) diff --git a/common/action.c b/common/action.c index e6938f5a..fddb97c5 100644 --- a/common/action.c +++ b/common/action.c @@ -294,7 +294,7 @@ void process_action(keyrecord_t *record) #ifdef BACKLIGHT_ENABLE case ACT_BACKLIGHT: if (!event.pressed) { - switch (action.backlight.id) { + switch (action.backlight.opt) { case BACKLIGHT_INCREASE: backlight_increase(); break; @@ -307,6 +307,9 @@ void process_action(keyrecord_t *record) case BACKLIGHT_STEP: backlight_step(); break; + case BACKLIGHT_LEVEL: + backlight_level(action.backlight.level); + break; } } break; diff --git a/common/action_code.h b/common/action_code.h index 8df86b11..50112d4d 100644 --- a/common/action_code.h +++ b/common/action_code.h @@ -87,7 +87,7 @@ along with this program. If not, see . * 1100|1111| id(8) Macro record? * * ACT_BACKLIGHT(1101): - * 1101|xxxx| id(8) Backlight commands + * 1101|opt |level(8) Backlight commands * * ACT_COMMAND(1110): * 1110|opt | id(8) Built-in Command exec @@ -163,7 +163,9 @@ typedef union { uint8_t kind :4; } usage; struct action_backlight { - uint8_t id :8; + uint8_t level :8; + uint8_t opt :4; + uint8_t kind :4; } backlight; struct action_command { uint8_t id :8; @@ -282,21 +284,23 @@ enum layer_pram_tap_op { /* * Extensions */ -enum backlight_id { +enum backlight_opt { BACKLIGHT_INCREASE = 0, BACKLIGHT_DECREASE = 1, BACKLIGHT_TOGGLE = 2, BACKLIGHT_STEP = 3, + BACKLIGHT_LEVEL = 4, }; /* Macro */ #define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) #define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id)) #define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt)<<8 | (id)) /* Backlight */ -#define ACTION_BACKLIGHT_INCREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_INCREASE) -#define ACTION_BACKLIGHT_DECREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE) -#define ACTION_BACKLIGHT_TOGGLE() ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE) -#define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP) +#define ACTION_BACKLIGHT_INCREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_INCREASE << 8) +#define ACTION_BACKLIGHT_DECREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE << 8) +#define ACTION_BACKLIGHT_TOGGLE() ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE << 8) +#define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP << 8) +#define ACTION_BACKLIGHT_LEVEL(level) ACTION(ACT_BACKLIGHT, BACKLIGHT_LEVEL << 8 | level) /* Command */ #define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr)) /* Function */ diff --git a/common/backlight.c b/common/backlight.c index 00dc04a0..c3001dd0 100644 --- a/common/backlight.c +++ b/common/backlight.c @@ -33,6 +33,16 @@ void backlight_init(void) void backlight_increase(void) { +#ifdef BACKLIGHT_CUSTOM + if (backlight_config.enable) { + if (backlight_config.level < BACKLIGHT_LEVELS) { + backlight_config.level++; + eeconfig_write_backlight(backlight_config.raw); + } + dprintf("backlight custom increase: %u\n", backlight_config.level); + backlight_set(backlight_config.level); + } +#else if(backlight_config.level < BACKLIGHT_LEVELS) { backlight_config.level++; @@ -41,10 +51,22 @@ void backlight_increase(void) } dprintf("backlight increase: %u\n", backlight_config.level); backlight_set(backlight_config.level); +#endif } void backlight_decrease(void) { +#ifdef BACKLIGHT_CUSTOM + if (backlight_config.enable) { + if(backlight_config.level > 1) + { + backlight_config.level--; + eeconfig_write_backlight(backlight_config.raw); + } + dprintf("backlight custom decrease: %u\n", backlight_config.level); + backlight_set(backlight_config.level); + } +#else if(backlight_config.level > 0) { backlight_config.level--; @@ -53,11 +75,18 @@ void backlight_decrease(void) } dprintf("backlight decrease: %u\n", backlight_config.level); backlight_set(backlight_config.level); +#endif } void backlight_toggle(void) { backlight_config.enable ^= 1; + if (backlight_config.enable) + { + if (backlight_config.level == 0) { + backlight_config.level = 1; + } + } eeconfig_write_backlight(backlight_config.raw); dprintf("backlight toggle: %u\n", backlight_config.enable); backlight_set(backlight_config.enable ? backlight_config.level : 0); @@ -75,3 +104,11 @@ void backlight_step(void) dprintf("backlight step: %u\n", backlight_config.level); backlight_set(backlight_config.level); } + +void backlight_level(uint8_t level) +{ + backlight_config.level ^= level; + backlight_config.enable = !!backlight_config.level; + eeconfig_write_backlight(backlight_config.raw); + backlight_set(backlight_config.level); +} diff --git a/common/backlight.h b/common/backlight.h index 685c422a..525ec8bb 100644 --- a/common/backlight.h +++ b/common/backlight.h @@ -24,18 +24,17 @@ along with this program. If not, see . typedef union { uint8_t raw; struct { - bool enable:1; - uint8_t level:7; + bool enable :1; + uint8_t level :7; }; } backlight_config_t; void backlight_init(void); - void backlight_increase(void); void backlight_decrease(void); void backlight_toggle(void); void backlight_step(void); - void backlight_set(uint8_t level); +void backlight_level(uint8_t level); #endif diff --git a/common/bootmagic.c b/common/bootmagic.c index 0baff830..1668ee49 100644 --- a/common/bootmagic.c +++ b/common/bootmagic.c @@ -31,6 +31,7 @@ void bootmagic(void) /* eeconfig clear */ if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) { + eeconfig_disable(); eeconfig_init(); #ifdef KEYMAP_IN_EEPROM_ENABLE write_keymap_to_eeprom(); diff --git a/common/breathing_led.c b/common/breathing_led.c new file mode 100644 index 00000000..4e4822f8 --- /dev/null +++ b/common/breathing_led.c @@ -0,0 +1,73 @@ +#include +#include +#include "led.h" +#include "breathing_led.h" +#include "debug.h" + +#define BREATHING_LED_TIMER_TOP F_CPU/256 + +static uint8_t breathing_led_duration = 0; + +void breathing_led_init(void) +{ + /* Timer3 setup */ + /* CTC mode */ + TCCR3B |= (1<>8)&0xff; + OCR3AL = BREATHING_LED_TIMER_TOP&0xff; + SREG = sreg; +} + +void breathing_led_enable(void) +{ + /* Enable Compare Match Interrupt */ + TIMSK3 |= (1< breathing_led_duration) { + step = 0; + breathing_led_set_raw(pgm_read_byte(&breathing_table[index])); + index++; + } +} diff --git a/common/breathing_led.h b/common/breathing_led.h new file mode 100644 index 00000000..b3a9e775 --- /dev/null +++ b/common/breathing_led.h @@ -0,0 +1,25 @@ +#ifndef BREATHING_LED_H +#define BREATHING_LED_H + + +#ifdef BREATHING_LED_ENABLE + +void breathing_led_init(void); +void breathing_led_enable(void); +void breathing_led_disable(void); +void breathing_led_toggle(void); +void breathing_led_set_duration(uint8_t dur); +void breathing_led_set_raw(uint8_t raw); + +#else + +#define breathing_led_init() +#define breathing_led_enable() +#define breathing_led_disable() +#define breathing_led_toggle() +#define breathing_led_set_duration() +#define breathing_led_set_raw() + +#endif + +#endif diff --git a/common/command.c b/common/command.c index f6f27695..d2f8eb83 100644 --- a/common/command.c +++ b/common/command.c @@ -301,13 +301,13 @@ static bool command_common(uint8_t code) case KC_S: print("\n\n----- Status -----\n"); print_val_hex8(host_keyboard_leds()); + print_val_hex8(keyboard_protocol); + print_val_hex8(keyboard_idle); #ifdef PROTOCOL_PJRC print_val_hex8(UDCON); print_val_hex8(UDIEN); print_val_hex8(UDINT); print_val_hex8(usb_keyboard_leds); - print_val_hex8(usb_keyboard_protocol); - print_val_hex8(usb_keyboard_idle_config); print_val_hex8(usb_keyboard_idle_count); #endif diff --git a/common/eeconfig.c b/common/eeconfig.c index 5bd47dc6..5aadf1c5 100644 --- a/common/eeconfig.c +++ b/common/eeconfig.c @@ -2,6 +2,7 @@ #include #include #include "eeconfig.h" +#include "keymap_ex.h" void eeconfig_init(void) { @@ -13,6 +14,9 @@ void eeconfig_init(void) #ifdef BACKLIGHT_ENABLE eeprom_write_byte(EECONFIG_BACKLIGHT, 0); #endif +#ifdef KEYMAP_EX_ENABLE + keymap_ex_init(); +#endif } void eeconfig_enable(void) @@ -22,6 +26,9 @@ void eeconfig_enable(void) void eeconfig_disable(void) { +#ifdef KEYMAP_EX_ENABLE + keymap_ex_disable(); +#endif eeprom_write_word(EECONFIG_MAGIC, 0xFFFF); } diff --git a/common/host.c b/common/host.c index 1eafef75..2e56971b 100644 --- a/common/host.c +++ b/common/host.c @@ -24,7 +24,7 @@ along with this program. If not, see . #ifdef NKRO_ENABLE -bool keyboard_nkro = false; +bool keyboard_nkro = true; #endif static host_driver_t *driver; diff --git a/common/host.h b/common/host.h index 8ff26298..a56e6c3b 100644 --- a/common/host.h +++ b/common/host.h @@ -32,6 +32,9 @@ extern "C" { extern bool keyboard_nkro; #endif +uint8_t keyboard_idle; +uint8_t keyboard_protocol; + /* host driver */ void host_set_driver(host_driver_t *driver); diff --git a/common/keyboard.c b/common/keyboard.c index 20dfbca8..08f86be3 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -31,6 +31,7 @@ along with this program. If not, see . #include "bootmagic.h" #include "eeconfig.h" #include "backlight.h" +#include "breathing_led.h" #include "keymap_in_eeprom.h" #ifdef MOUSEKEY_ENABLE # include "mousekey.h" @@ -62,8 +63,15 @@ void keyboard_init(void) { timer_init(); matrix_init(); + +#ifdef LED_MATRIX_ENABLE + led_matrix_init(); +#endif + #ifdef PS2_MOUSE_ENABLE - ps2_mouse_init(); + if (ps2_enabled()) { + ps2_mouse_init(); + } #endif #ifdef BOOTMAGIC_ENABLE @@ -74,6 +82,10 @@ void keyboard_init(void) backlight_init(); #endif +#ifdef BREATHING_LED_ENABLE + breathing_led_init(); +#endif + #ifdef KEYMAP_IN_EEPROM_ENABLE keymap_in_eeprom_init(); #endif @@ -128,7 +140,9 @@ MATRIX_LOOP_END: #endif #ifdef PS2_MOUSE_ENABLE - ps2_mouse_task(); + if (ps2_enabled()) { + ps2_mouse_task(); + } #endif // update LED diff --git a/common/led_matrix.c b/common/led_matrix.c new file mode 100644 index 00000000..e5a4629f --- /dev/null +++ b/common/led_matrix.c @@ -0,0 +1,91 @@ +/* +Copyright 2013,2014 Kai Ryu + +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 "led_matrix.h" + +#define LED_MATRIX_TIMER_TOP F_CPU/(256*64)/LED_MATRIX_ROWS + +static led_matrix_element_t led_matrix[LED_MATRIX_ROWS][LED_MATRIX_COLS]; + +void led_matrix_init(void) +{ + led_matrix_unselect_rows(); + led_matrix_write_cols(0); + /* Timer1 setup */ + /* CTC mode */ + TCCR1B |= (1<> 8) & 0xFF; + OCR1AL = LED_MATRIX_TIMER_TOP & 0xFF; + SREG = sreg; +} + +void led_matrix_enable(void) +{ + /* Enable Compare Match Interrupt */ + TIMSK1 |= _BV(OCIE1A); +} + +void led_matrix_disable(void) +{ + /* Disable Compare Match Interrupt */ + TIMSK1 &= ~_BV(OCIE1A); +} + +inline +led_matrix_row_t led_matrix_make_cols(uint8_t row, uint8_t pwm) +{ + led_matrix_row_t cols = 0; + for (uint8_t i = 0; i < LED_MATRIX_COLS; i++) { + cols |= ((led_matrix[row][i].value < pwm ? 1 : 0) << i); + } + return cols; +} + +inline +void led_matrix_set_value(uint8_t row, uint8_t col, uint8_t value) +{ + led_matrix[row][col].value = value; +} + +inline +void led_matrix_set_delta(uint8_t row, uint8_t col, int8_t delta) +{ + led_matrix[row][col].delta = delta; +} + +ISR(TIMER1_COMPA_vect) +{ + static uint8_t row = 0; + static uint8_t pwm = 0; + + row = (row + 1) % LED_MATRIX_ROWS; + pwm++; + + led_matrix_select_row(row); + _delay_us(10); + led_matrix_write_cols(led_matrix_make_cols(row, pwm)); + _delay_us(10); + led_matrix_unselect_rows(); +} diff --git a/common/led_matrix.h b/common/led_matrix.h new file mode 100644 index 00000000..513f2c8d --- /dev/null +++ b/common/led_matrix.h @@ -0,0 +1,65 @@ +/* +Copyright 2013,2014 Kai Ryu + +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 LED_MATRIX_H +#define LED_MATRIX_H + +#include +#include + +#if (LED_MATRIX_COLS <= 8) +typedef uint8_t led_matrix_row_t; +#elif (LED_MATRIX_COLS <= 16) +typedef uint16_t led_matrix_row_t; +#elif (LED_MATRIX_COLS <= 32) +typedef uint32_t led_matrix_row_t; +#else +#error "LED_MATRIX_COLS: invalid value" +#endif + +typedef struct { + union { + int8_t delta; + struct { + bool direction:1; + }; + }; + uint8_t value; +} led_matrix_element_t; + +#ifdef LED_MATRIX_ENABLE +void led_matrix_init(void); +void led_matrix_enable(void); +void led_matrix_disable(void); +void led_matrix_init_cols(void); +led_matrix_row_t led_matrix_make_cols(uint8_t row, uint8_t pwm); +void led_matrix_set_value(uint8_t row, uint8_t col, uint8_t value); +void led_matrix_set_delta(uint8_t row, uint8_t col, int8_t delta); +extern void led_matrix_write_cols(led_matrix_row_t cols); +extern void led_matrix_unselect_rows(void); +extern void led_matrix_select_row(uint8_t row); +#else +#define led_matrix_init() +#define led_matrix_enable() +#define led_matrix_disable() +#define led_matrix_init_cols() +#define led_matrix_write_cols() +#define led_matrix_unselect_rows() +#define led_matrix_select_row() +#endif + +#endif diff --git a/doc/keymap.md b/doc/keymap.md index 7ef7430c..11feeac2 100644 --- a/doc/keymap.md +++ b/doc/keymap.md @@ -269,7 +269,7 @@ Default Layer is a layer which always is valid and referred to when actions is n This sets Default Layer to given parameter `layer` and activate it. - ACTION_DEFAULT_LAYER(layer) + ACTION_DEFAULT_LAYER_SET(layer) #### 2.2.2 Momentary @@ -444,6 +444,10 @@ Step through backlight levels. ACTION_BACKLIGHT_STEP() +Turn a specific backlight level on or off. + + ACTION_BACKLIGHT_LEVEL(1) + #### 2.5.2 Turn on / off backlight Turn the backlight on and off without changing level. diff --git a/protocol/lufa.mk b/protocol/lufa.mk index 3489f19c..ac70ac03 100644 --- a/protocol/lufa.mk +++ b/protocol/lufa.mk @@ -1,7 +1,12 @@ LUFA_DIR = protocol/lufa # Path to the LUFA library -LUFA_PATH ?= protocol/lufa/LUFA-120730 +ifeq (, $(wildcard $(TOP_DIR)/$(LUFA_DIR)/LUFA-git/LUFA/Version.h)) + LUFA_PATH ?= $(LUFA_DIR)/LUFA-120730 +else + LUFA_PATH ?= $(LUFA_DIR)/LUFA-git +endif + # Create the LUFA source path variables by including the LUFA makefile ifneq (, $(wildcard $(TOP_DIR)/$(LUFA_PATH)/LUFA/Build/lufa_sources.mk)) @@ -30,9 +35,12 @@ VPATH += $(TOP_DIR)/$(LUFA_PATH) #endif # LUFA library compile-time options and predefined tokens -LUFA_OPTS = -D USB_DEVICE_ONLY -LUFA_OPTS += -D USE_FLASH_DESCRIPTORS -LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" +LUFA_OPTS = -DUSB_DEVICE_ONLY +LUFA_OPTS += -DUSE_FLASH_DESCRIPTORS +LUFA_OPTS += -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" +#LUFA_OPTS += -DINTERRUPT_CONTROL_ENDPOINT +LUFA_OPTS += -DFIXED_CONTROL_ENDPOINT_SIZE=8 +LUFA_OPTS += -DFIXED_NUM_CONFIGURATIONS=1 OPT_DEFS += -DF_USB=$(F_USB)UL OPT_DEFS += -DARCH=ARCH_$(ARCH) diff --git a/protocol/lufa/LUFA-git b/protocol/lufa/LUFA-git new file mode 160000 index 00000000..b6c18b2a --- /dev/null +++ b/protocol/lufa/LUFA-git @@ -0,0 +1 @@ +Subproject commit b6c18b2a7c544653efbe12a1d4e8ba65e7d83c35 diff --git a/protocol/lufa/descriptor.c b/protocol/lufa/descriptor.c index a46ba3ec..c13a81bd 100644 --- a/protocol/lufa/descriptor.c +++ b/protocol/lufa/descriptor.c @@ -230,12 +230,12 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = { .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, - .USBSpecification = VERSION_BCD(01.10), + .USBSpecification = VERSION_BCD(1,1,0), .Class = USB_CSCP_NoDeviceClass, .SubClass = USB_CSCP_NoDeviceSubclass, .Protocol = USB_CSCP_NoDeviceProtocol, - .Endpoint0Size = 8, + .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, /* specified in config.h */ .VendorID = VENDOR_ID, @@ -246,7 +246,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = .ProductStrIndex = 0x02, .SerialNumStrIndex = NO_DESCRIPTOR, - .NumberOfConfigurations = 1 + .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS }; /******************************************************************************* @@ -292,7 +292,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, - .HIDSpec = VERSION_BCD(01.11), + .HIDSpec = VERSION_BCD(1,1,1), .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, @@ -306,7 +306,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 = KEYBOARD_EPSIZE, - .PollingIntervalMS = 0x01 + .PollingIntervalMS = 0x0A }, /* @@ -333,7 +333,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, - .HIDSpec = VERSION_BCD(01.11), + .HIDSpec = VERSION_BCD(1,1,1), .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, @@ -347,7 +347,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 = MOUSE_EPSIZE, - .PollingIntervalMS = 0x01 + .PollingIntervalMS = 0x0A }, #endif @@ -375,7 +375,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, - .HIDSpec = VERSION_BCD(01.11), + .HIDSpec = VERSION_BCD(1,1,1), .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, @@ -389,7 +389,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .EndpointAddress = (ENDPOINT_DIR_IN | EXTRAKEY_IN_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = EXTRAKEY_EPSIZE, - .PollingIntervalMS = 0x01 + .PollingIntervalMS = 0x0A }, #endif @@ -417,7 +417,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, - .HIDSpec = VERSION_BCD(01.11), + .HIDSpec = VERSION_BCD(1,1,1), .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, @@ -469,7 +469,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, - .HIDSpec = VERSION_BCD(01.11), + .HIDSpec = VERSION_BCD(1,1,1), .CountryCode = 0x00, .TotalReportDescriptors = 1, .HIDReportType = HID_DTYPE_Report, diff --git a/protocol/lufa/descriptor.h b/protocol/lufa/descriptor.h index 9ee1c04d..42af0791 100644 --- a/protocol/lufa/descriptor.h +++ b/protocol/lufa/descriptor.h @@ -137,13 +137,17 @@ typedef struct #ifdef CONSOLE_ENABLE # define CONSOLE_IN_EPNUM (EXTRAKEY_IN_EPNUM + 1) -# define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 2) +# define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 1) +//# define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 2) #else # define CONSOLE_OUT_EPNUM EXTRAKEY_IN_EPNUM #endif #ifdef NKRO_ENABLE # define NKRO_IN_EPNUM (CONSOLE_OUT_EPNUM + 1) +# if defined(__AVR_ATmega32U2__) && NKRO_IN_EPNUM > 4 +# error "Endpoints are not available enough to support all functions. Remove some in Makefile.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO)" +# endif #endif @@ -159,4 +163,14 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const void** const DescriptorAddress) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); + +/* new API */ +#if LUFA_VERSION_INTEGER < 0x140302 + #undef VERSION_BCD + #define VERSION_BCD(Major, Minor, Revision) \ + CPU_TO_LE16( ((Major & 0xFF) << 8) | \ + ((Minor & 0x0F) << 4) | \ + (Revision & 0x0F) ) +#endif + #endif diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index eca51c87..d60aecc3 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c @@ -52,8 +52,8 @@ #include "descriptor.h" #include "lufa.h" -static uint8_t idle_duration = 0; -static uint8_t protocol_report = 1; +uint8_t keyboard_idle = 0; +uint8_t keyboard_protocol = 1; static uint8_t keyboard_led_stats = 0; static report_keyboard_t keyboard_report_sent; @@ -184,15 +184,6 @@ void EVENT_USB_Device_StartOfFrame(void) /** Event handler for the USB_ConfigurationChanged event. * This is fired when the host sets the current configuration of the USB device after enumeration. */ -#if LUFA_VERSION_INTEGER < 0x120730 - /* old API 120219 */ - #define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint(epnum, eptype, epdir, epsize, epbank) -#else - /* new API >= 120730 */ - #define ENDPOINT_BANK_SINGLE 1 - #define ENDPOINT_BANK_DOUBLE 2 - #define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint((epdir) | (epnum) , eptype, epsize, epbank) -#endif void EVENT_USB_Device_ConfigurationChanged(void) { bool ConfigSuccess = true; @@ -217,9 +208,11 @@ void EVENT_USB_Device_ConfigurationChanged(void) /* Setup Console HID Report Endpoints */ ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, CONSOLE_EPSIZE, ENDPOINT_BANK_DOUBLE); +#if 0 ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); #endif +#endif #ifdef NKRO_ENABLE /* Setup NKRO HID Report Endpoints */ @@ -279,6 +272,7 @@ void EVENT_USB_Device_ControlRequest(void) // Interface switch (USB_ControlRequest.wIndex) { case KEYBOARD_INTERFACE: + case NKRO_INTERFACE: Endpoint_ClearSETUP(); while (!(Endpoint_IsOUTReceived())) { @@ -299,21 +293,29 @@ void EVENT_USB_Device_ControlRequest(void) 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(); + if (USB_ControlRequest.wIndex == KEYBOARD_INTERFACE) { + Endpoint_ClearSETUP(); + while (!(Endpoint_IsINReady())); + Endpoint_Write_8(keyboard_protocol); + Endpoint_ClearIN(); + Endpoint_ClearStatusStage(); + } } break; case HID_REQ_SetProtocol: if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) { - Endpoint_ClearSETUP(); - Endpoint_ClearStatusStage(); + if (USB_ControlRequest.wIndex == KEYBOARD_INTERFACE) { + Endpoint_ClearSETUP(); + Endpoint_ClearStatusStage(); - protocol_report = ((USB_ControlRequest.wValue & 0xFF) != 0x00); + keyboard_protocol = ((USB_ControlRequest.wValue & 0xFF) != 0x00); +#ifdef NKRO_ENABLE + keyboard_nkro = !!keyboard_protocol; +#endif + clear_keyboard(); + } } break; @@ -323,7 +325,7 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearSETUP(); Endpoint_ClearStatusStage(); - idle_duration = ((USB_ControlRequest.wValue & 0xFF00) >> 8); + keyboard_idle = ((USB_ControlRequest.wValue & 0xFF00) >> 8); } break; @@ -332,7 +334,7 @@ void EVENT_USB_Device_ControlRequest(void) { Endpoint_ClearSETUP(); while (!(Endpoint_IsINReady())); - Endpoint_Write_8(idle_duration); + Endpoint_Write_8(keyboard_idle); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); } @@ -351,7 +353,7 @@ static uint8_t keyboard_leds(void) static void send_keyboard(report_keyboard_t *report) { - uint8_t timeout = 0; + uint8_t timeout = 255; if (USB_DeviceState != DEVICE_STATE_Configured) return; @@ -359,26 +361,27 @@ static void send_keyboard(report_keyboard_t *report) /* Select the Keyboard Report Endpoint */ #ifdef NKRO_ENABLE if (keyboard_nkro) { + /* Report protocol - NKRO */ Endpoint_SelectEndpoint(NKRO_IN_EPNUM); - } - else -#endif - { - Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM); - } - /* Check if Keyboard Endpoint Ready for Read/Write */ - while (--timeout && !Endpoint_IsReadWriteAllowed()) ; + /* Check if write ready for a polling interval around 1ms */ + while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(4); + if (!Endpoint_IsReadWriteAllowed()) return; - /* Write Keyboard Report Data */ -#ifdef NKRO_ENABLE - if (keyboard_nkro) { + /* Write Keyboard Report Data */ Endpoint_Write_Stream_LE(report, NKRO_EPSIZE, NULL); } else #endif { - /* boot mode */ + /* Boot protocol */ + Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM); + + /* Check if write ready for a polling interval around 10ms */ + while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); + if (!Endpoint_IsReadWriteAllowed()) return; + + /* Write Keyboard Report Data */ Endpoint_Write_Stream_LE(report, KEYBOARD_EPSIZE, NULL); } @@ -391,7 +394,7 @@ static void send_keyboard(report_keyboard_t *report) static void send_mouse(report_mouse_t *report) { #ifdef MOUSE_ENABLE - uint8_t timeout = 0; + uint8_t timeout = 255; if (USB_DeviceState != DEVICE_STATE_Configured) return; @@ -399,8 +402,9 @@ 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 */ - while (--timeout && !Endpoint_IsReadWriteAllowed()) ; + /* Check if write ready for a polling interval around 10ms */ + while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); + if (!Endpoint_IsReadWriteAllowed()) return; /* Write Mouse Report Data */ Endpoint_Write_Stream_LE(report, sizeof(report_mouse_t), NULL); @@ -412,7 +416,7 @@ static void send_mouse(report_mouse_t *report) static void send_system(uint16_t data) { - uint8_t timeout = 0; + uint8_t timeout = 255; if (USB_DeviceState != DEVICE_STATE_Configured) return; @@ -422,14 +426,18 @@ static void send_system(uint16_t data) .usage = data }; Endpoint_SelectEndpoint(EXTRAKEY_IN_EPNUM); - while (--timeout && !Endpoint_IsReadWriteAllowed()) ; + + /* Check if write ready for a polling interval around 10ms */ + while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); + if (!Endpoint_IsReadWriteAllowed()) return; + Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); Endpoint_ClearIN(); } static void send_consumer(uint16_t data) { - uint8_t timeout = 0; + uint8_t timeout = 255; if (USB_DeviceState != DEVICE_STATE_Configured) return; @@ -439,7 +447,11 @@ static void send_consumer(uint16_t data) .usage = data }; Endpoint_SelectEndpoint(EXTRAKEY_IN_EPNUM); - while (--timeout && !Endpoint_IsReadWriteAllowed()) ; + + /* Check if write ready for a polling interval around 10ms */ + while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); + if (!Endpoint_IsReadWriteAllowed()) return; + 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 bcee060d..195123c0 100644 --- a/protocol/lufa/lufa.h +++ b/protocol/lufa/lufa.h @@ -66,4 +66,15 @@ typedef struct { uint16_t usage; } __attribute__ ((packed)) report_extra_t; + +#if LUFA_VERSION_INTEGER < 0x120730 + /* old API 120219 */ + #define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint(epnum, eptype, epdir, epsize, epbank) +#else + /* new API >= 120730 */ + #define ENDPOINT_BANK_SINGLE 1 + #define ENDPOINT_BANK_DOUBLE 2 + #define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint((epdir) | (epnum) , eptype, epsize, epbank) +#endif + #endif diff --git a/protocol/pjrc/usb.c b/protocol/pjrc/usb.c index 393b36f7..1e6ba871 100644 --- a/protocol/pjrc/usb.c +++ b/protocol/pjrc/usb.c @@ -38,6 +38,7 @@ #include "sleep_led.h" #endif #include "suspend.h" +#include "action.h" #include "action_util.h" @@ -628,6 +629,7 @@ uint8_t usb_configured(void) void usb_remote_wakeup(void) { UDCON |= (1<mods; UEDATX = 0; - uint8_t keys = usb_keyboard_protocol ? KBD_REPORT_KEYS : 6; + uint8_t keys = keyboard_protocol ? KBD_REPORT_KEYS : 6; for (uint8_t i=0; ikeys[i]; } @@ -901,13 +903,13 @@ ISR(USB_COM_vect) } if (bRequest == HID_GET_IDLE) { usb_wait_in_ready(); - UEDATX = usb_keyboard_idle_config; + UEDATX = keyboard_idle; usb_send_in(); return; } if (bRequest == HID_GET_PROTOCOL) { usb_wait_in_ready(); - UEDATX = usb_keyboard_protocol; + UEDATX = keyboard_protocol; usb_send_in(); return; } @@ -921,14 +923,18 @@ ISR(USB_COM_vect) return; } if (bRequest == HID_SET_IDLE) { - usb_keyboard_idle_config = (wValue >> 8); + keyboard_idle = (wValue >> 8); usb_keyboard_idle_count = 0; //usb_wait_in_ready(); usb_send_in(); return; } if (bRequest == HID_SET_PROTOCOL) { - usb_keyboard_protocol = wValue; + keyboard_protocol = wValue; +#ifdef NKRO_ENABLE + keyboard_nkro = !!keyboard_protocol; +#endif + clear_keyboard(); //usb_wait_in_ready(); usb_send_in(); return; diff --git a/protocol/pjrc/usb_keyboard.c b/protocol/pjrc/usb_keyboard.c index de798fcc..d1683318 100644 --- a/protocol/pjrc/usb_keyboard.c +++ b/protocol/pjrc/usb_keyboard.c @@ -34,12 +34,12 @@ // protocol setting from the host. We use exactly the same report // either way, so this variable only stores the setting since we // are required to be able to report which setting is in use. -uint8_t usb_keyboard_protocol=1; +uint8_t keyboard_protocol=1; // the idle configuration, how often we send the report to the // host (ms * 4) even when it hasn't changed // Windows and Linux set 0 while OS X sets 6(24ms) by SET_IDLE request. -uint8_t usb_keyboard_idle_config=125; +uint8_t keyobard_idle=125; // count until idle timeout uint8_t usb_keyboard_idle_count=0; @@ -61,10 +61,7 @@ int8_t usb_keyboard_send_report(report_keyboard_t *report) else #endif { - if (usb_keyboard_protocol) - result = send_report(report, KBD_ENDPOINT, 0, KBD_SIZE); - else - result = send_report(report, KBD_ENDPOINT, 0, 6); + result = send_report(report, KBD_ENDPOINT, 0, KBD_SIZE); } if (result) return result; diff --git a/protocol/pjrc/usb_keyboard.h b/protocol/pjrc/usb_keyboard.h index c362ca3b..9b798e9a 100644 --- a/protocol/pjrc/usb_keyboard.h +++ b/protocol/pjrc/usb_keyboard.h @@ -30,8 +30,6 @@ #include "host.h" -extern uint8_t usb_keyboard_protocol; -extern uint8_t usb_keyboard_idle_config; extern uint8_t usb_keyboard_idle_count; extern volatile uint8_t usb_keyboard_leds; diff --git a/protocol/ps2.h b/protocol/ps2.h index 483eea72..703e0c27 100644 --- a/protocol/ps2.h +++ b/protocol/ps2.h @@ -90,6 +90,7 @@ uint8_t ps2_host_send(uint8_t data); uint8_t ps2_host_recv_response(void); uint8_t ps2_host_recv(void); void ps2_host_set_led(uint8_t usb_led); +uint8_t ps2_enabled(void); /* Check port settings for clock and data line */