aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-07-11 16:26:00 +0900
committertmk <nobody@nowhere>2013-07-11 16:26:00 +0900
commitf4c69652c17e97241e2f7b7f22ab438e9a3ceb0a (patch)
tree7aeff8936604b5601317236f6d31bdac8565d713
parent292dbd51cc6967d1b98f29b29580f96535ae3ec7 (diff)
parentd2ea9e80a07ced7c2b6a420ad2bd43a8c6220eac (diff)
downloadqmk_firmware-f4c69652c17e97241e2f7b7f22ab438e9a3ceb0a.tar.gz
qmk_firmware-f4c69652c17e97241e2f7b7f22ab438e9a3ceb0a.zip
Merge branch 'hhkb_tmk'
-rw-r--r--keyboard/hhkb/Makefile.tmk129
-rw-r--r--keyboard/hhkb/README.md162
-rw-r--r--keyboard/hhkb/config.h2
-rw-r--r--keyboard/hhkb/doc/HHKB.txt36
-rw-r--r--keyboard/hhkb/doc/Power.txt48
-rw-r--r--keyboard/hhkb/led.c9
-rw-r--r--keyboard/hhkb/matrix.c61
7 files changed, 355 insertions, 92 deletions
diff --git a/keyboard/hhkb/Makefile.tmk b/keyboard/hhkb/Makefile.tmk
new file mode 100644
index 000000000..d3730081f
--- /dev/null
+++ b/keyboard/hhkb/Makefile.tmk
@@ -0,0 +1,129 @@
1#----------------------------------------------------------------------------
2# On command line:
3#
4# make all = Make software.
5#
6# make clean = Clean out built project files.
7#
8# make coff = Convert ELF to AVR COFF.
9#
10# make extcoff = Convert ELF to AVR Extended COFF.
11#
12# make program = Download the hex file to the device.
13# Please customize your programmer settings(PROGRAM_CMD)
14#
15# make teensy = Download the hex file to the device, using teensy_loader_cli.
16# (must have teensy_loader_cli installed).
17#
18# make dfu = Download the hex file to the device, using dfu-programmer (must
19# have dfu-programmer installed).
20#
21# make flip = Download the hex file to the device, using Atmel FLIP (must
22# have Atmel FLIP installed).
23#
24# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
25# (must have dfu-programmer installed).
26#
27# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
28# (must have Atmel FLIP installed).
29#
30# make debug = Start either simulavr or avarice as specified for debugging,
31# with avr-gdb or avr-insight as the front end for debugging.
32#
33# make filename.s = Just compile filename.c into the assembler code only.
34#
35# make filename.i = Create a preprocessed source file for use in submitting
36# bug reports to the GCC project.
37#
38# To rebuild project do "make clean" then "make all".
39#----------------------------------------------------------------------------
40
41# Target file name (without extension).
42TARGET = hhkb_tmk
43
44# Directory common source filess exist
45TOP_DIR = ../..
46
47# Directory keyboard dependent files exist
48TARGET_DIR = .
49
50
51# List C source files here. (C dependencies are automatically generated.)
52SRC += keymap.c \
53 matrix.c \
54 led.c
55
56CONFIG_H = config.h
57
58
59# MCU name
60#MCU = at90usb1286
61MCU = atmega32u4
62
63# Processor frequency.
64# This will define a symbol, F_CPU, in all source code files equal to the
65# processor frequency in Hz. You can then use this symbol in your source code to
66# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
67# automatically to create a 32-bit value in your source code.
68#
69# This will be an integer division of F_USB below, as it is sourced by
70# F_USB after it has run through any CPU prescalers. Note that this value
71# does not *change* the processor frequency - it should merely be updated to
72# reflect the processor speed set externally so that the code can use accurate
73# software delays.
74F_CPU = 16000000
75
76
77#
78# LUFA specific
79#
80# Target architecture (see library "Board Types" documentation).
81ARCH = AVR8
82
83# Input clock frequency.
84# This will define a symbol, F_USB, in all source code files equal to the
85# input clock frequency (before any prescaling is performed) in Hz. This value may
86# differ from F_CPU if prescaling is used on the latter, and is required as the
87# raw input clock is fed directly to the PLL sections of the AVR for high speed
88# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
89# at the end, this will be done automatically to create a 32-bit value in your
90# source code.
91#
92# If no clock division is performed on the input clock inside the AVR (via the
93# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
94F_USB = $(F_CPU)
95
96# Interrupt driven control endpoint task
97OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
98
99
100# Boot Section Size in *bytes*
101# Teensy halfKay 512
102# Teensy++ halfKay 1024
103# Atmel DFU loader 4096
104# LUFA bootloader 4096
105# USBaspLoader 2048
106OPT_DEFS += -DBOOTLOADER_SIZE=4096
107
108
109# Build Options
110# comment out to disable the options.
111#
112#BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration
113MOUSEKEY_ENABLE = yes # Mouse keys
114EXTRAKEY_ENABLE = yes # Audio control and System control
115CONSOLE_ENABLE = yes # Console for debug
116COMMAND_ENABLE = yes # Commands for debug and configuration
117#NKRO_ENABLE = yes # USB Nkey Rollover
118
119
120# Search Path
121VPATH += $(TARGET_DIR)
122VPATH += $(TOP_DIR)
123
124include $(TOP_DIR)/protocol/lufa.mk
125include $(TOP_DIR)/common.mk
126include $(TOP_DIR)/rules.mk
127
128debug-on: EXTRAFLAGS += -DDEBUG
129debug-on: all
diff --git a/keyboard/hhkb/README.md b/keyboard/hhkb/README.md
index f7e96126b..b9e0b534a 100644
--- a/keyboard/hhkb/README.md
+++ b/keyboard/hhkb/README.md
@@ -2,128 +2,144 @@ Alternative Controller for HHKB Pro
2=================================== 2===================================
3I wanted to add some features like vi cursor and mouse keys to my [HHKB][HHKB] but its controller is not programmable and 3I wanted to add some features like vi cursor and mouse keys to my [HHKB][HHKB] but its controller is not programmable and
4firmware source code is not open, of course. This means customizing this keyboard needs to replace original 4firmware source code is not open, of course. This means customizing this keyboard needs to replace original
5controller with programmable one. For this purpose I used PJRC [Teensy++][Teensy] as alternative controller. 5controller with programmable one. This controller can work with HHKB Professional and Professional 2 model.
6
7See [this thread][AltController] in geekhack.org.
6 8
7[HHKB]: http://www.pfu.fujitsu.com/hhkeyboard/ 9[HHKB]: http://www.pfu.fujitsu.com/hhkeyboard/
10[AltController]: http://geekhack.org/index.php?topic=12047.0
8[Teensy]: http://www.pjrc.com/teensy/ 11[Teensy]: http://www.pjrc.com/teensy/
9 12
10 13
11My keyboard firmware source tree is here: http://github.com/tmk/tmk_keyboard
12See directory keyboard/hhkb to build firmware for HHKB.
13
14
15##Features 14##Features
16* Customizable keymap 15* Customizable keymap
17* More keymap layers(more Fn keys) 16* More keymap layers(more Fn keys)
18* Mouse keys 17* Mouse keys
19* USB NKRO 18* USB NKRO
20 19
20See README of [tmk_keyboard] for more.
21
22[tmk_keyboard]: http://github.com/tmk/tmk_keyboard
23
21###Pros 24###Pros
25* No risk: Everything is all reversible
22* Without PCB trace cutting, case mod or any destructives 26* Without PCB trace cutting, case mod or any destructives
23* Can keep original controller intact 27* Can keep original controller intact
24* Can change all HHKB behaviour as you like 28* Can change all HHKB behaviour as you like
25 29
26###Cons 30###Cons
27* Void your warranty 31* Void your warranty
28* Lose USB hub function in case of Pro2 32* Lose USB hub function of Pro2
29 33
30##DISCLAIMER 34##DISCLAIMER
31I'm not a professional of electronics or MCU programming. This may damage your HHKB. 35I'm not a professional of electronics nor MCU programming. This may damage your HHKB.
32And my English writing is poor, I'm not sure I can convey my notions accurately. 36And my English writing is poor, I'm not sure I can convey my notions accurately.
33 37
34 38
39##Documents
40See [doc/HHKB.txt](doc/HHKB.txt) and files under [doc/](doc/) for internal of HHKB and this controller.
35 41
36 42
43##Build Firmware & Program
44You can choose some combination of hardware and USB protocol stack([LUFA], [PJRC]).
37 45
46### Install Tools
47See [this document](../../doc/build.md).
38 48
39##Build Firmware 49### TMK Alt Controller Board
40You can choose some combination of MCU and USB protocol stack. 50 $ make -f Makefile.tmk
41
42### Teensy++(AVR USB family) with [LUFA]
430. Edit **matrix.c** to use your pin configuration. See doc/HHKB.txt for detail.
44
451. Edit **keymap.c** to use your favoirte keymap.
46
472. Edit **Makefile** if you want to use other `MCU` than Teensy++ 2.0.
48 51
493. Build firmware binary file: 52This programs the controller with [dfu-programmer] if the tool is intalled and configured properly.
50 `$ make -f Makefile.lufa`
51 53
524. Program MCU with PJRC [Teensy Loader] tool. If you install command line version of the loader just run: 54 $ make -f Makefile.tmk dfu
53 `$ make -f Makefile.lufa teensy`
54 55
55[LUFA]: http://www.fourwalledcubicle.com/LUFA.php 56Push reset button and program with [FLIP]. The tool should be intalled and configured properly.
56[Teensy Loader]: http://www.pjrc.com/teensy/loader.html
57 57
58 $ make -f Makefile.tmk flip
58 59
59###AVR Mega with [V-USB] 60Or you can also program with FLIP GUI.
60Follow below if you want to use AVR with V-USB as .
61 61
620. Edit **matrix.c** to use your pin configuration. See doc/HHKB.txt for detail. 62[dfu-programmer]: http://dfu-programmer.sourceforge.net/
63[FLIP]: http://www.atmel.com/tools/FLIP.aspx
63 64
641. Edit **keymap.c** to use your favoirte keymap.
65 65
662. Edit **usbconfig.h** to configure V-USB options. 66### PJRC Teensy++
67Build with [LUFA] USB stack:
67 68
683. Edit **Makefile.vusb** to define `MCU` and `F_CPU`. 69 $ make -f Makefile.lufa
69 70
704. Build firmware binary file: 71or with [PJRC] USB stack:
71 `$ make -f Makefile.vusb`
72 72
735. Program MCU with AVR programmer like AVRISPmkII. If you already have [USBaspLoader] on MCU just run: 73 $ make -f Makefile.pjrc
74 `$ make -f Makefile.vusb program`
75 74
76[V-USB]: http://www.obdev.at/products/vusb/index.html 75Push reset button and program with [Teensy Loader(command line)]. The tool should be intalled and configured properly.
77[USBaspLoader]: http://www.obdev.at/products/vusb/usbasploader.html
78 76
77 $ make -f Makefile.lufa teensy
78 $ make -f Makefile.pjrc teensy
79 79
80###How to Customize Keymap 80Or you can also program with [Teensy Loader(GUI)].
81Later...
82See **keymap.c**.
83 81
82[LUFA]: http://www.fourwalledcubicle.com/LUFA.php
83[PJRC]: http://www.pjrc.com/teensy/usb_keyboard.html
84[Teensy Loader(command line)]: http://www.pjrc.com/teensy/loader_cli.html
85[Teensy Loader(GUI)]: http://www.pjrc.com/teensy/loader.html
84 86
85##Hardware
86 87
87###Teensy++ installation 88###AVR Mega with [V-USB]
88Angled USB mini B adapter is used to install Teensy++ laterally. 89Build:
90 $ make -f Makefile.vusb
89 91
90![Image of Teensy install](hhkb/doc/HHKB_img/teensy_install.jpg) 92Program [USBaspLoader] on MCU with AVR programmer like [AVRISPmkII] and tool like [avrdude].
91 93
92Bread baord wires are used to connect Teensy++. 94You can programs with [avrdude] once you have programmed [USBaspLoader] on MCU.
95 $ make -f Makefile.vusb program
93 96
94![Image of Teensy wiring](hhkb/doc/HHKB_img/teensy_wiring.jpg) 97[AVRISPmkII]: http://www.atmel.com/tools/AVRISPMKII.aspx
98[avrdude]: http://www.nongnu.org/avrdude/
95 99
96![Image of Connector](hhkb/doc/HHKB_img/connector_contact.jpg)
97 100
101##How to Customize
102See [tmk_keyboard] documents.
98 103
99###PJRC Teensy++ 2.0 connection
100 +---------------+
101 | Teensy++ |
102 | |
103 | | HHKB
104 | | ~~~~
105 | PB0-2|------->ROW(6-8)
106 | PB3-5|------->COL(9-11)
107 | PB6|------->ENABLE(12)
108 | PE6|<-------KEY(4)
109 | PE7|------->PREV(5)
110 | |
111 | |
112 | |
113 +---------------+
114 104
105##Hardware
106You have some options for hardware. Development boards with USB AVR family(ATMega32U4, AT90USB1286) like Teensy will work while MegaAVR with V-USB library is also cheapear option for DIY.
107
108###1. TMK Alt Controller Board
109TMK designed [Keyboard Controller Board for HHKB Pro2(KiCad project)](https://github.com/tmk/HHKB_controller).
110See [this post](http://geekhack.org/index.php?topic=12047.msg948923#msg948923).
111
112
113###2. PJRC Teensy++ 2.0 connection
114 +---------------+
115 | Teensy++ |
116 | |
117 | | HHKB pro HHKB pro2
118 | | ~~~~~~~~ ~~~~~~~~~
119 | PB0-2|------->ROW (6-8) (5-7)
120 | PB3-5|------->COL (9-11) (8-10)
121 | PB6|------->ENABLE (12) (11)
122 | PE6|<-------KEY (4) (3)
123 | PE7|------->PREV (5) (4)
124 | |
125 | | 5V--- (1-3) (1-2)
126 | | GND--- (13-14) (12-13)
127 +---------------+
128
129- NOTE: PJRC [Teensy](http://www.pjrc.com/teensy/)
130[Teensy Loader]: http://www.pjrc.com/teensy/loader.html
115 131
116###V-USB circuit 132###3. V-USB connection
117 +---+ +---------------+ 133 +---+ +---------------+
118 USB GND | | ATmega168 | 134 USB GND | | ATmega328p |
119 ~~~ C3 | | 135 ~~~ C3 | |
120 5V <-------+--------+---|Vcc,AVCC | HHKB 136 5V <-------+--------+---|Vcc,AVCC | HHKB pro pro2
121 R1 | | ~~~~ 137 R1 | | ~~~~~~~~ ~~~~
122 D- <----+--+-----R2-----|INT1 PB2-4|------->ROW(6-8) 138 D- <----+--+-----R2-----|INT1 PB2-4|------->ROW (6-8) (5-7)
123 D+ <----|---+----R3-----|INT0 PC0-2|------->COL(9-11) 139 D+ <----|---+----R3-----|INT0 PC0-2|------->COL (9-11) (8-10)
124 Z1 Z2 | PC3|------->ENABLE(12) 140 Z1 Z2 | PC3|------->ENABLE (12) (11)
125 GND<----+---+-----------|GND PB0|<-------KEY(4) 141 GND<----+---+-----------|GND PB0|<-------KEY (4) (3)
126 | PB1|------->PREV(5) 142 | PB1|------->PREV (5) (4)
127 | | 143 | |
128 GND+-C2--+--|XTAL1 RXD|------->Debug Console 144 GND+-C2--+--|XTAL1 RXD|------->Debug Console
129 X1 | TXD|<-------Debug Console 145 X1 | TXD|<-------Debug Console
@@ -134,5 +150,11 @@ Bread baord wires are used to connect Teensy++.
134 Z1,Z2: Zener 3.6V 150 Z1,Z2: Zener 3.6V
135 C1,C2: 22pF 151 C1,C2: 22pF
136 C3: 0.1uF 152 C3: 0.1uF
137 X1: Crystal 20MHz(16MHz/12MHz) 153 X1: Crystal 12MHz
138 SW: Push Switch(Optional for bootloader) 154 SW: Push Switch(for bootloader)
155
156- NOTE: See [V-USB] documentation for more detail of hardware and the USB stack.
157- NOTE: [USBaspLoader] is very useful for firmware update.
158
159[V-USB]: http://www.obdev.at/products/vusb/index.html
160[USBaspLoader]: http://www.obdev.at/products/vusb/usbasploader.html
diff --git a/keyboard/hhkb/config.h b/keyboard/hhkb/config.h
index ec51852c1..613e66d13 100644
--- a/keyboard/hhkb/config.h
+++ b/keyboard/hhkb/config.h
@@ -54,7 +54,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
54#endif 54#endif
55 55
56/* period of tapping(ms) */ 56/* period of tapping(ms) */
57#define TAPPING_TERM 200 57#define TAPPING_TERM 300
58/* tap count needed for toggling a feature */ 58/* tap count needed for toggling a feature */
59#define TAPPING_TOGGLE 5 59#define TAPPING_TOGGLE 5
60 60
diff --git a/keyboard/hhkb/doc/HHKB.txt b/keyboard/hhkb/doc/HHKB.txt
index f99a07443..422c452c9 100644
--- a/keyboard/hhkb/doc/HHKB.txt
+++ b/keyboard/hhkb/doc/HHKB.txt
@@ -30,25 +30,27 @@ Connector Cable
30Two PCBs are connected by 15 lines(13 in case of Pro2). 30Two PCBs are connected by 15 lines(13 in case of Pro2).
31Vcc and GND use 3(2) lines each, other 9 lines are for keyboard signaling. 31Vcc and GND use 3(2) lines each, other 9 lines are for keyboard signaling.
32 32
33 Keyswitch PCB connector Teensy++ pins 33 Keyswitch connector
34 ------------------------------------------------------------------------------- 34 pro pro2 Description Teensy++ pins
35 1 Vcc(5V) Not exist on Pro2 5V 35 --------------------------------------------------------------------------------------------
36 2 Vcc(5V) 5V 36 1 Vcc(5V) Not exist on Pro2 5V
37 3 Vcc(5V) 5V 37 2 1 Vcc(5V) 5V
38 4 TP1684 KEY: Low(0) when key pressed PE6 input(with pullup) 38 3 2 Vcc(5V) 5V
39 5 TP1684 KEY_PREV: assert previous key state??? PE7 output 39 4 3 TP1684 KEY: Low(0) when key pressed PE6 input(with pullup)
40 6 HC4051 A(bit0) select 8 rows(0 to 7) PB0 output 40 5 4 TP1684 KEY_PREV: make threshold PE7 output
41 7 HC4051 B(bit1) PB1 output 41 6 5 HC4051 A(bit0)\ PB0 output
42 8 HC4051 C(bit2) PB2 output 42 7 6 HC4051 B(bit1) > select row(0 to 7) PB1 output
43 9 LS145 A(bit0) select 8 columns(0 to 7) PB3 output 43 8 7 HC4051 C(bit2)/ PB2 output
44 10 LS145 B(bit1) PB4 output 44 9 8 LS145 A(bit0)\ PB3 output
45 11 LS145 C(bit2) PB5 output 45 10 9 LS145 B(bit1) > select column(0 to 7) PB4 output
46 12 LS145 D(enable) Low(0) enable selected column PB6 output 46 11 10 LS145 C(bit2)/ PB5 output
47 13 GND GND 47 12 11 LS145 D(enable) Low(0) enables selected column PB6 output
48 14 GND GND 48 13 12 GND GND
49 15 GND Not exist on Pro2 GND 49 14 13 GND GND
50 15 GND Not exist on Pro2 GND
50 51
51 NOTE: guessing pin5(KEY_PREV) may work for hysteresis of capacitive sensing. 52 NOTE: guessing pin5(KEY_PREV) may work for hysteresis of capacitive sensing.
53 NOTE: 1KOhm didn't work as pullup resistor on KEY. AVR internal pullup or 10KOhm resistor was OK.
52 54
53 (HHKB_connector.jpg) 55 (HHKB_connector.jpg)
54 56
diff --git a/keyboard/hhkb/doc/Power.txt b/keyboard/hhkb/doc/Power.txt
new file mode 100644
index 000000000..1287053c3
--- /dev/null
+++ b/keyboard/hhkb/doc/Power.txt
@@ -0,0 +1,48 @@
1HHKB Power consumption
2----------------------
3
4**Power consumption
5 board clock/prescaler keyswitch power ctrl current
6 --------------------------------------------------------------------------
7 tmk 16MHz no no 26.4mA
8 tmk 16MHz pro1 no 45.1mA
9 tmk 16MHz/2 no no 18.1mA
10 tmk 16MHz/2 pro1 no 37.3mA
11 tmk 8MHz no no 18.9mA
12 tmk 8MHz pro2 no(w/o FET) 32.1mA
13 tmk 8MHz pro2 no(w FET) 32.1mA withou POWER_ON/FF
14 tmk 8MHz pro2 no(w FET) 32.6mA with POWR_ON/OFF
15 tmk 8MHz pro2 15ms(w FET) 21.3mA with POWR_ON/OFF, enumerated but error -32
16 tmk 8MHz pro2 60ms(w FET) 13.3mA with POWR_ON/OFF, not enumerated
17
18 gh60 16MHz 25.8mA
19 gh60 16MHz USB suspend w LED breathing 17.6-29.1mA
20 gh60 16MHz USB suspend w/o LED 0.2mA(0.231-0.276mA)
21 Poker 5.6mA
22 Poker USB suspend 0.3mA(0.301mA)
23 gh60 16MHz stock firmware by komar 26.8mA
24
25
26 HHKB pro2 Over All 139.4mA
27 HHKB pro2 Controller 115.1mA
28 HHKB pro1 Controller 25.9mA
29
30
31keyswitch power consumption:
32pro1: 45.1-26.4=18.7mA
33 37.3-18.1=19.2mA
34pro2: 32.1-18.9=13.2mA
35
36
37
38
39
40**Low Freq Crystal or Prescaler?
41No advantage of Low Freq Crystal against Prescaled.
42
43Clock routing
44X'tal --+---->Prescaler-------> System Clock
45 |
46 +---------------------> USB PLL
47
48Design Decision: Install 16MHz crystal on board with using clock rescaler.
diff --git a/keyboard/hhkb/led.c b/keyboard/hhkb/led.c
index 669b6107f..8a08fe27f 100644
--- a/keyboard/hhkb/led.c
+++ b/keyboard/hhkb/led.c
@@ -15,6 +15,7 @@ You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18#include <avr/io.h>
18#include "stdint.h" 19#include "stdint.h"
19#include "led.h" 20#include "led.h"
20 21
@@ -22,5 +23,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
22/* HHKB has no LEDs */ 23/* HHKB has no LEDs */
23void led_set(uint8_t usb_led) 24void led_set(uint8_t usb_led)
24{ 25{
26 if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
27 DDRD |= (1<<6);
28 PORTD |= (1<<6);
29 } else {
30 DDRD |= (1<<6);
31 PORTD &= ~(1<<6);
32 }
25} 33}
26
diff --git a/keyboard/hhkb/matrix.c b/keyboard/hhkb/matrix.c
index 3d4b1f6c7..d0731ef1f 100644
--- a/keyboard/hhkb/matrix.c
+++ b/keyboard/hhkb/matrix.c
@@ -63,7 +63,7 @@ static matrix_row_t _matrix1[MATRIX_ROWS];
63 PORTE |= (1<<6); \ 63 PORTE |= (1<<6); \
64} while (0) 64} while (0)
65#define KEY_SELECT(ROW, COL) (PORTB = (PORTB & 0xC0) | \ 65#define KEY_SELECT(ROW, COL) (PORTB = (PORTB & 0xC0) | \
66 (((COL) & 0x07)<<3) | \ 66 (((COL) & 0x07)<<3) | \
67 ((ROW) & 0x07)) 67 ((ROW) & 0x07))
68#define KEY_ENABLE() (PORTB &= ~(1<<6)) 68#define KEY_ENABLE() (PORTB &= ~(1<<6))
69#define KEY_UNABLE() (PORTB |= (1<<6)) 69#define KEY_UNABLE() (PORTB |= (1<<6))
@@ -73,6 +73,50 @@ static matrix_row_t _matrix1[MATRIX_ROWS];
73#define KEY_POWER_ON() 73#define KEY_POWER_ON()
74#define KEY_POWER_OFF() 74#define KEY_POWER_OFF()
75 75
76#elif defined(__AVR_ATmega32U4__)
77// Ports for my designed Alt Controller PCB
78// row: PB0-2
79// col: PB3-5,6
80// key: PD7(pull-uped)
81// prev: PB7
82// power: PD4(L:off/H:on)
83#define KEY_INIT() do { \
84 DDRB = 0xFF; \
85 PORTB = 0x00; \
86 DDRD &= ~0x80; \
87 PORTD |= 0x80; \
88 /* keyswitch board power on */ \
89 DDRD |= (1<<4); \
90 PORTD |= (1<<4); \
91 KEY_UNABLE(); \
92 KEY_PREV_OFF(); \
93} while (0)
94#define KEY_SELECT(ROW, COL) (PORTB = (PORTB & 0xC0) | \
95 (((COL) & 0x07)<<3) | \
96 ((ROW) & 0x07))
97#define KEY_ENABLE() (PORTB &= ~(1<<6))
98#define KEY_UNABLE() (PORTB |= (1<<6))
99#define KEY_STATE() (PIND & (1<<7))
100#define KEY_PREV_ON() (PORTB |= (1<<7))
101#define KEY_PREV_OFF() (PORTB &= ~(1<<7))
102#define KEY_POWER_ON()
103#define KEY_POWER_OFF()
104/*
105#define KEY_POWER_ON() do { \
106 KEY_INIT(); \
107 PORTD |= (1<<4); \
108 _delay_ms(1); \
109} while (0)
110#define KEY_POWER_OFF() do { \
111 PORTD &= ~(1<<4); \
112 DDRB &= ~0xFF; \
113 PORTB &= ~0xFF; \
114 DDRB &= ~0x80; \
115 PORTB &= ~0x80; \
116} while (0)
117*/
118
119
76#elif defined(__AVR_ATmega328P__) 120#elif defined(__AVR_ATmega328P__)
77// Ports for V-USB 121// Ports for V-USB
78// key: PB0(pull-uped) 122// key: PB0(pull-uped)
@@ -130,7 +174,6 @@ uint8_t matrix_cols(void)
130void matrix_init(void) 174void matrix_init(void)
131{ 175{
132#ifdef DEBUG 176#ifdef DEBUG
133 print_enable = true;
134 debug_enable = true; 177 debug_enable = true;
135 debug_keyboard = true; 178 debug_keyboard = true;
136#endif 179#endif
@@ -170,9 +213,21 @@ uint8_t matrix_scan(void)
170 uint8_t last = TIMER_RAW; 213 uint8_t last = TIMER_RAW;
171 214
172 KEY_ENABLE(); 215 KEY_ENABLE();
216
173 // Wait for KEY_STATE outputs its value. 217 // Wait for KEY_STATE outputs its value.
174 // 1us was ok on one HHKB, but not worked on another. 218 // 1us was ok on one HHKB, but not worked on another.
175 _delay_us(10); 219 // no wait doesn't work on Teensy++ with pro(1us works)
220 // no wait does work on tmk PCB(8MHz) with pro2
221 // 1us wait does work on both of above
222 // 1us wait doesn't work on tmk(16MHz)
223 // 5us wait does work on tmk(16MHz)
224 // 5us wait does work on tmk(16MHz/2)
225 // 5us wait does work on tmk(8MHz)
226 // 10us wait does work on Teensy++ with pro
227 // 10us wait does work on 328p+iwrap with pro
228 // 10us wait doesn't work on tmk PCB(8MHz) with pro2(very lagged scan)
229 _delay_us(5);
230
176 if (KEY_STATE()) { 231 if (KEY_STATE()) {
177 matrix[row] &= ~(1<<col); 232 matrix[row] &= ~(1<<col);
178 } else { 233 } else {