aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bösebeck <sb@caluga.de>2016-01-13 22:55:48 +0100
committerStephan Bösebeck <sb@caluga.de>2016-01-13 22:55:48 +0100
commit28964bb04b3d2b6ccd5091218fec63a97fd588c9 (patch)
treeba5a75016cf56ed88c9d77d63eb075386df49923
parent5b14d9d84b165be26ac4d9b7dd4f7d9ed7061f1d (diff)
parent46f4494e55a08e3a076bb4a7629f2a7b6a6f7bcb (diff)
downloadqmk_firmware-28964bb04b3d2b6ccd5091218fec63a97fd588c9.tar.gz
qmk_firmware-28964bb04b3d2b6ccd5091218fec63a97fd588c9.zip
Merge branch 'master' of https://github.com/jackhumbert/qmk_firmware
-rw-r--r--keyboard/hhkb_qmk/Makefile149
-rw-r--r--keyboard/hhkb_qmk/README.md180
-rw-r--r--keyboard/hhkb_qmk/config.h71
-rw-r--r--keyboard/hhkb_qmk/hhkb_avr.h167
-rw-r--r--keyboard/hhkb_qmk/hhkb_qmk.c29
-rw-r--r--keyboard/hhkb_qmk/hhkb_qmk.h30
-rw-r--r--keyboard/hhkb_qmk/keymaps/keymap_default.c78
-rw-r--r--keyboard/hhkb_qmk/keymaps/keymap_lxol.c208
-rw-r--r--keyboard/hhkb_qmk/matrix.c196
9 files changed, 1108 insertions, 0 deletions
diff --git a/keyboard/hhkb_qmk/Makefile b/keyboard/hhkb_qmk/Makefile
new file mode 100644
index 000000000..8bd44100b
--- /dev/null
+++ b/keyboard/hhkb_qmk/Makefile
@@ -0,0 +1,149 @@
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_qmk
43
44
45# Directory common source filess exist
46TOP_DIR = ../..
47TMK_DIR = ../../tmk_core
48
49# Directory keyboard dependent files exist
50TARGET_DIR = .
51
52# # project specific files
53SRC = hhkb_qmk.c \
54 matrix.c
55
56ifdef KEYMAP
57 SRC := keymaps/keymap_$(KEYMAP).c $(SRC)
58else
59 SRC := keymaps/keymap_default.c $(SRC)
60endif
61
62CONFIG_H = config.h
63
64# MCU name
65#MCU = at90usb1287
66MCU = atmega32u4
67
68# Processor frequency.
69# This will define a symbol, F_CPU, in all source code files equal to the
70# processor frequency in Hz. You can then use this symbol in your source code to
71# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
72# automatically to create a 32-bit value in your source code.
73#
74# This will be an integer division of F_USB below, as it is sourced by
75# F_USB after it has run through any CPU prescalers. Note that this value
76# does not *change* the processor frequency - it should merely be updated to
77# reflect the processor speed set externally so that the code can use accurate
78# software delays.
79F_CPU = 16000000
80
81
82#
83# LUFA specific
84#
85# Target architecture (see library "Board Types" documentation).
86ARCH = AVR8
87
88# Input clock frequency.
89# This will define a symbol, F_USB, in all source code files equal to the
90# input clock frequency (before any prescaling is performed) in Hz. This value may
91# differ from F_CPU if prescaling is used on the latter, and is required as the
92# raw input clock is fed directly to the PLL sections of the AVR for high speed
93# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
94# at the end, this will be done automatically to create a 32-bit value in your
95# source code.
96#
97# If no clock division is performed on the input clock inside the AVR (via the
98# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
99F_USB = $(F_CPU)
100
101# Interrupt driven control endpoint task(+60)
102OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
103
104
105# Boot Section Size in *bytes*
106# Teensy halfKay 512
107# Teensy++ halfKay 1024
108# Atmel DFU loader 4096
109# LUFA bootloader 4096
110# USBaspLoader 2048
111#OPT_DEFS += -DBOOTLOADER_SIZE=4096
112
113# as per original hasu settings
114OPT_DEFS += -DBOOTLOADER_SIZE=512
115
116# Build Options
117# comment out to disable the options.
118#
119BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
120MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
121EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
122CONSOLE_ENABLE = yes # Console for debug(+400)
123COMMAND_ENABLE = yes # Commands for debug and configuration
124CUSTOM_MATRIX = yes # Custom matrix file for the HHKB
125# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
126# SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
127# NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
128# BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
129# MIDI_ENABLE = YES # MIDI controls
130# UNICODE_ENABLE = YES # Unicode
131# BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID
132
133
134# Optimize size but this may cause error "relocation truncated to fit"
135#EXTRALDFLAGS = -Wl,--relax
136
137# Search Path
138VPATH += $(TARGET_DIR)
139VPATH += $(TOP_DIR)
140VPATH += $(TMK_DIR)
141
142debug-on: EXTRAFLAGS += -DDEBUG -DDEBUG_ACTION
143debug-on: all
144
145debug-off: EXTRAFLAGS += -DNO_DEBUG -DNO_PRINT
146debug-off: OPT_DEFS := $(filter-out -DCONSOLE_ENABLE,$(OPT_DEFS))
147debug-off: all
148
149include $(TOP_DIR)/quantum/quantum.mk
diff --git a/keyboard/hhkb_qmk/README.md b/keyboard/hhkb_qmk/README.md
new file mode 100644
index 000000000..606025c41
--- /dev/null
+++ b/keyboard/hhkb_qmk/README.md
@@ -0,0 +1,180 @@
1hhkb_qmk keyboard firmware
2======================
3
4## Quantum MK Firmware
5
6You have access to a bunch of goodies! Check out the Makefile to enable/disable some of the features. Uncomment the `#` to enable them. Setting them to `no` does nothing and will only confuse future you.
7
8 BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
9 MIDI_ENABLE = yes # MIDI controls
10 # UNICODE_ENABLE = yes # Unicode support - this is commented out, just as an example. You have to use #, not //
11 BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID
12
13## Quick aliases to common actions
14
15Your keymap can include shortcuts to common operations (called "function actions" in tmk).
16
17### Switching and toggling layers
18
19`MO(layer)` - momentary switch to *layer*. As soon as you let go of the key, the layer is deactivated and you pop back out to the previous layer. When you apply this to a key, that same key must be set as `KC_TRNS` on the destination layer. Otherwise, you won't make it back to the original layer when you release the key (and you'll get a keycode sent). You can only switch to layers *above* your current layer. If you're on layer 0 and you use `MO(1)`, that will switch to layer 1 just fine. But if you include `MO(3)` on layer 5, that won't do anything for you -- because layer 3 is lower than layer 5 on the stack.
20
21`LT(layer, kc)` - momentary switch to *layer* when held, and *kc* when tapped. Like `MO()`, this only works upwards in the layer stack (`layer` must be higher than the current layer).
22
23`TG(layer)` - toggles a layer on or off. As with `MO()`, you should set this key as `KC_TRNS` in the destination layer so that tapping it again actually toggles back to the original layer. Only works upwards in the layer stack.
24
25### Fun with modifier keys
26
27* `LSFT(kc)` - applies left Shift to *kc* (keycode) - `S(kc)` is an alias
28* `RSFT(kc)` - applies right Shift to *kc*
29* `LCTL(kc)` - applies left Control to *kc*
30* `RCTL(kc)` - applies right Control to *kc*
31* `LALT(kc)` - applies left Alt to *kc*
32* `RALT(kc)` - applies right Alt to *kc*
33* `LGUI(kc)` - applies left GUI (command/win) to *kc*
34* `RGUI(kc)` - applies right GUI (command/win) to *kc*
35
36You can also chain these, like this:
37
38 LALT(LCTL(KC_DEL)) -- this makes a key that sends Alt, Control, and Delete in a single keypress.
39
40The following shortcuts automatically add `LSFT()` to keycodes to get commonly used symbols. Their long names are also available and documented in `/quantum/keymap_common.h`.
41
42 KC_TILD ~
43 KC_EXLM !
44 KC_AT @
45 KC_HASH #
46 KC_DLR $
47 KC_PERC %
48 KC_CIRC ^
49 KC_AMPR &
50 KC_ASTR *
51 KC_LPRN (
52 KC_RPRN )
53 KC_UNDS _
54 KC_PLUS +
55 KC_LCBR {
56 KC_RCBR }
57 KC_PIPE |
58 KC_COLN :
59
60`MT(mod, kc)` - is *mod* (modifier key - MOD_LCTL, MOD_LSFT) when held, and *kc* when tapped. In other words, you can have a key that sends Esc (or the letter O or whatever) when you tap it, but works as a Control key or a Shift key when you hold it down.
61
62These are the values you can use for the `mod` in `MT()` (right-hand modifiers are not available):
63
64 * MOD_LCTL
65 * MOD_LSFT
66 * MOD_LALT
67 * MOD_LGUI
68
69These can also be combined like `MOD_LCTL | MOD_LSFT` e.g. `MT(MOD_LCTL | MOD_LSFT, KC_ESC)` which would activate Control and Shift when held, and send Escape when tapped.
70
71We've added shortcuts to make common modifier/tap (mod-tap) mappings more compact:
72
73 * `CTL_T(kc)` - is LCTL when held and *kc* when tapped
74 * `SFT_T(kc)` - is LSFT when held and *kc* when tapped
75 * `ALT_T(kc)` - is LALT when held and *kc* when tapped
76 * `GUI_T(kc)` - is LGUI when held and *kc* when tapped
77 * `ALL_T(kc)` - is Hyper (all mods) when held and *kc* when tapped. To read more about what you can do with a Hyper key, see [this blog post by Brett Terpstra](http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/)
78
79### Temporarily setting the default layer
80
81`DF(layer)` - sets default layer to *layer*. The default layer is the one at the "bottom" of the layer stack - the ultimate fallback layer. This currently does not persist over power loss. When you plug the keyboard back in, layer 0 will always be the default. It is theoretically possible to work around that, but that's not what `DF` does.
82
83### Remember: These are just aliases
84
85These functions work the same way that their `ACTION_*` functions do - they're just quick aliases. To dig into all of the tmk ACTION_* functions, please see the [TMK documentation](https://github.com/jackhumbert/qmk_firmware/blob/master/tmk_core/doc/keymap.md#2-action).
86
87Instead of using `FNx` when defining `ACTION_*` functions, you can use `F(x)` - the benefit here is being able to use more than 32 function actions (up to 4096), if you happen to need them.
88
89## Macro shortcuts: Send a whole string when pressing just one key
90
91Instead of using the `ACTION_MACRO` function, you can simply use `M(n)` to access macro *n* - *n* will get passed into the `action_get_macro` as the `id`, and you can use a switch statement to trigger it. This gets called on the keydown and keyup, so you'll need to use an if statement testing `record->event.pressed` (see keymap_default.c).
92
93```c
94const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) // this is the function signature -- just copy/paste it into your keymap file as it is.
95{
96 switch(id) {
97 case 0: // this would trigger when you hit a key mapped as M(0)
98 if (record->event.pressed) {
99 return MACRO( I(255), T(H), T(E), T(L), T(L), W(255), T(O), END ); // this sends the string 'hello' when the macro executes
100 }
101 break;
102 }
103 return MACRO_NONE;
104};
105```
106A macro can include the following commands:
107
108* I() change interval of stroke in milliseconds.
109* D() press key.
110* U() release key.
111* T() type key(press and release).
112* W() wait (milliseconds).
113* END end mark.
114
115So above you can see the stroke interval changed to 255ms between each keystroke, then a bunch of keys being typed, waits a while, then the macro ends.
116
117Note: Using macros to have your keyboard send passwords for you is a bad idea.
118
119### Additional keycode aliases for software-implemented layouts (Colemak, Dvorak, etc)
120
121Everything is assuming you're in Qwerty (in software) by default, but there is built-in support for using a Colemak or Dvorak layout by including this at the top of your keymap:
122
123 #include "keymap_<layout>.h"
124
125Where <layout> is "colemak" or "dvorak". After including this line, you will get access to:
126
127 * `CM_*` for all of the Colemak-equivalent characters
128 * `DV_*` for all of the Dvorak-equivalent characters
129
130These implementations assume you're using Colemak or Dvorak on your OS, not on your keyboard - this is referred to as a software-implemented layout. If your computer is in Qwerty and your keymap is in Colemak or Dvorak, this is referred to as a firmware-implemented layout, and you won't need these features.
131
132To give an example, if you're using software-implemented Colemak, and want to get an `F`, you would use `CM_F` - `KC_F` under these same circumstances would result in `T`.
133
134## Additional language support
135
136In `quantum/keymap_extras/`, you'll see various language files - these work the same way as the alternative layout ones do. Most are defined by their two letter country/language code followed by an underscore and a 4-letter abbreviation of its name. `FR_UGRV` which will result in a `ù` when using a software-implemented AZERTY layout. It's currently difficult to send such characters in just the firmware (but it's being worked on - see Unicode support).
137
138## Unicode support
139
140You can currently send 4 hex digits with your OS-specific modifier key (RALT for OSX with the "Unicode Hex Input" layout) - this is currently limited to supporting one OS at a time, and requires a recompile for switching. 8 digit hex codes are being worked on. The keycode function is `UC(n)`, where *n* is a 4 digit hexidecimal. Enable from the Makefile.
141
142## Other firmware shortcut keycodes
143
144* `RESET` - puts the MCU in DFU mode for flashing new firmware (with `make dfu`)
145* `DEBUG` - the firmware into debug mode - you'll need hid_listen to see things
146* `BL_ON` - turns the backlight on
147* `BL_OFF` - turns the backlight off
148* `BL_<n>` - sets the backlight to level *n*
149* `BL_INC` - increments the backlight level by one
150* `BL_DEC` - decrements the backlight level by one
151* `BL_TOGG` - toggles the backlight
152* `BL_STEP` - steps through the backlight levels
153
154Enable the backlight from the Makefile.
155
156## MIDI functionalty
157
158This is still a WIP, but check out `quantum/keymap_midi.c` to see what's happening. Enable from the Makefile.
159
160## Bluetooth functionality
161
162This requires [some hardware changes](https://www.reddit.com/r/MechanicalKeyboards/comments/3psx0q/the_planck_keyboard_with_bluetooth_guide_and/?ref=search_posts), but can be enabled via the Makefile. The firmware will still output characters via USB, so be aware of this when charging via a computer. It would make sense to have a switch on the Bluefruit to turn it off at will.
163
164## Building
165
166Download or clone the whole firmware and navigate to the keyboard/planck folder. Once your dev env is setup, you'll be able to type `make` to generate your .hex - you can then use `make dfu` to program your PCB once you hit the reset button.
167
168Depending on which keymap you would like to use, you will have to compile slightly differently.
169
170### Default
171To build with the default keymap, simply run `make`.
172
173### Other Keymaps
174Several version of keymap are available in advance but you are recommended to define your favorite layout yourself. To define your own keymap create file named `keymap_<name>.c` and see keymap document (you can find in top README.md) and existent keymap files.
175
176To build the firmware binary hex file with a keymap just do `make` with `KEYMAP` option like:
177```
178$ make KEYMAP=[default|jack|<name>]
179```
180Keymaps follow the format **__keymap\_\<name\>.c__** and are stored in the `keymaps` folder.
diff --git a/keyboard/hhkb_qmk/config.h b/keyboard/hhkb_qmk/config.h
new file mode 100644
index 000000000..ee66e4457
--- /dev/null
+++ b/keyboard/hhkb_qmk/config.h
@@ -0,0 +1,71 @@
1/*
2Copyright 2012 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#include "config_common.h"
22
23/* USB Device descriptor parameter */
24#define VENDOR_ID 0xFEED
25#define PRODUCT_ID 0xCAFE
26#define DEVICE_VER 0x0104
27#define MANUFACTURER q.m.k
28#define PRODUCT HHKB mod
29#define DESCRIPTION q.m.k keyboard firmware for HHKB
30
31/* key matrix size */
32#define MATRIX_ROWS 8
33#define MATRIX_COLS 8
34
35#define TAPPING_TERM 200
36
37/* number of backlight levels */
38#define BACKLIGHT_LEVELS 3
39
40/* Set 0 if debouncing isn't needed */
41#define DEBOUNCE 5
42
43/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
44//#define LOCKING_SUPPORT_ENABLE
45/* Locking resynchronize hack */
46//#define LOCKING_RESYNC_ENABLE
47
48/* key combination for command */
49#define IS_COMMAND() ( \
50 keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
51)
52
53/*
54 * Feature disable options
55 * These options are also useful to firmware size reduction.
56*/
57
58/* disable debug print */
59//#define NO_DEBUG
60
61/* disable print */
62//#define NO_PRINT
63
64/* disable action features */
65//#define NO_ACTION_LAYER
66//#define NO_ACTION_TAPPING
67//#define NO_ACTION_ONESHOT
68//#define NO_ACTION_MACRO
69//#define NO_ACTION_FUNCTION
70
71#endif
diff --git a/keyboard/hhkb_qmk/hhkb_avr.h b/keyboard/hhkb_qmk/hhkb_avr.h
new file mode 100644
index 000000000..7ea6322c7
--- /dev/null
+++ b/keyboard/hhkb_qmk/hhkb_avr.h
@@ -0,0 +1,167 @@
1#ifndef HHKB_AVR_H
2#define HHKB_AVR_H
3
4#include <stdint.h>
5#include <stdbool.h>
6#include <avr/io.h>
7#include <avr/interrupt.h>
8#include <util/delay.h>
9
10
11// Timer resolution check
12#if (1000000/TIMER_RAW_FREQ > 20)
13# error "Timer resolution(>20us) is not enough for HHKB matrix scan tweak on V-USB."
14#endif
15
16
17/*
18 * HHKB Matrix I/O
19 *
20 * row: HC4051[A,B,C] selects scan row0-7
21 * row-ext: [En0,En1] row extention for JP
22 * col: LS145[A,B,C,D] selects scan col0-7 and enable(D)
23 * key: on: 0/off: 1
24 * prev: hysteresis control: assert(1) when previous key state is on
25 */
26
27
28#if defined(__AVR_ATmega32U4__)
29/*
30 * For TMK HHKB alt controller(ATMega32U4)
31 *
32 * row: PB0-2
33 * col: PB3-5,6
34 * key: PD7(pull-uped)
35 * prev: PB7
36 * power: PD4(L:off/H:on)
37 * row-ext: PC6,7 for HHKB JP(active low)
38 */
39static inline void KEY_ENABLE(void) { (PORTB &= ~(1<<6)); }
40static inline void KEY_UNABLE(void) { (PORTB |= (1<<6)); }
41static inline bool KEY_STATE(void) { return (PIND & (1<<7)); }
42static inline void KEY_PREV_ON(void) { (PORTB |= (1<<7)); }
43static inline void KEY_PREV_OFF(void) { (PORTB &= ~(1<<7)); }
44#ifdef HHKB_POWER_SAVING
45static inline void KEY_POWER_ON(void) {
46 DDRB = 0xFF; PORTB = 0x40; // change pins output
47 DDRD |= (1<<4); PORTD |= (1<<4); // MOS FET switch on
48 /* Without this wait you will miss or get false key events. */
49 _delay_ms(5); // wait for powering up
50}
51static inline void KEY_POWER_OFF(void) {
52 /* input with pull-up consumes less than without it when pin is open. */
53 DDRB = 0x00; PORTB = 0xFF; // change pins input with pull-up
54 DDRD |= (1<<4); PORTD &= ~(1<<4); // MOS FET switch off
55}
56static inline bool KEY_POWER_STATE(void) { return PORTD & (1<<4); }
57#else
58static inline void KEY_POWER_ON(void) {}
59static inline void KEY_POWER_OFF(void) {}
60static inline bool KEY_POWER_STATE(void) { return true; }
61#endif
62static inline void KEY_INIT(void)
63{
64 /* row,col,prev: output */
65 DDRB = 0xFF;
66 PORTB = 0x40; // unable
67 /* key: input with pull-up */
68 DDRD &= ~0x80;
69 PORTD |= 0x80;
70#ifdef HHKB_JP
71 /* row extention for HHKB JP */
72 DDRC |= (1<<6|1<<7);
73 PORTC |= (1<<6|1<<7);
74#endif
75 KEY_UNABLE();
76 KEY_PREV_OFF();
77
78 KEY_POWER_OFF();
79}
80static inline void KEY_SELECT(uint8_t ROW, uint8_t COL)
81{
82 PORTB = (PORTB & 0xC0) | (((COL) & 0x07)<<3) | ((ROW) & 0x07);
83#ifdef HHKB_JP
84 if ((ROW) & 0x08) PORTC = (PORTC & ~(1<<6|1<<7)) | (1<<6);
85 else PORTC = (PORTC & ~(1<<6|1<<7)) | (1<<7);
86#endif
87}
88
89
90#elif defined(__AVR_AT90USB1286__)
91/*
92 * For Teensy++(AT90USB1286)
93 *
94 * HHKB pro HHKB pro2
95 * row: PB0-2 (6-8) (5-7)
96 * col: PB3-5,6 (9-12) (8-11)
97 * key: PE6(pull-uped) (4) (3)
98 * prev: PE7 (5) (4)
99 *
100 * TODO: convert into 'staitc inline' function
101 */
102#define KEY_INIT() do { \
103 DDRB |= 0x7F; \
104 DDRE |= (1<<7); \
105 DDRE &= ~(1<<6); \
106 PORTE |= (1<<6); \
107} while (0)
108#define KEY_SELECT(ROW, COL) (PORTB = (PORTB & 0xC0) | \
109 (((COL) & 0x07)<<3) | \
110 ((ROW) & 0x07))
111#define KEY_ENABLE() (PORTB &= ~(1<<6))
112#define KEY_UNABLE() (PORTB |= (1<<6))
113#define KEY_STATE() (PINE & (1<<6))
114#define KEY_PREV_ON() (PORTE |= (1<<7))
115#define KEY_PREV_OFF() (PORTE &= ~(1<<7))
116#define KEY_POWER_ON()
117#define KEY_POWER_OFF()
118#define KEY_POWER_STATE() true
119
120
121#else
122# error "define code for matrix scan"
123#endif
124
125
126#if 0
127// For ATMega328P with V-USB
128//
129// #elif defined(__AVR_ATmega328P__)
130// Ports for V-USB
131// key: PB0(pull-uped)
132// prev: PB1
133// row: PB2-4
134// col: PC0-2,3
135// power: PB5(Low:on/Hi-z:off)
136#define KEY_INIT() do { \
137 DDRB |= 0x3E; \
138 DDRB &= ~(1<<0); \
139 PORTB |= 1<<0; \
140 DDRC |= 0x0F; \
141 KEY_UNABLE(); \
142 KEY_PREV_OFF(); \
143} while (0)
144#define KEY_SELECT(ROW, COL) do { \
145 PORTB = (PORTB & 0xE3) | ((ROW) & 0x07)<<2; \
146 PORTC = (PORTC & 0xF8) | ((COL) & 0x07); \
147} while (0)
148#define KEY_ENABLE() (PORTC &= ~(1<<3))
149#define KEY_UNABLE() (PORTC |= (1<<3))
150#define KEY_STATE() (PINB & (1<<0))
151#define KEY_PREV_ON() (PORTB |= (1<<1))
152#define KEY_PREV_OFF() (PORTB &= ~(1<<1))
153// Power supply switching
154#define KEY_POWER_ON() do { \
155 KEY_INIT(); \
156 PORTB &= ~(1<<5); \
157 _delay_ms(1); \
158} while (0)
159#define KEY_POWER_OFF() do { \
160 DDRB &= ~0x3F; \
161 PORTB &= ~0x3F; \
162 DDRC &= ~0x0F; \
163 PORTC &= ~0x0F; \
164} while (0)
165#endif
166
167#endif
diff --git a/keyboard/hhkb_qmk/hhkb_qmk.c b/keyboard/hhkb_qmk/hhkb_qmk.c
new file mode 100644
index 000000000..9c90e6eb4
--- /dev/null
+++ b/keyboard/hhkb_qmk/hhkb_qmk.c
@@ -0,0 +1,29 @@
1#include "hhkb_qmk.h"
2
3__attribute__ ((weak))
4void * matrix_init_user(void) {
5 // leave these blank
6};
7
8__attribute__ ((weak))
9void * matrix_scan_user(void) {
10 // leave these blank
11};
12
13void * matrix_init_kb(void) {
14 // put your keyboard start-up code here
15 // runs once when the firmware starts up
16
17 if (matrix_init_user) {
18 (*matrix_init_user)();
19 }
20};
21
22void * matrix_scan_kb(void) {
23 // put your looping keyboard code here
24 // runs every cycle (a lot)
25
26 if (matrix_scan_user) {
27 (*matrix_scan_user)();
28 }
29};
diff --git a/keyboard/hhkb_qmk/hhkb_qmk.h b/keyboard/hhkb_qmk/hhkb_qmk.h
new file mode 100644
index 000000000..f6bf20f43
--- /dev/null
+++ b/keyboard/hhkb_qmk/hhkb_qmk.h
@@ -0,0 +1,30 @@
1#ifndef HHKB_QMK_H
2#define HHKB_QMK_H
3
4#include "matrix.h"
5#include "keymap_common.h"
6//#include "backlight.h"
7#include <stddef.h>
8
9#define KEYMAP( \
10 K31, K30, K00, K10, K11, K20, K21, K40, K41, K60, K61, K70, K71, K50, K51, \
11 K32, K01, K02, K13, K12, K23, K22, K42, K43, K62, K63, K73, K72, K52, \
12 K33, K04, K03, K14, K15, K24, K25, K45, K44, K65, K64, K74, K53, \
13 K34, K05, K06, K07, K16, K17, K26, K46, K66, K76, K75, K55, K54, \
14 K35, K36, K37, K57, K56) \
15 \
16{ \
17 { K00, K01, K02, K03, K04, K05, K06, K07 }, \
18 { K10, K11, K12, K13, K14, K15, K16, K17 }, \
19 { K20, K21, K22, K23, K24, K25, K26, KC_NO }, \
20 { K30, K31, K32, K33, K34, K35, K36, K37 }, \
21 { K40, K41, K42, K43, K44, K45, K46, KC_NO }, \
22 { K50, K51, K52, K53, K54, K55, K56, K57 }, \
23 { K60, K61, K62, K63, K64, K65, K66, KC_NO }, \
24 { K70, K71, K72, K73, K74, K75, K76, KC_NO } \
25}
26
27void * matrix_init_user(void);
28void * matrix_scan_user(void);
29
30#endif
diff --git a/keyboard/hhkb_qmk/keymaps/keymap_default.c b/keyboard/hhkb_qmk/keymaps/keymap_default.c
new file mode 100644
index 000000000..bcd8ead37
--- /dev/null
+++ b/keyboard/hhkb_qmk/keymaps/keymap_default.c
@@ -0,0 +1,78 @@
1/* -*- eval: (turn-on-orgtbl); -*-
2 * default HHKB Layout
3 */
4#include "hhkb_qmk.h"
5
6#define BASE 0
7#define HHKB 1
8
9const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
10
11 /* BASE Level: Default Layer
12 |-------+---+---+---+---+---+---+---+---+---+---+-------+-----+-------+---|
13 | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | \ | ` |
14 |-------+---+---+---+---+---+---+---+---+---+---+-------+-----+-------+---|
15 | Tab | Q | W | E | R | T | Y | U | I | O | P | [ | ] | Backs | |
16 |-------+---+---+---+---+---+---+---+---+---+---+-------+-----+-------+---|
17 | Cont | A | S | D | F | G | H | J | K | L | ; | ' | Ent | | |
18 |-------+---+---+---+---+---+---+---+---+---+---+-------+-----+-------+---|
19 | Shift | Z | X | C | V | B | N | M | , | . | / | Shift | Fn0 | | |
20 |-------+---+---+---+---+---+---+---+---+---+---+-------+-----+-------+---|
21
22 |------+------+-----------------------+------+------|
23 | LAlt | LGUI | ******* Space ******* | RGUI | RAlt |
24 |------+------+-----------------------+------+------|
25 */
26
27 [BASE] = KEYMAP( // default layer
28 KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSLS, KC_GRV, \
29 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSPC, \
30 KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \
31 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, MO(HHKB), \
32 KC_LALT, KC_LGUI, /* */ KC_SPC, KC_RGUI, KC_RALT),
33
34
35
36 /* Layer HHKB: HHKB mode (HHKB Fn)
37 |------+-----+-----+-----+----+----+----+----+-----+-----+-----+-----+-------+-------+-----|
38 | Pwr | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | Ins | Del |
39 |------+-----+-----+-----+----+----+----+----+-----+-----+-----+-----+-------+-------+-----|
40 | Caps | | | | | | | | Psc | Slk | Pus | Up | | Backs | |
41 |------+-----+-----+-----+----+----+----+----+-----+-----+-----+-----+-------+-------+-----|
42 | | VoD | VoU | Mut | | | * | / | Hom | PgU | Lef | Rig | Enter | | |
43 |------+-----+-----+-----+----+----+----+----+-----+-----+-----+-----+-------+-------+-----|
44 | | | | | | | + | - | End | PgD | Dow | | | | |
45 |------+-----+-----+-----+----+----+----+----+-----+-----+-----+-----+-------+-------+-----|
46
47 |------+------+----------------------+------+------+
48 | **** | **** | ******************** | **** | **** |
49 |------+------+----------------------+------+------+
50
51 */
52
53 [HHKB] = KEYMAP(
54 KC_PWR, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_DEL, \
55 KC_CAPS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PSCR, KC_SLCK, KC_PAUS, KC_UP, KC_TRNS, KC_BSPC, \
56 KC_TRNS, KC_VOLD, KC_VOLU, KC_MUTE, KC_TRNS, KC_TRNS, KC_PAST, KC_PSLS, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, KC_PENT, \
57 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PPLS, KC_PMNS, KC_END, KC_PGDN, KC_DOWN, KC_TRNS, KC_TRNS, \
58 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS)};
59
60
61const uint16_t PROGMEM fn_actions[] = {
62
63};
64
65const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
66{
67 // MACRODOWN only works in this function
68 switch(id) {
69 case 0:
70 if (record->event.pressed) {
71 register_code(KC_RSFT);
72 } else {
73 unregister_code(KC_RSFT);
74 }
75 break;
76 }
77 return MACRO_NONE;
78};
diff --git a/keyboard/hhkb_qmk/keymaps/keymap_lxol.c b/keyboard/hhkb_qmk/keymaps/keymap_lxol.c
new file mode 100644
index 000000000..3256fda51
--- /dev/null
+++ b/keyboard/hhkb_qmk/keymaps/keymap_lxol.c
@@ -0,0 +1,208 @@
1/* -*- eval: (turn-on-orgtbl); -*-
2 * lxol HHKB Layout
3 */
4#include "hhkb_qmk.h"
5
6#define BASE 0
7#define WIN 1
8#define HHKB 2
9#define RGUILEV 3
10#define LGUILEV 4
11#define RALTLEV 5
12#define LALTLEV 6
13
14
15const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
16
17 /* Layer 0: Default Layer
18 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
19 | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | \ | ` |
20 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
21 | Tab | Q | W | E | R | T | Y | U | I | O | P | [ | ] | Backs | |
22 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
23 | Contro | A | S | D | F | G | H | J | K | L | ; | ' | RCtl/Ent | | |
24 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
25 | Shift | Z | X | C | V | B | N | M | , | . | Fn2 | Shift | Fn0 | | |
26 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
27
28 |------+------+-------+------+------|
29 | LAlt | LGUI | Space | RGUI | RAlt |
30 |------+------+-------+------+------|
31 */
32
33 [BASE] = KEYMAP( // layer 0 : default
34
35
36 KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSLS, KC_GRV, \
37 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSPC, \
38 KC_LCTL, LT(LALTLEV,KC_A), LT(LGUILEV,KC_S), KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, LT(RGUILEV,KC_L), LT(RALTLEV,KC_SCLN), KC_QUOT, KC_FN0, \
39 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, MO(HHKB), \
40 KC_LALT, KC_LGUI, KC_SPC, KC_RGUI, KC_RALT),
41
42
43
44 /* Layer 1: HHKB mode (HHKB Fn)
45 |------+-----+-----+-----+----+----+----+----+-----+-----+-----+-----+-------+-------+-----|
46 | Pwr | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | Ins | Del |
47 |------+-----+-----+-----+----+----+----+----+-----+-----+-----+-----+-------+-------+-----|
48 | Caps | | | | | | | | Psc | Slk | Pus | Up | | Backs | |
49 |------+-----+-----+-----+----+----+----+----+-----+-----+-----+-----+-------+-------+-----|
50 | | VoD | VoU | Mut | | | * | / | Hom | PgU | Lef | Rig | Enter | | |
51 |------+-----+-----+-----+----+----+----+----+-----+-----+-----+-----+-------+-------+-----|
52 | | | | | | | + | - | End | PgD | Dow | | | | |
53 |------+-----+-----+-----+----+----+----+----+-----+-----+-----+-----+-------+-------+-----|
54
55 |---+---+---+---+---|
56 | | | | | |
57 |---+---+---+---+---|
58 */
59
60 [HHKB] = KEYMAP(
61 KC_PWR, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_DEL, \
62 KC_CAPS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PSCR, KC_SLCK, KC_PAUS, KC_UP, KC_TRNS, KC_BSPC, \
63 KC_TRNS, KC_VOLD, KC_VOLU, KC_MUTE, KC_TRNS, KC_TRNS, KC_PAST, KC_PSLS, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, KC_PENT, \
64 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PPLS, KC_PMNS, KC_END, KC_PGDN, KC_DOWN, KC_TRNS, KC_TRNS, \
65 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS),
66
67
68 /* Layer LGUI: All keys with RGUI modifier
69 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
70 | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | \ | ` |
71 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
72 | Tab | Q | W | E | R | T | Y | U | I | O | P | [ | ] | Backs | |
73 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
74 | Contro | A | S | D | F | G | H | J | K | | ; | ' | RCtl/Ent | | |
75 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
76 | Shift | Z | X | C | V | B | N | M | , | . | Fn2 | Shift | Fn0 | | |
77 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
78
79 |------+------+-------+------+------|
80 | LAlt | LGUI | Space | RGUI | RAlt |
81 |------+------+-------+------+------|
82 */
83
84 [RGUILEV] = KEYMAP( // Right GUI layer by KC_L
85
86 RGUI(KC_ESC), RGUI(KC_1), RGUI(KC_2), RGUI(KC_3), RGUI(KC_4), RGUI(KC_5), RGUI(KC_6), RGUI(KC_7), RGUI(KC_8), RGUI(KC_9), RGUI(KC_0), RGUI(KC_MINS), RGUI(KC_EQL), RGUI(KC_BSLS), RGUI(KC_GRV), \
87 RGUI(KC_TAB), RGUI(KC_Q), RGUI(KC_W), RGUI(KC_E), RGUI(KC_R), RGUI(KC_T), RGUI(KC_Y), RGUI(KC_U), RGUI(KC_I), RGUI(KC_O), RGUI(KC_P), RGUI(KC_LBRC), RGUI(KC_RBRC), RGUI(KC_BSPC), \
88 RGUI(KC_LCTL), RGUI(KC_A), RGUI(KC_S), RGUI(KC_D), RGUI(KC_F), RGUI(KC_G), RGUI(KC_H), RGUI(KC_J), RGUI(KC_K), KC_TRNS, KC_TRNS, RGUI(KC_QUOT), KC_FN0, \
89 RGUI(KC_LSFT), RGUI(KC_Z), RGUI(KC_X), RGUI(KC_C), RGUI(KC_V), RGUI(KC_B), RGUI(KC_N), RGUI(KC_M), RGUI(KC_COMM), RGUI(KC_DOT), RGUI(KC_SLSH), RGUI(KC_RSFT), KC_TRNS, \
90 KC_LALT, KC_LGUI, RGUI(KC_SPC), KC_RGUI, KC_RALT),
91
92 /* Layer LGUI: All keys with LGUI modifier
93 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
94 | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | \ | ` |
95 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
96 | Tab | Q | W | E | R | T | Y | U | I | O | P | [ | ] | Backs | |
97 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
98 | Contro | A | S | D | F | G | H | J | K | | ; | ' | RCtl/Ent | | |
99 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
100 | Shift | Z | X | C | V | B | N | M | , | . | Fn2 | Shift | Fn0 | | |
101 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
102
103 |------+------+-------+------+------|
104 | LAlt | LGUI | Space | LGUI | RAlt |
105 |------+------+-------+------+------|
106 */
107
108 [LGUILEV] = KEYMAP( // Right GUI layer by KC_L
109
110 LGUI(KC_ESC), LGUI(KC_1), LGUI(KC_2), LGUI(KC_3), LGUI(KC_4), LGUI(KC_5), LGUI(KC_6), LGUI(KC_7), LGUI(KC_8), LGUI(KC_9), LGUI(KC_0), LGUI(KC_MINS), LGUI(KC_EQL), LGUI(KC_BSLS), LGUI(KC_GRV), \
111 LGUI(KC_TAB), LGUI(KC_Q), LGUI(KC_W), LGUI(KC_E), LGUI(KC_R), LGUI(KC_T), LGUI(KC_Y), LGUI(KC_U), LGUI(KC_I), LGUI(KC_O), LGUI(KC_P), LGUI(KC_LBRC), LGUI(KC_RBRC), LGUI(KC_BSPC), \
112 LGUI(KC_LCTL), KC_TRNS, KC_TRNS, LGUI(KC_D), LGUI(KC_F), LGUI(KC_G), LGUI(KC_H), LGUI(KC_J), LGUI(KC_K), LGUI(KC_L), LGUI(KC_SCLN), LGUI(KC_QUOT), KC_FN0, \
113 KC_LSFT, LGUI(KC_Z), LGUI(KC_X), LGUI(KC_C), LGUI(KC_V), LGUI(KC_B), LGUI(KC_N), LGUI(KC_M), LGUI(KC_COMM), LGUI(KC_DOT), LGUI(KC_SLSH), KC_RSFT, KC_TRNS, \
114 KC_LALT, KC_LGUI, LGUI(KC_SPC), KC_LGUI, KC_RALT),
115
116 /* Layer LALT: All keys with RALT modifier
117 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
118 | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | \ | ` |
119 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
120 | Tab | Q | W | E | R | T | Y | U | I | O | P | [ | ] | Backs | |
121 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
122 | Contro | A | S | D | F | G | H | J | K | | ; | ' | RCtl/Ent | | |
123 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
124 | Shift | Z | X | C | V | B | N | M | , | . | Fn2 | Shift | Fn0 | | |
125 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
126
127 |------+------+-------+------+------|
128 | LAlt | LGUI | Space | RGUI | RAlt |
129 |------+------+-------+------+------|
130 */
131
132 [RALTLEV] = KEYMAP( // Right ALT layer by KC_L
133
134 RALT(KC_ESC), RALT(KC_1), RALT(KC_2), RALT(KC_3), RALT(KC_4), RALT(KC_5), RALT(KC_6), RALT(KC_7), RALT(KC_8), RALT(KC_9), RALT(KC_0), RALT(KC_MINS), RALT(KC_EQL), RALT(KC_BSLS), RALT(KC_GRV), \
135 RALT(KC_TAB), RALT(KC_Q), RALT(KC_W), RALT(KC_E), RALT(KC_R), RALT(KC_T), RALT(KC_Y), RALT(KC_U), RALT(KC_I), RALT(KC_O), RALT(KC_P), RALT(KC_LBRC), RALT(KC_RBRC), RALT(KC_BSPC), \
136 RALT(KC_LCTL), RALT(KC_A), RALT(KC_S), RALT(KC_D), RALT(KC_F), RALT(KC_G), RALT(KC_H), RALT(KC_J), RALT(KC_K), KC_TRNS, KC_TRNS, RALT(KC_QUOT), KC_FN0, \
137 RALT(KC_LSFT), RALT(KC_Z), RALT(KC_X), RALT(KC_C), RALT(KC_V), RALT(KC_B), RALT(KC_N), RALT(KC_M), RALT(KC_COMM), RALT(KC_DOT), RALT(KC_SLSH), RALT(KC_RSFT), KC_TRNS, \
138 KC_LALT, KC_LGUI, RALT(KC_SPC), KC_RGUI, KC_RALT),
139
140 /* Layer LALT: All keys with LALT modifier
141 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
142 | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | \ | ` |
143 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
144 | Tab | Q | W | E | R | T | Y | U | I | O | P | [ | ] | Backs | |
145 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
146 | Contro | A | S | D | F | G | H | J | K | | ; | ' | RCtl/Ent | | |
147 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
148 | Shift | Z | X | C | V | B | N | M | , | . | Fn2 | Shift | Fn0 | | |
149 |--------+---+---+---+---+---+---+---+---+---+-----+-------+----------+-------+---|
150
151 |------+------+-------+------+------|
152 | LAlt | LGUI | Space | LGUI | RAlt |
153 |------+------+-------+------+------|
154 */
155
156 [LALTLEV] = KEYMAP( // Right ALT layer by KC_L
157
158 LALT(KC_ESC), LALT(KC_1), LALT(KC_2), LALT(KC_3), LALT(KC_4), LALT(KC_5), LALT(KC_6), LALT(KC_7), LALT(KC_8), LALT(KC_9), LALT(KC_0), LALT(KC_MINS), LALT(KC_EQL), LALT(KC_BSLS), LALT(KC_GRV), \
159 LALT(KC_TAB), LALT(KC_Q), LALT(KC_W), LALT(KC_E), LALT(KC_R), LALT(KC_T), LALT(KC_Y), LALT(KC_U), LALT(KC_I), LALT(KC_O), LALT(KC_P), LALT(KC_LBRC), LALT(KC_RBRC), LALT(KC_BSPC), \
160 LALT(KC_LCTL), KC_TRNS, KC_TRNS, LALT(KC_D), LALT(KC_F), LALT(KC_G), LALT(KC_H), LALT(KC_J), LALT(KC_K), LALT(KC_L), LALT(KC_SCLN), LALT(KC_QUOT), KC_FN0, \
161 KC_LSFT, LALT(KC_Z), LALT(KC_X), LALT(KC_C), LALT(KC_V), LALT(KC_B), LALT(KC_N), LALT(KC_M), LALT(KC_COMM), LALT(KC_DOT), LALT(KC_SLSH), KC_RSFT, KC_TRNS, \
162 KC_LALT, KC_LGUI, LALT(KC_SPC), KC_LGUI, KC_RALT),
163
164
165 /* Layer WIN: Win layer
166 |--------+---+---+---+---+---+---+---+---+---+---+-------+----------+-------+---|
167 | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | \ | ` |
168 |--------+---+---+---+---+---+---+---+---+---+---+-------+----------+-------+---|
169 | Tab | Q | W | E | R | T | Y | U | I | O | P | [ | ] | Backs | |
170 |--------+---+---+---+---+---+---+---+---+---+---+-------+----------+-------+---|
171 | Contro | A | S | D | F | G | H | J | K | L | ; | ' | RCtl/Ent | | |
172 |--------+---+---+---+---+---+---+---+---+---+---+-------+----------+-------+---|
173 | Shift | Z | X | C | V | B | N | M | , | . | / | Shift | Fn0 | | |
174 |--------+---+---+---+---+---+---+---+---+---+---+-------+----------+-------+---|
175
176 |------+------+-------+------+------|
177 | LGui | LAlt | Space | RGui | Ralt |
178 |------+------+-------+------+------|
179 */
180
181 [WIN] = KEYMAP( // BASE level with swapped GUI/ALT
182
183
184 KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSLS, KC_GRV, \
185 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSPC, \
186 KC_LCTL, LT(LGUILEV,KC_A), LT(LALTLEV,KC_S), KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, LT(RALTLEV,KC_L), LT(RGUILEV,KC_SCLN), KC_QUOT, KC_FN0, \
187 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, MO(HHKB), \
188 KC_RGUI, KC_RALT, KC_SPC, KC_RALT, KC_RGUI)};
189
190
191const uint16_t PROGMEM fn_actions[] = {
192 [0] = ACTION_MODS_TAP_KEY(MOD_RCTL, KC_ENT) // RControl with tap Enter*
193};
194
195const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
196{
197 // MACRODOWN only works in this function
198 switch(id) {
199 case 0:
200 if (record->event.pressed) {
201 register_code(KC_RSFT);
202 } else {
203 unregister_code(KC_RSFT);
204 }
205 break;
206 }
207 return MACRO_NONE;
208};
diff --git a/keyboard/hhkb_qmk/matrix.c b/keyboard/hhkb_qmk/matrix.c
new file mode 100644
index 000000000..14fae0b82
--- /dev/null
+++ b/keyboard/hhkb_qmk/matrix.c
@@ -0,0 +1,196 @@
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 <util/delay.h>
24#include "print.h"
25#include "debug.h"
26#include "util.h"
27#include "timer.h"
28#include "matrix.h"
29#include "hhkb_avr.h"
30#include <avr/wdt.h>
31#include "suspend.h"
32#include "lufa.h"
33
34
35// matrix power saving
36#define MATRIX_POWER_SAVE 10000
37static uint32_t matrix_last_modified = 0;
38
39// matrix state buffer(1:on, 0:off)
40static matrix_row_t *matrix;
41static matrix_row_t *matrix_prev;
42static matrix_row_t _matrix0[MATRIX_ROWS];
43static matrix_row_t _matrix1[MATRIX_ROWS];
44
45
46inline
47uint8_t matrix_rows(void)
48{
49 return MATRIX_ROWS;
50}
51
52inline
53uint8_t matrix_cols(void)
54{
55 return MATRIX_COLS;
56}
57
58void matrix_init(void)
59{
60#ifdef DEBUG
61 debug_enable = true;
62 debug_keyboard = true;
63#endif
64
65 KEY_INIT();
66
67 // initialize matrix state: all keys off
68 for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00;
69 for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00;
70 matrix = _matrix0;
71 matrix_prev = _matrix1;
72}
73
74uint8_t matrix_scan(void)
75{
76 uint8_t *tmp;
77
78 tmp = matrix_prev;
79 matrix_prev = matrix;
80 matrix = tmp;
81
82 // power on
83 if (!KEY_POWER_STATE()) KEY_POWER_ON();
84 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
85 for (uint8_t col = 0; col < MATRIX_COLS; col++) {
86 KEY_SELECT(row, col);
87 _delay_us(5);
88
89 // Not sure this is needed. This just emulates HHKB controller's behaviour.
90 if (matrix_prev[row] & (1<<col)) {
91 KEY_PREV_ON();
92 }
93 _delay_us(10);
94
95 // NOTE: KEY_STATE is valid only in 20us after KEY_ENABLE.
96 // If V-USB interrupts in this section we could lose 40us or so
97 // and would read invalid value from KEY_STATE.
98 uint8_t last = TIMER_RAW;
99
100 KEY_ENABLE();
101
102 // Wait for KEY_STATE outputs its value.
103 // 1us was ok on one HHKB, but not worked on another.
104 // no wait doesn't work on Teensy++ with pro(1us works)
105 // no wait does work on tmk PCB(8MHz) with pro2
106 // 1us wait does work on both of above
107 // 1us wait doesn't work on tmk(16MHz)
108 // 5us wait does work on tmk(16MHz)
109 // 5us wait does work on tmk(16MHz/2)
110 // 5us wait does work on tmk(8MHz)
111 // 10us wait does work on Teensy++ with pro
112 // 10us wait does work on 328p+iwrap with pro
113 // 10us wait doesn't work on tmk PCB(8MHz) with pro2(very lagged scan)
114 _delay_us(5);
115
116 if (KEY_STATE()) {
117 matrix[row] &= ~(1<<col);
118 } else {
119 matrix[row] |= (1<<col);
120 }
121
122 // Ignore if this code region execution time elapses more than 20us.
123 // MEMO: 20[us] * (TIMER_RAW_FREQ / 1000000)[count per us]
124 // MEMO: then change above using this rule: a/(b/c) = a*1/(b/c) = a*(c/b)
125 if (TIMER_DIFF_RAW(TIMER_RAW, last) > 20/(1000000/TIMER_RAW_FREQ)) {
126 matrix[row] = matrix_prev[row];
127 }
128
129 _delay_us(5);
130 KEY_PREV_OFF();
131 KEY_UNABLE();
132
133 // NOTE: KEY_STATE keep its state in 20us after KEY_ENABLE.
134 // This takes 25us or more to make sure KEY_STATE returns to idle state.
135#ifdef HHKB_JP
136 // Looks like JP needs faster scan due to its twice larger matrix
137 // or it can drop keys in fast key typing
138 _delay_us(30);
139#else
140 _delay_us(75);
141#endif
142 }
143 if (matrix[row] ^ matrix_prev[row]) matrix_last_modified = timer_read32();
144 }
145 // power off
146 if (KEY_POWER_STATE() &&
147 (USB_DeviceState == DEVICE_STATE_Suspended ||
148 USB_DeviceState == DEVICE_STATE_Unattached ) &&
149 timer_elapsed32(matrix_last_modified) > MATRIX_POWER_SAVE) {
150 KEY_POWER_OFF();
151 suspend_power_down();
152 }
153 return 1;
154}
155
156bool matrix_is_modified(void)
157{
158 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
159 if (matrix[i] != matrix_prev[i])
160 return true;
161 }
162 return false;
163}
164
165inline
166bool matrix_has_ghost(void)
167{
168 return false;
169}
170
171inline
172bool matrix_is_on(uint8_t row, uint8_t col)
173{
174 return (matrix[row] & (1<<col));
175}
176
177inline
178matrix_row_t matrix_get_row(uint8_t row)
179{
180 return matrix[row];
181}
182
183void matrix_print(void)
184{
185 print("\nr/c 01234567\n");
186 for (uint8_t row = 0; row < matrix_rows(); row++) {
187 xprintf("%02X: %08b\n", row, bitrev(matrix_get_row(row)));
188 }
189}
190
191void matrix_power_up(void) {
192 KEY_POWER_ON();
193}
194void matrix_power_down(void) {
195 KEY_POWER_OFF();
196}