aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2012-10-19 15:08:26 +0900
committertmk <nobody@nowhere>2012-10-19 15:08:26 +0900
commit81141ad0eba1a9db9abd0f7903d8077c28e76b40 (patch)
tree76ab2978baba4d9cf89e9d02fa13eb2e5424db8e
parent3c822b511e7af60332a7e5a938c08bafb2516ba3 (diff)
parentb56717b843859aa3188f9a40532b077241269482 (diff)
downloadqmk_firmware-81141ad0eba1a9db9abd0f7903d8077c28e76b40.tar.gz
qmk_firmware-81141ad0eba1a9db9abd0f7903d8077c28e76b40.zip
Merge branch 'sun'
-rw-r--r--common/mousekey.h2
-rw-r--r--converter/sun_usb/Makefile82
-rw-r--r--converter/sun_usb/README79
-rw-r--r--converter/sun_usb/config.h67
-rw-r--r--converter/sun_usb/keymap.c192
-rw-r--r--converter/sun_usb/led.c25
-rw-r--r--converter/sun_usb/matrix.c159
-rw-r--r--protocol/serial.h45
-rw-r--r--protocol/serial_soft.c114
-rw-r--r--rules.mk2
10 files changed, 765 insertions, 2 deletions
diff --git a/common/mousekey.h b/common/mousekey.h
index ac26a46c8..d8d7beaaa 100644
--- a/common/mousekey.h
+++ b/common/mousekey.h
@@ -45,7 +45,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
45#define MOUSEKEY_TIME_TO_MAX 20 45#define MOUSEKEY_TIME_TO_MAX 20
46#endif 46#endif
47#ifndef MOUSEKEY_WHEEL_MAX_SPEED 47#ifndef MOUSEKEY_WHEEL_MAX_SPEED
48#define MOUSEKEY_WHEEL_MAX_SPEED 16 48#define MOUSEKEY_WHEEL_MAX_SPEED 8
49#endif 49#endif
50#ifndef MOUSEKEY_WHEEL_TIME_TO_MAX 50#ifndef MOUSEKEY_WHEEL_TIME_TO_MAX
51#define MOUSEKEY_WHEEL_TIME_TO_MAX 40 51#define MOUSEKEY_WHEEL_TIME_TO_MAX 40
diff --git a/converter/sun_usb/Makefile b/converter/sun_usb/Makefile
new file mode 100644
index 000000000..4c79a8d27
--- /dev/null
+++ b/converter/sun_usb/Makefile
@@ -0,0 +1,82 @@
1# Target file name (without extension).
2TARGET = sun_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 protocol/serial_soft.c
15
16CONFIG_H = config.h
17
18
19# MCU name, you MUST set this to match the board you are using
20# type "make clean" after changing this, so all files will be rebuilt
21#MCU = at90usb162 # Teensy 1.0
22MCU = atmega32u4 # Teensy 2.0
23#MCU = at90usb646 # Teensy++ 1.0
24#MCU = at90usb1286 # Teensy++ 2.0
25
26
27# Processor frequency.
28# Normally the first thing your program should do is set the clock prescaler,
29# so your program will run at the correct speed. You should also set this
30# variable to same clock speed. The _delay_ms() macro uses this, and many
31# examples use this variable to calculate timings. Do not add a "UL" here.
32F_CPU = 16000000
33
34
35#
36# LUFA specific
37#
38# Target architecture (see library "Board Types" documentation).
39ARCH = AVR8
40
41# Input clock frequency.
42# This will define a symbol, F_USB, in all source code files equal to the
43# input clock frequency (before any prescaling is performed) in Hz. This value may
44# differ from F_CPU if prescaling is used on the latter, and is required as the
45# raw input clock is fed directly to the PLL sections of the AVR for high speed
46# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
47# at the end, this will be done automatically to create a 32-bit value in your
48# source code.
49#
50# If no clock division is performed on the input clock inside the AVR (via the
51# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
52F_USB = $(F_CPU)
53
54# Interrupt driven control endpoint task
55OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
56
57
58# Build Options
59# *Comment out* to disable the options.
60#
61MOUSEKEY_ENABLE = yes # Mouse keys
62EXTRAKEY_ENABLE = yes # Audio control and System control
63CONSOLE_ENABLE = yes # Console for debug
64#NKRO_ENABLE = yes # USB Nkey Rollover
65
66
67# Boot Section Size in bytes
68# Teensy halfKay 512
69# Atmel DFU loader 4096
70# LUFA bootloader 4096
71OPT_DEFS += -DBOOT_SIZE=4096
72
73
74# Search Path
75VPATH += $(TARGET_DIR)
76VPATH += $(TOP_DIR)
77
78
79include $(TOP_DIR)/protocol/lufa.mk
80include $(TOP_DIR)/protocol.mk
81include $(TOP_DIR)/common.mk
82include $(TOP_DIR)/rules.mk
diff --git a/converter/sun_usb/README b/converter/sun_usb/README
new file mode 100644
index 000000000..7b4f95ca2
--- /dev/null
+++ b/converter/sun_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/sun_usb/config.h b/converter/sun_usb/config.h
new file mode 100644
index 000000000..66961d933
--- /dev/null
+++ b/converter/sun_usb/config.h
@@ -0,0 +1,67 @@
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 Sun keyboard converter
26#define DESCRIPTION converts Sun 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
42/* Serial(USART) configuration
43 * asynchronous, negative logic, 1200baud, no flow control
44 * 1-start bit, 8-data bit, non parity, 1-stop bit
45 */
46#define SERIAL_NEGATIVE_LOGIC
47#define SERIAL_BAUD 1200
48#define SERIAL_RXD_DDR DDRD
49#define SERIAL_RXD_PORT PORTD
50#define SERIAL_RXD_PIN PIND
51#define SERIAL_RXD_BIT 2
52#define SERIAL_RXD_VECT INT2_vect
53#define SERIAL_RXD_INIT() do { \
54 /* pin configuration: input with pull-up */ \
55 SERIAL_RXD_DDR &= ~(1<<SERIAL_RXD_BIT); \
56 SERIAL_RXD_PORT |= (1<<SERIAL_RXD_BIT); \
57 /* enable interrupt: INT2(rising edge) */ \
58 EICRA |= ((1<<ISC21)|(1<<ISC20)); \
59 EIMSK |= (1<<INT2); \
60} while (0)
61#define SERIAL_RXD_INT_ENTER()
62#define SERIAL_RXD_INT_EXIT() do { \
63 /* clear interrupt flag */ \
64 EIFR = (1<<INTF2); \
65} while (0)
66
67#endif
diff --git a/converter/sun_usb/keymap.c b/converter/sun_usb/keymap.c
new file mode 100644
index 000000000..048a863ca
--- /dev/null
+++ b/converter/sun_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/sun_usb/led.c b/converter/sun_usb/led.c
new file mode 100644
index 000000000..5490ec0c6
--- /dev/null
+++ b/converter/sun_usb/led.c
@@ -0,0 +1,25 @@
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 "led.h"
20
21
22void led_set(uint8_t usb_led)
23{
24 // not supported now
25}
diff --git a/converter/sun_usb/matrix.c b/converter/sun_usb/matrix.c
new file mode 100644
index 000000000..717c131e6
--- /dev/null
+++ b/converter/sun_usb/matrix.c
@@ -0,0 +1,159 @@
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 serial_init();
70
71 // initialize matrix state: all keys off
72 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
73
74 return;
75}
76
77uint8_t matrix_scan(void)
78{
79 is_modified = false;
80
81 uint8_t code;
82 code = serial_recv();
83 if (!code) return 0;
84
85 debug_hex(code); debug(" ");
86
87 switch (code) {
88 case 0x7E: // reset fail
89 case 0xFE: // layout
90 case 0xFF: // reset success
91 _delay_ms(500);
92 // ignore response byte
93 debug("(response ignored:");
94 while ((code = serial_recv())) { debug(" "); debug_hex(code); }
95 debug(") ");
96 // FALL THROUGH
97 case 0x7F:
98 // all keys up
99 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
100 return 0;
101 }
102
103 if (code&0x80) {
104 // break code
105 if (matrix_is_on(ROW(code), COL(code))) {
106 matrix[ROW(code)] &= ~(1<<COL(code));
107 is_modified = true;
108 }
109 } else {
110 // make code
111 if (!matrix_is_on(ROW(code), COL(code))) {
112 matrix[ROW(code)] |= (1<<COL(code));
113 is_modified = true;
114 }
115 }
116 return code;
117}
118
119bool matrix_is_modified(void)
120{
121 return is_modified;
122}
123
124inline
125bool matrix_has_ghost(void)
126{
127 return false;
128}
129
130inline
131bool matrix_is_on(uint8_t row, uint8_t col)
132{
133 return (matrix[row] & (1<<col));
134}
135
136inline
137uint8_t matrix_get_row(uint8_t row)
138{
139 return matrix[row];
140}
141
142void matrix_print(void)
143{
144 print("\nr/c 01234567\n");
145 for (uint8_t row = 0; row < matrix_rows(); row++) {
146 phex(row); print(": ");
147 pbin_reverse(matrix_get_row(row));
148 print("\n");
149 }
150}
151
152uint8_t matrix_key_count(void)
153{
154 uint8_t count = 0;
155 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
156 count += bitpop(matrix[i]);
157 }
158 return count;
159}
diff --git a/protocol/serial.h b/protocol/serial.h
new file mode 100644
index 000000000..93b9ee922
--- /dev/null
+++ b/protocol/serial.h
@@ -0,0 +1,45 @@
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 SERIAL_H
39#define SERIAL_H
40
41/* host role */
42void serial_init(void);
43uint8_t serial_recv(void);
44
45#endif
diff --git a/protocol/serial_soft.c b/protocol/serial_soft.c
new file mode 100644
index 000000000..b7d06b644
--- /dev/null
+++ b/protocol/serial_soft.c
@@ -0,0 +1,114 @@
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 <util/delay.h>
42#include "serial.h"
43
44/*
45 * Stupid Inefficient Busy-wait Software Serial
46 * is still useful for negative logic signal like Sun protocol not supported by hardware USART.
47 */
48
49#define WAIT_US (1000000/SERIAL_BAUD)
50
51void serial_init(void)
52{
53 SERIAL_RXD_INIT();
54}
55
56// RX ring buffer
57#define RBUF_SIZE 8
58static uint8_t rbuf[RBUF_SIZE];
59static uint8_t rbuf_head = 0;
60static uint8_t rbuf_tail = 0;
61
62uint8_t serial_recv(void)
63{
64 uint8_t data = 0;
65 if (rbuf_head == rbuf_tail) {
66 return 0;
67 }
68
69 data = rbuf[rbuf_tail];
70 rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
71 return data;
72}
73
74//ISR(INT2_vect)
75ISR(SERIAL_RXD_VECT)
76{
77 SERIAL_RXD_INT_ENTER()
78
79 uint8_t data = 0;
80#ifdef SERIAL_BIT_ORDER_MSB
81 uint8_t pos = 0x80;
82#else
83 uint8_t pos = 0x01;
84#endif
85 // to center of start bit
86 _delay_us(WAIT_US/2);
87 do {
88 // to center of next bit
89 _delay_us(WAIT_US);
90
91 if (SERIAL_RXD_PIN&(1<<SERIAL_RXD_BIT)) {
92 data |= pos;
93 }
94#ifdef SERIAL_BIT_ORDER_MSB
95 pos >>= 1;
96#else
97 pos <<= 1;
98#endif
99 } while (pos);
100 // to center of stop bit
101 _delay_us(WAIT_US);
102
103#ifdef SERIAL_NEGATIVE_LOGIC
104 data = ~data;
105#endif
106
107 uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
108 if (next != rbuf_tail) {
109 rbuf[rbuf_head] = data;
110 rbuf_head = next;
111 }
112
113 SERIAL_RXD_INT_EXIT();
114}
diff --git a/rules.mk b/rules.mk
index f53fe912a..2e4fce518 100644
--- a/rules.mk
+++ b/rules.mk
@@ -252,7 +252,7 @@ EXTMEMOPTS =
252# (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12' 252# (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12'
253# 253#
254LDFLAGS = -Wl,-Map=$(TARGET).map,--cref 254LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
255LDFLAGS += -Wl,--relax 255#LDFLAGS += -Wl,--relax
256LDFLAGS += -Wl,--gc-sections 256LDFLAGS += -Wl,--gc-sections
257LDFLAGS += $(EXTMEMOPTS) 257LDFLAGS += $(EXTMEMOPTS)
258LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS)) 258LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))