aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2014-06-25 13:57:36 +0900
committertmk <nobody@nowhere>2014-07-30 14:38:25 +0900
commit4069776c022502f117b83b66c5a71700135acfbc (patch)
treed1259941dc233d6fe553edeeee7cce24cbf2b647
parentea60dae6e69bd3b120f2f702aeea691cb6d3d790 (diff)
downloadqmk_firmware-4069776c022502f117b83b66c5a71700135acfbc.tar.gz
qmk_firmware-4069776c022502f117b83b66c5a71700135acfbc.zip
Add initial files for RN-42
-rw-r--r--keyboard/hhkb_rn42/Makefile142
-rw-r--r--keyboard/hhkb_rn42/config.h67
-rw-r--r--keyboard/hhkb_rn42/keymap_common.c33
-rw-r--r--keyboard/hhkb_rn42/keymap_common.h57
-rw-r--r--keyboard/hhkb_rn42/keymap_hasu.c280
-rw-r--r--keyboard/hhkb_rn42/led.c33
-rw-r--r--keyboard/hhkb_rn42/main.c67
-rw-r--r--keyboard/hhkb_rn42/matrix.c288
-rw-r--r--keyboard/hhkb_rn42/rn42.c37
-rw-r--r--keyboard/hhkb_rn42/rn42.h6
10 files changed, 1010 insertions, 0 deletions
diff --git a/keyboard/hhkb_rn42/Makefile b/keyboard/hhkb_rn42/Makefile
new file mode 100644
index 000000000..7b3b993b7
--- /dev/null
+++ b/keyboard/hhkb_rn42/Makefile
@@ -0,0 +1,142 @@
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_lufa
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_common.c \
53 matrix.c \
54 led.c \
55 main.c
56
57ifdef KEYMAP
58 SRC := keymap_$(KEYMAP).c $(SRC)
59else
60 SRC := keymap_hhkb.c $(SRC)
61endif
62
63CONFIG_H = config.h
64
65
66# MCU name
67# PJRC Teensy++ 2.0
68#MCU = at90usb1286
69# TMK Alt Controller or PJRC Teensy 2.0
70MCU = atmega32u4
71
72# Processor frequency.
73# This will define a symbol, F_CPU, in all source code files equal to the
74# processor frequency in Hz. You can then use this symbol in your source code to
75# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
76# automatically to create a 32-bit value in your source code.
77#
78# This will be an integer division of F_USB below, as it is sourced by
79# F_USB after it has run through any CPU prescalers. Note that this value
80# does not *change* the processor frequency - it should merely be updated to
81# reflect the processor speed set externally so that the code can use accurate
82# software delays.
83F_CPU = 16000000
84
85
86#
87# LUFA specific
88#
89# Target architecture (see library "Board Types" documentation).
90ARCH = AVR8
91
92# Input clock frequency.
93# This will define a symbol, F_USB, in all source code files equal to the
94# input clock frequency (before any prescaling is performed) in Hz. This value may
95# differ from F_CPU if prescaling is used on the latter, and is required as the
96# raw input clock is fed directly to the PLL sections of the AVR for high speed
97# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
98# at the end, this will be done automatically to create a 32-bit value in your
99# source code.
100#
101# If no clock division is performed on the input clock inside the AVR (via the
102# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
103F_USB = $(F_CPU)
104
105# Interrupt driven control endpoint task
106#OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
107
108
109# Boot Section Size in *bytes*
110# Teensy halfKay 512
111# Teensy++ halfKay 1024
112# Atmel DFU loader 4096 (TMK Alt Controller)
113# LUFA bootloader 4096
114# USBaspLoader 2048
115OPT_DEFS += -DBOOTLOADER_SIZE=4096
116
117
118# Build Options
119# comment out to disable the options.
120#
121BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration
122MOUSEKEY_ENABLE = yes # Mouse keys
123EXTRAKEY_ENABLE = yes # Audio control and System control
124CONSOLE_ENABLE = yes # Console for debug
125COMMAND_ENABLE = yes # Commands for debug and configuration
126NKRO_ENABLE = yes # USB Nkey Rollover
127KEYMAP_SECTION_ENABLE = yes # fixed address keymap for keymap editor
128
129
130# Search Path
131VPATH += $(TARGET_DIR)
132VPATH += $(TOP_DIR)
133
134include $(TOP_DIR)/protocol/lufa.mk
135include $(TOP_DIR)/common.mk
136include $(TOP_DIR)/rules.mk
137
138debug-on: EXTRAFLAGS += -DDEBUG -DDEBUG_ACTION
139debug-on: all
140
141debug-off: EXTRAFLAGS += -DNO_DEBUG -DNO_PRINT
142debug-off: all
diff --git a/keyboard/hhkb_rn42/config.h b/keyboard/hhkb_rn42/config.h
new file mode 100644
index 000000000..a8f76ae6b
--- /dev/null
+++ b/keyboard/hhkb_rn42/config.h
@@ -0,0 +1,67 @@
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
22#define VENDOR_ID 0xFEED
23#define PRODUCT_ID 0xCAFE
24#define DEVICE_VER 0x0104
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(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)))
37
38
39/* period of tapping(ms) */
40#define TAPPING_TERM 300
41/* tap count needed for toggling a feature */
42#define TAPPING_TOGGLE 5
43/* Oneshot timeout(ms) */
44#define ONESHOT_TIMEOUT 300
45
46/* Boot Magic salt key: Space */
47#define BOOTMAGIC_KEY_SALT KC_FN6
48
49
50/*
51 * Feature disable options
52 * These options are also useful to firmware size reduction.
53 */
54/* disable debug print */
55//#define NO_DEBUG
56
57/* disable print */
58//#define NO_PRINT
59
60/* disable action features */
61//#define NO_ACTION_LAYER
62//#define NO_ACTION_TAPPING
63//#define NO_ACTION_ONESHOT
64//#define NO_ACTION_MACRO
65//#define NO_ACTION_FUNCTION
66
67#endif
diff --git a/keyboard/hhkb_rn42/keymap_common.c b/keyboard/hhkb_rn42/keymap_common.c
new file mode 100644
index 000000000..e938fb627
--- /dev/null
+++ b/keyboard/hhkb_rn42/keymap_common.c
@@ -0,0 +1,33 @@
1/*
2Copyright 2012,2013 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#include <stdint.h>
18#include "action.h"
19#include <avr/pgmspace.h>
20#include "keymap_common.h"
21
22
23/* translates key to keycode */
24uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
25{
26 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
27}
28
29/* translates Fn keycode to action */
30action_t keymap_fn_to_action(uint8_t keycode)
31{
32 return (action_t){ .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) };
33}
diff --git a/keyboard/hhkb_rn42/keymap_common.h b/keyboard/hhkb_rn42/keymap_common.h
new file mode 100644
index 000000000..ec922a322
--- /dev/null
+++ b/keyboard/hhkb_rn42/keymap_common.h
@@ -0,0 +1,57 @@
1/*
2Copyright 2012,2013 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#ifndef KEYMAP_COMMON_H
18#define KEYMAP_COMMON_H
19
20#include <stdint.h>
21#include <stdbool.h>
22#include "keycode.h"
23#include "action.h"
24#include "action_code.h"
25#include "action_layer.h"
26#include "action_macro.h"
27#include "action_util.h"
28#include "report.h"
29#include "host.h"
30#include "print.h"
31#include "debug.h"
32#include "keymap.h"
33
34
35extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
36extern const uint16_t fn_actions[];
37
38
39#define KEYMAP( \
40 K31, K30, K00, K10, K11, K20, K21, K40, K41, K60, K61, K70, K71, K50, K51, \
41 K32, K01, K02, K13, K12, K23, K22, K42, K43, K62, K63, K73, K72, K52, \
42 K33, K04, K03, K14, K15, K24, K25, K45, K44, K65, K64, K74, K53, \
43 K34, K05, K06, K07, K16, K17, K26, K46, K66, K76, K75, K55, K54, \
44 K35, K36, K37, K57, K56 \
45) \
46{ \
47 { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07 }, \
48 { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17 }, \
49 { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_NO }, \
50 { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37 }, \
51 { KC_##K40, KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46, KC_NO }, \
52 { KC_##K50, KC_##K51, KC_##K52, KC_##K53, KC_##K54, KC_##K55, KC_##K56, KC_##K57 }, \
53 { KC_##K60, KC_##K61, KC_##K62, KC_##K63, KC_##K64, KC_##K65, KC_##K66, KC_NO }, \
54 { KC_##K70, KC_##K71, KC_##K72, KC_##K73, KC_##K74, KC_##K75, KC_##K76, KC_NO } \
55}
56
57#endif
diff --git a/keyboard/hhkb_rn42/keymap_hasu.c b/keyboard/hhkb_rn42/keymap_hasu.c
new file mode 100644
index 000000000..e3d951bea
--- /dev/null
+++ b/keyboard/hhkb_rn42/keymap_hasu.c
@@ -0,0 +1,280 @@
1/*
2 * Hasu: my personal keymap
3 */
4#include "keymap_common.h"
5
6
7#ifdef KEYMAP_SECTION_ENABLE
8const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = {
9#else
10const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
11#endif
12 /* Layer 0: Default Layer
13 * ,-----------------------------------------------------------.
14 * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| \| `|
15 * |-----------------------------------------------------------|
16 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]|Backs|
17 * |-----------------------------------------------------------|
18 * |Contro| A| S| D| F| G| H| J| K| L|Fn3| '|Fn6 |
19 * |-----------------------------------------------------------|
20 * |Fn7 | Z| X| C| V| B| N| M| ,| .|Fn2|Shift |Fn1|
21 * `-----------------------------------------------------------'
22 * |Gui|Alt | Fn4 |Fn5 |Gui|
23 * `-------------------------------------------'
24 */
25 [0] = \
26 KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV, \
27 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \
28 LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT,FN6, \
29 FN7, Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \
30 LGUI,LALT, FN4, FN5, RGUI),
31
32 /* Layer 1: HHKB mode[HHKB Fn]
33 * ,-----------------------------------------------------------.
34 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
35 * |-----------------------------------------------------------|
36 * |Caps | | | | | | | |Psc|Slk|Pus|Up | |Backs|
37 * |-----------------------------------------------------------|
38 * |Contro|VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter |
39 * |-----------------------------------------------------------|
40 * |Shift | | | | | | +| -|End|PgD|Dow|Shift | |
41 * `-----------------------------------------------------------'
42 * |Gui|Alt | Space |Alt |Gui|
43 * `-------------------------------------------'
44 */
45 [1] = \
46 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
47 CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,PAUS, UP, NO, BSPC, \
48 LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \
49 LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,TRNS, \
50 LGUI,LALT, SPC, RALT,RGUI),
51
52 /* Layer 2: Vi mode[Slash]
53 * ,-----------------------------------------------------------.
54 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
55 * |-----------------------------------------------------------|
56 * |Tab |Hom|PgD|Up |PgU|End|Hom|PgD|PgUlEnd| | | |Backs|
57 * |-----------------------------------------------------------|
58 * |Contro| |Lef|Dow|Rig| |Lef|Dow|Up |Rig| | |Return |
59 * |-----------------------------------------------------------|
60 * |Shift | | | | | |Hom|PgD|PgUlEnd|Fn0|Shift | |
61 * `-----------------------------------------------------------'
62 * |Gui|Alt | Space |Alt |Gui|
63 * `-------------------------------------------'
64 */
65 [2] = \
66 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
67 TAB, HOME,PGDN,UP, PGUP,END, HOME,PGDN,PGUP,END, NO, NO, NO, BSPC, \
68 LCTL,NO, LEFT,DOWN,RGHT,NO, LEFT,DOWN,UP, RGHT,NO, NO, ENT, \
69 LSFT,NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, TRNS,RSFT,NO, \
70 LGUI,LALT, SPC, RALT,RGUI),
71
72 /* Layer 3: Mouse mode(IJKL)[Semicolon]
73 * ,-----------------------------------------------------------.
74 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
75 * |-----------------------------------------------------------|
76 * |Tab | | | | | |MwL|MwD|McU|MwU|MwR|Wbk|Wfr|Alt-T|
77 * |-----------------------------------------------------------|
78 * |Contro| | | | | |Mb2|McL|McD|McR|Fn | |Return |
79 * |-----------------------------------------------------------|
80 * |Shift | | | | |Mb3|Mb2|Mb1|Mb4|Mb5| |Shift | |
81 * `-----------------------------------------------------------'
82 * |Gui |Alt | Mb1 |Fn |Fn |
83 * `--------------------------------------------'
84 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel8
85 */
86 [3] = \
87 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
88 FN8, NO, NO, NO, NO, NO, WH_L,WH_D,MS_U,WH_U,WH_R,WBAK,WFWD,FN8, \
89 LCTL,ACL0,ACL1,ACL2,ACL2,NO, NO, MS_L,MS_D,MS_R,TRNS,NO, ENT, \
90 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,BTN4,BTN5,NO, RSFT,NO, \
91 LGUI,LALT, BTN1, TRNS,TRNS),
92
93 /* Layer 5: Mouse mode(IJKL)[Space]
94 * ,-----------------------------------------------------------.
95 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
96 * |-----------------------------------------------------------|
97 * |Tab | | | | | |MwL|MwD|McU|MwU|MwR|Wbk|Wfr|Alt-T|
98 * |-----------------------------------------------------------|
99 * |Contro| | | | | |Mb2|McL|McD|McR|Mb1| |Return |
100 * |-----------------------------------------------------------|
101 * |Shift | | | | |Mb3|Mb2|Mb1|Mb4|Mb5| |Shift | |
102 * `-----------------------------------------------------------'
103 * |Gui |Alt | Mb1 |Fn |Fn |
104 * `--------------------------------------------'
105 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel8
106 */
107 [4] = \
108 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
109 FN8, NO, NO, NO, NO, NO, WH_L,WH_D,MS_U,WH_U,WH_R,WBAK,WFWD,FN8, \
110 LCTL,VOLD,VOLU,MUTE,NO, NO, NO, MS_L,MS_D,MS_R,BTN1,NO, ENT, \
111 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,BTN4,BTN5,NO, RSFT,NO, \
112 LGUI,LALT, TRNS, TRNS,TRNS),
113
114#if 0
115 /* Layer 3: Mouse mode(HJKL)[Semicolon]
116 * ,-----------------------------------------------------------.
117 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
118 * |-----------------------------------------------------------|
119 * |Tab | | | | | |MwL|MwD|MwU|MwR| | | |Backs|
120 * |-----------------------------------------------------------|
121 * |Contro| | | | | |McL|McD|McU|McR|Fn0| |Return |
122 * |-----------------------------------------------------------|
123 * |Shift | | | | |Mb3|Mb2|Mb1|Mb4|Mb5| |Shift | |
124 * `-----------------------------------------------------------'
125 * |Gui |Alt | Mb1 |Alt |Fn0|
126 * `--------------------------------------------'
127 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
128 */
129 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
130 TAB, NO, NO, NO, NO, NO, WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSPC, \
131 LCTL,NO, ACL0,ACL1,ACL2,NO, MS_L,MS_D,MS_U,MS_R,TRNS,QUOT,ENT, \
132 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,BTN4,BTN5,SLSH,RSFT,NO, \
133 LGUI,LALT, BTN1, RALT,TRNS),
134
135 /* Layer4: Mouse mode(HJKL)[Space]
136 * ,-----------------------------------------------------------.
137 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
138 * |-----------------------------------------------------------|
139 * |Tab | | | | | |MwL|MwD|MwU|MwR| |Wbk|Wfr|Alt-T|
140 * |-----------------------------------------------------------|
141 * |Contro| | | | | |McL|McD|McU|McR|Fn0| |Return |
142 * |-----------------------------------------------------------|
143 * |Shift | | | | |Mb3|Mb2|Mb1|Mb4|Mb5| |Shift | |
144 * `-----------------------------------------------------------'
145 * |Gui |Alt | Fn0 |Alt |Fn0|
146 * `--------------------------------------------'
147 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
148 */
149 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
150 FN8, NO, NO, NO, NO, NO, WH_L,WH_D,WH_U,WH_R,NO, WBAK,WFWD,FN8, \
151 LCTL,NO, ACL0,ACL1,ACL2,NO, MS_L,MS_D,MS_U,MS_R,BTN1,NO, ENT, \
152 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,BTN4,BTN5,NO, RSFT,NO, \
153 LGUI,LALT, TRNS, RALT,RGUI),
154#endif
155#if 0
156 /* Layer x: Matias half-qwerty keyboard style[Space]
157 * ,-----------------------------------------------------------.
158 * | -| 0| 9| 8| 7| 6| 5| 4| 3| 2| 1| | | |Esc|
159 * |-----------------------------------------------------------|
160 * |Backs| P| O| I| U| Y| T| R| E| W| Q| | |Tab |
161 * |-----------------------------------------------------------|
162 * |Contro| ;| L| K| J| H| G| F| D| S| A|Con|Control |
163 * |-----------------------------------------------------------|
164 * |Shift | /| .| ,| M| N| B| V| C| X| Z|Shift | |
165 * `-----------------------------------------------------------'
166 * |Gui |Alt | Fn0 |Alt |Gui|
167 * `--------------------------------------------'
168 */
169 KEYMAP(MINS,0, 9, 8, 7, 6, 5, 4, 3, 2, 1, NO, NO, NO, ESC, \
170 BSPC,P, O, I, U, Y, T, R, E, W, Q, NO, NO, TAB, \
171 LCTL,SCLN,L, K, J, H, G, F, D, S, A, RCTL,RCTL, \
172 LSFT,SLSH,DOT, COMM,M, N, B, V, C, X, Z, RSFT,NO, \
173 LGUI,LALT, TRNS, RALT,RGUI),
174#endif
175};
176
177
178
179/* id for user defined functions */
180enum function_id {
181 LSHIFT_LPAREN,
182};
183
184enum macro_id {
185 HELLO,
186 VOLUP,
187 ALT_TAB,
188};
189
190
191/*
192 * Fn action definition
193 */
194#ifdef KEYMAP_SECTION_ENABLE
195const uint16_t fn_actions[] __attribute__ ((section (".keymap.fn_actions"))) = {
196#else
197const uint16_t fn_actions[] PROGMEM = {
198#endif
199 [0] = ACTION_DEFAULT_LAYER_SET(0), // Default layer(not used)
200 [1] = ACTION_LAYER_TAP_TOGGLE(1), // HHKB layer(toggle with 5 taps)
201 [2] = ACTION_LAYER_TAP_KEY(2, KC_SLASH), // Cursor layer with Slash*
202 [3] = ACTION_LAYER_TAP_KEY(3, KC_SCLN), // Mousekey layer with Semicolon*
203 [4] = ACTION_LAYER_TAP_KEY(4, KC_SPC), // Mousekey layer with Space
204 [5] = ACTION_LAYER_MOMENTARY(4), // Mousekey layer(IJKL)
205 [6] = ACTION_MODS_TAP_KEY(MOD_RCTL, KC_ENT), // RControl with tap Enter
206 [7] = ACTION_MODS_ONESHOT(MOD_LSFT), // Oneshot Shift
207 [8] = ACTION_MACRO(ALT_TAB), // Application switching
208
209// [x] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_BSPC), // LControl with tap Backspace
210// [x] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_ESC), // LControl with tap Esc
211// [x] = ACTION_FUNCTION_TAP(LSHIFT_LPAREN), // Function: LShift with tap '('
212// [x] = ACTION_MACRO(HELLO), // Macro: say hello
213// [x] = ACTION_MACRO(VOLUP), // Macro: media key
214};
215
216
217/*
218 * Macro definition
219 */
220const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
221{
222 switch (id) {
223 case HELLO:
224 return (record->event.pressed ?
225 MACRO( I(0), T(H), T(E), T(L), T(L), W(255), T(O), END ) :
226 MACRO_NONE );
227 case VOLUP:
228 return (record->event.pressed ?
229 MACRO( D(VOLU), U(VOLU), END ) :
230 MACRO_NONE );
231 case ALT_TAB:
232 return (record->event.pressed ?
233 MACRO( D(LALT), D(TAB), END ) :
234 MACRO( U(TAB), END ));
235 }
236 return MACRO_NONE;
237}
238
239
240
241/*
242 * user defined action function
243 */
244void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
245{
246 if (record->event.pressed) dprint("P"); else dprint("R");
247 dprintf("%d", record->tap.count);
248 if (record->tap.interrupted) dprint("i");
249 dprint("\n");
250
251 switch (id) {
252 case LSHIFT_LPAREN:
253 // Shift parentheses example: LShft + tap '('
254 // http://stevelosh.com/blog/2012/10/a-modern-space-cadet/#shift-parentheses
255 // http://geekhack.org/index.php?topic=41989.msg1304899#msg1304899
256 if (record->event.pressed) {
257 if (record->tap.count > 0 && !record->tap.interrupted) {
258 if (record->tap.interrupted) {
259 dprint("tap interrupted\n");
260 register_mods(MOD_BIT(KC_LSHIFT));
261 }
262 } else {
263 register_mods(MOD_BIT(KC_LSHIFT));
264 }
265 } else {
266 if (record->tap.count > 0 && !(record->tap.interrupted)) {
267 add_weak_mods(MOD_BIT(KC_LSHIFT));
268 send_keyboard_report();
269 register_code(KC_9);
270 unregister_code(KC_9);
271 del_weak_mods(MOD_BIT(KC_LSHIFT));
272 send_keyboard_report();
273 record->tap.count = 0; // ad hoc: cancel tap
274 } else {
275 unregister_mods(MOD_BIT(KC_LSHIFT));
276 }
277 }
278 break;
279 }
280}
diff --git a/keyboard/hhkb_rn42/led.c b/keyboard/hhkb_rn42/led.c
new file mode 100644
index 000000000..8a08fe27f
--- /dev/null
+++ b/keyboard/hhkb_rn42/led.c
@@ -0,0 +1,33 @@
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 <avr/io.h>
19#include "stdint.h"
20#include "led.h"
21
22
23/* HHKB has no LEDs */
24void led_set(uint8_t usb_led)
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 }
33}
diff --git a/keyboard/hhkb_rn42/main.c b/keyboard/hhkb_rn42/main.c
new file mode 100644
index 000000000..b6a8456f7
--- /dev/null
+++ b/keyboard/hhkb_rn42/main.c
@@ -0,0 +1,67 @@
1#include <avr/io.h>
2#include <avr/power.h>
3#include <avr/wdt.h>
4#include "lufa.h"
5#include "print.h"
6#include "sendchar.h"
7
8
9static void SetupHardware(void)
10{
11 /* Disable watchdog if enabled by bootloader/fuses */
12 MCUSR &= ~(1 << WDRF);
13 wdt_disable();
14
15 /* Disable clock division */
16 clock_prescale_set(clock_div_1);
17
18 // Leonardo needs. Without this USB device is not recognized.
19 USB_Disable();
20
21 USB_Init();
22
23 // for Console_Task
24 USB_Device_EnableSOFEvents();
25 print_set_sendchar(sendchar);
26}
27
28int main(void) __attribute__ ((weak));
29int main(void)
30{
31 SetupHardware();
32 sei();
33
34 /* wait for USB startup & debug output */
35 while (USB_DeviceState != DEVICE_STATE_Configured) {
36#if defined(INTERRUPT_CONTROL_ENDPOINT)
37 ;
38#else
39 USB_USBTask();
40#endif
41 }
42 print("USB configured.\n");
43
44 /* init modules */
45 keyboard_init();
46 host_set_driver(&lufa_driver);
47#ifdef SLEEP_LED_ENABLE
48 sleep_led_init();
49#endif
50
51 print("Keyboard start.\n");
52 while (1) {
53 while (USB_DeviceState == DEVICE_STATE_Suspended) {
54 suspend_power_down();
55 if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
56 USB_Device_SendRemoteWakeup();
57 }
58 }
59
60 keyboard_task();
61
62#if !defined(INTERRUPT_CONTROL_ENDPOINT)
63 USB_USBTask();
64#endif
65 }
66}
67
diff --git a/keyboard/hhkb_rn42/matrix.c b/keyboard/hhkb_rn42/matrix.c
new file mode 100644
index 000000000..d0731ef1f
--- /dev/null
+++ b/keyboard/hhkb_rn42/matrix.c
@@ -0,0 +1,288 @@
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 "debug.h"
28#include "util.h"
29#include "timer.h"
30#include "matrix.h"
31
32
33// Timer resolution check
34#if (1000000/TIMER_RAW_FREQ > 20)
35# error "Timer resolution(>20us) is not enough for HHKB matrix scan tweak on V-USB."
36#endif
37
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
46// Matrix I/O ports
47//
48// row: HC4051[A,B,C] selects scan row0-7
49// col: LS145[A,B,C,D] selects scan col0-7 and enable(D)
50// key: on: 0/off: 1
51// prev: unknown: output previous key state(negated)?
52
53#if defined(__AVR_AT90USB1286__)
54// Ports for Teensy++
55// row: PB0-2
56// col: PB3-5,6
57// key: PE6(pull-uped)
58// prev: PE7
59#define KEY_INIT() do { \
60 DDRB |= 0x7F; \
61 DDRE |= (1<<7); \
62 DDRE &= ~(1<<6); \
63 PORTE |= (1<<6); \
64} while (0)
65#define KEY_SELECT(ROW, COL) (PORTB = (PORTB & 0xC0) | \
66 (((COL) & 0x07)<<3) | \
67 ((ROW) & 0x07))
68#define KEY_ENABLE() (PORTB &= ~(1<<6))
69#define KEY_UNABLE() (PORTB |= (1<<6))
70#define KEY_STATE() (PINE & (1<<6))
71#define KEY_PREV_ON() (PORTE |= (1<<7))
72#define KEY_PREV_OFF() (PORTE &= ~(1<<7))
73#define KEY_POWER_ON()
74#define KEY_POWER_OFF()
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
120#elif defined(__AVR_ATmega328P__)
121// Ports for V-USB
122// key: PB0(pull-uped)
123// prev: PB1
124// row: PB2-4
125// col: PC0-2,3
126// power: PB5(Low:on/Hi-z:off)
127#define KEY_INIT() do { \
128 DDRB |= 0x3E; \
129 DDRB &= ~(1<<0); \
130 PORTB |= 1<<0; \
131 DDRC |= 0x0F; \
132 KEY_UNABLE(); \
133 KEY_PREV_OFF(); \
134} while (0)
135#define KEY_SELECT(ROW, COL) do { \
136 PORTB = (PORTB & 0xE3) | ((ROW) & 0x07)<<2; \
137 PORTC = (PORTC & 0xF8) | ((COL) & 0x07); \
138} while (0)
139#define KEY_ENABLE() (PORTC &= ~(1<<3))
140#define KEY_UNABLE() (PORTC |= (1<<3))
141#define KEY_STATE() (PINB & (1<<0))
142#define KEY_PREV_ON() (PORTB |= (1<<1))
143#define KEY_PREV_OFF() (PORTB &= ~(1<<1))
144// Power supply switching
145#define KEY_POWER_ON() do { \
146 KEY_INIT(); \
147 PORTB &= ~(1<<5); \
148 _delay_ms(1); \
149} while (0)
150#define KEY_POWER_OFF() do { \
151 DDRB &= ~0x3F; \
152 PORTB &= ~0x3F; \
153 DDRC &= ~0x0F; \
154 PORTC &= ~0x0F; \
155} while (0)
156
157#else
158# error "define code for matrix scan"
159#endif
160
161
162inline
163uint8_t matrix_rows(void)
164{
165 return MATRIX_ROWS;
166}
167
168inline
169uint8_t matrix_cols(void)
170{
171 return MATRIX_COLS;
172}
173
174void matrix_init(void)
175{
176#ifdef DEBUG
177 debug_enable = true;
178 debug_keyboard = true;
179#endif
180
181 KEY_INIT();
182
183 // initialize matrix state: all keys off
184 for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00;
185 for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00;
186 matrix = _matrix0;
187 matrix_prev = _matrix1;
188}
189
190uint8_t matrix_scan(void)
191{
192 uint8_t *tmp;
193
194 tmp = matrix_prev;
195 matrix_prev = matrix;
196 matrix = tmp;
197
198 KEY_POWER_ON();
199 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
200 for (uint8_t col = 0; col < MATRIX_COLS; col++) {
201 KEY_SELECT(row, col);
202 _delay_us(40);
203
204 // Not sure this is needed. This just emulates HHKB controller's behaviour.
205 if (matrix_prev[row] & (1<<col)) {
206 KEY_PREV_ON();
207 }
208 _delay_us(7);
209
210 // NOTE: KEY_STATE is valid only in 20us after KEY_ENABLE.
211 // If V-USB interrupts in this section we could lose 40us or so
212 // and would read invalid value from KEY_STATE.
213 uint8_t last = TIMER_RAW;
214
215 KEY_ENABLE();
216
217 // Wait for KEY_STATE outputs its value.
218 // 1us was ok on one HHKB, but not worked on another.
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
231 if (KEY_STATE()) {
232 matrix[row] &= ~(1<<col);
233 } else {
234 matrix[row] |= (1<<col);
235 }
236
237 // Ignore if this code region execution time elapses more than 20us.
238 // MEMO: 20[us] * (TIMER_RAW_FREQ / 1000000)[count per us]
239 // MEMO: then change above using this rule: a/(b/c) = a*1/(b/c) = a*(c/b)
240 if (TIMER_DIFF_RAW(TIMER_RAW, last) > 20/(1000000/TIMER_RAW_FREQ)) {
241 matrix[row] = matrix_prev[row];
242 }
243
244 KEY_PREV_OFF();
245 KEY_UNABLE();
246 // NOTE: KEY_STATE keep its state in 20us after KEY_ENABLE.
247 // This takes 25us or more to make sure KEY_STATE returns to idle state.
248 _delay_us(150);
249 }
250 }
251 KEY_POWER_OFF();
252 return 1;
253}
254
255bool matrix_is_modified(void)
256{
257 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
258 if (matrix[i] != matrix_prev[i])
259 return true;
260 }
261 return false;
262}
263
264inline
265bool matrix_has_ghost(void)
266{
267 return false;
268}
269
270inline
271bool matrix_is_on(uint8_t row, uint8_t col)
272{
273 return (matrix[row] & (1<<col));
274}
275
276inline
277matrix_row_t matrix_get_row(uint8_t row)
278{
279 return matrix[row];
280}
281
282void matrix_print(void)
283{
284 print("\nr/c 01234567\n");
285 for (uint8_t row = 0; row < matrix_rows(); row++) {
286 xprintf("%02X: %08b\n", row, bitrev(matrix_get_row(row)));
287 }
288}
diff --git a/keyboard/hhkb_rn42/rn42.c b/keyboard/hhkb_rn42/rn42.c
new file mode 100644
index 000000000..bbf05a392
--- /dev/null
+++ b/keyboard/hhkb_rn42/rn42.c
@@ -0,0 +1,37 @@
1#include "host.h"
2#include "host_driver.h"
3#include "rn42.h"
4
5
6/* Host driver */
7static uint8_t keyboard_leds(void);
8static void send_keyboard(report_keyboard_t *report);
9static void send_mouse(report_mouse_t *report);
10static void send_system(uint16_t data);
11static void send_consumer(uint16_t data);
12
13host_driver_t rn42_driver = {
14 keyboard_leds,
15 send_keyboard,
16 send_mouse,
17 send_system,
18 send_consumer
19};
20
21static uint8_t keyboard_leds(void) { return 0; }
22
23static void send_keyboard(report_keyboard_t *report)
24{
25}
26
27static void send_mouse(report_mouse_t *report)
28{
29}
30
31static void send_system(uint16_t data)
32{
33}
34
35static void send_consumer(uint16_t data)
36{
37}
diff --git a/keyboard/hhkb_rn42/rn42.h b/keyboard/hhkb_rn42/rn42.h
new file mode 100644
index 000000000..57ae17ba1
--- /dev/null
+++ b/keyboard/hhkb_rn42/rn42.h
@@ -0,0 +1,6 @@
1#ifndef RN42_H
2#define RN42_H
3
4host_driver_t rn42_driver;
5
6#endif