aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--x68k_usb/Makefile85
-rw-r--r--x68k_usb/README129
-rw-r--r--x68k_usb/config_pjrc.h66
-rw-r--r--x68k_usb/keymap.c140
-rw-r--r--x68k_usb/led.c26
-rw-r--r--x68k_usb/matrix.c141
-rw-r--r--x68k_usb/x68k.c75
-rw-r--r--x68k_usb/x68k.h47
8 files changed, 709 insertions, 0 deletions
diff --git a/x68k_usb/Makefile b/x68k_usb/Makefile
new file mode 100644
index 000000000..c4b9b221b
--- /dev/null
+++ b/x68k_usb/Makefile
@@ -0,0 +1,85 @@
1#
2# Makefile for PJRC Teensy
3#
4
5
6# Target file name (without extension).
7TARGET = x68k_usb_pjrc
8
9# Directory common source filess exist
10COMMON_DIR = ..
11
12# Directory keyboard dependent files exist
13TARGET_DIR = .
14
15# keyboard dependent files
16SRC = main.c \
17 keymap.c \
18 matrix.c \
19 led.c \
20 x68k.c
21
22CONFIG_H = config_pjrc.h
23
24
25# MCU name, you MUST set this to match the board you are using
26# type "make clean" after changing this, so all files will be rebuilt
27#MCU = at90usb162 # Teensy 1.0
28MCU = atmega32u4 # Teensy 2.0
29#MCU = at90usb646 # Teensy++ 1.0
30#MCU = at90usb1286 # Teensy++ 2.0
31
32
33# Processor frequency.
34# Normally the first thing your program should do is set the clock prescaler,
35# so your program will run at the correct speed. You should also set this
36# variable to same clock speed. The _delay_ms() macro uses this, and many
37# examples use this variable to calculate timings. Do not add a "UL" here.
38F_CPU = 16000000
39
40
41# Build Options
42# *Comment out* to disable the options.
43#
44MOUSEKEY_ENABLE = yes # Mouse keys
45EXTRAKEY_ENABLE = yes # Audio control and System control
46NKRO_ENABLE = yes # USB Nkey Rollover
47
48
49
50#---------------- Programming Options --------------------------
51AVRDUDE = avrdude
52# Type: avrdude -c ? to get a full listing.
53AVRDUDE_PROGRAMMER = avr109
54AVRDUDE_PORT = /dev/ttyACM0
55AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
56#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
57
58# Uncomment the following if you want avrdude's erase cycle counter.
59# Note that this counter needs to be initialized first using -Yn,
60# see avrdude manual.
61#AVRDUDE_ERASE_COUNTER = -y
62
63# Uncomment the following if you do /not/ wish a verification to be
64# performed after programming the device.
65#AVRDUDE_NO_VERIFY = -V
66
67# Increase verbosity level. Please use this when submitting bug
68# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
69# to submit bug reports.
70#AVRDUDE_VERBOSE = -v -v
71
72AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
73#AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER)
74AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
75AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
76AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
77
78#PROGRAM_CMD = $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
79#PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
80PROGRAM_CMD = dfu-programmer atmega32u4 flash $(TARGET).hex
81
82
83
84include $(COMMON_DIR)/pjrc.mk
85include $(COMMON_DIR)/common.mk
diff --git a/x68k_usb/README b/x68k_usb/README
new file mode 100644
index 000000000..0b61b2c4b
--- /dev/null
+++ b/x68k_usb/README
@@ -0,0 +1,129 @@
1X68000 to USB keyboard protocol converter
2=========================================
3SHARP X68000 is a hobby computer released in Japan.(1987-93)
4http://en.wikipedia.org/wiki/Sharp_X68000
5
6X68000 keyboard has ALPS linear switches.
7- DSETK0016CE01 green linear
8- DSETK0023CE03 yellow linear
9
10
11Hardware
12--------
13Target MCU is ATMega32u4 but other USB capable AVR will also work.
14You can use PJRC Teensy as dev board.
15 http://www.pjrc.com/teensy/
16
17Wiring:
18 Mini-DIN Teensy
19 -----------------------------------------------------
20 pin1 +5V VCC
21 pin2 MOUSE -
22 pin3 RXD PD2(RXD)
23 pin4 TXD PD3(TXD) NOTE: Not supported yet.
24 pin5 READY -
25 pin6 REMOTE -
26 pin7 GND GND
27
28
29Firmware
30--------
31Build:
32 $ cd x68k_usb
33 $ make
34
35And load the binary to MCU with your favorite programmer.
36If you use Teensy you can load with PJRC Teensy Loader tool.
37 http://www.pjrc.com/teensy/loader.html
38
39
40* * * * * * * * * * * * * * * * * *
41
42
43X68000 Keyboard Protocol
44========================
45http://kyoutan.jpn.org/uts/pc/pic/x68key/
46
47
48Connector
49---------
50Mini DIN 7pin(female connector on computer side)
51 7 6 5
52 o o o
53 4 o = o 3
54 o o
55 2 1
56
57 Mini-DIN
58 -------------
59 pin1 +5V
60 pin2 MOUSE
61 pin3 RXD
62 pin4 TXD
63 pin5 READY
64 pin6 REMOTE
65 pin7 GND
66
67
68Signaling
69---------
70- TXD,RXD
71 Asynchronous, 2400baud, 1-startbit(L), 8-databit, 1-stopbit(H)
72
73- READY
74 ready/not ready(1/0)
75
76
77Data from keyboard
78------------------
79bit 7 make/break flag(0/1)
80bit 6-0 following scan code
81
82
83Data from computer
84------------------
85- LED contorol ON/OFF(0/1)
86 bit 7 1(fixed)
87 bit 6 全角
88 bit 5 ひらがな
89 bit 4 INS
90 bit 3 CAPS
91 bit 2 コード入力
92 bit 1 ローマ字
93 bit 0 かな
94
95- Repeat delay
96 bit 7 0(fixed)
97 bit 6 1(fixed)
98 bit 5 1(fixed)
99 bit 4 0(fixed)
100 bit 3-0 delay
101 REPEAT_DELAY = 200+delay*100 ms
102 default: 500ms
103
104- Repeat time
105 bit 7 0(fixed)
106 bit 6 1(fixed)
107 bit 5 1(fixed)
108 bit 4 1(fixed)
109 bit 3-0 time
110 REPEAT_TIME = 30+time^2*5 ms
111 default: 110ms
112
113
114Scan Codes
115----------
116,---. ,---. ,-------------------, ,-------------------. ,-----------. ,---------------.
117| 61| | 62| | 63| 64| 65| 66| 67| | 68| 69| 6A| 6B| 6C| | 5A| 5B| 5C| | 5D| 52| 53| 54|
118`---' `---' `-------------------' `-------------------' `-----------' `---------------'
119,-----------------------------------------------------------. ,-----------. ,---------------.
120| 01| 02| 03| 04| 05| 06| 07| 08| 09| 0A| 0B| 0C| 0D| 0E| 0F| | 36| 5E| 37| | 3F| 40| 41| 42|
121|-----------------------------------------------------------| |------------ |---------------|
122| 10 | 11| 12| 13| 14| 15| 16| 17| 18| 19| 1A| 1B| 1C| | | 38| 39| 3A| | 43| 44| 45| 46|
123|------------------------------------------------------. 1D | `---=====---' |---------------|
124| 71 | 1E| 1F| 20| 21| 2l| 23| 24| 25| 26| 27| 28| 29| | ___| 3C|___ | 47| 48| 49| 4A|
125|-----------------------------------------------------------| | 3B|---| 3D| |-----------|---|
126| 70 | 2A| 2B| 2C| 2D| 2E| 2F| 30| 31| 32| 33| 34| 70 | `---| 3E|---' | 4B| 4C| 4D| |
127`-----------------------------------------------------------| .---=====---. |-----------| 4E|
128 | 5F| 55 | 56 | 35 | 57 | 58 | 59 | 60| | 72 | 73 | | 4F| 50| 51| |
129 `---------------------------------------------' `-----------' `---------------'
diff --git a/x68k_usb/config_pjrc.h b/x68k_usb/config_pjrc.h
new file mode 100644
index 000000000..20758bf24
--- /dev/null
+++ b/x68k_usb/config_pjrc.h
@@ -0,0 +1,66 @@
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/* controller configuration */
22#include "controller_teensy.h"
23
24#define VENDOR_ID 0xFEED
25#define PRODUCT_ID 0x6800
26#define MANUFACTURER t.m.k.
27#define PRODUCT SHARP X68000 keyboard converter
28#define DESCRIPTION converts SHARP X68000 keyboard protocol into USB
29
30
31/* matrix size */
32#define MATRIX_ROWS 16
33#define MATRIX_COLS 8
34
35
36/* key combination for command */
37#define IS_COMMAND() ( \
38 keyboard_report->mods == (MOD_BIT(KB_LALT) | MOD_BIT(KB_RALT)) || \
39 keyboard_report->mods == (MOD_BIT(KB_LCTRL) | MOD_BIT(KB_RSHIFT)) \
40)
41
42
43/* mouse keys */
44#ifdef MOUSEKEY_ENABLE
45# define MOUSEKEY_DELAY_TIME 255
46#endif
47
48
49/* USART configuration
50 * asynchronous, 2400baud, 8-data bit, non parity, 1-stop bit, no flow control
51 */
52#ifdef __AVR_ATmega32U4__
53# define KBD_RX_VECT USART1_RX_vect
54# define KBD_RX_DATA UDR1
55# define KBD_RX_BAUD 2400
56# define KBD_RX_UBBR ((F_CPU/(16UL*KBD_RX_BAUD))-1)
57# define KBD_RX_INIT() do { \
58 UBRR1L = (uint8_t) KBD_RX_UBBR; \
59 UBRR1H = (uint8_t) (KBD_RX_UBBR>>8); \
60 UCSR1B |= (1<<RXCIE1) | (1<<RXEN1); \
61 } while(0)
62#else
63# error "USART configuration is needed."
64#endif
65
66#endif
diff --git a/x68k_usb/keymap.c b/x68k_usb/keymap.c
new file mode 100644
index 000000000..94c2aeee1
--- /dev/null
+++ b/x68k_usb/keymap.c
@@ -0,0 +1,140 @@
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 "usb_keycodes.h"
22#include "util.h"
23#include "keymap.h"
24
25
26
27
28// Following macros help you to define a keymap with the form of actual keyboard layout.
29
30/* X68000 Keyboard Scan codes
31 ,---. ,---. ,-------------------, ,-------------------. ,-----------. ,---------------.
32 | 61| | 62| | 63| 64| 65| 66| 67| | 68| 69| 6A| 6B| 6C| | 5A| 5B| 5C| | 5D| 52| 53| 54|
33 `---' `---' `-------------------' `-------------------' `-----------' `---------------'
34 ,-----------------------------------------------------------. ,-----------. ,---------------.
35 | 01| 02| 03| 04| 05| 06| 07| 08| 09| 0A| 0B| 0C| 0D| 0E| 0F| | 36| 5E| 37| | 3F| 40| 41| 42|
36 |-----------------------------------------------------------| |------------ |---------------|
37 | 10 | 11| 12| 13| 14| 15| 16| 17| 18| 19| 1A| 1B| 1C| | | 38| 39| 3A| | 43| 44| 45| 46|
38 |------------------------------------------------------. 1D | `---=====---' |---------------|
39 | 71 | 1E| 1F| 20| 21| 2l| 23| 24| 25| 26| 27| 28| 29| | ___| 3C|___ | 47| 48| 49| 4A|
40 |-----------------------------------------------------------| | 3B|---| 3D| |-----------|---|
41 | 70 | 2A| 2B| 2C| 2D| 2E| 2F| 30| 31| 32| 33| 34| 70 | `---| 3E|---' | 4B| 4C| 4D| |
42 `-----------------------------------------------------------| .---=====---. |-----------| 4E|
43 | 5F| 55 | 56 | 35 | 57 | 58 | 59 | 60| | 72 | 73 | | 4F| 50| 51| |
44 `---------------------------------------------' `-----------' `---------------'
45*/
46#define KEYMAP( \
47 K61,K62, K63,K64,K65,K66,K67, K68,K69,K6A,K6B,K6C, K5A,K5B,K5C, K5D,K52,K53,K54, \
48 K01,K02,K03,K04,K05,K06,K07,K08,K09,K0A,K0B,K0C,K0D,K0E,K0F, K36,K5E,K37, K3F,K40,K41,K42, \
49 K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K1A,K1B,K1C, K1D, K38,K39,K3A, K43,K44,K45,K46, \
50 K71,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29, K3C, K47,K48,K49,K4A, \
51 K70,K2A,K2B,K2C,K2D,K2E,K2F,K30,K31,K32,K33,K34, K3B,K3E,K3D, K4B,K4C,K4D,K4E, \
52 K5F,K55,K56, K35, K57,K58,K59,K60, K72, K73, K4F,K50,K51 \
53) { \
54 { KB_NO, KB_##K01, KB_##K02, KB_##K03, KB_##K04, KB_##K05, KB_##K06, KB_##K07 }, \
55 { KB_##K08, KB_##K09, KB_##K0A, KB_##K0B, KB_##K0C, KB_##K0D, KB_##K0E, KB_##K0F }, \
56 { KB_##K10, KB_##K11, KB_##K12, KB_##K13, KB_##K14, KB_##K15, KB_##K16, KB_##K17 }, \
57 { KB_##K18, KB_##K19, KB_##K1A, KB_##K1B, KB_##K1C, KB_##K1D, KB_##K1E, KB_##K1F }, \
58 { KB_##K20, KB_##K21, KB_##K22, KB_##K23, KB_##K24, KB_##K25, KB_##K26, KB_##K27 }, \
59 { KB_##K28, KB_##K29, KB_##K2A, KB_##K2B, KB_##K2C, KB_##K2D, KB_##K2E, KB_##K2F }, \
60 { KB_##K30, KB_##K31, KB_##K32, KB_##K33, KB_##K34, KB_##K35, KB_##K36, KB_##K37 }, \
61 { KB_##K38, KB_##K39, KB_##K3A, KB_##K3B, KB_##K3C, KB_##K3D, KB_##K3E, KB_##K3F }, \
62 { KB_##K40, KB_##K41, KB_##K42, KB_##K43, KB_##K44, KB_##K45, KB_##K46, KB_##K47 }, \
63 { KB_##K48, KB_##K49, KB_##K4A, KB_##K4B, KB_##K4C, KB_##K4D, KB_##K4E, KB_##K4F }, \
64 { KB_##K50, KB_##K51, KB_##K52, KB_##K53, KB_##K54, KB_##K55, KB_##K56, KB_##K57 }, \
65 { KB_##K58, KB_##K59, KB_##K5A, KB_##K5B, KB_##K5C, KB_##K5D, KB_##K5E, KB_##K5F }, \
66 { KB_##K60, KB_##K61, KB_##K62, KB_##K63, KB_##K64, KB_##K65, KB_##K66, KB_##K67 }, \
67 { KB_##K68, KB_##K69, KB_##K6A, KB_##K6B, KB_##K6C, KB_NO, KB_NO, KB_NO }, \
68 { KB_##K70, KB_##K71, KB_##K72, KB_##K73, KB_NO, KB_NO, KB_NO, KB_NO, }, \
69 { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO } \
70}
71
72
73// Assign Fn key(0-7) to a layer to which switch with the Fn key pressed.
74static const uint8_t PROGMEM fn_layer[] = {
75 0, // Fn0
76 0, // Fn1
77 0, // Fn2
78 0, // Fn3
79 0, // Fn4
80 0, // Fn5
81 0, // Fn6
82 0 // Fn7
83};
84
85// Assign Fn key(0-7) to a keycode sent when release Fn key without use of the layer.
86// See layer.c for details.
87static const uint8_t PROGMEM fn_keycode[] = {
88 KB_NO, // Fn0
89 KB_NO, // Fn1
90 KB_NO, // Fn2
91 KB_NO, // Fn3
92 KB_NO, // Fn4
93 KB_NO, // Fn5
94 KB_NO, // Fn6
95 KB_NO // Fn7
96};
97
98
99static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
100/* X68000 Keyboard Scan codes
101 ,---. ,---. ,-------------------, ,-------------------. ,-----------. ,---------------.
102 | 61| | 62| | 63| 64| 65| 66| 67| | 68| 69| 6A| 6B| 6C| | 5A| 5B| 5C| | 5D| 52| 53| 54|
103 `---' `---' `-------------------' `-------------------' `-----------' `---------------'
104 ,-----------------------------------------------------------. ,-----------. ,---------------.
105 | 01| 02| 03| 04| 05| 06| 07| 08| 09| 0A| 0B| 0C| 0D| 0E| 0F| | 36| 5E| 37| | 3F| 40| 41| 42|
106 |-----------------------------------------------------------| |------------ |---------------|
107 | 10 | 11| 12| 13| 14| 15| 16| 17| 18| 19| 1A| 1B| 1C| | | 38| 39| 3A| | 43| 44| 45| 46|
108 |------------------------------------------------------. 1D | `---=====---' |---------------|
109 | 71 | 1E| 1F| 20| 21| 2l| 23| 24| 25| 26| 27| 28| 29| | ___| 3C|___ | 47| 48| 49| 4A|
110 |-----------------------------------------------------------| | 3B|---| 3D| |-----------|---|
111 | 70 | 2A| 2B| 2C| 2D| 2E| 2F| 30| 31| 32| 33| 34| 70 | `---| 3E|---' | 4B| 4C| 4D| |
112 `-----------------------------------------------------------| .---=====---. |-----------| 4E|
113 | 5F| 55 | 56 | 35 | 57 | 58 | 59 | 60| | 72 | 73 | | 4F| 50| 51| |
114 `---------------------------------------------' `-----------' `---------------'
115*/
116 KEYMAP(
117 NO, NO, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, PSCR,SLCK,PAUS, CAPS,NO, NO, NO,
118 ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS,
119 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, ENT, DEL, END, PGDN, P7, P8, P9, PPLS,
120 LCTL,A, S, D, F, G, H, J, K, L, SCLN,QUOT,ENT, UP, P4, P5, P6, PEQL,
121 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH,GRV, LEFT,DOWN,RGHT, P1, P2, P3, PENT,
122 LGUI,LALT,NO, SPC, RALT,RGUI,RCTL,APP, NO, NO, P0, PCMM,PDOT
123 ),
124};
125
126
127uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col)
128{
129 return pgm_read_byte(&keymaps[(layer)][(row)][(col)]);
130}
131
132uint8_t keymap_fn_layer(uint8_t fn_bits)
133{
134 return pgm_read_byte(&fn_layer[biton(fn_bits)]);
135}
136
137uint8_t keymap_fn_keycode(uint8_t fn_bits)
138{
139 return pgm_read_byte(&fn_keycode[(biton(fn_bits))]);
140}
diff --git a/x68k_usb/led.c b/x68k_usb/led.c
new file mode 100644
index 000000000..40156cf4a
--- /dev/null
+++ b/x68k_usb/led.c
@@ -0,0 +1,26 @@
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 "x68k.h"
20#include "led.h"
21
22
23void led_set(uint8_t usb_led)
24{
25 // not supported now
26}
diff --git a/x68k_usb/matrix.c b/x68k_usb/matrix.c
new file mode 100644
index 000000000..954e7ef12
--- /dev/null
+++ b/x68k_usb/matrix.c
@@ -0,0 +1,141 @@
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 "x68k.h"
25#include "matrix.h"
26
27
28/*
29 * Matrix Array usage:
30 *
31 * ROW: 16(4bits)
32 * COL: 8(3bits)
33 *
34 * 8bit wide
35 * +---------+
36 * 0|00 ... 07|
37 * 1|08 ... 0F|
38 * :| ... |
39 * :| ... |
40 * E|70 ... 77|
41 * F|78 ... 7F|
42 * +---------+
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 x68k_init();
67
68 // initialize matrix state: all keys off
69 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
70
71 return;
72}
73
74uint8_t matrix_scan(void)
75{
76 is_modified = false;
77
78 uint8_t code;
79 code = x68k_recv();
80 if (code == 0) {
81 return 0;
82 }
83
84 phex(code); print(" ");
85 if (code&0x80) {
86 // break code
87 if (matrix_is_on(ROW(code), COL(code))) {
88 matrix[ROW(code)] &= ~(1<<COL(code));
89 is_modified = true;
90 }
91 } else {
92 // make code
93 if (!matrix_is_on(ROW(code), COL(code))) {
94 matrix[ROW(code)] |= (1<<COL(code));
95 is_modified = true;
96 }
97 }
98 return code;
99}
100
101bool matrix_is_modified(void)
102{
103 return is_modified;
104}
105
106inline
107bool matrix_has_ghost(void)
108{
109 return false;
110}
111
112inline
113bool matrix_is_on(uint8_t row, uint8_t col)
114{
115 return (matrix[row] & (1<<col));
116}
117
118inline
119uint8_t matrix_get_row(uint8_t row)
120{
121 return matrix[row];
122}
123
124void matrix_print(void)
125{
126 print("\nr/c 01234567\n");
127 for (uint8_t row = 0; row < matrix_rows(); row++) {
128 phex(row); print(": ");
129 pbin_reverse(matrix_get_row(row));
130 print("\n");
131 }
132}
133
134uint8_t matrix_key_count(void)
135{
136 uint8_t count = 0;
137 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
138 count += bitpop(matrix[i]);
139 }
140 return count;
141}
diff --git a/x68k_usb/x68k.c b/x68k_usb/x68k.c
new file mode 100644
index 000000000..d17af51cc
--- /dev/null
+++ b/x68k_usb/x68k.c
@@ -0,0 +1,75 @@
1/*
2Copyright 2012 Jun WAKO <wakojun@gmail.com>
3
4This software is licensed with a Modified BSD License.
5All of this is supposed to be Free Software, Open Source, DFSG-free,
6GPL-compatible, and OK to use in both free and proprietary applications.
7Additions and corrections to this file are welcome.
8
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions are met:
12
13* Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15
16* Redistributions in binary form must reproduce the above copyright
17 notice, this list of conditions and the following disclaimer in
18 the documentation and/or other materials provided with the
19 distribution.
20
21* Neither the name of the copyright holders nor the names of
22 contributors may be used to endorse or promote products derived
23 from this software without specific prior written permission.
24
25THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35POSSIBILITY OF SUCH DAMAGE.
36*/
37
38#include <stdbool.h>
39#include <avr/io.h>
40#include <avr/interrupt.h>
41#include "x68k.h"
42
43
44void x68k_init(void)
45{
46 KBD_RX_INIT();
47}
48
49// RX ring buffer
50#define RBUF_SIZE 8
51static uint8_t rbuf[RBUF_SIZE];
52static uint8_t rbuf_head = 0;
53static uint8_t rbuf_tail = 0;
54
55uint8_t x68k_recv(void)
56{
57 uint8_t data = 0;
58 if (rbuf_head == rbuf_tail) {
59 return 0;
60 }
61
62 data = rbuf[rbuf_tail];
63 rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
64 return data;
65}
66
67// USART RX complete interrupt
68ISR(KBD_RX_VECT)
69{
70 uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
71 if (next != rbuf_tail) {
72 rbuf[rbuf_head] = KBD_RX_DATA;
73 rbuf_head = next;
74 }
75}
diff --git a/x68k_usb/x68k.h b/x68k_usb/x68k.h
new file mode 100644
index 000000000..2cfda63a7
--- /dev/null
+++ b/x68k_usb/x68k.h
@@ -0,0 +1,47 @@
1/*
2Copyright 2012 Jun WAKO <wakojun@gmail.com>
3
4This software is licensed with a Modified BSD License.
5All of this is supposed to be Free Software, Open Source, DFSG-free,
6GPL-compatible, and OK to use in both free and proprietary applications.
7Additions and corrections to this file are welcome.
8
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions are met:
12
13* Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15
16* Redistributions in binary form must reproduce the above copyright
17 notice, this list of conditions and the following disclaimer in
18 the documentation and/or other materials provided with the
19 distribution.
20
21* Neither the name of the copyright holders nor the names of
22 contributors may be used to endorse or promote products derived
23 from this software without specific prior written permission.
24
25THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35POSSIBILITY OF SUCH DAMAGE.
36*/
37
38#ifndef X68K_H
39#define X68K_H
40
41/* host role */
42void x68k_init(void);
43uint8_t x68k_recv(void);
44
45/* device role */
46
47#endif