diff options
| author | tmk <nobody@nowhere> | 2012-06-08 00:37:46 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2012-06-08 13:32:38 +0900 |
| commit | afb08462085132acf7a1962522952f7dbf064519 (patch) | |
| tree | bc60f28142bc36d882f5930191ba8da98a27c47c /terminal_usb | |
| parent | 63d82fcaeb78d0764f39667b937262ed4a692c17 (diff) | |
| download | qmk_firmware-afb08462085132acf7a1962522952f7dbf064519.tar.gz qmk_firmware-afb08462085132acf7a1962522952f7dbf064519.zip | |
Made directories for keyboard and converter projects.
Diffstat (limited to 'terminal_usb')
| -rw-r--r-- | terminal_usb/Makefile.102_pjrc | 58 | ||||
| -rw-r--r-- | terminal_usb/Makefile.122_pjrc | 58 | ||||
| -rw-r--r-- | terminal_usb/README | 47 | ||||
| -rw-r--r-- | terminal_usb/config_102_pjrc.h | 58 | ||||
| -rw-r--r-- | terminal_usb/config_122_pjrc.h | 58 | ||||
| -rw-r--r-- | terminal_usb/keymap_102.c | 208 | ||||
| -rw-r--r-- | terminal_usb/keymap_122.c | 143 | ||||
| -rw-r--r-- | terminal_usb/led.c | 33 | ||||
| -rw-r--r-- | terminal_usb/matrix.c | 226 |
9 files changed, 0 insertions, 889 deletions
diff --git a/terminal_usb/Makefile.102_pjrc b/terminal_usb/Makefile.102_pjrc deleted file mode 100644 index a02877acf..000000000 --- a/terminal_usb/Makefile.102_pjrc +++ /dev/null | |||
| @@ -1,58 +0,0 @@ | |||
| 1 | # | ||
| 2 | # Makefile for PJRC Teensy | ||
| 3 | # | ||
| 4 | |||
| 5 | |||
| 6 | # Target file name (without extension). | ||
| 7 | TARGET = terminal_usb_102_pjrc | ||
| 8 | |||
| 9 | # Directory common source filess exist | ||
| 10 | TOP_DIR = .. | ||
| 11 | |||
| 12 | # Directory keyboard dependent files exist | ||
| 13 | TARGET_DIR = . | ||
| 14 | |||
| 15 | # keyboard dependent files | ||
| 16 | SRC = main.c \ | ||
| 17 | keymap_102.c \ | ||
| 18 | matrix.c \ | ||
| 19 | led.c \ | ||
| 20 | ps2.c | ||
| 21 | |||
| 22 | CONFIG_H = config_102_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 | ||
| 28 | MCU = 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. | ||
| 38 | F_CPU = 16000000 | ||
| 39 | |||
| 40 | |||
| 41 | # Build Options | ||
| 42 | # *Comment out* to disable the options. | ||
| 43 | # | ||
| 44 | MOUSEKEY_ENABLE = yes # Mouse keys | ||
| 45 | EXTRAKEY_ENABLE = yes # Audio control and System control | ||
| 46 | NKRO_ENABLE = yes # USB Nkey Rollover | ||
| 47 | |||
| 48 | |||
| 49 | |||
| 50 | #---------------- Programming Options -------------------------- | ||
| 51 | PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex | ||
| 52 | |||
| 53 | |||
| 54 | |||
| 55 | include $(TOP_DIR)/protocol/pjrc.mk | ||
| 56 | include $(TOP_DIR)/protocol.mk | ||
| 57 | include $(TOP_DIR)/common.mk | ||
| 58 | include $(TOP_DIR)/rules.mk | ||
diff --git a/terminal_usb/Makefile.122_pjrc b/terminal_usb/Makefile.122_pjrc deleted file mode 100644 index 1f21d4e6c..000000000 --- a/terminal_usb/Makefile.122_pjrc +++ /dev/null | |||
| @@ -1,58 +0,0 @@ | |||
| 1 | # | ||
| 2 | # Makefile for PJRC Teensy | ||
| 3 | # | ||
| 4 | |||
| 5 | |||
| 6 | # Target file name (without extension). | ||
| 7 | TARGET = terminal_usb_122_pjrc | ||
| 8 | |||
| 9 | # Directory common source filess exist | ||
| 10 | TOP_DIR = .. | ||
| 11 | |||
| 12 | # Directory keyboard dependent files exist | ||
| 13 | TARGET_DIR = . | ||
| 14 | |||
| 15 | # keyboard dependent files | ||
| 16 | SRC = main.c \ | ||
| 17 | keymap_122.c \ | ||
| 18 | matrix.c \ | ||
| 19 | led.c \ | ||
| 20 | ps2.c | ||
| 21 | |||
| 22 | CONFIG_H = config_122_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 | ||
| 28 | MCU = 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. | ||
| 38 | F_CPU = 16000000 | ||
| 39 | |||
| 40 | |||
| 41 | # Build Options | ||
| 42 | # *Comment out* to disable the options. | ||
| 43 | # | ||
| 44 | #MOUSEKEY_ENABLE = yes # Mouse keys | ||
| 45 | #EXTRAKEY_ENABLE = yes # Audio control and System control | ||
| 46 | #NKRO_ENABLE = yes # USB Nkey Rollover | ||
| 47 | |||
| 48 | |||
| 49 | |||
| 50 | #---------------- Programming Options -------------------------- | ||
| 51 | PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex | ||
| 52 | |||
| 53 | |||
| 54 | |||
| 55 | include $(TOP_DIR)/protocol/pjrc.mk | ||
| 56 | include $(TOP_DIR)/protocol.mk | ||
| 57 | include $(TOP_DIR)/common.mk | ||
| 58 | include $(TOP_DIR)/rules.mk | ||
diff --git a/terminal_usb/README b/terminal_usb/README deleted file mode 100644 index 1ce49f33d..000000000 --- a/terminal_usb/README +++ /dev/null | |||
| @@ -1,47 +0,0 @@ | |||
| 1 | PS/2 to USB keyboard converter for IBM terminal keyboard | ||
| 2 | ========================================================= | ||
| 3 | It supports PS/2 Scan Code Set 3 and runs on Teensy, Teensy++ and boards withATMega32u4/AT90USB. | ||
| 4 | I tested the converter only on Teensy with 1392595(102keys terminal keyboard), | ||
| 5 | though, I think it will also work with 122keys boards. | ||
| 6 | |||
| 7 | http://geekhack.org/showwiki.php?title=Island:27272 | ||
| 8 | |||
| 9 | |||
| 10 | CONNECTION | ||
| 11 | ---------- | ||
| 12 | Data: PD0 | ||
| 13 | Clock: PD1 | ||
| 14 | VCC and GND, of course. | ||
| 15 | |||
| 16 | It is the same as Soarer's converter pin configuration. | ||
| 17 | See RESOURCE for keyboard connector pin assign. | ||
| 18 | |||
| 19 | |||
| 20 | |||
| 21 | BUILD | ||
| 22 | ----- | ||
| 23 | Get source: | ||
| 24 | $ git clone https://github.com/tmk/tmk_keyboard.git | ||
| 25 | $ cd terminal_usb | ||
| 26 | |||
| 27 | For 102keys: | ||
| 28 | $ make -f Makefile.102_pjrc | ||
| 29 | |||
| 30 | For 122keys(not tested): | ||
| 31 | $ make -f Makefile.122_pjrc | ||
| 32 | |||
| 33 | I used WinAVR 20100110 to develop and build. | ||
| 34 | |||
| 35 | |||
| 36 | |||
| 37 | RESOURCE | ||
| 38 | -------- | ||
| 39 | Soarer's Converter: http://geekhack.org/showwiki.php?title=Island:17458 | ||
| 40 | 102keys(1392595): http://geekhack.org/showthread.php?10737-What-Can-I-Do-With-a-Terminal-Model-M | ||
| 41 | 122keys(1390876): http://www.seasip.info/VintagePC/ibm_1390876.html | ||
| 42 | KbdBabel: http://www.kbdbabel.org/ | ||
| 43 | RJ45 Connector: http://www.kbdbabel.org/conn/kbd_connector_ibmterm.png | ||
| 44 | DIN Connector: http://www.kbdbabel.org/conn/kbd_connector_ibm3179_318x_319x.png | ||
| 45 | WinAVR: http://winavr.sourceforge.net/ | ||
| 46 | |||
| 47 | EOF | ||
diff --git a/terminal_usb/config_102_pjrc.h b/terminal_usb/config_102_pjrc.h deleted file mode 100644 index 2dce04af7..000000000 --- a/terminal_usb/config_102_pjrc.h +++ /dev/null | |||
| @@ -1,58 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along 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 0x6531 | ||
| 26 | #define MANUFACTURER t.m.k. | ||
| 27 | #define PRODUCT PS/2(Set3)-USB Keyboard converter(IBM 102keys) | ||
| 28 | #define DESCRIPTION USB converter for IBM Terminal Keyboard 102keys | ||
| 29 | |||
| 30 | |||
| 31 | /* matrix size */ | ||
| 32 | #define MATRIX_ROWS 17 // keycode bit: 3-0 | ||
| 33 | #define MATRIX_COLS 8 // keycode bit: 6-4 | ||
| 34 | |||
| 35 | |||
| 36 | /* key combination for command */ | ||
| 37 | #define IS_COMMAND() ( \ | ||
| 38 | keyboard_report->mods == (MOD_BIT(KB_RALT) | MOD_BIT(KB_RCTL)) \ | ||
| 39 | ) | ||
| 40 | |||
| 41 | |||
| 42 | /* mouse keys */ | ||
| 43 | #ifdef MOUSEKEY_ENABLE | ||
| 44 | # define MOUSEKEY_DELAY_TIME 255 | ||
| 45 | #endif | ||
| 46 | |||
| 47 | |||
| 48 | /* PS/2 lines */ | ||
| 49 | #define PS2_CLOCK_PORT PORTD | ||
| 50 | #define PS2_CLOCK_PIN PIND | ||
| 51 | #define PS2_CLOCK_DDR DDRD | ||
| 52 | #define PS2_CLOCK_BIT 1 | ||
| 53 | #define PS2_DATA_PORT PORTD | ||
| 54 | #define PS2_DATA_PIN PIND | ||
| 55 | #define PS2_DATA_DDR DDRD | ||
| 56 | #define PS2_DATA_BIT 0 | ||
| 57 | |||
| 58 | #endif | ||
diff --git a/terminal_usb/config_122_pjrc.h b/terminal_usb/config_122_pjrc.h deleted file mode 100644 index 43691bd71..000000000 --- a/terminal_usb/config_122_pjrc.h +++ /dev/null | |||
| @@ -1,58 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along 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 0x6532 | ||
| 26 | #define MANUFACTURER t.m.k. | ||
| 27 | #define PRODUCT PS/2(Set3)-USB Keyboard converter(IBM 122keys) | ||
| 28 | #define DESCRIPTION USB converter for IBM Terminal Keyboard 122keys | ||
| 29 | |||
| 30 | |||
| 31 | /* matrix size */ | ||
| 32 | #define MATRIX_ROWS 17 // keycode bit: 3-0 | ||
| 33 | #define MATRIX_COLS 8 // keycode bit: 6-4 | ||
| 34 | |||
| 35 | |||
| 36 | /* key combination for command */ | ||
| 37 | #define IS_COMMAND() ( \ | ||
| 38 | keyboard_report->mods == (MOD_BIT(KB_RALT) | MOD_BIT(KB_RCTL)) \ | ||
| 39 | ) | ||
| 40 | |||
| 41 | |||
| 42 | /* mouse keys */ | ||
| 43 | #ifdef MOUSEKEY_ENABLE | ||
| 44 | # define MOUSEKEY_DELAY_TIME 255 | ||
| 45 | #endif | ||
| 46 | |||
| 47 | |||
| 48 | /* PS/2 lines */ | ||
| 49 | #define PS2_CLOCK_PORT PORTD | ||
| 50 | #define PS2_CLOCK_PIN PIND | ||
| 51 | #define PS2_CLOCK_DDR DDRD | ||
| 52 | #define PS2_CLOCK_BIT 1 | ||
| 53 | #define PS2_DATA_PORT PORTD | ||
| 54 | #define PS2_DATA_PIN PIND | ||
| 55 | #define PS2_DATA_DDR DDRD | ||
| 56 | #define PS2_DATA_BIT 0 | ||
| 57 | |||
| 58 | #endif | ||
diff --git a/terminal_usb/keymap_102.c b/terminal_usb/keymap_102.c deleted file mode 100644 index 430570c47..000000000 --- a/terminal_usb/keymap_102.c +++ /dev/null | |||
| @@ -1,208 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along 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 "print.h" | ||
| 23 | #include "debug.h" | ||
| 24 | #include "util.h" | ||
| 25 | #include "keymap.h" | ||
| 26 | |||
| 27 | |||
| 28 | |||
| 29 | |||
| 30 | /* | ||
| 31 | * IBM Terminal keyboard 1392595(102keys) | ||
| 32 | * http://geekhack.org/showthread.php?10737-What-Can-I-Do-With-a-Terminal-Model-M | ||
| 33 | * http://www.seasip.info/VintagePC/ibm_1391406.html | ||
| 34 | * | ||
| 35 | * Keymap array: | ||
| 36 | * 8 bytes | ||
| 37 | * +---------+ | ||
| 38 | * 0| | | ||
| 39 | * :| | 0x00-0x87 | ||
| 40 | * ;| | | ||
| 41 | * 17| | | ||
| 42 | * +---------+ | ||
| 43 | */ | ||
| 44 | #define KEYMAP( \ | ||
| 45 | K08, K07,K0F,K17,K1F,K27,K2F,K37,K3F,K47,K4F,K56,K5E, K57,K5F,K62, \ | ||
| 46 | \ | ||
| 47 | K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K5D,K66, K67,K6E,K6F, K76,K77,K7E,K84, \ | ||
| 48 | K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B, K5C, K64,K65,K6D, K6C,K75,K7D,K7C, \ | ||
| 49 | K14,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52, K53,K5A, K6B,K73,K74,K7B, \ | ||
| 50 | K12,K13,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A, K51,K59, K63, K69,K72,K7A,K79, \ | ||
| 51 | K11, K19, K29, K39, K58, K61,K60,K6A, K68,K70,K71,K78 \ | ||
| 52 | ) { \ | ||
| 53 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_##K07 }, \ | ||
| 54 | { KB_##K08, KB_NO, KB_NO, KB_NO, KB_NO, KB_##K0D, KB_##K0E, KB_##K0F }, \ | ||
| 55 | { KB_NO, KB_##K11, KB_##K12, KB_##K13, KB_##K14, KB_##K15, KB_##K16, KB_##K17 }, \ | ||
| 56 | { KB_NO, KB_##K19, KB_##K1A, KB_##K1B, KB_##K1C, KB_##K1D, KB_##K1E, KB_##K1F }, \ | ||
| 57 | { KB_NO, KB_##K21, KB_##K22, KB_##K23, KB_##K24, KB_##K25, KB_##K26, KB_##K27 }, \ | ||
| 58 | { KB_NO, KB_##K29, KB_##K2A, KB_##K2B, KB_##K2C, KB_##K2D, KB_##K2E, KB_##K2F }, \ | ||
| 59 | { KB_NO, KB_##K31, KB_##K32, KB_##K33, KB_##K34, KB_##K35, KB_##K36, KB_##K37 }, \ | ||
| 60 | { KB_NO, KB_##K39, KB_##K3A, KB_##K3B, KB_##K3C, KB_##K3D, KB_##K3E, KB_##K3F }, \ | ||
| 61 | { KB_NO, KB_##K41, KB_##K42, KB_##K43, KB_##K44, KB_##K45, KB_##K46, KB_##K47 }, \ | ||
| 62 | { KB_NO, KB_##K49, KB_##K4A, KB_##K4B, KB_##K4C, KB_##K4D, KB_##K4E, KB_##K4F }, \ | ||
| 63 | { KB_NO, KB_##K51, KB_##K52, KB_##K53, KB_##K54, KB_##K55, KB_##K56, KB_##K57 }, \ | ||
| 64 | { KB_##K58, KB_##K59, KB_##K5A, KB_##K5B, KB_##K5C, KB_##K5D, KB_##K5E, KB_##K5F }, \ | ||
| 65 | { KB_##K60, KB_##K61, KB_##K62, KB_##K63, KB_##K64, KB_##K65, KB_##K66, KB_##K67 }, \ | ||
| 66 | { KB_##K68, KB_##K69, KB_##K6A, KB_##K6B, KB_##K6C, KB_##K6D, KB_##K6E, KB_##K6F }, \ | ||
| 67 | { KB_##K70, KB_##K71, KB_##K72, KB_##K73, KB_##K74, KB_##K75, KB_##K76, KB_##K77 }, \ | ||
| 68 | { KB_##K78, KB_##K79, KB_##K7A, KB_##K7B, KB_##K7C, KB_##K7D, KB_##K7E, KB_NO }, \ | ||
| 69 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_##K84, 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. | ||
| 74 | static const uint8_t PROGMEM fn_layer[] = { | ||
| 75 | 1, // Fn0 | ||
| 76 | 2, // Fn1 | ||
| 77 | 3, // 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. | ||
| 87 | static const uint8_t PROGMEM fn_keycode[] = { | ||
| 88 | KB_SCLN, // Fn0 | ||
| 89 | KB_SLSH, // Fn1 | ||
| 90 | KB_ESC, // Fn2 | ||
| 91 | KB_NO, // Fn3 | ||
| 92 | KB_NO, // Fn4 | ||
| 93 | KB_NO, // Fn5 | ||
| 94 | KB_NO, // Fn6 | ||
| 95 | KB_NO // Fn7 | ||
| 96 | }; | ||
| 97 | |||
| 98 | |||
| 99 | static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
| 100 | /* 0: default | ||
| 101 | * ,---. ,---------------. ,---------------. ,---------------. ,-----------. | ||
| 102 | * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| | ||
| 103 | * `---' `---------------' `---------------' `---------------' `-----------' | ||
| 104 | * ,-----------------------------------------------------------. ,-----------. ,---------------. | ||
| 105 | * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| \|BS | |Ins|Hom|PgU| |NmL| /| *| -| | ||
| 106 | * |-----------------------------------------------------------| |-----------| |---------------| | ||
| 107 | * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD| | 7| 8| 9| | | ||
| 108 | * |-----------------------------------------------------------| `-----------' |-----------| +| | ||
| 109 | * |CapsLo| A| S| D| F| G| H| J| K| L| ;| '| #|Retu| | 4| 5| 6| | | ||
| 110 | * |-----------------------------------------------------------| ,---. |---------------| | ||
| 111 | * |Shif| \| Z| X| C| V| B| N| M| ,| ,| /|Shift | |Up | | 1| 2| 3| | | ||
| 112 | * |-----------------------------------------------------------| ,-----------. |-----------|Ent| | ||
| 113 | * |Ctrl| |Alt | Space |Alt | |Ctrl| |Lef|Dow|Rig| | 0| .| | | ||
| 114 | * `----' `---------------------------------------' `----' `-----------' `---------------' | ||
| 115 | */ | ||
| 116 | KEYMAP( | ||
| 117 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, | ||
| 118 | GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, JYEN,BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
| 119 | TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, BSLS, DEL, END, PGDN, P7, P8, P9, PPLS, | ||
| 120 | LCTL,A, S, D, F, G, H, J, K, L, FN0, QUOT, NUHS,ENT, P4, P5, P6, PCMM, | ||
| 121 | LSFT,NUBS,Z, X, C, V, B, N, M, COMM,DOT, FN1, RO, FN2, UP, P1, P2, P3, PENT, | ||
| 122 | LGUI, LALT, SPC, RALT, RCTL, LEFT,DOWN,RGHT, NO, P0, PDOT,NO | ||
| 123 | ), | ||
| 124 | |||
| 125 | /* 1: Mouse keys | ||
| 126 | * ,-----------------------------------------------------------. | ||
| 127 | * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Backspa| | ||
| 128 | * |-----------------------------------------------------------| | ||
| 129 | * |Tab |MwL|MwU|McU|WwU|WwR|MwL|MwD|MwU|MwR| | | | \| | ||
| 130 | * |-----------------------------------------------------------| | ||
| 131 | * |CapsLo| |McL|McD|McR| |McL|McD|McU|McR|Fn0| |Return | | ||
| 132 | * |-----------------------------------------------------------| | ||
| 133 | * |Shift |VoD|VoU|Mut|Mb2|Mb3|Mb2|Mb1|VoD|VoU|Mut|Shift | | ||
| 134 | * |-----------------------------------------------------------| | ||
| 135 | * |Ctrl | |Alt | Mb1 |Alt | |Ctrl| | ||
| 136 | * `-----' `--------------------------------------' `----' | ||
| 137 | * Mc = mouse cursor, Mw = mouse wheel, Mb = mouse button | ||
| 138 | * Vo = Volume, Mut = Mute | ||
| 139 | */ | ||
| 140 | KEYMAP( | ||
| 141 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, | ||
| 142 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, NO, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
| 143 | TAB, WH_L,WH_D,MS_U,WH_U,WH_R,WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSLS, DEL, END, PGDN, P7, P8, P9, PPLS, | ||
| 144 | LCTL,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN0, NO, NO, ENT, P4, P5, P6, PCMM, | ||
| 145 | LSFT,NO, VOLD,VOLU,MUTE,BTN2,BTN3,BTN2,BTN1,VOLD,VOLU,MUTE, NO, RSFT, UP, P1, P2, P3, PENT, | ||
| 146 | LGUI, LALT, BTN1, RALT, RCTL, LEFT,DOWN,RGHT, NO, P0, PDOT,NO | ||
| 147 | ), | ||
| 148 | |||
| 149 | /* 2: Cursor keys | ||
| 150 | * ,-----------------------------------------------------------. | ||
| 151 | * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Backspa| | ||
| 152 | * |-----------------------------------------------------------| | ||
| 153 | * |Tab |Hom|PgU| Up|PgU|End|Hom|PgD|PgU|End| | | | \| | ||
| 154 | * |-----------------------------------------------------------| | ||
| 155 | * |CapsLo| |Lef|Dow|Rig| |Lef|Dow| Up|Rig| | |Return | | ||
| 156 | * |-----------------------------------------------------------| | ||
| 157 | * |Shift | | | | | |Hom|PgD|PgU|End|Fn1|Shift | | ||
| 158 | * |-----------------------------------------------------------| | ||
| 159 | * |Ctrl | |Alt | Space |Alt | |Ctrl| | ||
| 160 | * `-----' `--------------------------------------' `----' | ||
| 161 | */ | ||
| 162 | KEYMAP( | ||
| 163 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, | ||
| 164 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, NO, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
| 165 | TAB, NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, NO, NO, NO, BSLS, DEL, END, PGDN, P7, P8, P9, PMNS, | ||
| 166 | LCTL,NO, NO, NO, NO, NO, LEFT,DOWN,UP, RGHT,NO, NO, NO, ENT, P4, P5, P6, PCMM, | ||
| 167 | LSFT,NO, VOLD,VOLU,MUTE,NO, NO, HOME,PGDN,PGUP,END, FN1, NO, RSFT, UP, P1, P2, P3, PENT, | ||
| 168 | LGUI, LALT, SPC, RALT, RCTL, LEFT,DOWN,RGHT, NO, P0, PDOT,NO | ||
| 169 | ), | ||
| 170 | |||
| 171 | /* 3: HHKB | ||
| 172 | * ,-----------------------------------------------------------. | ||
| 173 | * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del| | ||
| 174 | * |-----------------------------------------------------------| | ||
| 175 | * |Caps | | | | | | | |Psc|Slk|Pus|Up | |Backs| | ||
| 176 | * |-----------------------------------------------------------| | ||
| 177 | * |Contro|VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter | | ||
| 178 | * |-----------------------------------------------------------| | ||
| 179 | * |Shift | | | | | | +| -|End|PgD|Dow|Fn2 | | ||
| 180 | * |-----------------------------------------------------------| | ||
| 181 | * |Ctrl | |Alt | Space |Alt | |Ctrl| | ||
| 182 | * `-----' `--------------------------------------' `----' | ||
| 183 | */ | ||
| 184 | KEYMAP( | ||
| 185 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, | ||
| 186 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, NO, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
| 187 | CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,BRK, UP, NO, BSLS, DEL, END, PGDN, P7, P8, P9, PPLS, | ||
| 188 | LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT, NO, ENT, P4, P5, P6, PCMM, | ||
| 189 | LSFT,NO, NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN, NO, FN2, UP, P1, P2, P3, PENT, | ||
| 190 | LGUI, LALT, SPC, RALT, RCTL, LEFT,DOWN,RGHT, NO, P0, PDOT,NO | ||
| 191 | ), | ||
| 192 | }; | ||
| 193 | |||
| 194 | |||
| 195 | uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col) | ||
| 196 | { | ||
| 197 | return pgm_read_byte(&keymaps[(layer)][(row)][(col)]); | ||
| 198 | } | ||
| 199 | |||
| 200 | uint8_t keymap_fn_layer(uint8_t fn_bits) | ||
| 201 | { | ||
| 202 | return pgm_read_byte(&fn_layer[biton(fn_bits)]); | ||
| 203 | } | ||
| 204 | |||
| 205 | uint8_t keymap_fn_keycode(uint8_t fn_bits) | ||
| 206 | { | ||
| 207 | return pgm_read_byte(&fn_keycode[(biton(fn_bits))]); | ||
| 208 | } | ||
diff --git a/terminal_usb/keymap_122.c b/terminal_usb/keymap_122.c deleted file mode 100644 index 7a2168122..000000000 --- a/terminal_usb/keymap_122.c +++ /dev/null | |||
| @@ -1,143 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along 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 "print.h" | ||
| 23 | #include "debug.h" | ||
| 24 | #include "util.h" | ||
| 25 | #include "keymap.h" | ||
| 26 | |||
| 27 | |||
| 28 | |||
| 29 | |||
| 30 | /* | ||
| 31 | * IBM Terminal keyboard 1392595(102keys) | ||
| 32 | * http://geekhack.org/showthread.php?10737-What-Can-I-Do-With-a-Terminal-Model-M | ||
| 33 | * http://www.seasip.info/VintagePC/ibm_1391406.html | ||
| 34 | * | ||
| 35 | * Keymap array: | ||
| 36 | * 8 bytes | ||
| 37 | * +---------+ | ||
| 38 | * 0| | | ||
| 39 | * :| | 0x00-0x87 | ||
| 40 | * ;| | | ||
| 41 | * 17| | | ||
| 42 | * +---------+ | ||
| 43 | */ | ||
| 44 | #define KEYMAP( \ | ||
| 45 | K08,K10,K18,K20,K28,K30,K38,K40,K48,K50,K57,K5F, \ | ||
| 46 | K07,K0F,K17,K1F,K27,K2F,K37,K3F,K47,K4F,K56,K5E, \ | ||
| 47 | \ | ||
| 48 | K05,K06, K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K5D,K66, K67,K6E,K6F, K76,K77,K7E,K84, \ | ||
| 49 | K04,K0C, K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B, K5C, K64,K65,K6D, K6C,K75,K7D,K7C, \ | ||
| 50 | K03,K0B, K14,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52, K53,K5A, K63, K6B,K73,K74,K7B, \ | ||
| 51 | K83,K0A, K12,K13,K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A, K51,K59, K61,K62,K6A, K69,K72,K7A,K79, \ | ||
| 52 | K01,K09, K11, K19, K29, K39, K58, K60, K68,K70,K71,K78 \ | ||
| 53 | ) { \ | ||
| 54 | { KB_NO, KB_##K01, KB_NO, 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_##K6D, KB_##K6E, KB_##K6F }, \ | ||
| 68 | { KB_##K70, KB_##K71, KB_##K72, KB_##K73, KB_##K74, KB_##K75, KB_##K76, KB_##K77 }, \ | ||
| 69 | { KB_##K78, KB_##K79, KB_##K7A, KB_##K7B, KB_##K7C, KB_##K7D, KB_##K7E, KB_NO }, \ | ||
| 70 | { KB_NO, KB_NO, KB_NO, KB_##K83, KB_##K84, KB_NO, KB_NO, KB_NO, }, \ | ||
| 71 | } | ||
| 72 | |||
| 73 | |||
| 74 | // Assign Fn key(0-7) to a layer to which switch with the Fn key pressed. | ||
| 75 | static const uint8_t PROGMEM fn_layer[] = { | ||
| 76 | 0, // Fn0 | ||
| 77 | 0, // Fn1 | ||
| 78 | 0, // Fn2 | ||
| 79 | 0, // Fn3 | ||
| 80 | 0, // Fn4 | ||
| 81 | 0, // Fn5 | ||
| 82 | 0, // Fn6 | ||
| 83 | 0 // Fn7 | ||
| 84 | }; | ||
| 85 | |||
| 86 | // Assign Fn key(0-7) to a keycode sent when release Fn key without use of the layer. | ||
| 87 | // See layer.c for details. | ||
| 88 | static const uint8_t PROGMEM fn_keycode[] = { | ||
| 89 | KB_NO, // Fn0 | ||
| 90 | KB_NO, // Fn1 | ||
| 91 | KB_NO, // Fn2 | ||
| 92 | KB_NO, // Fn3 | ||
| 93 | KB_NO, // Fn4 | ||
| 94 | KB_NO, // Fn5 | ||
| 95 | KB_NO, // Fn6 | ||
| 96 | KB_NO // Fn7 | ||
| 97 | }; | ||
| 98 | |||
| 99 | |||
| 100 | static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
| 101 | /* 0: default | ||
| 102 | * ,---. ,---------------. ,---------------. ,---------------. ,-----------. | ||
| 103 | * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| | ||
| 104 | * `---' `---------------' `---------------' `---------------' `-----------' | ||
| 105 | * ,-----------------------------------------------------------. ,-----------. ,---------------. | ||
| 106 | * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| \|BS | |Ins|Hom|PgU| |NmL| /| *| -| | ||
| 107 | * |-----------------------------------------------------------| |-----------| |---------------| | ||
| 108 | * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD| | 7| 8| 9| | | ||
| 109 | * |-----------------------------------------------------------| `-----------' |-----------| +| | ||
| 110 | * |CapsLo| A| S| D| F| G| H| J| K| L| ;| '| #|Retu| | 4| 5| 6| | | ||
| 111 | * |-----------------------------------------------------------| ,---. |---------------| | ||
| 112 | * |Shif| \| Z| X| C| V| B| N| M| ,| ,| /|Shift | |Up | | 1| 2| 3| | | ||
| 113 | * |-----------------------------------------------------------| ,-----------. |-----------|Ent| | ||
| 114 | * |Ctrl| |Alt | Space |Alt | |Ctrl| |Lef|Dow|Rig| | 0| .| | | ||
| 115 | * `----' `---------------------------------------' `----' `-----------' `---------------' | ||
| 116 | */ | ||
| 117 | KEYMAP( | ||
| 118 | F13, F14, F15, F16, F17, F18, F19, F20, F21, F22, F23, F24, | ||
| 119 | F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, | ||
| 120 | |||
| 121 | PSCR,ESC, GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, JYEN,BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
| 122 | SLCK,INT4, TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, BSLS, DEL, END, PGDN, P7, P8, P9, PPLS, | ||
| 123 | PAUS,INT5, CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT, NUHS,ENT, UP, P4, P5, P6, PCMM, | ||
| 124 | APP, INT6, LSFT,NUBS,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RO, RSFT, LEFT,INT2,RGHT, P1, P2, P3, PENT, | ||
| 125 | RGUI,LGUI, LCTL, LALT, SPC, RALT, RCTL, DOWN, NO, P0, PDOT,NO | ||
| 126 | ), | ||
| 127 | }; | ||
| 128 | |||
| 129 | |||
| 130 | uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col) | ||
| 131 | { | ||
| 132 | return pgm_read_byte(&keymaps[(layer)][(row)][(col)]); | ||
| 133 | } | ||
| 134 | |||
| 135 | uint8_t keymap_fn_layer(uint8_t fn_bits) | ||
| 136 | { | ||
| 137 | return pgm_read_byte(&fn_layer[biton(fn_bits)]); | ||
| 138 | } | ||
| 139 | |||
| 140 | uint8_t keymap_fn_keycode(uint8_t fn_bits) | ||
| 141 | { | ||
| 142 | return pgm_read_byte(&fn_keycode[(biton(fn_bits))]); | ||
| 143 | } | ||
diff --git a/terminal_usb/led.c b/terminal_usb/led.c deleted file mode 100644 index e448e84ec..000000000 --- a/terminal_usb/led.c +++ /dev/null | |||
| @@ -1,33 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "stdint.h" | ||
| 19 | #include "ps2.h" | ||
| 20 | #include "led.h" | ||
| 21 | |||
| 22 | |||
| 23 | void led_set(uint8_t usb_led) | ||
| 24 | { | ||
| 25 | uint8_t ps2_led = 0; | ||
| 26 | if (usb_led & (1<<USB_LED_SCROLL_LOCK)) | ||
| 27 | ps2_led |= (1<<PS2_LED_SCROLL_LOCK); | ||
| 28 | if (usb_led & (1<<USB_LED_NUM_LOCK)) | ||
| 29 | ps2_led |= (1<<PS2_LED_NUM_LOCK); | ||
| 30 | if (usb_led & (1<<USB_LED_CAPS_LOCK)) | ||
| 31 | ps2_led |= (1<<PS2_LED_CAPS_LOCK); | ||
| 32 | ps2_host_set_led(ps2_led); | ||
| 33 | } | ||
diff --git a/terminal_usb/matrix.c b/terminal_usb/matrix.c deleted file mode 100644 index a6eff8c1e..000000000 --- a/terminal_usb/matrix.c +++ /dev/null | |||
| @@ -1,226 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along 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 "debug.h" | ||
| 25 | #include "ps2.h" | ||
| 26 | #include "matrix.h" | ||
| 27 | |||
| 28 | |||
| 29 | static void matrix_make(uint8_t code); | ||
| 30 | static void matrix_break(uint8_t code); | ||
| 31 | #ifdef MATRIX_HAS_GHOST | ||
| 32 | static bool matrix_has_ghost_in_row(uint8_t row); | ||
| 33 | #endif | ||
| 34 | |||
| 35 | |||
| 36 | /* | ||
| 37 | * Matrix Array usage: | ||
| 38 | * 'Scan Code Set 3' is assigned into 17x8 cell matrix. | ||
| 39 | * | ||
| 40 | * 8bit wide | ||
| 41 | * +---------+ | ||
| 42 | * 0| | | ||
| 43 | * :| | 0x00-0x87 | ||
| 44 | * ;| | | ||
| 45 | * 17| | | ||
| 46 | * +---------+ | ||
| 47 | */ | ||
| 48 | static uint8_t matrix[MATRIX_ROWS]; | ||
| 49 | #define ROW(code) (code>>3) | ||
| 50 | #define COL(code) (code&0x07) | ||
| 51 | |||
| 52 | static bool is_modified = false; | ||
| 53 | |||
| 54 | |||
| 55 | inline | ||
| 56 | uint8_t matrix_rows(void) | ||
| 57 | { | ||
| 58 | return MATRIX_ROWS; | ||
| 59 | } | ||
| 60 | |||
| 61 | inline | ||
| 62 | uint8_t matrix_cols(void) | ||
| 63 | { | ||
| 64 | return MATRIX_COLS; | ||
| 65 | } | ||
| 66 | |||
| 67 | void matrix_init(void) | ||
| 68 | { | ||
| 69 | print_enable = true; | ||
| 70 | debug_enable = true; | ||
| 71 | //debug_matrix = true; | ||
| 72 | //debug_keyboard = true; | ||
| 73 | //debug_mouse = false; | ||
| 74 | |||
| 75 | ps2_host_init(); | ||
| 76 | // Make and Break code without Typematic | ||
| 77 | while (ps2_host_send(0xF8) != 0xFA) { | ||
| 78 | debug("send F8: failed\n"); | ||
| 79 | _delay_ms(500); | ||
| 80 | } | ||
| 81 | debug("send F8: OK\n"); | ||
| 82 | |||
| 83 | |||
| 84 | // initialize matrix state: all keys off | ||
| 85 | for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; | ||
| 86 | |||
| 87 | return; | ||
| 88 | } | ||
| 89 | |||
| 90 | uint8_t matrix_scan(void) | ||
| 91 | { | ||
| 92 | |||
| 93 | // scan code reading states | ||
| 94 | static enum { | ||
| 95 | INIT, | ||
| 96 | F0, | ||
| 97 | } state = INIT; | ||
| 98 | |||
| 99 | |||
| 100 | is_modified = false; | ||
| 101 | |||
| 102 | uint8_t code; | ||
| 103 | while ((code = ps2_host_recv())) { | ||
| 104 | debug_hex(code); | ||
| 105 | switch (state) { | ||
| 106 | case INIT: | ||
| 107 | switch (code) { | ||
| 108 | case 0xF0: | ||
| 109 | state = F0; | ||
| 110 | debug(" "); | ||
| 111 | break; | ||
| 112 | default: // normal key make | ||
| 113 | if (code < 0x88) { | ||
| 114 | matrix_make(code); | ||
| 115 | } else { | ||
| 116 | debug("unexpected scan code at INIT: "); debug_hex(code); debug("\n"); | ||
| 117 | } | ||
| 118 | state = INIT; | ||
| 119 | debug("\n"); | ||
| 120 | } | ||
| 121 | break; | ||
| 122 | case F0: // Break code | ||
| 123 | switch (code) { | ||
| 124 | default: | ||
| 125 | if (code < 0x88) { | ||
| 126 | matrix_break(code); | ||
| 127 | } else { | ||
| 128 | debug("unexpected scan code at F0: "); debug_hex(code); debug("\n"); | ||
| 129 | } | ||
| 130 | state = INIT; | ||
| 131 | debug("\n"); | ||
| 132 | } | ||
| 133 | break; | ||
| 134 | } | ||
| 135 | } | ||
| 136 | return 1; | ||
| 137 | } | ||
| 138 | |||
| 139 | bool matrix_is_modified(void) | ||
| 140 | { | ||
| 141 | return is_modified; | ||
| 142 | } | ||
| 143 | |||
| 144 | inline | ||
| 145 | bool matrix_has_ghost(void) | ||
| 146 | { | ||
| 147 | #ifdef MATRIX_HAS_GHOST | ||
| 148 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 149 | if (matrix_has_ghost_in_row(i)) | ||
| 150 | return true; | ||
| 151 | } | ||
| 152 | #endif | ||
| 153 | return false; | ||
| 154 | } | ||
| 155 | |||
| 156 | inline | ||
| 157 | bool matrix_is_on(uint8_t row, uint8_t col) | ||
| 158 | { | ||
| 159 | return (matrix[row] & (1<<col)); | ||
| 160 | } | ||
| 161 | |||
| 162 | inline | ||
| 163 | uint8_t matrix_get_row(uint8_t row) | ||
| 164 | { | ||
| 165 | return matrix[row]; | ||
| 166 | } | ||
| 167 | |||
| 168 | void matrix_print(void) | ||
| 169 | { | ||
| 170 | print("\nr/c 01234567\n"); | ||
| 171 | for (uint8_t row = 0; row < matrix_rows(); row++) { | ||
| 172 | phex(row); print(": "); | ||
| 173 | pbin_reverse(matrix_get_row(row)); | ||
| 174 | #ifdef MATRIX_HAS_GHOST | ||
| 175 | if (matrix_has_ghost_in_row(row)) { | ||
| 176 | print(" <ghost"); | ||
| 177 | } | ||
| 178 | #endif | ||
| 179 | print("\n"); | ||
| 180 | } | ||
| 181 | } | ||
| 182 | |||
| 183 | uint8_t matrix_key_count(void) | ||
| 184 | { | ||
| 185 | uint8_t count = 0; | ||
| 186 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 187 | count += bitpop(matrix[i]); | ||
| 188 | } | ||
| 189 | return count; | ||
| 190 | } | ||
| 191 | |||
| 192 | #ifdef MATRIX_HAS_GHOST | ||
| 193 | inline | ||
| 194 | static bool matrix_has_ghost_in_row(uint8_t row) | ||
| 195 | { | ||
| 196 | // no ghost exists in case less than 2 keys on | ||
| 197 | if (((matrix[row] - 1) & matrix[row]) == 0) | ||
| 198 | return false; | ||
| 199 | |||
| 200 | // ghost exists in case same state as other row | ||
| 201 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | ||
| 202 | if (i != row && (matrix[i] & matrix[row]) == matrix[row]) | ||
| 203 | return true; | ||
| 204 | } | ||
| 205 | return false; | ||
| 206 | } | ||
| 207 | #endif | ||
| 208 | |||
| 209 | |||
| 210 | inline | ||
| 211 | static void matrix_make(uint8_t code) | ||
| 212 | { | ||
| 213 | if (!matrix_is_on(ROW(code), COL(code))) { | ||
| 214 | matrix[ROW(code)] |= 1<<COL(code); | ||
| 215 | is_modified = true; | ||
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 | inline | ||
| 220 | static void matrix_break(uint8_t code) | ||
| 221 | { | ||
| 222 | if (matrix_is_on(ROW(code), COL(code))) { | ||
| 223 | matrix[ROW(code)] &= ~(1<<COL(code)); | ||
| 224 | is_modified = true; | ||
| 225 | } | ||
| 226 | } | ||
