aboutsummaryrefslogtreecommitdiff
path: root/keyboard/hhkb
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2012-06-11 10:53:02 +0900
committertmk <nobody@nowhere>2012-06-11 10:53:02 +0900
commit62d1ebb91c7b381ce3d88aad9ee0b03bea9fce26 (patch)
tree6b10864a310f611187e1b61102da7da1db1d2e29 /keyboard/hhkb
parent225de7a847a511d004bf909b1334e19497cf2f9d (diff)
parent81706d1130fdc3c0d6d110f4d8665c47ffd7fb59 (diff)
downloadqmk_firmware-62d1ebb91c7b381ce3d88aad9ee0b03bea9fce26.tar.gz
qmk_firmware-62d1ebb91c7b381ce3d88aad9ee0b03bea9fce26.zip
Merge branch 'newdir'
Diffstat (limited to 'keyboard/hhkb')
-rw-r--r--keyboard/hhkb/Makefile.iwrap93
-rw-r--r--keyboard/hhkb/Makefile.pjrc60
-rw-r--r--keyboard/hhkb/Makefile.vusb91
-rw-r--r--keyboard/hhkb/README151
-rw-r--r--keyboard/hhkb/config_iwrap.h55
-rw-r--r--keyboard/hhkb/config_pjrc.h62
-rw-r--r--keyboard/hhkb/config_vusb.h49
-rw-r--r--keyboard/hhkb/doc/Bluetooth.txt4
-rwxr-xr-xkeyboard/hhkb/doc/Bluetooth_img/.picasa.ini2
-rw-r--r--keyboard/hhkb/doc/Bluetooth_img/BT_circuit.jpgbin0 -> 502118 bytes
-rw-r--r--keyboard/hhkb/doc/HHKB.txt199
-rw-r--r--keyboard/hhkb/doc/HHKB_img/HHKB_TP1684.jpgbin0 -> 149082 bytes
-rw-r--r--keyboard/hhkb/doc/HHKB_img/HHKB_chart1.jpgbin0 -> 155342 bytes
-rw-r--r--keyboard/hhkb/doc/HHKB_img/HHKB_chart2.jpgbin0 -> 148225 bytes
-rw-r--r--keyboard/hhkb/doc/HHKB_img/HHKB_connector.jpgbin0 -> 193900 bytes
-rw-r--r--keyboard/hhkb/doc/HHKB_img/HHKB_controller.jpgbin0 -> 135100 bytes
-rw-r--r--keyboard/hhkb/doc/HHKB_img/HHKB_keyswitch.jpgbin0 -> 171469 bytes
-rw-r--r--keyboard/hhkb/doc/HHKB_img/connector_contact.jpgbin0 -> 192830 bytes
-rw-r--r--keyboard/hhkb/doc/HHKB_img/logic_analyzer.jpgbin0 -> 169564 bytes
-rw-r--r--keyboard/hhkb/doc/HHKB_img/probe_contact.jpgbin0 -> 208477 bytes
-rw-r--r--keyboard/hhkb/doc/HHKB_img/teensy_install.jpgbin0 -> 135851 bytes
-rw-r--r--keyboard/hhkb/doc/HHKB_img/teensy_wiring.jpgbin0 -> 154695 bytes
-rw-r--r--keyboard/hhkb/keymap.c221
-rw-r--r--keyboard/hhkb/led.c26
-rw-r--r--keyboard/hhkb/matrix.c294
-rw-r--r--keyboard/hhkb/usbconfig.h388
26 files changed, 1695 insertions, 0 deletions
diff --git a/keyboard/hhkb/Makefile.iwrap b/keyboard/hhkb/Makefile.iwrap
new file mode 100644
index 000000000..ef7ad2eac
--- /dev/null
+++ b/keyboard/hhkb/Makefile.iwrap
@@ -0,0 +1,93 @@
1#
2# Makefile for iWRAP
3#
4
5
6# Target file name (without extension).
7TARGET = hhkb_iwrap
8
9# Directory common source filess exist
10TOP_DIR = ../..
11
12# Directory keyboard dependent files exist
13TARGET_DIR = .
14
15# keyboard dependent files
16SRC = main.c \
17 keymap.c \
18 matrix.c \
19 led.c
20
21CONFIG_H = config_iwrap.h
22
23
24# V-USB debug level: To use ps2_usart.c level must be 0
25# ps2_usart.c requires USART to receive PS/2 signal.
26OPT_DEFS = -DDEBUG_LEVEL=0
27
28
29# MCU name, you MUST set this to match the board you are using
30# type "make clean" after changing this, so all files will be rebuilt
31MCU = atmega168p
32# avrdude doesn't know atmega168p
33AVRDUDE_MCU = atmega168
34
35
36# Processor frequency.
37# Normally the first thing your program should do is set the clock prescaler,
38# so your program will run at the correct speed. You should also set this
39# variable to same clock speed. The _delay_ms() macro uses this, and many
40# examples use this variable to calculate timings. Do not add a "UL" here.
41F_CPU = 12000000
42
43
44# Build Options
45# comment out to disable the options.
46#
47MOUSEKEY_ENABLE = yes # Mouse keys
48EXTRAKEY_ENABLE = yes # Audio control and System control
49#NKRO_ENABLE = yes # USB Nkey Rollover
50
51
52
53#---------------- Programming Options --------------------------
54AVRDUDE = avrdude
55# Type: avrdude -c ? to get a full listing.
56AVRDUDE_PROGRAMMER = usbasp
57AVRDUDE_PORT =
58AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
59#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
60
61# Uncomment the following if you want avrdude's erase cycle counter.
62# Note that this counter needs to be initialized first using -Yn,
63# see avrdude manual.
64#AVRDUDE_ERASE_COUNTER = -y
65
66# Uncomment the following if you do /not/ wish a verification to be
67# performed after programming the device.
68#AVRDUDE_NO_VERIFY = -V
69
70# Increase verbosity level. Please use this when submitting bug
71# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
72# to submit bug reports.
73#AVRDUDE_VERBOSE = -v -v
74
75#AVRDUDE_FLAGS = -p $(AVRDUDE_MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
76AVRDUDE_FLAGS = -p $(AVRDUDE_MCU) -c $(AVRDUDE_PROGRAMMER)
77AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
78AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
79AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
80
81PROGRAM_CMD = $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
82
83
84
85# Search Path
86VPATH = $(TARGET_DIR)
87
88include $(TOP_DIR)/protocol/iwrap.mk
89# To be swatchable btween Bluetooth and USB. Comment out if you don't need USB.
90include $(TOP_DIR)/protocol/vusb.mk
91include $(TOP_DIR)/protocol.mk
92include $(TOP_DIR)/common.mk
93include $(TOP_DIR)/rules.mk
diff --git a/keyboard/hhkb/Makefile.pjrc b/keyboard/hhkb/Makefile.pjrc
new file mode 100644
index 000000000..f6d133eae
--- /dev/null
+++ b/keyboard/hhkb/Makefile.pjrc
@@ -0,0 +1,60 @@
1#
2# Makefile for PJRC Teensy
3#
4
5
6# Target file name (without extension).
7TARGET = hhkb_pjrc
8
9# Directory common source filess exist
10TOP_DIR = ../..
11
12# Directory keyboard dependent files exist
13TARGET_DIR = .
14
15# keyboard dependent files
16SRC = main.c \
17 keymap.c \
18 matrix.c \
19 led.c
20
21CONFIG_H = config_pjrc.h
22
23
24# MCU name, you MUST set this to match the board you are using
25# type "make clean" after changing this, so all files will be rebuilt
26#MCU = at90usb162 # Teensy 1.0
27#MCU = atmega32u4 # Teensy 2.0
28#MCU = at90usb646 # Teensy++ 1.0
29MCU = at90usb1286 # Teensy++ 2.0
30
31
32# Processor frequency.
33# Normally the first thing your program should do is set the clock prescaler,
34# so your program will run at the correct speed. You should also set this
35# variable to same clock speed. The _delay_ms() macro uses this, and many
36# examples use this variable to calculate timings. Do not add a "UL" here.
37F_CPU = 16000000
38
39
40# Build Options
41# comment out to disable the options.
42MOUSEKEY_ENABLE = yes # Mouse keys
43#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
44EXTRAKEY_ENABLE = yes # Audio control and System control
45NKRO_ENABLE = yes # USB Nkey Rollover
46
47
48
49#---------------- Programming Options --------------------------
50PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
51
52
53
54# Search Path
55VPATH = $(TARGET_DIR)
56
57include $(TOP_DIR)/protocol/pjrc.mk
58include $(TOP_DIR)/protocol.mk
59include $(TOP_DIR)/common.mk
60include $(TOP_DIR)/rules.mk
diff --git a/keyboard/hhkb/Makefile.vusb b/keyboard/hhkb/Makefile.vusb
new file mode 100644
index 000000000..6dd628807
--- /dev/null
+++ b/keyboard/hhkb/Makefile.vusb
@@ -0,0 +1,91 @@
1#
2# Makefile for V-USB
3#
4
5
6# Target file name (without extension).
7TARGET = hhkb_vusb
8
9# Directory common source filess exist
10TOP_DIR = ../..
11
12# Directory keyboard dependent files exist
13TARGET_DIR = .
14
15# keyboard dependent files
16SRC = main.c \
17 keymap.c \
18 matrix.c \
19 led.c
20
21CONFIG_H = config_vusb.h
22
23
24# V-USB debug level: To use ps2_usart.c level must be 0
25# ps2_usart.c requires USART to receive PS/2 signal.
26OPT_DEFS = -DDEBUG_LEVEL=0
27
28
29# MCU name, you MUST set this to match the board you are using
30# type "make clean" after changing this, so all files will be rebuilt
31MCU = atmega328p
32# avrdude doesn't know atmega168p
33AVRDUDE_MCU = $(MCU)
34
35
36# Processor frequency.
37# Normally the first thing your program should do is set the clock prescaler,
38# so your program will run at the correct speed. You should also set this
39# variable to same clock speed. The _delay_ms() macro uses this, and many
40# examples use this variable to calculate timings. Do not add a "UL" here.
41F_CPU = 12000000
42
43
44# Build Options
45# comment out to disable the options.
46#
47MOUSEKEY_ENABLE = yes # Mouse keys
48EXTRAKEY_ENABLE = yes # Audio control and System control
49#NKRO_ENABLE = yes # USB Nkey Rollover
50
51
52
53#---------------- Programming Options --------------------------
54AVRDUDE = avrdude
55# Type: avrdude -c ? to get a full listing.
56AVRDUDE_PROGRAMMER = usbasp
57AVRDUDE_PORT =
58AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
59#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
60
61# Uncomment the following if you want avrdude's erase cycle counter.
62# Note that this counter needs to be initialized first using -Yn,
63# see avrdude manual.
64#AVRDUDE_ERASE_COUNTER = -y
65
66# Uncomment the following if you do /not/ wish a verification to be
67# performed after programming the device.
68#AVRDUDE_NO_VERIFY = -V
69
70# Increase verbosity level. Please use this when submitting bug
71# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
72# to submit bug reports.
73#AVRDUDE_VERBOSE = -v -v
74
75#AVRDUDE_FLAGS = -p $(AVRDUDE_MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
76AVRDUDE_FLAGS = -p $(AVRDUDE_MCU) -c $(AVRDUDE_PROGRAMMER)
77AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
78AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
79AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
80
81PROGRAM_CMD = $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
82
83
84
85# Search Path
86VPATH = $(TARGET_DIR)
87
88include $(TOP_DIR)/protocol/vusb.mk
89include $(TOP_DIR)/protocol.mk
90include $(TOP_DIR)/common.mk
91include $(TOP_DIR)/rules.mk
diff --git a/keyboard/hhkb/README b/keyboard/hhkb/README
new file mode 100644
index 000000000..65f7dcab5
--- /dev/null
+++ b/keyboard/hhkb/README
@@ -0,0 +1,151 @@
1Alternative Controller for HHKB
2===============================
3
4Feature
5-------
6- Mouse Keys
7- NKRO on USB(PJRC Tennsy only)
8- Keymap Layers
9
10
11Customize Keymap
12----------------
13see keymap.c.
14
15
16
17Build
18=====
19PJRC Teensy
20-----------
210. Edit matrix.c.
22 adjust scan code to your pin configuration.(see doc/HHKB.txt for pinouts)
231. Define macros in config_pjrc.h.(Optional)
24 VENDOR_ID, PRODUCT_ID and string descriptor.
25 IS_COMMAND
262. Edit Makefile for MCU setting and build options.
27 MCU, F_CPU
28 MOUSEKEY_ENABLE, EXTRAKEY_ENABLE, NKRO_ENABLE
293. Build hex file.
30 $ make -f Makefile.pjrc
314. Program MCU.
32 $ make -f Makefile.pjrc program
33
34
35V-USB
36-----
370. Edit matrix.c and usbconfig.h.
38 adjust scan code to your pin configuration.(see doc/HHKB.txt for pinouts)
39 define macros for V-USB in usbconfig.h.
401. Define macros in config_vusb.h.(Optional)
41 IS_COMMAND
422. Edit Makefile.vusb for MCU setting and build options.
43 MCU, F_CPU
44 MOUSEKEY_ENABLE, EXTRAKEY_ENABLE
453. Build hex file.
46 $ make -f Makefile.vusb
474. Program MCU.
48 $ make -f Makefile.vusb program
49
50 Using a bootloader to program for convenience is recommended.
51 Once program this V-USB bootloader at first, you can program MCU without
52 extra programmer. You should have reset switch to start up as bootloader
53 mode in this case.
54 USBaspLoader:
55 http://www.obdev.at/products/vusb/usbasploader.html
56
57
58iWRAP
59-----
600. Edit matrix.c and usbconfig.h.
61 adjust scan code to your pin configuration.(see doc/HHKB.txt for pinouts)
62 define macros for V-USB in usbconfig.h.
631. Define macros in config_iwrap.h.(Optional)
64 IS_COMMAND
652. Edit Makefile.iwrap for MCU setting and build options.
66 MCU, F_CPU
67 MOUSEKEY_ENABLE, EXTRAKEY_ENABLE
683. Build hex file.
69 $ make -f Makefile.iwrap
704. Program MCU.
71 $ make -f Makefile.iwrap program
72
73
74
75Hardware
76========
77PJRC Teensy
78-----------
79 +---------------+
80 | Teensy++ |
81 | |
82 | | HHKB
83 | | ~~~~
84 | PB0-2|------->ROW(6-8)
85 | PB3-5|------->COL(9-11)
86 | PB6|------->ENABLE(12)
87 | PE6|<-------KEY(4)
88 | PE7|------->PREV(5)
89 | |
90 | |
91 | |
92 +---------------+
93
94
95V-USB
96-----
97 +---+ +---------------+
98USB GND | | ATmega168 |
99~~~ C3 | |
1005V <-------+--------+---|Vcc,AVCC | HHKB
101 R1 | | ~~~~
102D- <----+--+-----R2-----|INT1 PB2-4|------->ROW(6-8)
103D+ <----|---+----R3-----|INT0 PC0-2|------->COL(9-11)
104 Z1 Z2 | PC3|------->ENABLE(12)
105GND<----+---+-----------|GND PB0|<-------KEY(4)
106 | PB1|------->PREV(5)
107 | |
108 GND+-C2--+--|XTAL1 RXD|------->Debug Console
109 X1 | TXD|<-------Debug Console
110 GND+-C3--+--|XTAL2 RST|---SW--+GND
111 +---------------+
112R1: 1.5K Ohm
113R2,R3: 68 Ohm
114Z1,Z2: Zener 3.6V
115C1,C2: 22pF
116C3: 0.1uF
117X1: Crystal 20MHz(16MHz/12MHz)
118SW: Push Switch(Optional for bootloader)
119
120
121iWRAP
122-----
123 +---------------+ WT12
124 5V | ATmega168 | 5V/3.3V~~~~
125 +-----+---|Vcc,AVCC PC4|---/--->iWRAP(RxD)
126USB | C3 | PC5|<--/----iWRAP(TxD)
127~~~ | + | |
1285V <--BATT + GND | | HHKB
129 R1 | | ~~~~
130D- <----+-----+--R2-----|INT1 PB2-4|------->ROW(6-8)
131D+ <----|---+----R3-----|INT0 PC0-2|------->COL(9-11)
132 Z1 Z2 | PC3|------->ENABLE(12)
133GND<----+---+-----------|GND PB0|<-------KEY(4)
134 | PB1|------->PREV(5)
135 | |
136 GND+-C2--+--|XTAL1 RXD|------->Debug Console
137 X1 | TXD|<-------Debug Console
138 GND+-C3--+--|XTAL2 RST|---SW--+GND
139 +---------------+
140
141R1: 1.5K Ohm
142R2,R3: 68 Ohm
143Z1,Z2: Zener 3.6V
144C1,C2: 22pF
145C3: 0.1uF
146X1: Crystal 12MHz
147SW: Push Switch(Optional)
148BATT: Li-Po Battery, Battery Charger and Voltage Regulator(5V and 3.3V).
149
150
151EOF
diff --git a/keyboard/hhkb/config_iwrap.h b/keyboard/hhkb/config_iwrap.h
new file mode 100644
index 000000000..80ab64398
--- /dev/null
+++ b/keyboard/hhkb/config_iwrap.h
@@ -0,0 +1,55 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef CONFIG_H
19#define CONFIG_H
20
21#define VENDOR_ID 0xFEED
22#define PRODUCT_ID 0xBEEA
23// TODO: share these strings with usbconfig.h
24// Edit usbconfig.h to change these.
25#define MANUFACTURER t.m.k.
26#define PRODUCT HHKB mod
27#define DESCRIPTION t.m.k. keyboard firmware for HHKB mod
28
29
30/* matrix size */
31#define MATRIX_ROWS 8
32#define MATRIX_COLS 8
33
34
35/* key combination for command */
36#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT)))
37
38/* mouse keys */
39#ifdef MOUSEKEY_ENABLE
40# define MOUSEKEY_DELAY_TIME 255
41#endif
42
43/* pins for Software UART */
44#define SUART_IN_PIN PINC
45#define SUART_IN_BIT 5
46#define SUART_OUT_PORT PORTC
47#define SUART_OUT_BIT 4
48
49
50#define DEBUG_LED 1
51#define DEBUG_LED_CONFIG (DDRD |= (1<<4))
52#define DEBUG_LED_OFF (PORTD |= (1<<4))
53#define DEBUG_LED_ON (PORTD &= ~(1<<4))
54
55#endif
diff --git a/keyboard/hhkb/config_pjrc.h b/keyboard/hhkb/config_pjrc.h
new file mode 100644
index 000000000..fffe3522c
--- /dev/null
+++ b/keyboard/hhkb/config_pjrc.h
@@ -0,0 +1,62 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef CONFIG_H
19#define CONFIG_H
20
21/* controller configuration */
22#include "controller_teensy.h"
23
24#define VENDOR_ID 0xFEED
25#define PRODUCT_ID 0xCAFE
26#define DEVICE_VER 0x0101
27#define MANUFACTURER t.m.k.
28#define PRODUCT HHKB mod
29#define DESCRIPTION t.m.k. keyboard firmware for HHKB mod
30
31
32/* matrix size */
33#define MATRIX_ROWS 8
34#define MATRIX_COLS 8
35/* define if matrix has ghost */
36//#define MATRIX_HAS_GHOST
37
38
39/* key combination for command */
40#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT)))
41
42/* mouse keys */
43#ifdef MOUSEKEY_ENABLE
44# define MOUSEKEY_DELAY_TIME 192
45#endif
46
47
48/* PS/2 mouse */
49#ifdef PS2_MOUSE_ENABLE
50/*
51# define PS2_CLOCK_PORT PORTF
52# define PS2_CLOCK_PIN PINF
53# define PS2_CLOCK_DDR DDRF
54# define PS2_CLOCK_BIT 0
55# define PS2_DATA_PORT PORTF
56# define PS2_DATA_PIN PINF
57# define PS2_DATA_DDR DDRF
58# define PS2_DATA_BIT 1
59*/
60#endif
61
62#endif
diff --git a/keyboard/hhkb/config_vusb.h b/keyboard/hhkb/config_vusb.h
new file mode 100644
index 000000000..268644849
--- /dev/null
+++ b/keyboard/hhkb/config_vusb.h
@@ -0,0 +1,49 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef CONFIG_H
19#define CONFIG_H
20
21#define VENDOR_ID 0xFEED
22#define PRODUCT_ID 0xC0FE
23// TODO: share these strings with usbconfig.h
24// Edit usbconfig.h to change these.
25#define MANUFACTURER t.m.k.
26#define PRODUCT HHKB mod
27#define DESCRIPTION t.m.k. keyboard firmware for HHKB mod
28
29
30/* matrix size */
31#define MATRIX_ROWS 8
32#define MATRIX_COLS 8
33
34
35/* key combination for command */
36#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT)))
37
38/* mouse keys */
39#ifdef MOUSEKEY_ENABLE
40# define MOUSEKEY_DELAY_TIME 255
41#endif
42
43
44#define DEBUG_LED 1
45#define DEBUG_LED_CONFIG (DDRD |= (1<<4))
46#define DEBUG_LED_OFF (PORTD |= (1<<4))
47#define DEBUG_LED_ON (PORTD &= ~(1<<4))
48
49#endif
diff --git a/keyboard/hhkb/doc/Bluetooth.txt b/keyboard/hhkb/doc/Bluetooth.txt
new file mode 100644
index 000000000..b27f19700
--- /dev/null
+++ b/keyboard/hhkb/doc/Bluetooth.txt
@@ -0,0 +1,4 @@
1HHKB Bluetooth mod
2==================
3See this article:
4http://geekhack.org/showwiki.php?title=Island:20851
diff --git a/keyboard/hhkb/doc/Bluetooth_img/.picasa.ini b/keyboard/hhkb/doc/Bluetooth_img/.picasa.ini
new file mode 100755
index 000000000..f6a4f6067
--- /dev/null
+++ b/keyboard/hhkb/doc/Bluetooth_img/.picasa.ini
@@ -0,0 +1,2 @@
1[Picasa]
2name=Bluetooth_img
diff --git a/keyboard/hhkb/doc/Bluetooth_img/BT_circuit.jpg b/keyboard/hhkb/doc/Bluetooth_img/BT_circuit.jpg
new file mode 100644
index 000000000..2e5a25e81
--- /dev/null
+++ b/keyboard/hhkb/doc/Bluetooth_img/BT_circuit.jpg
Binary files differ
diff --git a/keyboard/hhkb/doc/HHKB.txt b/keyboard/hhkb/doc/HHKB.txt
new file mode 100644
index 000000000..ace931de3
--- /dev/null
+++ b/keyboard/hhkb/doc/HHKB.txt
@@ -0,0 +1,199 @@
1Alternative Controller for HHKB pro
2===================================
3I want to add vi cursor and mouse keys to HHKB. Original HHKB controller is not programmable and
4firmware source code is not open. So, customizing HHKB needs to replace original controller with programmable one.
5I used Teensy++ as alternative controller. Though a Teensy has enough ports to drive HHKB,
6Teensy++ has clean pinout and it makes programing and wiring easier.
7
8This is just a proof of concept for replacing controller of HHKB, not a complete firmware.
9
10My prototype firmware source tree is here:
11 github(http://github.com/tmk/tmk_keyboard)
12This firmware is a port of my previous project:
13 HHKB style Mod(http://geekhack.org/showwiki.php?title=Island:11930)
14PJRC:
15 Teensy++/Teensy(http://www.pjrc.com/teensy/)
16
17
18Pros:
19 * without pattern cutting, case mod and soldering
20 * can keep original controller intact
21 * can change HHKB behaviour as you like(by C programming)
22
23Cons:
24 * void your warranty
25 * unavailability of Teensy++/Teensy(because of PS3 cracking boom?)
26
27Features:
28 * customized keymap
29 * more keymap layers
30 * mouse keys for minimum mouse operation(never comfortable for normal use)
31 * and more...(in the future)
32
33Any suggestions or ideas are welcome.
34
35
36NOTE:
37 My HHKB is just "Professional". This means followings may not be applied to "Professional2".
38
39DISCLAIMER:
40 I'm not a professional for electronics and MCU programming. This may damage your HHKB.
41 And my English writing is poor, I'm not sure I can convey my notions accurately.
42
43
44Teensy++ installation
45---------------------
46Angled USB mini B adapter is used to install Teensy++ laterally.
47(teensy_install.jpg)
48
49Bread baord wires are used to connect Teensy++.
50(teensy_wiring.jpg)
51(connector_contact.jpg)
52
53
54HHKB internal
55-------------
56HHKB pro has some chips on separate two PCBs.
57
58Controller PCB:
59 M38K07M4 Renesas MCU with USB function
60 http://documentation.renesas.com/eng/products/mpumcu/rej03b0192_38k0ds.pdf
61
62 (HHKB_controller.jpg)
63
64Keyswitch PCB:
65 HC4051 Analog Multiplexer: select a row line.
66 http://www.alldatasheet.com/datasheet-pdf/pdf/203989/KODENSHI/KK74HC4051A.html
67 LS145 BCD Decoder: select a column line.
68 http://www.alldatasheet.com/datasheet-pdf/pdf/27373/TI/SN74LS145D.html
69 BU9831 Non-volatile electronic potentiometer: for calibration?
70 http://www.alldatasheet.com/datasheet-pdf/pdf/36387/ROHM/BU9831.html
71 TP1683/4 Capacitive Sensing controller: no datasheet available.
72
73 (HHKB_keyswitch.jpg)
74
75 Topre original chip?
76 (HHKB_TP1684.jpg)
77
78
79Two PCBs are connected by 15 lines. Vcc and GND use 3 lines each, other 9 lines are for keyboard signaling.
80
81 Keyswitch PCB connector Teensy++ pins
82 -------------------------------------------------------------------------------
83 1 Vcc(5V) 5V
84 2 Vcc(5V)
85 3 Vcc(5V)
86 4 TP1684 KEY: Low(0) when key pressed PE6 input(with pullup)
87 5 TP1684 KEY_PREV: assert previous key state??? PE7 output
88 6 HC4051 A(bit0) select 8 rows(0 to 7) PB0 output
89 7 HC4051 B(bit1) PB1 output
90 8 HC4051 C(bit2) PB2 output
91 9 LS145 A(bit0) select 8 columns(0 to 7) PB3 output
92 10 LS145 B(bit1) PB4 output
93 11 LS145 C(bit2) PB5 output
94 12 LS145 D(enable) Low(0) enable selected column PB6 output
95 13 GND
96 14 GND
97 15 GND GND
98
99 (HHKB_connector.jpg)
100
101
102Keyswitch matrix
103----------------
10460 keyswitches in 8*8 matrix. It is ghost-free and bounce-free.
105
106 COL 0 1 2 3 4 5 6 7
107ROW ---------------------------------------------------------------
108 0| 2 q w s a z x c
109 1| 3 4 r e d f v b
110 2| 5 6 y t g h n _NONE_
111 3| 1 Esc Tab Control LShift LAlt LMeta Space
112 4| 7 8 u i k j m _NONE_
113 5| \ ` Delete Return Fn RShift RAlt RMeta
114 6| 9 0 o p ; l , _NONE_
115 7| - + ] [ ' / . _NONE_
116
117
118Matrix diagram:
119 +-------------------------+-+-+-+-+-+-+-+ Vcc
120 |bias control? - - - - - - - - ---
121 | 3.9K*8 R R R R R R R R |
122 +--------^+ +--------+ - - - - - - - - |
123 | 2| | HC4051 <0-------|-|-|-|-|-|-|-|--|R|-+
124 | |capa. | <1-------|-|-|-|-|-|-|-|--|R|-+
125 | TP1684 |sense | <2-------|-|-|-|-|-|-|-|--|R|-+
126 | 11<------| <3-------|-|-|-|-|-|-|-|--|R|-+
127 | | | <4-------|-|-|-|-|-|-|-|--|R|-+
128 | | | <5-------|-|-|-|-|-|-|-|--|R|-+
129 | <-+ | <6-------|-|-|-|-|-|-|-|--|R|-+
130 | 1 4 | | | <7-------|-|-|-|-|-|-|-|--|R|-+
131 +---V---^-+ | +-^-^-^--+ 0 1 2 3 4 5 6 7 33K*8
132 KEY PREV | A B C +-----------------+
133 | | +-^----+ | | | | LS145 |
134 Vcc | | |BU9831| | | | +-^--^--^--^------+
135 --- | | +------+ | | | A B C D +------+
136 | | | | | | | | | | | |
137 1-3 4 5 6 7 8 9 10 11 12 13-15 |
138 +--------------------------------------------------+ |
139 | connector | ---
140 +--------------------------------------------------+ GND
141 to controller
142
143
144Signals charts:
145 While pressing space bar, watched HHKB original controller signals by logic analyzer.
146 Row and column is looping between 0-7 each for selecting a key.
147 A key is scaned every about 15ms, so scan rate is 66Hz.
148
149 (HHKB_chart1.jpg)
150
151 Space bar locate at ROW:3 COL:7. A key is selected by HC4051(C,B,A) and LS145(C,B,A).
152 Key state can be read on TP1684(4/KEY) while asserting low on LS145(D).
153
154 Usage of TP1684(5) is not clear. Controller seemed to output previous key state on this line.
155 However key state can be read without using this signal.
156
157 (HHKB_chart2.jpg)
158
159
160Matrix scan pseudo code:
161 for (row: 0-7) {
162 SELECT_ROW(row); // set HC4051(A,B,C)
163
164 for (col: 0-7) {
165 SELECT_COL(col); // set LS145(A,B,C)
166
167 _delay_us(40);
168
169 if (prev_key_state(row, col)) {
170 KEY_PREV_ON;
171 }
172
173 _delay_us(7);
174
175 ENALBLE_COL(); // set LS145(D) to low
176
177 _delay_us(10);
178
179 if (KEY == 0) { // read TP1684(KEY)
180 // key pressed
181 } else {
182 // not pressed
183 }
184
185 KEY_PREV_OFF;
186 UNALBLE_COL(); // set LS145(D) to high
187
188 _delay_us(150);
189 }
190 }
191
192
193Keymap layers
194-------------
195Followings are added layers with additional Fn keys.
196
197see keymap.c
198
199EOF
diff --git a/keyboard/hhkb/doc/HHKB_img/HHKB_TP1684.jpg b/keyboard/hhkb/doc/HHKB_img/HHKB_TP1684.jpg
new file mode 100644
index 000000000..0a0316409
--- /dev/null
+++ b/keyboard/hhkb/doc/HHKB_img/HHKB_TP1684.jpg
Binary files differ
diff --git a/keyboard/hhkb/doc/HHKB_img/HHKB_chart1.jpg b/keyboard/hhkb/doc/HHKB_img/HHKB_chart1.jpg
new file mode 100644
index 000000000..1f09bd185
--- /dev/null
+++ b/keyboard/hhkb/doc/HHKB_img/HHKB_chart1.jpg
Binary files differ
diff --git a/keyboard/hhkb/doc/HHKB_img/HHKB_chart2.jpg b/keyboard/hhkb/doc/HHKB_img/HHKB_chart2.jpg
new file mode 100644
index 000000000..45f5ada90
--- /dev/null
+++ b/keyboard/hhkb/doc/HHKB_img/HHKB_chart2.jpg
Binary files differ
diff --git a/keyboard/hhkb/doc/HHKB_img/HHKB_connector.jpg b/keyboard/hhkb/doc/HHKB_img/HHKB_connector.jpg
new file mode 100644
index 000000000..e8a09e9b2
--- /dev/null
+++ b/keyboard/hhkb/doc/HHKB_img/HHKB_connector.jpg
Binary files differ
diff --git a/keyboard/hhkb/doc/HHKB_img/HHKB_controller.jpg b/keyboard/hhkb/doc/HHKB_img/HHKB_controller.jpg
new file mode 100644
index 000000000..e3dae8e86
--- /dev/null
+++ b/keyboard/hhkb/doc/HHKB_img/HHKB_controller.jpg
Binary files differ
diff --git a/keyboard/hhkb/doc/HHKB_img/HHKB_keyswitch.jpg b/keyboard/hhkb/doc/HHKB_img/HHKB_keyswitch.jpg
new file mode 100644
index 000000000..3afc269e7
--- /dev/null
+++ b/keyboard/hhkb/doc/HHKB_img/HHKB_keyswitch.jpg
Binary files differ
diff --git a/keyboard/hhkb/doc/HHKB_img/connector_contact.jpg b/keyboard/hhkb/doc/HHKB_img/connector_contact.jpg
new file mode 100644
index 000000000..5304bc8d7
--- /dev/null
+++ b/keyboard/hhkb/doc/HHKB_img/connector_contact.jpg
Binary files differ
diff --git a/keyboard/hhkb/doc/HHKB_img/logic_analyzer.jpg b/keyboard/hhkb/doc/HHKB_img/logic_analyzer.jpg
new file mode 100644
index 000000000..f1b438ae7
--- /dev/null
+++ b/keyboard/hhkb/doc/HHKB_img/logic_analyzer.jpg
Binary files differ
diff --git a/keyboard/hhkb/doc/HHKB_img/probe_contact.jpg b/keyboard/hhkb/doc/HHKB_img/probe_contact.jpg
new file mode 100644
index 000000000..dc79afa0c
--- /dev/null
+++ b/keyboard/hhkb/doc/HHKB_img/probe_contact.jpg
Binary files differ
diff --git a/keyboard/hhkb/doc/HHKB_img/teensy_install.jpg b/keyboard/hhkb/doc/HHKB_img/teensy_install.jpg
new file mode 100644
index 000000000..873d988ed
--- /dev/null
+++ b/keyboard/hhkb/doc/HHKB_img/teensy_install.jpg
Binary files differ
diff --git a/keyboard/hhkb/doc/HHKB_img/teensy_wiring.jpg b/keyboard/hhkb/doc/HHKB_img/teensy_wiring.jpg
new file mode 100644
index 000000000..1c4eb6743
--- /dev/null
+++ b/keyboard/hhkb/doc/HHKB_img/teensy_wiring.jpg
Binary files differ
diff --git a/keyboard/hhkb/keymap.c b/keyboard/hhkb/keymap.c
new file mode 100644
index 000000000..85a7c31b7
--- /dev/null
+++ b/keyboard/hhkb/keymap.c
@@ -0,0 +1,221 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18/*
19 * Keymap for PFU HHKB Pro
20 */
21#include <stdint.h>
22#include <stdbool.h>
23#include <avr/pgmspace.h>
24#include "host.h"
25#include "usb_keycodes.h"
26#include "print.h"
27#include "debug.h"
28#include "util.h"
29#include "keymap.h"
30
31
32// Convert physical keyboard layout to matrix array.
33// This is a macro to define keymap easily in keyboard layout form.
34#define KEYMAP( \
35 K31, K30, K00, K10, K11, K20, K21, K40, K41, K60, K61, K70, K71, K50, K51, \
36 K32, K01, K02, K13, K12, K23, K22, K42, K43, K62, K63, K73, K72, K52, \
37 K33, K04, K03, K14, K15, K24, K25, K45, K44, K65, K64, K74, K53, \
38 K34, K05, K06, K07, K16, K17, K26, K46, K66, K76, K75, K55, K54, \
39 K35, K36, K37, K57, K56 \
40) \
41{ \
42 { KB_##K00, KB_##K01, KB_##K02, KB_##K03, KB_##K04, KB_##K05, KB_##K06, KB_##K07 }, \
43 { KB_##K10, KB_##K11, KB_##K12, KB_##K13, KB_##K14, KB_##K15, KB_##K16, KB_##K17 }, \
44 { KB_##K20, KB_##K21, KB_##K22, KB_##K23, KB_##K24, KB_##K25, KB_##K26, KB_NO }, \
45 { KB_##K30, KB_##K31, KB_##K32, KB_##K33, KB_##K34, KB_##K35, KB_##K36, KB_##K37 }, \
46 { KB_##K40, KB_##K41, KB_##K42, KB_##K43, KB_##K44, KB_##K45, KB_##K46, KB_NO }, \
47 { KB_##K50, KB_##K51, KB_##K52, KB_##K53, KB_##K54, KB_##K55, KB_##K56, KB_##K57 }, \
48 { KB_##K60, KB_##K61, KB_##K62, KB_##K63, KB_##K64, KB_##K65, KB_##K66, KB_NO }, \
49 { KB_##K70, KB_##K71, KB_##K72, KB_##K73, KB_##K74, KB_##K75, KB_##K76, KB_NO } \
50}
51
52#define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)]))
53
54
55// Assign Fn key(0-7) to a layer to which switch with the Fn key pressed.
56static const uint8_t PROGMEM fn_layer[] = {
57 0, // Fn0
58 1, // Fn1
59 2, // Fn2
60 3, // Fn3
61 3, // Fn4
62 4, // Fn5
63 0, // Fn6
64 0 // Fn7
65};
66
67// Assign Fn key(0-7) to a keycode sent when release Fn key without use of the layer.
68// See layer.c for details.
69static const uint8_t PROGMEM fn_keycode[] = {
70 KB_NO, // Fn0
71 KB_NO, // Fn1
72 KB_SLSH, // Fn2
73 KB_SCLN, // Fn3
74 KB_NO, // Fn4
75 KB_SPC, // Fn5
76 KB_NO, // Fn6
77 KB_NO // Fn7
78};
79
80static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
81 /* Layer 0: Default Layer
82 * ,-----------------------------------------------------------.
83 * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| \| `|
84 * |-----------------------------------------------------------|
85 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]|Backs|
86 * |-----------------------------------------------------------|
87 * |Contro| A| S| D| F| G| H| J| K| L|Fn3| '|Return |
88 * |-----------------------------------------------------------|
89 * |Shift | Z| X| C| V| B| N| M| ,| .|Fn2|Shift |Fn1|
90 * `-----------------------------------------------------------'
91 * |Gui|Alt |Fn5 |Alt |Fn4|
92 * `-------------------------------------------'
93 */
94 KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV, \
95 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \
96 LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT,ENT, \
97 LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \
98 LGUI,LALT, FN5, RALT,FN4),
99
100 /* Layer 1: HHKB mode (HHKB Fn)
101 * ,-----------------------------------------------------------.
102 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
103 * |-----------------------------------------------------------|
104 * |Caps | | | | | | | |Psc|Slk|Pus|Up | |Backs|
105 * |-----------------------------------------------------------|
106 * |Contro|VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter |
107 * |-----------------------------------------------------------|
108 * |Shift | | | | | | +| -|End|PgD|Dow|Shift |xxx|
109 * `-----------------------------------------------------------'
110 * |Gui |Alt |Space |Alt |xxx|
111 * `--------------------------------------------'
112 */
113 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
114 CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,BRK, UP, NO, BSPC, \
115 LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \
116 LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,FN1, \
117 LGUI,LALT, SPC, RALT,FN7),
118
119 /* Layer 2: Vi mode (Slash)
120 * ,-----------------------------------------------------------.
121 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
122 * |-----------------------------------------------------------|
123 * |Tab |Hom|PgD|Up |PgU|End|Hom|PgD|PgUlEnd| | | |Backs|
124 * |-----------------------------------------------------------|
125 * |Contro| |Lef|Dow|Rig| |Lef|Dow|Up |Rig| | |Return |
126 * |-----------------------------------------------------------|
127 * |Shift | | | | | |Hom|PgD|PgUlEnd|xxx|Shift | |
128 * `-----------------------------------------------------------'
129 * |Gui|Alt |Space |Alt |Gui|
130 * `-------------------------------------------'
131 */
132 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
133 TAB, HOME,PGDN,UP, PGUP,END, HOME,PGDN,PGUP,END, NO, NO, NO, BSPC, \
134 LCTL,NO, LEFT,DOWN,RGHT,NO, LEFT,DOWN,UP, RGHT,NO, NO, ENT, \
135 LSFT,NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, FN2, RSFT,NO, \
136 LGUI,LALT, SPC, RALT,RGUI),
137
138 /* Layer 3: Mouse mode (Semicolon)
139 * ,-----------------------------------------------------------.
140 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
141 * |-----------------------------------------------------------|
142 * |Tab |MwL|MwU|McU|MwD|MwR|MwL|MwD|MwU|MwR| | | |Backs|
143 * |-----------------------------------------------------------|
144 * |Contro| |McL|McD|McR| |McL|McD|McU|McR|xxx| |Return |
145 * |-----------------------------------------------------------|
146 * |Shift |Mb4|Mb5|Mb1|Mb2|Mb3|Mb2|Mb1|Mb4|Mb5| |Shift | |
147 * `-----------------------------------------------------------'
148 * |Gui |Alt |Mb1 |Alt |Gui|
149 * `--------------------------------------------'
150 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
151 */
152#ifdef HOST_IWRAP
153// iWRAP does not support mouse wheel, use these keycodes to remap as wheel
154#define KB_KPPL KB_KP_PLUS
155#define KB_KPMI KB_KP_MINUS
156#define KB_KPAS KB_KP_ASTERISK
157#define KB_KPSL KB_KP_SLASH
158 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
159 TAB, KPAS,KPPL,MS_U,KPMI,KPSL,KPAS,KPPL,KPMI,KPSL,NO, NO, NO, BSPC, \
160 LCTL,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN3, NO, ENT, \
161 LSFT,BTN4,BTN5,BTN1,BTN2,BTN3,BTN2,BTN1,NO, NO, NO, RSFT,NO, \
162 LGUI,LALT, BTN1, RALT,FN4),
163#else
164 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
165 TAB, WH_L,WH_U,MS_U,WH_D,WH_R,WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSPC, \
166 LCTL,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN3, NO, ENT, \
167 LSFT,BTN4,BTN5,BTN1,BTN2,BTN3,BTN2,BTN1,BTN4,BTN5,NO, RSFT,NO, \
168 LGUI,LALT, BTN1, RALT,FN4),
169#endif
170
171 /* Layer 4: Matias half keyboard style (Space)
172 * ,-----------------------------------------------------------.
173 * | -| 0| 9| 8| 7| 6| 5| 4| 3| 2| 1| | | |Esc|
174 * |-----------------------------------------------------------|
175 * |Backs| P| O| I| U| Y| T| R| E| W| Q| | |Tab |
176 * |-----------------------------------------------------------|
177 * |Contro| ;| L| K| J| H| G| F| D| S| A|Con|Control |
178 * |-----------------------------------------------------------|
179 * |Shift | /| .| ,| M| N| B| V| C| X| Z|Shift | |
180 * `-----------------------------------------------------------'
181 * |Gui |Alt |xxxxxxxxxxxxxxxxxxxxxxx|Alt |Gui|
182 * `--------------------------------------------'
183 */
184/*
185 KEYMAP(MINS,0, 9, 8, 7, 6, 5, 4, 3, 2, 1, NO, NO, NO, ESC, \
186 BSPC,P, O, I, U, Y, T, R, E, W, Q, NO, NO, TAB, \
187 LCTL,SCLN,L, K, J, H, G, F, D, S, A, RCTL,RCTL, \
188 LSFT,SLSH,DOT, COMM,M, N, B, V, C, X, Z, RSFT,NO, \
189 LGUI,LALT, FN5, RALT,RGUI)
190*/
191 /* Mouse mode (Space) */
192#ifdef HOST_IWRAP
193 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
194 TAB, KPAS,KPPL,MS_U,KPMI,KPSL,KPAS,KPPL,KPMI,KPSL,NO, NO, NO, BSPC, \
195 LCTL,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN3, NO, ENT, \
196 LSFT,BTN4,BTN5,BTN1,BTN2,BTN3,BTN2,BTN1,BTN4,BTN5,NO, RSFT,NO, \
197 LGUI,LALT, FN5, RALT,RGUI),
198#else
199 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
200 TAB, WH_L,WH_U,MS_U,WH_D,WH_R,WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSPC, \
201 LCTL,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN3, NO, ENT, \
202 LSFT,BTN4,BTN5,BTN1,BTN2,BTN3,BTN2,BTN1,BTN4,BTN5,NO, RSFT,NO, \
203 LGUI,LALT, FN5, RALT,RGUI),
204#endif
205};
206
207
208uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col)
209{
210 return KEYCODE(layer, row, col);
211}
212
213uint8_t keymap_fn_layer(uint8_t fn_bits)
214{
215 return pgm_read_byte(&fn_layer[biton(fn_bits)]);
216}
217
218uint8_t keymap_fn_keycode(uint8_t fn_bits)
219{
220 return pgm_read_byte(&fn_keycode[(biton(fn_bits))]);
221}
diff --git a/keyboard/hhkb/led.c b/keyboard/hhkb/led.c
new file mode 100644
index 000000000..669b6107f
--- /dev/null
+++ b/keyboard/hhkb/led.c
@@ -0,0 +1,26 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "stdint.h"
19#include "led.h"
20
21
22/* HHKB has no LEDs */
23void led_set(uint8_t usb_led)
24{
25}
26
diff --git a/keyboard/hhkb/matrix.c b/keyboard/hhkb/matrix.c
new file mode 100644
index 000000000..350066b90
--- /dev/null
+++ b/keyboard/hhkb/matrix.c
@@ -0,0 +1,294 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18/*
19 * scan matrix
20 */
21#include <stdint.h>
22#include <stdbool.h>
23#include <avr/io.h>
24#include <avr/interrupt.h>
25#include <util/delay.h>
26#include "print.h"
27#include "util.h"
28#include "timer.h"
29#include "matrix.h"
30
31
32// Timer resolution check
33#if (1000000/TIMER_RAW_FREQ > 20)
34# error "Timer resolution(>20us) is not enough for HHKB matrix scan tweak on V-USB."
35#endif
36
37#if (MATRIX_COLS > 16)
38# error "MATRIX_COLS must not exceed 16"
39#endif
40#if (MATRIX_ROWS > 255)
41# error "MATRIX_ROWS must not exceed 255"
42#endif
43
44
45// matrix state buffer(1:on, 0:off)
46#if (MATRIX_COLS <= 8)
47static uint8_t *matrix;
48static uint8_t *matrix_prev;
49static uint8_t _matrix0[MATRIX_ROWS];
50static uint8_t _matrix1[MATRIX_ROWS];
51#else
52static uint16_t *matrix;
53static uint16_t *matrix_prev;
54static uint16_t _matrix0[MATRIX_ROWS];
55static uint16_t _matrix1[MATRIX_ROWS];
56#endif
57
58// HHKB has no ghost and no bounce.
59#ifdef MATRIX_HAS_GHOST
60static bool matrix_has_ghost_in_row(uint8_t row);
61#endif
62
63
64// Matrix I/O ports
65//
66// row: HC4051[A,B,C] selects scan row0-7
67// col: LS145[A,B,C,D] selects scan col0-7 and enable(D)
68// key: on: 0/off: 1
69// prev: unknown: output previous key state(negated)?
70
71#ifdef HOST_PJRC
72// Ports for Teensy
73// row: PB0-2
74// col: PB3-5,6
75// key: PE6(pull-uped)
76// prev: PE7
77#define KEY_INIT() do { \
78 DDRB |= 0x7F; \
79 DDRE |= (1<<7); \
80 DDRE &= ~(1<<6); \
81 PORTE |= (1<<6); \
82} while (0)
83#define KEY_SELECT(ROW, COL) (PORTB = (PORTB & 0xC0) | \
84 (((COL) & 0x07)<<3) | \
85 ((ROW) & 0x07))
86#define KEY_ENABLE() (PORTB &= ~(1<<6))
87#define KEY_UNABLE() (PORTB |= (1<<6))
88#define KEY_STATE() (PINE & (1<<6))
89#define KEY_PREV_ON() (PORTE |= (1<<7))
90#define KEY_PREV_OFF() (PORTE &= ~(1<<7))
91#define KEY_POWER_ON()
92#define KEY_POWER_OFF()
93#else
94// Ports for V-USB
95// key: PB0(pull-uped)
96// prev: PB1
97// row: PB2-4
98// col: PC0-2,3
99// power: PB5(Low:on/Hi-z:off)
100#define KEY_INIT() do { \
101 DDRB |= 0x3E; \
102 DDRB &= ~(1<<0); \
103 PORTB |= 1<<0; \
104 DDRC |= 0x0F; \
105 KEY_UNABLE(); \
106 KEY_PREV_OFF(); \
107} while (0)
108#define KEY_SELECT(ROW, COL) do { \
109 PORTB = (PORTB & 0xE3) | ((ROW) & 0x07)<<2; \
110 PORTC = (PORTC & 0xF8) | ((COL) & 0x07); \
111} while (0)
112#define KEY_ENABLE() (PORTC &= ~(1<<3))
113#define KEY_UNABLE() (PORTC |= (1<<3))
114#define KEY_STATE() (PINB & (1<<0))
115#define KEY_PREV_ON() (PORTB |= (1<<1))
116#define KEY_PREV_OFF() (PORTB &= ~(1<<1))
117// Power supply switching
118#define KEY_POWER_ON() do { \
119 KEY_INIT(); \
120 PORTB &= ~(1<<5); \
121 _delay_us(200); \
122} while (0)
123#define KEY_POWER_OFF() do { \
124 DDRB &= ~0x3F; \
125 PORTB &= ~0x3F; \
126 DDRC &= ~0x0F; \
127 PORTC &= ~0x0F; \
128} while (0)
129#endif
130
131
132inline
133uint8_t matrix_rows(void)
134{
135 return MATRIX_ROWS;
136}
137
138inline
139uint8_t matrix_cols(void)
140{
141 return MATRIX_COLS;
142}
143
144void matrix_init(void)
145{
146 KEY_INIT();
147
148 // initialize matrix state: all keys off
149 for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00;
150 for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00;
151 matrix = _matrix0;
152 matrix_prev = _matrix1;
153}
154
155uint8_t matrix_scan(void)
156{
157 uint8_t *tmp;
158
159 tmp = matrix_prev;
160 matrix_prev = matrix;
161 matrix = tmp;
162
163 KEY_POWER_ON();
164 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
165 for (uint8_t col = 0; col < MATRIX_COLS; col++) {
166 KEY_SELECT(row, col);
167 _delay_us(40);
168
169 // Not sure this is needed. This just emulates HHKB controller's behaviour.
170 if (matrix_prev[row] & (1<<col)) {
171 KEY_PREV_ON();
172 }
173 _delay_us(7);
174
175 // NOTE: KEY_STATE is valid only in 20us after KEY_ENABLE.
176 // If V-USB interrupts in this section we could lose 40us or so
177 // and would read invalid value from KEY_STATE.
178 uint8_t last = TIMER_RAW;
179
180 KEY_ENABLE();
181 // Wait for KEY_STATE outputs its value.
182 // 1us was ok on one HHKB, but not worked on another.
183 _delay_us(10);
184 if (KEY_STATE()) {
185 matrix[row] &= ~(1<<col);
186 } else {
187 matrix[row] |= (1<<col);
188 }
189
190 // Ignore if this code region execution time elapses more than 20us.
191 if (TIMER_DIFF_RAW(TIMER_RAW, last) > 20/(1000000/TIMER_RAW_FREQ)) {
192 matrix[row] = matrix_prev[row];
193 }
194
195 KEY_PREV_OFF();
196 KEY_UNABLE();
197 // NOTE: KEY_STATE keep its state in 20us after KEY_ENABLE.
198 // This takes 25us or more to make sure KEY_STATE returns to idle state.
199 _delay_us(150);
200 }
201 }
202 KEY_POWER_OFF();
203 return 1;
204}
205
206bool matrix_is_modified(void)
207{
208 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
209 if (matrix[i] != matrix_prev[i])
210 return true;
211 }
212 return false;
213}
214
215inline
216bool matrix_has_ghost(void)
217{
218#ifdef MATRIX_HAS_GHOST
219 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
220 if (matrix_has_ghost_in_row(i))
221 return true;
222 }
223#endif
224 return false;
225}
226
227inline
228bool matrix_is_on(uint8_t row, uint8_t col)
229{
230 return (matrix[row] & (1<<col));
231}
232
233inline
234#if (MATRIX_COLS <= 8)
235uint8_t matrix_get_row(uint8_t row)
236#else
237uint16_t matrix_get_row(uint8_t row)
238#endif
239{
240 return matrix[row];
241}
242
243void matrix_print(void)
244{
245#if (MATRIX_COLS <= 8)
246 print("\nr/c 01234567\n");
247#else
248 print("\nr/c 0123456789ABCDEF\n");
249#endif
250 for (uint8_t row = 0; row < matrix_rows(); row++) {
251 phex(row); print(": ");
252#if (MATRIX_COLS <= 8)
253 pbin_reverse(matrix_get_row(row));
254#else
255 pbin_reverse16(matrix_get_row(row));
256#endif
257#ifdef MATRIX_HAS_GHOST
258 if (matrix_has_ghost_in_row(row)) {
259 print(" <ghost");
260 }
261#endif
262 print("\n");
263 }
264}
265
266uint8_t matrix_key_count(void)
267{
268 uint8_t count = 0;
269 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
270#if (MATRIX_COLS <= 8)
271 count += bitpop(matrix[i]);
272#else
273 count += bitpop16(matrix[i]);
274#endif
275 }
276 return count;
277}
278
279#ifdef MATRIX_HAS_GHOST
280inline
281static bool matrix_has_ghost_in_row(uint8_t row)
282{
283 // no ghost exists in case less than 2 keys on
284 if (((matrix[row] - 1) & matrix[row]) == 0)
285 return false;
286
287 // ghost exists in case same state as other row
288 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
289 if (i != row && (matrix[i] & matrix[row]) == matrix[row])
290 return true;
291 }
292 return false;
293}
294#endif
diff --git a/keyboard/hhkb/usbconfig.h b/keyboard/hhkb/usbconfig.h
new file mode 100644
index 000000000..c3aad34be
--- /dev/null
+++ b/keyboard/hhkb/usbconfig.h
@@ -0,0 +1,388 @@
1/* Name: usbconfig.h
2 * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
3 * Author: Christian Starkjohann
4 * Creation Date: 2005-04-01
5 * Tabsize: 4
6 * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 * This Revision: $Id: usbconfig-prototype.h 785 2010-05-30 17:57:07Z cs $
9 */
10
11#ifndef __usbconfig_h_included__
12#define __usbconfig_h_included__
13
14#include "config_vusb.h"
15
16/*
17General Description:
18This file is an example configuration (with inline documentation) for the USB
19driver. It configures V-USB for USB D+ connected to Port D bit 2 (which is
20also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may
21wire the lines to any other port, as long as D+ is also wired to INT0 (or any
22other hardware interrupt, as long as it is the highest level interrupt, see
23section at the end of this file).
24*/
25
26/* ---------------------------- Hardware Config ---------------------------- */
27
28#define USB_CFG_IOPORTNAME D
29/* This is the port where the USB bus is connected. When you configure it to
30 * "B", the registers PORTB, PINB and DDRB will be used.
31 */
32#define USB_CFG_DMINUS_BIT 3
33/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
34 * This may be any bit in the port.
35 */
36#define USB_CFG_DPLUS_BIT 2
37/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
38 * This may be any bit in the port. Please note that D+ must also be connected
39 * to interrupt pin INT0! [You can also use other interrupts, see section
40 * "Optional MCU Description" below, or you can connect D- to the interrupt, as
41 * it is required if you use the USB_COUNT_SOF feature. If you use D- for the
42 * interrupt, the USB interrupt will also be triggered at Start-Of-Frame
43 * markers every millisecond.]
44 */
45#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
46/* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000,
47 * 16500, 18000 and 20000. The 12.8 MHz and 16.5 MHz versions of the code
48 * require no crystal, they tolerate +/- 1% deviation from the nominal
49 * frequency. All other rates require a precision of 2000 ppm and thus a
50 * crystal!
51 * Since F_CPU should be defined to your actual clock rate anyway, you should
52 * not need to modify this setting.
53 */
54#define USB_CFG_CHECK_CRC 0
55/* Define this to 1 if you want that the driver checks integrity of incoming
56 * data packets (CRC checks). CRC checks cost quite a bit of code size and are
57 * currently only available for 18 MHz crystal clock. You must choose
58 * USB_CFG_CLOCK_KHZ = 18000 if you enable this option.
59 */
60
61/* ----------------------- Optional Hardware Config ------------------------ */
62
63/* #define USB_CFG_PULLUP_IOPORTNAME D */
64/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
65 * V+, you can connect and disconnect the device from firmware by calling
66 * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
67 * This constant defines the port on which the pullup resistor is connected.
68 */
69/* #define USB_CFG_PULLUP_BIT 4 */
70/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
71 * above) where the 1.5k pullup resistor is connected. See description
72 * above for details.
73 */
74
75/* --------------------------- Functional Range ---------------------------- */
76
77#define USB_CFG_HAVE_INTRIN_ENDPOINT 1
78/* Define this to 1 if you want to compile a version with two endpoints: The
79 * default control endpoint 0 and an interrupt-in endpoint (any other endpoint
80 * number).
81 */
82#define USB_CFG_HAVE_INTRIN_ENDPOINT3 1
83/* Define this to 1 if you want to compile a version with three endpoints: The
84 * default control endpoint 0, an interrupt-in endpoint 3 (or the number
85 * configured below) and a catch-all default interrupt-in endpoint as above.
86 * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature.
87 */
88#define USB_CFG_EP3_NUMBER 3
89/* If the so-called endpoint 3 is used, it can now be configured to any other
90 * endpoint number (except 0) with this macro. Default if undefined is 3.
91 */
92/* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */
93/* The above macro defines the startup condition for data toggling on the
94 * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1.
95 * Since the token is toggled BEFORE sending any data, the first packet is
96 * sent with the oposite value of this configuration!
97 */
98#define USB_CFG_IMPLEMENT_HALT 0
99/* Define this to 1 if you also want to implement the ENDPOINT_HALT feature
100 * for endpoint 1 (interrupt endpoint). Although you may not need this feature,
101 * it is required by the standard. We have made it a config option because it
102 * bloats the code considerably.
103 */
104#define USB_CFG_SUPPRESS_INTR_CODE 0
105/* Define this to 1 if you want to declare interrupt-in endpoints, but don't
106 * want to send any data over them. If this macro is defined to 1, functions
107 * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if
108 * you need the interrupt-in endpoints in order to comply to an interface
109 * (e.g. HID), but never want to send any data. This option saves a couple
110 * of bytes in flash memory and the transmit buffers in RAM.
111 */
112#define USB_CFG_INTR_POLL_INTERVAL 10
113/* If you compile a version with endpoint 1 (interrupt-in), this is the poll
114 * interval. The value is in milliseconds and must not be less than 10 ms for
115 * low speed devices.
116 */
117#define USB_CFG_IS_SELF_POWERED 0
118/* Define this to 1 if the device has its own power supply. Set it to 0 if the
119 * device is powered from the USB bus.
120 */
121#define USB_CFG_MAX_BUS_POWER 100
122/* Set this variable to the maximum USB bus power consumption of your device.
123 * The value is in milliamperes. [It will be divided by two since USB
124 * communicates power requirements in units of 2 mA.]
125 */
126#define USB_CFG_IMPLEMENT_FN_WRITE 1
127/* Set this to 1 if you want usbFunctionWrite() to be called for control-out
128 * transfers. Set it to 0 if you don't need it and want to save a couple of
129 * bytes.
130 */
131#define USB_CFG_IMPLEMENT_FN_READ 0
132/* Set this to 1 if you need to send control replies which are generated
133 * "on the fly" when usbFunctionRead() is called. If you only want to send
134 * data from a static buffer, set it to 0 and return the data from
135 * usbFunctionSetup(). This saves a couple of bytes.
136 */
137#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0
138/* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints.
139 * You must implement the function usbFunctionWriteOut() which receives all
140 * interrupt/bulk data sent to any endpoint other than 0. The endpoint number
141 * can be found in 'usbRxToken'.
142 */
143#define USB_CFG_HAVE_FLOWCONTROL 0
144/* Define this to 1 if you want flowcontrol over USB data. See the definition
145 * of the macros usbDisableAllRequests() and usbEnableAllRequests() in
146 * usbdrv.h.
147 */
148#define USB_CFG_DRIVER_FLASH_PAGE 0
149/* If the device has more than 64 kBytes of flash, define this to the 64 k page
150 * where the driver's constants (descriptors) are located. Or in other words:
151 * Define this to 1 for boot loaders on the ATMega128.
152 */
153#define USB_CFG_LONG_TRANSFERS 0
154/* Define this to 1 if you want to send/receive blocks of more than 254 bytes
155 * in a single control-in or control-out transfer. Note that the capability
156 * for long transfers increases the driver size.
157 */
158/* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */
159/* This macro is a hook if you want to do unconventional things. If it is
160 * defined, it's inserted at the beginning of received message processing.
161 * If you eat the received message and don't want default processing to
162 * proceed, do a return after doing your things. One possible application
163 * (besides debugging) is to flash a status LED on each packet.
164 */
165/* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */
166/* This macro is a hook if you need to know when an USB RESET occurs. It has
167 * one parameter which distinguishes between the start of RESET state and its
168 * end.
169 */
170/* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */
171/* This macro (if defined) is executed when a USB SET_ADDRESS request was
172 * received.
173 */
174#define USB_COUNT_SOF 1
175/* define this macro to 1 if you need the global variable "usbSofCount" which
176 * counts SOF packets. This feature requires that the hardware interrupt is
177 * connected to D- instead of D+.
178 */
179/* #ifdef __ASSEMBLER__
180 * macro myAssemblerMacro
181 * in YL, TCNT0
182 * sts timer0Snapshot, YL
183 * endm
184 * #endif
185 * #define USB_SOF_HOOK myAssemblerMacro
186 * This macro (if defined) is executed in the assembler module when a
187 * Start Of Frame condition is detected. It is recommended to define it to
188 * the name of an assembler macro which is defined here as well so that more
189 * than one assembler instruction can be used. The macro may use the register
190 * YL and modify SREG. If it lasts longer than a couple of cycles, USB messages
191 * immediately after an SOF pulse may be lost and must be retried by the host.
192 * What can you do with this hook? Since the SOF signal occurs exactly every
193 * 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in
194 * designs running on the internal RC oscillator.
195 * Please note that Start Of Frame detection works only if D- is wired to the
196 * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES!
197 */
198#define USB_CFG_CHECK_DATA_TOGGLING 0
199/* define this macro to 1 if you want to filter out duplicate data packets
200 * sent by the host. Duplicates occur only as a consequence of communication
201 * errors, when the host does not receive an ACK. Please note that you need to
202 * implement the filtering yourself in usbFunctionWriteOut() and
203 * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable
204 * for each control- and out-endpoint to check for duplicate packets.
205 */
206#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0
207/* define this macro to 1 if you want the function usbMeasureFrameLength()
208 * compiled in. This function can be used to calibrate the AVR's RC oscillator.
209 */
210#define USB_USE_FAST_CRC 0
211/* The assembler module has two implementations for the CRC algorithm. One is
212 * faster, the other is smaller. This CRC routine is only used for transmitted
213 * messages where timing is not critical. The faster routine needs 31 cycles
214 * per byte while the smaller one needs 61 to 69 cycles. The faster routine
215 * may be worth the 32 bytes bigger code size if you transmit lots of data and
216 * run the AVR close to its limit.
217 */
218
219/* -------------------------- Device Description --------------------------- */
220
221#define USB_CFG_VENDOR_ID (VENDOR_ID & 0xFF), ((VENDOR_ID >> 8) & 0xFF)
222/* USB vendor ID for the device, low byte first. If you have registered your
223 * own Vendor ID, define it here. Otherwise you may use one of obdev's free
224 * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules!
225 * *** IMPORTANT NOTE ***
226 * This template uses obdev's shared VID/PID pair for Vendor Class devices
227 * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand
228 * the implications!
229 */
230#define USB_CFG_DEVICE_ID (PRODUCT_ID & 0xFF), ((PRODUCT_ID >> 8) & 0xFF)
231/* This is the ID of the product, low byte first. It is interpreted in the
232 * scope of the vendor ID. If you have registered your own VID with usb.org
233 * or if you have licensed a PID from somebody else, define it here. Otherwise
234 * you may use one of obdev's free shared VID/PID pairs. See the file
235 * USB-IDs-for-free.txt for details!
236 * *** IMPORTANT NOTE ***
237 * This template uses obdev's shared VID/PID pair for Vendor Class devices
238 * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand
239 * the implications!
240 */
241#define USB_CFG_DEVICE_VERSION 0x00, 0x01
242/* Version number of the device: Minor number first, then major number.
243 */
244#define USB_CFG_VENDOR_NAME 't', '.', 'm', '.', 'k', '.'
245#define USB_CFG_VENDOR_NAME_LEN 6
246/* These two values define the vendor name returned by the USB device. The name
247 * must be given as a list of characters under single quotes. The characters
248 * are interpreted as Unicode (UTF-16) entities.
249 * If you don't want a vendor name string, undefine these macros.
250 * ALWAYS define a vendor name containing your Internet domain name if you use
251 * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for
252 * details.
253 */
254#define USB_CFG_DEVICE_NAME 'H', 'H', 'K', 'B', ' ', 'm', 'o', 'd'
255#define USB_CFG_DEVICE_NAME_LEN 8
256/* Same as above for the device name. If you don't want a device name, undefine
257 * the macros. See the file USB-IDs-for-free.txt before you assign a name if
258 * you use a shared VID/PID.
259 */
260/*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */
261/*#define USB_CFG_SERIAL_NUMBER_LEN 0 */
262/* Same as above for the serial number. If you don't want a serial number,
263 * undefine the macros.
264 * It may be useful to provide the serial number through other means than at
265 * compile time. See the section about descriptor properties below for how
266 * to fine tune control over USB descriptors such as the string descriptor
267 * for the serial number.
268 */
269#define USB_CFG_DEVICE_CLASS 0
270#define USB_CFG_DEVICE_SUBCLASS 0
271/* See USB specification if you want to conform to an existing device class.
272 * Class 0xff is "vendor specific".
273 */
274#define USB_CFG_INTERFACE_CLASS 3 /* HID */
275#define USB_CFG_INTERFACE_SUBCLASS 1 /* Boot */
276#define USB_CFG_INTERFACE_PROTOCOL 1 /* Keyboard */
277/* See USB specification if you want to conform to an existing device class or
278 * protocol. The following classes must be set at interface level:
279 * HID class is 3, no subclass and protocol required (but may be useful!)
280 * CDC class is 2, use subclass 2 and protocol 1 for ACM
281 */
282#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 0
283/* Define this to the length of the HID report descriptor, if you implement
284 * an HID device. Otherwise don't define it or define it to 0.
285 * If you use this define, you must add a PROGMEM character array named
286 * "usbHidReportDescriptor" to your code which contains the report descriptor.
287 * Don't forget to keep the array and this define in sync!
288 */
289
290/* #define USB_PUBLIC static */
291/* Use the define above if you #include usbdrv.c instead of linking against it.
292 * This technique saves a couple of bytes in flash memory.
293 */
294
295/* ------------------- Fine Control over USB Descriptors ------------------- */
296/* If you don't want to use the driver's default USB descriptors, you can
297 * provide our own. These can be provided as (1) fixed length static data in
298 * flash memory, (2) fixed length static data in RAM or (3) dynamically at
299 * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more
300 * information about this function.
301 * Descriptor handling is configured through the descriptor's properties. If
302 * no properties are defined or if they are 0, the default descriptor is used.
303 * Possible properties are:
304 * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched
305 * at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is
306 * used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if
307 * you want RAM pointers.
308 * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found
309 * in static memory is in RAM, not in flash memory.
310 * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash),
311 * the driver must know the descriptor's length. The descriptor itself is
312 * found at the address of a well known identifier (see below).
313 * List of static descriptor names (must be declared PROGMEM if in flash):
314 * char usbDescriptorDevice[];
315 * char usbDescriptorConfiguration[];
316 * char usbDescriptorHidReport[];
317 * char usbDescriptorString0[];
318 * int usbDescriptorStringVendor[];
319 * int usbDescriptorStringDevice[];
320 * int usbDescriptorStringSerialNumber[];
321 * Other descriptors can't be provided statically, they must be provided
322 * dynamically at runtime.
323 *
324 * Descriptor properties are or-ed or added together, e.g.:
325 * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18))
326 *
327 * The following descriptors are defined:
328 * USB_CFG_DESCR_PROPS_DEVICE
329 * USB_CFG_DESCR_PROPS_CONFIGURATION
330 * USB_CFG_DESCR_PROPS_STRINGS
331 * USB_CFG_DESCR_PROPS_STRING_0
332 * USB_CFG_DESCR_PROPS_STRING_VENDOR
333 * USB_CFG_DESCR_PROPS_STRING_PRODUCT
334 * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER
335 * USB_CFG_DESCR_PROPS_HID
336 * USB_CFG_DESCR_PROPS_HID_REPORT
337 * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver)
338 *
339 * Note about string descriptors: String descriptors are not just strings, they
340 * are Unicode strings prefixed with a 2 byte header. Example:
341 * int serialNumberDescriptor[] = {
342 * USB_STRING_DESCRIPTOR_HEADER(6),
343 * 'S', 'e', 'r', 'i', 'a', 'l'
344 * };
345 */
346
347#define USB_CFG_DESCR_PROPS_DEVICE 0
348#define USB_CFG_DESCR_PROPS_CONFIGURATION USB_PROP_IS_DYNAMIC
349//#define USB_CFG_DESCR_PROPS_CONFIGURATION 0
350#define USB_CFG_DESCR_PROPS_STRINGS 0
351#define USB_CFG_DESCR_PROPS_STRING_0 0
352#define USB_CFG_DESCR_PROPS_STRING_VENDOR 0
353#define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0
354#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0
355#define USB_CFG_DESCR_PROPS_HID USB_PROP_IS_DYNAMIC
356//#define USB_CFG_DESCR_PROPS_HID 0
357#define USB_CFG_DESCR_PROPS_HID_REPORT USB_PROP_IS_DYNAMIC
358//#define USB_CFG_DESCR_PROPS_HID_REPORT 0
359#define USB_CFG_DESCR_PROPS_UNKNOWN 0
360
361/* ----------------------- Optional MCU Description ------------------------ */
362
363/* The following configurations have working defaults in usbdrv.h. You
364 * usually don't need to set them explicitly. Only if you want to run
365 * the driver on a device which is not yet supported or with a compiler
366 * which is not fully supported (such as IAR C) or if you use a differnt
367 * interrupt than INT0, you may have to define some of these.
368 */
369/* #define USB_INTR_CFG MCUCR */
370/* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */
371/* #define USB_INTR_CFG_CLR 0 */
372/* #define USB_INTR_ENABLE GIMSK */
373/* #define USB_INTR_ENABLE_BIT INT0 */
374/* #define USB_INTR_PENDING GIFR */
375/* #define USB_INTR_PENDING_BIT INTF0 */
376/* #define USB_INTR_VECTOR INT0_vect */
377
378/* Set INT1 for D- falling edge to count SOF */
379/* #define USB_INTR_CFG EICRA */
380#define USB_INTR_CFG_SET ((1 << ISC11) | (0 << ISC10))
381/* #define USB_INTR_CFG_CLR 0 */
382/* #define USB_INTR_ENABLE EIMSK */
383#define USB_INTR_ENABLE_BIT INT1
384/* #define USB_INTR_PENDING EIFR */
385#define USB_INTR_PENDING_BIT INTF1
386#define USB_INTR_VECTOR INT1_vect
387
388#endif /* __usbconfig_h_included__ */