aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--converter/pc98_usb/Makefile83
-rw-r--r--converter/pc98_usb/README79
-rw-r--r--converter/pc98_usb/command_extra.c43
-rw-r--r--converter/pc98_usb/config.h94
-rw-r--r--converter/pc98_usb/keymap.c192
-rw-r--r--converter/pc98_usb/led.c33
-rw-r--r--converter/pc98_usb/matrix.c179
-rw-r--r--protocol/serial_soft.c18
8 files changed, 720 insertions, 1 deletions
diff --git a/converter/pc98_usb/Makefile b/converter/pc98_usb/Makefile
new file mode 100644
index 000000000..076371dbf
--- /dev/null
+++ b/converter/pc98_usb/Makefile
@@ -0,0 +1,83 @@
1# Target file name (without extension).
2TARGET = pc98_usb
3
4# Directory common source filess exist
5TOP_DIR = ../..
6
7# Directory keyboard dependent files exist
8TARGET_DIR = .
9
10# keyboard dependent files
11SRC = keymap.c \
12 matrix.c \
13 led.c \
14 command_extra.c \
15 protocol/serial_soft.c
16
17CONFIG_H = config.h
18
19
20# MCU name, you MUST set this to match the board you are using
21# type "make clean" after changing this, so all files will be rebuilt
22#MCU = at90usb162 # Teensy 1.0
23MCU = atmega32u4 # Teensy 2.0
24#MCU = at90usb646 # Teensy++ 1.0
25#MCU = at90usb1286 # Teensy++ 2.0
26
27
28# Processor frequency.
29# Normally the first thing your program should do is set the clock prescaler,
30# so your program will run at the correct speed. You should also set this
31# variable to same clock speed. The _delay_ms() macro uses this, and many
32# examples use this variable to calculate timings. Do not add a "UL" here.
33F_CPU = 16000000
34
35
36#
37# LUFA specific
38#
39# Target architecture (see library "Board Types" documentation).
40ARCH = AVR8
41
42# Input clock frequency.
43# This will define a symbol, F_USB, in all source code files equal to the
44# input clock frequency (before any prescaling is performed) in Hz. This value may
45# differ from F_CPU if prescaling is used on the latter, and is required as the
46# raw input clock is fed directly to the PLL sections of the AVR for high speed
47# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
48# at the end, this will be done automatically to create a 32-bit value in your
49# source code.
50#
51# If no clock division is performed on the input clock inside the AVR (via the
52# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
53F_USB = $(F_CPU)
54
55# Interrupt driven control endpoint task
56OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
57
58
59# Build Options
60# *Comment out* to disable the options.
61#
62MOUSEKEY_ENABLE = yes # Mouse keys
63EXTRAKEY_ENABLE = yes # Audio control and System control
64CONSOLE_ENABLE = yes # Console for debug
65#NKRO_ENABLE = yes # USB Nkey Rollover
66
67
68# Boot Section Size in bytes
69# Teensy halfKay 512
70# Atmel DFU loader 4096
71# LUFA bootloader 4096
72OPT_DEFS += -DBOOT_SIZE=4096
73
74
75# Search Path
76VPATH += $(TARGET_DIR)
77VPATH += $(TOP_DIR)
78
79
80include $(TOP_DIR)/protocol/lufa.mk
81include $(TOP_DIR)/protocol.mk
82include $(TOP_DIR)/common.mk
83include $(TOP_DIR)/rules.mk
diff --git a/converter/pc98_usb/README b/converter/pc98_usb/README
new file mode 100644
index 000000000..7b4f95ca2
--- /dev/null
+++ b/converter/pc98_usb/README
@@ -0,0 +1,79 @@
1Sun to USB keyboard protocol converter
2======================================
3Target MCU is ATMega32u4 but other USB capable AVR will also work.
4Supported keyboards: Sun Type 5 Keyboard, CTCSP SHORT TYPE KEYBOARD(CKUB)
5
6CTCSP SHORT TYPE KEYBOARD: http://imgur.com/a/QIv6p
7
8
9
10
11Connector
12---------
13 8Pin mini DIN
14 ___ ___
15 / |_| \
16 / 8 7 6 \
17 | 5 4 3 |
18 \_ 2 1 _/
19 \_____/
20 (receptacle)
21
22 Wiring:
23 Pin mini DIN MCU
24 ----------------------------------
25 1 GND GND
26 2 GND GND
27 3 5V
28 4 RX/TX(Mouse)
29 5 RX PD3
30 6 TX PD2
31 7 GND GND
32 8 5V VCC
33
34
35Protocol
36--------
37Singnal: Asynchronous, Negative logic, 1200baud, No Flow control
38Frame format: 1-Start bit, 8-Data bits, No-Parity, 1-Stop bit
39
40 AVR USART engine expects positive logic while Sun keyboard signal is negative.
41 To use AVR UART engine you need exteral inverter in front of RX and TX pin.
42 Otherwise you can software serial routine to communicate the keyboard.
43
44This converter uses software method, you doesn't need any inverter part.
45
46
47Commands From System To Keyboard
48 0x01 Reset
49 Keyboard responds with following byte sequence:
50 Success: 0xFF 0x04 0x7F
51 Fail: 0x7E 0x01 0x7F
52 0x02 Bell On
53 0x03 Bell Off
54 0x0A Click On
55 0x0B Click Off
56 0x0E LED
57 followed by LED status byte:
58 bit: 3 2 1 0
59 LED: CapsLk ScrLk Compose NumLk
60 0x0F Layout
61 Keyboard responds with 'Layout Response' 0xFE 0xXX
62
63Commands From Keyboard To System
64 0x7F Idle
65 means no keys pressed.
66 0xFE Layout Response
67 0xFF Reset Response(followed by 0x04)
68
69Reference
70 http://kentie.net/article/sunkbd/page2.htm
71 http://kentie.net/article/sunkbd/KBD.pdf
72
73
74Build Firmware
75--------------
76Just use 'make'
77 $ cd sun_usb
78 $ make
79Then, load the binary to MCU with your favorite programmer.
diff --git a/converter/pc98_usb/command_extra.c b/converter/pc98_usb/command_extra.c
new file mode 100644
index 000000000..50389467e
--- /dev/null
+++ b/converter/pc98_usb/command_extra.c
@@ -0,0 +1,43 @@
1#include "stdbool.h"
2#include "stdint.h"
3#include "keycode.h"
4#include "serial.h"
5#include "print.h"
6#include "command.h"
7
8bool command_extra(uint8_t code)
9{
10 switch (code) {
11 case KC_H:
12 case KC_SLASH: /* ? */
13 print("\n\n----- Sun converter Help -----\n");
14 print("UP: Bell On\n");
15 print("DOWN: Bell Off\n");
16 print("LEFT: Click On\n");
17 print("RIGHT: Click Off\n");
18 return false;
19 case KC_UP:
20 print("Bell On\n");
21 serial_send(0x02);
22 break;
23 case KC_DOWN:
24 print("Bell Off\n");
25 serial_send(0x03);
26 break;
27 case KC_LEFT:
28 print("Click On\n");
29 serial_send(0x0A);
30 break;
31 case KC_RIGHT:
32 print("Click Off\n");
33 serial_send(0x0B);
34 break;
35 case KC_NUMLOCK:
36 print("layout\n");
37 serial_send(0x0F);
38 break;
39 default:
40 return false;
41 }
42 return true;
43}
diff --git a/converter/pc98_usb/config.h b/converter/pc98_usb/config.h
new file mode 100644
index 000000000..8bcaa26db
--- /dev/null
+++ b/converter/pc98_usb/config.h
@@ -0,0 +1,94 @@
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#define VENDOR_ID 0xFEED
22#define PRODUCT_ID 0x3333
23#define DEVICE_VER 0x0100
24#define MANUFACTURER t.m.k.
25#define PRODUCT PC98 keyboard converter
26#define DESCRIPTION converts PC98 keyboard protocol into USB
27
28
29/* matrix size */
30#define MATRIX_ROWS 16
31#define MATRIX_COLS 8
32
33
34/* key combination for command */
35#define IS_COMMAND() ( \
36 keyboard_report->mods == (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT)) || \
37 keyboard_report->mods == (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI)) || \
38 keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
39)
40
41/* PC98 control */
42#define PC98_RST_DDR DDRD
43#define PC98_RST_PORT PORTD
44#define PC98_RST_BIT 1
45#define PC98_RDY_DDR DDRD
46#define PC98_RDY_PORT PORTD
47#define PC98_RDY_BIT 4
48#define PC98_RTY_DDR DDRD
49#define PC98_RTY_PORT PORTD
50#define PC98_RTY_BIT 5
51
52/* Serial(USART) configuration
53 * asynchronous, negative logic, 19200baud, no flow control
54 * 1-start bit, 8-data bit, odd parity, 1-stop bit
55 */
56#define SERIAL_BAUD 19200
57#define SERIAL_PARITY_ODD
58#define SERIAL_BIT_ORDER_MSB
59
60#define SERIAL_RXD_DDR DDRD
61#define SERIAL_RXD_PORT PORTD
62#define SERIAL_RXD_PIN PIND
63#define SERIAL_RXD_BIT 2
64#define SERIAL_RXD_VECT INT2_vect
65#define SERIAL_RXD_INIT() do { \
66 /* pin configuration: input with pull-up */ \
67 SERIAL_RXD_DDR &= ~(1<<SERIAL_RXD_BIT); \
68 SERIAL_RXD_PORT |= (1<<SERIAL_RXD_BIT); \
69 /* enable interrupt: INT2(rising edge) */ \
70 EICRA |= ((1<<ISC21)|(1<<ISC20)); \
71 EIMSK |= (1<<INT2); \
72} while (0)
73#define SERIAL_RXD_INT_ENTER()
74#define SERIAL_RXD_INT_EXIT() do { \
75 /* clear interrupt flag */ \
76 EIFR = (1<<INTF2); \
77} while (0)
78#define SERIAL_RXD_READ() (~SERIAL_RXD_PIN&(1<<SERIAL_RXD_BIT))
79
80#define SERIAL_TXD_DDR DDRD
81#define SERIAL_TXD_PORT PORTD
82#define SERIAL_TXD_PIN PIND
83#define SERIAL_TXD_BIT 3
84/* negative logic */
85#define SERIAL_TXD_ON() do { SERIAL_TXD_PORT &= ~(1<<SERIAL_TXD_BIT); } while (0)
86#define SERIAL_TXD_OFF() do { SERIAL_TXD_PORT |= (1<<SERIAL_TXD_BIT); } while (0)
87#define SERIAL_TXD_INIT() do { \
88 /* pin configuration: output */ \
89 SERIAL_TXD_DDR |= (1<<SERIAL_TXD_BIT); \
90 /* idle */ \
91 SERIAL_TXD_ON(); \
92} while (0)
93
94#endif
diff --git a/converter/pc98_usb/keymap.c b/converter/pc98_usb/keymap.c
new file mode 100644
index 000000000..048a863ca
--- /dev/null
+++ b/converter/pc98_usb/keymap.c
@@ -0,0 +1,192 @@
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#include <stdint.h>
19#include <stdbool.h>
20#include <avr/pgmspace.h>
21#include "keycode.h"
22#include "util.h"
23#include "keymap.h"
24
25
26
27
28/* Sun type 5 keyboard
29,-------. ,---, ,---------------. ,---------------. ,---------------. ,-----------. ,---------------.
30| 76 | | | | 05| 06| 08| 0A| | 0C| 0E| 10| 11| | 12| 07| 09| 0B| | 16| 17| 15| | 2D| 02| 04| 30|
31`-------' `---' `---------------' `---------------' `---------------' `-----------' `---------------'
32,-------. ,-----------------------------------------------------------. ,-----------. ,---------------.
33| 01| 03| | 1D| 1E| 1F| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 58| 2A| | 2C| 34| 60| | 62| 2E| 2F| 47|
34|-------| |-----------------------------------------------------------| |------------ |---------------|
35| 19| 1A| | 35 | 36| 37| 38| 39| 3A| 3B| 3C| 3D| 3E| 3F| 40| 41| 2B | | 42| 4A| 7B| | 44| 45| 46| |
36|-------| |-----------------------------------------------------------| `-----------' |-----------| 7D|
37| 31| 33| | 4C | 4D| 4E| 4F| 50| 51| 52| 53| 54| 55| 56| 57| 59 | | 5B| 5C| 5D| |
38|-------| |-----------------------------------------------------------| ,---. |-----------|---|
39| 48| 49| | 63 | 64| 65| 66| 67| 68| 69| 6A| 6B| 6C| 6D| 6E | | 14| | 70| 71| 72| |
40|-------| |-----------------------------------------------------------| .-----------. |-----------| 5A|
41| 5F| 61| | 77 | 13| 78 |*73 | 79 |*74 |*75| 7A | 43| 0D| | 18| 1B| 1C| | 5E | 32| |
42`-------' `-----------------------------------------------------------' `-----------' `---------------'
43*/
44#define KEYMAP( \
45 K76, K05,K06,K08,K0A, K0C,K0E,K10,K11, K12,K07,K09,K0B, K16,K17,K15, K2D,K02,K04,K30, \
46 K01,K03, K1D,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K58,K2A, K2C,K34,K60, K62,K2E,K2F,K47, \
47 K19,K1A, K35, K36,K37,K38,K39,K3A,K3B,K3C,K3D,K3E,K3F,K40,K41, K2B, K42,K4A,K7B, K44,K45,K46,K7D, \
48 K31,K33, K4C, K4D,K4E,K4F,K50,K51,K52,K53,K54,K55,K56,K57, K59, K5B,K5C,K5D, \
49 K48,K49, K63, K64,K65,K66,K67,K68,K69,K6A,K6B,K6C,K6D, K6E, K14, K70,K71,K72,K5A, \
50 K5F,K61, K77,K13, K78, K73, K79, K74, K75, K7A, K43, K0D, K18,K1B,K1C, K5E, K32 \
51) { \
52 { KC_NO, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07 }, \
53 { KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D, KC_##K0E, KC_NO, }, \
54 { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17 }, \
55 { KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E, KC_##K1F }, \
56 { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27 }, \
57 { KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2E, KC_##K2F }, \
58 { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37 }, \
59 { KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E, KC_##K3F }, \
60 { KC_##K40, KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46, KC_##K47 }, \
61 { KC_##K48, KC_##K49, KC_##K4A, KC_NO, KC_##K4C, KC_##K4D, KC_##K4E, KC_##K4F }, \
62 { KC_##K50, KC_##K51, KC_##K52, KC_##K53, KC_##K54, KC_##K55, KC_##K56, KC_##K57 }, \
63 { KC_##K58, KC_##K59, KC_##K5A, KC_##K5B, KC_##K5C, KC_##K5D, KC_##K5E, KC_##K5F }, \
64 { KC_##K60, KC_##K61, KC_##K62, KC_##K63, KC_##K64, KC_##K65, KC_##K66, KC_##K67 }, \
65 { KC_##K68, KC_##K69, KC_##K6A, KC_##K6B, KC_##K6C, KC_##K6D, KC_##K6E, KC_NO }, \
66 { KC_##K70, KC_##K71, KC_##K72, KC_##K73, KC_##K74, KC_##K75, KC_##K76, KC_##K77 }, \
67 { KC_##K78, KC_##K79, KC_##K7A, KC_##K7B, KC_NO, KC_##K7D, KC_NO, KC_NO } \
68}
69
70/* CTCSP SHORT TYPE KEYBOARD */
71#define SHORT_TYPE( \
72 K01, K05,K06,K08,K0A,K0C,K0E, K61,K49,K33, K30, K2C,K34,K60, \
73 K10,K11,K12,K07,K09,K0B, K42,K4A,K7B, \
74 K1D,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K58,K2A, \
75 K35, K36,K37,K38,K39,K3A,K3B,K3C,K3D,K3E,K3F,K40,K41, K2B, \
76 K4C, K4D,K4E,K4F,K50,K51,K52,K53,K54,K55,K56,K57, K59, \
77 K63, K64,K65,K66,K67,K68,K69,K6A,K6B,K6C,K6D, K0D,K14,K6E, \
78 K77,K13, K78, K79, K7A,K43,K62,K18,K1B,K1C \
79) KEYMAP( \
80 HELP, K05,K06,K08,K0A, K0C,K0E,K10,K11, K12,K07,K09,K0B, PSCR,SLCK,PAUS, MUTE,VOLD,VOLU,PWR, \
81 K01, AGAIN, K1D,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K58,K2A, K2C, K34, K60, K62, PSLS,PAST,PMNS, \
82 MENU, UNDO, K35, K36,K37,K38,K39,K3A,K3B,K3C,K3D,K3E,K3F,K40,K41, K2B, K42, K4A, K7B, P7, P8, P9, PPLS, \
83 SELECT, COPY, K4C, K4D,K4E,K4F,K50,K51,K52,K53,K54,K55,K56,K57, K59, P4, P5, P6, \
84 EXECUTE,PASTE, K63, K64,K65,K66,K67,K68,K69,K6A,K6B,K6C,K6D, K6E, K14, P1, P2, P3, PENT, \
85 FIND, CUT, K77,K13, K78, HENK, K79, MHEN, KANA, K7A,K43,K0D, K18, K1B, K1C, P0, PDOT \
86)
87
88
89// Assign Fn key(0-7) to a layer to which switch with the Fn key pressed.
90static const uint8_t PROGMEM fn_layer[] = {
91 2, // Fn0
92 3, // Fn1
93 4, // Fn2
94 0, // Fn3
95 0, // Fn4
96 0, // Fn5
97 0, // Fn6
98 0 // Fn7
99};
100
101// Assign Fn key(0-7) to a keycode sent when release Fn key without use of the layer.
102// See layer.c for details.
103static const uint8_t PROGMEM fn_keycode[] = {
104 KC_NO, // Fn0
105 KC_SCLN, // Fn1
106 KC_SLSH, // Fn2
107 KC_NO, // Fn3
108 KC_NO, // Fn4
109 KC_NO, // Fn5
110 KC_NO, // Fn6
111 KC_NO // Fn7
112};
113
114
115static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
116/*
117 KEYMAP(
118 HELP, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10,F11,F12, PSCR,SLCK,PAUS, MUTE,VOLD,VOLU,PWR,
119 STOP, AGAIN, ESC,1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS,
120 MENU, UNDO, TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, BSPC, DEL, END, PGDN, P7, P8, P9, PPLS,
121 SELECT, COPY, LCTL, A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, P4, P5, P6,
122 EXECUTE,PASTE, LSFT, Z, X, C, V, B, N, M, COMM,DOT,SLSH, RSFT, UP, P1, P2, P3, PENT,
123 FIND, CUT, CAPS, LALT, LGUI,HENK, SPC, MHEN,KANA,RGUI,APP, RALT, LEFT,DOWN,RGHT, P0, PDOT
124 ),
125*/
126 // 0: default
127 SHORT_TYPE(
128 STOP, F1,F2,F3,F4, F5, F6, CUT,PASTE,COPY,PWR, INS, HOME,PGUP,
129 F7,F8,F9,F10,F11,F12, DEL, END, PGDN,
130 ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV,
131 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, BSPC,
132 LCTL, A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT,
133 LSFT, Z, X, C, V, B, N, M, COMM,DOT, SLSH, RALT,UP, RSFT,
134 CAPS,LALT,LGUI, SPC, RGUI,APP, NLCK,LEFT,DOWN,RGHT
135 ),
136 // 1: with layer keys
137 SHORT_TYPE(
138 ESC, F1,F2,F3,F4, F5, F6, CUT,PASTE,COPY,PWR, INS, HOME,PGUP,
139 F7,F8,F9,F10,F11,F12, DEL, END, PGDN,
140 ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV,
141 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, BSPC,
142 LCTL, A, S, D, F, G, H, J, K, L, FN1, QUOT, ENT,
143 LSFT, Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,UP, FN0,
144 CAPS,LALT,LGUI, SPC, RGUI,RALT,FN0, LEFT,DOWN,RGHT
145 ),
146 // 2: HHKB
147 SHORT_TYPE(
148 ESC, F1,F2,F3,F4, F5, F6, CUT,PASTE,COPY,PWR, INS, HOME,PGUP,
149 F7,F8,F9,F10,F11,F12, DEL, END, PGDN,
150 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL,
151 CAPS, NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,PAUS,UP, NO, BSPC,
152 LCTL, VOLD,VOLU,MUTE,NO, NO, NO, NO, HOME,PGUP,LEFT,RGHT, ENT,
153 LSFT, Z, X, C, V, B, NO, NO, END, PGDN,DOWN, RSFT,PGUP,FN0,
154 CAPS,LALT,LGUI, SPC, RGUI,RALT,FN0, HOME,PGDN,END
155 ),
156 // 3: Mousekey
157 SHORT_TYPE(
158 ESC, F1,F2,F3,F4, F5, F6, CUT,PASTE,COPY,PWR, INS, HOME,PGUP,
159 F7,F8,F9,F10,F11,F12, DEL, END, PGDN,
160 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL,
161 CAPS, NO, NO, NO, NO, NO, WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSPC,
162 LCTL, NO, ACL0,ACL1,ACL2,NO, MS_L,MS_D,MS_U,MS_R,FN1, NO, ENT,
163 LSFT, NO, NO, NO, NO, BTN3,BTN2,BTN1,NO, NO, NO, RSFT,UP, NO,
164 CAPS,LALT,LGUI, BTN1, RGUI,RALT,NO, LEFT,DOWN,RGHT
165 ),
166 // 4: Cursor
167 SHORT_TYPE(
168 ESC, F1,F2,F3,F4, F5, F6, CUT,PASTE,COPY,PWR, INS, HOME,PGUP,
169 F7,F8,F9,F10,F11,F12, DEL, END, PGDN,
170 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL,
171 CAPS, NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, NO, NO, NO, BSPC,
172 LCTL, NO, NO, NO, NO, NO, LEFT,DOWN,UP, RGHT,NO, NO, ENT,
173 LSFT, NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, FN2, RSFT,UP, NO,
174 CAPS,LALT,LGUI, BTN1, RGUI,RALT,NO, LEFT,DOWN,RGHT
175 ),
176};
177
178
179uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col)
180{
181 return pgm_read_byte(&keymaps[(layer)][(row)][(col)]);
182}
183
184uint8_t keymap_fn_layer(uint8_t index)
185{
186 return pgm_read_byte(&fn_layer[index]);
187}
188
189uint8_t keymap_fn_keycode(uint8_t index)
190{
191 return pgm_read_byte(&fn_keycode[index]);
192}
diff --git a/converter/pc98_usb/led.c b/converter/pc98_usb/led.c
new file mode 100644
index 000000000..48c3f1c2b
--- /dev/null
+++ b/converter/pc98_usb/led.c
@@ -0,0 +1,33 @@
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#include "stdint.h"
19#include "serial.h"
20#include "led.h"
21
22
23void led_set(uint8_t usb_led)
24{
25 uint8_t sun_led = 0;
26 if (usb_led & (1<<USB_LED_NUM_LOCK)) sun_led |= (1<<0);
27 if (usb_led & (1<<USB_LED_COMPOSE)) sun_led |= (1<<1);
28 if (usb_led & (1<<USB_LED_SCROLL_LOCK)) sun_led |= (1<<2);
29 if (usb_led & (1<<USB_LED_CAPS_LOCK)) sun_led |= (1<<3);
30
31 serial_send(0x0E);
32 serial_send(sun_led);
33}
diff --git a/converter/pc98_usb/matrix.c b/converter/pc98_usb/matrix.c
new file mode 100644
index 000000000..b3c11dc21
--- /dev/null
+++ b/converter/pc98_usb/matrix.c
@@ -0,0 +1,179 @@
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#include <stdint.h>
19#include <stdbool.h>
20#include <avr/io.h>
21#include <util/delay.h>
22#include "print.h"
23#include "util.h"
24#include "matrix.h"
25#include "debug.h"
26#include "protocol/serial.h"
27
28
29/*
30 * Matrix Array usage:
31 *
32 * ROW: 16(4bits)
33 * COL: 8(3bits)
34 *
35 * 8bit wide
36 * +---------+
37 * 0|00 ... 07|
38 * 1|08 ... 0F|
39 * :| ... |
40 * :| ... |
41 * E|70 ... 77|
42 * F|78 ... 7F|
43 * +---------+
44 */
45static uint8_t matrix[MATRIX_ROWS];
46#define ROW(code) ((code>>3)&0xF)
47#define COL(code) (code&0x07)
48
49static bool is_modified = false;
50
51
52inline
53uint8_t matrix_rows(void)
54{
55 return MATRIX_ROWS;
56}
57
58inline
59uint8_t matrix_cols(void)
60{
61 return MATRIX_COLS;
62}
63
64void matrix_init(void)
65{
66 print_enable = true;
67 debug_enable = true;
68
69 PC98_RST_DDR |= (1<<PC98_RST_BIT);
70 PC98_RDY_DDR |= (1<<PC98_RDY_BIT);
71 PC98_RTY_DDR |= (1<<PC98_RTY_BIT);
72 PC98_RST_PORT |= (1<<PC98_RST_BIT);
73 PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
74 PC98_RTY_PORT |= (1<<PC98_RTY_BIT);
75
76
77 serial_init();
78
79 // PC98 reset
80 PC98_RST_PORT &= ~(1<<PC98_RST_BIT);
81 _delay_us(15);
82 PC98_RST_PORT |= (1<<PC98_RST_BIT);
83 _delay_us(13);
84 PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
85
86 // initialize matrix state: all keys off
87 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
88
89 debug("init\n");
90 return;
91}
92
93uint8_t matrix_scan(void)
94{
95 is_modified = false;
96
97 uint8_t code;
98 PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
99 code = serial_recv();
100 PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
101 if (!code) return 0;
102
103 debug_hex(code); debug(" ");
104
105/*
106 switch (code) {
107 case 0x7E: // reset fail
108 case 0xFE: // layout
109 case 0xFF: // reset success
110 _delay_ms(500);
111 // ignore response byte
112 debug("(response ignored:");
113 while ((code = serial_recv())) { debug(" "); debug_hex(code); }
114 debug(") ");
115 // FALL THROUGH
116 case 0x7F:
117 // all keys up
118 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
119 return 0;
120 }
121
122 if (code&0x80) {
123 // break code
124 if (matrix_is_on(ROW(code), COL(code))) {
125 matrix[ROW(code)] &= ~(1<<COL(code));
126 is_modified = true;
127 }
128 } else {
129 // make code
130 if (!matrix_is_on(ROW(code), COL(code))) {
131 matrix[ROW(code)] |= (1<<COL(code));
132 is_modified = true;
133 }
134 }
135*/
136 return code;
137}
138
139bool matrix_is_modified(void)
140{
141 return is_modified;
142}
143
144inline
145bool matrix_has_ghost(void)
146{
147 return false;
148}
149
150inline
151bool matrix_is_on(uint8_t row, uint8_t col)
152{
153 return (matrix[row] & (1<<col));
154}
155
156inline
157uint8_t matrix_get_row(uint8_t row)
158{
159 return matrix[row];
160}
161
162void matrix_print(void)
163{
164 print("\nr/c 01234567\n");
165 for (uint8_t row = 0; row < matrix_rows(); row++) {
166 phex(row); print(": ");
167 pbin_reverse(matrix_get_row(row));
168 print("\n");
169 }
170}
171
172uint8_t matrix_key_count(void)
173{
174 uint8_t count = 0;
175 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
176 count += bitpop(matrix[i]);
177 }
178 return count;
179}
diff --git a/protocol/serial_soft.c b/protocol/serial_soft.c
index beddc353c..e0661c3aa 100644
--- a/protocol/serial_soft.c
+++ b/protocol/serial_soft.c
@@ -106,11 +106,19 @@ ISR(SERIAL_RXD_VECT)
106 SERIAL_RXD_INT_ENTER() 106 SERIAL_RXD_INT_ENTER()
107 107
108 uint8_t data = 0; 108 uint8_t data = 0;
109
109#ifdef SERIAL_BIT_ORDER_MSB 110#ifdef SERIAL_BIT_ORDER_MSB
110 uint8_t mask = 0x80; 111 uint8_t mask = 0x80;
111#else 112#else
112 uint8_t mask = 0x01; 113 uint8_t mask = 0x01;
113#endif 114#endif
115
116#ifdef SERIAL_PARITY_ODD
117 uint8_t parity = 0;
118#else
119 uint8_t parity = 1;
120#endif
121
114 /* to center of start bit */ 122 /* to center of start bit */
115 _delay_us(WAIT_US/2); 123 _delay_us(WAIT_US/2);
116 do { 124 do {
@@ -119,6 +127,7 @@ ISR(SERIAL_RXD_VECT)
119 127
120 if (SERIAL_RXD_READ()) { 128 if (SERIAL_RXD_READ()) {
121 data |= mask; 129 data |= mask;
130 parity ^= 1;
122 } 131 }
123#ifdef SERIAL_BIT_ORDER_MSB 132#ifdef SERIAL_BIT_ORDER_MSB
124 mask >>= 1; 133 mask >>= 1;
@@ -126,11 +135,18 @@ ISR(SERIAL_RXD_VECT)
126 mask <<= 1; 135 mask <<= 1;
127#endif 136#endif
128 } while (mask); 137 } while (mask);
138
139 /* to center of parity bit */
140 _delay_us(WAIT_US);
141 parity ^= SERIAL_RXD_READ();
142
129 /* to center of stop bit */ 143 /* to center of stop bit */
130 _delay_us(WAIT_US); 144 _delay_us(WAIT_US);
145 _delay_us(WAIT_US/2);
131 146
147 parity = 1;
132 uint8_t next = (rbuf_head + 1) % RBUF_SIZE; 148 uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
133 if (next != rbuf_tail) { 149 if (parity && next != rbuf_tail) {
134 rbuf[rbuf_head] = data; 150 rbuf[rbuf_head] = data;
135 rbuf_head = next; 151 rbuf_head = next;
136 } 152 }