From c958b2d19b0ec0dbc02f87dc4c9ccee933a54be5 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 21 Feb 2011 23:05:28 +0900 Subject: [PATCH 01/16] fixed adb_usb to comply new API. --- adb/Makefile | 82 --------------------------------------- adb_usb/Makefile | 52 +++++++++++++++++++++++++ {adb => adb_usb}/README | 0 {adb => adb_usb}/config.h | 14 ++++--- {adb => adb_usb}/keymap.c | 9 +---- adb_usb/led.c | 9 +++++ {adb => adb_usb}/matrix.c | 9 +---- pjrc/usb_keyboard.c | 4 ++ 8 files changed, 76 insertions(+), 103 deletions(-) delete mode 100644 adb/Makefile create mode 100644 adb_usb/Makefile rename {adb => adb_usb}/README (100%) rename {adb => adb_usb}/config.h (84%) rename {adb => adb_usb}/keymap.c (96%) create mode 100644 adb_usb/led.c rename {adb => adb_usb}/matrix.c (94%) diff --git a/adb/Makefile b/adb/Makefile deleted file mode 100644 index c27c75e1..00000000 --- a/adb/Makefile +++ /dev/null @@ -1,82 +0,0 @@ -# Hey Emacs, this is a -*- makefile -*- -#---------------------------------------------------------------------------- -# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al. -# -# 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 -# -#---------------------------------------------------------------------------- -# 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 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 = tmk_adb - -# Directory common source filess exist -COMMON_DIR = .. - -# Directory keyboard dependent files exist -TARGET_DIR = . - -# keyboard dependent files -TARGET_SRC = keymap.c \ - matrix.c \ - adb.c - - -# 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 -USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System control) -#USB_NKRO_ENABLE = yes # USB Nkey Rollover - - -include $(COMMON_DIR)/Makefile.common diff --git a/adb_usb/Makefile b/adb_usb/Makefile new file mode 100644 index 00000000..61e43a72 --- /dev/null +++ b/adb_usb/Makefile @@ -0,0 +1,52 @@ +# Target file name (without extension). +TARGET = adb_usb + +# Directory common source filess exist +COMMON_DIR = .. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# keyboard dependent files +TARGET_SRC = main_pjrc.c \ + keymap.c \ + matrix.c \ + led.c \ + adb.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 +USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System control) +#USB_NKRO_ENABLE = yes # USB Nkey Rollover + + + +#---------------- Programming Options -------------------------- +PROGRAM_CMD = teensy_loader_cli.exe -mmcu=$(MCU) -w -v $(TARGET).hex + + + +include $(COMMON_DIR)/Makefile.pjrc +include $(COMMON_DIR)/Makefile.common diff --git a/adb/README b/adb_usb/README similarity index 100% rename from adb/README rename to adb_usb/README diff --git a/adb/config.h b/adb_usb/config.h similarity index 84% rename from adb/config.h rename to adb_usb/config.h index 099a24bf..ea78dd9b 100644 --- a/adb/config.h +++ b/adb_usb/config.h @@ -13,18 +13,21 @@ /* matrix size */ #define MATRIX_ROWS 16 // keycode bit: 3-0 #define MATRIX_COLS 8 // keycode bit: 6-4 -/* define if matrix has ghost */ -//#define MATRIX_HAS_GHOST -/* USB NKey Rollover */ -#ifdef USB_NKRO_ENABLE -#endif + +/* key combination for command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \ + keyboard_report->mods == (BIT_LCTRL | BIT_RSHIFT) \ +) + /* mouse keys */ #ifdef MOUSEKEY_ENABLE # define MOUSEKEY_DELAY_TIME 192 #endif + /* PS/2 mouse */ #ifdef PS2_MOUSE_ENABLE # define PS2_CLOCK_PORT PORTF @@ -37,6 +40,7 @@ # define PS2_DATA_BIT 1 #endif + /* ADB port setting */ #define ADB_PORT PORTF #define ADB_PIN PINF diff --git a/adb/keymap.c b/adb_usb/keymap.c similarity index 96% rename from adb/keymap.c rename to adb_usb/keymap.c index 05ab4c45..c5345770 100644 --- a/adb/keymap.c +++ b/adb_usb/keymap.c @@ -9,7 +9,7 @@ #include "print.h" #include "debug.h" #include "util.h" -#include "keymap_skel.h" +#include "keymap.h" #define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)])) @@ -131,10 +131,3 @@ uint8_t keymap_fn_keycode(uint8_t fn_bits) { return pgm_read_byte(&fn_keycode[(biton(fn_bits))]); } - -// define a condition to enter special function mode -bool keymap_is_special_mode(uint8_t fn_bits) -{ - //return (usb_keyboard_mods == (BIT_LCTRL | BIT_LSHIFT | BIT_LALT | BIT_LGUI)); - return (usb_keyboard_mods == (BIT_RSHIFT)); -} diff --git a/adb_usb/led.c b/adb_usb/led.c new file mode 100644 index 00000000..93009a52 --- /dev/null +++ b/adb_usb/led.c @@ -0,0 +1,9 @@ +#include "stdint.h" +#include "adb.h" +#include "led.h" + + +void led_set(uint8_t usb_led) +{ + adb_host_kbd_led(~usb_led); +} diff --git a/adb/matrix.c b/adb_usb/matrix.c similarity index 94% rename from adb/matrix.c rename to adb_usb/matrix.c index 550506ec..72515dce 100644 --- a/adb/matrix.c +++ b/adb_usb/matrix.c @@ -9,8 +9,7 @@ #include "util.h" #include "debug.h" #include "adb.h" -#include "usb_keyboard.h" -#include "matrix_skel.h" +#include "matrix.h" #if (MATRIX_COLS > 16) @@ -72,12 +71,6 @@ uint8_t matrix_scan(void) uint16_t codes; uint8_t key0, key1; - static uint8_t prev_led = 0; - if (prev_led != usb_keyboard_leds) { - adb_host_kbd_led(~usb_keyboard_leds); - prev_led = usb_keyboard_leds; - } - _matrix_is_modified = false; codes = adb_host_kbd_recv(); key0 = codes>>8; diff --git a/pjrc/usb_keyboard.c b/pjrc/usb_keyboard.c index e29c5c9e..fc05f7c9 100644 --- a/pjrc/usb_keyboard.c +++ b/pjrc/usb_keyboard.c @@ -81,8 +81,12 @@ static inline int8_t send_report(report_keyboard_t *report, uint8_t endpoint, ui UENUM = endpoint; } UEDATX = report->mods; +#ifdef USB_NKRO_ENABLE if (!keyboard_nkro) UEDATX = 0; +#else + UEDATX = 0; +#endif for (uint8_t i = keys_start; i < keys_end; i++) { UEDATX = report->keys[i]; } -- 2.39.3 From 60052acc0fe3e6429f5c1d24073b1f6af019bd19 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 21 Feb 2011 23:46:08 +0900 Subject: [PATCH 02/16] fixed macway to comply new API. --- macway/Makefile | 60 +++++++++++++------------------------------------ macway/config.h | 12 +++++++--- macway/keymap.c | 9 +------- macway/led.c | 7 ++++++ macway/matrix.c | 2 +- 5 files changed, 33 insertions(+), 57 deletions(-) create mode 100644 macway/led.c diff --git a/macway/Makefile b/macway/Makefile index 49dba674..c603ca7b 100644 --- a/macway/Makefile +++ b/macway/Makefile @@ -1,46 +1,5 @@ -# Hey Emacs, this is a -*- makefile -*- -#---------------------------------------------------------------------------- -# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al. -# -# 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 -# -#---------------------------------------------------------------------------- -# 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 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 = tmk_macway +TARGET = macway # Directory common source filess exist COMMON_DIR = .. @@ -49,8 +8,12 @@ COMMON_DIR = .. TARGET_DIR = . # keyboard dependent files -TARGET_SRC = keymap.c \ - matrix.c +TARGET_SRC = main_pjrc.c \ + keymap.c \ + matrix.c \ + led.c + +CONFIG_H = config.h # MCU name, you MUST set this to match the board you are using @@ -73,9 +36,16 @@ F_CPU = 16000000 # comment out to disable the options. # MOUSEKEY_ENABLE = yes # Mouse keys -PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System control) #USB_NKRO_ENABLE = yes # USB Nkey Rollover + +#---------------- Programming Options -------------------------- +PROGRAM_CMD = teensy_loader_cli.exe -mmcu=$(MCU) -w -v $(TARGET).hex + + + +include $(COMMON_DIR)/Makefile.pjrc include $(COMMON_DIR)/Makefile.common diff --git a/macway/config.h b/macway/config.h index 1403ef12..9e443ba7 100644 --- a/macway/config.h +++ b/macway/config.h @@ -10,21 +10,27 @@ #define PRODUCT Macway mod #define DESCRIPTION t.m.k. keyboard firmware for Macway mod + /* matrix size */ #define MATRIX_ROWS 9 #define MATRIX_COLS 8 /* define if matrix has ghost */ #define MATRIX_HAS_GHOST -/* USB NKey Rollover */ -#ifdef USB_NKRO_ENABLE -#endif + +/* key combination for command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \ + keyboard_report->mods == (BIT_LCTRL | BIT_RSHIFT) \ +) + /* mouse keys */ #ifdef MOUSEKEY_ENABLE # define MOUSEKEY_DELAY_TIME 192 #endif + /* PS/2 mouse */ #ifdef PS2_MOUSE_ENABLE # define PS2_CLOCK_PORT PORTF diff --git a/macway/keymap.c b/macway/keymap.c index f26267fd..610d62cb 100644 --- a/macway/keymap.c +++ b/macway/keymap.c @@ -4,12 +4,11 @@ #include #include #include -#include "usb_keyboard.h" #include "usb_keycodes.h" #include "print.h" #include "debug.h" #include "util.h" -#include "keymap_skel.h" +#include "keymap.h" // Convert physical keyboard layout to matrix array. @@ -177,9 +176,3 @@ uint8_t keymap_fn_keycode(uint8_t fn_bits) { return pgm_read_byte(&fn_keycode[(biton(fn_bits))]); } - -// define a condition to enter special function mode -bool keymap_is_special_mode(uint8_t fn_bits) -{ - return usb_keyboard_mods == (BIT_LSHIFT | BIT_RSHIFT); -} diff --git a/macway/led.c b/macway/led.c new file mode 100644 index 00000000..bdc838d4 --- /dev/null +++ b/macway/led.c @@ -0,0 +1,7 @@ +#include "stdint.h" +#include "led.h" + + +void led_set(uint8_t usb_led) +{ +} diff --git a/macway/matrix.c b/macway/matrix.c index f8c0640f..81c4042f 100644 --- a/macway/matrix.c +++ b/macway/matrix.c @@ -7,7 +7,7 @@ #include #include "print.h" #include "util.h" -#include "matrix_skel.h" +#include "matrix.h" #if (MATRIX_COLS > 16) -- 2.39.3 From d2b9489a5e19fabb5d6ec285192b19dc25b36d5e Mon Sep 17 00:00:00 2001 From: tmk Date: Tue, 22 Feb 2011 01:21:53 +0900 Subject: [PATCH 03/16] fixed hhkb to comply new API. --- command.c | 5 +-- hhkb/Makefile | 10 +++++- hhkb/config.h | 13 +++---- hhkb/keymap.c | 8 +---- hhkb/matrix.c | 2 +- host.h | 3 +- pjrc/host.c | 18 ++++++---- tmk.c | 97 --------------------------------------------------- 8 files changed, 33 insertions(+), 123 deletions(-) delete mode 100644 tmk.c diff --git a/command.c b/command.c index 0152ccd8..7afed5d7 100644 --- a/command.c +++ b/command.c @@ -32,7 +32,7 @@ uint8_t command_proc(void) uint8_t processed = 1; bool last_print_enable = print_enable; print_enable = true; - switch (keyboard_report->keys[0]) { + switch (host_get_first_key()) { case KB_H: help(); break; @@ -89,7 +89,7 @@ uint8_t command_proc(void) print("timer: "); phex16(timer_count); print("\n"); break; case KB_P: // print toggle - if (print_enable) { + if (last_print_enable) { print("print disabled.\n"); last_print_enable = false; } else { @@ -107,6 +107,7 @@ uint8_t command_proc(void) break; #ifdef USB_NKRO_ENABLE case KB_N: + // send empty report before change host_clear_keyboard_report(); host_send_keyboard_report(); keyboard_nkro = !keyboard_nkro; diff --git a/hhkb/Makefile b/hhkb/Makefile index 7c7ed0ee..2c8cd5af 100644 --- a/hhkb/Makefile +++ b/hhkb/Makefile @@ -8,11 +8,13 @@ COMMON_DIR = .. TARGET_DIR = . # keyboard dependent files -TARGET_SRC = tmk.c \ +TARGET_SRC = main_pjrc.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 @@ -38,5 +40,11 @@ USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System c USB_NKRO_ENABLE = yes # USB Nkey Rollover + +#---------------- Programming Options -------------------------- +PROGRAM_CMD = teensy_loader_cli.exe -mmcu=$(MCU) -w -v $(TARGET).hex + + + include $(COMMON_DIR)/Makefile.pjrc include $(COMMON_DIR)/Makefile.common diff --git a/hhkb/config.h b/hhkb/config.h index b8392aa8..886eef92 100644 --- a/hhkb/config.h +++ b/hhkb/config.h @@ -10,26 +10,27 @@ #define PRODUCT HHKB mod #define DESCRIPTION t.m.k. keyboard firmware for HHKB mod + /* matrix size */ #define MATRIX_ROWS 8 #define MATRIX_COLS 8 - /* define if matrix has ghost */ //#define MATRIX_HAS_GHOST -/* key combination for command */ -#define IS_COMMAND() (keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT)) +/* key combination for command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \ + keyboard_report->mods == (BIT_LCTRL | BIT_RSHIFT) \ +) -/* USB NKey Rollover */ -#ifdef USB_NKRO_ENABLE -#endif /* mouse keys */ #ifdef MOUSEKEY_ENABLE # define MOUSEKEY_DELAY_TIME 192 #endif + /* PS/2 mouse */ #ifdef PS2_MOUSE_ENABLE /* diff --git a/hhkb/keymap.c b/hhkb/keymap.c index d6acf459..78f1a7f7 100644 --- a/hhkb/keymap.c +++ b/hhkb/keymap.c @@ -9,7 +9,7 @@ #include "print.h" #include "debug.h" #include "util.h" -#include "keymap_skel.h" +#include "keymap.h" // Convert physical keyboard layout to matrix array. @@ -193,9 +193,3 @@ uint8_t keymap_fn_keycode(uint8_t fn_bits) { return pgm_read_byte(&fn_keycode[(biton(fn_bits))]); } - -// define a condition to enter special function mode -bool keymap_is_special_mode(uint8_t fn_bits) -{ - return host_get_mods() == (BIT_LSHIFT | BIT_RSHIFT) || host_get_mods() == (BIT_LCTRL | BIT_RSHIFT); -} diff --git a/hhkb/matrix.c b/hhkb/matrix.c index 15633d53..fefd2478 100644 --- a/hhkb/matrix.c +++ b/hhkb/matrix.c @@ -7,7 +7,7 @@ #include #include "print.h" #include "util.h" -#include "matrix_skel.h" +#include "matrix.h" #if (MATRIX_COLS > 16) diff --git a/host.h b/host.h index 5764e02c..045ccd8e 100644 --- a/host.h +++ b/host.h @@ -70,8 +70,7 @@ void host_add_code(uint8_t code); void host_swap_keyboard_report(void); void host_clear_keyboard_report(void); uint8_t host_has_anykey(void); -uint8_t *host_get_keys(void); -uint8_t host_get_mods(void); +uint8_t host_get_first_key(void); void host_send_keyboard_report(void); diff --git a/pjrc/host.c b/pjrc/host.c index 7247288b..8da88517 100644 --- a/pjrc/host.c +++ b/pjrc/host.c @@ -4,6 +4,7 @@ #include "usb_mouse.h" #include "debug.h" #include "host.h" +#include "util.h" #ifdef USB_NKRO_ENABLE @@ -80,14 +81,17 @@ uint8_t host_has_anykey(void) return cnt; } -uint8_t *host_get_keys(void) +uint8_t host_get_first_key(void) { - return keyboard_report->keys; -} - -uint8_t host_get_mods(void) -{ - return keyboard_report->mods; +#ifdef USB_NKRO_ENABLE + if (keyboard_nkro) { + uint8_t i = 0; + for (; i < REPORT_KEYS && !keyboard_report->keys[i]; i++) + ; + return i<<3 | biton(keyboard_report->keys[i]); + } +#endif + return keyboard_report->keys[0]; } diff --git a/tmk.c b/tmk.c deleted file mode 100644 index 18a05ffd..00000000 --- a/tmk.c +++ /dev/null @@ -1,97 +0,0 @@ -/* 2010/08/23 noname - * keyboard firmware based on PJRC USB keyboard example - */ -/* Keyboard example with debug channel, for Teensy USB Development Board - * http://www.pjrc.com/teensy/usb_keyboard.html - * Copyright (c) 2008 PJRC.COM, LLC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include -#include -#include -#include "keyboard.h" -#include "usb.h" -#include "matrix.h" -#include "print.h" -#include "debug.h" -#include "util.h" -#include "jump_bootloader.h" -#ifdef PS2_MOUSE_ENABLE -# include "ps2_mouse.h" -#endif - - -#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) - - -bool debug_enable = false; -bool debug_matrix = false; -bool debug_keyboard = false; -bool debug_mouse = false; - - -int main(void) -{ - DEBUG_LED_CONFIG; - DEBUG_LED_OFF; - - // set for 16 MHz clock - CPU_PRESCALE(0); - - // Initialize the USB, and then wait for the host to set configuration. - // If the Teensy is powered without a PC connected to the USB port, - // this will wait forever. - usb_init(); - while (!usb_configured()) /* wait */ ; - - keyboard_init(); - matrix_scan(); - if (matrix_key_count() >= 3) { -#ifdef DEBUG_LED - for (int i = 0; i < 6; i++) { - DEBUG_LED_CONFIG; - DEBUG_LED_ON; - _delay_ms(500); - DEBUG_LED_OFF; - _delay_ms(500); - } -#else - _delay_ms(5000); -#endif - print_enable = true; - debug_enable = true; - debug_matrix = true; - debug_keyboard = true; - debug_mouse = true; - print("debug enabled.\n"); - } - if (matrix_key_count() >= 4) { - print("jump to bootloader...\n"); - _delay_ms(1000); - jump_bootloader(); // not return - } - - - while (1) { - keyboard_proc(); - } -} -- 2.39.3 From 00350c180dee31ec9d9c4aee31e06faf55bd1c6b Mon Sep 17 00:00:00 2001 From: tmk Date: Tue, 22 Feb 2011 02:57:01 +0900 Subject: [PATCH 04/16] v3.0 cleanse files --- ADB.txt | 173 ------------------------------------------- README | 35 +++++++-- TODO | 103 -------------------------- adb.c | 213 +++++++++++++++++++++++++++++++++++++++++++++++++++++ pjrc/usb.c | 0 5 files changed, 240 insertions(+), 284 deletions(-) delete mode 100644 ADB.txt delete mode 100644 TODO mode change 100755 => 100644 pjrc/usb.c diff --git a/ADB.txt b/ADB.txt deleted file mode 100644 index 63005b3d..00000000 --- a/ADB.txt +++ /dev/null @@ -1,173 +0,0 @@ -ADB Protocol -============ - -Resources ---------- -ADB - The Untold Story: Space Aliens Ate My Mouse - http://developer.apple.com/legacy/mac/library/#technotes/hw/hw_01.html -Apple IIgs Hardware Reference Second Edition [p80(Chapter6 p121)] - ftp://ftp.apple.asimov.net/pub/apple_II/documentation/Apple%20IIgs%20Hardware%20Reference.pdf -ADB Keycode - http://72.0.193.250/Documentation/macppc/adbkeycodes/ - http://m0115.web.fc2.com/m0115.jpg - [Inside Macintosh volume V, pages 191-192] -ADB Signaling - http://kbdbabel.sourceforge.net/doc/kbd_signaling_pcxt_ps2_adb.pdf -ADB Overview & History - http://en.wikipedia.org/wiki/Apple_Desktop_Bus -Microchip Application Note: ADB device(with code for PIC16C) - http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en011062 -AVR ATtiny2131 ADB to PS/2 converter(Japanese) - http://hp.vector.co.jp/authors/VA000177/html/KeyBoardA5DEA5CBA5A2II.html - - -Pinouts -------- - ADB female socket from the front: - __________ - | | <--- top - | 4o o3 | - |2o o1| - | == | - |________| <--- bottom - | | <--- 4pins - - - ADB female socket from bottom: - - ========== <--- front - | | - | | - |2o o1| - |4o o3| - ---------- <--- back - - 1: Data - 2: Power SW(low when press Power key) - 3: Vcc(5V) - 4: GND - - - -Commands --------- - ADB command is 1byte and consists of 4bit-address, 2bit-command - type and 2bit-register. The commands are always sent by Host. - - Command format: - 7 6 5 4 3 2 1 0 - | | | |------------ address - | |-------- command type - | |---- register - - bits commands - ------------------------------------------------------ - - - - - 0 0 0 0 Send Request(reset all devices) - A A A A 0 0 0 1 Flush(reset a device) - - - - - 0 0 1 0 Reserved - - - - - 0 0 1 1 Reserved - - - - - 0 1 - - Reserved - A A A A 1 0 R R Listen(write to a device) - A A A A 1 1 R R Talk(read from a device) - - The command to read keycodes from keyboard is 0x2C which - consist of keyboard address 2 and Talk against register 0. - - Address: - 2: keyboard - 3: mice - - Registers: - 0: application(keyobard uses this to store its data.) - 1: application - 2: application(keyboard uses this for LEDs and state of modifiers) - 3: status and command - - -Communication -------------- - This is a minimum information for keyboard communication. - See "Resources" for detail. - - Signaling: - - ~~~~____________~~||||||||||||__~~~~~_~~|||||||||||||||__~~~~ - - |800us | |7 Command 0| | | |15-64 Data 0|Stopbit(0) - +Attention | | | +Startbit(1) - +Startbit(1) | +Tlt(140-260us) - +stopbit(0) - - Bit cells: - - bit0: ______~~~ - 65 :35us - - bit1: ___~~~~~~ - 35 :65us - - bit0 low time: 60-70% of bit cell(42-91us) - bit1 low time: 30-40% of bit cell(21-52us) - bit cell time: 70-130us - [from Apple IIgs Hardware Reference Second Edition] - - Criterion for bit0/1: - After 55us if line is low/high then bit is 0/1. - - Attention & start bit: - Host asserts low in 560-1040us then places start bit(1). - - Tlt(Stop to Start): - Bus stays high in 140-260us then device places start bit(1). - - Global reset: - Host asserts low in 2.8-5.2ms. All devices are forced to reset. - - Send request from device(Srq): - Device can request to send at commad(Global only?) stop bit. - keep low for 300us to request. - - -Keyboard Data(Register0) - This 16bit data can contains two keycodes and two released flags. - First keycode is palced in upper byte. When one keyocode is sent, - lower byte is 0xFF. - Release flag is 1 when key is released. - - 1514 . . . . . 8 7 6 . . . . . 0 - | | | | | | | | | +-+-+-+-+-+-+- Keycode2 - | | | | | | | | +--------------- Released2(1 when the key is released) - | +-+-+-+-+-+-+----------------- Keycode1 - +------------------------------- Released1(1 when the key is released) - - Keycodes: - Scancode consists of 7bit keycode and 1bit release flag. - Device can send two keycodes at once. If just one keycode is sent - keycode1 contains it and keyocode2 is 0xFF. - - Power switch: - You can read the state from PSW line(active low) however - the switch has a special scancode 0x7F7F, so you can - also read from Data line. It uses 0xFFFF for release scancode. - -Keyboard LEDs & state of keys(Register2) - This register hold current state of three LEDs and nine keys. - The state of LEDs can be changed by sending Listen command. - - 1514 . . . . . . 7 6 5 . 3 2 1 0 - | | | | | | | | | | | | | | | +- LED1(NumLock) - | | | | | | | | | | | | | | +--- LED2(CapsLock) - | | | | | | | | | | | | | +----- LED3(ScrollLock) - | | | | | | | | | | +-+-+------- Reserved - | | | | | | | | | +------------- ScrollLock - | | | | | | | | +--------------- NumLock - | | | | | | | +----------------- Apple/Command - | | | | | | +------------------- Option - | | | | | +--------------------- Shift - | | | | +----------------------- Control - | | | +------------------------- Reset/Power - | | +--------------------------- CapsLock - | +----------------------------- Delete - +------------------------------- Reserved - -END_OF_ADB diff --git a/README b/README index 3361c1f9..2aa0106b 100644 --- a/README +++ b/README @@ -1,16 +1,19 @@ t.m.k. Keyboard Firmware ======================== -http://github.com/tmk/tmk_keyboard - -This is keyboard firmware for AVR USB MCUs or Teensy/Teensy++. -http://www.pjrc.com/teensy +This is keyboard firmware for Teensy(AVR USB MCU) and V-USB board. -The project is heavily based on PJRC USB Keyboard/Mouse Example and -owes a debt to preceding keyboard firmware projects. +source code repository: +http://github.com/tmk/tmk_keyboard This firmware is used in following projects: HHKB mod: http://geekhack.org/showwiki.php?title=Island:12047 Macway mod: http://geekhack.org/showwiki.php?title=Island:11930 +PS2 to USB: http://geekhack.org/showwiki.php?title=Island:14618 +ADB to USB: http://geekhack.org/showwiki.php?title=Island:14290 + +The project is heavily based on PJRC USB Keyboard/Mouse Example and +owes a debt to preceding keyboard firmware projects. +http://www.pjrc.com/teensy Features @@ -31,12 +34,27 @@ Limitations ----------- +Files & Directories +------------------- +Target: +hhkb/ keyboard controller for PFU HHKB pro +macway/ keyboard controller for Macway mod +ps2_usb/ PS2 to USB keyboard converter +adb_usb/ ADB to USB keyboard converter + +USB Protocol Stack: +pjrc/ PJRC USB stack +vusb/ V-USB USB stack +ps2.[ch] PS/2 protocol +adb.[ch] ADB protocol + + Build ----- To compile needs AVR GCC, AVR Libc and GNU make. You can use WinAVR on Windows. http://winavr.sourceforge.net/ -$ cd (hhkb or macway currently) +$ cd $ make The firmware will be compiled as a file tmk_.hex. @@ -100,7 +118,8 @@ Build Options Debuging & Rescue ----------------- Use PJRC's hid_listen.exe to see debug messages. -Press right Control + Shift + Alt + GUI + H to debug menu. +Press + H to debug menu. +(see config.h for key combination.) Pressing any 3 keys when connected enables debug output. Pressing any 4 keys when connected makes bootloader comes up. diff --git a/TODO b/TODO deleted file mode 100644 index c15e546c..00000000 --- a/TODO +++ /dev/null @@ -1,103 +0,0 @@ -TODO & IDEAS ------------- -Code cleaning - keymap layer definition -Debug/Config console - keymap/layer setting - layer switching timing - matrix display - help - display keymap - display matrix(row, col) - debug console - through PJRC console - through UART/USB CDC - mouse acceleration - store setting to EEPROM -Document - development -Interchangable protocol stack - USB - PJRC stack(default currently) - LUFA - original minimal stack for keyboard/mouse - PS/2 - from keyboard-upgrade? -Layer switch - toggle layer switch -Debouncing logic - will be coded when bouncing occurs. - bouncing doesnt occur on my ALPS switch so far. - scan rate is too slow?(to be measure) -Child lock - disable keyboard to protect against atacking by child -Windows key blocking - disable Windows keys for gamers -OneHand operation - RAlt + Del(or \) to Alt + Tab -Licensings(GPL) - GPL will not be infringement of PJRC license. -Extra switch - foot sw for layer switching - mouse button -PS/2->USB keyboard converter - PS/2 keyboard host protocol support -PS/2,USB detection - act as PS/2 keyboard or USB keyboard. - PS/2 keyboard device protocol support -Thinkpad keyboard support - turn to USB keyboard/mouse composite device -Other MCU/board support - architectures on which GCC is available. - AT90USBKEY and other AVR USB boards - Cortex-M3 ARM board(STM32) - http://strawberry-linux.com/catalog/items?code=32105 -Separate keyboard support - comunicate between keyboards by I2C? - this is for ergo keyoboard style. - - -DONE & STATUS -------------- -PS2 mouse bug to be FIX'd - macway/matrix: line select changes pins for mouse. - 2010/01/02 -support for HHKB pro matrix signal - exchange controller board with teensy - 2010/10/11 -OneHand operation - Matias half keyboard style - 2010/10/23 -souce code cleaning - 2010/10/23 -debug on/off - debug off by default - pressing keys during booting - 2010/10/23 -mouse horizontal wheel - http://www.microchip.com/forums/tm.aspx?high=&m=391435&mpage=1#391521 - http://www.keil.com/forum/15671/ - http://www.microsoft.com/whdc/device/input/wheel.mspx - 2010/10/13 -debug on/off - Fn key conbination during normal operation - matrix print on/off - key print on/off - mouse print on/off - 2010/10/26 -layer switching - time before switching - timeout when not used during specific time - 2010/10/30 -Build Option - windows media keys suport - 2010/01/06 -Document - build, customize - 2010/01/06 -Trackpoint(PS/2) - receive PS/2 signal from TrackPoint - 2010/01/02 - send USB HID report - -EOF diff --git a/adb.c b/adb.c index 6848fa65..6a3fb8e0 100644 --- a/adb.c +++ b/adb.c @@ -1,3 +1,39 @@ +/* +Copyright (c) 2011 Jun WAKO + +This software is licensed with a Modified BSD License. +All of this is supposed to be Free Software, Open Source, DFSG-free, +GPL-compatible, and OK to use in both free and proprietary applications. +Additions and corrections to this file are welcome. + + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + +* Neither the name of the copyright holders nor the names of + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ #include #include #include @@ -191,3 +227,180 @@ static inline uint8_t wait_data_hi(uint8_t us) } return us; } + + +/* +ADB Protocol +============ + +Resources +--------- +ADB - The Untold Story: Space Aliens Ate My Mouse + http://developer.apple.com/legacy/mac/library/#technotes/hw/hw_01.html +Apple IIgs Hardware Reference Second Edition [p80(Chapter6 p121)] + ftp://ftp.apple.asimov.net/pub/apple_II/documentation/Apple%20IIgs%20Hardware%20Reference.pdf +ADB Keycode + http://72.0.193.250/Documentation/macppc/adbkeycodes/ + http://m0115.web.fc2.com/m0115.jpg + [Inside Macintosh volume V, pages 191-192] +ADB Signaling + http://kbdbabel.sourceforge.net/doc/kbd_signaling_pcxt_ps2_adb.pdf +ADB Overview & History + http://en.wikipedia.org/wiki/Apple_Desktop_Bus +Microchip Application Note: ADB device(with code for PIC16C) + http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en011062 +AVR ATtiny2131 ADB to PS/2 converter(Japanese) + http://hp.vector.co.jp/authors/VA000177/html/KeyBoardA5DEA5CBA5A2II.html + + +Pinouts +------- + ADB female socket from the front: + __________ + | | <--- top + | 4o o3 | + |2o o1| + | == | + |________| <--- bottom + | | <--- 4pins + + + ADB female socket from bottom: + + ========== <--- front + | | + | | + |2o o1| + |4o o3| + ---------- <--- back + + 1: Data + 2: Power SW(low when press Power key) + 3: Vcc(5V) + 4: GND + + + +Commands +-------- + ADB command is 1byte and consists of 4bit-address, 2bit-command + type and 2bit-register. The commands are always sent by Host. + + Command format: + 7 6 5 4 3 2 1 0 + | | | |------------ address + | |-------- command type + | |---- register + + bits commands + ------------------------------------------------------ + - - - - 0 0 0 0 Send Request(reset all devices) + A A A A 0 0 0 1 Flush(reset a device) + - - - - 0 0 1 0 Reserved + - - - - 0 0 1 1 Reserved + - - - - 0 1 - - Reserved + A A A A 1 0 R R Listen(write to a device) + A A A A 1 1 R R Talk(read from a device) + + The command to read keycodes from keyboard is 0x2C which + consist of keyboard address 2 and Talk against register 0. + + Address: + 2: keyboard + 3: mice + + Registers: + 0: application(keyobard uses this to store its data.) + 1: application + 2: application(keyboard uses this for LEDs and state of modifiers) + 3: status and command + + +Communication +------------- + This is a minimum information for keyboard communication. + See "Resources" for detail. + + Signaling: + + ~~~~____________~~||||||||||||__~~~~~_~~|||||||||||||||__~~~~ + + |800us | |7 Command 0| | | |15-64 Data 0|Stopbit(0) + +Attention | | | +Startbit(1) + +Startbit(1) | +Tlt(140-260us) + +stopbit(0) + + Bit cells: + + bit0: ______~~~ + 65 :35us + + bit1: ___~~~~~~ + 35 :65us + + bit0 low time: 60-70% of bit cell(42-91us) + bit1 low time: 30-40% of bit cell(21-52us) + bit cell time: 70-130us + [from Apple IIgs Hardware Reference Second Edition] + + Criterion for bit0/1: + After 55us if line is low/high then bit is 0/1. + + Attention & start bit: + Host asserts low in 560-1040us then places start bit(1). + + Tlt(Stop to Start): + Bus stays high in 140-260us then device places start bit(1). + + Global reset: + Host asserts low in 2.8-5.2ms. All devices are forced to reset. + + Send request from device(Srq): + Device can request to send at commad(Global only?) stop bit. + keep low for 300us to request. + + +Keyboard Data(Register0) + This 16bit data can contains two keycodes and two released flags. + First keycode is palced in upper byte. When one keyocode is sent, + lower byte is 0xFF. + Release flag is 1 when key is released. + + 1514 . . . . . 8 7 6 . . . . . 0 + | | | | | | | | | +-+-+-+-+-+-+- Keycode2 + | | | | | | | | +--------------- Released2(1 when the key is released) + | +-+-+-+-+-+-+----------------- Keycode1 + +------------------------------- Released1(1 when the key is released) + + Keycodes: + Scancode consists of 7bit keycode and 1bit release flag. + Device can send two keycodes at once. If just one keycode is sent + keycode1 contains it and keyocode2 is 0xFF. + + Power switch: + You can read the state from PSW line(active low) however + the switch has a special scancode 0x7F7F, so you can + also read from Data line. It uses 0xFFFF for release scancode. + +Keyboard LEDs & state of keys(Register2) + This register hold current state of three LEDs and nine keys. + The state of LEDs can be changed by sending Listen command. + + 1514 . . . . . . 7 6 5 . 3 2 1 0 + | | | | | | | | | | | | | | | +- LED1(NumLock) + | | | | | | | | | | | | | | +--- LED2(CapsLock) + | | | | | | | | | | | | | +----- LED3(ScrollLock) + | | | | | | | | | | +-+-+------- Reserved + | | | | | | | | | +------------- ScrollLock + | | | | | | | | +--------------- NumLock + | | | | | | | +----------------- Apple/Command + | | | | | | +------------------- Option + | | | | | +--------------------- Shift + | | | | +----------------------- Control + | | | +------------------------- Reset/Power + | | +--------------------------- CapsLock + | +----------------------------- Delete + +------------------------------- Reserved + +END_OF_ADB +*/ diff --git a/pjrc/usb.c b/pjrc/usb.c old mode 100755 new mode 100644 -- 2.39.3 From 258fd3c3680fadd16433511c038ac52dab0c39ae Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 25 Feb 2011 21:58:00 +0900 Subject: [PATCH 05/16] FIX: host_get_first_key in vusb/host.c --- vusb/host.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/vusb/host.c b/vusb/host.c index f637abac..05a1f29c 100644 --- a/vusb/host.c +++ b/vusb/host.c @@ -86,14 +86,17 @@ uint8_t host_has_anykey(void) return cnt; } -uint8_t *host_get_keys(void) +uint8_t host_get_first_key(void) { - return keyboard_report->keys; -} - -uint8_t host_get_mods(void) -{ - return keyboard_report->mods; +#ifdef USB_NKRO_ENABLE + if (keyboard_nkro) { + uint8_t i = 0; + for (; i < REPORT_KEYS && !keyboard_report->keys[i]; i++) + ; + return i<<3 | biton(keyboard_report->keys[i]); + } +#endif + return keyboard_report->keys[0]; } -- 2.39.3 From 1a7c3585ed9a68099e371b3180a404dd5d08ce1a Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 25 Feb 2011 22:46:13 +0900 Subject: [PATCH 06/16] ADD: V-USB Circuit in README --- ps2_usb/README | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ps2_usb/README b/ps2_usb/README index ad5c6c43..a0ff286c 100644 --- a/ps2_usb/README +++ b/ps2_usb/README @@ -74,6 +74,30 @@ Build for V-USB 4. program your V-USB controller. +V-USB Circuit +------------- + +---+ +---------------+ +USB GND | | ATmega168 | +=== C3 | | +5V <-------+--------+---|Vcc,AVCC | PS/2 + R1 | | ==== +D- <----+--+-----R2-----|INT0 RXD|------->DATA +D+ <----|---+----R3-----|INT1 XCK|------->CLOCK + Z1 Z2 | | ->5V +GND<----+---+--+--+-----|GND | ->GND + | | | | + | C2-+--|XTAL1 | + | X1 | | + +--C3-+--|XTAL2 | + +---------------+ +R1: 1.5K Ohm +R2,R3: 68 Ohm +Z1,Z2: Zenner 3.6V +C1,C2: 22pF +C3: 0.1uF +X1: Crystal 20MHz(16MHz/12MHz) + + Keymap ------ You can change a keymap by editing code of keymap.c like following. -- 2.39.3 From cec254950509038ca9c805e87feea9091d77d29f Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 10 Mar 2011 00:50:27 +0900 Subject: [PATCH 07/16] FIX: send last report when idle timeouts. (pjrc) --- adb.c | 2 +- adb_usb/Makefile | 2 +- adb_usb/config.h | 4 ++-- adb_usb/matrix.c | 2 +- command.c | 5 ++++- pjrc/host.c | 4 ++++ pjrc/usb.c | 7 ++++--- pjrc/usb_keyboard.c | 1 + vusb/host.c | 5 +++++ 9 files changed, 23 insertions(+), 9 deletions(-) mode change 100644 => 100755 adb.c mode change 100644 => 100755 adb_usb/Makefile mode change 100644 => 100755 adb_usb/matrix.c mode change 100644 => 100755 command.c diff --git a/adb.c b/adb.c old mode 100644 new mode 100755 index 6a3fb8e0..006e424a --- a/adb.c +++ b/adb.c @@ -280,7 +280,6 @@ Pinouts 4: GND - Commands -------- ADB command is 1byte and consists of 4bit-address, 2bit-command @@ -381,6 +380,7 @@ Keyboard Data(Register0) You can read the state from PSW line(active low) however the switch has a special scancode 0x7F7F, so you can also read from Data line. It uses 0xFFFF for release scancode. + Release code seems to delay about some 100ms. Due to Mac soft power? Keyboard LEDs & state of keys(Register2) This register hold current state of three LEDs and nine keys. diff --git a/adb_usb/Makefile b/adb_usb/Makefile old mode 100644 new mode 100755 index 61e43a72..92b9ba1a --- a/adb_usb/Makefile +++ b/adb_usb/Makefile @@ -44,7 +44,7 @@ USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System c #---------------- Programming Options -------------------------- -PROGRAM_CMD = teensy_loader_cli.exe -mmcu=$(MCU) -w -v $(TARGET).hex +PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex diff --git a/adb_usb/config.h b/adb_usb/config.h index ea78dd9b..adc76bd5 100644 --- a/adb_usb/config.h +++ b/adb_usb/config.h @@ -17,8 +17,8 @@ /* key combination for command */ #define IS_COMMAND() ( \ - keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \ - keyboard_report->mods == (BIT_LCTRL | BIT_RSHIFT) \ + keyboard_report->mods == (BIT_LSHIFT | BIT_LCTRL | BIT_LALT | BIT_LGUI) || \ + keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) \ ) diff --git a/adb_usb/matrix.c b/adb_usb/matrix.c old mode 100644 new mode 100755 index 72515dce..db202896 --- a/adb_usb/matrix.c +++ b/adb_usb/matrix.c @@ -87,7 +87,7 @@ uint8_t matrix_scan(void) _register_key(key1); } - if (debug_matrix && matrix_is_modified()) { + if (debug_enable) { print("adb_host_kbd_recv: "); phex16(codes); print("\n"); } return 1; diff --git a/command.c b/command.c old mode 100644 new mode 100755 index 7afed5d7..cd51b79c --- a/command.c +++ b/command.c @@ -102,7 +102,10 @@ uint8_t command_proc(void) print("UDCON: "); phex(UDCON); print("\n"); print("UDIEN: "); phex(UDIEN); print("\n"); print("UDINT: "); phex(UDINT); print("\n"); - print("host_keyboard_leds:"); phex(host_keyboard_leds()); print("\n"); + print("usb_keyboard_leds:"); phex(usb_keyboard_leds); print("\n"); + print("usb_keyboard_protocol: "); phex(usb_keyboard_protocol); print("\n"); + print("usb_keyboard_idle_config:"); phex(usb_keyboard_idle_config); print("\n"); + print("usb_keyboard_idle_count:"); phex(usb_keyboard_idle_count); print("\n"); #endif break; #ifdef USB_NKRO_ENABLE diff --git a/pjrc/host.c b/pjrc/host.c index 8da88517..b69c6cb2 100644 --- a/pjrc/host.c +++ b/pjrc/host.c @@ -1,4 +1,5 @@ #include +#include #include "usb_keycodes.h" #include "usb_keyboard.h" #include "usb_mouse.h" @@ -58,9 +59,12 @@ void host_add_code(uint8_t code) void host_swap_keyboard_report(void) { + uint8_t sreg = SREG; + cli(); report_keyboard_t *tmp = keyboard_report_prev; keyboard_report_prev = keyboard_report; keyboard_report = tmp; + SREG = sreg; } void host_clear_keyboard_report(void) diff --git a/pjrc/usb.c b/pjrc/usb.c index 9fd30dee..3cfe9473 100644 --- a/pjrc/usb.c +++ b/pjrc/usb.c @@ -687,10 +687,11 @@ ISR(USB_GEN_vect) usb_keyboard_idle_count++; if (usb_keyboard_idle_count == usb_keyboard_idle_config) { usb_keyboard_idle_count = 0; - UEDATX = keyboard_report->mods; + UEDATX = keyboard_report_prev->mods; UEDATX = 0; - for (i=0; i<6; i++) { - UEDATX = keyboard_report->keys[i]; + uint8_t keys = usb_keyboard_protocol ? KBD_REPORT_KEYS : 6; + for (i=0; ikeys[i]; } UEINTX = 0x3A; } diff --git a/pjrc/usb_keyboard.c b/pjrc/usb_keyboard.c index fc05f7c9..8aae2d38 100644 --- a/pjrc/usb_keyboard.c +++ b/pjrc/usb_keyboard.c @@ -15,6 +15,7 @@ uint8_t usb_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; // count until idle timeout diff --git a/vusb/host.c b/vusb/host.c index 05a1f29c..901537bc 100644 --- a/vusb/host.c +++ b/vusb/host.c @@ -1,3 +1,5 @@ +#include +#include #include "usbdrv.h" #include "usbconfig.h" #include "print.h" @@ -63,9 +65,12 @@ void host_add_code(uint8_t code) void host_swap_keyboard_report(void) { + uint8_t sreg = SREG; + cli(); report_keyboard_t *tmp = keyboard_report_prev; keyboard_report_prev = keyboard_report; keyboard_report = tmp; + SREG = sreg; } void host_clear_keyboard_report(void) -- 2.39.3 From 13e4662baee972a6df340bfabe5fcb8aa00646e3 Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 4 May 2011 08:12:27 +0900 Subject: [PATCH 08/16] minor fix for HHKB Makefile and doc --- hhkb/Makefile | 2 +- hhkb/doc/HHKB.txt | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) mode change 100644 => 100755 hhkb/Makefile diff --git a/hhkb/Makefile b/hhkb/Makefile old mode 100644 new mode 100755 index 2c8cd5af..4a0af1cd --- a/hhkb/Makefile +++ b/hhkb/Makefile @@ -42,7 +42,7 @@ USB_NKRO_ENABLE = yes # USB Nkey Rollover #---------------- Programming Options -------------------------- -PROGRAM_CMD = teensy_loader_cli.exe -mmcu=$(MCU) -w -v $(TARGET).hex +PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex diff --git a/hhkb/doc/HHKB.txt b/hhkb/doc/HHKB.txt index e9f41ada..ace931de 100644 --- a/hhkb/doc/HHKB.txt +++ b/hhkb/doc/HHKB.txt @@ -68,7 +68,7 @@ Keyswitch PCB: http://www.alldatasheet.com/datasheet-pdf/pdf/27373/TI/SN74LS145D.html BU9831 Non-volatile electronic potentiometer: for calibration? http://www.alldatasheet.com/datasheet-pdf/pdf/36387/ROHM/BU9831.html - TP1684 Capacitive Sensing controller: no datasheet available. + TP1683/4 Capacitive Sensing controller: no datasheet available. (HHKB_keyswitch.jpg) @@ -120,16 +120,16 @@ Matrix diagram: |bias control? - - - - - - - - --- | 3.9K*8 R R R R R R R R | +--------^+ +--------+ - - - - - - - - | - | TP 1684 | | HC4051 <0-------|-|-|-|-|-|-|-|--|R|-+ + | 2| | HC4051 <0-------|-|-|-|-|-|-|-|--|R|-+ | |capa. | <1-------|-|-|-|-|-|-|-|--|R|-+ - | |sense | <2-------|-|-|-|-|-|-|-|--|R|-+ - | <------| <3-------|-|-|-|-|-|-|-|--|R|-+ + | TP1684 |sense | <2-------|-|-|-|-|-|-|-|--|R|-+ + | 11<------| <3-------|-|-|-|-|-|-|-|--|R|-+ | | | <4-------|-|-|-|-|-|-|-|--|R|-+ | | | <5-------|-|-|-|-|-|-|-|--|R|-+ - | |calib.| <6-------|-|-|-|-|-|-|-|--|R|-+ - | <-+? | <7-------|-|-|-|-|-|-|-|--|R|-+ - +---V-----+ | +-^-^-^--+ 0 1 2 3 4 5 6 7 33K*8 - KEY ??? | A B C +-----------------+ + | <-+ | <6-------|-|-|-|-|-|-|-|--|R|-+ + | 1 4 | | | <7-------|-|-|-|-|-|-|-|--|R|-+ + +---V---^-+ | +-^-^-^--+ 0 1 2 3 4 5 6 7 33K*8 + KEY PREV | A B C +-----------------+ | | +-^----+ | | | | LS145 | Vcc | | |BU9831| | | | +-^--^--^--^------+ --- | | +------+ | | | A B C D +------+ -- 2.39.3 From 5de62e26a04bd99a1f70f13270ab95e6b3e85d59 Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 4 May 2011 08:15:29 +0900 Subject: [PATCH 09/16] fix for ps2_usb Makefile and circuit --- ps2_usb/Makefile | 2 +- ps2_usb/README | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 ps2_usb/Makefile diff --git a/ps2_usb/Makefile b/ps2_usb/Makefile old mode 100644 new mode 100755 index af73be2c..7b55e020 --- a/ps2_usb/Makefile +++ b/ps2_usb/Makefile @@ -43,7 +43,7 @@ USB_NKRO_ENABLE = yes # USB Nkey Rollover #---------------- Programming Options -------------------------- -PROGRAM_CMD = teensy_loader_cli.exe -mmcu=$(MCU) -w -v $(TARGET).hex +PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex diff --git a/ps2_usb/README b/ps2_usb/README index a0ff286c..f4f344c0 100644 --- a/ps2_usb/README +++ b/ps2_usb/README @@ -81,8 +81,8 @@ USB GND | | ATmega168 | === C3 | | 5V <-------+--------+---|Vcc,AVCC | PS/2 R1 | | ==== -D- <----+--+-----R2-----|INT0 RXD|------->DATA -D+ <----|---+----R3-----|INT1 XCK|------->CLOCK +D- <----+--+-----R2-----|INT1 RXD|------->DATA +D+ <----|---+----R3-----|INT0 XCK|------->CLOCK Z1 Z2 | | ->5V GND<----+---+--+--+-----|GND | ->GND | | | | -- 2.39.3 From b0b6c333320216492ea63979e9a01f5c4cb090db Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 4 May 2011 13:42:34 +0900 Subject: [PATCH 10/16] ad hoc fix for IDLE bug which affects on Mac only. --- pjrc/usb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) mode change 100644 => 100755 pjrc/usb.c diff --git a/pjrc/usb.c b/pjrc/usb.c old mode 100644 new mode 100755 index 3cfe9473..b2c18d98 --- a/pjrc/usb.c +++ b/pjrc/usb.c @@ -681,7 +681,8 @@ ISR(USB_GEN_vect) UEINTX = 0x3A; } } - if (usb_keyboard_idle_config && (++div4 & 3) == 0) { + /* TODO: should keep IDLE rate on each keyboard interface */ + if (!keyboard_nkro && usb_keyboard_idle_config && (++div4 & 3) == 0) { UENUM = KBD_ENDPOINT; if (UEINTX & (1< Date: Wed, 4 May 2011 21:19:34 +0900 Subject: [PATCH 11/16] fix bug: send Fn key even after the layer is used. --- layer.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/layer.c b/layer.c index 0c59c91f..700752c9 100644 --- a/layer.c +++ b/layer.c @@ -52,7 +52,7 @@ */ // LAYER_ENTER_DELAY: prevent from moving new layer -#define LAYER_ENTER_DELAY 10 +#define LAYER_ENTER_DELAY 5 // LAYER_SEND_FN_TERM: send keycode if release key in this term #define LAYER_SEND_FN_TERM 40 @@ -76,7 +76,7 @@ uint8_t layer_get_keycode(uint8_t row, uint8_t col) } // bit substract b from a -#define BIT_SUBT(a, b) (a&(a^b)) +#define BIT_SUBST(a, b) (a&(a^b)) void layer_switching(uint8_t fn_bits) { // layer switching @@ -90,7 +90,7 @@ void layer_switching(uint8_t fn_bits) // do nothing } else { if (timer_elapsed(last_timer) > LAYER_ENTER_DELAY) { - uint8_t _layer_to_switch = new_layer(BIT_SUBT(fn_bits, sent_fn)); + uint8_t _layer_to_switch = new_layer(BIT_SUBST(fn_bits, sent_fn)); if (current_layer != _layer_to_switch) { // not switch layer yet debug("Fn case: 1,2,3(LAYER_ENTER_DELAY passed)\n"); debug("Switch Layer: "); debug_hex(current_layer); @@ -100,7 +100,7 @@ void layer_switching(uint8_t fn_bits) } } else { if (host_has_anykey()) { // other keys is pressed - uint8_t _fn_to_send = BIT_SUBT(fn_bits, sent_fn); + uint8_t _fn_to_send = BIT_SUBST(fn_bits, sent_fn); if (_fn_to_send) { debug("Fn case: 4(send Fn before other key pressed)\n"); // send only Fn key first @@ -127,27 +127,26 @@ void layer_switching(uint8_t fn_bits) debug("last_timer: "); debug_hex16(last_timer); debug("\n"); // pressed Fn - if ((fn_changed = BIT_SUBT(fn_bits, last_fn))) { + if ((fn_changed = BIT_SUBST(fn_bits, last_fn))) { debug("fn_changed: "); debug_bin(fn_changed); debug("\n"); if (host_has_anykey()) { debug("Fn case: 5(pressed Fn with other key)\n"); sent_fn |= fn_changed; } else if (fn_changed & sent_fn) { // pressed same Fn in a row if (timer_elapsed(last_timer) > LAYER_ENTER_DELAY) { - debug("Fn case: 6(repate2)\n"); + debug("Fn case: 6(not repeat)\n"); // time passed: not repeate sent_fn &= ~fn_changed; } else { - debug("Fn case: 6(repate)\n"); + debug("Fn case: 6(repeat)\n"); } } } // released Fn - if ((fn_changed = BIT_SUBT(last_fn, fn_bits))) { + if ((fn_changed = BIT_SUBST(last_fn, fn_bits))) { debug("fn_changed: "); debug_bin(fn_changed); debug("\n"); if (timer_elapsed(last_timer) < LAYER_SEND_FN_TERM) { - //if (!layer_used && BIT_SUBT(fn_changed, sent_fn)) { // layer not used && Fn not sent - if (BIT_SUBT(fn_changed, sent_fn)) { // layer not used && Fn not sent + if (!layer_used && BIT_SUBST(fn_changed, sent_fn)) { debug("Fn case: 2(send Fn one shot: released Fn during LAYER_SEND_FN_TERM)\n"); // send only Fn key first host_swap_keyboard_report(); @@ -160,11 +159,11 @@ void layer_switching(uint8_t fn_bits) } } debug("Switch Layer(released Fn): "); debug_hex(current_layer); - current_layer = new_layer(BIT_SUBT(fn_bits, sent_fn)); - layer_used = false; + current_layer = new_layer(BIT_SUBST(fn_bits, sent_fn)); debug(" -> "); debug_hex(current_layer); debug("\n"); } + layer_used = false; last_fn = fn_bits; last_mods = keyboard_report->mods; last_timer = timer_read(); -- 2.39.3 From 61e12a3157ea6860f23bf8e29372aa70aeb02be0 Mon Sep 17 00:00:00 2001 From: tmk Date: Sat, 7 May 2011 00:04:18 +0900 Subject: [PATCH 12/16] move files: main_vusb.c ps2_usart.c sendchar_usart.c from ps2_usb to common dir --- Makefile.vusb | 3 +- ps2_usb/main_vusb.c => main_vusb.c | 0 ps2_usb/ps2_usart.c => ps2_usart.c | 0 ps2_usb/Makefile | 2 +- ps2_usb/Makefile.vusb | 6 ++-- ps2_usb/sendchar_dummy.c | 8 ----- ps2_usb/sendchar_usart.c | 58 ------------------------------ vusb/sendchar_usart.c | 19 ++++++++++ 8 files changed, 25 insertions(+), 71 deletions(-) rename ps2_usb/main_vusb.c => main_vusb.c (100%) rename ps2_usb/ps2_usart.c => ps2_usart.c (100%) delete mode 100644 ps2_usb/sendchar_dummy.c delete mode 100644 ps2_usb/sendchar_usart.c create mode 100644 vusb/sendchar_usart.c diff --git a/Makefile.vusb b/Makefile.vusb index 0ef1b115..b8e71a8e 100644 --- a/Makefile.vusb +++ b/Makefile.vusb @@ -2,7 +2,8 @@ OPT_DEFS += -DHOST_VUSB SRC = usbdrv.c \ usbdrvasm.S \ - oddebug.c + oddebug.c \ + sendchar_usart.c SRC += $(TARGET_SRC) diff --git a/ps2_usb/main_vusb.c b/main_vusb.c similarity index 100% rename from ps2_usb/main_vusb.c rename to main_vusb.c diff --git a/ps2_usb/ps2_usart.c b/ps2_usart.c similarity index 100% rename from ps2_usb/ps2_usart.c rename to ps2_usart.c diff --git a/ps2_usb/Makefile b/ps2_usb/Makefile index 7b55e020..60596291 100755 --- a/ps2_usb/Makefile +++ b/ps2_usb/Makefile @@ -10,7 +10,7 @@ TARGET_DIR = . # keyboard dependent files TARGET_SRC = main_pjrc.c \ keymap.c \ - matrix.c \ + matrix.c \ led.c \ ps2.c diff --git a/ps2_usb/Makefile.vusb b/ps2_usb/Makefile.vusb index 7b69dc27..6e49fc44 100644 --- a/ps2_usb/Makefile.vusb +++ b/ps2_usb/Makefile.vusb @@ -12,13 +12,13 @@ TARGET_SRC = main_vusb.c \ keymap.c \ matrix.c \ led.c \ - ps2_usart.c \ - sendchar_dummy.c -# sendchar_usart.c + ps2_usart.c CONFIG_H = config_vusb.h +# V-USB debug level: To use ps2_usart.c level must be 0 +# ps2_usart.c requires USART to receive PS/2 signal. OPT_DEFS = -DDEBUG_LEVEL=0 diff --git a/ps2_usb/sendchar_dummy.c b/ps2_usb/sendchar_dummy.c deleted file mode 100644 index 8c9e583f..00000000 --- a/ps2_usb/sendchar_dummy.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "sendchar.h" - - -int8_t sendchar(uint8_t c) -{ - return 1; -} diff --git a/ps2_usb/sendchar_usart.c b/ps2_usb/sendchar_usart.c deleted file mode 100644 index fe18177a..00000000 --- a/ps2_usb/sendchar_usart.c +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include "oddebug.h" -#include "sendchar.h" - - -/* from oddebug.h */ -#if defined UBRR -# define ODDBG_UBRR UBRR -#elif defined UBRRL -# define ODDBG_UBRR UBRRL -#elif defined UBRR0 -# define ODDBG_UBRR UBRR0 -#elif defined UBRR0L -# define ODDBG_UBRR UBRR0L -#endif - -#if defined UCR -# define ODDBG_UCR UCR -#elif defined UCSRB -# define ODDBG_UCR UCSRB -#elif defined UCSR0B -# define ODDBG_UCR UCSR0B -#endif - -#if defined TXEN -# define ODDBG_TXEN TXEN -#else -# define ODDBG_TXEN TXEN0 -#endif - -#if defined USR -# define ODDBG_USR USR -#elif defined UCSRA -# define ODDBG_USR UCSRA -#elif defined UCSR0A -# define ODDBG_USR UCSR0A -#endif - -#if defined UDRE -# define ODDBG_UDRE UDRE -#else -# define ODDBG_UDRE UDRE0 -#endif - -#if defined UDR -# define ODDBG_UDR UDR -#elif defined UDR0 -# define ODDBG_UDR UDR0 -#endif - - -/* from oddebug.c */ -int8_t sendchar(uint8_t c) -{ - while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */ - ODDBG_UDR = c; - return 1; -} diff --git a/vusb/sendchar_usart.c b/vusb/sendchar_usart.c new file mode 100644 index 00000000..d6f3c894 --- /dev/null +++ b/vusb/sendchar_usart.c @@ -0,0 +1,19 @@ +#include +#include "oddebug.h" +#include "sendchar.h" + + +#if DEBUG_LEVEL > 0 +/* from oddebug.c */ +int8_t sendchar(uint8_t c) +{ + while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */ + ODDBG_UDR = c; + return 1; +} +#else +int8_t sendchar(uint8_t c) +{ + return 1; +} +#endif -- 2.39.3 From 068c31a7ba9fc6aea33f69c0edb30ad195c320ec Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 16 May 2011 00:08:06 +0900 Subject: [PATCH 13/16] added initial V-USB support for HHKB --- hhkb/Makefile.vusb | 83 ++++++++++ hhkb/config_vusb.h | 120 ++++++++++++++ hhkb/keymap.c | 30 +--- hhkb/matrix.c | 98 ++++++++---- hhkb/usbconfig.h | 378 +++++++++++++++++++++++++++++++++++++++++++++ ps2.c | 5 + vusb/host.c | 4 +- 7 files changed, 661 insertions(+), 57 deletions(-) create mode 100644 hhkb/Makefile.vusb create mode 100644 hhkb/config_vusb.h create mode 100644 hhkb/usbconfig.h diff --git a/hhkb/Makefile.vusb b/hhkb/Makefile.vusb new file mode 100644 index 00000000..ea89a6f6 --- /dev/null +++ b/hhkb/Makefile.vusb @@ -0,0 +1,83 @@ +# Target file name (without extension). +TARGET = hhkb_vusb + +# Directory common source filess exist +COMMON_DIR = .. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# keyboard dependent files +TARGET_SRC = main_vusb.c \ + keymap.c \ + matrix.c \ + led.c + +CONFIG_H = config_vusb.h + + +# V-USB debug level: To use ps2_usart.c level must be 0 +# ps2_usart.c requires USART to receive PS/2 signal. +OPT_DEFS = -DDEBUG_LEVEL=0 + + +# 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 +MCU = atmega168 + + +# 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 = 20000000 + + +# Build Options +# comment out to disable the options. +# +MOUSEKEY_ENABLE = yes # Mouse keys +#USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System control) +#USB_NKRO_ENABLE = yes # USB Nkey Rollover + + + +#---------------- Programming Options -------------------------- +AVRDUDE = avrdude +# Type: avrdude -c ? to get a full listing. +AVRDUDE_PROGRAMMER = usbasp +AVRDUDE_PORT = +AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex +#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep + +# Uncomment the following if you want avrdude's erase cycle counter. +# Note that this counter needs to be initialized first using -Yn, +# see avrdude manual. +#AVRDUDE_ERASE_COUNTER = -y + +# Uncomment the following if you do /not/ wish a verification to be +# performed after programming the device. +#AVRDUDE_NO_VERIFY = -V + +# Increase verbosity level. Please use this when submitting bug +# reports about avrdude. See +# to submit bug reports. +#AVRDUDE_VERBOSE = -v -v + +#AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) +AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER) +AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) +AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) +AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) + +PROGRAM_CMD = $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) + + + +include $(COMMON_DIR)/Makefile.vusb +include $(COMMON_DIR)/Makefile.common diff --git a/hhkb/config_vusb.h b/hhkb/config_vusb.h new file mode 100644 index 00000000..3b44b94a --- /dev/null +++ b/hhkb/config_vusb.h @@ -0,0 +1,120 @@ +#ifndef CONFIG_H +#define CONFIG_H + + +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0xC0FE +// TODO: share these strings with usbconfig.h +// Edit usbconfig.h to change these. +#define MANUFACTURER t.m.k. +#define PRODUCT HHKB mod +#define DESCRIPTION t.m.k. keyboard firmware for HHKB mod + + +/* matrix size */ +#define MATRIX_ROWS 8 +#define MATRIX_COLS 8 + + +/* key combination for command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \ + keyboard_report->mods == (BIT_LCTRL | BIT_RSHIFT) \ +) + + +/* mouse keys */ +#ifdef MOUSEKEY_ENABLE +# define MOUSEKEY_DELAY_TIME 255 +#endif + + +/* PS/2 lines */ +#ifdef PS2_MOUSE_ENABLE + +#define PS2_CLOCK_PORT PORTD +#define PS2_CLOCK_PIN PIND +#define PS2_CLOCK_DDR DDRD +#define PS2_CLOCK_BIT 4 +#define PS2_DATA_PORT PORTD +#define PS2_DATA_PIN PIND +#define PS2_DATA_DDR DDRD +#define PS2_DATA_BIT 0 + + +// Synchronous USART is used to receive data from keyboard. +// Use RXD pin for PS/2 DATA line and XCK for PS/2 CLOCK. +// NOTE: This is recomended strongly if you use V-USB library. +#define PS2_USE_USART + +// External or Pin Change Interrupt is used to receive data from keyboard. +// Use INT1 or PCINTxx for PS/2 CLOCK line. see below. +//#define PS2_USE_INT + + +#ifdef PS2_USE_USART +// synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge +// set DDR of CLOCK as input to be slave +#define PS2_USART_INIT() do { \ + PS2_CLOCK_DDR &= ~(1< #include #include +#include #include #include "print.h" #include "util.h" @@ -31,29 +32,62 @@ static uint16_t _matrix0[MATRIX_ROWS]; static uint16_t _matrix1[MATRIX_ROWS]; #endif +// HHKB has no ghost and no bounce. #ifdef MATRIX_HAS_GHOST static bool matrix_has_ghost_in_row(uint8_t row); #endif -// matrix is active low. (key on: 0/key off: 1) +// Matrix I/O ports // -// HHKB has no ghost and no bounce. -// row: HC4051 select input channel(0-8) -// PB0, PB1, PB2(A, B, C) -// col: LS145 select low output line(0-8) -// PB3, PB4, PB5, PB6(A, B, C, D) -// use D as ENABLE: (enable: 0/unenable: 1) -// key: KEY: (on: 0/ off:1) -// KEY_PREV: (on: 1/ off: 0) -// PE6,PE7(KEY, KEY_PREV) -#define COL_ENABLE (1<<6) -#define KEY_SELELCT(ROW, COL) (PORTB = (PORTB&(1<<7))|COL_ENABLE|(((COL)&0x07)<<3)|((ROW)&0x07)) -#define KEY_ENABLE (PORTB &= ~COL_ENABLE) -#define KEY_UNABLE (PORTB |= COL_ENABLE) -#define KEY_STATE (PINE&(1<<6)) -#define KEY_PREV_ON (PORTE |= (1<<7)) -#define KEY_PREV_OFF (PORTE &= ~(1<<7)) +// row: HC4051[A,B,C] selects scan row0-7 +// col: LS145[A,B,C,D] selects scan col0-7 and enable(D) +// key: on: 0/off: 1 +// prev: unknown: output previous key state(negated)? + +#ifdef HOST_PJRC +// Ports for Teensy +// row: PB0-2 +// col: PB3-5,6 +// key: PE6(pull-uped) +// prev: PE7 +#define KEY_INIT() do { \ + DDRB |= 0x7F; \ + DDRE |= (1<<7); \ + DDRE &= ~(1<<6); \ + PORTE |= (1<<6); \ +} while (0) +#define KEY_SELECT(ROW, COL) (PORTB = (PORTB & 0xC0) | \ + (((COL) & 0x07)<<3) | \ + ((ROW) & 0x07)) +#define KEY_ENABLE() (PORTB &= ~(1<<6)) +#define KEY_UNABLE() (PORTB |= (1<<6)) +#define KEY_STATE() (PINE & (1<<6)) +#define KEY_PREV_ON() (PORTE |= (1<<7)) +#define KEY_PREV_OFF() (PORTE &= ~(1<<7)) + +#else +// Ports for V-USB +// key: PB0(pull-uped) +// prev: PB1 +// row: PB2-4 +// col: PC0-2,3 +#define KEY_INIT() do { \ + DDRB |= 0x1E; \ + DDRB &= ~(1<<0); \ + PORTB |= (1<<0); \ + DDRC |= 0x0F; \ +} while (0) +#define KEY_SELECT(ROW, COL) do { \ + PORTB = (PORTB & 0xE3) | ((ROW) & 0x07)<<2; \ + PORTC = (PORTC & 0xF8) | ((COL) & 0x07); \ +} while (0) +#define KEY_ENABLE() (PORTC &= ~(1<<3)) +#define KEY_UNABLE() (PORTC |= (1<<3)) +#define KEY_STATE() (PINB & (1<<0)) +#define KEY_PREV_ON() (PORTB |= (1<<1)) +#define KEY_PREV_OFF() (PORTB &= ~(1<<1)) +#endif inline @@ -70,13 +104,7 @@ uint8_t matrix_cols(void) void matrix_init(void) { - // row & col output(PB0-6) - DDRB = 0xFF; - KEY_SELELCT(0, 0); - // KEY: input with pullup(PE6) - // KEY_PREV: output(PE7) - DDRE = 0xBF; - PORTE = 0x40; + KEY_INIT(); // initialize matrix state: all keys off for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00; @@ -95,21 +123,31 @@ uint8_t matrix_scan(void) for (uint8_t row = 0; row < MATRIX_ROWS; row++) { for (uint8_t col = 0; col < MATRIX_COLS; col++) { - KEY_SELELCT(row, col); + KEY_SELECT(row, col); _delay_us(40); // from logic analyzer chart if (matrix_prev[row] & (1<> 8) & 0xFF) +/* USB vendor ID for the device, low byte first. If you have registered your + * own Vendor ID, define it here. Otherwise you may use one of obdev's free + * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules! + * *** IMPORTANT NOTE *** + * This template uses obdev's shared VID/PID pair for Vendor Class devices + * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand + * the implications! + */ +#define USB_CFG_DEVICE_ID (PRODUCT_ID & 0xFF), ((PRODUCT_ID >> 8) & 0xFF) +/* This is the ID of the product, low byte first. It is interpreted in the + * scope of the vendor ID. If you have registered your own VID with usb.org + * or if you have licensed a PID from somebody else, define it here. Otherwise + * you may use one of obdev's free shared VID/PID pairs. See the file + * USB-IDs-for-free.txt for details! + * *** IMPORTANT NOTE *** + * This template uses obdev's shared VID/PID pair for Vendor Class devices + * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand + * the implications! + */ +#define USB_CFG_DEVICE_VERSION 0x00, 0x01 +/* Version number of the device: Minor number first, then major number. + */ +#define USB_CFG_VENDOR_NAME 't', '.', 'm', '.', 'k', '.' +#define USB_CFG_VENDOR_NAME_LEN 6 +/* These two values define the vendor name returned by the USB device. The name + * must be given as a list of characters under single quotes. The characters + * are interpreted as Unicode (UTF-16) entities. + * If you don't want a vendor name string, undefine these macros. + * ALWAYS define a vendor name containing your Internet domain name if you use + * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for + * details. + */ +#define USB_CFG_DEVICE_NAME 'H', 'H', 'K', 'B', ' ', 'm', 'o', 'd' +#define USB_CFG_DEVICE_NAME_LEN 8 +/* Same as above for the device name. If you don't want a device name, undefine + * the macros. See the file USB-IDs-for-free.txt before you assign a name if + * you use a shared VID/PID. + */ +/*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */ +/*#define USB_CFG_SERIAL_NUMBER_LEN 0 */ +/* Same as above for the serial number. If you don't want a serial number, + * undefine the macros. + * It may be useful to provide the serial number through other means than at + * compile time. See the section about descriptor properties below for how + * to fine tune control over USB descriptors such as the string descriptor + * for the serial number. + */ +#define USB_CFG_DEVICE_CLASS 0 +#define USB_CFG_DEVICE_SUBCLASS 0 +/* See USB specification if you want to conform to an existing device class. + * Class 0xff is "vendor specific". + */ +#define USB_CFG_INTERFACE_CLASS 3 /* HID */ +#define USB_CFG_INTERFACE_SUBCLASS 1 /* Boot */ +#define USB_CFG_INTERFACE_PROTOCOL 1 /* Keyboard */ +/* See USB specification if you want to conform to an existing device class or + * protocol. The following classes must be set at interface level: + * HID class is 3, no subclass and protocol required (but may be useful!) + * CDC class is 2, use subclass 2 and protocol 1 for ACM + */ +#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 0 +/* Define this to the length of the HID report descriptor, if you implement + * an HID device. Otherwise don't define it or define it to 0. + * If you use this define, you must add a PROGMEM character array named + * "usbHidReportDescriptor" to your code which contains the report descriptor. + * Don't forget to keep the array and this define in sync! + */ + +/* #define USB_PUBLIC static */ +/* Use the define above if you #include usbdrv.c instead of linking against it. + * This technique saves a couple of bytes in flash memory. + */ + +/* ------------------- Fine Control over USB Descriptors ------------------- */ +/* If you don't want to use the driver's default USB descriptors, you can + * provide our own. These can be provided as (1) fixed length static data in + * flash memory, (2) fixed length static data in RAM or (3) dynamically at + * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more + * information about this function. + * Descriptor handling is configured through the descriptor's properties. If + * no properties are defined or if they are 0, the default descriptor is used. + * Possible properties are: + * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched + * at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is + * used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if + * you want RAM pointers. + * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found + * in static memory is in RAM, not in flash memory. + * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash), + * the driver must know the descriptor's length. The descriptor itself is + * found at the address of a well known identifier (see below). + * List of static descriptor names (must be declared PROGMEM if in flash): + * char usbDescriptorDevice[]; + * char usbDescriptorConfiguration[]; + * char usbDescriptorHidReport[]; + * char usbDescriptorString0[]; + * int usbDescriptorStringVendor[]; + * int usbDescriptorStringDevice[]; + * int usbDescriptorStringSerialNumber[]; + * Other descriptors can't be provided statically, they must be provided + * dynamically at runtime. + * + * Descriptor properties are or-ed or added together, e.g.: + * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18)) + * + * The following descriptors are defined: + * USB_CFG_DESCR_PROPS_DEVICE + * USB_CFG_DESCR_PROPS_CONFIGURATION + * USB_CFG_DESCR_PROPS_STRINGS + * USB_CFG_DESCR_PROPS_STRING_0 + * USB_CFG_DESCR_PROPS_STRING_VENDOR + * USB_CFG_DESCR_PROPS_STRING_PRODUCT + * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER + * USB_CFG_DESCR_PROPS_HID + * USB_CFG_DESCR_PROPS_HID_REPORT + * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver) + * + * Note about string descriptors: String descriptors are not just strings, they + * are Unicode strings prefixed with a 2 byte header. Example: + * int serialNumberDescriptor[] = { + * USB_STRING_DESCRIPTOR_HEADER(6), + * 'S', 'e', 'r', 'i', 'a', 'l' + * }; + */ + +#define USB_CFG_DESCR_PROPS_DEVICE 0 +#define USB_CFG_DESCR_PROPS_CONFIGURATION USB_PROP_IS_DYNAMIC +//#define USB_CFG_DESCR_PROPS_CONFIGURATION 0 +#define USB_CFG_DESCR_PROPS_STRINGS 0 +#define USB_CFG_DESCR_PROPS_STRING_0 0 +#define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 +#define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 +#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 +//#define USB_CFG_DESCR_PROPS_HID USB_PROP_IS_DYNAMIC +#define USB_CFG_DESCR_PROPS_HID 0 +#define USB_CFG_DESCR_PROPS_HID_REPORT USB_PROP_IS_DYNAMIC +//#define USB_CFG_DESCR_PROPS_HID_REPORT 0 +#define USB_CFG_DESCR_PROPS_UNKNOWN 0 + +/* ----------------------- Optional MCU Description ------------------------ */ + +/* The following configurations have working defaults in usbdrv.h. You + * usually don't need to set them explicitly. Only if you want to run + * the driver on a device which is not yet supported or with a compiler + * which is not fully supported (such as IAR C) or if you use a differnt + * interrupt than INT0, you may have to define some of these. + */ +/* #define USB_INTR_CFG MCUCR */ +/* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */ +/* #define USB_INTR_CFG_CLR 0 */ +/* #define USB_INTR_ENABLE GIMSK */ +/* #define USB_INTR_ENABLE_BIT INT0 */ +/* #define USB_INTR_PENDING GIFR */ +/* #define USB_INTR_PENDING_BIT INTF0 */ +/* #define USB_INTR_VECTOR INT0_vect */ + +#endif /* __usbconfig_h_included__ */ diff --git a/ps2.c b/ps2.c index 99749cf6..d5c3d4d4 100644 --- a/ps2.c +++ b/ps2.c @@ -227,8 +227,13 @@ uint8_t ps2_host_recv(void) return pbuf_dequeue(); } +#if 0 #define DEBUGP_INIT() do { DDRC = 0xFF; } while (0) #define DEBUGP(x) do { PORTC = x; } while (0) +#else +#define DEBUGP_INIT() +#define DEBUGP(x) +#endif ISR(PS2_INT_VECT) { static enum { diff --git a/vusb/host.c b/vusb/host.c index 901537bc..c49eb62a 100644 --- a/vusb/host.c +++ b/vusb/host.c @@ -163,8 +163,8 @@ usbRequest_t *rq = (void *)data; if(rq->bRequest == USBRQ_HID_GET_REPORT){ debug(" GET_REPORT"); /* we only have one report type, so don't look at wValue */ - usbMsgPtr = (void *)keyboard_report; - return sizeof(*keyboard_report); + usbMsgPtr = (void *)keyboard_report_prev; + return sizeof(*keyboard_report_prev); }else if(rq->bRequest == USBRQ_HID_GET_IDLE){ debug(" GET_IDLE: "); debug_hex(idleRate); -- 2.39.3 From 74f7e19863ced21bf5d27c1fb1207f79f2195e24 Mon Sep 17 00:00:00 2001 From: tmk Date: Sat, 21 May 2011 10:28:57 +0900 Subject: [PATCH 14/16] added USB_EXTRA feature to HHKB/V-USB --- command.c | 6 +- hhkb/Makefile.vusb | 2 +- host.h | 22 ++++++ keyboard.c | 20 +++--- pjrc/host.c | 19 +++++ pjrc/usb.c | 4 ++ vusb/host.c | 171 +++++++++++++++++++++++++++------------------ 7 files changed, 166 insertions(+), 78 deletions(-) diff --git a/command.c b/command.c index cd51b79c..ca149dbd 100755 --- a/command.c +++ b/command.c @@ -122,11 +122,15 @@ uint8_t command_proc(void) #endif #ifdef USB_EXTRA_ENABLE case KB_ESC: +#ifdef HOST_PJRC if (suspend && remote_wakeup) { usb_remote_wakeup(); } else { - usb_extra_system_send(SYSTEM_POWER_DOWN); + host_system_send(SYSTEM_POWER_DOWN); } +#else + host_system_send(SYSTEM_POWER_DOWN); +#endif break; #endif case KB_BSPC: diff --git a/hhkb/Makefile.vusb b/hhkb/Makefile.vusb index ea89a6f6..7826ffd0 100644 --- a/hhkb/Makefile.vusb +++ b/hhkb/Makefile.vusb @@ -42,7 +42,7 @@ F_CPU = 20000000 # comment out to disable the options. # MOUSEKEY_ENABLE = yes # Mouse keys -#USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System control) +USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System control) #USB_NKRO_ENABLE = yes # USB Nkey Rollover diff --git a/host.h b/host.h index 045ccd8e..7ba9dd43 100644 --- a/host.h +++ b/host.h @@ -4,6 +4,11 @@ #include +/* report id */ +#define REPORT_ID_MOUSE 1 +#define REPORT_ID_SYSTEM 2 +#define REPORT_ID_AUDIO 3 + /* keyboard Modifiers in boot protocol report */ #define BIT_LCTRL (1<<0) #define BIT_LSHIFT (1<<1) @@ -25,6 +30,16 @@ #define MOUSE_BTN4 (1<<3) #define MOUSE_BTN5 (1<<4) +// Consumer Page(0x0C) Consumer Control(0x01) +#define AUDIO_VOL_UP (1<<0) +#define AUDIO_VOL_DOWN (1<<1) +#define AUDIO_MUTE (1<<2) + +// Generic Desktop Page(0x01) System Control(0x80) +#define SYSTEM_POWER_DOWN (1<<0) +#define SYSTEM_SLEEP (1<<1) +#define SYSTEM_WAKE_UP (1<<2) + #if defined(HOST_PJRC) # include "usb.h" @@ -44,6 +59,7 @@ typedef struct { } report_keyboard_t; typedef struct { + uint8_t report_id; uint8_t buttons; int8_t x; int8_t y; @@ -74,6 +90,12 @@ uint8_t host_get_first_key(void); void host_send_keyboard_report(void); +#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE) void host_mouse_send(report_mouse_t *report); +#endif +#ifdef USB_EXTRA_ENABLE +void host_system_send(uint8_t data); +void host_audio_send(uint8_t data); +#endif #endif diff --git a/keyboard.c b/keyboard.c index 03db3257..fd6e2304 100644 --- a/keyboard.c +++ b/keyboard.c @@ -11,9 +11,7 @@ #ifdef MOUSEKEY_ENABLE #include "mousekey.h" #endif -/* TODO: shoud make new API */ #ifdef USB_EXTRA_ENABLE -#include "usb_extra.h" #include #endif @@ -68,23 +66,27 @@ void keyboard_proc(void) #ifdef USB_EXTRA_ENABLE // audio control & system control else if (code == KB_MUTE) { - usb_extra_audio_send(AUDIO_MUTE); - usb_extra_audio_send(0); + host_audio_send(AUDIO_MUTE); _delay_ms(500); + host_audio_send(0); } else if (code == KB_VOLU) { - usb_extra_audio_send(AUDIO_VOL_UP); - usb_extra_audio_send(0); + host_audio_send(AUDIO_VOL_UP); _delay_ms(200); + host_audio_send(0); } else if (code == KB_VOLD) { - usb_extra_audio_send(AUDIO_VOL_DOWN); - usb_extra_audio_send(0); + host_audio_send(AUDIO_VOL_DOWN); _delay_ms(200); + host_audio_send(0); } else if (code == KB_PWR) { +#ifdef HOST_PJRC if (suspend && remote_wakeup) { usb_remote_wakeup(); } else { - usb_extra_system_send(SYSTEM_POWER_DOWN); + host_system_send(SYSTEM_POWER_DOWN); } +#else + host_system_send(SYSTEM_POWER_DOWN); +#endif _delay_ms(1000); } #endif diff --git a/pjrc/host.c b/pjrc/host.c index b69c6cb2..2a81e4c5 100644 --- a/pjrc/host.c +++ b/pjrc/host.c @@ -2,7 +2,12 @@ #include #include "usb_keycodes.h" #include "usb_keyboard.h" +#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE) #include "usb_mouse.h" +#endif +#ifdef USB_EXTRA_ENABLE +#include "usb_extra.h" +#endif #include "debug.h" #include "host.h" #include "util.h" @@ -104,10 +109,24 @@ void host_send_keyboard_report(void) usb_keyboard_send_report(keyboard_report); } +#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE) void host_mouse_send(report_mouse_t *report) { usb_mouse_send(report->x, report->y, report->v, report->h, report->buttons); } +#endif + +#ifdef USB_EXTRA_ENABLE +void host_system_send(uint8_t data) +{ + usb_extra_system_send(data); +} + +void host_audio_send(uint8_t data) +{ + usb_extra_audio_send(data); +} +#endif static inline void add_key_byte(uint8_t code) diff --git a/pjrc/usb.c b/pjrc/usb.c index b2c18d98..711c0e68 100755 --- a/pjrc/usb.c +++ b/pjrc/usb.c @@ -682,7 +682,11 @@ ISR(USB_GEN_vect) } } /* TODO: should keep IDLE rate on each keyboard interface */ +#ifdef USB_NKRO_ENABLE if (!keyboard_nkro && usb_keyboard_idle_config && (++div4 & 3) == 0) { +#else + if (usb_keyboard_idle_config && (++div4 & 3) == 0) { +#endif UENUM = KBD_ENDPOINT; if (UEINTX & (1<report_id = REPORT_ID_MOUSE; if (usbInterruptIsReady3()) { usbSetInterrupt3((void *)report, sizeof(*report)); } else { debug("Int3 not ready\n"); } } +#endif + +#ifdef USB_EXTRA_ENABLE +void host_system_send(uint8_t data) +{ + static uint8_t report[] = { REPORT_ID_SYSTEM, 0 }; + report[1] = data; + if (usbInterruptIsReady3()) { + usbSetInterrupt3((void *)&report, sizeof(report)); + } else { + debug("Int3 not ready\n"); + } +} + +void host_audio_send(uint8_t data) +{ + static uint8_t report[] = { REPORT_ID_AUDIO, 0 }; + report[1] = data; + if (usbInterruptIsReady3()) { + usbSetInterrupt3((void *)&report, sizeof(report)); + } else { + debug("Int3 not ready\n"); + } +} +#endif @@ -265,77 +292,87 @@ PROGMEM uchar keyboard_hid_report[] = { * http://www.microsoft.com/whdc/device/input/wheel.mspx */ PROGMEM uchar mouse_hid_report[] = { - /* from HID 1.11 spec example */ + /* mouse */ 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x09, 0x02, // USAGE (Mouse) 0xa1, 0x01, // COLLECTION (Application) - 0x09, 0x02, // USAGE (Mouse) - 0xa1, 0x02, // COLLECTION (Logical) - 0x09, 0x01, // USAGE (Pointer) - 0xa1, 0x00, // COLLECTION (Physical) - // ------------------------------ Buttons - 0x05, 0x09, // USAGE_PAGE (Button) - 0x19, 0x01, // USAGE_MINIMUM (Button 1) - 0x29, 0x05, // USAGE_MAXIMUM (Button 5) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x75, 0x01, // REPORT_SIZE (1) - 0x95, 0x05, // REPORT_COUNT (5) - 0x81, 0x02, // INPUT (Data,Var,Abs) - // ------------------------------ Padding - 0x75, 0x03, // REPORT_SIZE (3) - 0x95, 0x01, // REPORT_COUNT (1) - 0x81, 0x03, // INPUT (Cnst,Var,Abs) - // ------------------------------ X,Y position - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x30, // USAGE (X) - 0x09, 0x31, // USAGE (Y) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x02, // REPORT_COUNT (2) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0xa1, 0x02, // COLLECTION (Logical) - // ------------------------------ Vertical wheel res multiplier - 0x09, 0x48, // USAGE (Resolution Multiplier) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x35, 0x01, // PHYSICAL_MINIMUM (1) - 0x45, 0x04, // PHYSICAL_MAXIMUM (4) - 0x75, 0x02, // REPORT_SIZE (2) - 0x95, 0x01, // REPORT_COUNT (1) - 0xa4, // PUSH - 0xb1, 0x02, // FEATURE (Data,Var,Abs) - // ------------------------------ Vertical wheel - 0x09, 0x38, // USAGE (Wheel) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical - 0x45, 0x00, // PHYSICAL_MAXIMUM (0) - 0x75, 0x08, // REPORT_SIZE (8) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0xc0, // END_COLLECTION - 0xa1, 0x02, // COLLECTION (Logical) - // ------------------------------ Horizontal wheel res multiplier - 0x09, 0x48, // USAGE (Resolution Multiplier) - 0xb4, // POP - 0xb1, 0x02, // FEATURE (Data,Var,Abs) - // ------------------------------ Padding for Feature report - 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical - 0x45, 0x00, // PHYSICAL_MAXIMUM (0) - 0x75, 0x04, // REPORT_SIZE (4) - 0xb1, 0x03, // FEATURE (Cnst,Var,Abs) - // ------------------------------ Horizontal wheel - 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) - 0x0a, 0x38, 0x02, // USAGE (AC Pan) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x75, 0x08, // REPORT_SIZE (8) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0xc0, // END_COLLECTION - 0xc0, // END_COLLECTION + 0x85, 0x01, // REPORT_ID (1) + 0x09, 0x01, // USAGE (Pointer) + 0xa1, 0x00, // COLLECTION (Physical) + // ---------------------------- Buttons + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) + 0x29, 0x05, // USAGE_MAXIMUM (Button 5) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x75, 0x01, // REPORT_SIZE (1) + 0x95, 0x05, // REPORT_COUNT (5) + 0x81, 0x02, // INPUT (Data,Var,Abs) + // ---------------------------- Padding + 0x75, 0x03, // REPORT_SIZE (3) + 0x95, 0x01, // REPORT_COUNT (1) + 0x81, 0x03, // INPUT (Cnst,Var,Abs) + // ---------------------------- X,Y position + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x30, // USAGE (X) + 0x09, 0x31, // USAGE (Y) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x02, // REPORT_COUNT (2) + 0x81, 0x06, // INPUT (Data,Var,Rel) + // ---------------------------- Vertical wheel + 0x09, 0x38, // USAGE (Wheel) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical + 0x45, 0x00, // PHYSICAL_MAXIMUM (0) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x01, // REPORT_COUNT (1) + 0x81, 0x06, // INPUT (Data,Var,Rel) + // ---------------------------- Horizontal wheel + 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) + 0x0a, 0x38, 0x02, // USAGE (AC Pan) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x01, // REPORT_COUNT (1) + 0x81, 0x06, // INPUT (Data,Var,Rel) 0xc0, // END_COLLECTION - 0xc0 // END_COLLECTION + 0xc0, // END_COLLECTION + /* system */ + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x80, // USAGE (System Control) + 0xa1, 0x01, // COLLECTION (Application) + 0x85, 0x02, // REPORT_ID (2) + 0x19, 0x81, // USAGE_MINIMUM (System Power Down) + 0x29, 0x83, // USAGE_MAXIMUM (System Wake Up) + 0x75, 0x01, // REPORT_SIZE (1) + 0x95, 0x03, // REPORT_COUNT (3) + 0x81, 0x06, // INPUT (Data,Var,Rel) + 0x95, 0x05, // REPORT_COUNT (5) + 0x81, 0x07, // INPUT (Cnst,Var,Rel) + 0xc0, // END_COLLECTION + /* audio */ + 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) + 0x09, 0x01, // USAGE (Consumer Control) + 0xa1, 0x01, // COLLECTION (Application) + 0x85, 0x03, // REPORT_ID (3) + 0x09, 0xe9, // USAGE (Volume Up) + 0x09, 0xea, // USAGE (Volume Down) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x75, 0x01, // REPORT_SIZE (1) + 0x95, 0x02, // REPORT_COUNT (2) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x09, 0xe2, // USAGE (Mute) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x95, 0x01, // REPORT_COUNT (1) + 0x81, 0x06, // INPUT (Data,Var,Rel) + 0x95, 0x05, // REPORT_COUNT (5) + 0x81, 0x07, // INPUT (Cnst,Var,Abs) + 0xc0, // END_COLLECTION }; -- 2.39.3 From af85b6bba6744573f1edecd26fb504c31094414f Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 25 May 2011 10:37:58 +0900 Subject: [PATCH 15/16] added HHKB/README and clean some codes. --- adb.c | 0 adb_usb/Makefile | 2 +- adb_usb/matrix.c | 0 command.c | 0 hhkb/Makefile | 11 ++-- hhkb/Makefile.vusb | 11 ++-- hhkb/README | 80 ++++++++++++++++++++++++++++ hhkb/{config.h => config_pjrc.h} | 0 hhkb/config_vusb.h | 88 ------------------------------- hhkb/doc/HHKB_TP1684.jpg | Bin hhkb/doc/HHKB_chart1.jpg | Bin hhkb/doc/HHKB_chart2.jpg | Bin hhkb/doc/HHKB_connector.jpg | Bin hhkb/doc/HHKB_controller.jpg | Bin hhkb/doc/HHKB_keyswitch.jpg | Bin hhkb/doc/connector_contact.jpg | Bin hhkb/doc/logic_analyzer.jpg | Bin hhkb/doc/probe_contact.jpg | Bin hhkb/doc/teensy_install.jpg | Bin hhkb/doc/teensy_wiring.jpg | Bin macway/Makefile | 4 +- ps2_usb/Makefile | 9 +++- ps2_usb/Makefile.vusb | 9 +++- 23 files changed, 111 insertions(+), 103 deletions(-) mode change 100755 => 100644 adb.c mode change 100755 => 100644 adb_usb/Makefile mode change 100755 => 100644 adb_usb/matrix.c mode change 100755 => 100644 command.c mode change 100755 => 100644 hhkb/Makefile create mode 100644 hhkb/README rename hhkb/{config.h => config_pjrc.h} (100%) mode change 100755 => 100644 hhkb/doc/HHKB_TP1684.jpg mode change 100755 => 100644 hhkb/doc/HHKB_chart1.jpg mode change 100755 => 100644 hhkb/doc/HHKB_chart2.jpg mode change 100755 => 100644 hhkb/doc/HHKB_connector.jpg mode change 100755 => 100644 hhkb/doc/HHKB_controller.jpg mode change 100755 => 100644 hhkb/doc/HHKB_keyswitch.jpg mode change 100755 => 100644 hhkb/doc/connector_contact.jpg mode change 100755 => 100644 hhkb/doc/logic_analyzer.jpg mode change 100755 => 100644 hhkb/doc/probe_contact.jpg mode change 100755 => 100644 hhkb/doc/teensy_install.jpg mode change 100755 => 100644 hhkb/doc/teensy_wiring.jpg mode change 100755 => 100644 ps2_usb/Makefile diff --git a/adb.c b/adb.c old mode 100755 new mode 100644 diff --git a/adb_usb/Makefile b/adb_usb/Makefile old mode 100755 new mode 100644 index 92b9ba1a..802b4248 --- a/adb_usb/Makefile +++ b/adb_usb/Makefile @@ -38,7 +38,7 @@ F_CPU = 16000000 # MOUSEKEY_ENABLE = yes # Mouse keys #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support -USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System control) +USB_EXTRA_ENABLE = yes # Audio control and System control #USB_NKRO_ENABLE = yes # USB Nkey Rollover diff --git a/adb_usb/matrix.c b/adb_usb/matrix.c old mode 100755 new mode 100644 diff --git a/command.c b/command.c old mode 100755 new mode 100644 diff --git a/hhkb/Makefile b/hhkb/Makefile old mode 100755 new mode 100644 index 4a0af1cd..e1cc2f21 --- a/hhkb/Makefile +++ b/hhkb/Makefile @@ -1,5 +1,10 @@ +# +# Makefile for PJRC Teensy +# + + # Target file name (without extension). -TARGET = hhkb +TARGET = hhkb_pjrc # Directory common source filess exist COMMON_DIR = .. @@ -13,7 +18,7 @@ TARGET_SRC = main_pjrc.c \ matrix.c \ led.c -CONFIG_H = config.h +CONFIG_H = config_pjrc.h # MCU name, you MUST set this to match the board you are using @@ -36,7 +41,7 @@ F_CPU = 16000000 # comment out to disable the options. MOUSEKEY_ENABLE = yes # Mouse keys #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support -USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System control) +USB_EXTRA_ENABLE = yes # Audio control and System control USB_NKRO_ENABLE = yes # USB Nkey Rollover diff --git a/hhkb/Makefile.vusb b/hhkb/Makefile.vusb index 7826ffd0..77841b82 100644 --- a/hhkb/Makefile.vusb +++ b/hhkb/Makefile.vusb @@ -1,3 +1,8 @@ +# +# Makefile for V-USB +# + + # Target file name (without extension). TARGET = hhkb_vusb @@ -23,10 +28,6 @@ OPT_DEFS = -DDEBUG_LEVEL=0 # 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 MCU = atmega168 @@ -42,7 +43,7 @@ F_CPU = 20000000 # comment out to disable the options. # MOUSEKEY_ENABLE = yes # Mouse keys -USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System control) +USB_EXTRA_ENABLE = yes # Audio control and System control #USB_NKRO_ENABLE = yes # USB Nkey Rollover diff --git a/hhkb/README b/hhkb/README new file mode 100644 index 00000000..2a441810 --- /dev/null +++ b/hhkb/README @@ -0,0 +1,80 @@ +Alternative Controller for HHKB +=============================== + +Feature +------- +- Mouse Keys +- NKRO on USB +- Keymap Layers + + +Customize Keymap +---------------- +see keymap.c. + + +Build for Teensy +---------------- +0. Edit matrix.c. + adjust scan code to your pin configuration.(see doc/HHKB.txt for pinouts) +1. Define macros in config_pjrc.h.(Optional) + VENDOR_ID, PRODUCT_ID and string descriptor. + IS_COMMAND +2. Edit Makefile for MCU setting and build options. + MCU, F_CPU + MOUSEKEY_ENABLE, USB_EXTRA_ENABLE, USB_NKRO_ENABLE +3. Build hex file. + $ make +4. Program MCU. + $ make program + + +Build for V-USB +--------------- +0. Edit matrix.c and usbconfig.h. + adjust scan code to your pin configuration.(see doc/HHKB.txt for pinouts) + define macros for V-USB in usbconfig.h. +1. Define macros in config_vusb.h.(Optional) + IS_COMMAND +2. Edit Makefile.vusb for MCU setting and build options. + MCU, F_CPU + MOUSEKEY_ENABLE, USB_EXTRA_ENABLE, USB_NKRO_ENABLE +3. Build hex file. + $ make -f Makefile.vusb +4. Program MCU. + $ make -f Makefile.vusb program + + Using a bootloader to program for convenience is recommended. + Once program this V-USB bootloader at first, you can program MCU without + extra programmer. You should have reset switch to start up as bootloader + mode in this case. + USBaspLoader: + http://www.obdev.at/products/vusb/usbasploader.html + + +V-USB Circuit +------------- + +---+ +---------------+ +USB GND | | ATmega168 | +=== C3 | | +5V <-------+--------+---|Vcc,AVCC | HHKB + R1 | | ==== +D- <----+--+-----R2-----|INT1 PB0-2|------->ROW +D+ <----|---+----R3-----|INT0 PB3-5|------->COL + Z1 Z2 | PB6|------->ENABLE +GND<----+---+--+--+-----|GND PE6|------->KEY + | | | PE7|------->PREV + | C2-+--|XTAL1 | (see doc/HHKB.txt for pinouts) + | X1 | | + +--C3-+--|XTAL2 RST|---SW--+GND + +---------------+ +R1: 1.5K Ohm +R2,R3: 68 Ohm +Z1,Z2: Zener 3.6V +C1,C2: 22pF +C3: 0.1uF +X1: Crystal 20MHz(16MHz/12MHz) +SW: Push Switch(Optional for bootloader) + + +EOF diff --git a/hhkb/config.h b/hhkb/config_pjrc.h similarity index 100% rename from hhkb/config.h rename to hhkb/config_pjrc.h diff --git a/hhkb/config_vusb.h b/hhkb/config_vusb.h index 3b44b94a..7c4291a2 100644 --- a/hhkb/config_vusb.h +++ b/hhkb/config_vusb.h @@ -29,92 +29,4 @@ #endif -/* PS/2 lines */ -#ifdef PS2_MOUSE_ENABLE - -#define PS2_CLOCK_PORT PORTD -#define PS2_CLOCK_PIN PIND -#define PS2_CLOCK_DDR DDRD -#define PS2_CLOCK_BIT 4 -#define PS2_DATA_PORT PORTD -#define PS2_DATA_PIN PIND -#define PS2_DATA_DDR DDRD -#define PS2_DATA_BIT 0 - - -// Synchronous USART is used to receive data from keyboard. -// Use RXD pin for PS/2 DATA line and XCK for PS/2 CLOCK. -// NOTE: This is recomended strongly if you use V-USB library. -#define PS2_USE_USART - -// External or Pin Change Interrupt is used to receive data from keyboard. -// Use INT1 or PCINTxx for PS/2 CLOCK line. see below. -//#define PS2_USE_INT - - -#ifdef PS2_USE_USART -// synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge -// set DDR of CLOCK as input to be slave -#define PS2_USART_INIT() do { \ - PS2_CLOCK_DDR &= ~(1< Date: Tue, 31 May 2011 21:17:56 +0900 Subject: [PATCH 16/16] Added PS/2 multimeda key support. HID Consumer page and System control are also supported now. merged mediakey branch: d53a356cd2011b461843a5c7c1527a61692893c1 --- host.h | 39 ++++++--- keyboard.c | 74 +++++++++++++---- pjrc/host.c | 10 ++- pjrc/usb.c | 165 +++++++++++++++--------------------- pjrc/usb_extra.c | 15 ++-- pjrc/usb_extra.h | 17 +--- ps2_usb/README | 30 +++++++ ps2_usb/keymap.c | 80 +++++++++++++----- usb_keycodes.h | 211 ++++++++++++++++++++++++----------------------- vusb/host.c | 154 +++++++++++++++++----------------- 10 files changed, 446 insertions(+), 349 deletions(-) mode change 100755 => 100644 pjrc/usb.c diff --git a/host.h b/host.h index 7ba9dd43..7ddcafc0 100644 --- a/host.h +++ b/host.h @@ -7,7 +7,7 @@ /* report id */ #define REPORT_ID_MOUSE 1 #define REPORT_ID_SYSTEM 2 -#define REPORT_ID_AUDIO 3 +#define REPORT_ID_CONSUMER 3 /* keyboard Modifiers in boot protocol report */ #define BIT_LCTRL (1<<0) @@ -30,15 +30,30 @@ #define MOUSE_BTN4 (1<<3) #define MOUSE_BTN5 (1<<4) -// Consumer Page(0x0C) Consumer Control(0x01) -#define AUDIO_VOL_UP (1<<0) -#define AUDIO_VOL_DOWN (1<<1) -#define AUDIO_MUTE (1<<2) - -// Generic Desktop Page(0x01) System Control(0x80) -#define SYSTEM_POWER_DOWN (1<<0) -#define SYSTEM_SLEEP (1<<1) -#define SYSTEM_WAKE_UP (1<<2) +// Consumer Page(0x0C) +#define AUDIO_MUTE 0x00E2 +#define AUDIO_VOL_UP 0x00E9 +#define AUDIO_VOL_DOWN 0x00EA +#define TRANSPORT_NEXT_TRACK 0x00B5 +#define TRANSPORT_PREV_TRACK 0x00B6 +#define TRANSPORT_STOP 0x00B7 +#define TRANSPORT_PLAY_PAUSE 0x00CD +#define AL_CC_CONFIG 0x0183 +#define AL_EMAIL 0x018A +#define AL_CALCULATOR 0x0192 +#define AL_LOCAL_BROWSER 0x0194 +#define AC_SEARCH 0x0221 +#define AC_HOME 0x0223 +#define AC_BACK 0x0224 +#define AC_FORWARD 0x0225 +#define AC_STOP 0x0226 +#define AC_REFRESH 0x0227 +#define AC_BOOKMARKS 0x022A + +// Generic Desktop Page(0x01) +#define SYSTEM_POWER_DOWN 0x0081 +#define SYSTEM_SLEEP 0x0082 +#define SYSTEM_WAKE_UP 0x0083 #if defined(HOST_PJRC) @@ -94,8 +109,8 @@ void host_send_keyboard_report(void); void host_mouse_send(report_mouse_t *report); #endif #ifdef USB_EXTRA_ENABLE -void host_system_send(uint8_t data); -void host_audio_send(uint8_t data); +void host_system_send(uint16_t data); +void host_consumer_send(uint16_t data); #endif #endif diff --git a/keyboard.c b/keyboard.c index fd6e2304..af170673 100644 --- a/keyboard.c +++ b/keyboard.c @@ -31,6 +31,9 @@ void keyboard_init(void) void keyboard_proc(void) { uint8_t fn_bits = 0; +#ifdef USB_EXTRA_ENABLE + uint16_t consumer_code = 0; +#endif matrix_scan(); @@ -64,20 +67,8 @@ void keyboard_proc(void) fn_bits |= FN_BIT(code); } #ifdef USB_EXTRA_ENABLE - // audio control & system control - else if (code == KB_MUTE) { - host_audio_send(AUDIO_MUTE); - _delay_ms(500); - host_audio_send(0); - } else if (code == KB_VOLU) { - host_audio_send(AUDIO_VOL_UP); - _delay_ms(200); - host_audio_send(0); - } else if (code == KB_VOLD) { - host_audio_send(AUDIO_VOL_DOWN); - _delay_ms(200); - host_audio_send(0); - } else if (code == KB_PWR) { + // System Control + else if (code == KB_SYSTEM_POWER) { #ifdef HOST_PJRC if (suspend && remote_wakeup) { usb_remote_wakeup(); @@ -87,7 +78,57 @@ void keyboard_proc(void) #else host_system_send(SYSTEM_POWER_DOWN); #endif - _delay_ms(1000); + host_system_send(0); + _delay_ms(500); + } else if (code == KB_SYSTEM_SLEEP) { + host_system_send(SYSTEM_SLEEP); + host_system_send(0); + _delay_ms(500); + } else if (code == KB_SYSTEM_WAKE) { + host_system_send(SYSTEM_WAKE_UP); + host_system_send(0); + _delay_ms(500); + } + // Consumer Page + else if (code == KB_AUDIO_MUTE) { + consumer_code = AUDIO_MUTE; + } else if (code == KB_AUDIO_VOL_UP) { + consumer_code = AUDIO_VOL_UP; + } else if (code == KB_AUDIO_VOL_DOWN) { + consumer_code = AUDIO_VOL_DOWN; + } + else if (code == KB_MEDIA_NEXT_TRACK) { + consumer_code = TRANSPORT_NEXT_TRACK; + } else if (code == KB_MEDIA_PREV_TRACK) { + consumer_code = TRANSPORT_PREV_TRACK; + } else if (code == KB_MEDIA_STOP) { + consumer_code = TRANSPORT_STOP; + } else if (code == KB_MEDIA_PLAY_PAUSE) { + consumer_code = TRANSPORT_PLAY_PAUSE; + } else if (code == KB_MEDIA_SELECT) { + consumer_code = AL_CC_CONFIG; + } + else if (code == KB_MAIL) { + consumer_code = AL_EMAIL; + } else if (code == KB_CALCULATOR) { + consumer_code = AL_CALCULATOR; + } else if (code == KB_MY_COMPUTER) { + consumer_code = AL_LOCAL_BROWSER; + } + else if (code == KB_WWW_SEARCH) { + consumer_code = AC_SEARCH; + } else if (code == KB_WWW_HOME) { + consumer_code = AC_HOME; + } else if (code == KB_WWW_BACK) { + consumer_code = AC_BACK; + } else if (code == KB_WWW_FORWARD) { + consumer_code = AC_FORWARD; + } else if (code == KB_WWW_STOP) { + consumer_code = AC_STOP; + } else if (code == KB_WWW_REFRESH) { + consumer_code = AC_REFRESH; + } else if (code == KB_WWW_FAVORITES) { + consumer_code = AC_BOOKMARKS; } #endif else if (IS_KEY(code)) { @@ -113,6 +154,9 @@ void keyboard_proc(void) // TODO: should send only when changed from last report if (matrix_is_modified()) { host_send_keyboard_report(); +#ifdef USB_EXTRA_ENABLE + host_consumer_send(consumer_code); +#endif #ifdef DEBUG_LED // LED flash for debug DEBUG_LED_CONFIG; diff --git a/pjrc/host.c b/pjrc/host.c index 2a81e4c5..ee933cee 100644 --- a/pjrc/host.c +++ b/pjrc/host.c @@ -117,14 +117,18 @@ void host_mouse_send(report_mouse_t *report) #endif #ifdef USB_EXTRA_ENABLE -void host_system_send(uint8_t data) +void host_system_send(uint16_t data) { usb_extra_system_send(data); } -void host_audio_send(uint8_t data) +void host_consumer_send(uint16_t data) { - usb_extra_audio_send(data); + static uint16_t last_data = 0; + if (data == last_data) return; + last_data = data; + + usb_extra_consumer_send(data); } #endif diff --git a/pjrc/usb.c b/pjrc/usb.c old mode 100755 new mode 100644 index 711c0e68..ea2e71b3 --- a/pjrc/usb.c +++ b/pjrc/usb.c @@ -219,76 +219,53 @@ static uint8_t PROGMEM keyboard2_hid_report_desc[] = { // http://www.keil.com/forum/15671/ // http://www.microsoft.com/whdc/device/input/wheel.mspx static uint8_t PROGMEM mouse_hid_report_desc[] = { - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x02, // USAGE (Mouse) - 0xa1, 0x01, // COLLECTION (Application) - 0x09, 0x02, // USAGE (Mouse) - 0xa1, 0x02, // COLLECTION (Logical) - 0x09, 0x01, // USAGE (Pointer) - 0xa1, 0x00, // COLLECTION (Physical) - // ------------------------------ Buttons - 0x05, 0x09, // USAGE_PAGE (Button) - 0x19, 0x01, // USAGE_MINIMUM (Button 1) - 0x29, 0x05, // USAGE_MAXIMUM (Button 5) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x75, 0x01, // REPORT_SIZE (1) - 0x95, 0x05, // REPORT_COUNT (5) - 0x81, 0x02, // INPUT (Data,Var,Abs) - // ------------------------------ Padding - 0x75, 0x03, // REPORT_SIZE (3) - 0x95, 0x01, // REPORT_COUNT (1) - 0x81, 0x03, // INPUT (Cnst,Var,Abs) - // ------------------------------ X,Y position - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x30, // USAGE (X) - 0x09, 0x31, // USAGE (Y) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x02, // REPORT_COUNT (2) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0xa1, 0x02, // COLLECTION (Logical) - // ------------------------------ Vertical wheel res multiplier - 0x09, 0x48, // USAGE (Resolution Multiplier) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x35, 0x01, // PHYSICAL_MINIMUM (1) - 0x45, 0x04, // PHYSICAL_MAXIMUM (4) - 0x75, 0x02, // REPORT_SIZE (2) - 0x95, 0x01, // REPORT_COUNT (1) - 0xa4, // PUSH - 0xb1, 0x02, // FEATURE (Data,Var,Abs) - // ------------------------------ Vertical wheel - 0x09, 0x38, // USAGE (Wheel) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical - 0x45, 0x00, // PHYSICAL_MAXIMUM (0) - 0x75, 0x08, // REPORT_SIZE (8) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0xc0, // END_COLLECTION - 0xa1, 0x02, // COLLECTION (Logical) - // ------------------------------ Horizontal wheel res multiplier - 0x09, 0x48, // USAGE (Resolution Multiplier) - 0xb4, // POP - 0xb1, 0x02, // FEATURE (Data,Var,Abs) - // ------------------------------ Padding for Feature report - 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical - 0x45, 0x00, // PHYSICAL_MAXIMUM (0) - 0x75, 0x04, // REPORT_SIZE (4) - 0xb1, 0x03, // FEATURE (Cnst,Var,Abs) - // ------------------------------ Horizontal wheel - 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) - 0x0a, 0x38, 0x02, // USAGE (AC Pan) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x75, 0x08, // REPORT_SIZE (8) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0xc0, // END_COLLECTION - 0xc0, // END_COLLECTION - 0xc0, // END_COLLECTION - 0xc0 // END_COLLECTION + /* mouse */ + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x02, // USAGE (Mouse) + 0xa1, 0x01, // COLLECTION (Application) + //0x85, REPORT_ID_MOUSE, // REPORT_ID (1) + 0x09, 0x01, // USAGE (Pointer) + 0xa1, 0x00, // COLLECTION (Physical) + // ---------------------------- Buttons + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) + 0x29, 0x05, // USAGE_MAXIMUM (Button 5) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x75, 0x01, // REPORT_SIZE (1) + 0x95, 0x05, // REPORT_COUNT (5) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x75, 0x03, // REPORT_SIZE (3) + 0x95, 0x01, // REPORT_COUNT (1) + 0x81, 0x03, // INPUT (Cnst,Var,Abs) + // ---------------------------- X,Y position + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x30, // USAGE (X) + 0x09, 0x31, // USAGE (Y) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x02, // REPORT_COUNT (2) + 0x81, 0x06, // INPUT (Data,Var,Rel) + // ---------------------------- Vertical wheel + 0x09, 0x38, // USAGE (Wheel) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical + 0x45, 0x00, // PHYSICAL_MAXIMUM (0) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x01, // REPORT_COUNT (1) + 0x81, 0x06, // INPUT (Data,Var,Rel) + // ---------------------------- Horizontal wheel + 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) + 0x0a, 0x38, 0x02, // USAGE (AC Pan) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x01, // REPORT_COUNT (1) + 0x81, 0x06, // INPUT (Data,Var,Rel) + 0xc0, // END_COLLECTION + 0xc0, // END_COLLECTION }; #endif @@ -309,38 +286,32 @@ static uint8_t PROGMEM debug_hid_report_desc[] = { // audio controls & system controls // http://www.microsoft.com/whdc/archive/w2kbd.mspx static uint8_t PROGMEM extra_hid_report_desc[] = { + /* system control */ + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x80, // USAGE (System Control) + 0xa1, 0x01, // COLLECTION (Application) + 0x85, REPORT_ID_SYSTEM, // REPORT_ID (2) + 0x15, 0x01, // LOGICAL_MINIMUM (0x1) + 0x25, 0xb7, // LOGICAL_MAXIMUM (0xb7) + 0x19, 0x01, // USAGE_MINIMUM (0x1) + 0x29, 0xb7, // USAGE_MAXIMUM (0xb7) + 0x75, 0x10, // REPORT_SIZE (16) + 0x95, 0x01, // REPORT_COUNT (1) + 0x81, 0x00, // INPUT (Data,Array,Abs) + 0xc0, // END_COLLECTION + /* consumer */ 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) 0x09, 0x01, // USAGE (Consumer Control) 0xa1, 0x01, // COLLECTION (Application) - 0x85, 0x01, // REPORT_ID (1) - 0x09, 0xe9, // USAGE (Volume Up) - 0x09, 0xea, // USAGE (Volume Down) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x75, 0x01, // REPORT_SIZE (1) - 0x95, 0x02, // REPORT_COUNT (2) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x09, 0xe2, // USAGE (Mute) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x75, 0x01, // REPORT_SIZE (1) + 0x85, REPORT_ID_CONSUMER, // REPORT_ID (3) + 0x15, 0x01, // LOGICAL_MINIMUM (0x1) + 0x26, 0x9c, 0x02, // LOGICAL_MAXIMUM (0x29c) + 0x19, 0x01, // USAGE_MINIMUM (0x1) + 0x2a, 0x9c, 0x02, // USAGE_MAXIMUM (0x29c) + 0x75, 0x10, // REPORT_SIZE (16) 0x95, 0x01, // REPORT_COUNT (1) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0x95, 0x05, // REPORT_COUNT (5) - 0x81, 0x07, // INPUT (Cnst,Var,Abs) + 0x81, 0x00, // INPUT (Data,Array,Abs) 0xc0, // END_COLLECTION - - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x80, // USAGE (System Control) - 0xa1, 0x01, // COLLECTION (Application) - 0x85, 0x02, // REPORT_ID (2) - 0x19, 0x81, // USAGE_MINIMUM (System Power Down) - 0x29, 0x83, // USAGE_MAXIMUM (System Wake Up) - 0x95, 0x03, // REPORT_COUNT (3) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0x95, 0x05, // REPORT_COUNT (5) - 0x81, 0x07, // INPUT (Cnst,Var,Rel) - 0xc0 // END_COLLECTION }; #endif diff --git a/pjrc/usb_extra.c b/pjrc/usb_extra.c index 9bc0c3f5..670d01e9 100644 --- a/pjrc/usb_extra.c +++ b/pjrc/usb_extra.c @@ -1,8 +1,10 @@ +#include #include +#include "host.h" #include "usb_extra.h" -int8_t usb_extra_send(uint8_t report_id, uint8_t bits) +int8_t usb_extra_send(uint8_t report_id, uint16_t data) { uint8_t intr_state, timeout; @@ -26,19 +28,20 @@ int8_t usb_extra_send(uint8_t report_id, uint8_t bits) } UEDATX = report_id; - UEDATX = bits; + UEDATX = data&0xFF; + UEDATX = (data>>8)&0xFF; UEINTX = 0x3A; SREG = intr_state; return 0; } -int8_t usb_extra_audio_send(uint8_t bits) +int8_t usb_extra_consumer_send(uint16_t bits) { - return usb_extra_send(1, bits); + return usb_extra_send(REPORT_ID_CONSUMER, bits); } -int8_t usb_extra_system_send(uint8_t bits) +int8_t usb_extra_system_send(uint16_t bits) { - return usb_extra_send(2, bits); + return usb_extra_send(REPORT_ID_SYSTEM, bits); } diff --git a/pjrc/usb_extra.h b/pjrc/usb_extra.h index d6f9e8ba..b9128314 100644 --- a/pjrc/usb_extra.h +++ b/pjrc/usb_extra.h @@ -13,22 +13,11 @@ #define EXTRA_INTERFACE 3 #define EXTRA_ENDPOINT 4 -#define EXTRA_SIZE 2 +#define EXTRA_SIZE 8 #define EXTRA_BUFFER EP_DOUBLE_BUFFER -// Consumer Page(0x0C) Consumer Control(0x01) -#define AUDIO_VOL_UP (1<<0) -#define AUDIO_VOL_DOWN (1<<1) -#define AUDIO_MUTE (1<<2) - -// Generic Desktop Page(0x01) System Control(0x80) -#define SYSTEM_POWER_DOWN (1<<0) -#define SYSTEM_SLEEP (1<<1) -#define SYSTEM_WAKE_UP (1<<2) - - -int8_t usb_extra_audio_send(uint8_t bits); -int8_t usb_extra_system_send(uint8_t bits); +int8_t usb_extra_consumer_send(uint16_t bits); +int8_t usb_extra_system_send(uint16_t bits); #endif diff --git a/ps2_usb/README b/ps2_usb/README index f4f344c0..0fdeaf1d 100644 --- a/ps2_usb/README +++ b/ps2_usb/README @@ -133,4 +133,34 @@ needs a bit of your effort at this time. ), +Multimedia keys +--------------- +Following lists PS/2 special keys supported by Windows. +http://msdn.microsoft.com/en-us/windows/hardware/gg463372.aspx + +Key PS/2(Set2) HID +--------------------------------------------------- +System Power E0 37 01 0081 +System Sleep E0 3F 01 0082 +System Wake E0 5E 01 0083 +System Mute E0 23 0C 00E2 +Volume Up E0 32 0C 00E9 +Volume Down E0 21 0C 00EA +Scan Next Track E0 4D 0C 00B5 +Scan Previous Track E0 15 0C 00B6 +Stop E0 3B 0C 00B7 +Play/Pause E0 34 0C 00CD +Media Select E0 50 0C 0183 +Mail E0 48 0C 018A +Calculator E0 2B 0C 0192 +My Computer E0 40 0C 0194 +WWW Search E0 10 0C 0221 +WWW Home E0 3A 0C 0223 +WWW Back E0 38 0C 0224 +WWW Forward E0 30 0C 0225 +WWW Stop E0 28 0C 0226 +WWW Refresh E0 20 0C 0227 +WWW Favorites E0 18 0C 022A + + EOF diff --git a/ps2_usb/keymap.c b/ps2_usb/keymap.c index 253351f6..7c5bddc9 100644 --- a/ps2_usb/keymap.c +++ b/ps2_usb/keymap.c @@ -13,15 +13,23 @@ #define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)])) -// Convert physical keyboard layout to matrix array. -// This is a macro to define keymap easily in keyboard layout form. -#define KEYMAP( \ - K76, K05,K06,K04,K0C, K03,K0B,K83,K0A, K01,K09,K78,K07, KFC,K7E,KFE, KB7,KBF,KDE, \ + +// The keymap is a 32*8 matrix which convert a PS/2 scancode into a USB keycode. +// See matrix.c for the detail of matrix. +#define KEYMAP_ALL( \ + K76,K05,K06,K04,K0C,K03,K0B,K83,K0A,K01,K09,K78,K07, KFC,K7E,KFE, \ K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K66, KF0,KEC,KFD, K77,KCA,K7C,K7B, \ K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B,K5D, KF1,KE9,KFA, K6C,K75,K7D, \ K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52, K5A, K6B,K73,K74,K79, \ K12,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A, K59, KF5, K69,K72,K7A, \ - K14,K9F,K11, K29, K91,KA7,KAF,K94, KEB,KF2,KF4, K70, K71,KDA \ + K14,K9F,K11, K29, K91,KA7,KAF,K94, KEB,KF2,KF4, K70, K71,KDA, \ + \ + KB7, KBF, KDE, /* System Power, Sleep, Wake */ \ + KA3, KB2, KA1, /* Mute, Volume Up, Volume Down */ \ + KCD, K95, KBB, KB4, KD0, /* Next, Previous, Stop, Pause, Media Select */ \ + KC8, KAB, KC0, /* Mail, Calculator, My Computer */ \ + K90, KBA, KB8, KB0, /* WWW Search, Home, Back, Forward */ \ + KA8, KA0, K98 /* WWW Stop, Refresh, Favorites */ \ ) { \ { KB_NO, KB_##K01, KB_NO, KB_##K03, KB_##K04, KB_##K05, KB_##K06, KB_##K07 }, \ { KB_NO, KB_##K09, KB_##K0A, KB_##K0B, KB_##K0C, KB_##K0D, KB_##K0E, KB_NO }, \ @@ -41,15 +49,15 @@ { KB_##K78, KB_##K79, KB_##K7A, KB_##K7B, KB_##K7C, KB_##K7D, KB_##K7E, KB_NO }, \ { KB_NO, KB_NO, KB_NO, KB_##K83, KB_NO, KB_NO, KB_NO, KB_NO }, \ { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, \ - { KB_NO, KB_##K91, KB_NO, KB_NO, KB_##K94, KB_NO, KB_NO, KB_NO }, \ - { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_##K9F }, \ - { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_##KA7 }, \ - { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_##KAF }, \ - { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_##KB7 }, \ - { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_##KBF }, \ - { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, \ - { KB_NO, KB_NO, KB_##KCA, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, \ - { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, \ + { KB_##K90, KB_##K91, KB_NO, KB_NO, KB_##K94, KB_##K95, KB_NO, KB_NO }, \ + { KB_##K98, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_##K9F }, \ + { KB_##KA0, KB_##KA1, KB_NO, KB_##KA3, KB_NO, KB_NO, KB_NO, KB_##KA7 }, \ + { KB_##KA8, KB_NO, KB_NO, KB_##KAB, KB_NO, KB_NO, KB_NO, KB_##KAF }, \ + { KB_##KB0, KB_NO, KB_##KB2, KB_NO, KB_##KB4, KB_NO, KB_NO, KB_##KB7 }, \ + { KB_##KB8, KB_NO, KB_##KBA, KB_##KBB, KB_NO, KB_NO, KB_NO, KB_##KBF }, \ + { KB_##KC0, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, \ + { KB_##KC8, KB_NO, KB_##KCA, KB_NO, KB_NO, KB_##KCD, KB_NO, KB_NO }, \ + { KB_##KD0, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, \ { KB_NO, KB_NO, KB_##KDA, KB_NO, KB_NO, KB_NO, KB_##KDE, KB_NO }, \ { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, \ { KB_NO, KB_##KE9, KB_NO, KB_##KEB, KB_##KEC, KB_NO, KB_NO, KB_NO }, \ @@ -57,6 +65,30 @@ { KB_NO, KB_NO, KB_##KFA, KB_NO, KB_##KFC, KB_##KFD, KB_##KFE, KB_NO }, \ } +#define KEYMAP( \ + K76,K05,K06,K04,K0C,K03,K0B,K83,K0A,K01,K09,K78,K07, KFC,K7E,KFE, \ + K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K66, KF0,KEC,KFD, K77,KCA,K7C,K7B, \ + K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B,K5D, KF1,KE9,KFA, K6C,K75,K7D, \ + K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52, K5A, K6B,K73,K74,K79, \ + K12,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A, K59, KF5, K69,K72,K7A, \ + K14,K9F,K11, K29, K91,KA7,KAF,K94, KEB,KF2,KF4, K70, K71,KDA \ +) \ +KEYMAP_ALL( \ + K76,K05,K06,K04,K0C,K03,K0B,K83,K0A,K01,K09,K78,K07, KFC,K7E,KFE, \ + K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K66, KF0,KEC,KFD, K77,KCA,K7C,K7B, \ + K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B,K5D, KF1,KE9,KFA, K6C,K75,K7D, \ + K58,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52, K5A, K6B,K73,K74,K79, \ + K12,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A, K59, KF5, K69,K72,K7A, \ + K14,K9F,K11, K29, K91,KA7,KAF,K94, KEB,KF2,KF4, K70, K71,KDA, \ + \ + SYSTEM_POWER, SYSTEM_SLEEP, SYSTEM_WAKE, \ + AUDIO_MUTE, AUDIO_VOL_UP, AUDIO_VOL_DOWN, \ + MEDIA_NEXT_TRACK, MEDIA_PREV_TRACK, MEDIA_STOP, MEDIA_PLAY_PAUSE, MEDIA_SELECT, \ + MAIL, CALCULATOR, MY_COMPUTER, \ + WWW_SEARCH, WWW_HOME, WWW_BACK, WWW_FORWARD, \ + WWW_STOP, WWW_REFRESH, WWW_FAVORITES \ +) + // Assign Fn key(0-7) to a layer to which switch with the Fn key pressed. static const uint8_t PROGMEM fn_layer[] = { @@ -102,61 +134,67 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { */ /* 0: default */ KEYMAP( - ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14, + ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, CAPS,FN2, S, D, F, G, H, J, K, L, FN0, QUOT, ENT, P4, P5, P6, PPLS, LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN1, RSFT, UP, P1, P2, P3, LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT ), + /* 1: plain Qwerty without layer switching */ KEYMAP( - ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14, + ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, P4, P5, P6, PPLS, LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3, LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT ), + /* 2: Colemak http://colemak.com */ KEYMAP( - ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14, + ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, TAB, Q, W, F, P, G, J, L, U, Y, SCLN,LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, BSPC,A, R, S, T, D, H, N, E, I, O, QUOT, ENT, P4, P5, P6, PPLS, LSFT,Z, X, C, V, B, K, M, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3, LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT ), + /* 3: Dvorak http://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard */ KEYMAP( - ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14, + ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, LBRC,RBRC,BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, TAB, QUOT,COMM,DOT, P, Y, F, G, C, R, L, SLSH,EQL, BSLS, DEL, END, PGDN, P7, P8, P9, CAPS,A, O, E, U, I, D, H, T, N, S, MINS, ENT, P4, P5, P6, PPLS, LSFT,SCLN,Q, J, K, X, B, M, W, V, Z, RSFT, UP, P1, P2, P3, LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT ), + /* 4: Workman http://viralintrospection.wordpress.com/2010/09/06/a-different-philosophy-in-designing-keyboard-layouts/ */ KEYMAP( - ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14, + ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, TAB, Q, D, R, W, B, J, F, U, P, SCLN,LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, BSPC,A, S, H, T, G, Y, N, E, O, I, QUOT, ENT, P4, P5, P6, PPLS, LSFT,Z, X, M, C, V, K, L, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3, LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT ), + /* 5: Mouse keys */ KEYMAP( - ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14, + ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, ESC, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, TAB, WH_L,WH_D,MS_U,WH_U,WH_R,WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSLS, DEL, END, PGDN, P7, P8, P9, CAPS,FN2, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN0, NO, ENT, P4, P5, P6, PPLS, LSFT,VOLD,VOLU,MUTE,BTN2,BTN3,BTN2,BTN1,VOLD,VOLU,MUTE, RSFT, UP, P1, P2, P3, LCTL,LGUI,LALT, BTN1, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT ), + /* 6: Cursor keys */ KEYMAP( - ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, PWR, F13, F14, + ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, ESC, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, TAB, NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, NO, NO, NO, BSLS, DEL, END, PGDN, P7, P8, P9, CAPS,NO, NO, NO, NO, NO, LEFT,DOWN,UP, RGHT,NO, NO, ENT, P4, P5, P6, PPLS, diff --git a/usb_keycodes.h b/usb_keycodes.h index dc6f2693..bdec9539 100644 --- a/usb_keycodes.h +++ b/usb_keycodes.h @@ -1,43 +1,13 @@ /* * Key codes from HID Keyboard/Keypad Page * http://www.usb.org/developers/devclass_docs/Hut1_12.pdf - * - * Based on Keyboard Upgrade v0.3.0 http://github.com/rhomann/kbupgrade - */ -/* - * Keyboard Upgrade -- Firmware for homebrew computer keyboard controllers. - * Copyright (C) 2009 Robert Homann - * - * Based on RUMP (http://mg8.org/rump/), Copyright (C) 2008 Chris Lee - * - * Based on c64key (http://symlink.dk/projects/c64key/), - * Copyright (C) 2006-2007 Mikkel Holm Olsen - * - * Based on HID-Test by Christian Starkjohann, Objective Development - * - * This file is part of the Keyboard Upgrade package. - * - * 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 the Keyboard Upgrade package; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA */ #ifndef USB_KEYCODES_H #define USB_KEYCODES_H #define IS_ERROR(code) (KB_ROLL_OVER <= (code) && (code) <= KB_UNDEFINED) -#define IS_KEY(code) (KB_A <= (code) && (code) <= KB_KP_HEXADECIMAL) +#define IS_KEY(code) (KB_A <= (code) && (code) <= KB_EXSEL) #define IS_MOD(code) (KB_LCTRL <= (code) && (code) <= KB_RGUI) #define IS_FN(code) (KB_FN0 <= (code) && (code) <= KB_FN7) #define IS_MOUSEKEY(code) (KB_MS_UP <= (code) && (code) <= KB_MS_WH_RIGHT) @@ -49,9 +19,7 @@ #define FN_BIT(code) (1<<((code) - KB_FN0)) -// -// Short names -// +/* Short names */ #define KB_LCTL KB_LCTRL #define KB_RCTL KB_RCTRL #define KB_LSFT KB_LSHIFT @@ -79,20 +47,17 @@ #define KB_SLSH KB_SLASH #define KB_SCLN KB_SCOLON #define KB_QUOT KB_QUOTE -#define KB_PWR KB_POWER -#define KB_VOLU KB_VOLUP -#define KB_VOLD KB_VOLDOWN #define KB_APP KB_APPLICATION #define KB_NUHS KB_NONUS_HASH #define KB_NUBS KB_NONUS_BSLASH -// for Japanese +/* for Japanese */ #define KB_RO KB_INT1 #define KB_KANA KB_INT2 #define KB_JYEN KB_INT3 #define KB_HENK KB_INT4 #define KB_MHEN KB_INT5 #define KB_ZEHA KB_GRAVE -// Keypad +/* Keypad */ #define KB_P1 KB_KP_1 #define KB_P2 KB_KP_2 #define KB_P3 KB_KP_3 @@ -110,7 +75,7 @@ #define KB_PPLS KB_KP_PLUS #define KB_PEQL KB_KP_EQUAL #define KB_PENT KB_KP_ENTER -// Mousekey +/* Mousekey */ #define KB_MS_U KB_MS_UP #define KB_MS_D KB_MS_DOWN #define KB_MS_L KB_MS_LEFT @@ -124,7 +89,68 @@ #define KB_WH_D KB_MS_WH_DOWN #define KB_WH_L KB_MS_WH_LEFT #define KB_WH_R KB_MS_WH_RIGHT +/* Sytem Control & Consumer usage */ +#define KB_PWR KB_SYSTEM_POWER +#define KB_MUTE KB_AUDIO_MUTE +#define KB_VOLU KB_AUDIO_VOL_UP +#define KB_VOLD KB_AUDIO_VOL_DOWN + + +/* Special keycode */ +enum special_keycodes { + /* System Control */ + KB_SYSTEM_POWER = 0xB0, + KB_SYSTEM_SLEEP, + KB_SYSTEM_WAKE, + /* Consumer Page */ + KB_AUDIO_MUTE, + KB_AUDIO_VOL_UP, + KB_AUDIO_VOL_DOWN, + KB_MEDIA_NEXT_TRACK, + KB_MEDIA_PREV_TRACK, + KB_MEDIA_STOP, + KB_MEDIA_PLAY_PAUSE, + KB_MEDIA_SELECT, + KB_MAIL, + KB_CALCULATOR, + KB_MY_COMPUTER, + KB_WWW_SEARCH, + KB_WWW_HOME, + KB_WWW_BACK, /* 0xC0 */ + KB_WWW_FORWARD, + KB_WWW_STOP, + KB_WWW_REFRESH, + KB_WWW_FAVORITES, + + /* reserve 0xE0-E7 for Modifiers */ + + /* Layer Switching */ + KB_FN0 = 0xE8, + KB_FN1, + KB_FN2, + KB_FN3, + KB_FN4, + KB_FN5, + KB_FN6, + KB_FN7, + + /* Mousekey */ + KB_MS_UP = 0xF0, + KB_MS_DOWN, + KB_MS_LEFT, + KB_MS_RIGHT, + KB_MS_BTN1, + KB_MS_BTN2, + KB_MS_BTN3, + KB_MS_BTN4, + KB_MS_BTN5, + /* Mousekey wheel */ + KB_MS_WH_UP, + KB_MS_WH_DOWN, + KB_MS_WH_LEFT, + KB_MS_WH_RIGHT, +}; enum keycodes { KB_NO = 0, @@ -143,7 +169,7 @@ enum keycodes { KB_J, KB_K, KB_L, - KB_M, /* 0x10 */ + KB_M, /* 0x10 */ KB_N, KB_O, KB_P, @@ -159,7 +185,7 @@ enum keycodes { KB_Z, KB_1, KB_2, - KB_3, /* 0x20 */ + KB_3, /* 0x20 */ KB_4, KB_5, KB_6, @@ -174,16 +200,16 @@ enum keycodes { KB_SPACE, KB_MINUS, KB_EQUAL, - KB_LBRACKET, /* [ */ - KB_RBRACKET, /* ] */ - KB_BSLASH, /* \ (and |) */ - KB_NONUS_HASH, /* Non-US # and ~ */ - KB_SCOLON, /* ; (and :) */ - KB_QUOTE, /* ' and " */ - KB_GRAVE, /* Grave accent and tilde */ - KB_COMMA, /* , and < */ - KB_DOT, /* . and > */ - KB_SLASH, /* / and ? */ + KB_LBRACKET, + KB_RBRACKET, /* 0x30 */ + KB_BSLASH, /* \ (and |) */ + KB_NONUS_HASH, /* Non-US # and ~ */ + KB_SCOLON, /* ; (and :) */ + KB_QUOTE, /* ' and " */ + KB_GRAVE, /* Grave accent and tilde */ + KB_COMMA, /* , and < */ + KB_DOT, /* . and > */ + KB_SLASH, /* / and ? */ KB_CAPSLOCK, KB_F1, KB_F2, @@ -191,7 +217,7 @@ enum keycodes { KB_F4, KB_F5, KB_F6, - KB_F7, /* 0x40 */ + KB_F7, /* 0x40 */ KB_F8, KB_F9, KB_F10, @@ -207,7 +233,7 @@ enum keycodes { KB_END, KB_PGDOWN, KB_RIGHT, - KB_LEFT, /* 0x50 */ + KB_LEFT, /* 0x50 */ KB_DOWN, KB_UP, KB_NUMLOCK, @@ -223,11 +249,11 @@ enum keycodes { KB_KP_5, KB_KP_6, KB_KP_7, - KB_KP_8, /* 0x60 */ + KB_KP_8, /* 0x60 */ KB_KP_9, KB_KP_0, KB_KP_DOT, - KB_NONUS_BSLASH, /* Non-US \ and | */ + KB_NONUS_BSLASH, /* Non-US \ and | */ KB_APPLICATION, KB_POWER, KB_KP_EQUAL, @@ -239,7 +265,7 @@ enum keycodes { KB_F18, KB_F19, KB_F20, - KB_F21, /* 0x70 */ + KB_F21, /* 0x70 */ KB_F22, KB_F23, KB_F24, @@ -254,14 +280,14 @@ enum keycodes { KB_COPY, KB_PASTE, KB_FIND, - KB_MUTE, - KB_VOLUP, /* 0x80 */ - KB_VOLDOWN, - KB_LOCKING_CAPS, /* locking Caps Lock */ - KB_LOCKING_NUM, /* locking Num Lock */ - KB_LOCKING_SCROLL, /* locking Scroll Lock */ + KB__MUTE, + KB__VOLUP, /* 0x80 */ + KB__VOLDOWN, + KB_LOCKING_CAPS, /* locking Caps Lock */ + KB_LOCKING_NUM, /* locking Num Lock */ + KB_LOCKING_SCROLL, /* locking Scroll Lock */ KB_KP_COMMA, - KB_KP_EQUAL_AS400, /* equal sign on AS/400 */ + KB_KP_EQUAL_AS400, /* equal sign on AS/400 */ KB_INT1, KB_INT2, KB_INT3, @@ -271,7 +297,7 @@ enum keycodes { KB_INT7, KB_INT8, KB_INT9, - KB_LANG1, /* 0x90 */ + KB_LANG1, /* 0x90 */ KB_LANG2, KB_LANG3, KB_LANG4, @@ -287,12 +313,13 @@ enum keycodes { KB_PRIOR, KB_RETURN, KB_SEPARATOR, - KB_OUT, + KB_OUT, /* 0xA0 */ KB_OPER, KB_CLEAR_AGAIN, KB_CRSEL, KB_EXSEL, + /* NOTE: uses 0xB0-DF for special keycodes */ KB_KP_00 = 0xB0, KB_KP_000, KB_THOUSANDS_SEPARATOR, @@ -301,15 +328,15 @@ enum keycodes { KB_CURRENCY_SUB_UNIT, KB_KP_LPAREN, KB_KP_RPAREN, - KB_KP_LCBRACKET, /* { */ - KB_KP_RCBRACKET, /* } */ + KB_KP_LCBRACKET, /* { */ + KB_KP_RCBRACKET, /* } */ KB_KP_TAB, KB_KP_BSPACE, KB_KP_A, KB_KP_B, KB_KP_C, KB_KP_D, - KB_KP_E, + KB_KP_E, /* 0xC0 */ KB_KP_F, KB_KP_XOR, KB_KP_HAT, @@ -325,7 +352,7 @@ enum keycodes { KB_KP_SPACE, KB_KP_ATMARK, KB_KP_EXCLAMATION, - KB_KP_MEM_STORE, + KB_KP_MEM_STORE, /* 0xD0 */ KB_KP_MEM_RECALL, KB_KP_MEM_CLEAR, KB_KP_MEM_ADD, @@ -340,41 +367,17 @@ enum keycodes { KB_KP_DECIMAL, KB_KP_HEXADECIMAL, - /* modifiers */ - KB_LCTRL = 0xE0, /* 0x01 */ - KB_LSHIFT, /* 0x02 */ - KB_LALT, /* 0x04 */ - KB_LGUI, /* 0x08 */ - KB_RCTRL, /* 0x10 */ - KB_RSHIFT, /* 0x20 */ - KB_RALT, /* 0x40 */ - KB_RGUI, /* 0x80 */ + /* Modifiers */ + KB_LCTRL = 0xE0, + KB_LSHIFT, + KB_LALT, + KB_LGUI, + KB_RCTRL, + KB_RSHIFT, + KB_RALT, + KB_RGUI, - /* extensions for internal use */ - KB_FN0 = 0xE8, - KB_FN1, - KB_FN2, - KB_FN3, - KB_FN4, - KB_FN5, - KB_FN6, - KB_FN7, - // Mousekey move - KB_MS_UP = 0xF0, - KB_MS_DOWN, - KB_MS_LEFT, - KB_MS_RIGHT, - // Mousekey buttons - KB_MS_BTN1 = 0xF4, - KB_MS_BTN2, - KB_MS_BTN3, - KB_MS_BTN4, - KB_MS_BTN5, - // Mousekey wheel - KB_MS_WH_UP, - KB_MS_WH_DOWN, - KB_MS_WH_LEFT, - KB_MS_WH_RIGHT, + /* NOTE: uses 0xE8-FF for special keycodes */ }; #endif /* USB_KEYCODES_H */ diff --git a/vusb/host.c b/vusb/host.c index 6b091a72..0a507d48 100644 --- a/vusb/host.c +++ b/vusb/host.c @@ -146,10 +146,12 @@ void host_mouse_send(report_mouse_t *report) #endif #ifdef USB_EXTRA_ENABLE -void host_system_send(uint8_t data) +void host_system_send(uint16_t data) { - static uint8_t report[] = { REPORT_ID_SYSTEM, 0 }; - report[1] = data; + // Not need static? + static uint8_t report[] = { REPORT_ID_SYSTEM, 0, 0 }; + report[1] = data&0xFF; + report[2] = (data>>8)&0xFF; if (usbInterruptIsReady3()) { usbSetInterrupt3((void *)&report, sizeof(report)); } else { @@ -157,10 +159,16 @@ void host_system_send(uint8_t data) } } -void host_audio_send(uint8_t data) +void host_consumer_send(uint16_t data) { - static uint8_t report[] = { REPORT_ID_AUDIO, 0 }; - report[1] = data; + static uint16_t last_data = 0; + 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; if (usbInterruptIsReady3()) { usbSetInterrupt3((void *)&report, sizeof(report)); } else { @@ -293,85 +301,77 @@ PROGMEM uchar keyboard_hid_report[] = { */ PROGMEM uchar mouse_hid_report[] = { /* mouse */ - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x02, // USAGE (Mouse) - 0xa1, 0x01, // COLLECTION (Application) - 0x85, 0x01, // REPORT_ID (1) - 0x09, 0x01, // USAGE (Pointer) - 0xa1, 0x00, // COLLECTION (Physical) - // ---------------------------- Buttons - 0x05, 0x09, // USAGE_PAGE (Button) - 0x19, 0x01, // USAGE_MINIMUM (Button 1) - 0x29, 0x05, // USAGE_MAXIMUM (Button 5) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x75, 0x01, // REPORT_SIZE (1) - 0x95, 0x05, // REPORT_COUNT (5) - 0x81, 0x02, // INPUT (Data,Var,Abs) - // ---------------------------- Padding - 0x75, 0x03, // REPORT_SIZE (3) - 0x95, 0x01, // REPORT_COUNT (1) - 0x81, 0x03, // INPUT (Cnst,Var,Abs) - // ---------------------------- X,Y position - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x30, // USAGE (X) - 0x09, 0x31, // USAGE (Y) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x02, // REPORT_COUNT (2) - 0x81, 0x06, // INPUT (Data,Var,Rel) - // ---------------------------- Vertical wheel - 0x09, 0x38, // USAGE (Wheel) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical - 0x45, 0x00, // PHYSICAL_MAXIMUM (0) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x01, // REPORT_COUNT (1) - 0x81, 0x06, // INPUT (Data,Var,Rel) - // ---------------------------- Horizontal wheel - 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) - 0x0a, 0x38, 0x02, // USAGE (AC Pan) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x01, // REPORT_COUNT (1) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0xc0, // END_COLLECTION - 0xc0, // END_COLLECTION - /* system */ + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x02, // USAGE (Mouse) + 0xa1, 0x01, // COLLECTION (Application) + 0x85, REPORT_ID_MOUSE, // REPORT_ID (1) + 0x09, 0x01, // USAGE (Pointer) + 0xa1, 0x00, // COLLECTION (Physical) + // ---------------------------- Buttons + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) + 0x29, 0x05, // USAGE_MAXIMUM (Button 5) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x75, 0x01, // REPORT_SIZE (1) + 0x95, 0x05, // REPORT_COUNT (5) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x75, 0x03, // REPORT_SIZE (3) + 0x95, 0x01, // REPORT_COUNT (1) + 0x81, 0x03, // INPUT (Cnst,Var,Abs) + // ---------------------------- X,Y position + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x30, // USAGE (X) + 0x09, 0x31, // USAGE (Y) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x02, // REPORT_COUNT (2) + 0x81, 0x06, // INPUT (Data,Var,Rel) + // ---------------------------- Vertical wheel + 0x09, 0x38, // USAGE (Wheel) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical + 0x45, 0x00, // PHYSICAL_MAXIMUM (0) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x01, // REPORT_COUNT (1) + 0x81, 0x06, // INPUT (Data,Var,Rel) + // ---------------------------- Horizontal wheel + 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) + 0x0a, 0x38, 0x02, // USAGE (AC Pan) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x01, // REPORT_COUNT (1) + 0x81, 0x06, // INPUT (Data,Var,Rel) + 0xc0, // END_COLLECTION + 0xc0, // END_COLLECTION + /* system control */ 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x09, 0x80, // USAGE (System Control) 0xa1, 0x01, // COLLECTION (Application) - 0x85, 0x02, // REPORT_ID (2) - 0x19, 0x81, // USAGE_MINIMUM (System Power Down) - 0x29, 0x83, // USAGE_MAXIMUM (System Wake Up) - 0x75, 0x01, // REPORT_SIZE (1) - 0x95, 0x03, // REPORT_COUNT (3) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0x95, 0x05, // REPORT_COUNT (5) - 0x81, 0x07, // INPUT (Cnst,Var,Rel) + 0x85, REPORT_ID_SYSTEM, // REPORT_ID (2) + 0x15, 0x01, // LOGICAL_MINIMUM (0x1) + 0x25, 0xb7, // LOGICAL_MAXIMUM (0xb7) + 0x19, 0x01, // USAGE_MINIMUM (0x1) + 0x29, 0xb7, // USAGE_MAXIMUM (0xb7) + 0x75, 0x10, // REPORT_SIZE (16) + 0x95, 0x01, // REPORT_COUNT (1) + 0x81, 0x00, // INPUT (Data,Array,Abs) 0xc0, // END_COLLECTION - /* audio */ + /* consumer */ 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) 0x09, 0x01, // USAGE (Consumer Control) 0xa1, 0x01, // COLLECTION (Application) - 0x85, 0x03, // REPORT_ID (3) - 0x09, 0xe9, // USAGE (Volume Up) - 0x09, 0xea, // USAGE (Volume Down) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x75, 0x01, // REPORT_SIZE (1) - 0x95, 0x02, // REPORT_COUNT (2) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x09, 0xe2, // USAGE (Mute) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x85, REPORT_ID_CONSUMER, // REPORT_ID (3) + 0x15, 0x01, // LOGICAL_MINIMUM (0x1) + 0x26, 0x9c, 0x02, // LOGICAL_MAXIMUM (0x29c) + 0x19, 0x01, // USAGE_MINIMUM (0x1) + 0x2a, 0x9c, 0x02, // USAGE_MAXIMUM (0x29c) + 0x75, 0x10, // REPORT_SIZE (16) 0x95, 0x01, // REPORT_COUNT (1) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0x95, 0x05, // REPORT_COUNT (5) - 0x81, 0x07, // INPUT (Cnst,Var,Abs) + 0x81, 0x00, // INPUT (Data,Array,Abs) 0xc0, // END_COLLECTION }; -- 2.39.3