aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2014-08-20 13:36:15 +0900
committertmk <nobody@nowhere>2014-08-20 13:36:15 +0900
commit4f22a45b99abd6b018ac0ab8be915e45a9f88282 (patch)
tree65f334550b8a385ce15729299ac3188fff987e15
parent17f22da3cf3366344347b24b068fa4043a79d64b (diff)
downloadqmk_firmware-4f22a45b99abd6b018ac0ab8be915e45a9f88282.tar.gz
qmk_firmware-4f22a45b99abd6b018ac0ab8be915e45a9f88282.zip
Add support for HHKB JP
-rw-r--r--keyboard/hhkb_rn42/MEMO.txt1
-rw-r--r--keyboard/hhkb_rn42/Makefile26
-rw-r--r--keyboard/hhkb_rn42/config.h6
-rw-r--r--keyboard/hhkb_rn42/keymap_common.h27
-rw-r--r--keyboard/hhkb_rn42/matrix.c133
5 files changed, 59 insertions, 134 deletions
diff --git a/keyboard/hhkb_rn42/MEMO.txt b/keyboard/hhkb_rn42/MEMO.txt
index 02cd2e188..a5fa04db1 100644
--- a/keyboard/hhkb_rn42/MEMO.txt
+++ b/keyboard/hhkb_rn42/MEMO.txt
@@ -12,6 +12,7 @@ Improving:
12- Battry voltage display by command; like full(solid), medium(blink), low(flash) 12- Battry voltage display by command; like full(solid), medium(blink), low(flash)
13- move rn42 to protocol directory when it becomes reusable stack 13- move rn42 to protocol directory when it becomes reusable stack
14- LUFA sendchar should be buffered and serial_uart.c buffur size is too large(256). 14- LUFA sendchar should be buffered and serial_uart.c buffur size is too large(256).
15- keyboard LED update
15 16
16Testing: 17Testing:
17- Factroy reset doesn't work; need to **test again** 10K pull-up is too high? 18- Factroy reset doesn't work; need to **test again** 10K pull-up is too high?
diff --git a/keyboard/hhkb_rn42/Makefile b/keyboard/hhkb_rn42/Makefile
index b46b77789..e28b3e0be 100644
--- a/keyboard/hhkb_rn42/Makefile
+++ b/keyboard/hhkb_rn42/Makefile
@@ -53,12 +53,6 @@ SRC += keymap_common.c \
53 matrix.c \ 53 matrix.c \
54 led.c 54 led.c
55 55
56ifdef KEYMAP
57 SRC := keymap_$(KEYMAP).c $(SRC)
58else
59 SRC := keymap_hasu.c $(SRC)
60endif
61
62CONFIG_H = config.h 56CONFIG_H = config.h
63 57
64 58
@@ -124,6 +118,26 @@ CONSOLE_ENABLE = yes # Console for debug
124COMMAND_ENABLE = yes # Commands for debug and configuration 118COMMAND_ENABLE = yes # Commands for debug and configuration
125#NKRO_ENABLE = yes # USB Nkey Rollover 119#NKRO_ENABLE = yes # USB Nkey Rollover
126#KEYMAP_SECTION_ENABLE = yes # fixed address keymap for keymap editor 120#KEYMAP_SECTION_ENABLE = yes # fixed address keymap for keymap editor
121#HHKB_JP = yes # HHKB JP support
122
123
124ifdef HHKB_JP
125 OPT_DEFS += -DHHKB_JP
126endif
127
128
129#
130# Keymap file
131#
132ifdef KEYMAP
133 SRC := keymap_$(KEYMAP).c $(SRC)
134else
135 ifdef HHKB_JP
136 SRC := keymap_jp.c $(SRC)
137 else
138 SRC := keymap_hasu.c $(SRC)
139 endif
140endif
127 141
128 142
129# Search Path 143# Search Path
diff --git a/keyboard/hhkb_rn42/config.h b/keyboard/hhkb_rn42/config.h
index e641a5a2b..a46c7a8bf 100644
--- a/keyboard/hhkb_rn42/config.h
+++ b/keyboard/hhkb_rn42/config.h
@@ -28,7 +28,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
28 28
29 29
30/* matrix size */ 30/* matrix size */
31#define MATRIX_ROWS 8 31#ifdef HHKB_JP
32# define MATRIX_ROWS 16
33#else
34# define MATRIX_ROWS 8
35#endif
32#define MATRIX_COLS 8 36#define MATRIX_COLS 8
33 37
34 38
diff --git a/keyboard/hhkb_rn42/keymap_common.h b/keyboard/hhkb_rn42/keymap_common.h
index ec922a322..3622665f3 100644
--- a/keyboard/hhkb_rn42/keymap_common.h
+++ b/keyboard/hhkb_rn42/keymap_common.h
@@ -54,4 +54,31 @@ extern const uint16_t fn_actions[];
54 { KC_##K70, KC_##K71, KC_##K72, KC_##K73, KC_##K74, KC_##K75, KC_##K76, KC_NO } \ 54 { KC_##K70, KC_##K71, KC_##K72, KC_##K73, KC_##K74, KC_##K75, KC_##K76, KC_NO } \
55} 55}
56 56
57
58#define KEYMAP_JP( \
59 K02, K32, K62, K22, K12, K52, K72, KA2, K92, K82, KB2, KE2, KF2, KD2, KC2, \
60 K03, K63, K23, K13, K53, K73, KA3, K93, K83, KB3, KE3, KF3, KD3, \
61 K06, K66, K26, K16, K56, K76, KA6, K96, K86, KB6, KE6, KF6, KD6, KC6, \
62 K05, K65, K25, K15, K55, K75, KA5, K95, K85, KB5, KE5, KF5, KD5, KC5, \
63 K04, K34, K64, K24, K14, K74, K94, K84, KB4, KE4, KF4, KD4, KC4 \
64) \
65{ \
66 { KC_NO, KC_NO, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_NO }, \
67 { KC_NO, KC_NO, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_NO }, \
68 { KC_NO, KC_NO, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_NO }, \
69 { KC_NO, KC_NO, KC_##K32, KC_NO, KC_##K34, KC_NO, KC_NO, KC_NO }, \
70 { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
71 { KC_NO, KC_NO, KC_##K52, KC_##K53, KC_NO, KC_##K55, KC_##K56, KC_NO }, \
72 { KC_NO, KC_NO, KC_##K62, KC_##K63, KC_##K64, KC_##K65, KC_##K66, KC_NO }, \
73 { KC_NO, KC_NO, KC_##K72, KC_##K73, KC_##K74, KC_##K75, KC_##K76, KC_NO }, \
74 { KC_NO, KC_NO, KC_##K82, KC_##K83, KC_##K84, KC_##K85, KC_##K86, KC_NO }, \
75 { KC_NO, KC_NO, KC_##K92, KC_##K93, KC_##K94, KC_##K95, KC_##K96, KC_NO }, \
76 { KC_NO, KC_NO, KC_##KA2, KC_##KA3, KC_NO, KC_##KA5, KC_##KA6, KC_NO }, \
77 { KC_NO, KC_NO, KC_##KB2, KC_##KB3, KC_##KB4, KC_##KB5, KC_##KB6, KC_NO }, \
78 { KC_NO, KC_NO, KC_##KC2, KC_NO, KC_##KC4, KC_##KC5, KC_##KC6, KC_NO }, \
79 { KC_NO, KC_NO, KC_##KD2, KC_##KD3, KC_##KD4, KC_##KD5, KC_##KD6, KC_NO }, \
80 { KC_NO, KC_NO, KC_##KE2, KC_##KE3, KC_##KE4, KC_##KE5, KC_##KE6, KC_NO }, \
81 { KC_NO, KC_NO, KC_##KF2, KC_##KF3, KC_##KF4, KC_##KF5, KC_##KF6, KC_NO } \
82}
83
57#endif 84#endif
diff --git a/keyboard/hhkb_rn42/matrix.c b/keyboard/hhkb_rn42/matrix.c
index d0731ef1f..b0af4baa5 100644
--- a/keyboard/hhkb_rn42/matrix.c
+++ b/keyboard/hhkb_rn42/matrix.c
@@ -20,20 +20,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */ 20 */
21#include <stdint.h> 21#include <stdint.h>
22#include <stdbool.h> 22#include <stdbool.h>
23#include <avr/io.h>
24#include <avr/interrupt.h>
25#include <util/delay.h> 23#include <util/delay.h>
26#include "print.h" 24#include "print.h"
27#include "debug.h" 25#include "debug.h"
28#include "util.h" 26#include "util.h"
29#include "timer.h" 27#include "timer.h"
30#include "matrix.h" 28#include "matrix.h"
31 29#include "hhkb_avr.h"
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 30
38 31
39// matrix state buffer(1:on, 0:off) 32// matrix state buffer(1:on, 0:off)
@@ -43,122 +36,6 @@ static matrix_row_t _matrix0[MATRIX_ROWS];
43static matrix_row_t _matrix1[MATRIX_ROWS]; 36static matrix_row_t _matrix1[MATRIX_ROWS];
44 37
45 38
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 39inline
163uint8_t matrix_rows(void) 40uint8_t matrix_rows(void)
164{ 41{
@@ -199,13 +76,13 @@ uint8_t matrix_scan(void)
199 for (uint8_t row = 0; row < MATRIX_ROWS; row++) { 76 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
200 for (uint8_t col = 0; col < MATRIX_COLS; col++) { 77 for (uint8_t col = 0; col < MATRIX_COLS; col++) {
201 KEY_SELECT(row, col); 78 KEY_SELECT(row, col);
202 _delay_us(40); 79 _delay_us(5);
203 80
204 // Not sure this is needed. This just emulates HHKB controller's behaviour. 81 // Not sure this is needed. This just emulates HHKB controller's behaviour.
205 if (matrix_prev[row] & (1<<col)) { 82 if (matrix_prev[row] & (1<<col)) {
206 KEY_PREV_ON(); 83 KEY_PREV_ON();
207 } 84 }
208 _delay_us(7); 85 _delay_us(10);
209 86
210 // NOTE: KEY_STATE is valid only in 20us after KEY_ENABLE. 87 // 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 88 // If V-USB interrupts in this section we could lose 40us or so
@@ -241,11 +118,13 @@ uint8_t matrix_scan(void)
241 matrix[row] = matrix_prev[row]; 118 matrix[row] = matrix_prev[row];
242 } 119 }
243 120
121 _delay_us(5);
244 KEY_PREV_OFF(); 122 KEY_PREV_OFF();
245 KEY_UNABLE(); 123 KEY_UNABLE();
124
246 // NOTE: KEY_STATE keep its state in 20us after KEY_ENABLE. 125 // 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. 126 // This takes 25us or more to make sure KEY_STATE returns to idle state.
248 _delay_us(150); 127 _delay_us(75);
249 } 128 }
250 } 129 }
251 KEY_POWER_OFF(); 130 KEY_POWER_OFF();